Exemplo n.º 1
0
function siremisFillDB()
{
    siremisReplaceDbConfig();
    BizSystem::log(LOG_DEBUG, "SIREMIS", "install module siremis sql - " . $_REQUEST['db1type']);
    if ($_REQUEST['db1type'] == "Pdo_Pgsql" || $_REQUEST['db1type'] == "pdo_pgsql") {
        $sqlfile = MODULE_PATH . "/ser/mod.install.siremis.pgsql.sql";
    } else {
        $sqlfile = MODULE_PATH . "/ser/mod.install.siremis.sql";
    }
    if (!file_exists($sqlfile)) {
        return true;
    }
    // Getting the SQL file content
    $query = trim(file_get_contents($sqlfile));
    if (empty($query)) {
        return true;
    }
    // $db = BizSystem::dbConnection("Serdb");
    $db = siremisConnectDB();
    include_once MODULE_PATH . "/system/lib/MySQLDumpParser.php";
    $queryArr = MySQLDumpParser::parse($query);
    foreach ($queryArr as $query) {
        try {
            $db->exec($query);
        } catch (Exception $e) {
            BizSystem::log(LOG_DEBUG, "SIREMIS", $e->getMessage());
            echo 'ERROR: ' . $e->getMessage();
            exit;
        }
    }
    return true;
}
Exemplo n.º 2
0
function giveActionAccess($where, $role_id)
{
    $db = BizSystem::dbConnection();
    try {
        if (empty($where)) {
            $sql = "SELECT * FROM acl_action";
        } else {
            $sql = "SELECT * FROM acl_action WHERE {$where}";
        }
        BizSystem::log(LOG_DEBUG, "DATAOBJ", $sql);
        $rs = $db->fetchAll($sql);
        $sql = "";
        foreach ($rs as $r) {
            $sql = "DELETE FROM acl_role_action WHERE role_id={$role_id} AND action_id={$r['0']}; ";
            BizSystem::log(LOG_DEBUG, "DATAOBJ", $sql);
            $db->query($sql);
            $sql = "INSERT INTO acl_role_action (role_id, action_id, access_level) VALUES ({$role_id},{$r['0']},1)";
            BizSystem::log(LOG_DEBUG, "DATAOBJ", $sql);
            $db->query($sql);
        }
    } catch (Exception $e) {
        echo "ERROR: " . $e->getMessage() . "" . PHP_EOL;
        return false;
    }
}
Exemplo n.º 3
0
 public function Log($eventName, $eventMessage, $eventComment = array())
 {
     global $g_BizSystem;
     $logDataObj = BizSystem::getObject($this->m_logDataObj);
     if (!$logDataObj) {
         return false;
     }
     $profile = $g_BizSystem->getUserProfile();
     $recArr['user_id'] = $profile["Id"];
     $recArr['ipaddr'] = $_SERVER['REMOTE_ADDR'];
     $recArr['event'] = $eventName;
     $recArr['message'] = $eventMessage;
     $recArr['comment'] = serialize($eventComment);
     $recArr['timestamp'] = date("Y-m-d H:i:s");
     $ok = $logDataObj->insertRecord($recArr);
     if ($ok == false) {
         BizSystem::log(LOG_ERR, "EVENTLOG", $logDataObj->getErrorMessage());
         return false;
     }
 }
Exemplo n.º 4
0
 public function runSearch()
 {
     //include_once(OPENBIZ_BIN . "/easy/SearchHelper.php");
     $searchRule = "";
     foreach ($this->m_SearchPanel as $element) {
         $searchStr = '';
         if (method_exists($element, "getSearchRule")) {
             $searchStr = $element->getSearchRule();
         } else {
             if (!$element->m_FieldName) {
                 continue;
             }
             $value = BizSystem::clientProxy()->getFormInputs($element->m_Name);
             if ($element->m_FuzzySearch == "Y") {
                 $value = "*{$value}*";
             }
             if ($value != '') {
                 $searchStr = inputValToRule($element->m_FieldName, $value, $this);
                 $values[] = $value;
             }
         }
         if ($searchStr) {
             if ($searchRule == "") {
                 $searchRule .= $searchStr;
             } else {
                 $searchRule .= " AND " . $searchStr;
             }
         }
     }
     $this->m_SearchRule = $searchRule;
     $this->m_SearchRuleBindValues = $values;
     $this->m_RefreshData = true;
     $this->m_CurrentPage = 1;
     BizSystem::log(LOG_DEBUG, "FORMOBJ", $this->m_Name . "::runSearch(), SearchRule=" . $this->m_SearchRule);
     $recArr = $this->readInputRecord();
     $this->m_SearchPanelValues = $recArr;
     $this->runEventLog();
     $this->rerender();
 }
