";
$i=pmb_sql_value("SELECT MONTH('".$date."')");
if($i==2 || $i==5 || $i==8 || $i==11) {
$calend.= "
";
$calend.= "
\n";
}
if($i==3 || $i==6 || $i==9 || $i==12) {
$calend.= "
";
$calend.= "
\n";
$calend.= "
";
$calend.= "
\n";
}
do {
$year=pmb_sql_value("SELECT YEAR('".$date."')");
if($year!=$cur_year){
$calend.= "
";
$calend.="
$year
";
$cur_year=$year;
}
$i=pmb_sql_value("SELECT MONTH('".$date."')");
if ($i==1 || $i==4 || $i==7 || $i==10 ) $calend.= "
";
else
$calend.= "
";
$calend.= pmb_bidi(calendar_gestion(str_replace("-","",$date), 0, $base_url, $base_url_mois,0,$this->modele_id,0));
$calend.= "
\n";
if ($i==3 || $i==6 || $i==9 || $i==12 ) $calend.="
\n";
$date=pmb_sql_value("SELECT DATE_ADD('".$date."', INTERVAL 1 MONTH)");
$diff=pmb_sql_value("SELECT DATEDIFF('".$date_fin."','".$date."')");
}
while($diff>=0);
//fin expand
$calend.= "
";
$calend.= "
\n";
$calend.="";
$r.=$calend;
}
return $r;
}
public function gen_date(){
global $dbh;
global $msg;
global $include_path;
if($this->modele_id) {
$dummy = "delete FROM abts_grille_modele WHERE num_modele='".$this->modele_id."' ";
pmb_mysql_query($dummy, $dbh);
$date = construitdateheuremysql($this->date_debut);
$date_fin = construitdateheuremysql($this->date_fin);
//Lire la périodicté
$duree=1;
$requete="select duree,unite from abts_periodicites where periodicite_id='".$this->num_periodicite."'";
$resultat=pmb_mysql_query($requete);
if($r=pmb_mysql_fetch_object($resultat)) {
$duree=$r->duree;
$unite=$r->unite;
do {
$dayofweek=pmb_sql_value("SELECT DAYOFWEEK('".$date."')"); //1 = Dimanche, 2 = Lundi, ... 7 = Samedi
if($dayofweek==1)$dayofweek=8;
$dayofweek--;
$day=pmb_sql_value("SELECT DAYOFMONTH('".$date."')"); // 1 à 31
$month=pmb_sql_value("SELECT MONTH('".$date."')"); //1 à 12
$week=pmb_sql_value("SELECT WEEK('".$date."',5)") + 1;//0 ... 53
//calcul numero de semaine dans le mois
$weekofmonth=($day+7-$dayofweek)/7+1;
//Mois dans l'année exclu
if (substr($this->month_year, $month-1, 1)) {
if (substr($this->week_year, $week-1, 1)) {
if (substr($this->week_month, $weekofmonth-1, 1)) {
if (substr($this->day_month, $day-1, 1)) {
if (substr($this->days, $dayofweek-1, 1)) {
//c'est un jour prévu de réception
$requete = "INSERT INTO abts_grille_modele SET num_modele='".$this->modele_id."', date_parution ='".$date."', type_serie = '1'";
pmb_mysql_query($requete, $dbh);
}
}
}
}
}
// Calcul de la date suivante à analyser et la sortie du while
if($unite==0) $sql_add="INTERVAL ".$duree." DAY";
if($unite==1) $sql_add="INTERVAL ".$duree." MONTH";
if($unite==2) $sql_add="INTERVAL ".$duree." YEAR";
$date=pmb_sql_value("SELECT DATE_ADD('$date', $sql_add)");
$diff=pmb_sql_value("SELECT DATEDIFF('$date_fin','$date')");
}
while(($diff>=0) && ($duree != 0));
}
}
}
public function update() {
global $dbh;
global $msg;
global $include_path;
global $act;
if(!$this->modele_name) return false;
// nettoyage des valeurs en entrée
$this->modele_name = clean_string($this->modele_name);
// construction de la requête
$requete = "SET modele_name='".addslashes($this->modele_name)."', ";
$requete .= "num_notice='$this->num_notice', ";
$requete .= "num_periodicite='$this->num_periodicite', ";
$requete .= "duree_abonnement='$this->duree_abonnement', ";
$requete .= "date_debut='$this->date_debut', ";
$requete .= "date_fin='$this->date_fin', ";
$requete .= "days='$this->days', ";
$requete .= "day_month='$this->day_month', ";
$requete .= "week_month='$this->week_month', ";
$requete .= "week_year='$this->week_year', ";
$requete .= "month_year='$this->month_year', ";
$requete .= "num_cycle='$this->num_cycle', ";
$requete .= "num_increment='$this->num_increment', ";
$requete .= "num_combien='$this->num_combien', ";
$requete .= "num_date_unite='$this->num_date_unite', ";
$requete .= "num_increment_date='$this->num_increment_date', ";
$requete .= "num_depart='$this->num_depart', ";
$requete .= "vol_actif='$this->vol_actif', ";
$requete .= "vol_increment='$this->vol_increment', ";
$requete .= "vol_date_unite='$this->vol_date_unite', ";
$requete .= "vol_increment_numero='$this->vol_increment_numero', ";
$requete .= "vol_increment_date='$this->vol_increment_date', ";
$requete .= "vol_cycle='$this->vol_cycle', ";
$requete .= "vol_combien='$this->vol_combien', ";
$requete .= "vol_depart='$this->vol_depart', ";
$requete .= "tom_actif='$this->tom_actif', ";
$requete .= "tom_increment='$this->tom_increment', ";
$requete .= "tom_date_unite='$this->tom_date_unite', ";
$requete .= "tom_increment_numero='$this->tom_increment_numero', ";
$requete .= "tom_increment_date='$this->tom_increment_date', ";
$requete .= "tom_cycle='$this->tom_cycle', ";
$requete .= "tom_combien='$this->tom_combien', ";
$requete .= "tom_depart='$this->tom_depart', ";
$requete .= "format_aff='".addslashes($this->format_aff)."', ";
$requete .= "format_periode='".addslashes($this->format_periode)."' ";
if($this->modele_id) {
// update: s'assurer que le nom de modèle n'existe pas déjà
$dummy = "SELECT * FROM abts_modeles WHERE modele_name='".addslashes($this->modele_name)."' and num_notice='".$this->num_notice."' and modele_id!='".$this->modele_id."' ";
$check = pmb_mysql_query($dummy, $dbh);
if(pmb_mysql_num_rows($check)) {
require_once("$include_path/user_error.inc.php");
warning($msg["abonnements_titre_creation_edition_modele"], $msg["abonnements_erreur_creation_doublon_modele"]." ($this->modele_name).");
return FALSE;
}
$requete = 'UPDATE abts_modeles '.$requete;
$requete .= ' WHERE modele_id='.$this->modele_id.' LIMIT 1;';
if(pmb_mysql_query($requete, $dbh)) {
if($act=="gen") $this->gen_date();
return TRUE;
}else {
require_once("$include_path/user_error.inc.php");
warning($msg["abonnements_titre_creation_edition_modele"], $msg["abonnements_titre_creation_edition_modele_impossible"]);
return FALSE;
}
} else {
// s'assurer que le modèle n'existe pas déjà
$dummy = "SELECT * FROM abts_modeles WHERE modele_name='".addslashes($this->modele_name)."' and num_notice='".$this->num_notice."'";
$check = pmb_mysql_query($dummy, $dbh);
if(pmb_mysql_num_rows($check)) {
require_once("$include_path/user_error.inc.php");
warning($msg["abonnements_titre_creation_edition_modele"], $msg["abonnements_erreur_creation_doublon_modele"]." ($this->modele_name).");
return FALSE;
}
$requete = 'INSERT INTO abts_modeles '.$requete.';';
if(pmb_mysql_query($requete, $dbh)) {
$this->modele_id=pmb_mysql_insert_id();
if($act=="gen") $this->gen_date();
return TRUE;
} else {
require_once("$include_path/user_error.inc.php");
warning($msg["abonnements_titre_creation_edition_modele"], $msg["abonnements_titre_creation_edition_modele_impossible"]);
return FALSE;
}
}
}
public function delete() {
global $dbh;
global $msg;
global $include_path;
//Je supprime les abonnements liés au modèle
$requete="SELECT abt_id FROM abts_abts_modeles WHERE modele_id='".$this->modele_id."'";
$res=pmb_mysql_query($requete);
if(pmb_mysql_num_rows($res)){
while ($ligne=pmb_mysql_fetch_object($res)) {
$mon_abt= new abts_abonnement($ligne->abt_id);
$mon_abt->delete();
}
}
$dummy = "delete FROM abts_modeles WHERE modele_id='".$this->modele_id."' ";
$check = pmb_mysql_query($dummy, $dbh);
$dummy = "delete FROM abts_grille_modele WHERE num_modele='".$this->modele_id."' ";
$check = pmb_mysql_query($dummy, $dbh);
}
public function proceed() {
global $include_path,$charset;
global $act;
global $serial_id,$msg,$modele_name,$num_notice,$num_periodicite,$duree_abonnement,$date_debut,$date_fin,$days,$day_month,$week_month,$week_year,$month_year,$date_parution;
global $num_cycle,$num_combien,$num_depart,$vol_actif,$vol_increment,$vol_date_unite,$vol_increment_numero,
$vol_increment_date,$vol_cycle,$vol_combien,$vol_depart,$tom_actif,$tom_increment,$tom_date_unite,$tom_increment_numero,
$tom_increment_date,$tom_cycle,$tom_combien,$tom_depart,$month_year,$format_aff,$format_periode,$new_serial_id,$num_increment,$num_date_unite,$num_increment_date;
global $dbh,$include_path;
switch ($act) {
case 'update':
// mise à jour modèle
$this->modele_name= stripslashes($modele_name);
$this->num_notice= $num_notice;
$this->num_periodicite= $num_periodicite;
$this->duree_abonnement= $duree_abonnement;
$this->date_debut=$date_debut;
$this->date_fin= $date_fin;
$this->days=$this->calc_selection($days,7);
$this->day_month=$this->calc_selection($day_month,31);
$this->week_month=$this->calc_selection($week_month,6);
$this->week_year= $this->calc_selection($week_year,54);
$this->month_year=$this->calc_selection($month_year,12);
$this->num_cycle = 1-$this->calc_selection($num_cycle,1);
$this->num_combien = $num_combien;
$this->num_depart = $num_depart;
$this->num_increment=$num_increment;
$this->num_date_unite=$num_date_unite;
$this->num_increment_date=$num_increment_date;
$this->vol_actif = 1-$this->calc_selection($vol_actif,1);
$this->vol_increment = $vol_increment;
$this->vol_date_unite = $vol_date_unite;
$this->vol_increment_numero = $vol_increment_numero;
$this->vol_increment_date = $vol_increment_date;
$this->vol_cycle = 1-$this->calc_selection($vol_cycle,1);
$this->vol_combien = $vol_combien;
$this->vol_depart = $vol_depart;
$this->tom_actif = 1-$this->calc_selection($tom_actif,1);
$this->tom_increment = $tom_increment;
$this->tom_date_unite = $tom_date_unite;
$this->tom_increment_numero = $tom_increment_numero;
$this->tom_increment_date = $tom_increment_date;
$this->tom_cycle = 1-$this->calc_selection($tom_cycle,1);
$this->tom_combien = $tom_combien;
$this->tom_depart = $tom_depart;
$this->format_aff = stripslashes($format_aff);
$this->format_periode = stripslashes($format_periode);
$this->update();
print $this->show_form();
break;
case 'gen':
// mise à jour modèle
$this->modele_name= stripslashes($modele_name);
$this->num_notice= $num_notice;
$this->num_periodicite= $num_periodicite;
$this->duree_abonnement= $duree_abonnement;
$this->date_debut=$date_debut;
$this->date_fin= $date_fin;
$this->days=$this->calc_selection($days,7);
$this->day_month=$this->calc_selection($day_month,31);
$this->week_month=$this->calc_selection($week_month,6);
$this->week_year= $this->calc_selection($week_year,54);
$this->month_year=$this->calc_selection($month_year,12);
$this->num_cycle = 1-$this->calc_selection($num_cycle,1);
$this->num_combien = $num_combien;
$this->num_depart = $num_depart;
$this->vol_actif = 1-$this->calc_selection($vol_actif,1);
$this->vol_increment = $vol_increment;
$this->vol_date_unite = $vol_date_unite;
$this->vol_increment_numero = $vol_increment_numero;
$this->vol_increment_date = $vol_increment_date;
$this->vol_cycle = 1-$this->calc_selection($vol_cycle,1);
$this->vol_combien = $vol_combien;
$this->vol_depart = $vol_depart;
$this->tom_actif = 1-$this->calc_selection($tom_actif,1);
$this->tom_increment = $tom_increment;
$this->tom_date_unite = $tom_date_unite;
$this->tom_increment_numero = $tom_increment_numero;
$this->tom_increment_date = $tom_increment_date;
$this->tom_cycle = 1-$this->calc_selection($tom_cycle,1);
$this->tom_combien = $tom_combien;
$this->tom_depart = $tom_depart;
$this->format_aff = stripslashes($format_aff);
$this->format_periode = stripslashes($format_periode);
$this->update();
print $this->show_form();
break;
case 'copy':
// mise à jour modèle
$requete = "select type_serie, numero,date_parution,type_serie,nombre_recu from abts_grille_modele where num_modele='".$this->modele_id."'";
$resultat=pmb_mysql_query($requete);
//Création du nouveau modèle
$this->modele_id='';
$this->num_notice=$new_serial_id;
$this->modele_name= clean_string($this->modele_name);
$serial_id=$new_serial_id;
$this->update();
$requete = "delete FROM abts_grille_modele WHERE num_modele='".$this->modele_id."'";
pmb_mysql_query($requete, $dbh);
//recopie des infos du calendrier
if(pmb_mysql_num_rows($resultat)) {
while(($r=pmb_mysql_fetch_object($resultat))){
$date_parution=$r->date_parution;
$type_serie=$r->type_serie;
$nombre_recu=$r->nombre_recu;
$numero=$r->numero;
$requete = "INSERT INTO abts_grille_modele SET num_modele='".$this->modele_id."', date_parution ='".$date_parution."', type_serie = '".$type_serie."', nombre_recu= '".$nombre_recu."'";
pmb_mysql_query($requete, $dbh);
}
}
print $this->show_form();
break;
case 'del':
// Verif si abonnements associés
$requete="select abt_name,abts_abts.abt_id as ab_id from abts_abts_modeles,abts_abts where modele_id='".$this->modele_id."' and abts_abts.abt_id=abts_abts_modeles.abt_id";
$resultat=pmb_mysql_query($requete);
if (pmb_mysql_num_rows($resultat)) {
while(($r=pmb_mysql_fetch_object($resultat))) {
$liste.="
num_notice."&abt_id=".$r->ab_id."\">".$r->abt_name."";
}
require_once("$include_path/user_error.inc.php");
warning(htmlentities($msg["abonnements_titre_effacement_modele"],ENT_QUOTES,$charset), htmlentities($msg["abonnements_effacement_modele_erreur"],ENT_QUOTES,$charset)."
".$liste."");
print $this->show_form();
return;
}
$this->delete();
print "
";
$id_form = md5(microtime());
$retour = "./catalog.php?categ=serials&sub=view&serial_id=".$serial_id."&view=modele";
print "
";
break;
default:
print $this->show_form();
break;
}
}
public function calc_selection($val,$size){
$ret='';
for ($i=0; $i<$size; $i++) {
if(!isset($val[$i+1])) $ret .='1'; else $ret .='0';
}
return $ret;
}
}
class abts_modeles {
public $modeles = array(); //Tableau des IDs des modèles
public function __construct($id_perio) {
$id_perio += 0;
$requete="select modele_id from abts_modeles where num_notice=$id_perio";
$resultat=pmb_mysql_query($requete);
while ($r=pmb_mysql_fetch_object($resultat)) {
$modele=new abts_modele($r->modele_id);
if (!$modele->error) $this->modeles[]=$modele;
}
}
public function show_list() {
global $modele_list,$msg;
$r=$modele_list;
$modeles="";
if (count($this->modeles)) {
for ($i=0; $i