function getNumberOfDaysBetween($s_date1, $s_date2)
{
    return sizeof(getDaysBetween($s_date1, $s_date2));
}
Exemplo n.º 2
0
function runShowEventCountdown($input, $argv, $parser)
{
    $now = time();
    if (!array_key_exists('date', $argv)) {
        return '';
    }
    $then = strtotime($argv['date']);
    $daysUntil = getDaysBetween($now, $then);
    $output = '';
    if ($daysUntil > 0) {
        $output = parse($parser, $input);
    }
    return $output;
}
 function deleteOldRecords()
 {
     parent::deleteOldRecords();
     // delete records in VISIT that are useless
     // (means when week AND month using these records are archived)
     if (($this->periodType === DB_ARCHIVES_PERIOD_MONTH || $this->periodType === DB_ARCHIVES_PERIOD_WEEK) && $this->state !== DB_ARCHIVES_TEMP) {
         // select all weeks and months begin and end
         $r = query("SELECT date1, date2, idsite, period, idarchives\n\t\t\t\t\t\tFROM " . T_ARCHIVES . "\n\t\t\t\t\t\tWHERE done = " . DB_ARCHIVES_DONE . "\n\t\t\t\t\t\t\tAND (period = " . DB_ARCHIVES_PERIOD_WEEK . "\n\t\t\t\t\t\t\t\tOR period = " . DB_ARCHIVES_PERIOD_MONTH . "\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t");
         while ($l = mysql_fetch_assoc($r)) {
             // stock all dates between these two in an array
             $dateBetween = getDaysBetween($l['date1'], $l['date2']);
             //print($l['idarchives'] ."<br>");
             //print( $l['date1'].",". $l['date2']." id=:". $l['idsite']." period=:". $l['period']." "	);
             //print_r($dateBetween); print("<br> which is ".sizeof($dateBetween)." elements <br><br>");
             if (isset($flag[$l['idsite']][$l['period']][$l['date1']])) {
                 $c = $flag[$l['idsite']][$l['period']][$l['date1']];
                 if (sizeof($c) < sizeof($dateBetween) && sizeof($dateBetween) >= 7) {
                     $flag[$l['idsite']][$l['period']][$l['date1']] = $dateBetween;
                 }
             } else {
                 $flag[$l['idsite']][$l['period']][$l['date1']] = $dateBetween;
             }
         }
         //exit;
         foreach ($flag as $idsite => $a_idsite) {
             foreach ($a_idsite as $period => $a_period) {
                 foreach ($a_period as $a_date) {
                     foreach ($a_date as $d) {
                         if (!isset($toCheck[$idsite][$d])) {
                             $toCheck[$idsite][$d] = 1;
                         } else {
                             $toCheck[$idsite][$d]++;
                         }
                     }
                 }
             }
         }
         //print("<pre>Apres sommes des dates <br>");
         //print_r($toCheck);
         $deleted = 0;
         foreach ($toCheck as $idsite => $a_date) {
             foreach ($a_date as $date => $hits) {
                 // for the days who have 2 hits (mean that weeks and month that contain
                 // this day are archived)
                 // delete these day records!
                 if ($hits > 1) {
                     $r = query("DELETE\n\t\t\t\t\t\t\t\t\tFROM " . T_VISIT . "\n\t\t\t\t\t\t\t\t\tWHERE server_date = '" . $date . "'\n\t\t\t\t\t\t\t\t\t\tAND idsite = {$idsite}\n\t\t\t\t\t\t\t\t\t\t");
                     $deleted += mysql_affected_rows();
                 }
             }
         }
         //print("rows deleted = $deleted");
         if (time() % 3 == 0) {
             $r = query("OPTIMIZE TABLE " . T_VISIT);
         }
     }
 }