Exemplo n.º 1
0
 /**
  * Rendering backend
  *
  * @param \phpOMS\Message\Http\Request  $request  Request
  * @param \phpOMS\Message\Http\Response $response Response
  *
  * @since  1.0.0
  * @author Dennis Eichhorn <*****@*****.**>
  */
 public function run($request, $response)
 {
     $pageView = new \Web\Views\Page\GenericView($this->app, $request, $response);
     if ($request->getMethod() !== \phpOMS\Message\RequestMethod::GET) {
         $response->setHeader('HTTP', 'HTTP/1.0 406 Not acceptable');
         $response->setHeader('Status', 'Status:406 Not acceptable');
         $response->setStatusCode(406);
         $pageView->setTemplate('/Web/Backend/Error/406');
         $response->set('Content', $pageView);
         return;
     }
     if ($this->app->dbPool->get()->getStatus() !== \phpOMS\DataStorage\Database\DatabaseStatus::OK) {
         $response->setHeader('HTTP', 'HTTP/1.0 503 Service Temporarily Unavailable');
         $response->setHeader('Status', 'Status: 503 Service Temporarily Unavailable');
         $response->setHeader('Retry-After', 'Retry-After: 300');
         $response->setStatusCode(503);
         $pageView->setTemplate('/Web/Backend/Error/503');
         $response->set('Content', $pageView);
         return;
     }
     $options = $this->app->appSettings->get([1000000009, 1000000029]);
     $account = $this->app->accountManager->get($request->getAccount());
     $l11n = new \phpOMS\Localization\Localization();
     $l11n->setLanguage(!in_array($request->getLanguage(), $this->config['language']) ? $options[1000000029] : $request->getLanguage());
     $account->setL11n($l11n);
     $response->setL11n($l11n);
     include realpath(__DIR__ . '/lang/' . $response->getL11n()->getLanguage() . '.lang.php');
     $this->app->l11nManager->loadLanguage($response->getL11n()->getLanguage(), 0, $THEMELANG);
     include realpath(__DIR__ . '/../../phpOMS/Localization/lang/' . $response->getL11n()->getLanguage() . '.lang.php');
     $this->app->l11nManager->loadLanguage($response->getL11n()->getLanguage(), 0, $CORELANG);
     /* Carefull we are setting an array here that's why changes in the future will result in different values */
     $response->getL11n()->setLang($this->app->l11nManager->getLanguage($l11n->getLanguage()));
     $head = $response->getHead();
     $baseUri = $request->getUri()->getBase();
     if ($account->getId() < 1) {
         $head->addAsset(\phpOMS\Asset\AssetType::CSS, $baseUri . 'External/fontawesome/css/font-awesome.min.css');
         $head->addAsset(\phpOMS\Asset\AssetType::JS, $baseUri . 'jsOMS/oms.min.js');
         $head->addAsset(\phpOMS\Asset\AssetType::JS, $baseUri . 'Web/Backend/js/backend.js');
         $head->setScript('core', 'var Url = "' . $baseUri . '", assetManager = new jsOMS.AssetManager();');
         $pageView->setTemplate('/Web/Backend/login');
         $response->set('Content', $pageView);
         return;
     }
     $modules = $this->app->moduleManager->getRoutedModules($request);
     $this->app->moduleManager->initModule($modules);
     $this->app->moduleManager->loadLanguage($response->getLanguage(), 'backend');
     $head->addAsset(\phpOMS\Asset\AssetType::CSS, $baseUri . 'Web/Backend/css/backend.css');
     $head->addAsset(\phpOMS\Asset\AssetType::CSS, $baseUri . 'External/fontawesome/css/font-awesome.min.css');
     $head->addAsset(\phpOMS\Asset\AssetType::JS, $baseUri . 'jsOMS/oms.min.js');
     $head->addAsset(\phpOMS\Asset\AssetType::JS, $baseUri . 'External/d3/d3.min.js');
     $head->addAsset(\phpOMS\Asset\AssetType::JS, $baseUri . 'Web/Backend/js/backend.js');
     $head->setStyle('core', file_get_contents(__DIR__ . '/Theme/Backend/css/backend-small.css'));
     $head->setScript('core', 'var Url = "' . $baseUri . '", assetManager = new jsOMS.AssetManager();');
     $pageView->setData('Name', $options[1000000009]);
     $pageView->setData('Title', 'Orange Management');
     $pageView->setData('Destination', $request->getRequestDestination());
     $this->disptacher($this->router->route($this->request->getRoutify()), $request, $response, null);
     $pageView->setTemplate('/Web/Backend/index');
     $response->set('Content', $pageView);
 }
