コード例 #1
0
ファイル: controller.php プロジェクト: u007/FlexiPHP
 function methodProcessForm()
 {
     $aForm = $this->loadForm();
     //var_dump($aForm["form"]);
     if (!$this->validateForm($aForm["form"])) {
         FlexiLogger::error(__METHOD__, "Validation failed");
         $this->addMessage("Validation failed", "error");
         return $this->renderForm($aForm);
     }
     //var_dump($this->getRequest("txtListKey"));
     $oModel = $this->getModelFromForm("RepositoryListValuesTable", $aForm["form"]);
     if (!$oModel->isValid()) {
         FlexiLogger::error(__METHOD__, "Validation failed.");
         $this->addMessage("Validation failed.", "error");
         return $this->runControl("form");
     }
     try {
         $oModel->replace();
         //$this->oView->addVar("message", "saved.");
         $this->addMessage("Saved", "success");
         return $this->redirectControl(null, "default");
     } catch (Exception $e) {
         FlexiLogger::error(__METHOD__, "Save failed:" . $e->getMessage());
         return $this->runControl("form");
     }
 }
コード例 #2
0
ファイル: FlexiRemoteServer.php プロジェクト: u007/FlexiPHP
 public function run()
 {
     try {
         $this->oRequest = $this->_run();
         $oRequest =& $this->oRequest;
         $this->sServiceModule = $oRequest->module;
         $this->sServiceMethod = $oRequest->method;
         $this->sServiceToken = $oRequest->token;
         FlexiLogger::info(__METHOD__, "Running service: " . $this->sServiceModule . "::" . $this->sServiceMethod);
         FlexiLogger::debug(__METHOD__, "Token: " . $this->sServiceToken);
         //throw new Exception("Token: " . $this->sServiceToken);
         //if ($this->sServiceMethod!="login") throw new Exception("Token: " . $this->sServiceToken);
         FlexiConfig::getLoginHandler()->doLoginByToken($this->sServiceToken);
         //if ($this->sServiceMethod!="login") throw new Exception("Logged in as: " . FlexiConfig::getLoginHandler()->getLoggedInUserId());
         FlexiLogger::debug(__METHOD__, "Logged in as: " . FlexiConfig::getLoginHandler()->getLoggedInUserId());
         $this->mRequestData = array();
         if (isset($oRequest->data)) {
             $this->mRequestData = $oRequest->data;
         }
         $mResult = FlexiController::getInstance()->runService($this->sServiceModule, $this->sServiceMethod, $this->mRequestData);
         unset($mResult["control"]);
         FlexiLogger::debug(__METHOD__, "Done service: " . $this->sServiceModule . "::" . $this->sServiceMethod);
         echo $this->returnResult($mResult);
     } catch (Exception $e) {
         echo $this->returnResult(array("status" => false, "return" => null, "msg" => $e->getMessage()));
     }
 }
コード例 #3
0
ファイル: FlexiBaseView.php プロジェクト: u007/FlexiPHP
 public function render($sView, $aVariables = null, $asPath = null)
 {
     if (!is_null($aVariables)) {
         $vars = FlexiArrayUtil::cloneArray($aVariables);
     } else {
         //var_dump($this->aVariables);
         $vars = FlexiArrayUtil::cloneArray($this->aVariables);
     }
     $vars["#viewpath"] = $asPath;
     $vars["#css"] = $this->aHeader["css"];
     $vars["#js"] = $this->aHeader["js"];
     $vars["#template"] = $this->sTemplate;
     $sViewFile = "";
     //final file
     $sViewFile = $this->getViewFile($sView, $asPath);
     if (empty($sViewFile)) {
         FlexiLogger::error(__METHOD__, "View: " . $sView . " is missing...");
         return null;
     }
     //echo "rendering view: " . $sViewFile;
     ob_start();
     //FlexiLogger::info(__METHOD__, "found view: " . $sViewFile);
     require $sViewFile;
     $sResult = ob_get_contents();
     @ob_end_clean();
     return $sResult;
 }