Exemplo n.º 5
0
 public function render()
 {
     if (!$this->allowAccess()) {
         return "";
     }
     if ($this->m_CacheLifeTime > 0) {
         $cache_id = md5($this->m_Name);
         //try to process cache service.
         $cacheSvc = BizSystem::getService(CACHE_SERVICE, 1);
         $cacheSvc->init($this->m_Name, $this->m_CacheLifeTime);
         if ($cacheSvc->test($cache_id)) {
             BizSystem::log(LOG_DEBUG, "MENU", "Cache Hit. menu widget name = " . $this->m_Name);
             $output = $cacheSvc->load($cache_id);
         } else {
             BizSystem::log(LOG_DEBUG, "MENU", "Set cache. menu widget = " . $this->m_Name);
             $output = $this->renderHTML();
             $cacheSvc->save($output, $cache_id);
         }
         return $output;
     }
     $renderedHTML = $this->renderHTML();
     return $renderedHTML;
 }
Exemplo n.º 6
0
 /**
  * Render this form (return html content),
  * called by EasyView's render method (called when form is loaded).
  * Query is issued before returning the html content.
  *
  * @return string - HTML text of this form's read mode
  * @example ../../../example/FormObject.php
  */
 public function render()
 {
     if (!$this->allowAccess()) {
         return "";
     }
     if ($this->m_CacheLifeTime > 0 && $this->m_SubForms == null) {
         $cache_id = md5($this->m_Name);
         //try to process cache service.
         $cacheSvc = BizSystem::getService(CACHE_SERVICE, 1);
         $cacheSvc->init($this->m_Name, $this->m_CacheLifeTime);
         if ($cacheSvc->test($cache_id)) {
             BizSystem::log(LOG_DEBUG, "FORM", "Cache Hit. form name = " . $this->m_Name);
             $output = $cacheSvc->load($cache_id);
         } else {
             BizSystem::log(LOG_DEBUG, "FORM", "Set cache. form name = " . $this->m_Name);
             $output = $this->renderHTML();
             $cacheSvc->save($output, $cache_id);
         }
         return $output;
     }
     //Moved the renderHTML function infront of declaring subforms
     $renderedHTML = $this->renderHTML();
     // prepare the subforms' dataobjs, since the subform relates to parent form by dataobj association
     /*
             if ($this->m_SubForms && $this->getDataObj())
             {
                 foreach ($this->m_SubForms as $subForm)
                 {
                     $formObj = BizSystem::objectFactory()->getObject($subForm);
                     $dataObj = $this->getDataObj()->getRefObject($formObj->m_DataObjName);
                     if ($dataObj)
                         $formObj->setDataObj($dataObj);
                 }
             }
     */
     if (!$this->allowAccess()) {
         return "";
     }
     return $renderedHTML;
 }
Exemplo n.º 7
0
 /**
  * Update login time
  *
  * @return void
  */
 protected function UpdateloginTime()
 {
     $userObj = BizSystem::getObject('system.do.UserDO');
     try {
         $curRecs = $userObj->directFetch("[username]='" . $this->username . "'", 1);
         $dataRec = new DataRecord($curRecs[0], $userObj);
         $dataRec['lastlogin'] = date("Y-m-d H:i:s");
         $ok = $dataRec->save();
         if (!$ok) {
             $errorMsg = $userObj->getErrorMessage();
             BizSystem::log(LOG_ERR, "DATAOBJ", "DataObj error = " . $errorMsg);
             BizSystem::ClientProxy()->showErrorMessage($errorMsg);
             return false;
         }
     } catch (BDOException $e) {
         $errorMsg = $e->getMessage();
         BizSystem::log(LOG_ERR, "DATAOBJ", "DataObj error = " . $errorMsg);
         BizSystem::ClientProxy()->showErrorMessage($errorMsg);
         return false;
     }
     return true;
 }
Exemplo n.º 8
0
 public function getSQLFromList()
 {
     $sql = $this->getSelectFromSQL();
     if (!$sql) {
         return;
     }
     $formObj = $this->getFormObj();
     $do = $formObj->getDataObj();
     $db = $do->getDBConnection();
     try {
         $resultSet = $db->query($sql);
         $recList = $resultSet->fetchAll();
         foreach ($recList as $rec) {
             $list[$i]['val'] = $rec[0];
             $list[$i]['txt'] = isset($rec[1]) ? $rec[1] : $rec[0];
             $i++;
         }
     } catch (Exception $e) {
         BizSystem::log(LOG_ERR, "DATAOBJ", "Query Error: " . $e->getMessage());
         $this->m_ErrorMessage = "Error in SQL query: " . $sql . ". " . $e->getMessage();
         throw new BDOException($this->m_ErrorMessage);
         return null;
     }
     return $list;
 }
