';
// All data (now)
$time["all"] = get_system_time ();
// 1 day ago
$time["1day"] = $time["all"]-86400;
// 3 days ago
$time["3day"] = $time["all"] - 259200;
// 1 week ago
$time["1week"] = $time["all"] - 604800;
// 2 weeks ago
$time["2week"] = $time["all"] - 1209600;
// 1 month ago
$time["1month"] = $time["all"] - 2592000;
// Three months ago
$time["3month"] = $time["all"] - 7776000;
//Init data
$data["1day"] = 0;
$data["3day"] = 0;
$data["1week"] = 0;
$data["2week"] = 0;
$data["1month"] = 0;
$data["3month"] = 0;
$data["total"] = 0;
// Purge data using dates
if (isset($_POST["purgedb"])) {
$from_date = get_parameter_post ("date_purge", 0);
if ($id_agent > 0) {
echo __('Purge task launched for agent')." ".get_agent_name ($id_agent)." :: ".__('Data older than')." ".human_time_description ($from_date);
echo "
".__('Please be patient. This operation can take a long time depending on the amount of modules.')."
";
$sql = sprintf ("SELECT id_agente_modulo FROM tagente_modulo WHERE id_agente = %d", $id_agent);
$result = get_db_all_rows_sql ($sql);
if (empty ($result)) {
$result = array ();
}
//Made it in a transaction so it gets done all at once.
process_sql_begin ();
$errors = 0;
$affected = 0;
foreach ($result as $row) {
echo __('Deleting records for module')." ".get_agentmodule_name ($row["id_agente_modulo"]);
echo " ";
flush (); //Flush here in case there are errors and the script dies, at least we know where we ended
set_time_limit (); //Reset the time limit just in case
$sql = sprintf ("DELETE FROM `tagente_datos` WHERE `id_agente_modulo` = %d AND `utimestamp` < %d",$row["id_agente_modulo"],$from_date);
$result = process_sql ($sql);
if ($result === false)
$errors++;
else
$affected += $result;
if ($errors == 0) {
$sql = sprintf ("DELETE FROM `tagente_datos_inc` WHERE `id_agente_modulo` = %d AND `utimestamp` < %d",$row["id_agente_modulo"],$from_date);
$result = process_sql ($sql);
if ($result === false)
$errors++;
else
$affected += $result;
}
if ($errors == 0) {
$sql = sprintf ("DELETE FROM `tagente_datos_string` WHERE `id_agente_modulo` = %d AND `utimestamp` < %d",$row["id_agente_modulo"],$from_date);
$result = process_sql ($sql);
if ($result === false)
$errors++;
else
$affected += $result;
}
if ($errors == 0) {
$sql = sprintf ("DELETE FROM `tagente_datos_log4x` WHERE `id_agente_modulo` = %d AND `utimestamp` < %d",$row["id_agente_modulo"],$from_date);
$result = process_sql ($sql);
if ($result === false)
$errors++;
else
$affected += $result;
}
}
if ($errors > 0) {
process_sql_rollback ();
} else {
process_sql_commit ();
echo __('Total records deleted: ') . $affected;
}
} else {
//All agents
echo __('Deleting records for all agents');
flush ();
$query = sprintf ("DELETE FROM `tagente_datos` WHERE `utimestamp` < %d",$from_date);
process_sql ($query);
$query = sprintf ("DELETE FROM `tagente_datos_inc` WHERE `utimestamp` < %d",$from_date);
process_sql ($query);
$query = sprintf ("DELETE FROM `tagente_datos_string` WHERE `utimestamp` < %d",$from_date);
process_sql ($query);
$query = sprintf ("DELETE FROM `tagente_datos_log4x` WHERE `utimestamp` < %d",$from_date);
process_sql ($query);
}
echo "