public function fetchData()
 {
     if ($this->activeRecord != null) {
         return $this->activeRecord;
     }
     $dataObj = $this->getDataObj();
     if ($dataObj == null) {
         return;
     }
     QueryStringParam::setBindValues($this->searchRuleBindValues);
     if ($this->isRefreshData) {
         $dataObj->resetRules();
     } else {
         $dataObj->clearSearchRule();
     }
     if ($this->fixSearchRule) {
         if ($this->searchRule) {
             $searchRule = $this->searchRule . " AND " . $this->fixSearchRule;
         } else {
             $searchRule = $this->fixSearchRule;
         }
     }
     $dataObj->setSearchRule($searchRule);
     QueryStringParam::setBindValues($this->searchRuleBindValues);
     $resultRecords = $dataObj->fetch();
     foreach ($resultRecords as $record) {
         $settingRecord["_" . $record['name']] = $record["value"];
     }
     $this->recordId = $resultRecords[0]['Id'];
     $this->setActiveRecord($settingRecord);
     QueryStringParam::ReSet();
     return $settingRecord;
 }
 public function fetchDataSet()
 {
     $roleId = $this->getRoleId();
     if ($this->searchRuleBindValues) {
         QueryStringParam::setBindValues($this->searchRuleBindValues);
     }
     // fetch acl_action records
     $aclActionDO = Openbiz::getObject("system.do.AclActionDO", 1);
     //var_dump($this->searchRuleBindValues);
     $aclActionDO->setQueryParameters($this->queryParams);
     $aclActionDO->setLimit($this->range, ($this->currentPage - 1) * $this->range);
     $rs = $aclActionDO->fetch()->toArray();
     //echo '<pre>';
     //DebugLine::show(__METHOD__.__LINE__);
     //DebugLine::show(var_dump($rs));
     //return;
     $this->totalRecords = $aclActionDO->count();
     if ($this->range && $this->range > 0) {
         $this->totalPages = ceil($this->totalRecords / $this->range);
     }
     // fetch role and access
     //$this->getDataObj()->searchRule .= "[role_id]=$roleId ";
     $this->getDataObj()->setSearchRule("[role_id]={$roleId}");
     if ($this->searchRule) {
         $this->getDataObj()->setSearchRule($this->searchRule);
     }
     //DebugLine::show(' -- ' . $this->searchRule);
     //return;
     $rs1 = $this->getDataObj()->fetch();
     $this->getDataObj()->clearSearchRule();
     foreach ($rs1 as $rec) {
         $actionRoleAccess[$rec['action_id']] = $rec;
     }
     //print_r($actionRoleAccess);
     // merge 2 rs
     for ($i = 0; $i < count($rs); $i++) {
         $actionId = $rs[$i]['Id'];
         $rs[$i]['access_level'] = "";
         if (isset($actionRoleAccess[$actionId])) {
             $rs[$i]['access_level'] = $actionRoleAccess[$actionId]['access_level'];
         }
     }
     return $rs;
 }
 public function fetchDataSet()
 {
     $dataObj = $this->getDataObj();
     if (!$dataObj) {
         return null;
     }
     QueryStringParam::setBindValues($this->searchRuleBindValues);
     if ($this->isRefreshData) {
         $dataObj->resetRules();
     } else {
         $dataObj->clearSearchRule();
     }
     if ($this->fixSearchRule) {
         if ($this->searchRule) {
             $searchRule = $this->searchRule . " AND " . $this->fixSearchRule;
         } else {
             $searchRule = $this->fixSearchRule;
         }
     } else {
         $searchRule = $this->searchRule;
     }
     $dataObj->setSearchRule($searchRule);
     if ($this->startItem > 1) {
         $dataObj->setLimit($this->range, $this->startItem);
     } else {
         $dataObj->setLimit($this->range, ($this->currentPage - 1) * $this->range);
     }
     //$resultRecords = $dataObj->fetch();
     $resultRecordTree = $dataObj->fetchTree($this->rootSearchRule, $this->treeDepth);
     if (is_array($resultRecordTree)) {
         foreach ($resultRecordTree as $resultRecordTreeNode) {
             $this->tree2array($resultRecordTreeNode, $resultRecords);
         }
     }
     $this->totalRecords = $dataObj->count();
     if ($this->range && $this->range > 0) {
         $this->totalPages = ceil($this->totalRecords / $this->range);
     }
     $selectedIndex = 0;
     $this->getDataObj()->setActiveRecord($resultRecords[$selectedIndex]);
     QueryStringParam::ReSet();
     return $resultRecords;
 }
 public function fetchData()
 {
     if ($this->activeRecord != null) {
         return $this->activeRecord;
     }
     $dataObj = $this->getDataObj();
     if ($dataObj == null) {
         return;
     }
     if (!$this->fixSearchRule && !$this->searchRule) {
         return array();
     }
     QueryStringParam::setBindValues($this->searchRuleBindValues);
     if ($this->isRefreshData) {
         $dataObj->resetRules();
     } else {
         $dataObj->clearSearchRule();
     }
     if ($this->fixSearchRule) {
         if ($this->searchRule) {
             $searchRule = $this->searchRule . " AND " . $this->fixSearchRule;
         } else {
             $searchRule = $this->fixSearchRule;
         }
     }
     $dataObj->setSearchRule($searchRule);
     QueryStringParam::setBindValues($this->searchRuleBindValues);
     $resultRecords = $dataObj->fetch();
     foreach ($resultRecords as $record) {
         $prefRecord["_" . $record['name']] = $record["value"];
     }
     if ($prefRecord["_siteurl"] == "") {
         if ($_SERVER["HTTPS"]) {
             $prefRecord["_siteurl"] = "https://" . $_SERVER["SERVER_NAME"] . OPENBIZ_APP_URL;
         } else {
             $prefRecord["_siteurl"] = "http://" . $_SERVER["SERVER_NAME"] . OPENBIZ_APP_URL;
         }
     }
     $this->recordId = $resultRecords[0]['Id'];
     $this->setActiveRecord($prefRecord);
     QueryStringParam::ReSet();
     return $prefRecord;
 }
 protected function fetchDatasetByColumn()
 {
     $this->chartCategory = array();
     $this->chartDataAttrset = array();
     $this->chartDataset = array();
     $this->chartDataDescset = array();
     $this->chartDataIdset = array();
     $this->chartColorset = array();
     // query recordset first
     $dataObj = $this->getDataObj();
     QueryStringParam::setBindValues($this->searchRuleBindValues);
     if ($this->isRefreshData) {
         $dataObj->resetRules();
     } else {
         $dataObj->clearSearchRule();
     }
     //echo "search rule is $this->searchRule"; exit;
     if ($this->fixSearchRule) {
         if ($this->searchRule) {
             $searchRule = $this->searchRule . " AND " . $this->fixSearchRule;
         } else {
             $searchRule = $this->fixSearchRule;
         }
     } else {
         $searchRule = $this->searchRule;
     }
     $dataObj->setSearchRule($searchRule);
     if ($this->startItem > 1) {
         $dataObj->setLimit($this->range, $this->startItem);
     } else {
         $dataObj->setLimit($this->range, ($this->currentPage - 1) * $this->range);
     }
     QueryStringParam::setBindValues($this->searchRuleBindValues);
     $resultRecords = $dataObj->fetch();
     $this->totalRecords = $dataObj->count();
     if ($this->range && $this->range > 0) {
         $this->totalPages = ceil($this->totalRecords / $this->range);
     }
     //$resultRecords = $dataObj->directFetch($searchRule);
     $counter = 0;
     while (true) {
         $arr = $resultRecords[$counter];
         if (!$arr) {
             break;
         }
         foreach ($this->dataPanel as $element) {
             $element->value = $arr[$element->fieldName];
             $value = $element->getValue();
             if ($element->fieldName && isset($value)) {
                 switch ($element->className) {
                     case "chart.lib.ChartColor":
                         $this->chartColorset[] = $value;
                         break;
                     case "chart.lib.ChartDataId":
                         $this->chartIdset[] = $value;
                         break;
                     case "chart.lib.ChartDescription":
                         $this->chartDescset[] = $value;
                         break;
                     case "chart.lib.ChartColor":
                         $this->chartColorset[] = $value;
                         break;
                     case "chart.lib.ChartCategory":
                         $this->chartCategory[] = $value;
                         break;
                     case "chart.lib.ChartData":
                         $this->chartDataset[$element->key][] = $value;
                         $this->chartDataAttrset[$element->key] = $element->attrs;
                         break;
                 }
             }
         }
         $counter++;
     }
 }
 public function fetchData()
 {
     if ($this->activeRecord != null) {
         return $this->activeRecord;
     }
     $dataObj = $this->getDataObj();
     if ($dataObj == null) {
         return;
     }
     $this->fixSearchRule = "[user_id]='0'";
     if (!$this->fixSearchRule && !$this->searchRule) {
         return array();
     }
     QueryStringParam::setBindValues($this->searchRuleBindValues);
     if ($this->isRefreshData) {
         $dataObj->resetRules();
     } else {
         $dataObj->clearSearchRule();
     }
     if ($this->fixSearchRule) {
         if ($this->searchRule) {
             $searchRule = $this->searchRule . " AND " . $this->fixSearchRule;
         } else {
             $searchRule = $this->fixSearchRule;
         }
     }
     $dataObj->setSearchRule($searchRule);
     QueryStringParam::setBindValues($this->searchRuleBindValues);
     $resultRecords = $dataObj->fetch();
     foreach ($resultRecords as $record) {
         $prefRecord["_" . $record['name']] = $record["value"];
     }
     $prefRecord["_siteurl"] = SITE_URL;
     $prefRecord["_system_name"] = OPENBIZ_DEFAULT_SYSTEM_NAME;
     $this->recordId = $resultRecords[0]['Id'];
     $this->setActiveRecord($prefRecord);
     QueryStringParam::ReSet();
     return $prefRecord;
 }
 protected function getDOFromList($selectFrom)
 {
     $pos0 = strpos($selectFrom, "[");
     $pos1 = strpos($selectFrom, "]");
     if ($pos0 > 0 && $pos1 > $pos0) {
         // select from bizObj
         // support BizObjName[BizFieldName] or
         // BizObjName[BizFieldName4Text:BizFieldName4Value] or
         // BizObjName[BizFieldName4Text:BizFieldName4Value:BizFieldName4Pic]
         $bizObjName = substr($selectFrom, 0, $pos0);
         $pos3 = strpos($selectFrom, ":");
         if ($pos3 > $pos0 && $pos3 < $pos1) {
             $fieldName = substr($selectFrom, $pos0 + 1, $pos3 - $pos0 - 1);
             $fieldName_v = substr($selectFrom, $pos3 + 1, $pos1 - $pos3 - 1);
         } else {
             $fieldName = substr($selectFrom, $pos0 + 1, $pos1 - $pos0 - 1);
             $fieldName_v = $fieldName;
         }
         $pos4 = strpos($fieldName_v, ":");
         if ($pos4) {
             $fieldName_v_mixed = $fieldName_v;
             $fieldName_v = substr($fieldName_v_mixed, 0, $pos4);
             $fieldName_p = substr($fieldName_v_mixed, $pos4 + 1, strlen($fieldName_v_mixed) - $pos4 - 1);
             unset($fieldName_v_mixed);
         }
         $commaPos = strpos($selectFrom, ",", $pos1);
         if ($commaPos > $pos1) {
             $searchRule = trim(substr($selectFrom, $commaPos + 1));
         }
         /* @var $bizObj BizDataObj */
         $bizObj = Openbiz::getObject($bizObjName);
         if (!$bizObj) {
             return false;
         }
         $recList = array();
         $oldAssoc = $bizObj->association;
         $bizObj->association = null;
         QueryStringParam::reset();
         $recList = $bizObj->directFetch($searchRule);
         $bizObj->association = $oldAssoc;
         foreach ($recList as $rec) {
             $list[$i]['val'] = $rec[$fieldName_v];
             $list[$i]['txt'] = $rec[$fieldName];
             $list[$i]['pic'] = $rec[$fieldName_p];
             $i++;
         }
         return $list;
     }
     return false;
 }
 public function fetchDataGroup()
 {
     //get group list first
     $dataObj = $this->getDataObj();
     if (!$dataObj) {
         return null;
     }
     if ($this->isRefreshData) {
         $dataObj->resetRules();
     } else {
         $dataObj->clearSearchRule();
     }
     if (strpos($this->groupBy, ":")) {
         preg_match("/\\[(.*?):(.*?)\\]/si", $this->groupBy, $match);
         $GroupFieldName = $match[1];
         $GroupField = $match[2];
     } else {
         $GroupField = str_replace("[", "", $this->groupBy);
         $GroupField = str_replace("]", "", $GroupField);
     }
     $GroupSQLRule = "GROUP BY [{$GroupField}]";
     $dataObj->setOtherSQLRule($GroupSQLRule);
     //within each group, search records like before
     QueryStringParam::setBindValues($this->searchRuleBindValues);
     if ($this->fixSearchRule) {
         if ($this->searchRule) {
             $searchRule = $this->searchRule . " AND " . $this->fixSearchRule;
         } else {
             $searchRule = $this->fixSearchRule;
         }
     } else {
         $searchRule = $this->searchRule;
     }
     $dataObj->setSearchRule($searchRule);
     $resultRecords = $dataObj->fetch();
     $this->totalRecords = $dataObj->count();
     if ($this->range && $this->range > 0) {
         $this->totalPages = ceil($this->totalRecords / $this->range);
     }
     $this->totalPagesBak = $this->totalPages;
     QueryStringParam::ReSet();
     //looping
     $i = 0;
     $results = array();
     foreach ($resultRecords as $record) {
         if ($this->isRefreshData) {
             $dataObj->resetRules();
         } else {
             $dataObj->clearSearchRule();
         }
         QueryStringParam::setBindValues($this->searchRuleBindValues);
         $group_val = $record[$GroupField];
         if ($this->fixSearchRule) {
             if ($this->searchRule) {
                 $searchRule = $this->searchRule . " AND " . $this->fixSearchRule;
             } else {
                 $searchRule = $this->fixSearchRule;
             }
         } else {
             $searchRule = $this->searchRule;
         }
         if ($group_val) {
             if ($searchRule != "") {
                 $searchRule = $searchRule . " AND [{$GroupField}]='{$group_val}'";
             } else {
                 $searchRule = " [{$GroupField}]='{$group_val}'";
             }
         } else {
             if ($searchRule != "") {
                 $searchRule = $searchRule . " AND [{$GroupField}]  is NULL";
             } else {
                 $searchRule = " [{$GroupField}] is NULL";
             }
         }
         $dataObj->setOtherSQLRule("");
         $dataObj->setLimit(0, 0);
         $dataObj->setSearchRule($searchRule);
         $resultRecords_grouped = $dataObj->fetch();
         //renderTable
         $resultRecords_grouped_table = $this->dataPanel->renderTable($resultRecords_grouped);
         if ($record[$GroupField]) {
             if ($GroupFieldName) {
                 $results[$record[$GroupFieldName]] = $resultRecords_grouped_table;
             } else {
                 $results[$record[$GroupField]] = $resultRecords_grouped_table;
             }
         } else {
             $results["Empty"] = $resultRecords_grouped_table;
         }
         $i++;
         QueryStringParam::ReSet();
     }
     //set active records
     $selectedIndex = 0;
     $this->getDataObj()->setActiveRecord($resultRecords[$selectedIndex]);
     return $results;
 }