コード例 #4
0
ファイル: FlexiRedBeanEvent.php プロジェクト: u007/FlexiPHP
 public function onEvent($event, $oModel)
 {
     $sTable = $oModel->getMeta("type");
     FlexiLogger::debug(__METHOD__, $sTable . ", Event: " . $event);
     $sMethod = "on" . $event;
     FlexiLogger::debug(__METHOD__, $sTable . ", Method: " . $sMethod);
     if (isset(self::$aValidator[$sTable])) {
         if (is_array(self::$aValidator[$sTable])) {
             foreach (self::$aValidator[$sTable] as $oClass) {
                 if (method_exists($oClass, $sMethod)) {
                     FlexiLogger::debug(__METHOD__, "Calling: " . $sTable . ": " . $sMethod);
                     $oClass->{$sMethod}($oModel);
                 }
             }
             //is array
         } else {
             if (method_exists(self::$aValidator[$sTable], $sMethod)) {
                 FlexiLogger::info(__METHOD__, "Calling: " . $sTable . ": " . $sMethod);
                 self::$aValidator[$sTable]->{$sMethod}($oModel);
             }
         }
         //if is direct
     }
     //if exists table event
 }
コード例 #5
0
 public function getIDField($type)
 {
     FlexiLogger::debug(__METHOD__, "Getting id: " . $type);
     if (isset(FlexiModelUtil::$aTableId[$type])) {
         FlexiLogger::debug(__METHOD__, "Is set: " . FlexiModelUtil::$aTableId[$type]);
         return FlexiModelUtil::$aTableId[$type];
     }
     return parent::getIDField($type);
 }
コード例 #6
0
 /**
  * Called to return request object
  * @return request object
  */
 public function _run()
 {
     $sRaw = $this->getDecodedData();
     //FlexiLogger::error(__METHOD__, "Running: " . serialize($sRaw));
     FlexiLogger::debug(__METHOD__, "Running2: " . print_r($sRaw, true));
     $oRequest = json_decode($sRaw);
     //FlexiLogger::error(__METHOD__, "JSON: " . serialize($oRequest));
     return $oRequest;
 }
コード例 #7
0
 public function getIDField($type)
 {
     if (gettype($type) != "string") {
         throw new FlexiException("Type must be string: " . gettype($type), ERROR_UNKNOWNTYPE);
     }
     FlexiLogger::debug(__METHOD__, "Getting id: " . $type);
     if (isset(FlexiModelUtil::$aTableId[$type])) {
         //FlexiLogger::info(__METHOD__, "Is set: " . FlexiModelUtil::$aTableId[$type]);
         return FlexiModelUtil::$aTableId[$type];
     }
     return parent::getIDField($type);
 }
コード例 #8
0
ファイル: controller.php プロジェクト: u007/FlexiPHP
 public function methodTestremote()
 {
     FlexiLogger::debug(__METHOD__, "starting");
     $sURL = FlexiConfig::$sBaseURL . "remote.php";
     $oData = array("testme" => "xyz");
     $oClient = new FlexiRemoteJSONClient();
     $oClient->setContent($oData);
     $bResult = $oClient->callRemote($sURL, "xxx", "test");
     FlexiLogger::debug(__METHOD__, "Result status: " . serialize($bResult));
     var_dump($oClient->getResultReturned());
     return true;
 }
コード例 #9
0
ファイル: FlexiFacebook.php プロジェクト: u007/FlexiPHP
 public function getMe()
 {
     if (is_null($this->me)) {
         $this->startSession();
         try {
             $this->me = $this->facebook->api('/me');
             //var_dump($this->me);
         } catch (FacebookApiException $e) {
             FlexiLogger::error(__METHOD__, "failed");
         }
     }
     return $this->me;
 }
コード例 #10
0
ファイル: controller.php プロジェクト: u007/FlexiPHP
 public function serviceSyncTable($oData)
 {
     FlexiLogger::debug(__METHOD__, "Running");
     //var_dump($aData["type"]);
     //FlexiLogger::error(__METHOD__, print_r($oData, true));
     $aTable = $oData->tables;
     $sType = $oData->type;
     $aMessage = array();
     FlexiLogger::info(__METHOD__, "Sync type: " . $sType);
     $oUtil = FlexiModelUtil::getInstance();
     foreach ($aTable as $sTable => $aTableSetting) {
         $aRow = $aTableSetting->rows;
         $sIDField = $aTableSetting->idfield;
         //FlexiLogger::error(__METHOD__, $sTable);
         $oModel = $oUtil->getRedBeanModel($sTable);
         if ($sType == "fullsync") {
             FlexiLogger::info(__METHOD__, "Clearing table: " . $sTable);
             if ($oUtil->getRedBeanDB()->tableExists($sTable)) {
                 $oUtil->getRedBeanExecute("delete from " . $sTable);
             }
         }
         if (count($aRow) > 0) {
             $sFields = implode(",", array_keys((array) $aRow[0]));
         }
         $oUtil->setRedBeanTableIdField($sTable, $sIDField);
         FlexiLogger::debug(__METHOD__, $sTable . ", fields: " . $sFields);
         foreach ($aRow as $oRow) {
             $oRowData = (array) $oRow;
             $oModel = $oUtil->getRedBeanModel($sTable);
             //        $sPrimaryField = "id";
             //        if (isset($oRowData[$sPrimaryField])) {
             //          $oModel = $oUtil->getRedBeanModel($sTable, $oRowData[$sPrimaryField]);
             //        } else {
             //          $oModel = $oUtil->getRedBeanModel($sTable);
             //        }
             //FlexiLogger::info(__METHOD__, "Type: " . $oModel->getMeta("type"));
             $oModel->import($oRowData, $sFields);
             FlexiLogger::info(__METHOD__, "model: " . $sTable . ", values: " . print_r($oModel->export(), true));
             $oUtil->insertOrUpdateRedBean($oModel);
             unset($oModel);
         }
         //each records
         $aMessage[] = "Imported: " . $sTable . ", cnt: " . count($aRow);
         FlexiLogger::info(__METHOD__, "Imported: " . $sTable . ", cnt: " . count($aRow));
         //if (1==1) { break; }
     }
     //each table
     $this->unsetToken();
     FlexiLogger::info(__METHOD__, "Done");
     return array("msg" => implode("\r\n<br/>", $aMessage));
 }
