id_bannette = $id;
$this->getData();
} else {
// la notice n'existe pas
$this->id_bannette = 0;
$this->getData();
}
}
// ---------------------------------------------------------------
// getData() : récupération infos
// ---------------------------------------------------------------
function getData() {
global $dbh;
global $msg;
$this->p_perso=new parametres_perso("notices");
if (!$this->id_bannette) {
// pas d'identifiant. on retourne un tableau vide
$this->id_bannette=0;
$this->num_classement = 1 ;
$this->nom_classement = "" ;
$this->nom_bannette="";
$this->comment_gestion="";
$this->comment_public="";
$this->entete_mail="";
$this->piedpage_mail="";
$this->notice_tpl="";
$this->date_last_remplissage="";
$this->date_last_envoi=today();
$this->aff_date_last_remplissage="";
$this->aff_date_last_envoi=formatdate($this->date_last_envoi);
$this->proprio_bannette=0;
$this->bannette_auto=0;
$this->periodicite=0;
$this->diffusion_email=0;
$this->nb_notices_diff=0;
$this->categorie_lecteurs="";
$this->update_type="C";
$this->nb_notices = 0 ;
$this->nb_abonnes = 0 ;
$this->alert_diff = 0 ;
$this->num_panier = 0 ;
$this->limite_type = '' ;
$this->limite_nombre = 0 ;
$this->typeexport = '';
$this->group_pperso = 0;
$this->statut_not_account = 0;
$this->archive_number = 0;
$this->document_generate=0;
$this->document_notice_tpl=0;
$this->document_insert_docnum=0;
$this->document_group=0;
$this->document_add_summary=0;
$this->prefixe_fichier = "prefix_";
} else {
$requete = "SELECT id_bannette, num_classement, nom_bannette,comment_gestion,comment_public,statut_not_account, ";
$requete .= "date_last_remplissage, date_format(date_last_remplissage, '".$msg["format_date_heure"]."') as aff_date_last_remplissage, ";
$requete .= "date_last_envoi, date_format(date_last_envoi, '".$msg["format_date_heure"]."') as aff_date_last_envoi, ";
$requete .= "proprio_bannette,bannette_auto,periodicite,diffusion_email, nb_notices_diff, categorie_lecteurs, update_type, entete_mail, piedpage_mail, notice_tpl, num_panier, ";
$requete .= "limite_type, limite_nombre, typeexport, prefixe_fichier, param_export, group_pperso, archive_number, ";
$requete .= "document_generate, document_notice_tpl, document_insert_docnum, document_group, document_add_summary ";
$requete .= "FROM bannettes WHERE id_bannette='".$this->id_bannette."' " ;
$result = mysql_query($requete, $dbh) or die ($requete."
in bannette.class.php : ".mysql_error());
if(mysql_num_rows($result)) {
$temp = mysql_fetch_object($result);
$this->id_bannette = $temp->id_bannette ;
$this->num_classement = $temp->num_classement ;
$this->nom_bannette = $temp->nom_bannette ;
$this->comment_gestion = $temp->comment_gestion ;
$this->comment_public = $temp->comment_public ;
$this->entete_mail = $temp->entete_mail ;
$this->piedpage_mail = $temp->piedpage_mail ;
$this->notice_tpl = $temp->notice_tpl ;
$this->date_last_remplissage= $temp->date_last_remplissage ;
$this->date_last_envoi = $temp->date_last_envoi ;
$this->aff_date_last_remplissage = $temp->aff_date_last_remplissage ;
$this->aff_date_last_envoi = $temp->aff_date_last_envoi ;
$this->proprio_bannette = $temp->proprio_bannette ;
$this->bannette_auto = $temp->bannette_auto ;
$this->periodicite = $temp->periodicite ;
$this->diffusion_email = $temp->diffusion_email ;
$this->nb_notices_diff = $temp->nb_notices_diff;
$this->categorie_lecteurs = $temp->categorie_lecteurs ;
$this->update_type = $temp->update_type ;
$this->num_panier = $temp->num_panier ;
$this->limite_type = $temp->limite_type ;
$this->limite_nombre = $temp->limite_nombre ;
$this->typeexport = $temp->typeexport ;
$this->prefixe_fichier = $temp->prefixe_fichier ;
$this->group_pperso = $temp->group_pperso ;
$this->statut_not_account = $temp->statut_not_account ;
$this->archive_number = $temp->archive_number ;
$this->document_generate = $temp->document_generate ;
$this->document_notice_tpl = $temp->document_notice_tpl;
$this->document_insert_docnum= $temp->document_insert_docnum ;
$this->document_group = $temp->document_group ;
$this->document_add_summary = $temp->document_add_summary ;
$this->param_export = unserialize($temp->param_export) ;
$this->compte_elements();
$requete = "SELECt nom_classement FROM classements WHERE id_classement='".$this->num_classement."'" ;
$resultclass = mysql_query($requete, $dbh) or die ($requete."
in bannette.class.php : ".mysql_error());
if ($temp = mysql_fetch_object($resultclass)) $this->nom_classement = $temp->nom_classement ;
else $this->nom_classement = "" ;
} else {
// pas de bannette avec cette clé
$this->id_bannette=0;
$this->num_classement = 1 ;
$this->nom_classement = "" ;
$this->nom_bannette="";
$this->comment_gestion="";
$this->comment_public="";
$this->entete_mail="";
$this->piedpage_mail="";
$this->notice_tpl="";
$this->date_last_remplissage="";
$this->date_last_envoi="";
$this->aff_date_last_remplissage="";
$this->aff_date_last_envoi="";
$this->proprio_bannette=0;
$this->bannette_auto=0;
$this->periodicite=0;
$this->diffusion_email=0;
$this->nb_notices_diff=0;
$this->categorie_lecteurs="";
$this->update_type="C";
$this->nb_notices = 0 ;
$this->nb_abonnes = 0 ;
$this->num_panier = 0 ;
$this->limite_type = '' ;
$this->limite_nombre = 0 ;
$this->typeexport = '' ;
$this->prefixe_fichier = "prefix_";
$this->group_pperso = 0;
$this->statut_not_account = 0;
$this->archive_number=0;
$this->document_generate=0;
$this->document_notice_tpl=0;
$this->document_insert_docnum=0;
$this->document_group=0;
$this->document_add_summary=0;
}
}
}
// ---------------------------------------------------------------
// show_form : affichage du formulaire de saisie
// ---------------------------------------------------------------
function show_form($type="pro") {
global $msg, $charset;
global $dsi_bannette_form;
global $dsi_bannette_form_abo;
global $nom_prenom_abo;
global $opac_bannette_notices_template, $PMBuserid;
global $form_cb;
if ($type=="abo") $dsi_bannette_form = $dsi_bannette_form_abo ;
if($this->id_bannette) {
$action = "./dsi.php?categ=bannettes&sub=$type&id_bannette=$this->id_bannette&suite=update";
$link_duplicate = "";
$link_annul = "";
$button_delete = "";
$libelle = $msg['dsi_ban_form_modif'];
} else {
$action = "./dsi.php?categ=bannettes&sub=$type&id_bannette=0&suite=update";
$link_duplicate = "";
$link_annul = "";
$libelle = $msg['dsi_ban_form_creat'];
$button_delete ="";
$this->notice_tpl=$opac_bannette_notices_template;
}
$dsi_bannette_form = str_replace('!!libelle!!', $libelle, $dsi_bannette_form);
$dsi_bannette_form = str_replace('!!type!!', $type, $dsi_bannette_form);
$dsi_bannette_form = str_replace('!!id_bannette!!', $this->id_bannette, $dsi_bannette_form);
$dsi_bannette_form = str_replace('!!action!!', $action, $dsi_bannette_form);
$dsi_bannette_form = str_replace('!!link_duplicate!!', $link_duplicate, $dsi_bannette_form);
$dsi_bannette_form = str_replace('!!link_annul!!', $link_annul, $dsi_bannette_form);
$dsi_bannette_form = str_replace('!!nom_bannette!!', htmlentities($this->nom_bannette,ENT_QUOTES, $charset), $dsi_bannette_form);
if ($type=="pro") $dsi_bannette_form = str_replace('!!num_classement!!', show_classement_utilise ('BAN', $this->num_classement, 0), $dsi_bannette_form);
else $dsi_bannette_form = str_replace('!!num_classement!!', "", $dsi_bannette_form);
global $id_empr ;
$dsi_bannette_form = str_replace('!!id_empr!!', $id_empr, $dsi_bannette_form);
$dsi_bannette_form = str_replace('!!comment_gestion!!', htmlentities($this->comment_gestion,ENT_QUOTES, $charset), $dsi_bannette_form);
$dsi_bannette_form = str_replace('!!comment_public!!', htmlentities($this->comment_public,ENT_QUOTES, $charset), $dsi_bannette_form);
$dsi_bannette_form = str_replace('!!entete_mail!!', htmlentities($this->entete_mail,ENT_QUOTES, $charset), $dsi_bannette_form);
$dsi_bannette_form = str_replace('!!piedpage_mail!!', htmlentities($this->piedpage_mail,ENT_QUOTES, $charset), $dsi_bannette_form);
$dsi_bannette_form = str_replace('!!date_last_remplissage!!', htmlentities($this->aff_date_last_remplissage,ENT_QUOTES, $charset), $dsi_bannette_form);
$date_clic = "onClick=\"openPopUp('./select.php?what=calendrier&caller=saisie_bannette&date_caller=".preg_replace('/-/', '', $this->date_last_envoi)."¶m1=form_date_last_envoi¶m2=form_aff_date_last_envoi&auto_submit=NO&date_anterieure=YES', 'date_last_envoi', 250, 300, -2, -2, 'toolbar=no, dependent=yes, resizable=yes')\" ";
$date_last_envoi = "
date_last_envoi)))."' />
";
$dsi_bannette_form = str_replace('!!date_last_envoi!!', $date_last_envoi, $dsi_bannette_form);
$dsi_bannette_form = str_replace('!!archive_number!!', $this->archive_number, $dsi_bannette_form);
if ($type=="pro") $dsi_bannette_form = str_replace('!!proprio_bannette!!', htmlentities($msg['dsi_ban_no_proprio'],ENT_QUOTES, $charset), $dsi_bannette_form);
else $dsi_bannette_form = str_replace('!!proprio_bannette!!', htmlentities($nom_prenom_abo,ENT_QUOTES, $charset), $dsi_bannette_form);
if ($this->bannette_auto) $dsi_bannette_form = str_replace('!!bannette_auto!!', "checked", $dsi_bannette_form);
else $dsi_bannette_form = str_replace('!!bannette_auto!!', "", $dsi_bannette_form);
$dsi_bannette_form = str_replace('!!periodicite!!', htmlentities($this->periodicite,ENT_QUOTES, $charset), $dsi_bannette_form);
if ($this->diffusion_email) $dsi_bannette_form = str_replace('!!diffusion_email!!', "checked='checked'", $dsi_bannette_form);
else $dsi_bannette_form = str_replace('!!diffusion_email!!', "", $dsi_bannette_form);
$dsi_bannette_form = str_replace('!!nb_notices_diff!!', htmlentities($this->nb_notices_diff,ENT_QUOTES, $charset), $dsi_bannette_form);
$dsi_bannette_form = str_replace('!!notice_tpl!!', notice_tpl_gen::gen_tpl_select("notice_tpl",$this->notice_tpl), $dsi_bannette_form);
if ($this->statut_not_account) $dsi_bannette_form = str_replace('!!statut_not_account!!', "checked", $dsi_bannette_form);
else $dsi_bannette_form = str_replace('!!statut_not_account!!', "", $dsi_bannette_form);
$liste_p_perso = $this->p_perso->gen_liste_field("group_pperso",$this->group_pperso,$msg["dsi_ban_form_regroupe_pperso_no"]);
$dsi_bannette_form = str_replace('!!pperso_group!!', $liste_p_perso, $dsi_bannette_form);
if ($type=="pro") {
$requete = "SELECT id_categ_empr, libelle FROM empr_categ ORDER BY libelle ";
$onchange="res=confirm('".htmlentities($msg[dsi_ban_confirm_modif_categ],ENT_QUOTES, $charset)."'); if (res) this.form.majautocateg.value=1; else this.form.majautocateg.value=0;";
$categ_lect_aff = gen_liste ($requete, "id_categ_empr", "libelle", "categorie_lecteurs", $onchange, $this->categorie_lecteurs, 0, $msg[dsi_ban_aucune_categ], 0,$msg[dsi_ban_aucune_categ], 0) ;
$dsi_bannette_form = str_replace('!!categorie_lecteurs!!', $categ_lect_aff, $dsi_bannette_form);
} else $dsi_bannette_form = str_replace('!!categorie_lecteurs!!', "", $dsi_bannette_form);
$requete = "SELECT idcaddie, name FROM caddie where type='NOTI' ";
if ($PMBuserid!=1) $requete.=" and (autorisations='$PMBuserid' or autorisations like '$PMBuserid %' or autorisations like '% $PMBuserid %' or autorisations like '% $PMBuserid') ";
$requete.=" ORDER BY name ";
$panier_bann_aff = gen_liste ($requete, "idcaddie", "name", "num_panier", "", $this->num_panier, 0, $msg[dsi_panier_aucun], 0,$msg[dsi_panier_aucun], 0) ;
$dsi_bannette_form = str_replace('!!num_panier!!', $panier_bann_aff, $dsi_bannette_form);
switch ($this->limite_type) {
case "D":
$selectn = "" ;
$selecti = "" ;
$selectd = " SELECTED " ;
break;
case "I":
$selectn = "" ;
$selectd = "" ;
$selecti = " SELECTED " ;
break;
default:
case "":
$selecti = "" ;
$selectd = "" ;
$selectn = " SELECTED " ;
break;
}
$limite_type = "";
$dsi_bannette_form = str_replace('!!limite_type!!', $limite_type, $dsi_bannette_form);
$dsi_bannette_form = str_replace('!!limite_nombre!!', $this->limite_nombre, $dsi_bannette_form);
// update_type: se baser sur la date de création ou la date de mise à jour des notices ?
switch ($this->update_type) {
case "C":
$selectu = "" ;
$selectc = " SELECTED " ;
break;
case "U":
$selectc = "" ;
$selectu = " SELECTED " ;
break;
default:
case "":
$selectu = "" ;
$selectc = " SELECTED " ;
break;
}
$update_type = "";
$dsi_bannette_form = str_replace('!!update_type!!', $update_type, $dsi_bannette_form);
$exp = start_export::get_exports();
$liste_exports = "" ;
$dsi_bannette_form = str_replace('!!typeexport!!', $liste_exports, $dsi_bannette_form);
$dsi_bannette_form = str_replace('!!prefixe_fichier!!', $this->prefixe_fichier, $dsi_bannette_form);
if ($this->document_generate) $dsi_bannette_form = str_replace('!!document_generate!!', "checked=checked", $dsi_bannette_form);
else $dsi_bannette_form = str_replace('!!document_generate!!', "", $dsi_bannette_form);
$dsi_bannette_form = str_replace('!!document_notice_tpl!!', notice_tpl_gen::gen_tpl_select("document_notice_tpl",$this->document_notice_tpl), $dsi_bannette_form);
if ($this->document_insert_docnum) $dsi_bannette_form = str_replace('!!document_insert_docnum!!', "checked=checked", $dsi_bannette_form);
else $dsi_bannette_form = str_replace('!!document_insert_docnum!!', "", $dsi_bannette_form);
if ($this->document_group) $dsi_bannette_form = str_replace('!!document_group!!', "checked=checked", $dsi_bannette_form);
else $dsi_bannette_form = str_replace('!!document_group!!', "", $dsi_bannette_form);
if ($this->document_add_summary) $dsi_bannette_form = str_replace('!!document_add_summary!!', "checked=checked", $dsi_bannette_form);
else $dsi_bannette_form = str_replace('!!document_add_summary!!', "", $dsi_bannette_form);
$dsi_bannette_form = str_replace('!!delete!!', $button_delete, $dsi_bannette_form);
// afin de revenir où on était : $form_cb, le critère de recherche
$dsi_bannette_form = str_replace('!!form_cb!!', $form_cb, $dsi_bannette_form);
if($this->param_export)
$param=new export_param(EXP_DSI_CONTEXT, $this->param_export);
else $param=new export_param(EXP_DEFAULT_GESTION);
if(!$this->typeexport)
$dsi_bannette_form = str_replace('!!display_liste_param!!', 'display:none', $dsi_bannette_form);
else $dsi_bannette_form = str_replace('!!display_liste_param!!', '', $dsi_bannette_form);
$dsi_bannette_form = str_replace('!!form_param!!', $param->check_default_param(), $dsi_bannette_form);
print $dsi_bannette_form;
}
// ---------------------------------------------------------------
// delete() : suppression
// ---------------------------------------------------------------
function delete() {
global $dbh;
global $msg;
if (!$this->id_bannette) return $msg[dsi_ban_no_access]; // impossible d'accéder à cette bannette
$requete = "delete from bannette_abon WHERE num_bannette='$this->id_bannette'";
$res = mysql_query($requete, $dbh);
if ($this->proprio_bannette) {
$requete = "select num_equation from bannette_equation WHERE num_bannette='$this->id_bannette'";
$res = mysql_query($requete, $dbh);
$temp = @mysql_fetch_object($res);
$requete = "delete from equations WHERE id_equation='$temp->num_equation'";
$res = mysql_query($requete, $dbh);
}
$requete = "delete from bannette_equation WHERE num_bannette='$this->id_bannette'";
$res = mysql_query($requete, $dbh);
$requete = "delete from bannette_contenu WHERE num_bannette='$this->id_bannette'";
$res = mysql_query($requete, $dbh);
$requete = "delete from bannettes WHERE id_bannette='$this->id_bannette'";
$res = mysql_query($requete, $dbh);
$query = mysql_query("DELETE bannettes FROM bannettes LEFT JOIN empr ON proprio_bannette = id_empr WHERE id_empr IS NULL AND proprio_bannette !=0");
$query = mysql_query("DELETE equations FROM equations LEFT JOIN empr ON proprio_equation = id_empr WHERE id_empr IS NULL AND proprio_equation !=0 ");
$query = mysql_query("DELETE bannette_equation FROM bannette_equation LEFT JOIN bannettes ON num_bannette = id_bannette WHERE id_bannette IS NULL ");
$query = mysql_query("DELETE bannette_equation FROM bannette_equation LEFT JOIN equations on num_equation=id_equation WHERE id_equation is null");
$query = mysql_query("DELETE bannette_abon FROM bannette_abon LEFT JOIN empr on num_empr=id_empr WHERE id_empr is null");
$query = mysql_query("DELETE bannette_abon FROM bannette_abon LEFT JOIN bannettes ON num_bannette=id_bannette WHERE id_bannette IS NULL ");
}
// ---------------------------------------------------------------
// update
// ---------------------------------------------------------------
function update($temp) {
global $dbh;
global $msg;
if ($this->id_bannette) {
// update
$req = "UPDATE bannettes set ";
$clause = " WHERE id_bannette='".$this->id_bannette."'";
} else {
$req = "insert into bannettes set date_last_remplissage=sysdate(), ";
$clause = "";
}
$req.="num_classement='$temp->num_classement',";
$req.="nom_bannette='$temp->nom_bannette',";
$req.="comment_gestion='$temp->comment_gestion',";
$req.="comment_public='$temp->comment_public',";
$req.="entete_mail='$temp->entete_mail',";
$req.="piedpage_mail='$temp->piedpage_mail',";
$req.="notice_tpl='$temp->notice_tpl',";
$req.="proprio_bannette='$temp->proprio_bannette',";
$req.="bannette_auto='$temp->bannette_auto',";
$req.="periodicite='$temp->periodicite',";
$req.="diffusion_email='$temp->diffusion_email',";
$req.="statut_not_account='$temp->statut_not_account',";
$req.="nb_notices_diff='$temp->nb_notices_diff',";
$req.="categorie_lecteurs='$temp->categorie_lecteurs',";
$req.="update_type='$temp->update_type',";
$req.="num_panier='$temp->num_panier',";
$req.="limite_type='$temp->limite_type',";
$req.="limite_nombre='$temp->limite_nombre',";
$req.="typeexport='$temp->typeexport',";
$req.="prefixe_fichier='$temp->prefixe_fichier',";
$req.="group_pperso='$temp->group_pperso',";
$req.="archive_number='$temp->archive_number',";
$req.="param_export='".addslashes(serialize($temp->param_export))."',";
$req.="document_generate='$temp->document_generate',";
$req.="document_notice_tpl='$temp->document_notice_tpl',";
$req.="document_insert_docnum='$temp->document_insert_docnum',";
$req.="document_group='$temp->document_group',";
$req.="document_add_summary='$temp->document_add_summary',";
if (!$temp->date_last_envoi) $req.="date_last_envoi=sysdate() ";
else $req.="date_last_envoi='".construitdateheuremysql($temp->date_last_envoi)."' ";
$req.=$clause ;
$res = mysql_query($req, $dbh);
if (!$this->id_bannette) $this->id_bannette = mysql_insert_id() ;
}
// ---------------------------------------------------------------
// purger() : après remplissage, vider ce qui dépasse selon le type de cumul de la bannette
// ---------------------------------------------------------------
function purger() {
global $dbh;
global $msg;
global $gestion_acces_active,$gestion_acces_empr_notice;
if (!$this->id_bannette) return $msg[dsi_ban_no_access]; // impossible d'accéder à cette bannette
//purge pour les bannettes privees des notices ne devant pas etre diffusees
if ($this->proprio_bannette && $gestion_acces_active==1 && $gestion_acces_empr_notice==1){
$ac = new acces();
$dom_2 = $ac->setDomain(2);
$acces_j = $dom_2->getJoin($this->proprio_bannette,'4=0','num_notice');
$q="delete from bannette_contenu using bannette_contenu $acces_j WHERE num_bannette='$this->id_bannette' ";
mysql_query($q,$dbh);
}
switch ($this->limite_type) {
case "D":
$requete = "select num_notice from bannette_contenu WHERE num_bannette='$this->id_bannette' and ";
$requete .= " date_add(date_ajout, INTERVAL ".$this->limite_nombre." DAY)
$requete");
}
$requete = "delete from bannette_contenu WHERE num_bannette='$this->id_bannette' and num_notice in (".$notice_suppr.") ";
$res = mysql_query($requete, $dbh) or die(mysql_error()."
$requete");
}
break;
case "I":
$tab = array();
// selection des ## dernières notices, celles qu'il faut absolument garder
$requete = "select num_notice from bannette_contenu, notices WHERE num_bannette='$this->id_bannette' and notice_id=num_notice order by date_ajout DESC, update_date DESC ";
$requete .= " limit $this->limite_nombre ";
$res = mysql_query($requete, $dbh) or die(mysql_error()."
$requete");
while ($obj=mysql_fetch_object($res)) $tab[]=$obj->num_notice ;
// selection des notices ajoutées depuis moins d'un jour
$requete = "select num_notice from bannette_contenu WHERE num_bannette='$this->id_bannette' and ";
$requete .= " date_add(date_ajout, INTERVAL 1 DAY)>=sysdate() ";
$res = mysql_query($requete, $dbh) or die(mysql_error()."
$requete");
while ($obj=mysql_fetch_object($res)) $tab[]=$obj->num_notice ;
// suppression de tout ce qui dépasse
$notice_suppr=implode(",",$tab);
if ($notice_suppr) {
if ($this->num_panier) {
$requete = "delete from caddie_content WHERE caddie_id='$this->num_panier' and object_id not in (".$notice_suppr.") ";
$res = mysql_query($requete, $dbh) or die(mysql_error()."
$requete");
}
$requete = "delete from bannette_contenu WHERE num_bannette='$this->id_bannette' and num_notice not in (".$notice_suppr.") ";
$res = mysql_query($requete, $dbh) or die(mysql_error()."
$requete");
}
break;
default:
case "":
break;
}
$this->compte_elements() ;
}
// ---------------------------------------------------------------
// vider() : vider le contenu de la bannette
// ---------------------------------------------------------------
function vider() {
global $dbh;
global $msg;
if (!$this->id_bannette) return $msg[dsi_ban_no_access]; // impossible d'accéder à cette bannette
$requete = "delete from bannette_contenu WHERE num_bannette='$this->id_bannette'";
mysql_query($requete, $dbh);
$requete = "delete from caddie_content WHERE caddie_id='$this->num_panier'";
mysql_query($requete, $dbh);
$this->compte_elements() ;
}
// ---------------------------------------------------------------
// remplir() : remplir la bannette à partir des équations
// ---------------------------------------------------------------
function remplir() {
global $dbh;
global $msg;
if (!$this->id_bannette) return $msg[dsi_ban_no_access]; // impossible d'accéder à cette bannette
// récupérer les équations associées à la bannette
$equations = $this->get_equations() ;
$res_affichage = "
$echec_email
$no_email