Exemplo n.º 9
0
 /**
  * Get the number of records according the Select SQL
  *
  * @param object $db database connection
  * @param string $sql SQL string
  * @return int number of records
  */
 private function _getNumberRecords($db, $sql)
 {
     $has_subquery = false;
     if (preg_match("/\\(\\s*?SELECT\\s*?.+\\)/si", $sql)) {
         $has_subquery = true;
     }
     if (preg_match("/^\\s*SELECT\\s+DISTINCT/is", $sql) || preg_match('/\\s+GROUP\\s+BY\\s+/is', $sql)) {
         // ok, has SELECT DISTINCT or GROUP BY so see if we can use a table alias
         $rewritesql = preg_replace('/(\\sORDER\\s+BY\\s.*)/is', '', $sql);
         $rewritesql = "SELECT COUNT(*) FROM ({$rewritesql}) _TABLE_ALIAS_";
     } elseif ($has_subquery == false) {
         // now replace SELECT ... FROM with SELECT COUNT(*) FROM
         $rewritesql = preg_replace('/\\s*?SELECT\\s.*?\\s+FROM\\s/is', 'SELECT COUNT(*) FROM ', $sql);
         // Because count(*) and 'order by' fails with mssql, access and postgresql.
         // Also a good speedup optimization - skips sorting!
         $rewritesql = preg_replace('/(\\sORDER\\s+BY\\s.*)/is', '', $rewritesql);
     } else {
         $rewritesql = $sql;
     }
     try {
         if ($this->m_CacheLifeTime > 0) {
             $cache_id = md5($this->m_Name . $rewritesql . serialize($bindValues));
             //try to process cache service.
             $cacheSvc = BizSystem::getService(CACHE_SERVICE);
             $cacheSvc->init($this->m_Name, $this->m_CacheLifeTime);
             if ($cacheSvc->test($cache_id)) {
                 //BizSystem::log(LOG_DEBUG, "DATAOBJ", ". Query Sql = ".$rewritesql);
                 $resultArray = $cacheSvc->load($cache_id);
             } else {
                 BizSystem::log(LOG_DEBUG, "DATAOBJ", "Query Sql = " . $rewritesql);
                 $result = $db->query($rewritesql);
                 $resultArray = $result->fetch();
                 $cacheSvc->save($resultArray, $cache_id);
             }
         } else {
             BizSystem::log(LOG_DEBUG, "DATAOBJ", "Query Sql = " . $rewritesql);
             $resultSet = $db->query($rewritesql);
             $resultArray = $resultSet->fetch();
         }
     } catch (Exception $e) {
         BizSystem::log(LOG_ERR, "DATAOBJ", "Query Error: " . $e->getMessage());
         $this->m_ErrorMessage = $this->getMessage("DATA_ERROR_QUERY") . ": Rewrite:" . $rewritesql . ". Raw:" . $sql . ". " . $e->getMessage();
         throw new BDOException($this->m_ErrorMessage);
         return 0;
     }
     if ($has_subquery) {
         $record_count = (int) $resultSet->rowCount();
     } else {
         $record_count = (int) $resultArray[0];
     }
     return (string) $record_count;
 }
Exemplo n.º 10
0
 /**
  * Get ID with SQL
  *
  * @param Zend_Db_Adapter_Abstract $conn
  * @param string $sql
  * @return mixed
  */
 private function _getIdWithSql($conn, $sql)
 {
     try {
         $rs = $conn->query($sql);
         BizSystem::log(LOG_DEBUG, "DATAOBJ", "Get New Id: {$sql}");
     } catch (Exception $e) {
         $this->m_ErrorMessage = "Error in query: " . $sql . ". " . $e->getMessage();
         return false;
     }
     if (($row = $rs->fetch()) != null) {
         //print_r($row);
         return $row[0];
     }
     return false;
 }
Exemplo n.º 11
0
 /**
  * Handle the exception from DataObj method,
  *  report the error as an alert window
  *
  * @param int $errCode
  * @return string
  */
 public function processBDOException($e)
 {
     $errorMsg = $e->getMessage();
     BizSystem::log(LOG_ERR, "DATAOBJ", "DataObj error = " . $errorMsg);
     //BizSystem::clientProxy()->showClientAlert($errorMsg);   //showErrorMessage($errorMsg);
     //BizSystem::clientProxy()->showErrorMessage($errorMsg);
     $e->no_exit = true;
     OB_ErrorHandler::ExceptionHandler($e);
 }
Exemplo n.º 12
0
 /**
  * Save session variables of all stateful objects into sessionid_obj file
  *
  * @return void
  **/
 public function saveSessionObjects()
 {
     // loop all objects (bizview, bizform, bizdataobj) collect their session vars
     $allobjs = BizSystem::objectFactory()->getAllObjects();
     foreach ($allobjs as $obj) {
         if (method_exists($obj, "SetSessionVars")) {
             //after calling $obj->setSessionVars SessObjArr and StatefulSessObjArr are filled
             $obj->setSessionVars($this);
         }
         // if previous view's object is used in current view, don't discard its session data
         if (isset($obj->m_Name) && key_exists($obj->m_Name, $this->_prevViewObjNames)) {
             unset($this->_prevViewObjNames[$obj->m_Name]);
             BizSystem::log(LOG_ERR, "SESSION", "unset " . $obj->m_Name);
         }
     }
     // discard useless previous view's session objects
     //foreach($this->_prevViewObjNames as $objName=>$tmp)
     //    unset($this->_sessObjArr[$objName]);
     $this->_sessObjArr["ViewHist"] = $this->_viewHistory;
     $this->setVar(OB_TRANSIENT_DATA_SESSION_INDEX, $this->_sessObjArr);
     $this->setVar(OB_STATEFUL_DATA_SESSION_INDEX, $this->_statefulSessObjArr);
 }
