/** * Proses security rule * return true go to check next rule * return false report an error and stop checking * * @return boolean */ public function process() { if (strtoupper($this->status) == 'ENABLE') { parent::process(); if (!$this->checkEffectiveTime()) { return true; } else { $get_str = serialize($_GET); if (preg_match("/" . $this->match . "/si", $get_str)) { if (strtoupper($this->action) == 'OPENBIZ_DENY') { $this->errorMessage = MessageHelper::getMessage('SECURITYSVC_GET_DENIED'); return false; } elseif (strtoupper($this->action) == 'OPENBIZ_ALLOW') { return true; } return false; } } } }
/** * 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 = MessageHelper::getMessage("EXCELSVC_INVALID_FILE", array($filename)); Openbizx::$app->getLog()->log(LOG_ERR, "EXCEL SERVICE", "Import error = " . $errorMsg); Openbizx::$app->getClientProxy()->showClientAlert($errorMsg); return; } /* @var $formObj EasyForm */ $formObj = Openbizx::getObject($objName); // get the existing EasyForm object $parentFormObj = Openbizx::getObject($formObj->parentFormName); $dataObj = $parentFormObj->getDataObj(); $handle = fopen($tmpFileName, "r"); $fields = fgetcsv($handle, 2000, ","); if (!$fields || count($fields) < 2) { $errorMsg = MessageHelper::getMessage("EXCELSVC_INVALID_FILE", array($filename)); Openbizx::$app->getLog()->log(LOG_ERR, "EXCEL SERVICE", "Import error = " . $errorMsg); Openbizx::$app->getClientProxy()->showClientAlert($errorMsg); return; } // convert form element names to DO field names foreach ($parentFormObj->dataPanel as $element) { $elem_fields[$element->label] = $element->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 = MessageHelper::getMessage("EXCELSVC_INVALID_COLUMN", array($field, $dataObj->objectName)); Openbizx::$app->getLog()->log(LOG_ERR, "EXCEL SERVICE", "Import error = " . $errorMsg); Openbizx::$app->getClientProxy()->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->parentFormName) { $formObj->close(); $formObj->renderParent(); } }
public function deleteRecords($condition = null) { if (!$this->canDeleteRecordCondition()) { throw new Openbiz\Data\Exception(MessageHelper::getMessage("DATA_NO_PERMISSION_DELETE", $this->objectName)); return false; } $sql = $this->getSQLHelper()->buildDeleteSQLwithCondition($this, $condition); $db = $this->getDBConnection("WRITE"); try { if ($sql) { // delete joint table first then delete main table's data' Openbiz::$app->getLog()->log(LOG_DEBUG, "DATAOBJ", "Delete Sql = {$sql}"); $db->query($sql); } } catch (Exception $e) { Openbiz::$app->getLog()->log(LOG_ERR, "DATAOBJ", "Query error : " . $e->getMessage()); $db->rollBack(); //if one failed then rollback all $this->errorMessage = $this->getMessage("DATA_ERROR_QUERY") . ": " . $sql . ". " . $e->getMessage(); throw new Openbiz\Data\Exception($this->errorMessage); return false; } //clean cached data $this->cleanCache(); return true; }
/** * Returns the database info from <DataSource> defined in application.xml as an array. * Returned array is a 2D map. * (DBName1 => ["Name"], ["Driver"], ["Server"], ["DBName"], ["User"], {"Password"]) * (DBName2 => ["Name"], ["Driver"], ["Server"], ["DBName"], ["User"], {"Password"]) * (...) * If DBName is given, returns the record only related to the given DBName, * otherwise returns all records * * @param string $dbName * @return array database information */ public function getDatabaseInfo($dbName = null) { if ($dbName && $this->_databaseInfo[$dbName]) { return $this->_databaseInfo[$dbName]; } if (!$this->_xmlArr["APPLICATION"]["DATASOURCE"]) { $errMsg = MessageHelper::getMessage("SYS_ERROR_NODBINFO"); trigger_error($errMsg, E_USER_ERROR); } $breakFlag = false; foreach ($this->_xmlArr["APPLICATION"]["DATASOURCE"]["DATABASE"] as $db) { if (isset($this->_xmlArr["APPLICATION"]["DATASOURCE"]["DATABASE"]['ATTRIBUTES'])) { $db = $this->_xmlArr["APPLICATION"]["DATASOURCE"]["DATABASE"]; $breakFlag = true; } $tmp["Name"] = $db["ATTRIBUTES"]["NAME"]; $tmp["Driver"] = $db["ATTRIBUTES"]["DRIVER"]; $tmp["Server"] = $db["ATTRIBUTES"]["SERVER"]; $tmp["DBName"] = $db["ATTRIBUTES"]["DBNAME"]; $tmp["User"] = $db["ATTRIBUTES"]["USER"]; $tmp["Password"] = $db["ATTRIBUTES"]["PASSWORD"]; $tmp["Port"] = isset($db["ATTRIBUTES"]["PORT"]) ? $db["ATTRIBUTES"]["PORT"] : null; $tmp["Charset"] = isset($db["ATTRIBUTES"]["CHARSET"]) ? $db["ATTRIBUTES"]["CHARSET"] : null; $tmp["Options"] = isset($db["ATTRIBUTES"]["OPTIONS"]) ? $db["ATTRIBUTES"]["OPTIONS"] : null; $this->_databaseInfo[$tmp["Name"]] = $tmp; if ($breakFlag) { break; } } if ($dbName && $this->_databaseInfo[$dbName]) { return $this->_databaseInfo[$dbName]; } if ($dbName && !isset($this->_databaseInfo[$dbName])) { $errMsg = MessageHelper::getMessage("DATA_INVALID_DBNAME", array($dbName, $dbName)); trigger_error($errMsg, E_USER_ERROR); } if (!$dbName) { return $this->_databaseInfo; } }