Exemplo n.º 1
0
 /**
  * Replase field expression with value from $bizObj
  *
  * @param string $expression
  * @param BizDataObj $bizObj
  * @return mixed
  */
 protected static function replaceFieldsExpr($expression, $bizObj)
 {
     $script = "";
     $start = 0;
     // replace [field] with field value
     while (true) {
         $pos0 = strpos($expression, "[", $start);
         $pos1 = strpos($expression, "]", $start);
         if ($pos0 === false) {
             $script .= substr($expression, $start);
             break;
         }
         if ($pos0 >= 0 && $pos1 > $pos0) {
             $script .= substr($expression, $start, $pos0 - $start);
             $start = $pos1 + 1;
             $fieldName = substr($expression, $pos0 + 1, $pos1 - $pos0 - 1);
             // get field value
             $fieldValue = $bizObj->getField($fieldName)->value;
             if ($fieldValue == null) {
                 $fieldValue = $bizObj->getFieldValue($fieldName);
             }
             if ($fieldValue !== null) {
                 $script .= $fieldValue;
             } else {
                 //$script .= substr($expression, $pos0, $pos1 - $pos0);
                 //return "fail to evaluate $expression";
                 return "";
             }
         } elseif ($pos0 >= 0 && $pos1 <= $pos0) {
             break;
         }
     }
     return $script;
 }
Exemplo n.º 2
0
 public function UpdateRecord($recArr, $oldRec = null)
 {
     $l_Profile = BizSystem::sessionContext()->getVar("_USER_PROFILE");
     if (!$l_Profile) {
         return false;
     }
     $recArr['username'] = $l_Profile['username'];
     $recArr['ha1'] = md5($recArr['username'] . ':' . $recArr['domain'] . ':' . $recArr['password']);
     $recArr['ha1b'] = md5($recArr['username'] . '@' . $recArr['domain'] . ':' . $recArr['domain'] . ':' . $recArr['password']);
     return parent::UpdateRecord($recArr, $oldRec);
 }
Exemplo n.º 3
0
 public function insertRecord($recArr)
 {
     foreach ($this->fields as $field) {
         if (isset($recArr[$field])) {
             $datetime = explode(' ', $recArr[$field]);
             $date = explode('-', $datetime[0]);
             $time = explode(':', $datetime[1]);
             $recArr[$field] = mktime((int) $time[0], (int) $time[1], (int) $time[2], (int) $date[1], (int) $date[2], (int) $date[0]);
         }
     }
     return parent::insertRecord($recArr);
 }
Exemplo n.º 4
0
 /**
  * Pick the joined object's current record to the current record
  *
  * @param BizDataObj $joinDataObj
  * @param string $joinName name of join (optional)
  * @return array return a modified record with joined record data
  */
 public function joinRecord($joinDataObj, $joinName = "")
 {
     // get the maintable of the joindataobj
     $joinTable = $joinDataObj->m_MainTable;
     $joinRecord = null;
     $returnRecord = array();
     // find the proper join according to join name and the maintable
     foreach ($this->m_TableJoins as $tableJoin) {
         if (($joinName == $tableJoin->m_Name || $joinName == "") && $tableJoin->m_Table == $joinTable) {
             // populate the column-fieldvalue to columnRef-fieldvalue
             // get the field mapping to the column, then get the field value
             $joinFieldName = $joinDataObj->m_BizRecord->getFieldByColumn($tableJoin->m_Column);
             // joined-main table
             if (!$joinFieldName) {
                 continue;
             }
             if (!$joinRecord) {
                 $joinRecord = $joinDataObj->getActiveRecord();
             }
             $refFieldName = $this->m_BizRecord->getFieldByColumn($tableJoin->m_ColumnRef);
             // join table
             $returnRecord[$refFieldName] = $joinRecord[$joinFieldName];
             // populate joinRecord's field to current record
             foreach ($this->m_BizRecord as $fld) {
                 if ($fld->m_Join == $tableJoin->m_Name) {
                     // use join column to match joinRecord field's column
                     $jfldname = $joinDataObj->m_BizRecord->getFieldByColumn($fld->m_Column);
                     // joined-main table
                     $returnRecord[$fld->m_Name] = $joinRecord[$jfldname];
                 }
             }
             break;
         }
     }
     // return a modified record with joined record data
     return $returnRecord;
 }
