public static function checkDate($month, $day, $year, $mandatory = false) { if (!$mandatory && (empty($month) && empty($day) && empty($year))) { return true; } return checkDate($month, $day, $year); }
public function run() { global $ilDB, $ilLog, $ilSetting, $lng; $status = ilCronJobResult::STATUS_NO_ACTION; $lng->loadLanguageModule('forum'); if (!($last_run_datetime = $ilSetting->get('cron_forum_notification_last_date'))) { $last_run_datetime = null; } $numRows = 0; $types = array(); $values = array(); if ($last_run_datetime != null && checkDate(date('m', strtotime($last_run_datetime)), date('d', strtotime($last_run_datetime)), date('Y', strtotime($last_run_datetime)))) { $threshold = max(strtotime($last_run_datetime), strtotime('-' . (int) $this->settings->get('max_notification_age', 30) . ' days', time())); } else { $threshold = strtotime('-' . (int) $this->settings->get('max_notification_age', 30) . ' days', time()); } $date_condition = ' frm_posts.pos_date >= %s AND '; $types[] = 'timestamp'; $values[] = date('Y-m-d H:i:s', $threshold); $cj_start_date = date('Y-m-d H:i:s'); /*** FORUMS ***/ $res = $ilDB->queryf(' SELECT frm_threads.thr_subject thr_subject, frm_data.top_name top_name, frm_data.top_frm_fk obj_id, frm_notification.user_id user_id, frm_posts.* FROM frm_notification, frm_posts, frm_threads, frm_data WHERE ' . $date_condition . ' frm_posts.pos_thr_fk = frm_threads.thr_pk AND frm_threads.thr_top_fk = frm_data.top_pk AND frm_data.top_frm_fk = frm_notification.frm_id ORDER BY frm_posts.pos_date ASC', $types, $values); $numRows += $this->sendMails($res); /*** THREADS ***/ $res = $ilDB->queryf(' SELECT frm_threads.thr_subject thr_subject, frm_data.top_name top_name, frm_data.top_frm_fk obj_id, frm_notification.user_id user_id, frm_posts.* FROM frm_notification, frm_posts, frm_threads, frm_data WHERE ' . $date_condition . ' frm_posts.pos_thr_fk = frm_threads.thr_pk AND frm_threads.thr_pk = frm_notification.thread_id AND frm_data.top_pk = frm_threads.thr_top_fk ORDER BY frm_posts.pos_date ASC', $types, $values); $numRows += $this->sendMails($res); $ilSetting->set('cron_forum_notification_last_date', $cj_start_date); $mess = 'Send ' . $numRows . ' messages.'; $ilLog->write(__METHOD__ . ': ' . $mess); $result = new ilCronJobResult(); if ($numRows) { $status = ilCronJobResult::STATUS_OK; $result->setMessage($mess); } $result->setStatus($status); return $result; }
public function process(Zend_Controller_Request_Abstract $request) { //echo "<br/>here at process."; $this->title = $this->sanitize($request->getPost('username')); $this->title = substr($this->title, 0, 255); if (strlen($this->title) == 0) { $this->addError('title', 'Please enter a title for this post'); //this is a giving FormProcessor.php function. } $this->title_link = $this->sanitize($request->getPost('title_link')); //echo "the current year is: ".$request->getPost('ts_createdYear'); //echo "the current month is: ".$request->getPost('ts_createdMonth'); $date = array('y' => (int) $request->getPost('ts_createdYear'), 'm' => (int) $request->getPost('ts_createdMonth'), 'd' => (int) $request->getPost('ts_createdDay')); $time = array('h' => (int) $request->getPost('ts_createdHour'), 'm' => (int) $request->getPost('ts_createdMinute')); $time['h'] = max(1, min(12, $time['h'])); $time['m'] = max(0, min(59, $time['m'])); $meridian = strtolower($request->getPost('ts_createdMeridian')); if ($meridian != 'pm') { $meridian = 'am'; } //conver the hour into 23 hour time if ($time['h'] < 12 && $meridian == 'pm') { $time['h'] += 12; } else { if ($time['h'] == 12 && $meridian == 'am') { $time['h'] = 0; } } if (!checkDate($date['m'], $date['d'], $date['y'])) { $this->addError('ts_created', 'Please select a valid date'); } $this->ts_created = mktime($time['h'], $time['m'], 0, $date['m'], $date['d'], $date['y']); //echo "the time that is created is: ".date('Y-m-d', $this->ts_created); $this->content = self::cleanHtml($request->getPost('content')); //echo "<br/>here before there is error()."; if (!$this->hasError()) { $this->post->profile->title = $this->title; $this->post->ts_created = $this->ts_created; $this->post->profile->content = $this->content; $this->post->profile->title_link = $this->title_link; $preview = !is_null($request->getPost('preview')); if (!$preview) { $this->post->sendLive(); } $this->post->save(); } return !$this->hasError(); }
public function process(Zend_Controller_Request_Abstract $request) { $this->title = $this->sanitize($request->getPost('username')); $this->title = substr($this->title, 0, 255); if (strlen($this->title) == 0) { $this->addError('title', 'Please enter a title for this post'); } $date = array('y' => (int) $request->getPost('ts_createdYear'), 'm' => (int) $request->getPost('ts_createdMonth'), 'd' => (int) $request->getPost('ts_createdDay')); $time = array('h' => (int) $request->getPost('ts_createdHour'), 'm' => (int) $request->getPost('ts_createdMinute')); $time['h'] = max(1, min(12, $time['h'])); $time['m'] = max(0, min(59, $time['m'])); $meridian = strtolower($request->getPost('ts_createdMeridian')); if ($meridian != 'pm') { $meridian = 'am'; } if ($time['h'] < 12 && $meridian == 'pm') { $time['h'] += 12; } else { if ($time['h'] == 12 && $meridian == 'am') { $time['h'] = 0; } } if (!checkDate($date['m'], $date['d'], $date['y'])) { $this->addError('ts_created', 'Please select a valid date'); } $this->ts_created = mktime($time['h'], $time['m'], 0, $date['m'], $date['d'], $date['y']); $this->content = $this->cleanHtml($request->getPost('content')); if (!$this->hasError()) { $this->post->profile->title = $this->title; $this->post->ts_created = $this->ts_created; $this->post->profile->content = $this->content; $preview = !is_null($request->getPost('preview')); if (!$preview) { $this->post->sendLive(); } $this->post->save(); } return !$this->hasError(); }
echo $TEXT['bio-ok']; ?> "> <input type="hidden" name="showpng" value="1"> </form> <?php include 'showcode.php'; pageFooter(); exit; } // get different parts of the date $birthMonth = substr($_REQUEST['birthdate'], 0, 2); $birthDay = substr($_REQUEST['birthdate'], 3, 2); $birthYear = substr($_REQUEST['birthdate'], 6, 4); // check date for validity, display error message if invalid if (!@checkDate($birthMonth, $birthDay, $birthYear)) { pageHeader(); //print("The date '$birthMonth/$birthDay/$birthYear' is invalid."); echo "<h2>" . $TEXT['bio-error1'] . " '{$birthMonth}/{$birthDay}/{$birthYear}' " . $TEXT['bio-error2'] . ".</h2>"; pageFooter(); exit; } if (isset($_POST['showpng']) && $_POST['showpng'] == 1) { pageHeader(); echo "<img src='" . basename($_SERVER['PHP_SELF']) . "?" . htmlentities("birthdate=" . urlencode($_REQUEST['birthdate'])) . "' alt=''>"; pageFooter(); exit; } // specify diagram parameters (these are global) $diagramWidth = 710; $diagramHeight = 400;
function isValidDateIso($date) { $dateLen = strlen($date); switch ($dateLen) { case 4: // pouze rok YYYY if (preg_match('/[0-9]{4}/', $date)) { return true; } else { return false; } case 7: // YYYY-MM if (preg_match('/[0-9]{4}\\-[0-9]{2}/', $date)) { if (substr($date, 5, 2) < 13) { return true; } else { return false; } } else { return false; } case 10: // YYYY-MM-DD if (preg_match('/[0-9]{4}\\-[0-9]{2}\\-[0-9]{2}/', $date)) { list($year, $month, $day) = explode("-", $date); if (checkDate($month, $day, $year)) { return true; } else { return false; } } else { return false; } default: // špatný tvar datumu return false; } }
require_once "config.php"; require_once "functions.php"; # Set the timezone for the date() function date_default_timezone_set("America/Los_Angeles"); # Retrieve the input and clean it for database insertion. $challenger = cleanInputs($_POST['challenger'], $connection); $challengee = cleanInputs($_POST['challengee'], $connection); $issueDate = date("Y-m-d"); # Convert the times received to a timestamp for insertion into the database. $scheduleDate = cleanInputs($_POST['date'], $connection); $scheduleTime = cleanInputs($_POST['time'], $connection); $challengeDate = $scheduleDate . " " . $scheduleTime; # Before attempting to insert the challenge, perform one final # check to make sure that the given date is valid. $toCheck = split("-", $scheduleDate); $validDate = checkDate($toCheck[1], $toCheck[2], $toCheck[0]); if ($validDate) { # Insert the new challenge into the database. $challengeSuccess = mysqli_query($connection, "INSERT INTO challenge (challenger, challengee, issued, scheduled) \n VALUES ('{$challenger}', '{$challengee}', '{$issueDate}', '{$challengeDate}')"); } else { $challengeSuccess = false; } ?> <!DOCTYPE html> <html> <head> <title>Wrath of Titans - Issue Challenge</title> <!-- CSS Inclusion --> <link href="../../styles/reset.css" rel="stylesheet" type="text/css" />
function DateField($title, $name, $interval = "90:90", $callback = false, $format = 'd-m-y', $extra = '') { //get the current value of the field $value = $this->value($name); // get the year interval for the dates in the field if (strpos($interval, ':')) { list($start, $end) = split(':', $interval, 2); } elseif (is_string($interval) || is_integer($interval) && !empty($interval)) { $start = $interval; $end = 90; } else { $start = 90; $end = 90; } // if the form is posted, get the date in a correct format ? if ($this->posted) { $fmt = str_replace(array('y', 'm', 'd'), array('^', '^', '^'), strToLower($format)); $fmt = explode('^', $fmt); $tmp = $value; foreach ($fmt as $splitter) { if ($splitter == '') { continue; } $pos = strpos($tmp, $splitter); if ($pos !== false) { $parts[] = substr($tmp, 0, $pos); $tmp = substr($tmp, $pos + strLen($splitter)); } } $parts[] = $tmp; $i = $teller = 0; $value = strToLower($format); for ($i = 0; $i < strLen($value); $i++) { $c = substr($value, $i, 1); if (in_array($c, array('y', 'm', 'd')) && $this->ArrayKeyExists($teller, $parts)) { switch ($c) { case 'y': $jaar = $parts[$teller++]; break; case 'm': $maand = $parts[$teller++]; break; case 'd': $dag = $parts[$teller++]; break; } } } if (!isset($dag)) { $dag = ''; } if (!isset($maand)) { $maand = ''; } if (!isset($jaar)) { $jaar = ''; } } else { if (ereg('^([0-9]{4})[-]([0-9]{1,2})[-]([0-9]{1,2})$', $value)) { list($jaar, $maand, $dag) = explode("-", $value); } else { list($dag, $maand, $jaar) = explode('-', $value == '' ? date("j-n-Y") : $value); } } // generate the day field $field = "<select name='{$name}_dag' {$extra}>"; for ($i = 1; $i <= 31; $i++) { $selected = $dag == $i ? ' selected="selected"' : ""; $field .= "\n\t<option value=\"" . sprintf("%02d", $i) . "\"{$selected}>{$i}</option>"; } $field .= "\n </select>\n" . " <select name='{$name}_maand' {$extra}>"; // generate the month field $maanden = $this->_months; for ($i = 0; $i < count($maanden); $i++) { $selected = $maand == $i + 1 ? ' selected="selected"' : ""; $field .= "\n\t<option value=\"" . sprintf("%02d", $i + 1) . "\"{$selected}>" . $maanden[$i] . "</option>"; } $field .= "\n </select>\n" . " <select name='{$name}_jaar' {$extra}>"; // generate the year field // for($i = date("Y") + intval($end); $i >= date("Y") - intval($start); $i--) { // for($i = (date("Y") - intval($start)); $i < (date("Y") + intval($end)); $i++){ date_default_timezone_set('UTC'); for ($i = date("Y") - 90; $i < date("Y") + 90; $i++) { $selected = $i == $jaar ? ' selected="selected"' : ""; $field .= "\n\t<option value=\"" . $i . "\"" . $selected . ">" . $i . "</option>"; } $field .= "\n </select>\n" . " <input type='hidden' size='5' value='{$format}' name='{$name}_format' />\n"; // check the value of the field $error = $this->callUserFunction($callback, $value); if ($this->posted) { $error = checkDate($maand, $dag, $jaar) ? $error : "{$dag} - {$maand} - {$jaar}: " . $this->_date; } // put the field in the form $this->generateField($title, $field, $name, $error); }
function validDate($DateString) { $DateTime = explode(' ', $DateString); if (count($DateTime) != 2) { return false; } list($Date, $Time) = $DateTime; $SplitTime = explode(':', $Time); if (count($SplitTime) != 3) { return false; } list($H, $M, $S) = $SplitTime; if ($H != 0 && !(is_number($H) && $H < 24 && $H >= 0)) { return false; } if ($M != 0 && !(is_number($M) && $M < 60 && $M >= 0)) { return false; } if ($S != 0 && !(is_number($S) && $S < 60 && $S >= 0)) { return false; } $SplitDate = explode('-', $Date); if (count($SplitDate) != 3) { return false; } list($Y, $M, $D) = $SplitDate; return checkDate($M, $D, $Y); }
public function validateDate($month, $day, $year, $fieldId) { $yearRange = $this->_helper->getYearRange(); list($yearFrom, $yearTo) = explode(',', $yearRange); if (!checkDate($month, $day, $year) || $year < $yearFrom || $year > $yearTo) { return "'" . $this->_fieldTitle . "' is not valid"; } $day += 1; $dateToFormat = "{$year}-{$month}-{$day}"; //$dateToFormat = '2011-12-11'; $this->_dateToBeSaved[$fieldId] = Mage::helper('core')->formatDate($dateToFormat, 'long', false); return; }
public function process(Zend_Controller_Request_Abstract $request) { //echo "<br/>here at process."; $this->name = $this->sanitize($request->getPost('title')); $this->name = substr($this->name, 0, 255); if (strlen($this->name) == 0) { $this->addError('title', 'Please enter a title for this post'); //this is a giving FormProcessor.php function. } $cdate = array('y' => (int) $request->getPost('ts_createdYear'), 'm' => (int) $request->getPost('ts_createdMonth'), 'd' => (int) $request->getPost('ts_createdDay')); $ctime = array('h' => (int) $request->getPost('ts_createdHour'), 'm' => (int) $request->getPost('ts_createdMinute')); $ctime['h'] = max(1, min(12, $ctime['h'])); $ctime['m'] = max(0, min(59, $ctime['m'])); $cmeridian = strtolower($request->getPost('ts_createdMeridian')); if ($cmeridian != 'pm') { $cmeridian = 'am'; } //conver the hour into 23 hour time if ($ctime['h'] < 12 && $cmeridian == 'pm') { $ctime['h'] += 12; } else { if ($ctime['h'] == 12 && $cmeridian == 'am') { $ctime['h'] = 0; } } if (!checkDate($cdate['m'], $cdate['d'], $cdate['y'])) { $this->addError('ts_created', 'Please select a valid date'); } $this->ts_created = mktime($ctime['h'], $ctime['m'], 0, $cdate['m'], $cdate['d'], $cdate['y']); //echo "<br/>you are at the end of firs ttime"; //------------------------------------------------------------------------------ $edate = array('y' => (int) $request->getPost('ts_endYear'), 'm' => (int) $request->getPost('ts_endMonth'), 'd' => (int) $request->getPost('ts_endDay')); $etime = array('h' => (int) $request->getPost('ts_endHour'), 'm' => (int) $request->getPost('ts_endMinute')); $etime['h'] = max(1, min(12, $etime['h'])); $etime['m'] = max(0, min(59, $etime['m'])); $emeridian = strtolower($request->getPost('ts_endMeridian')); if ($emeridian != 'pm') { $emeridian = 'am'; } //conver the hour into 23 hour time if ($etime['h'] < 12 && $emeridian == 'pm') { $etime['h'] += 12; } else { if ($etime['h'] == 12 && $emeridian == 'am') { $etime['h'] = 0; } } if (!checkDate($edate['m'], $edate['d'], $edate['y'])) { $this->addError('ts_created', 'Please select a valid date'); } $this->ts_end = mktime($etime['h'], $etime['m'], 0, $edate['m'], $edate['d'], $edate['y']); //echo "<br/>you are at the end of the second time"; //----------------------------------------------------------------------------- $this->ticket_price = $this->sanitize(trim($request->getPost('ticket_price'))); //echo "<br/>your ticket_price is: ".$this->ticket_price; if ($this->ticket_price == 'FREE') { //echo "<br/>after ticket_price"; $this->ticket_price = (int) 0; //echo "<br/>after ticket_price is: ".$this->ticket_price; } if ($this->ticket_price == '') { $this->ticket_price = (int) 0; } if (!is_numeric($this->ticket_price)) { $this->addError('ticket_price', 'Please enter a valid product price'); } $this->content = FormProcessor_BlogPost::cleanHtml($request->getPost('content')); $this->location = $this->sanitize($request->getPost('location')); //echo "<br/>you are at after clean HTML"; if (!$this->hasError()) { //echo "<br/>you are at no error"; $this->event->profile->name = $this->name; $this->event->profile->price = $this->ticket_price; $this->event->profile->content = $this->content; $this->event->ts_created = $this->ts_created; $this->event->ts_end = $this->ts_end; $this->event->profile->location = $this->location; //echo "<br/>you are at before save()"; $this->event->save(); } //echo "<br/>you are at before return"; return !$this->hasError(); }
} $out[$field . '_NEXT_MONTH'] = date('m/01/Y', $tm + 30 * 24 * 60 * 60); if (checkDate(date('m', $tm + 30 * 24 * 60 * 60), $last_days[(int) date('m', $tm + 30 * 24 * 60 * 60) - 1], date('Y', $tm + 30 * 24 * 60 * 60))) { $out[$field . '_NEXT_MONTH_TO'] = date('m/' . $last_days[(int) date('m', $tm + 30 * 24 * 60 * 60) - 1] . '/Y', $tm + 30 * 24 * 60 * 60); } else { $out[$field . '_NEXT_MONTH_TO'] = date('m/' . ($last_days[(int) date('m', $tm + 30 * 24 * 60 * 60) - 1] - 1) . '/Y', $tm + 30 * 24 * 60 * 60); } $out[$field . '_THIS_MONTH'] = date('m/01/Y', $tm); if (checkDate(date('m', $tm), $last_days[(int) date('m', $tm) - 1], date('Y', $tm))) { $out[$field . '_THIS_MONTH_TO'] = date('m/' . $last_days[(int) date('m', $tm) - 1] . '/Y', $tm); } else { $out[$field . '_THIS_MONTH_TO'] = date('m/' . ($last_days[(int) date('m', $tm) - 1] - 1) . '/Y', $tm); } $days = array(); for ($i = 1; $i <= 31; $i++) { if (checkDate($month, $i, $yr)) { $tm = mktime(0, 0, 0, $month, $i, $yr); $rec = array(); $day = $i; if ($i < 10) { $day = "0{$i}"; } $rec['DAY'] = $i; $rec['DATE'] = "{$month}/{$day}/{$yr}"; $rec['DB_DATE'] = "{$yr}-{$month}-{$day}"; if ($field != '') { $event = SQLSelectOne("SELECT ID FROM userlog WHERE TO_DAYS({$field})=TO_DAYS('" . $rec['DB_DATE'] . "')"); if ($event['ID']) { $rec['EVENTS'] = 1; } }
public function sendNotifications() { global $ilDB, $ilLog, $ilSetting, $lng; $lng->loadLanguageModule('forum'); if (!($lastDate = $ilSetting->get('cron_forum_notification_last_date'))) { $lastDate = null; } $numRows = 0; $datecondition_frm = ''; $types = array(); $values = array(); if ($lastDate != null && checkDate(date('m', strtotime($lastDate)), date('d', strtotime($lastDate)), date('Y', strtotime($lastDate)))) { $datecondition_frm = ' frm_posts.pos_date >= %s AND '; $types[] = 'timestamp'; $values[] = $lastDate; } /*** FORUMS ***/ $res = $ilDB->queryf(' SELECT frm_threads.thr_subject thr_subject, frm_data.top_name top_name, frm_data.top_frm_fk obj_id, frm_notification.user_id user_id, frm_posts.* FROM frm_notification, frm_posts, frm_threads, frm_data WHERE ' . $datecondition_frm . ' frm_posts.pos_thr_fk = frm_threads.thr_pk AND frm_threads.thr_top_fk = frm_data.top_pk AND frm_data.top_frm_fk = frm_notification.frm_id ORDER BY frm_posts.pos_date ASC', $types, $values); $numRows += $this->sendMails($res); /*** THREADS ***/ $res = $ilDB->queryf(' SELECT frm_threads.thr_subject thr_subject, frm_data.top_name top_name, frm_data.top_frm_fk obj_id, frm_notification.user_id user_id, frm_posts.* FROM frm_notification, frm_posts, frm_threads, frm_data WHERE ' . $datecondition_frm . ' frm_posts.pos_thr_fk = frm_threads.thr_pk AND frm_threads.thr_pk = frm_notification.thread_id AND frm_data.top_pk = frm_threads.thr_top_fk ORDER BY frm_posts.pos_date ASC', $types, $values); $numRows += $this->sendMails($res); $ilSetting->set('cron_forum_notification_last_date', date('Y-m-d H:i:s')); $ilLog->write(__METHOD__ . ': Send ' . $numRows . ' messages.'); return true; }
function myCheckDate($dateValue) { $response = false; $formatMatch = preg_match("/^([0-9]{4})-([0-9]{2})-([0-9]{2})\$/", $dateValue); if ($formatMatch) { $dateParts = explode("-", $dateValue); $response = checkDate($dateParts[1], $dateParts[2], $dateParts[0]); } return $response; }