=' :'=';
switch ($type) {
case 'show_nb_data_to_purge':
$DATA_PURGE = "";
$years = $_REQUEST["years"];
sort($years);
$TOTALTOPURGE = 0;
foreach ($years as $year) {
$q = "SELECT COUNT(*) nb FROM (
SELECT
date_arrivee
FROM
ca_historique_clients
WHERE
date_arrivee BETWEEN '".$year."-01-01 00:00:00' AND '".$year."-12-31 23:59:59' ORDER BY date_arrivee DESC
) s ";
$result = excuteQuery($q);
$n = $result['stmt']->fetchObject();
if($_REQUEST['all'] && $_REQUEST['all']!=""){
$DATA_NB_PURGED = $n->nb;
}
$TOTALTOPURGE = $TOTALTOPURGE + $n->nb;
$DATA_PURGE .= " ".$year." (".$n->nb." visites)";
}
break;
case 'purgeText':
$LOG = "##########################################\r\n";
$LOG .= date('Y-m-d H:i:s')."\r\n";
$LOG .= "Purge ".$_REQUEST['from']." par ".$_SESSION['nom']." \r\n";
$fp = fopen ("../outils/logs/purge.txt", "a+");
fwrite($fp, $LOG);
fclose ($fp);
break;
case 'delete':
$q = "DELETE ca_historique_client_motifs FROM ca_historique_client_motifs
INNER JOIN ca_historique_clients ON ca_historique_client_motifs.id_client = ca_historique_clients.id_client
WHERE ca_historique_clients.date_arrivee BETWEEN '".$from."-01-01 00:00:00' AND '".$from."-12-31 23:59:59'";
$result = excuteQuery($q);
$q = "DELETE FROM ca_historique_clients WHERE date_arrivee BETWEEN '".$from."-01-01 00:00:00' AND '".$from."-12-31 23:59:59'";
$result = excuteQuery($q);
$afa = (isset($GLOBALS["BO_CONF"]["AFA"]) && $GLOBALS["BO_CONF"]["AFA"]) ? true : false;
if($afa){
$q = "DELETE FROM ca_historique_pile_cc WHERE date_arrivee BETWEEN '".$from."-01-01 00:00:00' AND '".$from."-12-31 23:59:59'";
$result = excuteQuery($q);
}
$q = "DELETE FROM ca_statistiques WHERE date_arrivee BETWEEN '".$from."-01-01 00:00:00' AND '".$from."-12-31 23:59:59'";
// $q = "UPDATE ca_historique_clients SET telephone = 222 WHERE date_arrivee BETWEEN '".$from."-01-01 00:00:00' AND '".$from."-12-31 23:59:59'";
// $q = "UPDATE ca_statistiques SET telephone = 555 WHERE date_arrivee BETWEEN '".$from."-01-01 00:00:00' AND '".$from."-12-31 23:59:59'";
$result = excuteQuery($q);
$DATA_NB_PURGED = $result['stmt']->rowCount();
$DATA_PURGE = " ".$from." (".$DATA_NB_PURGED." visites)";
break;
}
$output = array(
'data_purge' => $DATA_PURGE,
'data_nb_purged' => $DATA_NB_PURGED
);
if($type == 'show_nb_data_to_purge'){
$output['total_data_to_purge'] = $TOTALTOPURGE;
$output['years'] = $_REQUEST["years"];
}
if($type == 'delete'){
$output['year_purged'] = $from;
}
echo json_encode($output);