Exemplo n.º 5
0
 /**
  * Set the association of the object
  *
  * @param ObjReference $objRef
  * @param BizDataObj $asscObj
  * @return void
  */
 protected function setAssociation($objRef, $asscObj)
 {
     $this->m_Association["AsscObjName"] = $asscObj->m_Name;
     $this->m_Association["Relationship"] = $objRef->m_Relationship;
     $this->m_Association["Table"] = $objRef->m_Table;
     $this->m_Association["Column"] = $objRef->m_Column;
     $this->m_Association["FieldRef"] = $objRef->m_FieldRef;
     $this->m_Association["FieldRefVal"] = $asscObj->getFieldValue($objRef->m_FieldRef);
     if ($objRef->m_Relationship == "M-M") {
         $this->m_Association["XTable"] = $objRef->m_XTable;
         $this->m_Association["XColumn1"] = $objRef->m_XColumn1;
         $this->m_Association["XColumn2"] = $objRef->m_XColumn2;
         $this->m_Association["XKeyColumn"] = $objRef->m_XKeyColumn;
         $this->m_Association["XDataObj"] = $objRef->m_XDataObj;
     }
 }
Exemplo n.º 6
0
 public function insertRecord($recArr)
 {
     $oflags = $recArr['flags_other'];
     if ($recArr['flags'][0] == ",") {
         $recArr['flags'] = "00";
     }
     $inactive = "0";
     $probing = "0";
     if (strlen($recArr['flags']) > 0) {
         $sflagsArr = explode(",", $recArr['flags']);
         $inactive = array_search("1", $sflagsArr) !== FALSE ? "1" : "0";
         $probing = array_search("2", $sflagsArr) !== FALSE ? "1" : "0";
     }
     $sflags = $probing . $inactive;
     $recArr['flags'] = (string) (bindec($oflags) | bindec($sflags));
     $attributes = explode(',', $recArr['attrs']);
     if (strlen($attributes[0]) == 0) {
         $recArr['attrs'] = '';
     } else {
         if (strlen($attributes[1]) > 0) {
             $recArr['attrs'] = str_replace(',', '=', $recArr['attrs']);
             $recArr['attrs'] .= ';';
         } else {
             $recArr['attrs'] = $attributes[0] . '=0;';
         }
     }
     $recArr['attrs'] .= $recArr['attrs_other'];
     if (substr($recArr['attrs'], -1) == ';') {
         $recArr['attrs'] = substr($recArr['attrs'], 0, -1);
     }
     return parent::insertRecord($recArr);
 }
Exemplo n.º 7
0
 /**
  * Get reference object with given object name
  *
  * @param string $objName name of the object reference
  * @return obejct the instance of reference object
  */
 public function getRefObject($objName)
 {
     return $this->bizDataObj->getRefObject($objName);
 }
Exemplo n.º 8
0
 /**
  * Build insert-sql
  * INSERT INTO table_name (column1, column2,...) VALUES (value1, value2,....)
  *
  * @param BizDataObj $dataObj
  * @param array $joinValues array of join values
  * @return string Insert-SQL statement
  */
 public function buildInsertSQL($dataObj, $joinValues = null)
 {
     // generate column value pairs.
     $sqlFlds = $dataObj->m_BizRecord->getToSaveFields('CREATE');
     $dbInfo = BizSystem::configuration()->getDatabaseInfo($dataObj->m_Database);
     $dbType = $dbInfo["Driver"];
     $sql_col = "";
     $sql_val = "";
     $db = $dataObj->getDBConnection('WRITE');
     foreach ($sqlFlds as $fldobj) {
         $col = $fldobj->m_Column;
         // if Field Id has null value and Id is an identity type, remove the Id's column from the array
         if ($fldobj->m_Name == "Id" && $dataObj->m_IdGeneration == "Identity") {
             continue;
         }
         if ($fldobj->isLobField()) {
             // special value for blob/clob type
             $_val = $fldobj->getInsertLobValue($dbType);
         } else {
             $_val = $fldobj->getSqlValue();
             if ($_val == '' && $fldobj->m_ValueOnCreate != "") {
                 $_val = $fldobj->getValueOnCreate();
             }
         }
         //if (!$_val || $_val == '') continue;
         // modified by jixian for not ignore 0 value
         if ($_val === '') {
             continue;
         }
         $sql_col .= "`" . $col . "`, ";
         $sql_val .= $db->quote($_val) . ", ";
         //$sql_val .= QueryStringParam::formatQueryValue($_val). ", ";
     }
     // if joinValues is given then add join values in to the main table InsertSQL.
     if (is_array($joinValues)) {
         foreach ($joinValues as $joinColumn => $joinValue) {
             if (!$joinValue || $joinValue == '') {
                 continue;
             }
             $sql_col .= "`" . $joinColumn . "`, ";
             $sql_val .= "'" . $joinValue . "', ";
         }
     }
     $sql_col = substr($sql_col, 0, -2);
     $sql_val = substr($sql_val, 0, -2);
     $sql = "INSERT INTO  `" . $dataObj->m_MainTable . "` (" . $sql_col . ") VALUES (" . $sql_val . ")";
     return $sql;
 }