Exemplo n.º 13
0
 private static function _removeRecordSelftoSelf($dataObj, $recArr)
 {
     // delete a record on XTable
     $db = $dataObj->getDBConnection();
     //TODO: delete using XDataObj if XDataObj is defined
     $where = $dataObj->m_Association["XColumn1"] . "='" . $dataObj->m_Association["FieldRefVal"] . "'";
     $where .= " AND " . $dataObj->m_Association["XColumn2"] . "='" . $recArr["Id"] . "'";
     $sql = "DELETE FROM " . $dataObj->m_Association["XTable"] . " WHERE " . $where;
     $where_2 = $dataObj->m_Association["XColumn2"] . "='" . $dataObj->m_Association["FieldRefVal"] . "'";
     $where_2 .= " AND " . $dataObj->m_Association["XColumn1"] . "='" . $recArr["Id"] . "'";
     $sql_2 = "DELETE FROM " . $dataObj->m_Association["XTable"] . " WHERE " . $where_2;
     try {
         BizSystem::log(LOG_DEBUG, "DATAOBJ", "Associate Delete Sql = {$sql}");
         $db->query($sql);
         $db->query($sql_2);
     } catch (Exception $e) {
         BizSystem::log(LOG_ERR, "DATAOBJ", "Query Error: " . $e->getMessage());
         throw new BDOException("Query Error: " . $e->getMessage());
         return false;
     }
     return true;
 }
Exemplo n.º 14
0
 /**
  * Log that an email attemp was made.
  * We assume it was successfull, since Zend_Mail throws an exception otherwise
  *
  * @param string $subject
  * @param array $To
  * @param array $CCs
  * @param array $BCCs
  * @return mixed boolean|string|void
  */
 public function logEmail($result, $subject, $body = NULL, $TOs = NULL, $CCs = NULL, $BCCs = NULL)
 {
     //Log the email attempt
     $recipients = '';
     // add TO addresses
     if ($TOs) {
         foreach ($TOs as $to) {
             if (is_array($to)) {
                 $recipients .= $to['name'] . "<" . $to['email'] . ">;";
             } else {
                 $recipients .= $to . ";";
             }
         }
     }
     // add CC addresses
     if ($CCs) {
         foreach ($CCs as $cc) {
             if (is_array($cc)) {
                 $recipients .= $cc['name'] . "<" . $cc['email'] . ">;";
             } else {
                 $recipients .= $cc . ";";
             }
         }
     }
     // add BCC addresses
     if ($BCCs) {
         foreach ($BCCs as $bcc) {
             if (is_array($bcc)) {
                 $recipients .= $bcc['name'] . "<" . $bcc['email'] . ">;";
             } else {
                 $recipients .= $bcc . ";";
             }
         }
     }
     if ($this->_logType == 'DB') {
         $account = $this->m_Accounts->get($this->m_UseAccount);
         $sender_name = $account->m_FromName;
         $sender = $account->m_FromEmail;
         // Store the message log
         $boMessageLog = BizSystem::getObject($this->_logObject);
         $mlArr = $boMessageLog->newRecord();
         $mlArr["sender"] = $sender;
         $mlArr["sender_name"] = $sender_name;
         $mlArr["recipients"] = $recipients;
         $mlArr["subject"] = $subject;
         $mlArr["content"] = $body;
         $mlArr["result"] = $result;
         //Escape Data since this may contain quotes or other goodies
         foreach ($mlArr as $key => $value) {
             $mlArr[$key] = addslashes($value);
         }
         $ok = $boMessageLog->insertRecord($mlArr);
         if (!$ok) {
             return $boMessageLog->getErrorMessage();
         } else {
             return TRUE;
         }
     } else {
         $back_trace = debug_backtrace();
         if ($result == 'Success') {
             $logNum = LOG_INFO;
         } else {
             $logNum = LOG_ERR;
         }
         BizSystem::log($logNum, "EmailService", "Sent email with subject - \"{$subject}\" and body - {$body} to - {$recipients} with result {$result}.", NULL, $back_trace);
     }
 }