コード例 #11
0
 public function informError($sMsg)
 {
     //echo, write to file, and mail?
     $aLine = explode("\n", $sMsg);
     $sResult = "";
     foreach ($aLine as $sLine) {
         $sResult .= "[" . get_class($this) . "]:" . $sLine . "<br/>\n";
     }
     echo $sResult;
     FlexiLogger::error(__METHOD__, $sResult);
     if (!empty($this->sInformEmail)) {
         $sHeader = "From: " . FlexiConfig::$sSupportEmail . "\n" . "Reply-to: " . FlexiConfig::$sSupportEmail;
         $oMail = FlexiMailer::getInstance();
         $oMail->mail(FlexiConfig::$sBaseURLDir . ":Error", $sResult, $this->sInformEmail, "text");
     }
 }
コード例 #12
0
ファイル: FlexiEvent.php プロジェクト: u007/FlexiPHP
 public static function triggerEvent($sName, &$args = null)
 {
     FlexiLogger::debug(__METHOD__, "Name: " . $sName);
     $aFunc = self::getEvent($sName);
     foreach ($aFunc as $sFunc) {
         FlexiLogger::debug(__METHOD__, "Function: " . $sFunc);
         $bIsClass = strpos($sFunc, "::") !== false ? true : false;
         if ($bIsClass) {
             list($sClass, $sMethod) = explode("::", $sFunc);
             FlexiLogger::debug(__METHOD__, "Class: " . $sClass . ", method: " . $sMethod);
             call_user_func(array($sClass, $sMethod), $args);
         } else {
             call_user_func($sFunc, $args);
         }
     }
     //end foreach
 }
コード例 #13
0
ファイル: FlexiBaseService.php プロジェクト: u007/FlexiPHP
 /**
  * get table rows
  * @param array $aCond ['field:condition'=>'value'], eg: 'id:=' => 1
  * @param String $sOrderby
  * @param String $sSelect, eg: select id, name
  */
 public function getFetchList($sTable, $aCond = array(), $sOrderby = null, $sSelect = null, $iLimit = null, $iOffset = 0)
 {
     $select = empty($sSelect) ? "select * " : $sSelect;
     $aWhere = FlexiService::getWhere($aCond);
     $sSQL = $select . " from " . FlexiService::cleanField($sTable);
     $aParams = array();
     if (!empty($aWhere["where"])) {
         $aParams = $aWhere["params"];
         $sSQL .= " where " . $aWhere["where"];
     }
     if (!empty($sOrderby)) {
         $sSQL .= " order by " . $sOrderby;
     }
     if ($iLimit > 0) {
         $sSQL .= " limit " . $iLimit . " offset " . $iOffset;
     }
     FlexiLogger::info(__METHOD__, "SQL: " . $sSQL . "|" . print_r($aParams, true));
     return FlexiModelUtil::getInstance()->getRedbeanFetchAll($sSQL, $aParams);
 }
