id = intval($id); $this->getData(); } // --------------------------------------------------------------- // getData() : récupération infos // --------------------------------------------------------------- public function getData() { global $msg; $this->name = ''; $this->comment = ''; $this->id_test = ''; $this->code=array(); $this->code[0]=array(); $req_loc="select idlocation,location_libelle from docs_location"; $res_loc=pmb_mysql_query($req_loc); $this->location_label[0]=$msg["all_location"]; if (pmb_mysql_num_rows($res_loc)) { while (($r=pmb_mysql_fetch_object($res_loc))) { $this->code[$r->idlocation]=array(); $this->location_label[$r->idlocation]=$r->location_libelle; } } $source = marc_list_collection::get_instance("doctype"); $source_tab = $source->table; $type_doc=array(); $type_doc[0]=""; $this->type_doc_label[0]=$msg["tous_types_docs"]; foreach($source_tab as $key=>$libelle) { $type_doc[$key]=""; $this->type_doc_label[$key]=$libelle; } foreach($this->code as $key =>$val) { $this->code[$key]["0"]=$type_doc; $this->code[$key]["m"]=$type_doc; $this->code[$key]["a"]=$type_doc; $this->code[$key]["s"]=$type_doc; $this->code[$key]["b"]=$type_doc; } $this->type_notice["0"]=$msg["notice_tpl_notice_all"]; $this->type_notice["m"]=$msg["notice_tpl_notice_monographie"]; $this->type_notice["a"]=$msg["notice_tpl_notice_article"]; $this->type_notice["s"]=$msg["notice_tpl_notice_periodique"]; $this->type_notice["b"]=$msg["notice_tpl_notice_bulletin"]; if($this->id) { $requete = "SELECT * FROM notice_tpl WHERE notpl_id='".$this->id."' LIMIT 1 "; $result = @pmb_mysql_query($requete); if(pmb_mysql_num_rows($result)) { $temp = pmb_mysql_fetch_object($result); $this->name = $temp->notpl_name; $this->comment = $temp->notpl_comment; $this->show_opac = $temp->notpl_show_opac; $this->id_test = $temp->notpl_id_test; $requete = "SELECT * FROM notice_tplcode WHERE num_notpl='".$this->id."' "; $result_code = @pmb_mysql_query($requete); if(pmb_mysql_num_rows($result_code)) { while(($temp_code= pmb_mysql_fetch_object($result_code))) { $this->code[$temp_code->notplcode_localisation][$temp_code->notplcode_niveau_biblio] [$temp_code->notplcode_typdoc]=$temp_code->nottplcode_code; } } } else { // pas trouvé avec cette clé $this->id = 0; } } } // ---------------------------------------------------------------------------------- // get_is_truncated_form : affichage du formulaire avec les localisations ou non // ---------------------------------------------------------------------------------- public function get_is_truncated_form() { $is_truncated_form = true; if($this->id) { //En modif, on vérifie si un template dans une loc if (count($this->code)>1) { foreach ($this->code as $id_location =>$tab_typenotice) { //on passe la loc "0" (toutes les locs) if (!$id_location) { continue; } foreach($tab_typenotice as $typenotice =>$tab_typedoc) { foreach($tab_typedoc as $typedoc=>$code) { if ($code) { $is_truncated_form = false; return $is_truncated_form; } } } } } } return $is_truncated_form; } // --------------------------------------------------------------- // show_form : affichage du formulaire de saisie // --------------------------------------------------------------- public function get_form() { global $msg; global $notice_tpl_content_form, $notice_tpl_show_loc_btn; global $charset; $content_form = $notice_tpl_content_form; $content_form = str_replace('!!id!!', $this->id, $content_form); $interface_form = new interface_form('notice_tpl_form'); if(!$this->id){ $interface_form->set_label($msg['notice_tpl_ajouter']); }else{ $interface_form->set_label($msg['notice_tpl_modifier']); } //on n'affiche les localisations que si un template existe dans une des locs $is_truncated_form = $this->get_is_truncated_form(); $form_code = ''; if ($is_truncated_form) { $form_typenotice_all = $this->get_form_typenotice_all(0, $this->code[0]); $form_code.=gen_plus("plus_location0",$this->location_label[0],$form_typenotice_all); } else { foreach($this->code as $id_location =>$tab_typenotice) { $form_typenotice_all = $this->get_form_typenotice_all($id_location, $tab_typenotice); $form_code.=gen_plus("plus_location".$id_location,$this->location_label[$id_location],$form_typenotice_all); } } $content_form = str_replace("!!name!!", htmlentities($this->name,ENT_QUOTES, $charset), $content_form); $content_form = str_replace("!!comment!!", htmlentities($this->comment,ENT_QUOTES, $charset), $content_form); $content_form = str_replace("!!id_test!!", htmlentities($this->id_test,ENT_QUOTES, $charset), $content_form); $content_form = str_replace("!!show_opac!!",($this->show_opac ? " checked='checked' " : ""), $content_form); $content_form = str_replace("!!code_part!!", $form_code, $content_form); if ($is_truncated_form) { $content_form = str_replace("!!show_loc!!", $notice_tpl_show_loc_btn, $content_form); } else { $content_form = str_replace("!!show_loc!!", "", $content_form); } $interface_form->set_object_id($this->id) ->set_duplicable(true) ->set_confirm_delete_msg($msg['confirm_suppr_de']." ".$this->name." ?") ->set_content_form($content_form) ->set_table_name('notice_tpl') ->set_field_focus('name'); return $interface_form->get_display(); } // --------------------------------------------------------------------- // get_form_typenotice_all : récupère l'affichage des localisations // --------------------------------------------------------------------- public function get_form_typenotice_all_loc() { $form_typenotice_all_loc = ''; foreach($this->code as $id_location =>$tab_typenotice) { if (!$id_location) { continue; } $line = $this->get_form_typenotice_all($id_location, $tab_typenotice); $form_typenotice_all_loc.=gen_plus("plus_location".$id_location,$this->location_label[$id_location],$line); } return $form_typenotice_all_loc; } // ---------------------------------------------------------------------- // get_form_typenotice_all : récupère l'affichage d'une localisation // ---------------------------------------------------------------------- public function get_form_typenotice_all($id_location, $tab_typenotice) { global $charset; global $notice_tpl_form_code; $form_typenotice_all=''; foreach($tab_typenotice as $typenotice =>$tab_typedoc) { $form_code_typedoc=''; foreach($tab_typedoc as $typedoc=>$code) { $form_code_temp = str_replace("!!loc!!", $id_location, $notice_tpl_form_code); $form_code_temp = str_replace("!!typenotice!!", $typenotice, $form_code_temp); $form_code_temp = str_replace("!!typedoc!!", $typedoc, $form_code_temp); $form_code_temp = str_replace("!!code!!", htmlentities($code,ENT_QUOTES, $charset), $form_code_temp); $form_code_typedoc.= gen_plus("plus_typedoc".$id_location."_".$typenotice."_".$typedoc,$this->type_doc_label["$typedoc"],$form_code_temp); if ($code != "") { $form_code_typedoc.= ""; } } $form_typenotice_all.= gen_plus("plus_typenotice".$id_location."_".$typenotice."_",$this->type_notice["$typenotice"],$form_code_typedoc); } return $form_typenotice_all; } public function set_properties_from_form() { global $name, $code_list, $comment,$id_test,$show_opac; $this->name = clean_string(stripslashes($name)); $this->comment = stripslashes($comment); $this->id_test = stripslashes($id_test); $this->show_opac = stripslashes($show_opac); $this->code=array(); $this->code[0]=array(); if(!empty($code_list)) { foreach($code_list as $input_code) { $code=""; eval("global \$".$input_code.";\$code= $".$input_code.";"); if($code) { list($label,$location,$type_notice,$type_doc)=explode("_",$input_code); $this->code["$location"]["$type_notice"]["$type_doc"]=stripslashes($code); } } } } public function save() { global $msg; global $include_path; if(!$this->name) return false; $requete = "SET "; $requete .= "notpl_name='".addslashes($this->name)."', "; $requete .= "notpl_id_test='".$this->id_test."', "; $requete .= "notpl_comment='".addslashes($this->comment)."', "; $requete .= "notpl_show_opac='".$this->show_opac."' "; if($this->id) { // update $requete = "UPDATE notice_tpl $requete WHERE notpl_id=".$this->id." "; if(!pmb_mysql_query($requete)) { require_once("$include_path/user_error.inc.php"); warning($msg["notice_tpl_modifier"], $msg["notice_tpl_modifier_erreur"]); return false; } } else { // creation $requete = "INSERT INTO notice_tpl ".$requete; if(pmb_mysql_query($requete)) { $this->id=pmb_mysql_insert_id(); } else { require_once("$include_path/user_error.inc.php"); warning($msg["notice_tpl_ajouter"], $msg["notice_tpl_ajouter_erreur"]); return false; } } // insertion du code $requete = "DELETE FROM notice_tplcode WHERE num_notpl='".$this->id."' "; pmb_mysql_query($requete); if(!empty($this->code)) { foreach($this->code as $id_location =>$tab_typenotice) { foreach($tab_typenotice as $typenotice =>$tab_typedoc) { foreach($tab_typedoc as $typedoc=>$code) { $requete = "INSERT INTO notice_tplcode SET num_notpl='".$this->id."', notplcode_localisation='$id_location', notplcode_typdoc='$typedoc', notplcode_niveau_biblio='$typenotice', nottplcode_code='". addslashes($code)."' "; if(!pmb_mysql_query($requete)) { require_once("$include_path/user_error.inc.php"); warning($msg["notice_tpl_ajouter"], $msg["notice_tpl_ajouter_erreur"]); return false; } } } } } return true; } // --------------------------------------------------------------- // delete() : suppression // --------------------------------------------------------------- public static function delete($id) { global $msg; $id = intval($id); if(!$id) { pmb_error::get_instance(static::class)->add_message("", $msg[403]); return false; } // effacement dans la table $requete = "DELETE FROM notice_tpl WHERE notpl_id='".$id."' "; pmb_mysql_query($requete); $requete = "DELETE FROM notice_tplcode WHERE num_notpl='".$id."' "; pmb_mysql_query($requete); return true; } public function get_id() { return $this->id; } static public function gen_tpl_select($select_name="notice_tpl", $selected_id=0) { global $msg; $requete = "SELECT notpl_id, concat(notpl_name,'. ',notpl_comment) as nom FROM notice_tpl ORDER BY notpl_name "; $onchange=""; return gen_liste ($requete, "notpl_id", "nom", $select_name, $onchange, $selected_id, 0, $msg["notice_tpl_list_default"], 0,$msg["notice_tpl_list_default"], 0) ; } static public function get_list() { $list = array(); $query = "SELECT notpl_id, if(notpl_comment!='',concat(notpl_name,'. ',notpl_comment),notpl_name) as nom FROM notice_tpl ORDER BY notpl_name "; $result = pmb_mysql_query($query); if (pmb_mysql_num_rows($result)) { while($row = pmb_mysql_fetch_object($result)) { $list[$row->notpl_id] = $row->nom; } } return $list; } public function show_eval($notice_id=0) { global $notice_tpl_eval; global $deflt2docs_location; if(!$notice_id)$notice_id=$this->id_test; $notice_tpl_gen = notice_tpl_gen::get_instance($this->id); $tpl= $notice_tpl_gen->build_notice($notice_id,$deflt2docs_location); $form = str_replace("!!tpl!!", $tpl, $notice_tpl_eval); return $form; } public function show_import_form($link="./edit.php") { global $notice_tpl_form_import; $form=$notice_tpl_form_import; $action = $link."?categ=tpl&sub=notice&action=import_suite"; $form = str_replace("!!action!!", $action, $form); return $form; } public function do_import(){ global $msg, $charset; $erreur=0; $userfile_name = $_FILES['f_fichier']['name']; $userfile_temp = $_FILES['f_fichier']['tmp_name']; $userfile_moved = basename($userfile_temp); $userfile_name = preg_replace("/ |'|\\|\"|\//m", "_", $userfile_name); // création if (move_uploaded_file($userfile_temp,'./temp/'.$userfile_moved)) { $fic=1; } if (!$fic) { $erreur=$erreur+10; }else{ $fp = fopen('./temp/'.$userfile_moved , "r" ); $contenu = fread ($fp, filesize('./temp/'.$userfile_moved)); if (!$fp || $contenu=="") $erreur=$erreur+100; ; fclose ($fp) ; } //récupération et affectation des lignes $input_main_tmp=''; $input_sub_tmp=''; $input_locations_tmp=''; $input_charset_tmp=''; $input_cours=''; $tmpLignes=explode("\n",$contenu); foreach ($tmpLignes as $ligne){ if (preg_match('`^\#main\#=(.+)`',$ligne,$out)) { $cours='input_main'; $input_main_tmp=$out[1]; } elseif (preg_match('`^\#sub\#=(.+)`',$ligne,$out)) { $cours='input_sub'; $input_sub_tmp=$out[1]; } elseif (preg_match('`^\#locations\#=(.+)`',$ligne,$out)) { $cours='input_locations'; $input_locations_tmp=$out[1]; } elseif (preg_match('`^\#charset\#=(.+)`',$ligne,$out)) { $cours='input_charset'; $input_charset_tmp=$out[1]; } else { switch ($cours) { case 'input_main' : $input_main_tmp.="\n".$ligne; break; case 'input_sub' : $input_sub_tmp.="\n".$ligne; break; case 'input_locations' : $input_locations_tmp.="\n".$ligne; break; case 'input_charset' : $input_charset_tmp.="\n".$ligne; break; default : $erreur=5; break; } } } //on recrée les données $input_main=unserialize($input_main_tmp); $input_sub=unserialize($input_sub_tmp); $input_locations_tmp=unserialize($input_locations_tmp); $input_locations=array(); if(is_array($input_locations_tmp) && count($input_locations_tmp)){ foreach($input_locations_tmp as $value){ $input_locations[$value["id_location"]]=$value["lib_location"]; } } $input_charset=$input_charset_tmp; //on vérifie if(!count($input_main)||!count($input_sub)||!trim($input_charset)){ $erreur=5; } if(!$erreur){ //valeurs à connaitre $doctype = marc_list_collection::get_instance('doctype'); $locations = array(); $res=pmb_mysql_query("SELECT idlocation, location_libelle FROM docs_location ORDER BY 1"); while($row=pmb_mysql_fetch_object($res)){ $locations[$row->idlocation]=$row->location_libelle; } //gestion de l'encodage fichier/PMB $fonction_convert=""; if($input_charset=='iso-8859-1' && $charset=='utf-8'){ $input_main=pmb_utf8_encode($input_main); $input_sub=pmb_utf8_encode($input_sub); $input_locations=pmb_utf8_encode($input_locations); }elseif($input_charset=='utf-8' && $charset=='iso-8859-1'){ $input_main=pmb_utf8_decode($input_main); $input_sub=pmb_utf8_decode($input_sub); $input_locations=pmb_utf8_decode($input_locations); } //Ajout dans notice_tpl $requete="INSERT INTO notice_tpl SET "; foreach($input_main as $key=>$value){ if($key){ $requete.=", "; } $requete.=$value["field"]."='".addslashes($value["value"])."'"; } pmb_mysql_query($requete); $id_tpl = pmb_mysql_insert_id(); if ($id_tpl) { //Ajouts dans notice_tpl_code $array_errors=array(); foreach($input_sub as $sub){ $ok_import=true; $array_error_row=array(); if(isset($id_loc_cours)){ unset($id_loc_cours); } if(isset($typdoc_cours)){ unset($typdoc_cours); } //création requête $requete="INSERT INTO notice_tplcode SET num_notpl=".$id_tpl; foreach($sub as $value){ $requete.=", ".$value["field"]."='".addslashes($value["value"])."'"; if($value["field"]=="notplcode_localisation"){ $id_loc_cours=$value["value"]; } if($value["field"]=="notplcode_typdoc"){ $typdoc_cours=$value["value"]; } if($value["field"]=="nottplcode_code"){ $array_error_row["tpl_code"]=$value["value"]; } } $array_error_row["typdoc"]=$typdoc_cours; $array_error_row["location"]=$input_locations[$id_loc_cours]." (".$id_loc_cours.")"; //vérification localisation et type de document if(!isset($id_loc_cours)||!isset($typdoc_cours)){ $ok_import=false; $array_error_row["error"]=$msg["notice_tpl_import_error_missing_info"]; }elseif(($id_loc_cours) || ($typdoc_cours)){ if($id_loc_cours){ if(!isset($locations[$id_loc_cours])||($locations[$id_loc_cours]!=$input_locations[$id_loc_cours])){ $array_error_row["error"]=$msg["notice_tpl_import_error_missing_location"]; $ok_import=false; } } if($typdoc_cours){ if(!isset($doctype->table[$typdoc_cours])){ $array_error_row["error"]=$msg["notice_tpl_import_error_missing_typdoc"]; $ok_import=false; } } } //ajout requête if($ok_import){ pmb_mysql_query($requete); }else{ $array_errors[]=$array_error_row; } } //Affichage des templates en erreur if(count($array_errors)){ print "