Exemplo n.º 15
0
 /**
  * Render this view. This function is called by Render() or ReRender()
  *
  * @return mixed either print html content or return html content if called by Render(), or void if called by ReRender()
  */
 protected function _render()
 {
     $this->setClientScripts();
     if ($this->m_CacheLifeTime > 0) {
         $pageUrl = $this->curPageURL();
         $cache_id = md5($pageUrl);
         //try to process cache service.
         $cacheSvc = BizSystem::getService(CACHE_SERVICE, 1);
         $cacheSvc->init($this->m_Name, $this->m_CacheLifeTime);
         if ($cacheSvc->test($cache_id)) {
             BizSystem::log(LOG_DEBUG, "VIEW", "Cache Hit. url = " . $pageUrl);
             $output = $cacheSvc->load($cache_id);
         } else {
             include_once OPENBIZ_BIN . "/easy/ViewRenderer.php";
             $this->m_ConsoleOutput = false;
             $output = ViewRenderer::render($this);
             BizSystem::log(LOG_DEBUG, "VIEW", "Set cache. url = " . $pageUrl);
             $cacheSvc->save($output, $cache_id);
         }
         print $output;
     } else {
         include_once OPENBIZ_BIN . "/easy/ViewRenderer.php";
         ViewRenderer::render($this);
     }
     return;
     /*
             $this->setClientScripts();
           	include_once(OPENBIZ_BIN."/easy/ViewRenderer.php"); 
     	    return ViewRenderer::render($this);*/
 }
Exemplo n.º 16
0
 /**
  * BizForm::runSearch() - Run search on query mode, then go read mode
  *
  * @return void
  */
 public function runSearch()
 {
     BizSystem::log(LOG_DEBUG, "FORMOBJ", $this->m_Name . "::runSearch()");
     global $g_BizSystem;
     $this->m_SearchRule = "";
     foreach ($this->m_RecordRow as $fldCtrl) {
         $value = BizSystem::clientProxy()->getFormInputs($fldCtrl->m_Name);
         if ($value !== null && $value !== '') {
             $searchStr = $this->inputValToRule($fldCtrl->m_BizFieldName, $value);
             if ($searchStr) {
                 $this->m_SearchRule .= $this->m_SearchRule == '' ? $searchStr : ' AND ' . $searchStr;
             } else {
                 // If it's emtpy; we will not alter anything
             }
         }
     }
     $this->SetDisplayMode(MODE_R);
     $this->gotoPage(1);
     $this->m_RecordId = null;
     // clean the current record id
     $this->m_ClearSearchRule = true;
     $this->rerender();
 }
Exemplo n.º 17
0
 /**
  * Render this form (return html content),
  * called by EasyView's render method (called when form is loaded).
  * Query is issued before returning the html content.
  *
  * @return string - HTML text of this form's read mode
  * @example ../../../example/FormObject.php
  */
 public function render()
 {
     if (!$this->allowAccess()) {
         return "";
     }
     //$this->setClientScripts();
     if ($this->m_CacheLifeTime > 0 && $this->m_SubForms == null) {
         $cache_id = md5($this->m_Name);
         //try to process cache service.
         $cacheSvc = BizSystem::getService(CACHE_SERVICE, 1);
         $cacheSvc->init($this->m_Name, $this->m_CacheLifeTime);
         if ($cacheSvc->test($cache_id)) {
             BizSystem::log(LOG_DEBUG, "FORM", "Cache Hit. form name = " . $this->m_Name);
             $output = $cacheSvc->load($cache_id);
         } else {
             BizSystem::log(LOG_DEBUG, "FORM", "Set cache. form name = " . $this->m_Name);
             $output = FormRenderer::render($this);
             $cacheSvc->save($output, $cache_id);
         }
         return $output;
     }
     //Moved the renderHTML function infront of declaring subforms
     $output = FormRenderer::render($this);
     // lazy subform loading - prepare the subforms' dataobjs, since the subform relates to parent form by dataobj association
     $this->prepareSubFormsDataObj();
     return $output;
 }
Exemplo n.º 18
0
 /**
  * Set the search rule of the bizform, this search rule will apply on its bizdataobj
  *
  * @param string $rule - search rule has format "[fieldName1] opr1 Value1 AND/OR [fieldName2] opr2 Value2"
  * @param boolean $overwrite specify if this rule should overwrite any existing rule
  * @return void
  */
 public function setSearchRule($rule = null, $overwrite = false)
 {
     if (!$rule) {
         return;
     } elseif (!$this->m_SearchRule or $overwrite == true) {
         $this->m_SearchRule = $rule;
     } elseif (strpos($this->m_SearchRule, $rule) === false) {
         $this->m_SearchRule .= " AND " . $rule;
     }
     echo $this->m_SearchRule;
     BizSystem::log(LOG_DEBUG, "FORMOBJ", $this->m_Name . " SetSearch() " . $this->m_SearchRule);
 }
Exemplo n.º 19
0
 /**
  * Generate an unique token for future validation
  *
  * @param array $userProfile user profile array
  * @return mixed $token array or false
  */
 protected function GenerateToken($userProfile)
 {
     $token = uniqid();
     $recArr = array("user_id" => $userProfile['Id'], "token" => $token, "expiration" => date("Y-m-d H:i:s", time() + 86400 * 2));
     $tokenObj = BizSystem::getObject('system.do.UserPassTokenDO');
     try {
         if ($tokenObj->insertRecord($recArr)) {
             $recArr = $tokenObj->getActiveRecord();
             return $recArr;
         } else {
             return false;
         }
     } catch (BDOException $e) {
         $errorMsg = $e->getMessage();
         BizSystem::log(LOG_ERR, "DATAOBJ", "DataObj error = " . $errorMsg);
         BizSystem::ClientProxy()->showErrorMessage($errorMsg);
         return false;
     }
 }
