Exemplo n.º 1
0
 /**
  * Sets for each column the value correspondeing to the reference/method
  * @access public
  */
 function compileColumnsValues()
 {
     // Use multiple values in kt_pk or from get
     $savedPK = $this->primaryKeyColumn;
     $this->primaryKeyColumn['method'] = 'POST';
     $this->primaryKeyColumn['reference'] = $this->pkName;
     tNG_prepareValues($this->primaryKeyColumn);
     if (!isset($this->primaryKeyColumn['value'])) {
         $this->primaryKeyColumn = $savedPK;
         tNG_prepareValues($this->primaryKeyColumn);
     }
     foreach ($this->columns as $colName => $colDetails) {
         tNG_prepareValues($this->columns[$colName]);
     }
 }
Exemplo n.º 2
0
 function Execute()
 {
     $show_filter_reference = "show_filter_" . $this->filterName;
     $reset_filter_reference = "reset_filter_" . $this->filterName;
     $has_filter_reference = "has_filter_" . $this->filterName;
     $filter_reference = "filter_" . $this->filterName;
     if (isset($_GET[$show_filter_reference])) {
         $_SESSION[$has_filter_reference] = 1;
         $url = KT_addReplaceParam(KT_getFullUri(), $show_filter_reference);
         KT_redir($url);
     }
     if (isset($_GET[$reset_filter_reference])) {
         unset($_SESSION[$reset_filter_reference]);
         unset($_SESSION[$has_filter_reference]);
         unset($_SESSION[$filter_reference]);
         foreach ($this->columns as $key => $columnDetails) {
             foreach ($columnDetails as $key => $details) {
                 $_SESSION[$details['reference']] = '';
             }
         }
         $url = KT_addReplaceParam(KT_getFullUri(), $reset_filter_reference);
         KT_redir($url);
     }
     if (sizeof($_POST) > 0 && isset($_POST[$this->filterName])) {
         foreach ($this->columns as $columnName => $columnDetails) {
             foreach ($columnDetails as $key => $details) {
                 $variableName = $details['reference'];
                 if (isset($_POST[$variableName])) {
                     $details['method'] = 'POST';
                     if ($details['type'] == 'DATE_TYPE' || $details['type'] == 'DATE_ACCESS_TYPE') {
                         $details['type'] = 'STRING_TYPE';
                         tNG_prepareValues($details);
                     } else {
                         tNG_prepareValues($details);
                     }
                     $_SESSION[$variableName] = $details['value'];
                 } else {
                     $_SESSION[$variableName] = '';
                 }
             }
         }
         $url = KT_getFullUri();
         $url = KT_addReplaceParam($url, '/pageNum_.*/');
         $url = KT_addReplaceParam($url, '/totalRows_.*/');
         KT_redir($url);
     }
     $condition = '';
     foreach ($this->columns as $columnName => $columnDetails) {
         foreach ($columnDetails as $key => $details) {
             $variableName = $details['reference'];
             $details['value'] = @$_SESSION[$variableName];
             if (!isset($details['value']) || $details['value'] == '') {
                 continue;
             }
             if ($condition != '') {
                 $condition .= " AND ";
             }
             $variableValue = trim($details['value']);
             $compareType = $details['compareType'];
             switch ($details['type']) {
                 case 'NUMERIC_TYPE':
                 case 'DOUBLE_TYPE':
                     // if decimal separator is , => .
                     $variableValue = str_replace(',', '.', $variableValue);
                     if (preg_match('/^(<|>|=|<=|>=|=<|=>|<>|!=)\\s?-?\\d*\\.?\\d+$/', $variableValue, $matches)) {
                         $modifier = trim($matches[1]);
                         if ($modifier == '!=') {
                             $modifier = '<>';
                         }
                         $variableValue = trim(substr($variableValue, strlen($modifier)));
                         $condition .= KT_escapeFieldName($columnName) . ' ' . $modifier . ' ' . $variableValue;
                     } else {
                         $condition .= KT_escapeFieldName($columnName) . ' ' . $compareType . ' ' . KT_escapeForSql($variableValue, $details['type']);
                     }
                     break;
                 case 'CHECKBOX_1_0_TYPE':
                 case 'CHECKBOX_-1_0_TYPE':
                     if (preg_match('/^[<>]{1}\\s?-?\\d*\\.?\\d+$/', $variableValue)) {
                         $condition .= KT_escapeFieldName($columnName) . $variableValue;
                     } else {
                         $condition .= KT_escapeFieldName($columnName) . " = " . KT_escapeForSql($variableValue, $details['type']);
                     }
                     break;
                 case 'DATE_TYPE':
                 case 'DATE_ACCESS_TYPE':
                     $localCond = $this->prepareDateCondition($columnName, $details);
                     if ($localCond != '') {
                         $condition .= $localCond;
                     } else {
                         if (strlen($condition) > 0) {
                             // if the date entered is invalid, we will not add it to the condition
                             $condition = substr($condition, 0, strlen($condition) - 5);
                         }
                     }
                     break;
                 default:
                     switch ($compareType) {
                         case '=':
                             break;
                         case 'A%':
                             $variableValue = $variableValue . '%';
                             $compareType = 'LIKE';
                             break;
                         case '%A':
                             $variableValue = '%' . $variableValue;
                             $compareType = 'LIKE';
                             break;
                         default:
                             $variableValue = '%' . $variableValue . '%';
                             $compareType = 'LIKE';
                             break;
                     }
                     $variableValue = KT_escapeForSql($variableValue, $details['type']);
                     $condition .= KT_escapeFieldName($columnName) . ' ' . $compareType . ' ' . $variableValue;
                     break;
             }
         }
     }
     if ($condition == '') {
         $condition = '1=1';
     }
     $condition = str_replace("%", "%%", $condition);
     $_SESSION[$filter_reference] = $condition;
 }