コード例 #14
0
ファイル: FlexiRemoteClient.php プロジェクト: u007/FlexiPHP
 /**
  * Do call to remote url
  * @param String $asURL
  * @param String $asModule
  * @param String $asMethod
  * @return boolean: true/false
  */
 public function callRemote($asURL = "http://localhost", $asModule = "", $asMethod = "")
 {
     FlexiLogger::debug(__METHOD__, "Calling URL: " . $asURL);
     $bDebug = false;
     $sURL = $asURL;
     $sModule = empty($asModule) ? "default" : $asModule;
     $sMethod = empty($asMethod) ? "default" : $asMethod;
     //$sURL = "temp/bloomberg-stocks.html";
     $aHeader = $this->getHeaders();
     $opts = array('http' => array('method' => "POST", 'header' => implode("\r\n", $aHeader), 'content' => $this->getRequestContent($sModule, $sMethod)));
     FlexiLogger::debug(__METHOD__, "Content: " . $opts["http"]["content"]);
     $context = stream_context_create($opts);
     FlexiLogger::debug(__METHOD__, "Processing URL: " . $sURL);
     $sResult = file_get_contents($sURL, false, $context);
     if ($sResult === false || empty($sResult)) {
         throw new Exception("Remote returned empty or false");
     }
     try {
         $this->mResult = FlexiCryptUtil::b64Decrypt($sResult, $this->sRemoteKey);
     } catch (Exception $e) {
         throw new Exception($e->getMessage() . "<br/>\nOriginal Remote result: " . $sResult);
     }
     //echo "<hr/>";
     if ($bDebug) {
         echo "\r\n" . __METHOD__ . ": " . $sResult . "<Br/>\r\n";
     }
     //var_dump($this->mResult);
     if (empty($this->mResult)) {
         throw new Exception("Unknown result: " . $sResult);
     }
     FlexiLogger::debug(__METHOD__, "Result raw: " . $this->mResult);
     $aResult = $this->getResult();
     if (empty($aResult)) {
         throw new Exception("Remote returned malformed result: " . $sResult);
     }
     return $aResult->status;
 }
コード例 #15
0
 public function hasPermission($sTitle, $asContext = null)
 {
     FlexiLogger::info(__METHOD__, "Checking permission: " . $sTitle);
     if ($this->isSuperUser()) {
         return true;
     }
     global $modx;
     $sContext = empty($asContext) ? $modx->context->get("key") : $context;
     $bResult = $modx->hasPermission($sTitle);
     if (!$bResult) {
         $oUser = $modx->getAuthenticatedUser($sContext);
         if (is_null($oUser)) {
             return false;
         }
         //FlexiLogger::info(__METHOD__, "object: " . get_class($oUser));
         $aGroups = $oUser->getResourceGroups($sContext);
         //FlexiLogger::info(__METHOD__, $oUser->username . ", Doc Groups: " . print_r($aGroups,true));
         //if empty doc group, return no permission
         if (count($aGroups) < 1) {
             return false;
         }
         $oQuery = $modx->newQuery("modResourceGroup");
         $oQuery->where(array("id:in" => $aGroups));
         $aListGroups = $modx->getCollection("modResourceGroup", $oQuery);
         $aGroupName = array();
         foreach ($aListGroups as $oGroup) {
             $aGroupName[] = $oGroup->get("name");
         }
         FlexiLogger::info(__METHOD__, $oUser->username . ", Result Doc names: " . print_r($aGroupName, true));
         if ($aGroupName != null) {
             foreach ($aGroupName as $sGroup) {
                 //echo "Doc Group: " . $sGroup . " vs " . $sTitle . "\r\n<br/>";
                 FlexiLogger::info(__METHOD__, "Doc Group: " . $sGroup . " vs " . $sTitle);
                 if (strtolower(trim($sGroup)) == strtolower(trim($sTitle))) {
                     FlexiLogger::info(__METHOD__, "Found match: " . $sGroup);
                     $bResult = true;
                     break;
                 }
             }
         } else {
             //echo "doc group empty";
             FlexiLogger::info(__METHOD__, "Doc Group empty: " . serialize($aGroups));
         }
     }
     return $bResult;
 }