Exemplo n.º 20
0
 /**
  * Check expression for syntax errors just before eval() function
  * If the expression fails, do not eval the funciton.  Return DEBUG error in logs
  *
  * @param string $code - expression text
  * @return boolean
  **/
 public static function eval_syntax($code)
 {
     $b = 0;
     foreach (token_get_all($code) as $token) {
         if ('{' == $token) {
             ++$b;
         } else {
             if ('}' == $token) {
                 --$b;
             }
         }
     }
     if ($b) {
         return false;
     } else {
         // --- fix for parse error
         if (preg_match('{[[:alnum:]]+([,][ ][[:digit:]]+){2}}', $code, $matches) === 1) {
             BizSystem::log(LOG_ERR, 'MATCH', __LINE__ . ': preg_match: ' . $code . '; $matches = ' . var_export($matches, true) . ' ' . $error);
             return false;
         }
         ob_start();
         // Catch potential parse error messages
         // if(preg_match("/.*?\= '.*?'/si",$code)){
         //if(!preg_match("/,/si",$code) && !preg_match("/\//si",$code)){
         //if( !preg_match("/\//si",$code)){
         $r = eval('if(0){' . $code . '}');
         // Put $code in a dead code sandbox to prevent its execution
         //}else{
         //	return false;
         //}
         $error = ob_get_contents();
         if ($r === false) {
             //trigger_error("EVAL: $code ".$error, E_USER_ERROR);
             //      added by shyokou in 'Expression.php'    {
             //
             trigger_error('EVAL: ' . $code . ' ' . $error, E_USER_ERROR);
             BizSystem::log(LOG_ERR, 'ERROR', 'EVAL: ' . $code . ' ' . $error);
             //
             //      added by shyokou in 'Expression.php'    }
             //BizSystem::log(LOG_ERR, "ERROR", "EVAL: $code. ".$error);
         }
         ob_end_clean();
         return false !== $r;
     }
 }
Exemplo n.º 21
0
 /**
  * Run Search
  *
  * @return void
  */
 public function runSearch()
 {
     /*static $isSearchHelperLoaded = false;
       
       if (!$isSearchHelperLoaded) {
           include_once(OPENBIZ_BIN."/easy/SearchHelper.php");
           $isSearchHelperLoaded = true;
       }*/
     $queryArray = array();
     foreach ($this->m_SearchPanel as $element) {
         if (!$element->m_FieldName) {
             continue;
         }
         $value = BizSystem::clientProxy()->getFormInputs($element->m_Name);
         $this->m_SearchPanelValues[$element->m_FieldName] = $value;
         // ??? neede
         if ($element->m_FuzzySearch == "Y") {
             $value = "*{$value}*";
         }
         if ($value != '') {
             $this->queryParams[$element->m_FieldName] = $value;
         }
     }
     $this->m_RefreshData = true;
     $this->m_CurrentPage = 1;
     BizSystem::log(LOG_DEBUG, "FORMOBJ", $this->m_Name . "::runSearch(), SearchRule=" . $this->m_SearchRule);
     //$recArr = $this->readInputRecord();
     //$this->m_SearchPanelValues = $recArr;
     //$this->runEventLog();
     $this->rerender();
 }
