id_empr= intval($id_empr); $this->id_expl = intval($id_expl); $this->cb_expl = $cb_expl; $this->getData(); } // récupération infos du prêt public function getData() { global $dbh; global $msg; if(($this->id_expl==0) && ($this->cb_expl=="")) { // aucun identifiant. on retourne un tableau vide $this->id_empr = 0; $this->id_expl = 0; $this->pret_date = ""; $this->pret_retour = ""; $this->cb_expl = ""; $this->type_doc=""; $this->statut_doc=""; $this->owner=""; $this->date_pret_display=""; $this->date_retour_display=""; $this->etat=0; $this->display = $msg[4052]; } else { $sql_dates = " date_format(pret_date, '".$msg["format_date"]."') as aff_pret_date, "; $sql_dates .= " date_format(pret_retour, '".$msg["format_date"]."') as aff_pret_retour, "; $sql_dates .= " IF(pret_retour>sysdate(),0,1) as retard " ; if ($this->id_expl!=0) $requete = "SELECT pret_idempr, pret_idexpl, pret_date, pret_retour, expl_cb, expl_typdoc, expl_statut, expl_owner, $sql_dates FROM pret, exemplaires WHERE pret_idexpl='".$this->id_expl."' and pret_idexpl=expl_id LIMIT 1 "; else $requete = "SELECT pret_idempr, pret_idexpl, pret_date, pret_retour, expl_cb, expl_typdoc, expl_statut, expl_owner, $sql_dates FROM pret, exemplaires WHERE expl_cb='".$this->cb_expl."' and pret_idexpl=expl_id LIMIT 1 "; $result = @pmb_mysql_query($requete, $dbh); if(pmb_mysql_num_rows($result)) { $temp = pmb_mysql_fetch_object($result); pmb_mysql_free_result($result); $this->id_empr = $temp->pret_idempr; $this->id_expl = $temp->pret_idexpl; $this->pret_date = $temp->pret_date; $this->pret_retour = $temp->pret_retour; $this->cb_expl = $temp->expl_cb; $requete = "select tdoc_libelle from docs_type where idtyp_doc='".$temp->expl_typdoc."' "; $result = @pmb_mysql_query($requete, $dbh); $typdoc = pmb_mysql_fetch_object($result); pmb_mysql_free_result($result); $this->type_doc = $typdoc->tdoc_libelle; $requete = "select statut_libelle from docs_statut where idstatut='".$temp->expl_statut."' "; $result = @pmb_mysql_query($requete, $dbh); $statdoc = pmb_mysql_fetch_object($result); pmb_mysql_free_result($result); $this->statut_doc = $statdoc->statut_libelle; $requete = "select lender_libelle from lenders where idlender='".$temp->expl_owner."' "; $result = @pmb_mysql_query($requete, $dbh); $lender = pmb_mysql_fetch_object($result); pmb_mysql_free_result($result); $this->owner = $lender->lender_libelle; $this->date_pret_display=$temp->aff_pret_date; $this->date_retour_display=$temp->aff_pret_retour; $this->retard=$temp->retard; $this->etat=1; $this->display = "Prêt existant"; } else { // pas de prêt avec cette clé : on va aller chercher le expl_cb avec l'id ou l'inverse $long_maxi_cb_expl = pmb_mysql_field_len(pmb_mysql_query("SELECT expl_cb FROM exemplaires limit 1"),0); $this->cb_expl = rtrim(substr(pmb_preg_replace('/\[|\]/', '', rtrim(ltrim($this->cb_expl))),0,$long_maxi_cb_expl)); if ($this->id_expl==0) { /* ici la recherche de l'id_expl */ $query = "SELECT expl_id, expl_cb FROM exemplaires WHERE expl_cb='${key_cb_expl}' LIMIT 1 "; } else { /* ici la recherche du cb à partir de l'id */ $query = "SELECT expl_id, expl_cb FROM exemplaires WHERE expl_id='".$this->id_expl."' LIMIT 1 "; } $result = @pmb_mysql_query($query, $dbh) or die("can't SELECT exemplaires ".$query); if (pmb_mysql_num_rows($result)==0) { /* on n'a trouvé aucun exemplaire */ $this->id_empr = 0; $this->id_expl = 0; $this->pret_date = ""; $this->pret_retour = ""; $this->cb_expl = ""; $this->type_doc=""; $this->statut_doc=""; $this->owner = ""; $this->date_pret_display=""; $this->date_retour_display=""; $this->etat=3; $this->display = "Exemplaire introuvable"; } else { $expl = pmb_mysql_fetch_object($result); $this->id_expl = $expl->expl_id; $this->cb_expl = $expl->expl_cb; $this->pret_retour = ""; $this->type_doc=""; $this->statut_doc=""; $this->owner = ""; $this->date_pret_display=""; $this->date_retour_display=""; $this->etat=2; $this->display = "Prêt possible, inexistant avec cette clé"; } } } } // retour prêt public function retour($retour_effectif) { global $dbh; global $msg; // check sur le type de la variable passée en paramètre if ($retour_effectif=="") $retour_effectif=time(); /* on a tout ce qu'il faut, on peut supprimer le prêt */ /* on va d'abord transférer tout ce que l'on connait dans la table des archives pour les stats */ $query = "SELECT pret_date as debut, cpt_prolongation, empr_cp, empr_ville, empr_prof, empr_year, empr_categ, empr_codestat, empr_sexe, empr_statut, empr_location, type_abt, "; $query.= "expl_typdoc, expl_cote, expl_statut, expl_location, expl_codestat, expl_section, expl_owner FROM pret, empr, exemplaires WHERE pret_idexpl='".$this->id_expl."' and id_empr=pret_idempr and expl_id=pret_idexpl "; $res_stat = @pmb_mysql_query($query, $dbh) or die(pmb_mysql_error()."
can't SELECT pret & co for stats
".$query."
"); $temp = pmb_mysql_fetch_object($res_stat); $query = "insert into pret_archive set "; $query.="arc_debut ='".$temp->debut ."', "; $query.="arc_fin ='".date("Y-m-d",$retour_effectif) ."', "; $query.="arc_empr_cp ='".addslashes($temp->empr_cp )."', "; $query.="arc_empr_ville ='".addslashes($temp->empr_ville )."', "; $query.="arc_empr_prof ='".addslashes($temp->empr_prof )."', "; $query.="arc_empr_year ='".$temp->empr_year ."', "; $query.="arc_empr_categ ='".$temp->empr_categ ."', "; $query.="arc_empr_codestat ='".$temp->empr_codestat ."', "; $query.="arc_empr_sexe ='".$temp->empr_sexe ."', "; $query.= "arc_empr_statut ='".$temp->empr_statut ."', "; $query.= "arc_empr_location ='".$temp->empr_location ."', "; $query.= "arc_type_abt ='".$temp->type_abt ."', "; $query.="arc_expl_typdoc ='".$temp->expl_typdoc ."', "; $query.="arc_expl_cote ='".addslashes($temp->expl_cote )."', "; $query.="arc_expl_statut ='".$temp->expl_statut ."', "; $query.="arc_expl_location ='".$temp->expl_location ."', "; $query.="arc_expl_section ='".$temp->expl_section ."', "; $query.="arc_expl_codestat ='".$temp->expl_codestat ."', "; $query.="arc_expl_owner ='".$temp->expl_owner ."', "; $query.="arc_niveau_relance='". $temp->niveau_relance ."', "; $query.="arc_date_relance='". $temp->date_relance ."', "; $query.="arc_printed='". $temp->printed ."', "; $query.="arc_cpt_prolongation='".$temp->cpt_prolongation ."' "; @pmb_mysql_query($query, $dbh) or die(pmb_mysql_error()."
can't insert in pret_archive
".$query."
"); $query = "delete from pret where pret_idexpl = '".$this->id_expl."' "; @pmb_mysql_query($query, $dbh) or die("can't delete from pret ".$query."
".pmb_mysql_error()); return 0; } // --------------------------------------------------------------- // annulation() : annulation violente d'un prêt // --------------------------------------------------------------- public function annulation() { global $dbh; global $msg; $query = "delete from pret where "; $query .= "pret_idexpl = '".$this->id_expl."' "; $result = @pmb_mysql_query($query, $dbh) or die("can't delete from pret ".$query."
".pmb_mysql_error()); return 0; } // --------------------------------------------------------------- // prolongation() : prolongation d'un prêt // --------------------------------------------------------------- public function prolongation($nouvelle_date) { global $dbh; global $msg; $query = "update pret set pret_retour = '".$nouvelle_date."', "; $query .= "niveau_relance = 0, date_relance = '0000-00-00', printed=0 "; $query .= "where pret_idexpl = '".$this->id_expl."' "; $result = @pmb_mysql_query($query, $dbh) or die("can't update pret ".$query."
".pmb_mysql_error()); return 0; } public function get_exemplaire() { if(!isset($this->exemplaire)) { $this->exemplaire = new exemplaire($this->cb_expl, $this->id_expl); } return $this->exemplaire; } public function get_emprunteur() { if(!isset($this->emprunteur)) { $this->emprunteur = new emprunteur($this->id_empr); } return $this->emprunteur; } public static function get_display_info($title='', $content) { global $pmb_play_pret_sound; global $alert_sound_list; if($pmb_play_pret_sound) { $alert_sound_list[]="information"; } return "
".($title ? $title." :" : "")." ".$content."