Exemplo n.º 2
0
 /**
  * Rendering backend
  *
  * @param \phpOMS\Message\Http\Request  $request  Request
  * @param \phpOMS\Message\Http\Response $response Response
  *
  * @since  1.0.0
  * @author Dennis Eichhorn <*****@*****.**>
  */
 public function run($request, $response)
 {
     $response->setHeader('Content-Type', 'text/plain; charset=utf-8');
     $pageView = new \Web\Views\Page\GenericView($this->app, $request, $response);
     if ($this->app->dbPool->get()->getStatus() !== \phpOMS\DataStorage\Database\DatabaseStatus::OK) {
         $response->setHeader('HTTP', 'HTTP/1.0 503 Service Temporarily Unavailable');
         $response->setHeader('Status', 'Status: 503 Service Temporarily Unavailable');
         $response->setHeader('Retry-After', 'Retry-After: 300');
         $response->setStatusCode(503);
         $pageView->setTemplate('/Web/Backend/Error/503');
         $response->set('Content', $pageView);
         return;
     }
     $options = $this->app->appSettings->get([1000000009, 1000000029]);
     $account = $this->app->accountManager->get($request->getAccount());
     $l11n = new \phpOMS\Localization\Localization();
     $l11n->setLanguage(!in_array($request->getLanguage(), $this->config['language']) ? $options[1000000029] : $request->getLanguage());
     $account->setL11n($l11n);
     $response->setL11n($l11n);
     if (($uris = $request->getUri()->getQuery('r')) !== null) {
         $request_r = clone $request;
         $uris = json_decode($uris, true);
         foreach ($uris as $key => $uri) {
             $request_r->init($uri);
             $modules = $this->app->moduleManager->getRoutedModules($request_r);
             $this->app->moduleManager->initModule($modules);
             $this->app->moduleManager->loadLanguage($response->getLanguage(), 'backend');
             $this->disptacher($this->router->route($this->request_r->getRoutify()), $request_r, $response, null);
         }
     } else {
         if ($request->getPath(2) === 'login' && $account->getId() < 1) {
             $login = $account->login($request->getData('user'), $request->getData('pass'));
             if ($login === \phpOMS\Auth\LoginReturnType::OK) {
                 $response->get('Content')->add($request->__toString(), (new \Model\Message\Reload())->toArray());
                 $response->set('Content', $response->get('Content')->__toString());
             } else {
                 // TODO: create login failure msg
             }
             return;
         } elseif ($request->getPath(2) === 'logout') {
             $this->app->sessionManager->remove('UID');
             $this->app->sessionManager->save();
             $response->get('Content')->add($request->__toString(), 1);
             $response->set('Content', $response->get('Content')->__toString());
             return;
         }
         $modules = $this->app->moduleManager->getRoutedModules($request);
         $this->app->moduleManager->initModule($modules);
         $this->app->moduleManager->loadLanguage($response->getLanguage(), 'api');
         $this->disptacher($this->router->route($this->request->getRoutify()), $request, $response, null);
     }
 }
 /**
  * Get modules that run on this page
  *
  * @param \phpOMS\Message\Http\Request $request Request
  *
  * @return array
  *
  * @since  1.0.0
  * @author Dennis Eichhorn
  */
 public function getRoutedModules($request)
 {
     switch ($this->app->dbPool->get('core')->getType()) {
         case \phpOMS\DataStorage\Database\DatabaseType::MYSQL:
             $uri_hash = $request->getHash();
             $uri_pdo = '';
             $i = 1;
             foreach ($uri_hash as $hash) {
                 $uri_pdo .= ':pid' . $i . ',';
                 $i++;
             }
             $uri_pdo = rtrim($uri_pdo, ',');
             /* TODO: make join in order to see if they are active */
             $sth = $this->app->dbPool->get('core')->con->prepare('SELECT
                     `' . $this->app->dbPool->get('core')->prefix . 'module_load`.`module_load_type`, `' . $this->app->dbPool->get('core')->prefix . 'module_load`.*
                     FROM
                     `' . $this->app->dbPool->get('core')->prefix . 'module_load`
                     WHERE
                     `module_load_pid` IN(' . $uri_pdo . ')');
             $i = 1;
             foreach ($uri_hash as $hash) {
                 $sth->bindValue(':pid' . $i, $hash, \PDO::PARAM_STR);
                 $i++;
             }
             $sth->execute();
             return $sth->fetchAll(\PDO::FETCH_GROUP);
     }
     return null;
 }