Exemplo n.º 22
0
 /**
  * Import from CSV file
  * NOTE: This method must be called from a popup form where a file is uploaded.
  *       The parent form of the popup form is the target to import.
  *
  * @param string $objName
  * @return void
  */
 public function importCSV($objName)
 {
     // read in file from $_FILE
     foreach ($_FILES as $file) {
         $error = $file['error'];
         if ($error != 0) {
             $this->reportError($error);
             return;
         }
         $tmpFileName = $file['tmp_name'];
         break;
     }
     //echo "upload file name = $tmpFileName";
     $filename = $file['name'];
     if (strpos($filename, ".csv") === false) {
         $errorMsg = BizSystem::getMessage("EXCELSVC_INVALID_FILE", array($filename));
         BizSystem::log(LOG_ERR, "EXCEL SERVICE", "Import error = " . $errorMsg);
         BizSystem::clientProxy()->showClientAlert($errorMsg);
         return;
     }
     /* @var $formObj EasyForm */
     $formObj = BizSystem::objectFactory()->getObject($objName);
     // get the existing EasyForm object
     $parentFormObj = BizSystem::objectFactory()->getObject($formObj->m_ParentFormName);
     $dataObj = $parentFormObj->getDataObj();
     $handle = fopen($tmpFileName, "r");
     $fields = fgetcsv($handle, 2000, ",");
     if (!$fields || count($fields) < 2) {
         $errorMsg = BizSystem::getMessage("EXCELSVC_INVALID_FILE", array($filename));
         BizSystem::log(LOG_ERR, "EXCEL SERVICE", "Import error = " . $errorMsg);
         BizSystem::clientProxy()->showClientAlert($errorMsg);
         return;
     }
     // convert form element names to DO field names
     foreach ($parentFormObj->m_DataPanel as $element) {
         $elem_fields[$element->m_Label] = $element->m_FieldName;
     }
     // validate with dataobj fields
     for ($i = 0; $i < count($fields); $i++) {
         $fields[$i] = $elem_fields[$fields[$i]];
         $field = $fields[$i];
         if (!$dataObj->getField($field)) {
             $errorMsg = BizSystem::getMessage("EXCELSVC_INVALID_COLUMN", array($field, $dataObj->m_Name));
             BizSystem::log(LOG_ERR, "EXCEL SERVICE", "Import error = " . $errorMsg);
             BizSystem::clientProxy()->showClientAlert($errorMsg);
             return;
         }
     }
     while (($arr = fgetcsv($handle, 2000, ",")) !== FALSE) {
         if (count($arr) != count($fields)) {
             continue;
         }
         unset($recArr);
         $i = 0;
         for ($i = 0; $i < count($arr); $i++) {
             $recArr[$fields[$i]] = $arr[$i];
         }
         //print_r($recArr); echo "<hr>";
         $dataRec = new DataRecord(null, $dataObj);
         foreach ($recArr as $k => $v) {
             $dataRec[$k] = $v;
         }
         $ok = $dataRec->save();
         if (!$ok) {
             // NOTE: EasyForm::processDataObjError() not return any value (void)
             return $formObj->processDataObjError($ok);
         }
     }
     fclose($handle);
     // in case of popup form, close it, then rerender the parent form
     if ($formObj->m_ParentFormName) {
         $formObj->close();
         $formObj->renderParent();
     }
 }
Exemplo n.º 23
0
 /**
  * Audit DataObj
  *
  * @param string $dataObjName
  * @return boolean
  * @todo all return false? really?
  */
 public function audit($dataObjName)
 {
     // get audit dataobj
     $auditDataObj = BizSystem::getObject($this->m_AuditDataObj);
     if (!$auditDataObj) {
         return false;
     }
     // get the source dataobj
     $srcDataObj = BizSystem::getObject($dataObjName);
     if (!$srcDataObj) {
         return false;
     }
     // for each onaudit field, add a record in audit dataobj
     $auditFields = $srcDataObj->getOnAuditFields();
     foreach ($auditFields as $field) {
         if ($field->m_OldValue == $field->m_Value) {
             continue;
         }
         $recArr = $auditDataObj->newRecord();
         if ($recArr == false) {
             BizSystem::log(LOG_ERR, "DATAOBJ", $auditDataObj->getErrorMessage());
             return false;
         }
         $profile = BizSystem::getUserProfile();
         $recArr['DataObjName'] = $dataObjName;
         $recArr['ObjectId'] = $srcDataObj->getFieldValue("Id");
         $recArr['FieldName'] = $field->m_Name;
         $recArr['OldValue'] = $field->m_OldValue;
         $recArr['NewValue'] = $field->m_Value;
         $recArr['ChangeTime'] = date("Y-m-d H:i:s");
         $recArr['ChangeBy'] = $profile["USERID"];
         $recArr['ChangeFrom'] = $_SERVER['REMOTE_ADDR'];
         $recArr['RequestURI'] = $_SERVER['REQUEST_URI'];
         $recArr['Timestamp'] = date("Y-m-d H:i:s");
         $ok = $auditDataObj->insertRecord($recArr);
         if ($ok == false) {
             BizSystem::log(LOG_ERR, "DATAOBJ", $auditDataObj->getErrorMessage());
             return false;
         }
     }
 }
Exemplo n.º 24
0
 public function fetchTreeByName($start_item, $deep)
 {
     if ($this->m_CacheLifeTime > 0) {
         $cache_id = md5($this->m_Name . "-" . $start_item . "-" . $deep);
         //try to process cache service.
         $cacheSvc = BizSystem::getService(CACHE_SERVICE, 1);
         $cacheSvc->init($this->m_Name, $this->m_CacheLifeTime);
         if ($cacheSvc->test($cache_id)) {
             BizSystem::log(LOG_DEBUG, "MENU", "Cache Hit. menu fetch tree, name = " . $this->m_Name);
             $output = $cacheSvc->load($cache_id);
         } else {
             BizSystem::log(LOG_DEBUG, "MENU", "Set cache. menu fetch tree, name = " . $this->m_Name);
             if ($start_item != "") {
                 //$this->fetchEntireTree();
                 $tree = $this->getTreeByStartItem($start_item);
             }
             $output = $this->cutTree($tree, $deep);
             $cacheSvc->save($output, $cache_id);
         }
         $tree = $output;
     } else {
         if ($start_item != "") {
             //$this->fetchEntireTree();
             $tree = $this->getTreeByStartItem($start_item);
         }
         $tree = $this->cutTree($tree, $deep);
     }
     return $tree->m_ChildNodes;
 }