コード例 #16
0
ファイル: FlexiObjectManager.php プロジェクト: u007/FlexiPHP
 public function updateTable(FlexiObject $oObject)
 {
     $bDebug = false;
     $aList = FlexiModelUtil::getTableSchema($oObject->sTableName);
     $aFieldSQL = array();
     $aPrimary = array();
     $sLastField = "";
     $aLastPrimary = array();
     foreach ($oObject->aChild["field"] as $oFieldObject) {
         $oField = $oFieldObject->toArray();
         //finding field by old name and new name
         $bHasField = false;
         foreach ($aList as $oTableField) {
             $sFindName = empty($oField["oldname"]) ? $oField["sName"] : $oField["oldname"];
             if ($bDebug) {
                 echo "[" . $oTableField["Field"] . "]vs[" . $sFindName . "]";
             }
             if ($oTableField["Field"] == $sFindName) {
                 $bHasField = true;
                 break;
             }
         }
         //if old name not found, use new name
         if (!$bHasField && $oField["sName"] != $oField["oldname"]) {
             foreach ($aList as $oTableField) {
                 $sFindName = $oField["sName"];
                 if ($bDebug) {
                     echo "[" . $oTableField["Field"] . "]vs[" . $sFindName . "]";
                 }
                 if ($oTableField["Field"] == $sFindName) {
                     $bHasField = true;
                     break;
                 }
             }
         }
         if ($oField["iStatus"] == 1) {
             //update or add
             $sSQLDefault = FlexiModelUtil::getDefaultSQL($oField["default"], $oField["cannull"]);
             if ($oField["primary"]) {
                 $aPrimary[] = $oField["sName"];
             }
             if (strpos($oTableField["Key"], "PRI") !== false) {
                 $aLastPrimary[] = $oTableField["Field"];
             }
             //$this->doLog("Field: " . $oField["sName"] . ", " . $oFieldObject->options . ", enum: " . $oFieldObject->getEnum());
             $sFieldTypeSQL = FlexiModelUtil::getSQLName($oField["sName"]) . " " . strtoupper($oField["dbtype"]) . "" . (empty($oField["precision"]) ? "" : "(" . $oField["precision"] . ") ") . (!empty($oField["options"]) && $oField["dbtype"] == "enum" ? "(" . $oFieldObject->getEnum() . ")" : "") . " " . $sSQLDefault . " " . ($oField["autonumber"] ? "AUTO_INCREMENT" : "");
             if ($bHasField) {
                 $sFieldSQL = "CHANGE COLUMN " . FlexiModelUtil::getSQLName($sFindName) . " " . $sFieldTypeSQL;
             } else {
                 $sFieldSQL = "ADD COLUMN " . $sFieldTypeSQL;
             }
             $sFieldSQL .= empty($sLastField) ? " FIRST " : " AFTER " . FlexiModelUtil::getSQLName($sLastField);
             $aFieldSQL[] = $sFieldSQL;
             $sLastField = $oField["sName"];
         } else {
             //do delete
             if ($bHasField) {
                 $aFieldSQL[] = "DROP COLUMN " . FlexiModelUtil::getSQLName($sFindName);
             }
         }
     }
     //for
     $sSQL = "ALTER TABLE " . FlexiModelUtil::getSQLName($oObject->sTableName) . "\n";
     $sSQL .= implode(",\n", $aFieldSQL);
     if (!empty($aPrimary)) {
         $bIsSame = false;
         if (!empty($aLastPrimary)) {
             foreach ($aPrimary as $sPKey) {
                 $bFoundKey = false;
                 foreach ($aLastPrimary as $sLastKey) {
                     if ($sLastKey == $sPKey) {
                         $bFoundKey = true;
                         $bIsSame = true;
                         break;
                     }
                 }
                 //once found a single not same, time to redo primary key
                 if (!$bFoundKey) {
                     $bIsSame = false;
                     break;
                 }
             }
         }
         if (!$bIsSame) {
             $sPrimarySQL = FlexiModelUtil::getSQLName($aPrimary);
             if (!empty($aLastPrimary)) {
                 $sSQL .= "\n,DROP PRIMARY KEY";
             }
             $sSQL .= "\n,ADD PRIMARY KEY (" . $sPrimarySQL . ")";
         }
     } else {
         //new no primary key
         if (!empty($aLastPrimary)) {
             //last has primary, time to drop it
             $sSQL .= "\n,DROP PRIMARY KEY";
         }
     }
     //$sSQL .= ";";
     FlexiLogger::info(__METHOD__, "SQL: " . $sSQL);
     $this->logSQL($sSQL);
     return FlexiModelUtil::getInstance()->getXPDOExecute($sSQL);
 }
コード例 #17
0
 public function verifyUser($iId, $sCode)
 {
     $oModel = FlexiModelUtil::getDBQuery("ModxWebUsers", "flexiphp/base/FlexiAdminUser")->where("id=?", array($iId))->fetchOne();
     if ($oModel === false) {
         return false;
     }
     //echo "Comparing: " . $sCode . " vs " . $oModel->Extend->verifycode;
     try {
         //echo "same :)";
         if ($oModel->Extend->verifycode == $sCode) {
             $oModel->Extend->verified = 1;
             $oModel->Extend->replace();
             return true;
         }
     } catch (Exception $e) {
         //echo "error: " . $e->getMessage();
         FlexiLogger::error(__METHOD__, "Unable to save User verification");
         return false;
     }
 }
