Exemplo n.º 1
0
/**
 * Sets the value for a specific column
 * @param array &$colDetails column details (one element of the $column array)
 * @access private
 */
function tNG_prepareValues(&$colDetails)
{
    $type2alt = array('CHECKBOX_1_0_TYPE' => '1', 'CHECKBOX_-1_0_TYPE' => '-1', 'CHECKBOX_YN_TYPE' => "Y", 'CHECKBOX_TF_TYPE' => "t");
    if (isset($colDetails['method']) && isset($colDetails['reference']) && isset($colDetails['type'])) {
        $colValue = KT_getRealValue($colDetails['method'], $colDetails['reference']);
        if ($colDetails['method'] == 'VALUE') {
            $colValue = KT_DynamicData($colValue, null);
            if (isset($colDetails['default'])) {
                $colDetails['default'] = $colValue;
            }
        } elseif (isset($colDetails['default'])) {
            $colDetails['default'] = KT_DynamicData($colDetails['default'], null);
        }
        switch ($colDetails['type']) {
            case 'CHECKBOX_YN_TYPE':
            case 'CHECKBOX_1_0_TYPE':
            case 'CHECKBOX_-1_0_TYPE':
            case 'CHECKBOX_TF_TYPE':
                $colValue = !isset($colValue) ? '' : $type2alt[$colDetails['type']];
                break;
            case 'DATE_TYPE':
            case 'DATE_ACCESS_TYPE':
                $colValue = KT_formatDate2DB($colValue);
                if (isset($colDetails['default'])) {
                    $colDetails['default'] = KT_formatDate2DB($colDetails['default']);
                }
                break;
        }
    } else {
        $colValue = "";
    }
    $colDetails['value'] = $colValue;
}
Exemplo n.º 2
0
 /**
 	NAME:
 		Execute
 	DESCRIPTION:
 		validates the columnsValue based on regExp and required information
 	ARGUMENTS:
 		none - 
 		property used: 
 				$columns
 				$columnsValue
 	RETURN:
 		string - empty on succes , an error message if fails
 		property changed:
 			- none
 	**/
 function Execute()
 {
     $failed = false;
     $errObj = new tNG_error('', array(), array());
     if ($this->mustValidate && count($this->columns) > 0) {
         $columnKeys = array_keys($this->columns);
         $cols = count($columnKeys);
         for ($i = 0; $i < $cols; $i++) {
             $doRequiredVal = true;
             $colIdx = $columnKeys[$i];
             $column =& $this->columns[$colIdx];
             if (!in_array($column['name'], array_keys($this->tNG->columns))) {
                 continue;
             }
             // on update don't require FILE_TYPE and tNG password fields
             if ($this->tNG->getTransactionType() == '_update' || $this->tNG->getTransactionType() == '_multipleUpdate') {
                 if ($this->tNG->getColumnType($column['name']) == 'FILE_TYPE') {
                     $doRequiredVal = false;
                 }
                 if ($this->tNG->getTable() == $GLOBALS['tNG_login_config']["table"] && $column['name'] == $GLOBALS['tNG_login_config']["password_field"]) {
                     $doRequiredVal = false;
                 }
                 // if it is setted to CURRVAL is not required;
                 if ($this->tNG->columns[$column['name']]['method'] == 'CURRVAL') {
                     $doRequiredVal = false;
                 }
             }
             $hasRequiredError = false;
             $hasTypeError = false;
             $tmpFieldValue = $this->tNG->getColumnValue($column['name']);
             if ($column['type'] == 'date' && $column['format'] != '') {
                 if (!in_array($this->tNG->getColumnType($column['name']), array('DATE_TYPE', 'DATE_ACCESS_TYPE'))) {
                     $tmpFieldValue = KT_formatDate2DB($tmpFieldValue);
                 }
             }
             $column['failed'] = false;
             // required parameter validation
             $colCustomMsg = $column['message'];
             if ($doRequiredVal && $column['required']) {
                 if (strlen($colCustomMsg) == 0) {
                     $colCustomMsg = $this->genericValidationMessages['required'];
                 }
                 if ((string) $tmpFieldValue == '') {
                     $failed = true;
                     $hasRequiredError = true;
                     $column['failed'] = true;
                     if ($this->tNG->exportsRecordset() !== true) {
                         $colCustomMsg = KT_DynamicData($colCustomMsg, $this->tNG, '', $this->tNG->transactionType == '_delete');
                         $errObj->addDetails('%s', array($colCustomMsg), array($colCustomMsg));
                     } else {
                         $errObj->setFieldError($column['name'], '%s', array($colCustomMsg));
                     }
                 }
             }
             // type and format validation
             $colCustomMsg = $column['message'];
             if ($tmpFieldValue != '' && $column['type'] != '') {
                 if (strlen($colCustomMsg) == 0) {
                     $colCustomMsgBefore = $this->genericValidationMessages['format'];
                     $colCustomMsgAfter = $this->genericValidationMessages[$column['type'] . '_' . $column['format']];
                     $colCustomMsg = sprintf($colCustomMsgBefore, $colCustomMsgAfter);
                 }
                 $tmpFieldValue = substr($tmpFieldValue, 0, 400);
                 switch ($column['type']) {
                     case 'regexp':
                         $res = @preg_match($column['additional_params'], $tmpFieldValue);
                         if ($res === false) {
                             $hasTypeError = true;
                             $colCustomMsgBefore = $this->genericValidationMessages['format'];
                             $colCustomMsgAfter = $this->genericValidationMessages['regexp_failed'];
                             $colCustomMsg = sprintf($colCustomMsgBefore, $colCustomMsgAfter);
                         }
                         if ($res === 0) {
                             $hasTypeError = true;
                         }
                         break;
                     case 'mask':
                         $myRegexp = $this->mask2regexp($column['additional_params']);
                         if (!preg_match($myRegexp, $tmpFieldValue)) {
                             $hasTypeError = true;
                         }
                         break;
                     case 'text':
                     case 'numeric':
                     case 'double':
                         $type = $column['type'];
                         $format = $column['format'];
                         if (is_array($this->validationRules[$type][$format])) {
                             $myValidationRule =& $this->validationRules[$type][$format];
                             if (isset($myValidationRule['mask'])) {
                                 $myRegexp = $this->mask2regexp($myValidationRule['mask']);
                                 $myValidationRule['regexp'] = $myRegexp;
                             }
                             if (isset($myValidationRule['regexp'])) {
                                 if (!preg_match($myValidationRule['regexp'], $tmpFieldValue)) {
                                     $hasTypeError = true;
                                 }
                             }
                             if (isset($myValidationRule['callback'])) {
                                 $ret = call_user_func(array('tNG_FormValidation', $myValidationRule['callback']), $tmpFieldValue);
                                 if (!$ret) {
                                     $hasTypeError = true;
                                 }
                             }
                         }
                         break;
                     case 'date':
                         $format = $column['format'];
                         $checkFullDateTime = true;
                         switch ($format) {
                             case 'date':
                                 $inFmtRule = KT_format2rule($GLOBALS['KT_db_date_format']);
                                 $checkFullDateTime = true;
                                 break;
                             case 'time':
                                 $inFmtRule = KT_format2rule($GLOBALS['KT_db_time_format_internal']);
                                 $checkFullDateTime = false;
                                 break;
                             case 'datetime':
                                 $inFmtRule = KT_format2rule($GLOBALS['KT_db_date_format'] . ' ' . $GLOBALS['KT_db_time_format_internal']);
                                 $checkFullDateTime = true;
                                 break;
                             default:
                                 break 2;
                         }
                         $dateArr = KT_applyDate2rule($tmpFieldValue, $inFmtRule);
                         $ret = KT_isValidDate($dateArr, $checkFullDateTime);
                         if (!$ret) {
                             $hasTypeError = true;
                         }
                         break;
                 }
             }
             if (!$hasRequiredError && $hasTypeError) {
                 $column['failed'] = true;
                 $failed = true;
                 if ($this->tNG->exportsRecordset() !== true) {
                     $colCustomMsg = KT_DynamicData($colCustomMsg, $this->tNG, '', $this->tNG->transactionType == '_delete');
                     $errObj->addDetails('%s', array($colCustomMsg), array($colCustomMsg));
                 } else {
                     $errObj->setFieldError($column['name'], '%s', array($colCustomMsg));
                 }
             }
         }
         for ($i = 0; $i < $cols; $i++) {
             $colIdx = $columnKeys[$i];
             $column =& $this->columns[$colIdx];
             if (!in_array($column['name'], array_keys($this->tNG->columns))) {
                 continue;
             }
             $hasMinMaxError = false;
             $tmpFieldValue = $this->tNG->getColumnValue($column['name']);
             if ($column['type'] == 'date' && $column['format'] != '') {
                 if (!in_array($this->tNG->getColumnType($column['name']), array('DATE_TYPE', 'DATE_ACCESS_TYPE'))) {
                     $tmpFieldValue = KT_formatDate2DB($tmpFieldValue);
                 }
             }
             // MIN MAX parameter validation
             $tNG_tNGfield_min = array();
             $tNG_tNGfield_max = array();
             $min = $column['min'];
             $min_placeholders = KT_getReplacementsFromMessage($min);
             if (count($min_placeholders) > 0) {
                 foreach ($min_placeholders as $key => $placeholder) {
                     if (strpos($placeholder, '.') === false) {
                         $tNG_tNGfield_min[] = $placeholder;
                     }
                 }
             }
             $max = $column['max'];
             $max_placeholders = KT_getReplacementsFromMessage($max);
             if (count($max_placeholders) > 0) {
                 foreach ($max_placeholders as $key => $placeholder) {
                     if (strpos($placeholder, '.') === false) {
                         $tNG_tNGfield_max[] = $placeholder;
                     }
                 }
             }
             $min = KT_DynamicData($min, $this->tNG);
             $max = KT_DynamicData($max, $this->tNG);
             // MIN parameter validation
             if ($tmpFieldValue != '' && $min != '') {
                 if ($column['type'] == 'text') {
                     if (strlen($tmpFieldValue) < $min) {
                         $hasMinMaxError = true;
                     }
                 }
                 if (in_array($column['type'], array('numeric', 'double'))) {
                     $evaluateNumeric = true;
                     if (count($tNG_tNGfield_min) > 0) {
                         foreach ($tNG_tNGfield_min as $key => $tNG_tNGfield) {
                             if (!isset($this->columns[$tNG_tNGfield]) || !in_array($this->columns[$tNG_tNGfield]['type'], array('numeric', 'double')) || $this->columns[$tNG_tNGfield]['format'] == '' || $column['failed']) {
                                 $evaluateNumeric = false;
                                 break;
                             }
                         }
                     }
                     $tmpFieldValue = str_replace(',', '.', $tmpFieldValue);
                     $min = str_replace(',', '.', $min);
                     if ($evaluateNumeric) {
                         $min = $this->tNG->evaluateNumeric($min);
                     }
                     if (floatval($tmpFieldValue) < floatval($min)) {
                         $hasMinMaxError = true;
                     }
                 }
                 if ($column['type'] == 'date') {
                     if (count($tNG_tNGfield_min) > 0) {
                         foreach ($tNG_tNGfield_min as $key => $tNG_tNGfield) {
                             if (in_array($this->tNG->getColumnType($tNG_tNGfield), array('DATE_TYPE', 'DATE_ACCESS_TYPE'))) {
                                 $min = KT_formatDate($min);
                                 break;
                             }
                         }
                     }
                     $minDate = KT_formatDate2DB($min);
                     $format = $column['format'];
                     $checkFullDateTime = true;
                     switch ($format) {
                         case 'date':
                             $inFmtRule = KT_format2rule($GLOBALS['KT_db_date_format']);
                             $checkFullDateTime = true;
                             break;
                         case 'time':
                             $inFmtRule = KT_format2rule($GLOBALS['KT_db_time_format_internal']);
                             $checkFullDateTime = false;
                             break;
                         case 'datetime':
                             $inFmtRule = KT_format2rule($GLOBALS['KT_db_date_format'] . ' ' . $GLOBALS['KT_db_time_format_internal']);
                             $checkFullDateTime = true;
                             break;
                         default:
                             break 2;
                     }
                     $dateArr = KT_applyDate2rule($tmpFieldValue, $inFmtRule);
                     $minArr = KT_applyDate2rule($minDate, $inFmtRule);
                     if (KT_isValidDate($minArr, $checkFullDateTime)) {
                         if (KT_compareDates($dateArr, $minArr) === 1) {
                             $hasMinMaxError = true;
                         }
                     }
                 }
             }
             // MAX parameter validation
             if ($tmpFieldValue != '' && $max != '') {
                 if ($column['type'] == 'text') {
                     if (strlen($tmpFieldValue) > $max) {
                         $hasMinMaxError = true;
                     }
                 }
                 if (in_array($column['type'], array('numeric', 'double'))) {
                     $evaluateNumeric = true;
                     if (count($tNG_tNGfield_max) > 0) {
                         foreach ($tNG_tNGfield_max as $key => $tNG_tNGfield) {
                             if (!isset($this->columns[$tNG_tNGfield]) || !in_array($this->columns[$tNG_tNGfield]['type'], array('numeric', 'double')) || $this->columns[$tNG_tNGfield]['format'] == '' || $column['failed']) {
                                 $evaluateNumeric = false;
                                 break;
                             }
                         }
                     }
                     $tmpFieldValue = str_replace(',', '.', $tmpFieldValue);
                     $max = str_replace(',', '.', $max);
                     if ($evaluateNumeric) {
                         $max = $this->tNG->evaluateNumeric($max);
                     }
                     if (floatval($tmpFieldValue) > floatval($max)) {
                         $hasMinMaxError = true;
                     }
                 }
                 if ($column['type'] == 'date') {
                     if (count($tNG_tNGfield_max) > 0) {
                         foreach ($tNG_tNGfield_max as $key => $tNG_tNGfield) {
                             if (in_array($this->tNG->getColumnType($tNG_tNGfield), array('DATE_TYPE', 'DATE_ACCESS_TYPE'))) {
                                 $max = KT_formatDate($max);
                                 break;
                             }
                         }
                     }
                     $maxDate = KT_formatDate2DB($max);
                     $format = $column['format'];
                     $checkFullDateTime = true;
                     switch ($format) {
                         case 'date':
                             $inFmtRule = KT_format2rule($GLOBALS['KT_db_date_format']);
                             $checkFullDateTime = true;
                             break;
                         case 'time':
                             $inFmtRule = KT_format2rule($GLOBALS['KT_db_time_format_internal']);
                             $checkFullDateTime = false;
                             break;
                         case 'datetime':
                             $inFmtRule = KT_format2rule($GLOBALS['KT_db_date_format'] . ' ' . $GLOBALS['KT_db_time_format_internal']);
                             $checkFullDateTime = true;
                             break;
                         default:
                             break 2;
                     }
                     $dateArr = KT_applyDate2rule($tmpFieldValue, $inFmtRule);
                     $maxArr = KT_applyDate2rule($maxDate, $inFmtRule);
                     if (KT_isValidDate($maxArr, $checkFullDateTime)) {
                         if (KT_compareDates($dateArr, $maxArr) === -1) {
                             $hasMinMaxError = true;
                         }
                     }
                 }
             }
             $colCustomMsg = $column['message'];
             if (strlen($colCustomMsg) == 0) {
                 $colCustomMsgBefore = $column['type'] == 'text' ? 'text' : 'other';
                 if ($min != '' && $max != '') {
                     $colCustomMsgAfter = 'between';
                     $colCustomMsg = $this->genericValidationMessages[$colCustomMsgBefore . '_' . $colCustomMsgAfter];
                     $colCustomMsg = sprintf($colCustomMsg, $min, $max);
                 } elseif ($min != '') {
                     $colCustomMsgAfter = 'min';
                     $colCustomMsg = $this->genericValidationMessages[$colCustomMsgBefore . '_' . $colCustomMsgAfter];
                     $colCustomMsg = sprintf($colCustomMsg, $min);
                 } else {
                     $colCustomMsgAfter = 'max';
                     $colCustomMsg = $this->genericValidationMessages[$colCustomMsgBefore . '_' . $colCustomMsgAfter];
                     $colCustomMsg = sprintf($colCustomMsg, $max);
                 }
             }
             if ($hasMinMaxError && $column['failed'] == false) {
                 $column['failed'] = true;
                 $failed = true;
                 if ($this->tNG->exportsRecordset() !== true) {
                     $colCustomMsg = KT_DynamicData($colCustomMsg, $this->tNG, '', $this->tNG->transactionType == '_delete');
                     $errObj->addDetails('%s', array($colCustomMsg), array($colCustomMsg));
                 } else {
                     $errObj->setFieldError($column['name'], '%s', array($colCustomMsg));
                 }
             }
         }
     }
     if (!$failed) {
         $errObj = null;
     } else {
         if ($this->tNG->exportsRecordset() === true) {
             $errObj->addDetails('%s', array($this->genericValidationMessages['failed']), array(''));
         }
     }
     return $errObj;
 }
