Пример #1
0
 /**
  * Builds the search where clause when the user perform a search
  * Return arrray the first element is a strinng with the where clause,
  * the second element is array containing the value parameters passed to
  * the sql.
  *
  * @param array $prm - parameters passed to the sql
  * @return array
  */
 protected function _buildSearch(array $prm = null, $str_filter = '')
 {
     $filters = $str_filter && strlen($str_filter) > 0 ? $str_filter : jqGridUtils::GetParam($this->GridParams["filter"], "");
     $rules = "";
     // multiple filter
     if ($filters) {
         $count = 0;
         $filters = str_replace('$', '\\$', $filters, $count);
         if (function_exists('json_decode') && strtolower(trim($this->encoding)) == "utf-8" && $count == 0) {
             $jsona = json_decode($filters, true);
         } else {
             $jsona = jqGridUtils::decode($filters);
         }
         if (is_array($jsona)) {
             $gopr = $jsona['groupOp'];
             $rules[0]['data'] = 'dummy';
             //$jsona['rules'];
         }
         // single filter
     } else {
         if (jqGridUtils::GetParam($this->GridParams['searchField'], '')) {
             $gopr = '';
             $rules[0]['field'] = jqGridUtils::GetParam($this->GridParams['searchField'], '');
             $rules[0]['op'] = jqGridUtils::GetParam($this->GridParams['searchOper'], '');
             $rules[0]['data'] = jqGridUtils::GetParam($this->GridParams['searchString'], '');
             $jsona = array();
             $jsona['groupOp'] = "AND";
             $jsona['rules'] = $rules;
             $jsona['groups'] = array();
         }
     }
     $ret = array("", $prm);
     if ($jsona) {
         if ($rules && count($rules) > 0) {
             if (!is_array($prm)) {
                 $prm = array();
             }
             $ret = $this->getStringForGroup($jsona, $prm);
             if (count($ret[1]) == 0) {
                 $ret[1] = null;
             }
         }
     }
     return $ret;
 }
Пример #2
0
 protected function _buildSearch($sqlEx, array $prm = null)
 {
     $s = '';
     $s1 = '';
     $i_ = $this->I;
     $sopt = array('eq' => "=", 'ne' => "<>", 'lt' => "<", 'le' => "<=", 'gt' => ">", 'ge' => ">=", 'bw' => " {$i_}LIKE ", 'bn' => " NOT {$i_}LIKE ", 'in' => ' IN ', 'ni' => ' NOT IN', 'ew' => " {$i_}LIKE ", 'en' => " NOT {$i_}LIKE ", 'cn' => " {$i_}LIKE ", 'nc' => " NOT {$i_}LIKE ");
     $s1 = " ( ";
     $filters = jqGridUtils::GetParam($this->GridParams["filter"], "");
     $rules = "";
     if ($filters) {
         if (function_exists('json_decode') && strtolower(trim($this->encoding)) == "utf-8") {
             $jsona = json_decode($filters, true);
         } else {
             $jsona = jqGridUtils::decode($filters);
         }
         if (is_array($jsona)) {
             $gopr = $jsona['groupOp'];
             $rules = $jsona['rules'];
         }
     } else {
         if (jqGridUtils::GetParam($this->GridParams['searchField'], '')) {
             $gopr = '';
             $rules[0]['field'] = jqGridUtils::GetParam($this->GridParams['searchField'], '');
             $rules[0]['op'] = jqGridUtils::GetParam($this->GridParams['searchOper'], '');
             $rules[0]['data'] = jqGridUtils::GetParam($this->GridParams['searchString'], '');
         }
     }
     $i = 0;
     if (!$rules) {
         return array('', $prm);
     }
     if (!is_array($prm)) {
         $prm = array();
     }
     foreach ($rules as $key => $val) {
         $field = $val['field'];
         $op = $val['op'];
         $v = $val['data'];
         if (strlen($v) != 0 && $op) {
             if (in_array($field, $this->datearray)) {
                 $v = jqGridUtils::parseDate($this->userdateformat, $v, $this->dbdateformat);
             }
             $i++;
             $s .= $i == 1 ? "" : " " . $gopr . " ";
             switch ($op) {
                 case 'bw':
                 case 'bn':
                     $s .= $field . $sopt[$op] . " ?";
                     $prm[] = "{$v}%";
                     break;
                 case 'ew':
                 case 'en':
                     $s .= $field . $sopt[$op] . " ?";
                     $prm[] = "%{$v}";
                     break;
                 case 'cn':
                 case 'nc':
                     $s .= $field . $sopt[$op] . " ?";
                     $prm[] = "%{$v}%";
                     break;
                 case 'in':
                 case 'ni':
                     $s .= $field . $sopt[$op] . "( ?)";
                     $prm[] = $v;
                     break;
                 default:
                     $s .= $field . $sopt[$op] . " ?";
                     $prm[] = $v;
                     break;
             }
         }
     }
     $s = $s ? $s1 . $s . " )" : "";
     return array($s, $prm);
 }