コード例 #18
0
ファイル: FlexiBaseController.php プロジェクト: u007/FlexiPHP
 public function renderLayout()
 {
     //echo "class: " . get_class($this) . ", layout: " . $this->sLayoutTemplate;
     FlexiLogger::debug(__METHOD__, $this->sLayoutTemplate);
     foreach ($this->aViewVars as $sKey => $mValue) {
         $this->oView->addVar($sKey, $mValue);
     }
     //putting up messages
     $this->oView->addVar("#message", FlexiConfig::$aMessage);
     //echo "layout: " . $this->sLayoutTemplate;
     if (!$this->beforeRender()) {
         return;
     }
     //echo "layout: " . $this->sLayoutTemplate;
     if (!empty($this->sLayoutTemplate)) {
         //echo "has layout";
         $this->oView->addVar("header", $this->oView->render("header", null, $this->sModulePath));
         $this->oView->addVar("notice", $this->oView->render("notice", null, $this->sModulePath));
         //manually called in
         //$this->oView->addVar("body", $this->renderView());
         $this->oView->addVar("footer", $this->oView->render("footer", null, $this->sModulePath));
         //echo "ppp";
         if (FlexiConfig::$sFramework == "modx2") {
             //FlexiController::appendOutput("is render layout: " . $this->sLayoutTemplate);
             FlexiController::appendOutput($this->oView->render($this->sLayoutTemplate, null, $this->sModulePath));
         } else {
             echo $this->oView->render($this->sLayoutTemplate, null, $this->sModulePath);
         }
     } else {
         //echo __METHOD__.": no layout, viewname: " . $this->sRenderViewName;
         if (FlexiConfig::$sFramework == "modx2") {
             //FlexiController::appendOutput("is render non-layout");
             FlexiController::appendOutput($this->oView->getVar($this->sRenderViewName));
         } else {
             echo $this->oView->getVar($this->sRenderViewName);
         }
     }
     $this->afterRender();
     $this->unsetSession("#messages");
 }
コード例 #19
0
ファイル: controller.php プロジェクト: u007/FlexiPHP
 public function methodDenied()
 {
     FlexiLogger::debug(__METHOD__, "ok");
     return true;
 }
コード例 #20
0
 /**
  * @param string message
  * @param int	code:
  * 	0: uncategoriesed code, 1: invalid class type
  */
 public function __construct($message = "", $code = 0)
 {
     FlexiLogger::error(__METHOD__, $code . ":" . $message);
     parent::__construct($message, $code);
 }
コード例 #21
0
ファイル: FlexiModelUtil.php プロジェクト: u007/FlexiPHP
 /**
  * Get Doctrine query object
  * @param string name
  * @param string path (optional)
  * @return Doctrine_Record
  */
 public static function getDBQuery($asName, $asPath = null)
 {
     self::loadModel($asName, $asPath);
     FlexiLogger::debug(__METHOD__, "Loaded model: " . $asName);
     return Doctrine_Query::create()->from($asName);
 }
コード例 #22
0
ファイル: controller.php プロジェクト: u007/FlexiPHP
 function methodModXProcessform()
 {
     $iId = $this->getRequest("rid");
     $aForm = $this->loadForm();
     if (!empty($iId)) {
         $oModel = $this->getDBQuery("ModxWebUsers")->where("id=?", array($iId))->fetchOne();
         if ($oModel === false) {
             FlexiLogger::error(__METHOD__, "Record not found.");
             $this->addMessage("Record not found", "error");
             return $this->renderForm($aForm);
         }
         $oModel = $this->getModelFromForm($oModel, $aForm["form"]);
     } else {
         $oModel = $this->getModelFromForm("ModxWebUsers", $aForm["form"]);
     }
     $oModel->Attributes->fullname = $aForm["form"]["txtFullName"]["#value"];
     //$oModel->dob 					= "1980-01-01";
     if (!$this->validateFormByModel($aForm["form"], $oModel) || !$this->validateForm($aForm["form"])) {
         FlexiLogger::error(__METHOD__, "Validation failed: " . $oModel->getErrorStackAsString());
         $this->addMessage("Validation failed", "error");
         return $this->renderForm($aForm);
     }
     FlexiLogger::debug(__METHOD__, "ok");
     try {
         $oModel->replace();
         $oGroupModel = $this->getModelInstance("ModxWebGroups");
         $oGroupModel->webuser = $oModel->id;
         $oGroupModel->webgroup = 2;
         //hardcoded to registered user
         $oGroupModel->replace();
         //$this->oView->addVar("message", "saved.");
         $this->addMessage("Saved", "success");
         return $this->runControl("default");
     } catch (Exception $e) {
         FlexiLogger::error(__METHOD__, "Save failed:" . $e->getMessage());
         $this->addMessage("Error saving: " . $e->getMessage(), "error");
         return $this->runControl("form");
     }
 }
