id = $id+0;
$this->getData();
}
// ---------------------------------------------------------------
// getData() : récupération infos
// ---------------------------------------------------------------
public function getData() {
global $dbh,$msg;
$this->name ="";
$this->comment="";
$this->tpl ="";
$this->piedpage="";
if($this->id) {
$requete = "SELECT * FROM serialcirc_tpl WHERE serialcirctpl_id='".$this->id."' LIMIT 1 ";
$result = @pmb_mysql_query($requete, $dbh);
if(pmb_mysql_num_rows($result)) {
$temp = pmb_mysql_fetch_object($result);
$this->name = $temp->serialcirctpl_name;
$this->comment = $temp->serialcirctpl_comment;
$this->tpl = $temp->serialcirctpl_tpl;
$this->piedpage = $temp->serialcirctpl_piedpage;
} else {
// pas trouvé avec cette clé
$this->id = 0;
}
}
}
// ---------------------------------------------------------------
// show_list : affichage de la liste des éléments
// ---------------------------------------------------------------
public function show_list($link="./edit.php") {
global $dbh, $charset,$msg;
global $serialcirc_tpl_liste, $serialcirc_tpl_liste_ligne;
$tableau = "";
$requete = "SELECT * FROM serialcirc_tpl ORDER BY serialcirctpl_name ";
$result = @pmb_mysql_query($requete, $dbh);
if(pmb_mysql_num_rows($result)) {
$pair="odd";
while(($temp = pmb_mysql_fetch_object($result))){
$id = $temp->serialcirctpl_id;
$name = $temp->serialcirctpl_name;
$comment = $temp->serialcirctpl_comment;
if($pair=="even") $pair ="odd"; else $pair ="even";
// contruction de la ligne
$ligne=$serialcirc_tpl_liste_ligne;
$ligne = str_replace("!!name!!", htmlentities($name,ENT_QUOTES, $charset), $ligne);
$ligne = str_replace("!!comment!!", htmlentities($comment,ENT_QUOTES, $charset), $ligne);
$ligne = str_replace("!!pair!!", $pair, $ligne);
$ligne = str_replace("!!link_edit!!", $link."?categ=tpl&sub=serialcirc&action=edit&id=$id", $ligne);
$ligne = str_replace("!!id!!", $id, $ligne);
$tableau.=$ligne;
}
}
$liste = str_replace("!!serialcirc_tpl_liste!!",$tableau, $serialcirc_tpl_liste);
$liste = str_replace("!!link_ajouter!!", $link."?categ=tpl&sub=serialcirc&action=edit", $liste);
return $liste;
}
// ---------------------------------------------------------------
// show_form : affichage du formulaire de saisie
// ---------------------------------------------------------------
public function show_form($link="./edit.php", $act="") {
global $msg;
global $serialcirc_tpl_form;
global $charset;
global $name, $comment;
$form=$serialcirc_tpl_form;
$action = $link."?categ=tpl&sub=serialcirc&action=update&id=!!id!!";
if($this->id) {
$libelle = $msg["serialcirc_tpl_modifier"];
$button_delete = "";
$action_delete = $link."?categ=tpl&sub=serialcirc&action=delete&id=!!id!!";
$button_duplicate = "id."';\" />";
} else {
$libelle = $msg["serialcirc_tpl_ajouter"];
$button_delete = "";
$button_duplicate = "";
$action_delete= "";
}
if ($this->duplicate_from_id) $fields =new serialcirc_tpl_print_fields($this->duplicate_from_id);
else $fields =new serialcirc_tpl_print_fields($this->id);
switch ($act) {
case "add_field" :
$this->name = $name;
$this->comment = $comment;
$this->piedpage = $piedpage;
$fields->add_field();
break;
case "del_field" :
$this->name = $name;
$this->comment = $comment;
$this->piedpage = $piedpage;
$fields->del_field();
break;
default :
break;
}
$select_field=$fields->get_select_form("select_field",0,"serialcirc_tpl_print_add_button();");
$format_serialcirc = $select_field;
$fields_options="";
$form=str_replace('!!fields_options!!', $fields_options, $form);
$form=str_replace('!!pied_page!!', $this->piedpage, $form);
$form = str_replace("!!libelle!!", $libelle, $form);
$form = str_replace("!!name!!", htmlentities($this->name,ENT_QUOTES, $charset), $form);
$form = str_replace("!!comment!!", htmlentities($this->comment,ENT_QUOTES, $charset), $form);
$form = str_replace("!!format_serialcirc!!", $format_serialcirc, $form);
$form = str_replace("!!action!!", $action, $form);
$form = str_replace("!!duplicate!!", $button_duplicate, $form);
$form = str_replace("!!delete!!", $button_delete, $form);
$form = str_replace("!!action_delete!!",$action_delete, $form);
$form = str_replace("!!id!!", $this->id, $form);
$form = str_replace("!!order_tpl!!", implode(",",array_keys($fields->circ_tpl)), $form);
return $form;
}
// ---------------------------------------------------------------
// delete() : suppression
// ---------------------------------------------------------------
public function delete() {
global $dbh;
global $msg;
if(!$this->id) return $msg[403];
$total = 0;
$total = pmb_mysql_result(pmb_mysql_query("select count(1) from serialcirc where serialcirc_tpl ='".$this->id."' ", $dbh), 0, 0);
if ($total==0) {
// effacement dans la table
$requete = "DELETE FROM serialcirc_tpl WHERE serialcirctpl_id='".$this->id."' ";
pmb_mysql_query($requete, $dbh);
} else {
error_message( $msg["edit_tpl_serialcirc_delete"], $msg["edit_tpl_serialcirc_delete_forbidden"], 1, 'edit.php?categ=tpl&sub=serialcirc&action=');
}
return false;
}
// ---------------------------------------------------------------
// update($value) : mise à jour
// ---------------------------------------------------------------
public function update($value) {
global $dbh;
global $msg;
global $include_path;
// nettoyage des chaînes en entrée
$value['name'] = addslashes(clean_string($value['name']));
$value['comment'] = addslashes($value['comment']);
$value['piedpage'] = addslashes($value['piedpage']);
if(!$value['name']) return false;
$requete = "SET ";
$requete .= "serialcirctpl_name='".$value["name"]."', ";
$requete .= "serialcirctpl_comment='".$value["comment"]."', ";
$requete .= "serialcirctpl_piedpage='".$value["piedpage"]."' ";
if($this->id) {
// update
$requete = "UPDATE serialcirc_tpl $requete WHERE serialcirctpl_id=".$this->id." ";
if(!pmb_mysql_query($requete, $dbh)) {
require_once("$include_path/user_error.inc.php");
warning($msg["serialcirc_tpl_modifier"], $msg["serialcirc_tpl_modifier_erreur"]);
return false;
} else {
// on enregistre les champs
$fields =new serialcirc_tpl_print_fields($this->id);
$fields->save_form();
}
} else {
// creation
$requete = "INSERT INTO serialcirc_tpl ".$requete;
if(pmb_mysql_query($requete, $dbh)) {
$this->id=pmb_mysql_insert_id();
// on enregistre les champs
$fields =new serialcirc_tpl_print_fields($this->id);
$fields->save_form();
} else {
require_once("$include_path/user_error.inc.php");
warning($msg["serialcirc_tpl_ajouter"], $msg["serialcirc_tpl_ajouter_erreur"]);
return false;
}
}
return true;
}
public function update_from_form() {
global $name, $comment, $piedpage;
$value['name']=stripslashes($name);
$value['comment']=stripslashes($comment);
$value['piedpage']=stripslashes($piedpage);
$this->update($value);
}
public static function gen_tpl_select($select_name="form_serialcirc_tpl", $selected_id=0, $onchange="") {
global $msg;
$requete = "SELECT serialcirctpl_id, concat(serialcirctpl_name,'. ',serialcirctpl_comment) as nom FROM serialcirc_tpl ORDER BY serialcirctpl_name ";
return gen_liste ($requete, "serialcirctpl_id", "nom", $select_name, $onchange, $selected_id, 0, $msg["serialcirc_tpl_list_default"], 0,$msg["serialcirc_tpl_list_default"], 0) ;
}
} // fin class