Пример #3
0
        $str .= "BSE;" . "\n";
    }
}
if (isset($otherset['ajax_success'])) {
    if (trim($otherset['ajax_success'])) {
        $str .= "\$" . "success = <<< SU" . "\n";
        $str .= "function( response, status, xhr) {" . "\n";
        $str .= html_entity_decode($otherset['ajax_success']) . "\n";
        $str .= "}" . "\n";
        $str .= "SU;" . "\n";
    }
}
$ajax = "array(";
if (isset($otherset['ajax_data'])) {
    if (trim($otherset['ajax_data'])) {
        $apr = jqGridUtils::decode("{" . $otherset['ajax_data'] . "}");
        $new_array = array_map(create_function('$key, $value', 'return "\\"". $key."\\" => \\"".$value."\\" ";'), array_keys($apr), array_values($apr));
        $ajax .= "'data'=>array(" . implode($new_array, ",") . ")," . "\n";
    }
}
if (isset($otherset['ajax_dataType'])) {
    if ($otherset['ajax_dataType']) {
        if ($otherset['ajax_dataType'] == 'null') {
            $ajax .= "'dataType'=>" . $otherset['ajax_dataType'] . "," . "\n";
        } else {
            $ajax .= "'dataType'=>'" . $otherset['ajax_dataType'] . "'," . "\n";
        }
    }
}
if (isset($otherset['ajax_resetForm'])) {
    if ($otherset['ajax_resetForm']) {
Пример #4
0
 public static function _mongoSearch($mongoquery, $GridParams = array(), $encoding = 'utf-8', $datearray = array(), $mongointegers = array())
 {
     $s = '';
     $v = array();
     $sopt = array('eq' => '===', 'ne' => '!==', 'lt' => '<', 'le' => '<=', 'gt' => '>', 'ge' => '>=', 'bw' => "", 'bn' => "", 'in' => '==', 'ni' => '!=', 'ew' => '', 'en' => '', 'cn' => '', 'nc' => '');
     $filters = jqGridUtils::GetParam($GridParams["filter"], "");
     $rules = "";
     // multiple filter
     if ($filters) {
         if (function_exists('json_decode') && strtolower(trim($encoding)) == "utf-8") {
             $jsona = json_decode($filters, true);
         } else {
             $jsona = jqGridUtils::decode($filters);
         }
         if (is_array($jsona)) {
             $gopr = strtolower(trim($jsona['groupOp']));
             $rules = $jsona['rules'];
         }
         // single filter
     } else {
         if (jqGridUtils::GetParam($GridParams['searchField'], '')) {
             $gopr = 'or';
             $rules[0]['field'] = jqGridUtils::GetParam($GridParams['searchField'], '');
             $rules[0]['op'] = jqGridUtils::GetParam($GridParams['searchOper'], '');
             $rules[0]['data'] = jqGridUtils::GetParam($GridParams['searchString'], '');
         }
     }
     if ($gopr == 'or') {
         $gopr = ' || ';
     } else {
         $gopr = ' && ';
     }
     $i = 0;
     if (!is_array($mongoquery)) {
         $mongoquery = array();
     }
     foreach ($rules as $key => $val) {
         $field = $val['field'];
         $op = $val['op'];
         $v = $val['data'];
         if (strlen($v) != 0 && $op) {
             $string = true;
             if (in_array($field, $datearray)) {
                 $av = explode(",", jqGridUtils::parseDate('d/m/Y H:i:s', $v, 'Y,m,d,H,i,s'));
                 $av[1] = (int) $av[1] - 1;
                 $v = "new Date(" . implode(",", $av) . ")";
                 $string = false;
             }
             if (in_array($field, $mongointegers)) {
                 $string = false;
             }
             $i++;
             if ($i > 1) {
                 $s .= $gopr;
             }
             switch ($op) {
                 case 'bw':
                     $s .= "this." . $field . ".match(/^{$v}.*\$/i)";
                     break;
                 case 'bn':
                     $s .= "!this." . $field . ".match(/^{$v}.*\$/i)";
                     break;
                 case 'ew':
                     $s .= "this." . $field . ".match(/^.*{$v}\$/i)";
                     break;
                 case 'en':
                     $s .= "!this." . $field . ".match(/^.*{$v}\$/i)";
                     break;
                 case 'cn':
                     $s .= "this." . $field . ".match(/^.*{$v}.*\$/i)";
                     break;
                 case 'nc':
                     $s .= "!this." . $field . ".match(/^.*{$v}.*\$/i)";
                     break;
                 default:
                     if ($string) {
                         $v = "'" . $v . "'";
                     }
                     $s .= " this." . $field . " " . $sopt[$op] . $v;
                     break;
             }
         }
     }
     if (isset($mongoquery) && is_array($mongoquery)) {
         $mongoquery = jqGridUtils::array_extend($mongoquery, array('$where' => "function(){ return " . $s . ";}"));
     } else {
         $mongoquery = array('$where' => "function(){ return " . $s . ";}");
     }
     return $mongoquery;
 }