function tNG_FormValidation()
 {
     $this->tNG = null;
     $this->validationRules = array();
     $this->loadValidatioRules($this->validationRules);
     $this->loadGenericValidationMessages($this->genericValidationMessages);
     KT_getInternalTimeFormat();
 }
/**
 * Wrapper for KT_convertDate
 * For internal use
 * @param string $date The date in input format
 * @param string $toScreen if $toScreen == 'toscreen' the date will be outputed in screen format; otherwise in database format
 * @return string the date in the new format
 */
function KT_convertDateCall($date, $toScreen = '')
{
    if (!isset($GLOBALS['KT_screen_time_format_internal'])) {
        KT_getInternalTimeFormat();
    }
    if (!preg_match('/^([\\d-\\/\\[\\]\\(\\)\\s\\*\\|\\+\\.:=,]|a|p|am|pm)+$/i', $date)) {
        return $date;
    }
    $date = str_replace('1900-01-01 ', '', $date);
    if (preg_match('/^\\d+$/', $date)) {
        if (strlen(trim($date)) == 14) {
            $newDate = substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-' . substr($date, 6, 2);
            $newDate .= ' ' . substr($date, 8, 2) . ':' . substr($date, 10, 2) . ':' . substr($date, 12, 2);
            $date = $newDate;
            $from = 'yyyy-mm-dd HH:ii:ss';
            $to = $GLOBALS['KT_screen_date_format'] . ' ' . $GLOBALS['KT_screen_time_format_internal'];
        } else {
            return $date;
        }
    }
    if (!preg_match('/^(\\d+[-\\/\\[\\]\\(\\)\\s\\*\\|\\+\\.=,]\\d+[-\\/\\[\\]\\(\\)\\s\\*\\|\\+\\.=,]\\d+)+/i', $date) && !preg_match('/^\\d+:\\d+(:\\d+|\\s+a|\\s+p|\\s+am|\\s+pm)/i', $date)) {
        return $date;
    }
    if ($toScreen == '' && preg_match('/^\\d+[-\\/\\[\\]\\(\\)\\s\\*\\|\\+\\.=,]\\d+[-\\/\\[\\]\\(\\)\\s\\*\\|\\+\\.=,]\\d+\\s+\\d+/i', $date)) {
        $date = KT_expandTime($date);
    }
    if (strstr($date, ' ') && strstr($date, ':') && strpos($date, ' ') < strpos($date, ':')) {
        $from = $GLOBALS['KT_screen_date_format'] . ' ' . $GLOBALS['KT_screen_time_format_internal'];
        $to = $GLOBALS['KT_db_date_format'] . ' ' . $GLOBALS['KT_db_time_format_internal'];
    } elseif (strstr($date, ':')) {
        $from = $GLOBALS['KT_screen_time_format_internal'];
        $to = $GLOBALS['KT_db_time_format_internal'];
    } else {
        $from = $GLOBALS['KT_screen_date_format'];
        $to = $GLOBALS['KT_db_date_format'];
    }
    if ($toScreen == 'toscreen') {
        $tmp = $from;
        $from = $to;
        $to = $tmp;
    }
    $date = KT_convertDate($date, $from, $to);
    if ($toScreen == 'toscreen') {
        $date = KT_stripTime($date);
    }
    return $date;
}
Exemple #3
0
 /**
  * transform the date value in a valid SQL condition; used for calculating the filter
  * @param string column name;
  * @param array column array information
  * @param column value;
  * @return string;
  * @access public
  */
 function prepareDateCondition($columnName, &$arr, $value)
 {
     $year = '';
     $month = '';
     $day = '';
     $hour = '';
     $min = '';
     $sec = '';
     $dateType = '';
     $modifier = '';
     $date1 = '';
     $date2 = '';
     $compareType1 = '';
     $compareType2 = '';
     $condJoin = '';
     $cond = '';
     $myDate = '';
     $dateArr = array();
     if (!isset($GLOBALS['KT_db_time_format_internal'])) {
         KT_getInternalTimeFormat();
     }
     // extract modifier and date from value
     if (preg_match('/^(<|>|=|<=|>=|=<|=>|<>|!=)\\s*\\d+.*$/', $value, $matches)) {
         $modifier = trim($matches[1]);
         $value = trim(substr($value, strlen($modifier)));
     } elseif (preg_match('/^[^\\d]+/', $value)) {
         $ret = '';
         return $ret;
     }
     // prepare modifier for databases that do not support !=
     if ($modifier == '!=') {
         $modifier = '<>';
     }
     /* date pieces isolation */
     // year only
     if (preg_match('/^\\d+$/', $value)) {
         $dateType = 'y';
         $year = $value;
     }
     // year month
     if (preg_match('/^\\d+[-\\/\\[\\]\\(\\)\\*\\|\\+\\.=,]{1}\\d+$/', $value)) {
         $dateType = 'm';
         $dateArr = preg_split('/([-\\/\\[\\]\\(\\)\\*\\|\\+\\.=,])/', $value, -1, PREG_SPLIT_NO_EMPTY);
         $month = $dateArr[0];
         $year = $dateArr[1];
         if (strlen($month) > 2) {
             $month = $dateArr[1];
             $year = $dateArr[0];
         }
     }
     // full date (year, month, day)
     if (preg_match('/^\\d+[-\\/\\[\\]\\(\\)\\*\\|\\+\\.=,]{1}\\d+[-\\/\\[\\]\\(\\)\\*\\|\\+\\.=,]{1}\\d+$/', $value)) {
         $dateType = 'd';
         list($year, $month, $day) = $this->getDateParts($value);
     }
     // full date & hour
     if (preg_match('/^\\d+[-\\/\\[\\]\\(\\)\\*\\|\\+\\.=,]{1}\\d+[-\\/\\[\\]\\(\\)\\*\\|\\+\\.=,]{1}\\d+\\s+\\d+[^\\d]*$/', $value)) {
         $dateType = 'h';
         $myParts = strpos($value, ' ');
         $datePart = substr($value, 0, $myParts);
         $timePart = substr($value, $myParts + 1);
         list($year, $month, $day) = $this->getDateParts($datePart);
         list($hour, $min, $sec) = $this->getTimeParts($timePart, 'HH');
     }
     // full date + hour, minutes
     if (preg_match('/^\\d+[-\\/\\[\\]\\(\\)\\*\\|\\+\\.=,]{1}\\d+[-\\/\\[\\]\\(\\)\\*\\|\\+\\.=,]{1}\\d+\\s+\\d+:\\d+[^\\d]*$/', $value)) {
         $dateType = 'i';
         $myParts = strpos($value, ' ');
         $datePart = substr($value, 0, $myParts);
         $timePart = substr($value, $myParts + 1);
         list($year, $month, $day) = $this->getDateParts($datePart);
         list($hour, $min, $sec) = $this->getTimeParts($timePart, 'HH:ii');
     }
     // full date time
     if (preg_match('/^\\d+[-\\/\\[\\]\\(\\)\\*\\|\\+\\.=,]{1}\\d+[-\\/\\[\\]\\(\\)\\*\\|\\+\\.=,]{1}\\d+\\s+\\d+:\\d+:\\d+[^\\d]*$/', $value)) {
         $dateType = 's';
         $myParts = strpos($value, ' ');
         $datePart = substr($value, 0, $myParts);
         $timePart = substr($value, $myParts + 1);
         list($year, $month, $day) = $this->getDateParts($datePart);
         list($hour, $min, $sec) = $this->getTimeParts($timePart, 'HH:ii:ss');
     }
     if ($dateType == '') {
         $dateType = 't';
         $value = KT_formatDate2DB($value);
     }
     /* prepare date parts */
     // 1 or 2 digits year
     if (preg_match('/^\\d{1,2}$/', $year)) {
         if ($year < 70) {
             $year = 2000 + $year;
         } else {
             $year = 1900 + $year;
         }
     }
     if ($month < 1 || $month > 12) {
         $month = '01';
     }
     if ($hour > 23) {
         $hour = '00';
     }
     if ($min > 59) {
         $min = '00';
     }
     if ($sec > 59) {
         $sec = '00';
     }
     /* prepare condition operators based on modifiers */
     switch ($modifier) {
         case '>=':
             $compareType1 = '>=';
             $compareType2 = '';
             $condJoin = '';
             break;
         case '<=':
             $compareType1 = '';
             $compareType2 = '<=';
             $condJoin = '';
             break;
         case '<':
             $compareType1 = '<';
             $compareType2 = '';
             $condJoin = '';
             break;
         case '>':
             $compareType1 = '';
             $compareType2 = '>';
             $condJoin = '';
             break;
         case '<>':
             $compareType1 = '<';
             $compareType2 = '>';
             $condJoin = 'OR';
             break;
         default:
             $compareType1 = '>=';
             $compareType2 = '<=';
             $condJoin = 'AND';
             break;
     }
     /* prepare dates for filtering */
     switch ($dateType) {
         case 'y':
             $date1 = KT_convertDate($year . '-01-01', 'yyyy-mm-dd', $GLOBALS['KT_db_date_format']);
             $date2 = KT_convertDate($year . '-12-31', 'yyyy-mm-dd', $GLOBALS['KT_db_date_format']);
             break;
         case 'm':
             $date1 = KT_convertDate($year . '-' . $month . '-01', 'yyyy-mm-dd', $GLOBALS['KT_db_date_format']);
             $maxday = KT_getDaysOfMonth($month, $year);
             $date2 = KT_convertDate($year . '-' . $month . '-' . $maxday, 'yyyy-mm-dd', $GLOBALS['KT_db_date_format']);
             break;
         case 'd':
             $date1 = KT_convertDate($year . '-' . $month . '-' . $day . ' 00:00:00', 'yyyy-mm-dd HH:ii:ss', $GLOBALS['KT_db_date_format'] . ' ' . $GLOBALS['KT_db_time_format_internal']);
             $date2 = KT_convertDate($year . '-' . $month . '-' . $day . ' 23:59:59', 'yyyy-mm-dd HH:ii:ss', $GLOBALS['KT_db_date_format'] . ' ' . $GLOBALS['KT_db_time_format_internal']);
             break;
         case 'h':
             $date1 = KT_convertDate($year . '-' . $month . '-' . $day . ' ' . $hour . ':00:00', 'yyyy-mm-dd HH:ii:ss', $GLOBALS['KT_db_date_format'] . ' ' . $GLOBALS['KT_db_time_format_internal']);
             $date2 = KT_convertDate($year . '-' . $month . '-' . $day . ' ' . $hour . ':59:59', 'yyyy-mm-dd HH:ii:ss', $GLOBALS['KT_db_date_format'] . ' ' . $GLOBALS['KT_db_time_format_internal']);
             break;
         case 'i':
             $date1 = KT_convertDate($year . '-' . $month . '-' . $day . ' ' . $hour . ':' . $min . ':00', 'yyyy-mm-dd HH:ii:ss', $GLOBALS['KT_db_date_format'] . ' ' . $GLOBALS['KT_db_time_format_internal']);
             $date2 = KT_convertDate($year . '-' . $month . '-' . $day . ' ' . $hour . ':' . $min . ':59', 'yyyy-mm-dd HH:ii:ss', $GLOBALS['KT_db_date_format'] . ' ' . $GLOBALS['KT_db_time_format_internal']);
             break;
         case 's':
             $date1 = KT_convertDate($year . '-' . $month . '-' . $day . ' ' . $hour . ':' . $min . ':' . $sec, 'yyyy-mm-dd HH:ii:ss', $GLOBALS['KT_db_date_format'] . ' ' . $GLOBALS['KT_db_time_format_internal']);
             $date2 = KT_convertDate($year . '-' . $month . '-' . $day . ' ' . $hour . ':' . $min . ':' . $sec, 'yyyy-mm-dd HH:ii:ss', $GLOBALS['KT_db_date_format'] . ' ' . $GLOBALS['KT_db_time_format_internal']);
             $compareType1 = '=';
             $compareType2 = '';
             $condJoin = '';
             break;
         case 't':
             $date1 = $value;
             $date2 = '';
             $compareType1 = '=';
             $compareType2 = '';
             $condJoin = '';
             break;
         default:
             $dateType = '';
             $compareType1 = '';
             $compareType2 = '';
             $condJoin = '';
             break;
     }
     if ($dateType != '') {
         $cond = '(';
         if ($compareType1 != '') {
             $cond .= KT_escapeFieldName($columnName) . ' ' . $compareType1 . ' ' . KT_escapeForSql($date1, $arr['type']);
         }
         if ($compareType2 != '') {
             if ($compareType1 != '') {
                 $cond .= ' ' . $condJoin . ' ';
             }
             $cond .= KT_escapeFieldName($columnName) . ' ' . $compareType2 . ' ' . KT_escapeForSql($date2, $arr['type']);
         }
         $cond .= ')';
     }
     return $cond;
 }