/**
 * Convert the user input on a given fieldcontrol in query mode to search rule
 *
 * @param string $fieldName - fieldcontrol name
 * @param string $inputVal - use input text
 * @param EasyForm $formObj
 * @return string - searchRule
 */
function inputValToRule($fieldName, $inputVal, $formObj)
{
    // todo: should check single quote for nonoperators clauses
    // find locations for all sql key words
    // search for starting ' and closing ' pair, check if sql key word in the pair
    $val = strtoupper(trim($inputVal));
    // check " AND ", " OR "
    if (($pos = strpos($val, " AND ")) !== false) {
        $inputArr = explode(" AND ", $val);
        $retStr = null;
        foreach ($inputArr as $v) {
            $retStr .= $retStr ? " AND " . inputValToRule($fieldName, $v, $formObj) : inputValToRule($fieldName, $v, $formObj);
        }
        return $retStr;
    } else {
        if (($pos = strpos($val, " OR ")) !== false) {
            $inputArr = explode(" OR ", $val);
            $retStr = null;
            foreach ($inputArr as $v) {
                $retStr .= $retStr ? " OR " . inputValToRule($fieldName, $v, $formObj) : inputValToRule($fieldName, $v, $formObj);
            }
            return "(" . $retStr . ")";
        }
    }
    // check >=, >, <=, <, =
    if (($pos = strpos($val, "<>")) !== false || ($pos = strpos($val, "!=")) !== false) {
        $opr = "<>";
        $oprlen = 2;
    } else {
        if (($pos = strpos($val, ">=")) !== false) {
            $opr = ">=";
            $oprlen = 2;
        } else {
            if (($pos = strpos($val, ">")) !== false) {
                $opr = ">";
                $oprlen = 1;
            } else {
                if (($pos = strpos($val, "<=")) !== false) {
                    $opr = "<=";
                    $oprlen = 2;
                } else {
                    if (($pos = strpos($val, "<")) !== false) {
                        $opr = "<";
                        $oprlen = 1;
                    } else {
                        if (($pos = strpos($val, "=")) !== false) {
                            $opr = "=";
                            $oprlen = 1;
                        }
                    }
                }
            }
        }
    }
    if ($opr) {
        $val = trim(substr($val, $pos + $oprlen));
    }
    if (strpos($val, "*") !== false) {
        $opr = "LIKE";
        $val = str_replace("*", "%", $val);
    }
    //if (strpos($val, "'") !== false) {   // not needed since addslashes() is called before
    //   $val = str_replace("'", "\\'", $val);
    //}
    if (!$opr) {
        $opr = "=";
    }
    // unformat value to real value data
    if ($formObj->getDataObj()) {
        $bizField = $formObj->getDataObj()->getField($fieldName);
        $realValue = Openbiz::$app->getTypeManager()->formattedStringToValue($bizField->type, $bizField->format, $val);
    } else {
        $realValue = $val;
    }
    // set the query param
    $queryString = QueryStringParam::formatQueryString("[{$fieldName}]", $opr, $realValue);
    return $queryString;
    //return "[" . $field . "] " . $opr . " '" . $realVal . "'";
}