public function login(Trace $trace, ServerConfig $serverConfig, LoginFactory $factory, AIS2ServerConnection $connection) { $login = $this->provideLogin($serverConfig, $factory, $this->request); if ($login === null) { return false; } $trace->tlog("logging in"); if (!$login->login($connection)) { return false; } $trace->tlog("logged in correctly."); $this->session->write('login/login.class', $login); FajrUtils::redirect(); assert(false); }
public function login(Trace $trace, ServerConfig $serverConfig, LoginFactory $factory, AIS2ServerConnection $connection) { $login = $this->provideLogin($serverConfig, $factory, $this->request); if ($login === null) { return false; } $trace->tlog("logging in"); if (!$login->login($connection)) { return false; } $trace->tlog("logged in correctly."); $this->session->write('login/login.class', $login); $this->session->write('server', $serverConfig); FajrUtils::redirect(); // it should be safe to end script execution here. exit; }
public function getHtml() { $trace = $this->trace->addChild("MojeTerminyHodnoteniaCallback"); $trace->tlog("Executing callback"); $terminyHodnotenia = $this->terminyHodnoteniaApp->getTerminyHodnotenia($trace->addChild("get terminy hodnotenia")); $hodnotenia = $this->hodnoteniaApp->getHodnotenia($trace->addChild("get hodnotenia")); if (Input::get('action') !== null) { $trace->tlog("odhlasujem zo skusky"); assert(Input::get("action") == "odhlasZoSkusky"); if ($this->odhlasZoSkusky(Input::get("odhlasIndex"))) { FajrUtils::redirect(); } else { throw new Exception('Z termínu sa nepodarilo odhlásiť.'); } } $baseUrlParams = array("studium" => Input::get("studium"), "list" => Input::get("list"), "tab" => Input::get("tab")); $terminyHodnoteniaTableActive = new Table(TableDefinitions::mojeTerminyHodnotenia(), 'termin', $baseUrlParams); $terminyHodnoteniaCollapsibleActive = new Collapsible(new HtmlHeader('Aktuálne termíny hodnotenia'), $terminyHodnoteniaTableActive); $terminyHodnoteniaTableOld = new Table(TableDefinitions::mojeTerminyHodnotenia(), 'termin', $baseUrlParams); $terminyHodnoteniaCollapsibleOld = new Collapsible(new HtmlHeader('Staré termíny hodnotenia'), $terminyHodnoteniaTableOld); if (Input::get('termin') != null) { $terminyHodnoteniaTableActive->setOption('selected_key', Input::get('termin')); $terminyHodnoteniaTableOld->setOption('selected_key', Input::get('termin')); } $actionUrl = FajrUtils::linkUrl($baseUrlParams); $hodnoteniePredmetu = array(); foreach ($hodnotenia->getData() as $row) { $hodnoteniePredmetu[$row['nazov']] = $row['znamka']; } foreach ($terminyHodnotenia->getData() as $row) { $datum = AIS2Utils::parseAISDateTime($row['dat'] . " " . $row['cas']); if ($row['znamka'] == "") { // skusme najst znamku v hodnoteniach if (isset($hodnoteniePredmetu[$row['predmet']]) && $hodnoteniePredmetu[$row['predmet']] != "") { $row['znamka'] = $hodnoteniePredmetu[$row['predmet']] . " (z predmetu)"; } } if ($datum < time()) { $row['odhlas'] = "Skúška už bola."; if ($row['jePrihlaseny'] == 'A') { $terminyHodnoteniaTableOld->addRow($row, null); } } else { if ($row['mozeOdhlasit'] == 1) { $class = 'terminmozeodhlasit'; $hash = $this->hashNaOdhlasenie($row); $row['odhlas'] = "<form method='post' action='{$actionUrl}'>\n <div>\n <input type='hidden' name='action' value='odhlasZoSkusky'/>\n <input type='hidden' name='odhlasIndex'\n value='" . $row['index'] . "'/>\n <input type='hidden' name='hash' value='{$hash}'/>\n <button name='submit' type='submit' class='tableButton negative'>\n <img src='images/cross.png' alt=''>Odhlás\n </button></div></form>"; } else { $row['odhlas'] = "nedá sa"; $class = 'terminnemozeodhlasit'; } if ($row['prihlaseny'] != 'A') { $row['odhlas'] = 'Si odhlásený. Ak chceš, opäť sa prihlás.'; $class = 'terminodhlaseny'; } $terminyHodnoteniaTableActive->addRow($row, array('class' => $class)); } } $html = $terminyHodnoteniaCollapsibleActive->getHtml(); $html .= $terminyHodnoteniaCollapsibleOld->getHtml(); if (Input::get('termin') != null) { $prihlaseni = $this->terminyHodnoteniaApp->getZoznamPrihlasenychDialog($trace, Input::get('termin'))->getZoznamPrihlasenych($trace); $zoznamPrihlasenychTable = new Table(TableDefinitions::zoznamPrihlasenych(), null, array('studium', 'list')); $zoznamPrihlasenychTable->addRows($prihlaseni->getData()); $zoznamPrihlasenychCollapsible = new Collapsible(new HtmlHeader('Zoznam prihlásených na vybratý termín'), $zoznamPrihlasenychTable); $html .= $zoznamPrihlasenychCollapsible->getHtml(); } return $html; }
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); } }
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'); } } }
public function getHtml() { $predmetyZapisnehoListu = $this->skusky->getPredmetyZapisnehoListu($this->trace); $hodnoteniaData = array(); foreach ($this->hodnotenia->getHodnotenia($this->trace)->getData() as $row) { $hodnoteniaData[$row['nazov']] = $row; } $this->hodnoteniaData = $hodnoteniaData; if (Input::get('action') !== null) { assert(Input::get("action") == "prihlasNaSkusku"); if ($this->prihlasNaSkusku(Input::get("prihlasPredmetIndex"), Input::get("prihlasTerminIndex"))) { FajrUtils::redirect(array('tab' => 'TerminyHodnotenia')); } else { throw new Exception('Na skúšku sa nepodarilo prihlásiť.'); } } $baseUrlParams = array("studium" => Input::get("studium"), "list" => Input::get("list"), "tab" => Input::get("tab")); $terminyTable = new Table(TableDefinitions::vyberTerminuHodnoteniaJoined(), array('termin' => 'index', 'predmet' => 'predmetIndex'), $baseUrlParams); $terminyCollapsible = new Collapsible(new HtmlHeader('Termíny, na ktoré sa môžem prihlásiť'), $terminyTable); $actionUrl = FajrUtils::linkUrl($baseUrlParams); foreach ($predmetyZapisnehoListu->getData() as $predmetRow) { $dialog = $this->skusky->getZoznamTerminovDialog($this->trace->addChild('Get zoznam terminov'), $predmetRow['index']); $terminy = $dialog->getZoznamTerminov($this->trace->addChild('Get zoznam terminov')); unset($dialog); foreach ($terminy->getData() as $row) { $row['predmet'] = $predmetRow['nazov']; $row['predmetIndex'] = $predmetRow['index']; $hash = $this->hashNaPrihlasenie($predmetRow['nazov'], $row); $mozeSaPrihlasit = $this->mozeSaPrihlasit($row); if ($mozeSaPrihlasit == self::PRIHLASIT_MOZE || $mozeSaPrihlasit == self::PRIHLASIT_MOZE_ZNAMKA) { $row['prihlas'] = "<form method='post' action='{$actionUrl}'><div>\n <input type='hidden' name='action' value='prihlasNaSkusku'/>\n <input type='hidden' name='prihlasPredmetIndex'\n value='" . $row['predmetIndex'] . "'/>\n <input type='hidden' name='prihlasTerminIndex'\n value='" . $row['index'] . "'/>\n <input type='hidden' name='hash' value='{$hash}'/>\n <button name='submit' type='submit' class='tableButton positive'>\n <img src='images/add.png' alt=''>Prihlás ma!\n </button></div></form>"; if ($mozeSaPrihlasit == self::PRIHLASIT_MOZE_ZNAMKA) { $row['prihlas'] = 'Už máš zápísané"' . $hodnoteniaData[$row['predmet']]['znamka'] . '"' . $row['prihlas']; } } else { if ($mozeSaPrihlasit == self::PRIHLASIT_NEMOZE_CAS) { $row['prihlas'] = 'Nedá sa (neskoro)'; } else { if ($mozeSaPrihlasit == self::PRIHLASIT_NEMOZE_POCET) { $row['prihlas'] = 'Termín je plný!'; } else { if ($mozeSaPrihlasit == self::PRIHLASIT_NEMOZE_ZNAMKA) { $row['prihlas'] = 'Už máš zápísané"' . $hodnoteniaData[$row['predmet']]['znamka'] . '"'; } else { if ($mozeSaPrihlasit == self::PRIHLASIT_NEMOZE_INE) { $row['prihlas'] = 'Nedá sa, dôvod neznámy'; } } } } } $terminyTable->addRow($row, null); } } if (Input::get('termin') != null && Input::get('predmet') != null) { $terminyTable->setOption('selected_key', array('index' => Input::get('termin'), 'predmetIndex' => Input::get('predmet'))); } $html = $terminyCollapsible->getHtml(); if (Input::get('termin') != null && Input::get('predmet') != null) { $prihlaseni = $this->skusky->getZoznamTerminovDialog($this->trace, Input::get('predmet'))->getZoznamPrihlasenychDialog($this->trace, Input::get('termin'))->getZoznamPrihlasenych($this->trace); $zoznamPrihlasenychTable = new Table(TableDefinitions::zoznamPrihlasenych(), null, array('studium', 'list')); $zoznamPrihlasenychCollapsible = new Collapsible(new HtmlHeader('Zoznam prihlásených na vybratý termín'), $zoznamPrihlasenychTable); $zoznamPrihlasenychTable->addRows($prihlaseni->getData()); $html .= $zoznamPrihlasenychCollapsible->getHtml(); } return $html; }
/** * Akcia ktora sa pokusi prihlasit cloveka na danu skusku * * @param Trace $trace trace object * @param Context $context */ public function runPrihlasNaSkusku(Trace $trace, Context $context) { $request = $context->getRequest(); $response = $context->getResponse(); $predmetIndex = $request->getParameter("prihlasPredmetIndex"); $terminIndex = $request->getParameter("prihlasTerminIndex"); $predmety = $this->terminyHodnoteniaScreen->getPredmetyZapisnehoListu($trace->addChild('Predmety zapisneho listu'))->getData(); $predmetKey = -1; foreach ($predmety as $key => $row) { if ($row[PredmetyFields::INDEX] == $predmetIndex) { $predmetKey = $key; } } $childTrace = $trace->addChild('Zoznam terminov'); $terminyDialog = $this->terminyHodnoteniaScreen->getZoznamTerminovDialog($childTrace, $predmetIndex); $terminy = $terminyDialog->getZoznamTerminov($childTrace)->getData(); $terminKey = -1; foreach ($terminy as $key => $terminyRow) { if ($terminyRow[TerminyFields::INDEX] == $terminIndex) { $terminKey = $key; } } if ($predmetKey == -1 || $terminKey == -1) { throw new Exception("Ooops, predmet/termín nenájdený. Pravdepodobne\n zmena dát v AISe."); } $hash = StudiumUtils::hashNaPrihlasenie($predmety[$predmetKey][PredmetyFields::SKRATKA], $terminy[$terminIndex]); if ($hash != $request->getParameter('hash')) { throw new Exception("Ooops, nesedia údaje o termíne. Pravdepodobne zmena\n dát v AISe spôsobila posunutie tabuliek."); } if (!$terminyDialog->prihlasNaTermin($trace->addChild('prihlasujem na termin'), $terminIndex)) { throw new Exception('Na skúšku sa nepodarilo prihlásiť.'); } $response->setTemplate('redirect'); FajrUtils::redirect(array('action' => 'studium.MojeTerminyHodnotenia', 'studium' => $this->studium, 'list' => $this->zapisnyList)); }