コード例 #23
0
 public function hasPermission($sTitle)
 {
     if ($this->isSuperUser()) {
         return true;
     }
     global $modx;
     $bResult = $modx->hasPermission($sTitle);
     if (!$bResult) {
         $aGroups = $modx->getUserDocGroups(true);
         if ($aGroups != null) {
             foreach ($aGroups as $sGroup) {
                 //echo "Doc Group: " . $sGroup . " vs " . $sTitle . "\r\n<br/>";
                 FlexiLogger::Debug(__METHOD__, "Doc Group: " . $sGroup . " vs " . $sTitle);
                 if (strtolower(trim($sGroup)) == strtolower(trim($sTitle))) {
                     $bResult = true;
                     break;
                 }
             }
         } else {
             //echo "doc group empty";
             FlexiLogger::debug(__METHOD__, "Doc Group empty");
         }
     }
     return $bResult;
 }
コード例 #24
0
 public function verifyUser($iId, $sCode)
 {
     global $modx;
     $oModel = $modx->getObject("modUser", $iId);
     if (is_null($oModel)) {
         return false;
     }
     $oUserExtend = FlexiModelUtil::Instance()->getRedbeanFetchOne("select * from modx_userextend where userid=:userid", array(":userid" => $iId));
     if (!empty($oUserExtend->id)) {
         $sVerifyCode = $oUserExtend->verifycode;
         if ($sCode == $sVerifyCode) {
             return true;
         }
     }
     FlexiLogger::error(__METHOD__, "Unable to save User verification");
     return false;
 }
コード例 #25
0
 public function onUpdate($oModel)
 {
     FlexiLogger::error(__METHOD__, "Model: " . $oModel->id);
     $aForm = self::getFormFields();
     FlexiModelUtil::validateForm($aForm, $oModel);
 }
コード例 #26
0
ファイル: rb.php プロジェクト: u007/FlexiPHP
 /**
  * (non-PHPdoc)
  * @see RedBean/RedBean_Driver#Execute()
  */
 public function Execute($sql, $aValues = array())
 {
     //FlexiLogger::error(__METHOD__, "SQL: " . $sql);
     $this->exc = 0;
     if ($this->debug) {
         echo "<HR>" . $sql . print_r($aValues, 1);
     }
     try {
         if (strpos("pgsql", $this->dsn) === 0) {
             $s = $this->pdo->prepare($sql, array(PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT => true));
         } else {
             $s = $this->pdo->prepare($sql);
         }
         $s->execute($aValues);
         $this->affected_rows = $s->rowCount();
         return $this->affected_rows;
     } catch (PDOException $e) {
         //Unfortunately the code field is supposed to be int by default (php)
         //So we need a property to convey the SQL State code.
         FlexiLogger::error(__METHOD__, "SQL: " . $sql . ", error: " . $e->getMessage());
         if (version_compare(PHP_VERSION, '5.3.0', '<')) {
             $x = new RedBean_Exception_SQL($e->getMessage(), 0);
         } else {
             $x = new RedBean_Exception_SQL($e->getMessage(), 0, $e);
         }
         $x->setSQLState($e->getCode());
         throw $x;
     }
     //
 }
コード例 #27
0
 public function checkPermission($sTitle)
 {
     if (!$this->hasAccessToContent($sTitle)) {
         FlexiLogger::error(__METHOD__, "Permission denied: " . get_class($this) . ":" . $sTitle);
         FlexiController::getInstance()->redirectURL(FlexiConfig::$sBaseURL . "?" . FlexiConfig::getRequestModuleVarName() . "=FlexiLogin&" . FlexiConfig::getRequestMethodVarName() . "=denied");
     }
     FlexiPlatformHandler::getPlatformHandler()->forceDie();
 }
