id = $id+0; $this->getData(); } /* --------------------------------------------------------------- getData() : récupération des propriétés --------------------------------------------------------------- */ public function getData() { global $dbh, $msg; global $opac_url_base; if(!$this->id) return; /* récupération des informations du statut */ $requete = "SELECT * FROM docs_location WHERE idlocation='".$this->id."'"; $result = @pmb_mysql_query($requete, $dbh); if(!pmb_mysql_num_rows($result)) return; $data = pmb_mysql_fetch_object($result); $this->id = $data->idlocation; $this->libelle = $data->location_libelle; $this->locdoc_codage_import = $data->locdoc_codage_import; $this->locdoc_owner = $data->locdoc_owner; $this->num_infopage = $data->num_infopage; if ($this->num_infopage) { $this->url_infopage="num_infopage."\" title=\"".$msg['location_more_info']."\">".htmlentities($this->libelle, ENT_QUOTES, $charset).""; } $this->email = $data->email; } // --------------------------------------------------------------- // 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(!sizeof($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 */ /* 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 where location_visible_opac=1 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 function gen_combo_box_sugg ( $selected, $afficher_premier=1, $on_change="" ) { global $msg; $requete="select idlocation, location_libelle from docs_location where location_visible_opac=1 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 */ } /* fin de définition de la classe */ } /* fin de délaration */