hellofacteurV1/ctrl/compte_abo_maj_tests.php

143 lines
4.2 KiB
PHP
Executable File

<?php
/**
* Script testant les données envoyées lors d'une demande de mise à jour / suppression d'un abonnement
* Peut être appelé en ajax ou directement en php si JS désactivé
*
**/
$form["id_abonnement"]=intval($_POST["id_abonnement"]);
$form["designation"]=trim($_POST["designation"]);
$form["jours_alerte"]="";
if(!empty($_POST["jours_alerte"]))
$form["jours_alerte"]=implode(",",$_POST["jours_alerte"]);
$form["heure_alerte"]="";
if(!empty($_POST["heure_alerte"]))
$form["heure_alerte"]=$_POST["heure_alerte"];
if(isset($_POST["max_liens"]))
$form["max_liens"]=intval($_POST["max_liens"]);
$ajax_on=false;
if(!empty($_POST["ajax"]))
{
$ajax_on=true;
session_save_path(SESSIONS_REP);
ini_set("session.use_only_cookies",1);
session_start();
header('Content-Type: text/html; charset=utf-8');
require_once("../modele/FclFlux_abonnement.php");
}
$msg_form=array();
if((empty($_SESSION["id_utilisateur"]))||(empty($form["id_abonnement"])))
$msg_form[]=ERREUR_IMPREVUE;
elseif(!empty($_POST["abo_suppr"]))
{
if(empty($Bd))
require("../modele/connexion-bd.php");
$user=new FclFlux_utilisateur();
$user->id_utilisateur=$_SESSION["id_utilisateur"];
$form["proprietaire"]=$user;
$abo_suppr=new FclFlux_abonnement($form);
if(empty($abo_suppr->erreurs))
{
$suppr=$abo_suppr->supprime();
if(!empty($abo_suppr->erreurs))
$msg_form=array_merge($abo_suppr->erreurs,$msg_form);
elseif($suppr===false)
$msg_form[]=ERREUR_IMPREVUE;
else
{
$_SESSION["message"]=MSG_UTILISA_MAJ_SUPPR_VALID;
if($ajax_on)
$msg_form[]=MSG_UTILISA_MAJ_SUPPR_VALID;
else
{
header("location:".PAGE_ABO_LISTE);
exit();
}
}
}
}
elseif((empty($_POST["designation"]))||(empty($form["max_liens"])))
$msg_form[]=ERREUR_UTILISA_CHAMPS_ABSENTS;
else
{
if(empty($Bd))
require("../modele/connexion-bd.php");
$user=new FclFlux_utilisateur();
$user->id_utilisateur=$_SESSION["id_utilisateur"];
$form["proprietaire"]=$user;
$abo_maj=new FclFlux_abonnement($form);
if(!empty($abo_maj->erreurs))
$msg_form=array_merge($abo_maj->erreurs,$msg_form);
//suppression des hubs / abonnement
if((empty($msg_form))&&(!empty($_POST["hubs_suppr"])))
{
$liste_hubs=array();$i=0;
foreach($_POST["hubs_suppr"] as $hub_id)
{
$hub_suppr=new FclFlux_hub();
$hub_suppr->id_hub=$hub_id;
$liste_hubs[$i]=$hub_suppr;
unset($hub_suppr);
$i++;
}
if($i>0)
{
$action=$abo_maj->supprime_hubs($liste_hubs);
if(!empty($abo_maj->erreurs))
$msg_form=array_merge($abo_maj->erreurs,$msg_form);
elseif($action===false)
$msg_form[]=ERREUR_IMPREVUE;
}
}
//ajout hub / abonnement
if((empty($msg_form))&&(empty($abo_maj->erreurs))&&(!empty($_POST["hubs_ajout"])))
{
$liste_hubs=array();$i=0;
foreach($_POST["hubs_ajout"] as $hub_id)
{
$hub_ajout=new FclFlux_hub();
$hub_ajout->id_hub=$hub_id;
$liste_hubs[$i]=$hub_ajout;
unset($hub_ajout);
$i++;
}
if($i>0)
{
$action=$abo_maj->ajout_hubs($liste_hubs);
if(!empty($abo_maj->erreurs))
$msg_form=array_merge($abo_maj->erreurs,$msg_form);
elseif($action===false)
$msg_form[]=ERREUR_IMPREVUE;
}
}
//changement de ville ?
if((empty($msg_form))&&(empty($abo_maj->erreurs))&&(!empty($_POST["insee"]))&&($_POST["a_insee"]!=$_POST["insee"]))
{
$abo_maj->set_ville_insee($_POST["insee"]);
$chgt_ville=$abo_maj->abo_rapide_nouvelle_ville($_POST["insee"],$user);
if(!empty($abo_maj->erreurs))
$msg_form=array_merge($abo_maj->erreurs,$msg_form);
elseif($chgt_ville===false)
$msg_form[]=ERREUR_IMPREVUE;
}
// les autres infos.
if((empty($msg_form))&&(empty($abo_maj->erreurs)))
{
$maj=$abo_maj->actualise();
if(!empty($abo_maj->erreurs))
$msg_form=array_merge($abo_maj->erreurs,$msg_form);
elseif($maj===false)
$msg_form[]=ERREUR_IMPREVUE;
}
if(empty($msg_form))
$msg_form[]=MSG_UTILISA_MAJ_INFOS_VALID;
$Bd=null;
}
if((!empty($msg_form))&&($ajax_on))
{
if(($msg_form[0]==MSG_UTILISA_MAJ_INFOS_VALID)&&(!empty($abo_maj->id_abonnement)))
echo $abo_maj->id_abonnement;//tout s'est bien passé, je recharge l'abonnement en ajax
elseif($msg_form[0]==MSG_UTILISA_MAJ_SUPPR_VALID)
echo str_replace("\"","'",MSG_UTILISA_MAJ_SUPPR_VALID);//pour comparaison en JS
else
echo get_html_alerte_msg($msg_form);
}