while ($data = db_fetch_numarray($rs)) {
    if (!$found && $data[0] == $lookupValue) {
        $found = true;
    }
    $response[] = $data[0];
    $response[] = $data[1];
}
if ($hasWhere) {
    if (!$found) {
        // try to make query without WHERE expression
        foreach ($fieldsArr as $f) {
            $fEditFormat = GetFieldData($strTableName, $f, 'EditFormat', '');
            if ($fEditFormat != EDIT_FORMAT_LOOKUP_WIZARD || GoodFieldName($f) != $field) {
                continue;
            }
            $origfield = GetFieldByGoodFieldName($field);
            $lookupValue = make_db_value($origfield, $lookupValue);
            $LookupType = GetFieldData($strTableName, $f, 'LookupType', '');
            if ($LookupType == LT_LOOKUPTABLE) {
                $LookupSQL = "SELECT count(*)";
                $LookupSQL .= " FROM " . AddTableWrappers(GetFieldData($strTableName, $f, 'LookupTable', '')) . " ";
                if (strlen(LookupWhere($f, $strTableName))) {
                    $LookupSQL .= "where (" . LookupWhere($f, $strTableName) . ")  AND " . GetLWLinkField($f, $strTableName, true) . "=" . $lookupValue;
                } else {
                    $LookupSQL .= " WHERE " . GetLWLinkField($f, $strTableName, true) . "=" . $lookupValue;
                }
                if (GetFieldData($strTableName, $f, 'UseCategory', false)) {
                    $cvalue = make_db_value(GetFieldData($strTableName, $f, 'CategoryControl', ''), postvalue("category"));
                    $LookupSQL .= " AND " . AddFieldWrappers(GetFieldData($strTableName, $f, 'CategoryFilter', '')) . "=" . $cvalue;
                }
            }
Exemplo n.º 2
0
 /**
  * Builde order params
  */
 function buildOrderParams()
 {
     //orderlinkattrs for fields
     $this->orderLinksAttr();
     $order_ind = -1;
     //Array fields for sort
     $this->arrFieldForSort = array();
     //Array how fields sort
     $this->arrHowFieldSort = array();
     $arrImplicitSortFields = array();
     $key = array();
     //Session field for sort
     if (@$_SESSION[$this->sessionPrefix . "_arrFieldForSort"]) {
         $this->arrFieldForSort = $_SESSION[$this->sessionPrefix . "_arrFieldForSort"];
     }
     //Session how field sort
     if (@$_SESSION[$this->sessionPrefix . "_arrHowFieldSort"]) {
         $this->arrHowFieldSort = $_SESSION[$this->sessionPrefix . "_arrHowFieldSort"];
     }
     //Session key fields for sort
     if (@$_SESSION[$this->sessionPrefix . "_key"]) {
         $key = $_SESSION[$this->sessionPrefix . "_key"];
     } else {
         $tKeys = GetTableKeys($this->tName);
         for ($i = 0; $i < count($tKeys); $i++) {
             if (GetFieldIndex($tKeys[$i])) {
                 $key[] = GetFieldIndex($tKeys[$i]);
             }
         }
         $_SESSION[$this->sessionPrefix . "_key"] = $key;
     }
     $lenkey = count($key);
     if (!isset($_SESSION[$this->sessionPrefix . "_order"])) {
         $this->arrFieldForSort = array();
         $this->arrHowFieldSort = array();
         if (count($this->gOrderIndexes)) {
             for ($i = 0; $i < count($this->gOrderIndexes); $i++) {
                 $this->arrFieldForSort[] = $this->gOrderIndexes[$i][0];
                 $this->arrHowFieldSort[] = $this->gOrderIndexes[$i][1];
             }
         } elseif ($this->gstrOrderBy != '') {
             $_SESSION[$this->sessionPrefix . "_noNextPrev"] = 1;
         }
         //add sorting on key fields
         if (count($key) && $this->moveNext) {
             for ($i = 0; $i < $lenkey; $i++) {
                 $idsearch = array_search($key[$i], $this->arrFieldForSort);
                 if ($idsearch === false) {
                     $this->arrFieldForSort[] = $key[$i];
                     $this->arrHowFieldSort[] = "ASC";
                     $arrImplicitSortFields[] = $key[$i];
                 }
             }
         }
     }
     $lenArr = count($this->arrFieldForSort);
     //Sorting defined on the sheet
     if (@$_SESSION[$this->sessionPrefix . "_orderby"]) {
         $order_field = GetFieldByGoodFieldName(substr($_SESSION[$this->sessionPrefix . "_orderby"], 1));
         $order_dir = substr($_SESSION[$this->sessionPrefix . "_orderby"], 0, 1);
         $order_ind = GetFieldIndex($order_field);
         if ($order_ind) {
             if (!@$_REQUEST["a"] and !@$_REQUEST["goto"] and !@$_REQUEST["pagesize"]) {
                 if (@$_REQUEST["ctrl"]) {
                     $idsearch = array_search($order_ind, $this->arrFieldForSort);
                     if ($idsearch === false) {
                         if ($order_dir == "a") {
                             $this->arrFieldForSort[] = $order_ind;
                             $this->arrHowFieldSort[] = "ASC";
                         } else {
                             $this->arrFieldForSort[] = $order_ind;
                             $this->arrHowFieldSort[] = "DESC";
                         }
                     } else {
                         $this->arrHowFieldSort[$idsearch] = $order_dir == "a" ? "ASC" : "DESC";
                     }
                 } else {
                     $this->arrFieldForSort = array();
                     $this->arrHowFieldSort = array();
                     if (!empty($_SESSION[$this->sessionPrefix . "_orderNo"])) {
                         unset($_SESSION[$this->sessionPrefix . "_orderNo"]);
                     }
                     $_SESSION[$this->sessionPrefix . "_noNextPrev"] = 0;
                     if ($order_dir == "a") {
                         $this->arrFieldForSort[] = $order_ind;
                         $this->arrHowFieldSort[] = "ASC";
                     } else {
                         $this->arrFieldForSort[] = $order_ind;
                         $this->arrHowFieldSort[] = "DESC";
                     }
                 }
             }
         }
     }
     $lenArr = count($this->arrFieldForSort);
     //Draw pictures of fields for sorting
     $condition = true;
     if (!count($this->arrFieldForSort)) {
         $condition = false;
     } elseif (!$this->arrFieldForSort[0]) {
         $condition = false;
     }
     if ($condition) {
         for ($i = 0; $i < $lenArr; $i++) {
             $order_field = GetFieldByIndex($this->arrFieldForSort[$i]);
             $order_dir = $this->arrHowFieldSort[$i] == "ASC" ? "a" : "d";
             $idsearch = array_search($this->arrFieldForSort[$i], $arrImplicitSortFields);
             if ($idsearch === false) {
                 $this->xt->assign_section(GoodFieldName($order_field) . "_fieldheader", "", "<img " . ($this->is508 == true ? "alt=\" \" " : "") . "src=\"images/" . ($order_dir == "a" ? "up" : "down") . ".gif\" border=0>");
             }
             // default ASC for key fields
             if ($idsearch !== false && in_array(GetFieldIndex($order_field), $arrImplicitSortFields)) {
                 $orderlinkattrs = $this->setLinksAttr(GoodFieldName($order_field));
             } else {
                 $orderlinkattrs = $this->setLinksAttr(GoodFieldName($order_field), $order_dir);
             }
             $this->xt->assign(GoodFieldName($order_field) . "_orderlinkattrs", $orderlinkattrs);
         }
     }
     //Shape sorting line for a request
     if ($lenArr > 0) {
         for ($i = 0; $i < $lenArr; $i++) {
             $this->strOrderBy .= GetFieldByIndex($this->arrFieldForSort[$i]) ? ($this->strOrderBy != "" ? ", " : " ORDER BY ") . $this->arrFieldForSort[$i] . " " . $this->arrHowFieldSort[$i] : "";
         }
     }
     if ($_SESSION[$this->sessionPrefix . "_noNextPrev"] == 1) {
         $this->strOrderBy = $this->gstrOrderBy;
     }
 }