function checkCronJob($sPeriods, $aDate = array()) { $aParam = explode(' ', preg_replace("{ +}", ' ', trim($sPeriods))); $bRes = true; if (empty($aDate)) { $aDate = getdate(time()); } for ($i = 0; $i < count($aParam); $i++) { switch ($i) { case 0: $aRes = getPeriod($aParam[$i], 0, 59); $bRes = in_array($aDate['minutes'], $aRes); break; case 1: $aRes = getPeriod($aParam[$i], 0, 23); $bRes = in_array($aDate['hours'], $aRes); break; case 2: $aRes = getPeriod($aParam[$i], 1, 31); $bRes = in_array($aDate['mday'], $aRes); break; case 3: $aRes = getPeriod($aParam[$i], 1, 12); $bRes = in_array($aDate['mon'], $aRes); break; case 4: $aRes = getPeriod($aParam[$i], 0, 6); $bRes = in_array($aDate['wday'], $aRes); break; } if (!$bRes) { break; } } return $bRes; }
$options = getopt('r'); if (isset($options['r'])) { echo "Clearing history table.\n"; dbQuery('TRUNCATE TABLE `bill_history`'); } foreach (dbFetchRows('SELECT * FROM `bills` ORDER BY `bill_id`') as $bill) { echo str_pad($bill['bill_id'] . ' ' . $bill['bill_name'], 30) . " \n"; $i = 0; while ($i <= 24) { unset($class); unset($rate_data); $day_data = getDates($bill['bill_day'], $i); $datefrom = $day_data['0']; $dateto = $day_data['1']; $check = dbFetchRow('SELECT * FROM `bill_history` WHERE bill_id = ? AND bill_datefrom = ? AND bill_dateto = ? LIMIT 1', array($bill['bill_id'], $datefrom, $dateto)); $period = getPeriod($bill['bill_id'], $datefrom, $dateto); $date_updated = str_replace('-', '', str_replace(':', '', str_replace(' ', '', $check['updated']))); if ($period > 0 && $dateto > $date_updated) { $rate_data = getRates($bill['bill_id'], $datefrom, $dateto); $rate_95th = $rate_data['rate_95th']; $dir_95th = $rate_data['dir_95th']; $total_data = $rate_data['total_data']; $rate_average = $rate_data['rate_average']; if ($bill['bill_type'] == 'cdr') { $type = 'CDR'; $allowed = $bill['bill_cdr']; $used = $rate_data['rate_95th']; $allowed_text = format_si($allowed) . 'bps'; $used_text = format_si($used) . 'bps'; $overuse = $used - $allowed; $overuse = $overuse <= 0 ? '0' : $overuse;