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 du code statistique */
$requete = 'SELECT * FROM docs_codestat WHERE idcode='.$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->id = $data->idcode;
$this->libelle = $data->codestat_libelle;
$this->statisdoc_codage_import = $data->statisdoc_codage_import;
$this->statisdoc_owner = $data->statisdoc_owner;
}
public function get_form() {
global $admin_codstat_content_form, $msg, $charset;
$content_form = $admin_codstat_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['101']);
}else{
$interface_form->set_label($msg['102']);
}
$content_form = str_replace('!!libelle!!', htmlentities($this->libelle, ENT_QUOTES, $charset), $content_form);
$content_form = str_replace('!!statisdoc_codage_import!!', $this->statisdoc_codage_import, $content_form);
$combo_lender= gen_liste ("select idlender, lender_libelle from lenders order by lender_libelle ", "idlender", "lender_libelle", "form_statisdoc_owner", "", $this->statisdoc_owner, 0, $msg[556],0,$msg["proprio_generique_biblio"]) ;
$content_form = str_replace('!!lender!!', $combo_lender, $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_codestat')
->set_field_focus('form_libelle');
return $interface_form->get_display();
}
public function set_properties_from_form() {
global $form_libelle, $form_statisdoc_codage_import, $form_statisdoc_owner;
$this->libelle = stripslashes($form_libelle);
$this->statisdoc_codage_import = stripslashes($form_statisdoc_codage_import);
$this->statisdoc_owner = intval($form_statisdoc_owner);
}
public function get_query_if_exists() {
return " SELECT count(1) FROM docs_codestat WHERE (codestat_libelle='".addslashes($this->libelle)."' AND idcode!='".$this->id."' )";
}
public function save() {
// O.K. if item already exists UPDATE else INSERT
if($this->id) {
$requete = "UPDATE docs_codestat SET codestat_libelle='".addslashes($this->libelle)."', statisdoc_codage_import='".addslashes($this->statisdoc_codage_import)."', statisdoc_owner='".$this->statisdoc_owner."' WHERE idcode=".$this->id;
pmb_mysql_query($requete);
} else {
$requete = "INSERT INTO docs_codestat (idcode,codestat_libelle,statisdoc_codage_import,statisdoc_owner) VALUES ('', '".addslashes($this->libelle)."','".addslashes($this->statisdoc_codage_import)."','".$this->statisdoc_owner."') ";
pmb_mysql_query($requete);
$this->id = pmb_mysql_insert_id();
}
$translation = new translation($this->id, "docs_codestat");
$translation->update("codestat_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 code statistique de document
// ---------------------------------------------------------------
public static function import($data) {
// cette méthode prend en entrée un tableau constitué des informations suivantes :
// $data['codestat_libelle']
// $data['statisdoc_codage_import']
// $data['statisdoc_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 codestat_libelle FROM docs_codestat limit 1"),0);
$data['codestat_libelle'] = rtrim(substr(preg_replace('/\[|\]/', '', rtrim(ltrim($data['codestat_libelle']))),0,$long_maxi));
$long_maxi = pmb_mysql_field_len(pmb_mysql_query("SELECT statisdoc_codage_import FROM docs_codestat limit 1"),0);
$data['statisdoc_codage_import'] = rtrim(substr(preg_replace('/\[|\]/', '', rtrim(ltrim($data['statisdoc_codage_import']))),0,$long_maxi));
if($data['statisdoc_owner']=="") $data['statisdoc_owner'] = 0;
if($data['codestat_libelle']=="") return 0;
/* statisdoc_codage_import est obligatoire si statisdoc_owner != 0 */
// commenté depuis le choix de quel codage rec995 on récupère if(($data['statisdoc_owner']!=0) && ($data['statisdoc_codage_import']=="")) return 0;
// préparation de la requête
$key0 = addslashes($data['codestat_libelle']);
$key1 = addslashes($data['statisdoc_codage_import']);
$key2 = $data['statisdoc_owner'];
/* vérification que le code statistique existe */
$query = "SELECT idcode FROM docs_codestat WHERE statisdoc_codage_import='${key1}' and statisdoc_owner = '${key2}' LIMIT 1 ";
$result = @pmb_mysql_query($query, $dbh);
if(!$result) die("can't SELECT docs_codestat ".$query);
$docs_codestat = pmb_mysql_fetch_object($result);
/* le code statistique de doc existe, on retourne l'ID */
if($docs_codestat->idcode) return $docs_codestat->idcode;
// id non-récupérée, il faut créer la forme.
$query = "INSERT INTO docs_codestat SET ";
$query .= "codestat_libelle='".$key0."', ";
$query .= "statisdoc_codage_import='".$key1."', ";
$query .= "statisdoc_owner='".$key2."' ";
$result = @pmb_mysql_query($query, $dbh);
if(!$result) die("can't INSERT into docs_codestat ".$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) {
$total = pmb_mysql_result(pmb_mysql_query("select count(1) from exemplaires where expl_codestat ='".$id."' "), 0, 0);
if ($total==0) {
translation::delete($id, "docs_codestat");
$requete = "DELETE FROM docs_codestat WHERE idcode=$id ";
pmb_mysql_query($requete);
return true;
} else {
$msg_suppr_err = $admin_liste_jscript;
$msg_suppr_err .= $msg[1701]." " ;
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 idcode, codestat_libelle from docs_codestat order by codestat_libelle ";
$champ_code="idcode";
$champ_info="codestat_libelle";
$nom="book_codestat_id";
$on_change="";
$liste_vide_code="0";
$liste_vide_info=$msg['class_codestat'];
$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_codestat', 'codestat_libelle', $this->libelle);
}
} /* fin de définition de la classe */
} /* fin de délaration */