Exemplo n.º 9
0
 /**
  * Remove record many to one
  *
  * @global BizSystem $g_BizSystem
  * @param BizDataObj $dataObj
  * @param array $recArr
  * @return boolean
  */
 private static function _removeRecordMto1($dataObj, $recArr)
 {
     // set the $recArr[Id] to the parent table foriegn key column
     // get parent/association dataobj
     $asscObj = Openbizx::getObject($dataObj->association["AsscObjName"]);
     // call parent dataobj's updateRecord
     $updateRecArr["Id"] = $asscObj->getFieldValue("Id");
     $updateRecArr[$dataObj->association["FieldRef"]] = "";
     $ok = $asscObj->updateRecord($updateRecArr);
     if ($ok == false) {
         return false;
     }
     // requery on this object
     $dataObj->association["FieldRefVal"] = "";
     return $dataObj->runSearch();
 }
Exemplo n.º 10
0
 /**
  * Get reference object with given object name
  *
  * @param string $objName name of the object reference
  * @return obejct the instance of reference object
  */
 public function getRefObject($objName)
 {
     return $this->m_BizObj->getRefObject($objName);
 }
Exemplo n.º 11
0
 public function UpdateRecord($recArr, $oldRec = null)
 {
     $recArr['ha1'] = md5($recArr['username'] . ':' . $recArr['domain'] . ':' . $recArr['password']);
     $recArr['ha1b'] = md5($recArr['username'] . '@' . $recArr['domain'] . ':' . $recArr['domain'] . ':' . $recArr['password']);
     return parent::UpdateRecord($recArr, $oldRec);
 }
Exemplo n.º 12
0
 /**
  * Get reference object with given object name
  *
  * @param string $objName name of the object reference
  * @return obejct the instance of reference object
  */
 public function getRefObject($objName)
 {
     $this->m_BizObj->setActiveRecord($this->m_var);
     return $this->m_BizObj->getRefObject($objName);
 }
Exemplo n.º 13
0
 protected function loadFullMenuTree()
 {
     if (self::$fullMenuTree != null) {
         return;
     }
     $cache_id = 'FULL_MENU_LIST';
     $cacheSvc = BizSystem::getService(CACHE_SERVICE, 1);
     $cacheSvc->init($this->m_Name, 600);
     // cache for 10 mins
     if ($cacheSvc->test($cache_id)) {
         self::$fullMenuTree = $cacheSvc->load($cache_id);
         return;
     }
     $rs = parent::directFetch();
     foreach ($rs as $record) {
         if (empty($record['PId'])) {
             $record['PId'] = "__root__";
         }
         unset($record['create_by']);
         unset($record['create_time']);
         unset($record['update_by']);
         unset($record['update_time']);
         unset($record['name']);
         unset($record['parent']);
         self::$fullMenuTree[$record['Id']] = $record;
     }
     foreach (self::$fullMenuTree as $mId => $record) {
         self::$fullMenuTree[$record['PId']]['children'][] = $mId;
     }
     //print_r(self::$fullMenuTree);
     $cacheSvc->save(self::$fullMenuTree, $cache_id);
     // put it in apc or file cache
 }