".$msg['notice_tpl_import_invalide']."

"; foreach($array_errors as $error){ echo "".$msg["notice_tpl_import_error_error"]." : ".$error["error"]."
"; echo "".$msg["notice_tpl_import_error_typdoc"]." : ".$error["typdoc"]."
"; echo "".$msg["notice_tpl_import_error_location"]." : ".$error["location"]."
"; echo "".$msg["notice_tpl_import_error_tplcode"]." :
".nl2br(htmlentities($error["tpl_code"]))."
"; echo "

"; } } print "
"; if(!count($array_errors)){ print ""; } } else { print "

".$msg['notice_tpl_import_invalide']."

Error code = 7"; print $this->show_import_form(); } } else { print "

".$msg['notice_tpl_import_invalide']."

Error code = $erreur"; print $this->show_import_form(); } print ""; //On efface le fichier temporaire if ($userfile_name) { unlink('./temp/'.$userfile_moved); } } /** * Retourne tous les répertoires de templates de notices * @param string $selected * @return string */ public static function get_directories_options($selected = '') { global $msg,$opac_notices_format_django_directory; if (!$selected) { $selected = $opac_notices_format_django_directory; } if (!$selected) { $selected = 'common'; } $dirs = array_filter(glob('./opac_css/includes/templates/record/*'), 'is_dir'); $tpl = ""; foreach($dirs as $dir){ if(basename($dir) != "CVS"){ $tpl.= ""; } } return $tpl; } } // fin class