示例#1
0
 public function runLogic(Trace $trace, HttpConnection $connection)
 {
     $serverConnection = new AIS2ServerConnection($connection, new AIS2ServerUrlMap(FajrConfig::get('AIS2.ServerName')));
     $timer = new SystemTimer();
     if (Input::get('logout') !== null) {
         FajrUtils::logout($serverConnection);
         // TODO(anty): fix this in a better way
         if (FajrConfig::get('Login.Type') == 'cosign') {
             // location header set in CosignProxyLogin
             // but we can't exit there because
             // the session wouldn't get dropped
             exit;
         }
         FajrUtils::redirect(array(), 'index.php');
     }
     $loggedIn = FajrUtils::isLoggedIn($serverConnection);
     $cosignLogin = $this->provideLogin();
     if (!$loggedIn && $cosignLogin != null) {
         FajrUtils::login($trace->addChild("logging in"), $cosignLogin, $serverConnection);
         $loggedIn = true;
     }
     if ($loggedIn) {
         DisplayManager::addContent('<div class=\'logout\'><a class="button negative" href="' . FajrUtils::linkUrl(array('logout' => true)) . '">
     <img src="images/door_in.png" alt=""/>Odhlásiť</a></div>');
         $screenFactory = new VSES017\VSES017_factory($serverConnection);
         $adminStudia = $screenFactory->newAdministraciaStudiaScreen($trace);
         if (Input::get('studium') === null) {
             Input::set('studium', 0);
         }
         $zoznamStudii = $adminStudia->getZoznamStudii($trace->addChild("Get Zoznam Studii:"));
         $zoznamStudiiTable = new Table(TableDefinitions::zoznamStudii(), 'studium', array('tab' => Input::get('tab')));
         $zoznamStudiiTable->addRows($zoznamStudii->getData());
         $zoznamStudiiTable->setOption('selected_key', Input::get('studium'));
         $zoznamStudiiTable->setOption('collapsed', true);
         $zoznamStudiiCollapsible = new Collapsible(new HtmlHeader('Zoznam štúdií'), $zoznamStudiiTable, true);
         DisplayManager::addContent($zoznamStudiiCollapsible->getHtml());
         $zapisneListy = $adminStudia->getZapisneListy($trace->addChild('getZapisneListy'), Input::get('studium'));
         $zapisneListyTable = new Table(TableDefinitions::zoznamZapisnychListov(), 'list', array('studium' => Input::get('studium'), 'tab' => Input::get('tab')));
         if (Input::get('list') === null) {
             $tmp = $zapisneListy->getData();
             $lastList = end($tmp);
             Input::set('list', $lastList['index']);
         }
         $zapisneListyTable->addRows($zapisneListy->getData());
         $zapisneListyTable->setOption('selected_key', Input::get('list'));
         $zapisneListyTable->setOption('collapsed', true);
         $zapisneListyCollapsible = new Collapsible(new HtmlHeader('Zoznam zápisných listov'), $zapisneListyTable, true);
         DisplayManager::addContent($zapisneListyCollapsible->getHtml());
         $terminyHodnotenia = $screenFactory->newTerminyHodnoteniaScreen($trace, $adminStudia->getZapisnyListIdFromZapisnyListIndex($trace, Input::get('list')), $adminStudia->getStudiumIdFromZapisnyListIndex($trace, Input::get('list')));
         if (Input::get('tab') === null) {
             Input::set('tab', 'TerminyHodnotenia');
         }
         $tabs = new TabManager('tab', array('studium' => Input::get('studium'), 'list' => Input::get('list')));
         // FIXME: chceme to nejak refaktorovat, aby sme nevytvarali zbytocne
         // objekty, ktore v konstruktore robia requesty
         $hodnoteniaScreen = $screenFactory->newHodnoteniaPriemeryScreen($trace, $adminStudia->getZapisnyListIdFromZapisnyListIndex($trace, Input::get('list')));
         $tabs->addTab('TerminyHodnotenia', 'Moje skúšky', new MojeTerminyHodnoteniaCallback($trace, $terminyHodnotenia, $hodnoteniaScreen));
         $tabs->addTab('ZapisSkusok', 'Prihlásenie na skúšky', new ZoznamTerminovCallback($trace, $terminyHodnotenia, $hodnoteniaScreen));
         $tabs->addTab('ZapisnyList', 'Zápisný list', new ZapisanePredmetyCallback($trace, $terminyHodnotenia));
         $tabs->addTab('Hodnotenia', 'Hodnotenia/Priemery', new HodnoteniaCallback($trace, $hodnoteniaScreen));
         $tabs->setActive(Input::get('tab'));
         DisplayManager::addContent($tabs->getHtml());
         $version = '<div>Fajr verzia ' . hescape(Version::getVersionString()) . '</div>';
         DisplayManager::addContent($version);
         $statistics = "<div> Fajr made " . $this->statsConnection->getTotalCount() . " requests and downloaded " . $this->rawStatsConnection->getTotalSize() . " bytes (" . $this->statsConnection->getTotalSize() . " bytes uncompressed) of data from AIS2 in " . sprintf("%.3f", $this->statsConnection->getTotalTime()) . " seconds. It took " . sprintf("%.3f", $timer->getElapsedTime()) . " seconds to generate this page.</div>";
         DisplayManager::addContent($statistics);
     } else {
         if (FajrConfig::get('Login.Type') == 'password') {
             DisplayManager::addContent('loginBox', true);
         } else {
             if (FajrConfig::get('Login.Type') == 'cosign') {
                 DisplayManager::addContent('cosignLoginBox', true);
             } else {
                 throw new Exception('Nespravna hodnota konfiguracnej volby Login.Type');
             }
         }
         DisplayManager::addContent('warnings', true);
         DisplayManager::addContent('terms', true);
         DisplayManager::addContent('credits', true);
         $version = "<div class='version prepend-1 span-21 last increase-line-height'>\n<strong>Verzia fajru:</strong> \n";
         $version .= hescape(Version::getVersionString());
         $version .= '</div>';
         DisplayManager::addContent($version);
         DisplayManager::addContent(Version::getChangelog(), false);
     }
 }
示例#2
0
 /**
  * Runs the whole logic. It is fajr's main()
  *
  * @returns void
  */
 public function run()
 {
     $trace = $this->injector->getInstance('Trace.class');
     $this->statistics = $this->injector->getInstance('Statistics.class');
     $this->displayManager = $this->injector->getInstance('DisplayManager.class');
     $this->context = $this->injector->getInstance('Context.class');
     $session = $this->injector->getInstance('Session.Storage.class');
     $loginManager = new LoginManager($session, $this->context->getRequest());
     $response = $this->context->getResponse();
     try {
         Input::prepare();
         // we are going to log in, so we get a clean session
         // this needs to be done before a connection
         // is created, because we pass cookie file name
         // that contains session_id into AIS2CurlConnection
         if ($loginManager->shouldLogin()) {
             $session->regenerate(true);
         }
         $connection = $this->provideConnection();
         $this->setResponseFields($response);
         $this->runLogic($trace, $connection);
     } catch (LoginException $e) {
         if ($connection) {
             FajrUtils::logout($connection);
         }
         $this->setException($e);
     } catch (SecurityException $e) {
         die($e);
         $this->logSecurityException($e);
         $response->setTemplate("securityViolation");
     } catch (Exception $e) {
         die($e);
         $this->setException($e);
     }
     $trace->tlog("everything done, rendering template");
     if (FajrConfig::get('Debug.Trace') === true) {
         $response->set('trace', $trace);
     } else {
         $response->set('trace', null);
     }
     try {
         echo $this->displayManager->display($this->context->getResponse());
     } catch (Exception $e) {
         throw new Exception('Chyba pri renderovaní template ' . $this->context->getResponse()->getTemplate() . ':' . $e->getMessage(), null, $e);
     }
 }
示例#3
0
 public function runLogic(Trace $trace, HttpConnection $connection)
 {
     $response = $this->context->getResponse();
     $response->set('version', new Version());
     $response->set('banner_debug', FajrConfig::get('Debug.Banner'));
     // TODO(anty): toto by chcelo nastavovat nejako lepsie
     $response->set('banner_beta', FajrConfig::get('AIS2.ServerName') == 'ais2-beta.uniba.sk');
     $response->set('google_analytics', FajrConfig::get('GoogleAnalytics.Account'));
     $response->set('serverName', FajrConfig::get('AIS2.ServerName'));
     $response->set('cosignCookieName', FajrConfig::get('Login.Cosign.CookieName'));
     $response->set('instanceName', FajrConfig::get('AIS2.InstanceName'));
     $serverConnection = new AIS2ServerConnection($connection, new AIS2ServerUrlMap(FajrConfig::get('AIS2.ServerName')));
     $this->context->setAisConnection($serverConnection);
     $action = $this->context->getRequest()->getParameter('action', 'studium.MojeTerminyHodnotenia');
     if ($action == 'logout') {
         FajrUtils::logout($serverConnection);
         // TODO(anty): fix this in a better way
         if (FajrConfig::get('Login.Type') == 'cosign') {
             // location header set in CosignProxyLogin
             // but we can't exit there because
             // the session wouldn't get dropped
             exit;
         }
         FajrUtils::redirect(array(), 'index.php');
     } else {
         if ($action == 'termsOfUse') {
             $response->setTemplate('termsOfUse');
             return;
         }
     }
     $loggedIn = FajrUtils::isLoggedIn($serverConnection);
     $cosignLogin = $this->provideLogin();
     if (!$loggedIn && $cosignLogin != null) {
         FajrUtils::login($trace->addChild("logging in"), $cosignLogin, $serverConnection);
         $loggedIn = true;
     }
     if ($loggedIn) {
         $controller = $this->injector->getInstance('Controller.class');
         $response->set("action", $action);
         $controller->invokeAction($trace, $action, $this->context);
         $response->set('statistics', $this->statistics);
     } else {
         if (FajrConfig::get('Login.Type') == 'password') {
             $response->setTemplate('welcome');
         } else {
             $response->setTemplate('welcomeCosign');
         }
     }
 }
示例#4
0
 /**
  * Runs the whole logic. It is fajr's main()
  *
  * @returns void
  */
 public function run()
 {
     try {
         $trace = $this->injector->getInstance('Trace.class');
         $this->statistics = $this->injector->getInstance('Statistics.class');
         $this->displayManager = $this->injector->getInstance('DisplayManager.class');
         $this->context = $this->injector->getInstance('Context.class');
         $session = $this->injector->getInstance('Session.Storage.class');
         $loginManager = new LoginManager($session, $this->context->getRequest());
         $response = $this->context->getResponse();
         // we are going to log in, so we get a clean session
         // this needs to be done before a connection
         // is created, because we pass cookie file name
         // that contains session_id into AIS2CurlConnection
         if ($loginManager->shouldLogin()) {
             $session->regenerate(true);
         }
         $connection = $this->provideConnection();
         $this->setResponseFields($response);
         $this->runLogic($trace, $connection);
     } catch (LoginException $e) {
         if ($connection) {
             FajrUtils::logout($connection);
         }
         $this->setException($e);
     } catch (SecurityException $e) {
         $this->logSecurityException($e);
         if (!FajrConfig::get('Debug.Exception.ShowStacktrace')) {
             die("Internal error");
         } else {
             die($e);
         }
     } catch (Exception $e) {
         $this->setException($e);
         // Note: We MUST unset this exception, because it's
         // stacktrace holds cyclic references to context
         // and therefore the order of destruction of all objects
         // is really random.
         unset($e);
     }
     $trace->tlog("everything done, rendering template");
     if (FajrConfig::get('Debug.Trace') === true) {
         $response->set('trace', $trace);
     } else {
         $response->set('trace', null);
     }
     try {
         echo $this->displayManager->display($this->context->getResponse());
     } catch (Exception $e) {
         throw new Exception('Chyba pri renderovaní template ' . $this->context->getResponse()->getTemplate() . ':' . $e->getMessage(), null, $e);
     }
 }