コード例 #28
0
ファイル: controller.php プロジェクト: u007/FlexiPHP
 public function getNewController($sControl, $oView, $sMethodName, $sModulePath)
 {
     $sClassName = $sControl . "Controller";
     $sBaseDir = $this->env["basedir"];
     $sModulePath = "";
     //echo "trying: " . $sControl;
     FlexiLogger::debug(__METHOD__, "Env.BaseDir: " . $sBaseDir . ", cwd: " . getcwd() . ", modpath: " . FlexiConfig::$sModulePath);
     FlexiLogger::debug(__METHOD__, "Checking sModulePath: " . FlexiConfig::$sModulePath . "/" . $sControl);
     FlexiLogger::debug(__METHOD__, "Checking sModulePath: " . $sBaseDir . "/modules/" . $sControl);
     FlexiLogger::debug(__METHOD__, "Checking sModulePath: " . $sBaseDir . "/base/" . $sControl);
     if (is_file(FlexiConfig::$sModulePath . "/" . $sControl . "/controller.php")) {
         $sModulePath = FlexiConfig::$sModulePath . "/" . $sControl;
         require_once $sModulePath . "/controller.php";
     } else {
         if (is_file(FlexiConfig::$sModulePath . "/" . strtolower($sControl) . "/controller.php")) {
             $sModulePath = FlexiConfig::$sModulePath . "/" . strtolower($sControl);
             require_once $sModulePath . "/controller.php";
         } else {
             if (is_file($sBaseDir . "/modules/" . $sControl . "/controller.php")) {
                 $sModulePath = $sBaseDir . "/modules/" . $sControl;
                 FlexiLogger::debug(__METHOD__, "Checking sModulePath: " . $sModulePath);
                 require_once $sModulePath . "/controller.php";
             } else {
                 if (is_file($sBaseDir . "/modules/" . strtolower($sControl) . "/controller.php")) {
                     $sModulePath = $sBaseDir . "/modules/" . strtolower($sControl);
                     FlexiLogger::debug(__METHOD__, "Checking sModulePath: " . $sModulePath);
                     require_once $sModulePath . "/controller.php";
                 } else {
                     if (is_file($sBaseDir . "/base/" . $sControl . "/controller.php")) {
                         $sModulePath = $sBaseDir . "/base/" . $sControl;
                         FlexiLogger::debug(__METHOD__, "Checking sModulePath: " . $sModulePath);
                         require_once $sModulePath . "/controller.php";
                     } else {
                         if (is_file($sBaseDir . "/base/" . strtolower($sControl) . "/controller.php")) {
                             $sModulePath = $sBaseDir . "/base/" . strtolower($sControl);
                             FlexiLogger::debug(__METHOD__, "Checking sModulePath: " . $sModulePath);
                             require_once $sModulePath . "/controller.php";
                         }
                     }
                 }
             }
         }
     }
     if (!class_exists($sClassName)) {
         //echo "not found: " . $sClassName;
         FlexiLogger::error(__METHOD__, "module: " . $sControl . " is missing.");
         throw new Exception("No such class: " . $sClassName);
         return;
     }
     FlexiLogger::debug(__METHOD__, "found module: " . $sControl . " at " . $sModulePath);
     //echo "found module: " . $sControl . " at " . $sModulePath;
     //echo "setting controllerpath: " . $sControl . "=>" . $sModulePath;
     $this->aControllerPath[strtolower($sControl)] = $sModulePath;
     //echo "initialising class: " . $sClassName;
     $oClass = new $sClassName($oView, $sMethodName, $sModulePath);
     //echo "xxxx";
     if (!is_subclass_of($oClass, "FlexiBaseController")) {
         //echo "no class of: " . $sClassName;
         throw new FlexiException("Class: " . $sClassName . " is not of type FlexiBaseController", 500);
     }
     //echo "ok: " .$sClassName;
     return $oClass;
 }
コード例 #29
0
 public function onLogout()
 {
     FlexiLogger::debug(__METHOD__, "Logging-out");
     unset($_SESSION["sess_adminname"]);
     unset($_SESSION["sess_username"]);
     unset($_SESSION["sess_userid"]);
     return true;
 }
コード例 #30
0
ファイル: FlexiFileUtil.php プロジェクト: u007/FlexiPHP
 public static function doUnlockFile($sPath)
 {
     if (!isset(self::$aLocks[$sPath])) {
         throw new FlexiException("No such lock for path: " . $sPath, ERROR_IO_LOCK);
     }
     flock(self::$aLocks[$sPath], LOCK_UN);
     fclose(self::$aLocks[$sPath]);
     unset(self::$aLocks[$sPath]);
     FlexiLogger::debug(__METHOD__, "Unlocked: " . $sPath);
     return true;
 }