/**
  * Build where for united search
  * Params are common for advanced search and search panel on list
  * Use in new projects
  * 
  * @protected
  * @return string
  *
  */
 function buildItegratedWhere($fieldsArr)
 {
     if (!count($fieldsArr)) {
         return '';
     }
     // get global options
     $simpleSrch = $this->_where[$this->sessionPrefix . "_simpleSrch"];
     if (trim($simpleSrch) === '%') {
         $simpleSrch = '[' . $simpleSrch . ']';
     }
     $srchType = $this->_where[$this->sessionPrefix . "_srchType"];
     $srchFields =& $this->_where[$this->sessionPrefix . "_srchFields"];
     $sWhere = '';
     // build where for any field contains search
     if (strlen($simpleSrch) || $this->_where[$this->sessionPrefix . "simpleSrchTypeComboOpt"] == "Empty") {
         if (strlen($this->_where[$this->sessionPrefix . "simpleSrchFieldsComboOpt"])) {
             $where = StrWhereExpression($this->_where[$this->sessionPrefix . "simpleSrchFieldsComboOpt"], $simpleSrch, $this->_where[$this->sessionPrefix . "simpleSrchTypeComboOpt"], "");
             if ($where && $this->_where[$this->sessionPrefix . "simpleSrchTypeComboNot"]) {
                 $where = "not (" . $where . ")";
             }
             $sWhere = $where;
         } else {
             for ($i = 0; $i < count($this->searchFieldsArr); $i++) {
                 if (in_array($this->searchFieldsArr[$i], $fieldsArr) && in_array($this->searchFieldsArr[$i], $this->googleLikeFields)) {
                     $where = StrWhereExpression($this->searchFieldsArr[$i], $simpleSrch, $this->_where[$this->sessionPrefix . "simpleSrchTypeComboOpt"], "");
                     // add not
                     if ($where && $this->_where[$this->sessionPrefix . "simpleSrchTypeComboNot"]) {
                         $where = "not (" . $where . ")";
                     }
                     if ($where) {
                         if ($sWhere) {
                             $sWhere .= " or ";
                         }
                         $sWhere .= $where;
                     }
                 }
             }
         }
     }
     $resWhere = whereAdd('', $sWhere);
     // if there are fields for build advanced where
     $sWhere = '';
     if (count($srchFields)) {
         // prepare vars
         $sWhere = $srchType == "and" ? "(1=1" : "(1=0";
         $prevSrchFieldName = '';
         // build where
         foreach ($srchFields as $srchF) {
             if (in_array($srchF['fName'], $fieldsArr)) {
                 $where = StrWhereAdv($srchF['fName'], $srchF['value1'], $srchF['opt'], $srchF['value2'], $srchF['eType']);
                 if ($where) {
                     // add not
                     if ($srchF['not']) {
                         $where = "not (" . $where . ")";
                     }
                     // and|or depends on search type
                     if ($srchType == "and") {
                         // add ( if we add new clause block for same field name
                         $sWhere .= ($prevSrchFieldName != $srchF['fName'] ? ") and (" : " and ") . $where;
                     } else {
                         $sWhere .= " or " . $where;
                     }
                 }
                 $prevSrchFieldName = $srchF['fName'];
             }
         }
         // add ) to final field block clause
         $sWhere .= ')';
     }
     $resWhere = whereAdd($resWhere, $sWhere);
     return $resWhere;
 }
示例#2
0
 /**
  * Build where for simple search. 
  * Need for compability with old projects
  * 
  * @protected
  * @return string
  */
 function buildSimpleWhere()
 {
     $sWhere = '';
     $strSearchFor = trim($this->_where[$this->sessionPrefix . "_searchfor"]);
     $strSearchOption = trim($this->_where[$this->sessionPrefix . "_searchoption"]);
     if (@$this->_where[$this->sessionPrefix . "_searchfield"]) {
         $strSearchField = $this->_where[$this->sessionPrefix . "_searchfield"];
         if ($where = StrWhereExpression($strSearchField, $strSearchFor, $strSearchOption, "", $this->cipherer)) {
             $sWhere = whereAdd($sWhere, $where);
         } else {
             $sWhere = whereAdd($sWhere, "1=0");
         }
     } else {
         $strWhere = "1=0";
         for ($i = 0; $i < count($this->searchFieldsArr); $i++) {
             if ($where = StrWhereExpression($this->searchFieldsArr[$i], $strSearchFor, $strSearchOption, "", $this->cipherer)) {
                 $strWhere .= " or " . $where;
             }
         }
         $sWhere = whereAdd($sWhere, $strWhere);
     }
     return $sWhere;
 }