0) {
$ret[0]=PBINSC_MAIL;
$ret[1]=str_replace("!!email!!",urlencode($f_email),$msg[subs_pb_email]);
return $ret ;
}
$rqt = "select id_empr from empr where empr_login ='".$f_login."' ";
$res = mysql_query($rqt,$dbh);
if (mysql_num_rows($res)>0) {
$ret[0]=PBINSC_LOGIN;
$ret[1]=str_replace("!!f_login!!",$f_login,$msg[subs_pb_login]).generate_form_inscription();
return $ret ;
}
// préparation des données:
// langue:
if ($_COOKIE['PhpMyBibli-LANG']) $lang=$_COOKIE['PhpMyBibli-LANG'];
if (!$lang) {
if ($opac_default_lang) $lang = $opac_default_lang;
else $lang = "fr_FR";
}
// paramétrage :
global $opac_websubscribe_empr_status, $opac_websubscribe_empr_categ, $opac_websubscribe_empr_stat, $opac_websubscribe_valid_limit ;
$opac_websubscribe_empr_status_array=explode(",",$opac_websubscribe_empr_status);
// codes-barres emprunteur bidon :
$pe_emprcb='www'.rand(0,100000);
// durée d'adhésion de la categ web
$rqt="select duree_adhesion from empr_categ where id_categ_empr='".$opac_websubscribe_empr_categ."' ";
$res = mysql_query($rqt,$dbh);
$obj=mysql_fetch_object($res);
$duree_adhesion=$obj->duree_adhesion;
global $pmb_lecteurs_localises,$opac_websubscribe_show_location;
if ($pmb_lecteurs_localises && $opac_websubscribe_show_location) {
global $empr_location_id;
$websubscribe_empr_location = ($empr_location_id ? $empr_location_id : 0);
} else {
global $opac_websubscribe_empr_location;
$websubscribe_empr_location = $opac_websubscribe_empr_location;
}
// clé de validation :
$alphanum = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
$cle_validation = substr(str_shuffle($alphanum), 0, 20);
$rqt = "insert into empr set ";
$rqt.= "id_empr=0, ";
$rqt.= "empr_cb ='".$pe_emprcb."', ";
$rqt.= "empr_login ='".$f_login."', ";
$rqt.= "empr_mail='".$f_email."', ";
$rqt.= "empr_nom='".$f_nom."', ";
$rqt.= "empr_prenom='".$f_prenom."', ";
$rqt.= "empr_password='".$f_password."', ";
$rqt.= "empr_creation=sysdate(), ";
$rqt.= "empr_modif=sysdate(), ";
$rqt.= "empr_date_adhesion=sysdate(), ";
$rqt.= "empr_date_expiration=date_add(sysdate(), INTERVAL $duree_adhesion DAY), ";
$rqt.= "empr_lang='".$lang."', ";
$rqt.= "empr_statut='".$opac_websubscribe_empr_status_array[0]."', ";
$rqt.= "empr_location='".$websubscribe_empr_location."', ";
$rqt.= "empr_categ='".$opac_websubscribe_empr_categ."', ";
$rqt.= "empr_codestat='".$opac_websubscribe_empr_stat."', ";
$rqt.= "empr_msg='".$f_msg."', ";
$rqt.= "empr_adr1='".$f_adr1."', ";
$rqt.= "empr_adr2='".$f_adr2."', ";
$rqt.= "empr_cp='".$f_cp."', ";
$rqt.= "empr_ville='".$f_ville."', ";
$rqt.= "empr_pays='".$f_pays."', ";
$rqt.= "empr_tel1='".$f_tel1."', ";
$rqt.= "cle_validation='".$cle_validation."' ";
$res = mysql_query($rqt,$dbh) or die (mysql_error()."
$rqt");
$id_empr = mysql_insert_id();
if ($id_empr) {
//redefine empr.empr_cb
$pe_emprcb='www'.$id_empr;
$rqt = "UPDATE empr SET empr_cb='$pe_emprcb' WHERE id_empr='$id_empr'";
$res = mysql_query($rqt, $dbh) or die (mysql_error()."
$rqt");
// envoyer le mail de demande de confirmation
global $opac_biblio_name,$opac_biblio_email,$opac_url_base ;
$obj = str_replace("!!biblio_name!!",$opac_biblio_name,$msg[subs_mail_obj]) ;
$corps = str_replace("!!biblio_name!!",$opac_biblio_name,$msg[subs_mail_corps]) ;
$lien_validation = "".$opac_url_base."subscribe.php?subsact=validation&login=$f_login&cle_validation=$cle_validation";
$corps = str_replace("!!lien_validation!!",$lien_validation,$corps) ;
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$res_envoi=@mailpmb(trim(stripslashes($f_prenom." ".$f_nom)), stripslashes($f_email),$obj,$corps,$opac_biblio_name, $opac_biblio_email, $headers);
if (!$res_envoi) {
$ret[0]=PBINSC_MAIL;
$ret[1]=str_replace("!!f_email!!",$f_email,$msg[subs_pb_mail]);
return $ret ;
}
$ret[0]=PBINSC_OK;
$ret[1]=str_replace("!!f_email!!",$f_email,$msg[subs_ok_inscrit]);
$ret[1]=str_replace("!!nb_h_valid!!",$opac_websubscribe_valid_limit,$ret[1]);
return $ret ;
} else {
$ret[0]=PBINSC_BDD;
$ret[1]=$msg[subs_pb_bdd];
return $ret ;
}
}
function verif_validation_compte() {
global $dbh, $msg;
global $login, $cle_validation, $form_access_compte ;
global $opac_websubscribe_empr_status, $opac_websubscribe_valid_limit ;
$opac_websubscribe_empr_status_array=explode(",",$opac_websubscribe_empr_status);
$ret=array();
$rqt = "select id_empr, if(date_add(empr_creation, INTERVAL $opac_websubscribe_valid_limit HOUR)>=sysdate(),1,0) as not_depasse, empr_password, cle_validation from empr where empr_login ='".$login."' and empr_statut='".$opac_websubscribe_empr_status_array[0]."' ";
$res = mysql_query($rqt,$dbh) or die (mysql_error()."
$rqt");
if (mysql_num_rows($res)>0) {
// trouvé !
$obj=mysql_fetch_object($res);
if ($obj->not_depasse) {
// validation pas dépassée
if ($obj->cle_validation==$cle_validation) {
$rqt = "update empr set cle_validation='', empr_statut='".$opac_websubscribe_empr_status_array[1]."' where empr_login='".$login."' ";
$res = mysql_query($rqt,$dbh) or die (mysql_error()."
$rqt");
$ret[0]=PBINSC_OK;
$form_access_compte=str_replace("!!login!!",$login,$form_access_compte) ;
$form_access_compte=str_replace("!!password!!",$obj->empr_password,$form_access_compte) ;
$ret[1] = str_replace("!!form_access_compte!!",$form_access_compte,$msg[subs_ok_validation]) ;
return $ret ;
} else {
// login Ok mais clé pas valide
$rqt = "delete from empr where empr_login='".$login."' ";
$res = mysql_query($rqt,$dbh) or die (mysql_error()."
$rqt");
$ret[0]=PBINSC_CLE;
$ret[1]=$msg[subs_pb_cle];
return $ret ;
}
} else {
// dépassée
$rqt = "delete from empr where empr_login='".$login."' ";
$res = mysql_query($rqt,$dbh) or die (mysql_error()."
$rqt");
$ret[0]=PBINSC_INVALID;
$ret[1]=$msg[subs_pb_invalid];
return $ret ;
}
}
// n'existe même pas !
$ret[0]=PBINSC_INCONNUE;
$ret[1] = str_replace("!!login!!",$login,$msg[subs_pb_inconnue]) ;
return $ret ;
}