Exemplo n.º 3
0
 /**
  * Main class method. return array of values/columns
  * @param string primary key table from slave table
  * @param string idx for multiple transactions
  * @param string pk name from many to many table
  * @param object recordeset reference 
  * @return array
  * @access public
  */
 function Execute($fk, $cnt1, $pkName, &$rs)
 {
     $arr = $this->arrFields;
     if (is_resource($rs)) {
         mysql_data_seek($rs, 0);
         $totalRows = mysql_num_rows($rs);
         $row = mysql_fetch_assoc($rs);
     } else {
         $rs->MoveFirst();
         $row = $rs->fields;
         $totalRows = $rs->RecordCount();
     }
     foreach ($row as $k => $v) {
         if (!isset($arr[$k])) {
             $arr[$k][0] = '';
         }
     }
     $arrFields = $arr;
     for ($i = 0; $i < $totalRows; $i++) {
         $id = $this->getColValue($row, $fk);
         reset($arr);
         foreach ($arr as $k => $v) {
             if ($k != $pkName) {
                 $name = $this->reference . '_' . $k . '_' . $id;
             } else {
                 $name = $this->reference . '_' . $id;
             }
             if ($cnt1 > 0) {
                 $name .= '_' . $cnt1;
             }
             $arrFields[$k][$i] = $arr[$k][0];
             if (isset($_POST[$name])) {
                 $arrFields[$k][$i] = $_POST[$name];
             } else {
                 if ($this->getColValue($row, $pkName) != '' || $arr[$k][0] == '') {
                     $arrFields[$k][$i] = $this->getColValue($row, $k);
                 }
             }
             if (isset($this->arrTypes[$k]) && $this->arrTypes[$k] == 'DATE_TYPE' && ($this->getColValue($row, $k) == '' || isset($_POST[$name]))) {
                 $arrFields[$k][$i] = KT_formatDate2DB($arrFields[$k][$i]);
             }
         }
         // move next row;
         if (is_resource($rs)) {
             $row = mysql_fetch_assoc($rs);
         } else {
             $rs->MoveNext();
             $row = $rs;
         }
     }
     $obj = new KT_FakeRecordset($this->conn);
     return $obj->getFakeRecordset($arrFields);
 }
