function writeLogs() { foreach ($this->logs as $log) { $Log = new Log(Factory::getDBH(), $log, false); $Log->save(); } }
/** * @return mixed */ public function getComponent() { if (!isset($this->Component)) { $dbh = Factory::getDBH(); $_Component = Factory::getRouter()->getRoute('Component'); $_Controller = Factory::getRouter()->getRoute('Controller'); $Action = Factory::getRouter()->getRoute('Action'); $ID = Factory::getRouter()->getRoute('ID'); try { $stmt = $dbh->prepare('SELECT * FROM Component WHERE ApplicationID = :AppID AND blStatus = 1 AND Component = :Component;'); try { $stmt->bindValue(':AppID', $this->ApplicationID, PDO::PARAM_STR); $stmt->bindValue(':Component', (string) ucfirst($_Component), PDO::PARAM_STR); $stmt->execute(); $Component = new Object($stmt->fetch(PDO::FETCH_OBJ)); } catch (PDOException $e) { $dbh->catchException($e, $stmt->queryString); throw new Exception('EpsilonCMS cannot Load Component DB'); } if ($Component->get('ComponentID')) { $AccessLevels = Factory::getUser()->getAuthorizedLevels(); /** Verify if the current user has access to the component */ if (!in_array($Component->get('AccessLevelID'), $AccessLevels)) { if (Factory::getUser()->isGuest()) { if (Factory::getApplication()->isCLI()) { Factory::getLogger()->alert(Factory::getLanguage()->_('NOT_AUTHORIZED')); } else { Factory::getApplication()->redirectLogin(); } } else { Factory::getApplication()->redirectHome(); } } /** Creates the Class|Controller Namespace */ $Namespace = '\\Components\\' . $_Component . '\\Controllers\\'; /** * If the route contains a controller use that controller * else * use the component name as default controller */ if ($_Controller) { $Controller = $_Controller; } else { $Controller = $_Component; } $Class = $Namespace . $Controller; if (!class_exists($Class)) { throw new \Exception("Controller does not exist {$Controller}->{$Action}({$ID})"); } $Component = new $Class($dbh, $Component); /** Verify if the method (Action) exist */ if (is_callable([$Component, $Action])) { $Component->{$Action}($ID); } else { throw new \Exception("Controller method does not exist {$Controller}->{$Action}({$ID})"); } $this->Component = $Component; } else { throw new \Exception('Component {' . $_Component . '} does not exist in Database'); } } catch (\Exception $e) { Factory::getLogger()->alert('ComponentManagerException: {Message} {File} {Line}', ['Message' => $e->getMessage(), 'File' => $e->getFile(), 'Line' => $e->getLine()]); } } return $this->Component; }
/** * TODO: rewrite method * * @return mixed */ public function getCurrentMenuID() { if (!isset($this->CurrentMenuID)) { $dbh = Factory::getDBH(); $App = Factory::getApplication(); $ComponentID = $App->get('Component')->get('ID'); $ApplicationID = $App->getApplicationID(); $URL = $this->getRouteString(); $ssql = 'SELECT m.MenuID AS MenuID FROM Menu m INNER JOIN MenuBundle mb ON mb.MenuBundleID = m.MenuBundleID WHERE (mb.ApplicationID = :AppID AND m.URL LIKE :URL) OR m.ComponentID = :ComponentID'; $stmt = $dbh->prepare($ssql); try { $this->bindMenuValues($stmt, $ApplicationID, $ComponentID, $URL, $MenuID); $stmt->execute(); $stmt->fetch(); $sections = count(array_filter(explode('/', $URL))); if ($sections == 5 && !$stmt->rowCount()) { $URL = explode('/', $URL); array_pop($URL); $sections--; $URL = implode('/', $URL) . '/'; $stmt = $dbh->prepare($ssql); $this->bindMenuValues($stmt, $ApplicationID, $ComponentID, $URL, $MenuID); $stmt->execute(); } if ($sections == 4 && !$stmt->rowCount()) { $URL = explode('/', $URL); array_pop($URL); $URL = implode('/', $URL) . '/'; $stmt = $dbh->prepare($ssql); $this->bindMenuValues($stmt, $ApplicationID, $ComponentID, $URL, $MenuID); $stmt->execute(); } if ($stmt->rowCount() == 1) { $stmt->fetch(); $this->CurrentMenuID = $MenuID; } } catch (PDOException $e) { $dbh->catchException($e, $stmt->queryString); } } return $this->CurrentMenuID; }
/** * @return int MainMenuID */ protected function getMainMenuID() { if (!$this->MainMenuID) { $dbh = Factory::getDBH(); $stmt = $dbh->prepare('SELECT m.MenuID AS MenuID FROM Menu m INNER JOIN MenuBundle mb ON mb.MenuBundleID = m.MenuBundleID WHERE mb.ApplicationID = :AppID AND m.Root = 1 AND blStatus = 1'); try { $stmt->bindValue(':AppID', Factory::getApplication()->getApplicationID(), PDO::PARAM_STR); $stmt->bindColumn('MenuID', $MenuID, PDO::PARAM_INT); $stmt->execute(); $stmt->fetch(); $this->MainMenuID = $MenuID; } catch (PDOException $e) { $dbh->catchException($e, $stmt->queryString); } } return $this->MainMenuID; }
/** * @return bool */ public function writeVariables() { if ($this->blWritten || Factory::getApplication()->isCLI()) { return false; } try { if (is_array($this->newSessionVariables)) { foreach ($this->newSessionVariables as $k => $v) { try { if (is_null(unserialize($v['Value']))) { $stmt = $this->objPDO->prepare('DELETE FROM SessionVariable WHERE AsciiSessionID = :Ascii_ID AND VariableName = :VariableName'); } else { if ($this->checkVar($k, $v['PHP_SessionID'])) { $stmt = $this->objPDO->prepare('INSERT INTO SessionVariable (AsciiSessionID, VariableName, VariableValue, Lifespan) VALUES (:Ascii_ID,:VariableName,:VariableValue,IF(:Lifespan>0,DATE_ADD(:now, INTERVAL :Lifespan SECOND),NULL))'); } else { $stmt = $this->objPDO->prepare('UPDATE SessionVariable SET VariableValue = :VariableValue, Lifespan = IF(:Lifespan>0,DATE_ADD(:now,INTERVAL :Lifespan SECOND),NULL) WHERE VariableName = :VariableName AND AsciiSessionID = :Ascii_ID'); } $stmt->bindValue(':VariableValue', $v['Value'], PDO::PARAM_LOB); $stmt->bindValue(':now', $this->getDateNOW(), PDO::PARAM_STR); $stmt->bindValue(':Lifespan', $v['Lifespan'], PDO::PARAM_INT); } $stmt->bindValue(':VariableName', $k, PDO::PARAM_STR); $stmt->bindValue(':Ascii_ID', $v['PHP_SessionID']); $stmt->execute(); $v['Written'] = true; } catch (PDOException $e) { } } $this->blWritten = true; return true; } } catch (PDOException $e) { Factory::getDBH()->catchException($e); } return false; }
/** * @return array */ public function getAccessLevels() { if (!$this->arAccessLevels) { $dbh = Factory::getDBH(); $stmt = $dbh->prepare('SELECT AccessLevelID, Rules FROM AccessLevel'); try { $stmt->execute(); foreach ($stmt->fetchAll(PDO::FETCH_OBJ) as $accl) { $this->arAccessLevels[$accl->AccessLevelID] = (array) json_decode($accl->Rules); } } catch (PDOException $e) { $dbh->catchException($e, $stmt->queryString); } } return $this->arAccessLevels; }
/** * @param $Element * @return bool */ public static function assignMessages($Element) { if (!isset(self::$arSystemMessagesElement[$Element])) { $dbh = Factory::getDBH(); $stmt = $dbh->prepare("SELECT SystemMessageID,Type,Message FROM SystemMessage WHERE (Element = :Element OR Element = '_system' OR Element = '_DBH') AND (UserID = :UserID OR SessionID = :SessionID) AND Viewed = 0"); try { $stmt->bindValue(':Element', $Element, PDO::PARAM_STR); $stmt->bindValue(':UserID', Factory::getUser()->get('ID'), PDO::PARAM_INT); $stmt->bindValue(':SessionID', Factory::getSession()->getPHP_SessionID()); $stmt->execute(); foreach ($stmt->fetchAll(PDO::FETCH_OBJ) as $Message) { array_push(self::$arSystemMessages, new SystemMessage($dbh, $Message)); } self::$arSystemMessagesElement[$Element] = true; return true; } catch (PDOException $e) { Factory::getDBH()->catchException($e, $stmt->queryString); } } return false; }
/** * @return mixed */ public static function getInstance() { if (!isset(self::$Instance)) { $dbh = Factory::getDBH(); if (Input::getVar('TemplateID', 'REQUEST')) { $TemplateID = Input::getVar('TemplateID', 'REQUEST'); } elseif (Factory::getCookie()->get('TemplateID')) { $TemplateID = Factory::getCookie()->get('TemplateID'); } else { $TemplateID = null; } if ($TemplateID) { $stmt = $dbh->prepare('SELECT * FROM Template WHERE TemplateID = :TemplateID AND ApplicationID = :AppID'); try { $stmt->bindValue(':AppID', Factory::getApplication()->getApplicationID(), PDO::PARAM_STR); $stmt->bindValue(':TemplateID', $TemplateID, PDO::PARAM_INT); $stmt->execute(); $rst = $stmt->fetch(PDO::FETCH_OBJ); if (is_object($rst)) { $Class = $rst->Template; self::$Instance = new $Class($dbh, $rst); } else { unset($rst); } } catch (PDOException $e) { $dbh->catchException($e, $stmt->queryString); } } if (!self::$Instance instanceof Template) { $stmt = $dbh->prepare('SELECT * FROM Template WHERE ApplicationID = :AppID AND Root = 1'); $stmt->bindValue(':AppID', Factory::getApplication()->getApplicationID(), PDO::PARAM_STR); try { $stmt->execute(); $rst = $stmt->fetch(PDO::FETCH_OBJ); if (is_object($rst)) { $Class = "Templates\\{$rst->Template}\\{$rst->Template}"; self::$Instance = new $Class($dbh, $rst); } } catch (PDOException $e) { $dbh->catchException($e, $stmt->queryString); } if (!self::$Instance) { Factory::getLogger()->emergency('No Template found in Database exiting...'); } } } return self::$Instance; }
/** * @return Language */ public static function getInstance() { if (!isset(self::$Instance)) { $dbh = Factory::getDBH(); $ApplicationID = Factory::getApplication()->getApplicationID(); $Session = Factory::getSession(); $LanguageID = null; if (Input::getVar('LanguageID', 'REQUEST')) { $LanguageID = Input::getVar('LanguageID', 'REQUEST'); } elseif ($Session->get('LanguageID')) { $LanguageID = $Session->get('LanguageID'); } if ($LanguageID) { $stmt = $dbh->prepare('SELECT * FROM Language WHERE ApplicationID = :AppID AND LanguageID = :LangID'); try { $stmt->bindValue(':AppID', $ApplicationID, PDO::PARAM_STR); $stmt->bindValue(':LangID', $LanguageID, PDO::PARAM_INT); $stmt->execute(); $rst = $stmt->fetch(PDO::FETCH_OBJ); if (is_object($rst)) { self::$Instance = new Language($dbh, $rst); } else { unset($rst); } } catch (PDOException $e) { $dbh->catchException($e, $stmt->queryString); } } if (!self::$Instance instanceof Language) { $stmt = $dbh->prepare('SELECT * FROM Language WHERE ApplicationID = :AppID AND Root = 1'); try { $stmt->bindValue(':AppID', $ApplicationID, PDO::PARAM_STR); $stmt->execute(); $rst = $stmt->fetch(PDO::FETCH_OBJ); if (is_object($rst)) { self::$Instance = new Language($dbh, $rst); } else { Factory::getLogger()->emergency('No Language found in Database exiting...'); } } catch (PDOException $e) { $dbh->catchException($e, $stmt->queryString); } } if (self::$Instance instanceof Language && !$Session->get('LanguageID') || self::$Instance->get('ID') != $Session->get('LanguageID')) { $Session->set('LanguageID', self::$Instance->get('ID')); Factory::getSession()->set('Language', null); } else { $Language = Factory::getSession()->get('Language'); if (is_array($Language)) { if (isset($Language['arImportedFiles'])) { self::$Instance->set('arImportedFiles', $Language['arImportedFiles']); } if (isset($Language['arStrings'])) { self::$Instance->set('arStrings', $Language['arStrings']); } } } } return self::$Instance; }
/** * @return Object */ public function getMainGroup() { $dbh = $this->objPDO; $stmt = $dbh->prepare('SELECT ug.UserGroupID,ug.Title FROM UserGroup ug INNER JOIN UserGroupMap ugm ON ugm.UserGroupID = ug.UserGroupID WHERE ugm.UserID = :UserID AND ugm.Main = 1'); try { $stmt->bindValue('UserID', $this->ID, PDO::PARAM_INT); $stmt->execute(); return new Object($stmt->fetch()); } catch (PDOException $e) { Factory::getDBH()->catchException($e, $stmt->queryString); return new Object(); } }