id = intval($id); $this->getData(); } /* --------------------------------------------------------------- getData() : récupération des propriétés --------------------------------------------------------------- */ public function getData() { global $dbh; if(!$this->id) return; /* récupération des informations du statut */ $requete = 'SELECT * FROM docs_location WHERE idlocation='.$this->id.' LIMIT 1;'; $result = @pmb_mysql_query($requete, $dbh); if(!pmb_mysql_num_rows($result)) { pmb_error::get_instance(static::class)->add_message("not_found", "not_found_object"); return; } $data = pmb_mysql_fetch_object($result); $this->libelle = $data->location_libelle; $this->locdoc_codage_import = $data->locdoc_codage_import; $this->locdoc_owner = $data->locdoc_owner; $this->pic = $data->location_pic; $this->visible_opac = $data->location_visible_opac; $this->name = $data->name; $this->adr1 = $data->adr1; $this->adr2 = $data->adr2; $this->cp = $data->cp; $this->town = $data->town; $this->state = $data->state; $this->country = $data->country; $this->phone = $data->phone; $this->email = $data->email; $this->website = $data->website; $this->logo = $data->logo; $this->commentaire = $data->commentaire; $this->num_infopage = $data->num_infopage; $this->css_style = $data->css_style; $this->surloc_num = $data->surloc_num; $this->surloc_used = $data->surloc_used; } public function get_form() { global $admin_location_content_form, $msg, $charset; global $pmb_sur_location_activate, $pmb_map_activate; $content_form = $admin_location_content_form; $content_form = str_replace('!!id!!', $this->id, $content_form); $interface_form = new interface_admin_form('locationform'); if(!$this->id){ $interface_form->set_label($msg['106']); }else{ $interface_form->set_label($msg['107']); } $content_form = str_replace('!!libelle!!', htmlentities($this->libelle,ENT_QUOTES, $charset), $content_form); $content_form = str_replace('!!location_pic!!', htmlentities($this->pic,ENT_QUOTES, $charset), $content_form); if($this->visible_opac) $checkbox="checked"; else $checkbox=""; $content_form = str_replace('!!checkbox!!', $checkbox, $content_form); $content_form = str_replace('!!locdoc_codage_import!!', $this->locdoc_codage_import, $content_form); $combo_lender= gen_liste ("select idlender, lender_libelle from lenders order by lender_libelle ", "idlender", "lender_libelle", "form_locdoc_owner", "", $this->locdoc_owner, 0, $msg[556],0,$msg["proprio_generique_biblio"]) ; $content_form = str_replace('!!lender!!', $combo_lender, $content_form); if($pmb_sur_location_activate){ $sur_loc= sur_location::get_info_surloc_from_location($this->id); $content_form = str_replace('!!sur_loc_selector!!', $sur_loc->get_list("form_sur_localisation",$sur_loc->id,1), $content_form); } else { $content_form = str_replace('!!sur_loc_selector!!', '', $content_form); } if($this->surloc_used) $checkbox="checked"; else $checkbox=""; $content_form = str_replace('!!checkbox_use_surloc!!', $checkbox, $content_form); // map if($pmb_map_activate){ $map_edition=new map_edition_controler(TYPE_LOCATION,$this->id); $map_form=$map_edition->get_form(); $content_form = str_replace('!!location_map!!', $map_form, $content_form); } else { $content_form = str_replace('!!location_map!!', "", $content_form); } $content_form = str_replace('!!loc_name!!', htmlentities($this->name,ENT_QUOTES, $charset) , $content_form); $content_form = str_replace('!!loc_adr1!!', htmlentities($this->adr1,ENT_QUOTES, $charset) , $content_form); $content_form = str_replace('!!loc_adr2!!', htmlentities($this->adr2,ENT_QUOTES, $charset) , $content_form); $content_form = str_replace('!!loc_cp!!', $this->cp , $content_form); $content_form = str_replace('!!loc_town!!', htmlentities($this->town,ENT_QUOTES, $charset) , $content_form); $content_form = str_replace('!!loc_state!!', htmlentities($this->state,ENT_QUOTES, $charset) , $content_form); $content_form = str_replace('!!loc_country!!', htmlentities($this->country,ENT_QUOTES, $charset) , $content_form); $content_form = str_replace('!!loc_phone!!', $this->phone , $content_form); $content_form = str_replace('!!loc_email!!', $this->email , $content_form); $content_form = str_replace('!!loc_website!!', $this->website , $content_form); $content_form = str_replace('!!loc_logo!!', $this->logo , $content_form); $content_form = str_replace('!!loc_commentaire!!', htmlentities($this->commentaire,ENT_QUOTES, $charset), $content_form); $requete = "SELECT id_infopage, title_infopage FROM infopages where valid_infopage=1 ORDER BY title_infopage "; $infopages = gen_liste ($requete, "id_infopage", "title_infopage", "form_num_infopage", "", $this->num_infopage, 0, $msg["location_no_infopage"], 0,$msg["location_no_infopage"], 0) ; $content_form = str_replace('!!loc_infopage!!', $infopages, $content_form); $content_form = str_replace('!!css_style!!', $this->css_style, $content_form); $interface_form->set_object_id($this->id) ->set_confirm_delete_msg($msg['confirm_suppr_de']." ".$this->libelle." ?") ->set_content_form($content_form) ->set_table_name('docs_location') ->set_field_focus('form_libelle'); return $interface_form->get_display(); } public function set_properties_from_form() { global $form_libelle, $form_locdoc_codage_import, $form_locdoc_owner, $form_location_pic; global $form_location_visible_opac, $form_locdoc_name, $form_locdoc_adr1, $form_locdoc_adr2; global $form_locdoc_cp, $form_locdoc_town, $form_locdoc_state, $form_locdoc_country, $form_locdoc_phone; global $form_locdoc_email, $form_locdoc_website, $form_locdoc_logo, $form_locdoc_commentaire, $form_num_infopage; global $form_css_style, $form_sur_localisation, $form_location_use_surloc; $this->libelle = stripslashes($form_libelle); $this->locdoc_codage_import = stripslashes($form_locdoc_codage_import); $this->locdoc_owner = intval($form_locdoc_owner); $this->pic = stripslashes($form_location_pic); $this->visible_opac = intval($form_location_visible_opac); $this->name = stripslashes($form_locdoc_name); $this->adr1 = stripslashes($form_locdoc_adr1); $this->adr2 = stripslashes($form_locdoc_adr2); $this->cp = stripslashes($form_locdoc_cp); $this->town = stripslashes($form_locdoc_town); $this->state = stripslashes($form_locdoc_state); $this->country = stripslashes($form_locdoc_country); $this->phone = stripslashes($form_locdoc_phone); $this->email = stripslashes($form_locdoc_email); $this->website = stripslashes($form_locdoc_website); $this->logo = stripslashes($form_locdoc_logo); $this->commentaire = stripslashes($form_locdoc_commentaire); $this->num_infopage = intval($form_num_infopage); $this->css_style = stripslashes($form_css_style); $this->surloc_num = intval($form_sur_localisation); $this->surloc_used = intval($form_location_use_surloc); } public function save() { global $pmb_map_activate; // O.K., now if item already exists UPDATE else INSERT $set_values = "SET location_libelle='".addslashes($this->libelle)."', locdoc_codage_import='".addslashes($this->locdoc_codage_import)."', locdoc_owner='".$this->locdoc_owner."', location_pic='".addslashes($this->pic)."', location_visible_opac='".$this->visible_opac."', name= '".addslashes($this->name)."', adr1= '".addslashes($this->adr1)."', adr2= '".addslashes($this->adr2)."', cp= '".addslashes($this->cp)."', town= '".addslashes($this->town)."', state= '".addslashes($this->state)."', country= '".addslashes($this->country)."', phone= '".addslashes($this->phone)."', email= '".addslashes($this->email)."', website= '".addslashes($this->website)."', logo= '".addslashes($this->logo)."', commentaire='".addslashes($this->commentaire)."', num_infopage='".$this->num_infopage."', css_style='".addslashes($this->css_style)."', surloc_num='".$this->surloc_num."', surloc_used='".$this->surloc_used."' " ; if($this->id) { $requete = "UPDATE docs_location $set_values WHERE idlocation='".$this->id."' "; pmb_mysql_query($requete); } else { $requete = "INSERT INTO docs_location $set_values "; pmb_mysql_query($requete); $this->id = pmb_mysql_insert_id(); } // map if($pmb_map_activate){ $map_edition=new map_edition_controler(TYPE_LOCATION,$this->id); $map_edition->save_form(); } } // --------------------------------------------------------------- // import() : import d'un lieu de document // --------------------------------------------------------------- public static function import($data) { // cette méthode prend en entrée un tableau constitué des informations suivantes : // $data['location_libelle'] // $data['locdoc_codage_import'] // $data['locdoc_owner'] global $dbh; // check sur le type de la variable passée en paramètre if ((empty($data) && !is_array($data)) || !is_array($data)) { // si ce n'est pas un tableau ou un tableau vide, on retourne 0 return 0; } // check sur les éléments du tableau $long_maxi = pmb_mysql_field_len(pmb_mysql_query("SELECT location_libelle FROM docs_location limit 1"),0); $data['location_libelle'] = rtrim(substr(preg_replace('/\[|\]/', '', rtrim(ltrim($data['location_libelle']))),0,$long_maxi)); $long_maxi = pmb_mysql_field_len(pmb_mysql_query("SELECT locdoc_codage_import FROM docs_location limit 1"),0); $data['locdoc_codage_import'] = rtrim(substr(preg_replace('/\[|\]/', '', rtrim(ltrim($data['locdoc_codage_import']))),0,$long_maxi)); if($data['locdoc_owner']=="") $data['locdoc_owner'] = 0; if($data['location_libelle']=="") return 0; /* locdoc_codage_import est obligatoire si locdoc_owner != 0 */ //if(($data['locdoc_owner']!=0) && ($data['locdoc_codage_import']=="")) return 0; // préparation de la requête $key0 = addslashes($data['location_libelle']); $key1 = addslashes($data['locdoc_codage_import']); $key2 = $data['locdoc_owner']; /* vérification que le lieu existe */ $query = "SELECT idlocation FROM docs_location WHERE locdoc_codage_import='${key1}' and locdoc_owner = '${key2}' LIMIT 1 "; $result = @pmb_mysql_query($query, $dbh); if(!$result) die("can't SELECT docs_location ".$query); $docs_location = pmb_mysql_fetch_object($result); /* le lieu de doc existe, on retourne l'ID */ if($docs_location->idlocation) return $docs_location->idlocation; // id non-récupérée, il faut créer la forme. $query = "INSERT INTO docs_location SET "; $query .= "location_libelle='".$key0."', "; $query .= "locdoc_codage_import='".$key1."', "; $query .= "locdoc_owner='".$key2."' "; $result = @pmb_mysql_query($query, $dbh); if(!$result) die("can't INSERT into docs_location ".$query); return pmb_mysql_insert_id($dbh); } /* fin méthode import */ public static function delete($id) { global $msg; global $admin_liste_jscript; $id = intval($id); if($id) { $total1 = pmb_mysql_result(pmb_mysql_query("select count(1) from exemplaires where expl_location='".$id."' "), 0, 0); $total2 = pmb_mysql_result(pmb_mysql_query("select count(1) from users where deflt2docs_location='".$id."' or deflt_docs_location='".$id."'"), 0, 0); $total3 = pmb_mysql_result(pmb_mysql_query("select count(1) from empr where empr_location='".$id."' "), 0, 0); $total4 = pmb_mysql_result(pmb_mysql_query("select count(1) from abts_abts where location_id ='".$id."' "), 0, 0); $total5 = pmb_mysql_result(pmb_mysql_query("select count(1) from collections_state where location_id ='".$id."' "), 0, 0); if (($total1+$total2+$total3+$total4+$total5)==0) { $requete = "DELETE FROM docs_location WHERE idlocation=$id "; pmb_mysql_query($requete); return true; } else { $msg_suppr_err = $admin_liste_jscript; $msg_suppr_err .= $msg["location_used"] ; if ($total1) $msg_suppr_err .= "
- ".$msg["location_used_docs"]." " ; if ($total2) $msg_suppr_err .= "
- ".$msg["location_used_users"]." " ; if ($total3) $msg_suppr_err .= "
- ".$msg["location_used_empr"]." " ; if ($total4) $msg_suppr_err .= "
- ".$msg["location_used_abts"]." " ; if ($total5) $msg_suppr_err .= "
- ".$msg["location_used_collections_state"]." " ; pmb_error::get_instance(static::class)->add_message('294', $msg_suppr_err); return false; } } return true; } /* une fonction pour générer des combo Box paramêtres : $selected : l'élément sélectioné le cas échéant retourne une chaine de caractères contenant l'objet complet */ public static function gen_combo_box ( $selected, $on_change="") { global $msg; $requete="select idlocation, location_libelle from docs_location order by location_libelle "; $champ_code="idlocation"; $champ_info="location_libelle"; $nom="book_location_id"; $liste_vide_code="0"; $liste_vide_info=$msg['class_location']; $option_premier_code=""; $option_premier_info=""; $gen_liste_str=""; $resultat_liste=pmb_mysql_query($requete); $gen_liste_str = "\n" ; return $gen_liste_str ; } /* fin gen_combo_box */ public static function gen_combo_box_empr ( $selected, $afficher_premier=1, $on_change="" ) { global $msg; $requete="select idlocation, location_libelle from docs_location order by location_libelle "; $champ_code="idlocation"; $champ_info="location_libelle"; $nom="empr_location_id"; $liste_vide_code="0"; $liste_vide_info=$msg['class_location']; $option_premier_code="0"; if ($afficher_premier) $option_premier_info=$msg['all_location']; else $option_premier_info=''; $gen_liste_str=""; $resultat_liste=pmb_mysql_query($requete); $gen_liste_str = "\n" ; return $gen_liste_str ; } /* fin gen_combo_box_empr */ public static function gen_combo_box_docs ( $selected, $afficher_premier=1, $on_change="" ) { global $msg; $requete="select idlocation, location_libelle from docs_location order by location_libelle "; $champ_code="idlocation"; $champ_info="location_libelle"; $nom="docs_location_id"; $liste_vide_code="0"; $liste_vide_info=$msg['class_location']; $option_premier_code="0"; if ($afficher_premier) $option_premier_info=$msg['all_location']; $gen_liste_str=""; $resultat_liste=pmb_mysql_query($requete); $gen_liste_str = "\n" ; return $gen_liste_str ; } /* fin gen_combo_box_docs */ public function gen_combo_box_sugg ( $selected, $afficher_premier=1, $on_change="" ) { global $msg; $requete="select idlocation, location_libelle from docs_location order by location_libelle "; $champ_code="idlocation"; $champ_info="location_libelle"; $nom="sugg_location_id"; $liste_vide_code="0"; $liste_vide_info=$msg['class_location']; $option_premier_code="0"; if ($afficher_premier) $option_premier_info=$msg['all_location']; else $option_premier_info=''; $gen_liste_str=""; $resultat_liste=pmb_mysql_query($requete); $gen_liste_str = "\n" ; return $gen_liste_str ; } /* fin gen_combo_box_sugg */ public function gen_multiple_combo($liste_id=array()){ global $dbh, $msg,$charset; if(!$liste_id) return; $req = "select count(1) from docs_location"; $res = pmb_mysql_query($req,$dbh); $nb_loc = pmb_mysql_result($res,0,0); $req= "select idlocation, location_libelle from docs_location"; $res = pmb_mysql_query($req,$dbh); $selector_location=""; if(pmb_mysql_num_rows($res)){ $selector_location = ""; } return $selector_location; } public static function get_html_select($selected=array(),$sel_all=array('id'=>0,'msg'=>''),$sel_attr=array()) { global $dbh,$charset; $sel=''; $q = "select idlocation, location_libelle from docs_location order by location_libelle"; $r = pmb_mysql_query($q, $dbh); $res = array(); if (count($sel_all)) { $res[$sel_all['id']]=htmlentities($sel_all['msg'],ENT_QUOTES,$charset); } if (pmb_mysql_num_rows($r)) { while ($row = pmb_mysql_fetch_object($r)){ $res[$row->idlocation] = $row->location_libelle; } } $size=count($res); if (isset($sel_attr['size']) && $sel_attr['size']>$size) $sel_attr['size']=$size; if ($size) { $sel="