Exemplo n.º 4
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;
 }
Exemplo n.º 5
0
 /**
  * Return the values for extra columns to use in insert/update SQL;
  * Only for PRO version	 
  * @param string foreign key value
  * @param array selected values
  * @return array
  * @access public
  */
 function getExtraColumnsValues($fk, $insertValues)
 {
     $arr = array();
     if (!in_array($fk, $insertValues)) {
         return $arr;
     }
     if (count($this->columns) > 0) {
         $arr['cols'] = array();
         $arr['values'] = array();
         $arr['update'] = array();
         $fkReference = $this->fkReference;
         $idxReference = "";
         if (isset($this->tNG->multipleIdx)) {
             $idxReference = '_' . $this->tNG->multipleIdx;
             $idxReference = preg_quote($idxReference, '/');
         }
         $fkReference = preg_quote($fkReference, '/');
         foreach ($this->columns as $colName => $arrTmp) {
             $arr['cols'][] = KT_escapeFieldName($colName);
             if ($arrTmp['method'] == 'VALUE') {
                 $arr['values'][] = KT_escapeForSql($arrTmp['value'], $arrTmp['type'], false);
                 $arr['update'][] = KT_escapeFieldName($colName) . '=' . $arr['values'][count($arr['values']) - 1];
             } else {
                 $found = false;
                 foreach ($_POST as $key => $val) {
                     if (preg_match('/^' . $fkReference . '_' . $colName . '_' . $fk . $idxReference . '$/', $key)) {
                         if ($arrTmp['type'] == 'DATE_TYPE') {
                             $val = KT_formatDate2DB($val);
                         }
                         $arr['values'][] = KT_escapeForSql($val, $arrTmp['type'], false);
                         $arr['update'][] = KT_escapeFieldName($colName) . '=' . $arr['values'][count($arr['values']) - 1];
                         $found = true;
                         break;
                     }
                 }
                 if (!$found && $this->columns[$colName]['default'] != '') {
                     $val = KT_DynamicData($this->columns[$colName]['default'], null);
                     if ($this->columns[$colName]['type'] == 'DATE_TYPE') {
                         $val = KT_formatDate2DB($val);
                     }
                     $arr['values'][] = KT_escapeForSql($val, $arrTmp['type'], false);
                     $arr['update'][] = KT_escapeFieldName($colName) . '=' . $arr['values'][count($arr['values']) - 1];
                 }
             }
         }
     }
     return $arr;
 }