id = $id+0; $this->getData(); } /* --------------------------------------------------------------- getData() : récupération des propriétés --------------------------------------------------------------- */ public function getData() { global $dbh; if(!$this->id) return; /* récupération des informations de la catégorie */ $requete = 'SELECT * FROM docs_type WHERE idtyp_doc='.$this->id.' LIMIT 1;'; $result = pmb_mysql_query($requete, $dbh) or die (pmb_mysql_error()." ".$requete); 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->id = $data->idtyp_doc; $this->libelle = $data->tdoc_libelle; $this->duree_pret = $data->duree_pret; $this->duree_resa = $data->duree_resa; $this->tdoc_codage_import = $data->tdoc_codage_import; $this->tdoc_owner = $data->tdoc_owner; $this->tarif_pret = $data->tarif_pret; $this->short_loan_duration = $data->short_loan_duration; } public function get_form() { global $admin_typdoc_content_form, $msg, $charset; global $pmb_quotas_avances, $pmb_short_loan_management; global $pmb_gestion_financiere, $pmb_gestion_tarif_prets; $content_form = $admin_typdoc_content_form; $content_form = str_replace('!!id!!', $this->id, $content_form); $interface_form = new interface_admin_form('typdocform'); if(!$this->id){ $interface_form->set_label($msg['122']); }else{ $interface_form->set_label($msg['124']); } $content_form = str_replace('!!libelle!!', htmlentities($this->libelle, ENT_QUOTES, $charset), $content_form); $form_pret=''; if (!$pmb_quotas_avances) { $form_pret = "
"; } $content_form = str_replace('', $form_pret, $content_form); $form_short_loan_duration=''; if (!$pmb_quotas_avances && $pmb_short_loan_management) { $form_short_loan_duration = "
"; } $content_form = str_replace('', $form_short_loan_duration, $content_form); $form_resa=''; if (!$pmb_quotas_avances) { $form_resa = "
"; } $content_form = str_replace('', $form_resa, $content_form); $content_form = str_replace('!!tdoc_codage_import!!', $this->tdoc_codage_import, $content_form); $combo_lender= gen_liste ("select idlender, lender_libelle from lenders order by lender_libelle ", "idlender", "lender_libelle", "form_tdoc_owner", "", $this->tdoc_owner, 0, $msg[556],0,$msg["proprio_generique_biblio"]); $content_form = str_replace('', $combo_lender, $content_form); $tarif_pret=''; if (($pmb_gestion_financiere)&&($pmb_gestion_tarif_prets==1)) { $tarif_pret="
"; } $content_form = str_replace('', $tarif_pret, $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_type') ->set_field_focus('form_libelle'); return $interface_form->get_display(); } public function set_properties_from_form() { global $form_libelle, $form_pret, $form_resa, $form_short_loan_duration, $form_tarif_pret, $form_tdoc_codage_import, $form_tdoc_owner; $this->libelle = stripslashes($form_libelle); $this->duree_pret = intval($form_pret); $this->duree_resa = intval($form_resa); $this->tdoc_owner = intval($form_tdoc_owner); $this->tdoc_codage_import = stripslashes($form_tdoc_codage_import); $this->tarif_pret = stripslashes($form_tarif_pret); $this->short_loan_duration = intval($form_short_loan_duration); } public function get_query_if_exists() { return "SELECT count(1) FROM docs_type WHERE (tdoc_libelle='".addslashes($this->libelle)."' AND idtyp_doc!='".$this->id."' )"; } public function save() { global $pmb_quotas_avances, $pmb_gestion_financiere, $pmb_gestion_tarif_prets, $pmb_short_loan_management; // O.k., now if the id already exist UPDATE else INSERT $q =(($this->id)?"update ":"insert into "); $q.= "docs_type set tdoc_libelle='".addslashes($this->libelle)."', "; $q.= ((!$pmb_quotas_avances)?"duree_pret='".$this->duree_pret."', duree_resa='".$this->duree_resa."', ":''); $q.= ((!$pmb_quotas_avances && $pmb_short_loan_management)?"short_loan_duration='".$this->short_loan_duration."', ":''); $q.= (($pmb_gestion_financiere && $pmb_gestion_tarif_prets==1)?"tarif_pret='".addslashes($this->tarif_pret)."', ":''); $q.= "tdoc_codage_import='".addslashes($this->tdoc_codage_import)."', tdoc_owner='".$this->tdoc_owner."' "; $q.= (($this->id)?"where idtyp_doc=".$this->id." ":''); pmb_mysql_query($q); if(!$this->id) { $this->id = pmb_mysql_insert_id(); } $translation = new translation($this->id, "docs_type"); $translation->update("tdoc_libelle", "form_libelle"); return true; } public static function check_data_from_form() { global $form_libelle; if(empty($form_libelle)) { return false; } return true; } // --------------------------------------------------------------- // import() : import d'un type de document // --------------------------------------------------------------- public static function import($data) { // cette méthode prend en entrée un tableau constitué des informations suivantes : // $data['tdoc_libelle'] // $data['duree_pret'] // $data['tdoc_codage_import'] // $data['tdoc_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 tdoc_libelle FROM docs_type limit 1"),0); $data['tdoc_libelle'] = rtrim(substr(preg_replace('/\[|\]/', '', rtrim(ltrim($data['tdoc_libelle']))),0,$long_maxi)); $long_maxi = pmb_mysql_field_len(pmb_mysql_query("SELECT tdoc_codage_import FROM docs_type limit 1"),0); $data['tdoc_codage_import'] = rtrim(substr(preg_replace('/\[|\]/', '', rtrim(ltrim($data['tdoc_codage_import']))),0,$long_maxi)); if($data['tdoc_owner']=="") $data['tdoc_owner'] = 0; if($data['tdoc_libelle']=="") return 0; /* tdoc_codage_import est obligatoire si tdoc_owner != 0 */ //if(($data['tdoc_owner']!=0) && ($data['tdoc_codage_import']=="")) return 0; // préparation de la requête $key0 = addslashes($data['tdoc_libelle']); $key1 = addslashes($data['tdoc_codage_import']); $key2 = $data['tdoc_owner']; /* vérification que le type doc existe */ $query = "SELECT idtyp_doc FROM docs_type WHERE tdoc_codage_import='${key1}' and tdoc_owner = '${key2}' LIMIT 1 "; $result = @pmb_mysql_query($query, $dbh); if(!$result) die("can't SELECT docs_type ".$query); $docs_type = pmb_mysql_fetch_object($result); /* le type de doc existe, on retourne l'ID */ if($docs_type->idtyp_doc) return $docs_type->idtyp_doc; // id non-récupérée, il faut créer la forme. /* une petite valeur par défaut */ if ($data['duree_pret']=="") $data['duree_pret']=0; $query = "INSERT INTO docs_type SET "; $query .= "tdoc_libelle='".$key0."', "; $query .= "duree_pret='".$data['duree_pret']."', "; $query .= "tdoc_codage_import='".$key1."', "; $query .= "tdoc_owner='".$key2."' "; $result = @pmb_mysql_query($query, $dbh); if(!$result) die("can't INSERT into docs_type ".$query); return pmb_mysql_insert_id($dbh); } /* fin méthode import */ public static function delete($id) { global $msg, $admin_liste_jscript; $id = intval($id); if($id) { // requête sur 'exemplaires' pour voir si ce typdoc est encore utilisé $total = 0; $total = pmb_mysql_result(pmb_mysql_query("select count(1) from exemplaires where expl_typdoc ='".$id."' "), 0, 0); if ($total==0) { translation::delete($id, "docs_type"); $q = "DELETE FROM docs_type WHERE idtyp_doc=$id "; pmb_mysql_query($q); return true; } else { $msg_suppr_err = $admin_liste_jscript; $msg_suppr_err .= $msg[1700]." " ; 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 ) { global $msg; $requete="select idtyp_doc, tdoc_libelle from docs_type order by tdoc_libelle "; $champ_code="idtyp_doc"; $champ_info="tdoc_libelle"; $nom="book_doctype_id"; $on_change=""; $liste_vide_code="0"; $liste_vide_info=$msg['class_typdoc']; $option_premier_code=""; $option_premier_info=""; $gen_liste_str=""; $resultat_liste=pmb_mysql_query($requete) or die (pmb_mysql_error()." ".$requete); $gen_liste_str = "\n" ; return $gen_liste_str ; } /* fin gen_combo_box */ public function get_translated_libelle() { return translation::get_translated_text($this->id, 'docs_type', 'tdoc_libelle', $this->libelle); } } /* fin de définition de la classe */ } /* fin de délaration */