/** * Fetch record * * @param string $doName data object name * @param string $searchRule rule of search * @return mixed */ public function fetchRecord($doName, $searchRule) { $do = Openbizx::getObject($doName); if (!$do) { throw new Exception("System cannot get object of {$doName}."); return; } $r = $do->directFetch($searchRule, 1); if (count($r) > 0) { return $r[0]; } return null; }
protected function getDOFromList(&$list, $selectFrom) { // from Database $pos0 = strpos($selectFrom, "["); $pos1 = strpos($selectFrom, "]"); if ($pos0 > 0 && $pos1 > $pos0) { // select from bizObj // support BizObjName[BizFieldName] or BizObjName[BizFieldName4Text:BizFieldName4Value] $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; } $this->selectFieldName = $fieldName; $commaPos = strpos($selectFrom, ",", $pos1); $commaPos2 = strpos($selectFrom, ",", $commaPos + 1); if ($commaPos > $pos1) { if ($commaPos2) { $searchRule = trim(substr($selectFrom, $commaPos + 1, $commaPos2 - $commaPos - 1)); } else { $searchRule = trim(substr($selectFrom, $commaPos + 1)); } } if ($commaPos2 > $commaPos) { $rootSearchRule = trim(substr($selectFrom, $commaPos2 + 1)); } $bizObj = Openbizx::getObject($bizObjName); if (!$bizObj) { return; } $recList = array(); $oldAssoc = $bizObj->association; $bizObj->association = null; if ($searchRule) { $searchRule = Expression::evaluateExpression($searchRule, $this->getFormObj()); } if ($rootSearchRule) { $rootSearchRule = Expression::evaluateExpression($rootSearchRule, $this->getFormObj()); } else { $rootSearchRule = "[PId]=0 OR [PId]='' OR [PId] is NULL"; } $recListTree = $bizObj->fetchTree($rootSearchRule, 100, $searchRule); $bizObj->association = $oldAssoc; if (!$recListTree) { return; } // bugfix : error if data blank foreach ($recListTree as $recListTreeNode) { $this->tree2array($recListTreeNode, $recList); } foreach ($recList as $rec) { $list[$i]['val'] = $rec[$fieldName_v]; $list[$i]['txt'] = $rec[$fieldName]; $i++; } return; } }
protected function getDOFromList(&$list, $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 = Openbizx::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 true; } return false; }
/** * Get the object instance defined in the object reference * * @param string $objName the object name list in the ObjectReference part * @return BizDataObj object instance */ public function getRefObject($objName) { // see if there is such object in the ObjReferences $objRef = $this->objReferences->get($objName); if (!$objRef) { return null; } // apply association on the object // $assc = $this->EvaluateExpression($objRef->association); // get the object instance $obj = Openbizx::getObject($objName); $obj->setAssociation($objRef, $this); return $obj; }
protected function getFormObj() { return Openbizx::getObject($this->formName); }
/** * Build the Select SQL statement based on the fields and search/sort rule * * @param BizDataObj $dataObj * @return void */ public function buildQuerySQL($dataObj) { //echo "buildQuerySQL ".$dataObj->objectName."\n"; // TODO: the same dataobj re-uses the same datasqlobj ... // build the SQL statement based on the fields and search rule $dataSqlObj = $this->getNewDataSqlObj($dataObj); if ($dataSqlObj->isfresh()) { // add table $dataSqlObj->addMainTable($dataObj->mainTableName); // add join table if ($dataObj->tableJoins) { foreach ($dataObj->tableJoins as $tableJoin) { $tbl_col = $dataSqlObj->addJoinTable($tableJoin, $this); } } // add columns foreach ($dataObj->bizRecord as $bizField) { if ($bizField->ignoreInQuery) { // field to be ignore in query - save memory continue; } if ($bizField->column && $bizField->type == "Blob") { // ignore blob column continue; } if ($bizField->column && !$bizField->sqlExpression && strpos($bizField->column, ',') == 0) { $dataSqlObj->addTableColumn($bizField->join, $bizField->column, $bizField->aliasName); } if ($bizField->sqlExpression) { $dataSqlObj->addSqlExpression($this->_convertSqlExpression($dataObj, $bizField->sqlExpression), $bizField->aliasName); } } } $dataSqlObj->resetSQL(); // append DataPerm in the WHERE clause if ($dataObj->dataPermControl == 'Y') { $svcObj = Openbizx::getService(OPENBIZ_DATAPERM_SERVICE); $hasOwnerField = $this->_hasOwnerField($dataObj); $dataPermSQLRule = $svcObj->buildSqlRule($dataObj, 'select', $hasOwnerField); $sqlSearchRule = $this->_ruleToSql($dataObj, $dataPermSQLRule); $dataSqlObj->addSqlWhere($sqlSearchRule); } // append QueryPameters in the WHERE clause foreach ($dataObj->getQueryParameters() as $fieldName => $value) { $queryRule = queryParamToRule($fieldName, $value, $dataObj); $sqlSearchRule = $this->_ruleToSql($dataObj, $queryRule); $dataSqlObj->addSqlWhere($sqlSearchRule); } // append SearchRule in the WHERE clause $sqlSearchRule = $this->_ruleToSql($dataObj, $dataObj->searchRule); $dataSqlObj->addSqlWhere($sqlSearchRule); // append SearchRule in the ORDER BY clause $sqlSortRule = $this->_ruleToSql($dataObj, $dataObj->sortRule); $dataSqlObj->addOrderBy($sqlSortRule); // append SearchRule in the other SQL clause $sqlOtherSQLRule = $this->_ruleToSql($dataObj, $dataObj->otherSQLRule); $dataSqlObj->addOtherSQL($sqlOtherSQLRule); // append SearchRule in the AccessRule clause $sqlAccessSQLRule = $this->_ruleToSql($dataObj, $dataObj->accessRule); $dataSqlObj->addSqlWhere($sqlAccessSQLRule); // add association to SQL if ($dataObj->association["AsscObjName"] != "" && $dataObj->association["FieldRefVal"] == "") { $asscObj = Openbizx::getObject($dataObj->association["AsscObjName"]); $dataObj->association["FieldRefVal"] = $asscObj->getFieldValue($dataObj->association["FieldRef"]); } if ($dataObj->association["AsscObjName"] != "" && $dataObj->association["FieldRefVal2"] == "") { $asscObj = Openbizx::getObject($dataObj->association["AsscObjName"]); $dataObj->association["FieldRefVal2"] = $asscObj->getFieldValue($dataObj->association["FieldRef2"]); } if ($dataObj->association["Relationship"] == "Self-Self") { $dataObj->association["ParentRecordIdColumn"] = $dataObj->getField("Id")->column; } $dataSqlObj->addAssociation($dataObj->association); // apply _ruleToSql to JoinCondition if any if ($dataSqlObj->hasJoinCondition) { $dataSqlObj->setTableJoinStm($this->_ruleToSql($dataObj, $dataSqlObj->getTableJoinStm())); } $querySQL = $dataSqlObj->getSqlStatement() . " "; //echo $querySQL."###\n"; return $querySQL; }
/** * Replace var expression * @objname:property, @objname:field[fldname].property, @objname:control[ctrlname].property * @:prop = @thisobjname:prop * * @global BizSystem $g_BizSystem * @param string $expression * @param object $object * @return string */ protected static function replaceVarExpr($expression, $object) { // replace @objname:property to GetObject()->getProperty(property) while (true) { // TODO: one clause must be separated by whitespace //modified by jixian for support package full name of a object //e.g : shared.objects.compaines.objCompany:Field[Id].Value $pattern = "/@([[a-zA-Z0-9_\\.]*):([a-zA-Z0-9_\\.\\[\\]]+)/"; if (!preg_match($pattern, $expression, $matches)) { break; } $macro = $matches[0]; $objName = $matches[1]; $propExpr = $matches[2]; $obj = null; if ($objName == "profile") { // @profile:attribute is reserved $profileAttribute = Openbizx::$app->getUserProfile($propExpr); $expression = str_replace($macro, $profileAttribute, $expression); continue; } if ($objName == "home") { // @home:url is reserved switch ($propExpr) { case "url": $value = "'" . OPENBIZ_APP_INDEX_URL . "'"; break; case "base_url": $value = "'" . OPENBIZ_APP_URL . "'"; break; } $expression = str_replace($macro, $value, $expression); continue; } elseif (in_array($objName, array_keys(Expression::$services))) { // reserved keywords $body = $expression; $objFunc = '@' . $objName . ':' . $propExpr; $posStart = strpos($body, $objFunc); $beforeString = substr($body, 0, $posStart); $paramStart = strpos($body, $objFunc . '(') + strlen($objFunc . '('); $paramEnd = strpos($body, ')', $paramStart); $paramLen = $paramEnd - $paramStart; $function = $propExpr; $paramString = substr($body, $paramStart, $paramLen); $restString = substr($body, $paramEnd + 1); $paramString = Expression::evaluateExpression('{' . $paramString . '}', $object); $serviceName = Expression::$services[$objName]; $serviceObj = Openbizx::getService($serviceName); $params = explode(',', $paramString); for ($i = 0; $i < count($params); $i++) { $params[$i] = trim($params[$i]); } $val_result = call_user_func_array(array($serviceObj, $function), $params); return $beforeString . $val_result . $restString; } elseif ($objName == "" || $objName == "this") { $obj = $object; $body = $expression; $objFunc = '@' . $objName . ':' . $propExpr; $posStart = strpos($body, $objFunc); $beforeString = substr($body, 0, $posStart); if (strpos($body, '(') > 0 && substr($expression, 0, 2) == '@:') { $paramStart = strpos($body, $objFunc . '(') + strlen($objFunc . '('); $paramEnd = strpos($body, ')', $paramStart); $paramLen = $paramEnd - $paramStart; $function = $propExpr; $paramString = substr($body, $paramStart, $paramLen); $restString = substr($body, $paramEnd + 1); $params = explode(',', $paramString); // bug fix for ($i = 0; $i < count($params); $i++) { $params[$i] = trim($params[$i]); } if (!is_array($params)) { $params = array(); } if (method_exists($obj, $function)) { $val_result = call_user_func_array(array($obj, $function), $params); return $beforeString . $val_result . $restString; } } } else { $obj = Openbizx::getObject($objName); } if ($obj == null) { throw new \Exception("Wrong expression syntax " . $expression . ", cannot get object " . $objName); } $pos = strpos($propExpr, "."); $paramStart = strpos($expression, $objFunc . '('); if ($pos > 0) { // in case of @objname:field[fldname].property $property1 = substr($propExpr, 0, $pos); $property2 = substr($propExpr, $pos + 1); $propertyObj = $obj->getProperty($property1); if ($propertyObj == null) { $propertyObj = $obj->getDataObj()->getProperty($property1); if ($propertyObj == null) { throw new Exception("Wrong expression syntax " . $expression . ", cannot get property object " . $property1 . " of object " . $objName); } else { $val = $propertyObj->getProperty($property2); } } $val = $propertyObj->getProperty($property2); } else { // in case of @objname:property $val = $obj->getProperty($propExpr); } if ($val === null) { $val = ""; } if (is_string($val)) { $val = "'{$val}'"; } $expression = str_replace($macro, $val, $expression); } return $expression; }
/** * Show HTML error message * This method call by {@link ShowErrorMessage} if RPC flag false. * * @param string $errMsg error message * @return void */ private function _errorOutput($errMsg) { //ob_clean(); //Openbizx::$app->isInitialized = false; if (defined('OPENBIZ_INTERNAL_ERROR_VIEW') && Openbizx::$app->isInitialized) { //render the view $_GET['ob_err_msg'] = $errMsg; ob_end_clean(); Openbizx::getObject(OPENBIZ_INTERNAL_ERROR_VIEW)->render(); exit; } else { echo $errMsg; echo "<input type='button' NAME='btn_back' VALUE='Go back' onClick='history.go(-1);return true;'>"; } }
/** * Gather all template variables needed. Should play well with Smarty or \Zend templates * * @param WebPage $webPage * @return array associative array holding all needed VIEW based template variables */ public static function buildTemplateAttributes($webPage) { // Assocative Array to hold all Template Values // Fill with default viewobj attributes //$tplAttributes = $viewObj->outputAttrs(); //Not sure what this is doing... $newClntObjs = ''; //Fill other direct view variables $tplAttributes["module"] = $webPage->getModuleName($webPage->objectName); $tplAttributes["description"] = $webPage->objectDescription; $tplAttributes["keywords"] = $webPage->keywords; if (isset($webPage->tiles)) { foreach ($webPage->tiles as $tname => $tile) { // renderForms() : BEGIN foreach ($tile as $formRef) { if ($formRef->display == false) { continue; } $tiles[$tname][$formRef->objectName] = Openbizx::getObject($formRef->objectName)->render(); $tiletabs[$tname][$formRef->objectName] = $formRef->objectDescription; } // renderForms() : END } } else { // renderForms() : BEGIN foreach ($webPage->formRefs as $formRef) { if ($formRef->display == false) { continue; } $forms[$formRef->objectName] = Openbizx::getObject($formRef->objectName)->render(); $formtabs[$formRef->objectName] = $formRef->objectDescription; } // renderForms() : END } if (count($webPage->widgets)) { // renderForms() : BEGIN foreach ($webPage->widgets as $formRef) { if ($formRef->display == false) { continue; } $widgets[$formRef->objectName] = Openbizx::getObject($formRef->objectName)->render(); } } //Fill Loop related data $tplAttributes["forms"] = $forms; $tplAttributes["widgets"] = $widgets; $tplAttributes["formtabs"] = $formtabs; $tplAttributes["tiles"] = $tiles; $tplAttributes["tiletabs"] = $tiletabs; // add clientProxy scripts $includedScripts = Openbizx::$app->getClientProxy()->getAppendedScripts(); $tplAttributes["style_sheets"] = Openbizx::$app->getClientProxy()->getAppendedStyles(); if ($webPage->isPopup && $bReRender == false) { $moveToCenter = "moveToCenter(self, " . $webPage->width . ", " . $webPage->height . ");"; $tplAttributes["scripts"] = $includedScripts . "\n<script>\n" . $newClntObjs . $moveToCenter . "</script>\n"; } else { $tplAttributes["scripts"] = $includedScripts . "\n<script>\n" . $newClntObjs . "</script>\n"; } if ($webPage->title) { $tplAttributes["title"] = Expression::evaluateExpression($webPage->title, $webPage); } else { $tplAttributes["title"] = $webPage->objectDescription; } if (OPENBIZ_DEFAULT_SYSTEM_NAME) { $tplAttributes["title"] = $tplAttributes["title"] . ' - ' . OPENBIZ_DEFAULT_SYSTEM_NAME; } return $tplAttributes; }
public function targetSwitchForm($targetForm, $formName = null, $id = null, $params = null, $target = null) { if ($targetForm) { $formObj = Openbizx::getObject($targetForm); if ($formObj) { return $formObj->switchForm($formName, $id, $params, $target); } } }
/** * Run DataObject trigger * * @param string $triggerType type of the trigger */ private function _runDOTrigger($triggerType) { // locate the trigger metadata file BOName_Trigger.xml $triggerServiceName = $this->objectName . "_Trigger"; $xmlFile = ObjectFactoryHelper::getXmlFileWithPath($triggerServiceName); if (!$xmlFile) { return; } $triggerService = Openbizx::getObject($triggerServiceName); if ($triggerService == null) { return; } // invoke trigger service ExecuteTrigger($triggerType, $currentRecord) $triggerService->execute($this, $triggerType); }
/** * Get the {@link BizDataObj} instance * * @return BizDataObj {@link BizDataObj} instance */ protected function getDataObj() { return Openbizx::getObject($this->bizDataObjName); }
/** * Get the openbiz view object by object name. * It's functional same as getObject() method, just this method can return more eclipse friendly result, * it can support IDE's code auto completaion. * * @param string $objectName object name * @return WebPage if the return object is a WebPage then return, or return null * @example ../../example/ViewObject.php */ public static function getWebpageObject($objectName) { return Openbizx::getObject($objectName, 0); }
public function getValue() { if ($this->allowAccess()) { $formElementObj = Openbizx::getObject($this->formReference); if (method_exists($formElementObj, "getValue")) { return $formElementObj->getValue(); } } }
private function executeRpcMethod($objName, $methodName, $params) { $obj = Openbizx::getObject($objName); if ($obj) { if (method_exists($obj, $methodName)) { if (!$this->validateRequest($obj, $methodName)) { $errmsg = MessageHelper::getMessage("SYS_ERROR_REQUEST_REJECT", array($obj->objectName, $methodName)); trigger_error($errmsg, E_USER_ERROR); } switch (count($params)) { case 0: $rt_val = $obj->{$methodName}(); break; case 1: $rt_val = $obj->{$methodName}($params[0]); break; case 2: $rt_val = $obj->{$methodName}($params[0], $params[1]); break; case 3: $rt_val = $obj->{$methodName}($params[0], $params[1], $params[2]); break; default: $rt_val = call_user_func_array(array($obj, $methodName), $params); } } else { $errmsg = MessageHelper::getMessage("SYS_ERROR_METHODNOTFOUND", array($objName, $methodName)); trigger_error($errmsg, E_USER_ERROR); } } else { $errmsg = MessageHelper::getMessage("SYS_ERROR_CLASSNOTFOUND", array($objName)); trigger_error($errmsg, E_USER_ERROR); } $invocationType = $this->request->getInvocationType(); if ($invocationType == "Invoke") { // no RPC invoke, page reloaded -> rerender view if ($this->getClientProxy()->hasOutput()) { $this->getClientProxy()->printOutput(); } } else { if ($invocationType == "RPCInvoke") { // RPC invoke if ($this->getClientProxy()->hasOutput()) { if ($_REQUEST['jsrs'] == 1) { echo "<html><body><form name=\"jsrs_Form\"><textarea name=\"jsrs_Payload\" id=\"jsrs_Payload\">"; } $this->getClientProxy()->printOutput(); if ($_REQUEST['jsrs'] == 1) { echo "</textarea></form></body></html>"; } } else { return $rt_val; } } } }
/** * Process request * * @return void */ protected function processRequest() { // if url has form=... $paramForm = isset($_REQUEST['form']) ? $_REQUEST['form'] : null; // check url arg as fld:name=val $getKeys = array_keys($_REQUEST); $pageid = $_GET["pageid"]; $paramFields = null; foreach ($getKeys as $key) { if (substr($key, 0, 4) == "fld:") { $fieldName = substr($key, 4); $fieldValue = $_REQUEST[$key]; $paramFields[$fieldName] = $fieldValue; } } if (!$paramFields && !$pageid) { return; } // get the form object if (!$paramForm) { // get the first form name if no form is given foreach ($this->formRefs as $formRef) { $paramForm = $formRef->objectName; break; } } if (!$paramForm) { return; } $paramForm = $this->prefixPackage($paramForm); $formObj = Openbizx::getObject($paramForm); $formObj->setRequestParams($paramFields); if ($pageid) { $formObj->setCurrentPage($pageid); } }
public function getInvokeAction() { if ($this->formedFunction) { return $this->formedFunction; } $name = $this->_elemName; $ehName = $this->objectName; $formobj = Openbizx::getObject($this->_formName); if (!$this->formedFunction) { // add direct URL support if ($this->url) { $_func = "loadPage('" . $this->url . "');"; } else { if (strpos($this->function, "js:") === 0) { $_func = substr($this->function, 3) . ";"; } else { $temp = $this->functionType == null ? "" : ",'" . $this->functionType . "'"; //$_func = "SetOnElement('$name:$ehName'); Openbizx.CallFunction('" . $this->function . "'$temp);"; list($funcName, $funcParams) = $this->parseFunction($this->function); $funcParams = Expression::evaluateExpression($funcParams, $formobj); $action = "{$name}:{$ehName}"; // TODO: encrypt paramString to add more security $_func = "Openbizx.invoke('{$this->_formName}','{$action}','{$funcParams}'{$temp});"; } } //$_func = Expression::evaluateExpression($_func, $formobj); $this->formedFunction = $_func; } return $this->formedFunction; }