"; } public static function get_display_error($title='', $content='', $show_cancel=0, $show_loan=0, $suffix_link_loan='') { global $msg; global $pmb_play_pret_sound; global $alert_sound_list; global $id_empr, $cb_doc, $confirm; if(!$title && !$content) { return "

"; } if($pmb_play_pret_sound) { $alert_sound_list[]="critique"; } $display = "
".($title ? $title." :" : "")." ".$content.""; if($show_cancel) { $display .= ""; } if($show_loan) { $display .= " "; } $display .= "

"; return $display; } public static function get_display_custom_fields($id_empr,$id_expl) { $p_perso=new pret_parametres_perso("pret"); if(!$p_perso->no_special_fields) { $query_custom = "select pret_arc_id from pret where pret_idempr='".$id_empr."' and pret_idexpl='".$id_expl."'"; $result_custom = pmb_mysql_query($query_custom); if ($result_custom && pmb_mysql_result($result_custom,0,0)) { $pret_arc_id = pmb_mysql_result($result_custom,0,0); $perso_ = $p_perso->show_fields($pret_arc_id); $perso=""; if (count($perso_["FIELDS"])) { for ($i=0; $i"; } $perso."
"; } return $perso; } } } public static function get_display_antivol($id_expl) { global $pmb_antivol; $script_magnetique=" "; if($type_antivol ==2)//c'est un support magnétique (cassette) return "$script_magnetique"."magnetise('SSS');"; } return ""; } public static function add_alert_sound_list($sound) { global $pmb_play_pret_sound, $alert_sound_list; if($pmb_play_pret_sound) { $alert_sound_list[] = $sound; } } public static function extendLoan($id_empr, $expl_id, $date_retour){ global $msg; $query = "SELECT cpt_prolongation FROM pret WHERE pret_idempr = $id_empr AND pret_idexpl = $expl_id"; $r = pmb_mysql_query($query); if (!pmb_mysql_num_rows($r)){ return ["status"=>false, "message"=>$msg["pnb_extend_loan_fail"], "infos"=>"infos"]; } $result = pmb_mysql_fetch_array($r); $new_cpt_prolongation = intval($result['cpt_prolongation']) + 1; $query = "UPDATE pret SET pret_retour = '$date_retour', cpt_prolongation = $new_cpt_prolongation WHERE pret_idempr = $id_empr AND pret_idexpl = $expl_id"; pmb_mysql_query($query); return true; } } # fin de définition de la classe pret } # fin de délaration