Exemplo n.º 25
0
 protected function processCascadeAction($objRef, $cascadeType)
 {
     if ($cascadeType == 'Delete' && $objRef->m_OnDelete || $cascadeType == 'Update' && $objRef->m_OnUpdate) {
         if ($objRef->m_Relationship == "1-M" || $objRef->m_Relationship == "1-1") {
             $table = $objRef->m_Table;
             $column = $objRef->m_Column;
         } else {
             if ($objRef->m_Relationship == "M-M") {
                 $table = $objRef->m_XTable;
                 $column = $objRef->m_XColumn1;
             }
         }
         $refField = $this->getField($objRef->m_FieldRef);
         $fieldVal = $this->getFieldValue($objRef->m_FieldRef);
         if (!$fieldVal) {
             return;
         }
         $db = $this->getDBConnection();
         // get the cascade action sql
         if ($cascadeType == 'Delete') {
             if ($objRef->m_OnDelete == "Cascade") {
                 $sql = "DELETE FROM " . $table . " WHERE " . $column . "='" . $fieldVal . "'";
             } else {
                 if ($objRef->m_OnDelete == "SetNull") {
                     $sql = "UPDATE " . $table . " SET {$column}=null WHERE " . $column . "='" . $fieldVal . "'";
                 } else {
                     if ($objRef->m_OnDelete == "Restrict") {
                         // check if objRef has records
                         $refObj = $this->getRefObject($objRef->m_Name);
                         if (count($refObj->directFetch("", 1)) == 1) {
                             throw new BDOException($this->getMessage("DATA_UNABLE_DEL_REC_CASCADE", array($objRef->m_Name)));
                         }
                         return;
                     }
                 }
             }
         } else {
             if ($cascadeType == 'Update') {
                 // check if the column value is actually changed
                 if ($refField->m_OldValue == $refField->m_Value) {
                     return;
                 }
                 if ($objRef->m_OnUpdate == "Cascade") {
                     $sql = "UPDATE " . $table . " SET {$column}='" . $refField->m_Value . "' WHERE " . $column . "='" . $refField->m_OldValue . "'";
                 } else {
                     if ($objRef->m_OnUpdate == "SetNull") {
                         $sql = "UPDATE " . $table . " SET {$column}=null WHERE " . $column . "='" . $refField->m_OldValue . "'";
                     } else {
                         if ($objRef->m_OnUpdate == "Restrict") {
                             // check if objRef has records
                             $refObj = BizSystem::getObject($objRef->m_Name);
                             if (count($refObj->directFetch("[" . $objRef->m_FieldRef . "]='" . $refField->m_OldValue . "'", 1)) == 1) {
                                 throw new BDOException($this->getMessage("DATA_UNABLE_UPD_REC_CASCADE", array($objRef->m_Name)));
                             }
                             return;
                         }
                     }
                 }
             }
         }
         try {
             BizSystem::log(LOG_DEBUG, "DATAOBJ", "Cascade {$cascadeType} Sql = {$sql}");
             $db->query($sql);
         } catch (Exception $e) {
             BizSystem::log(LOG_Err, "DATAOBJ", "Cascade {$cascadeType} Error: " . $e->getMessage());
             $this->m_ErrorMessage = $this->getMessage("DATA_ERROR_QUERY") . ": " . $sql . ". " . $e->getMessage();
             throw new BDOException($this->m_ErrorMessage);
         }
     }
 }
Exemplo n.º 26
0
 /**
  * Run search on query mode, then go read mode
  *
  * @return void
  */
 public function runSearch($targetForm = null)
 {
     BizSystem::log(LOG_DEBUG, "FORMOBJ", $this->m_Name . "::runSearch(), SearchRule=" . $this->m_SearchRule);
     global $g_BizSystem;
     $searchRule = "";
     foreach ($this->m_RecordRow as $fldCtrl) {
         $value = BizSystem::clientProxy()->getFormInputs($fldCtrl->m_Name);
         if ($value) {
             $searchStr = $this->inputValToRule($fldCtrl->m_BizFieldName, $value);
             if ($searchRule == "") {
                 $searchRule .= $searchStr;
             } else {
                 $searchRule .= " AND " . $searchStr;
             }
         }
     }
     if ($targetForm) {
         $tgtForm = BizSystem::objectFactory()->getObject($targetForm);
         if ($tgtForm) {
             $tgtForm->setSearchRule($searchRule);
             return $tgtForm->rerender();
         }
         return;
     }
     $this->m_SearchRule = $searchRule;
     //$this->SetDisplayMode (MODE_R);
     $this->gotoPage(1);
     $this->m_ClearSearchRule = true;
     $this->rerender();
 }