From: <pan...@us...> - 2008-12-06 23:13:26
|
Revision: 435 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=435&view=rev Author: panzaboi Date: 2008-12-06 23:13:21 +0000 (Sat, 06 Dec 2008) Log Message: ----------- Added functionality to submit problems by textarea or file upload. Modified Paths: -------------- website/application/layouts/layout.phtml website/application/modules/acm/controllers/ArchieveController.php website/application/modules/acm/controllers/IndexController.php website/application/modules/acm/models/Archieve.php website/application/modules/acm/views/scripts/archieve/entry.phtml website/application/modules/acm/views/scripts/archieve/index.phtml website/application/modules/acm/views/scripts/archieve/view.phtml website/application/modules/acm/views/scripts/index/index.phtml website/config/config.ini website/httpdocs/scripts/main.js website/library/Application.php website/library/Ostacium/Controller/Plugin/ErrorHandler.php website/library/Ostacium/Controller/Router/Route/Language.php website/library/Ostacium/Db/Table.php website/other/todo.txt Added Paths: ----------- website/application/modules/acm/models/Form/Submit.php website/application/modules/acm/views/scripts/archieve/submit.phtml website/other/submits/ website/other/uploads/ Property Changed: ---------------- website/library/ Modified: website/application/layouts/layout.phtml =================================================================== --- website/application/layouts/layout.phtml 2008-12-06 13:12:31 UTC (rev 434) +++ website/application/layouts/layout.phtml 2008-12-06 23:13:21 UTC (rev 435) @@ -12,6 +12,7 @@ <?= $this->headLink()->appendStylesheet('styles/style.css') ?> <?= /*$this->headLink()->appendStylesheet('styles/ie6.css', 'screen', 'IE 6')*/'' ?> <?= /*$this->headLink()->appendStylesheet('styles/ie7.css', 'screen', 'IE 7')*/'' ?> + <?= $this->headScript()->appendFile('/scripts/main.js') ?> <? if ($this->dojo()->isEnabled()): $this->dojo()->setLocalPath('/scripts/dojo/dojo.js') @@ -19,7 +20,6 @@ echo $this->dojo(); endif; ?> - <?= $this->headScript()->appendFile('/scripts/main.js') ?> </head> <body class="tundra"> <table border="0" cellpadding="0" cellspacing="0" width="100%"> @@ -39,10 +39,10 @@ <table width="100%" border="0" cellpadding="0" cellspacing="5"> <tr><td><img border="0" src="images/arrow.gif" width="8" height="8" hspace="5"><a href="index/about">Що це за проект</a></td></tr> <tr><td><img border="0" src="images/arrow.gif" width="8" height="8" hspace="5"><a href="index/rule">Правила</a></td></tr> - <tr><td><img border="0" src="images/arrow.gif" width="8" height="8" hspace="5"><a href="archieve/index">Набір завдань</a></td></tr> - <tr><td><img border="0" src="images/arrow.gif" width="8" height="8" hspace="5"><a href="archieve/submit">Протестувати Розв'язок</a></td></tr> - <tr><td><img border="0" src="images/arrow.gif" width="8" height="8" hspace="5"><a href="archieve/results">Результати Тестувань</a></td></tr> - <tr><td><img border="0" src="images/arrow.gif" width="8" height="8" hspace="5"><a href="archieve/ranks">Рейтинг Учасників</a></td></tr> + <tr><td><img border="0" src="images/arrow.gif" width="8" height="8" hspace="5"><a href="/acm/archieve/index">Набір завдань</a></td></tr> + <tr><td><img border="0" src="images/arrow.gif" width="8" height="8" hspace="5"><a href="/acm/archieve/submit">Протестувати Розв'язок</a></td></tr> + <tr><td><img border="0" src="images/arrow.gif" width="8" height="8" hspace="5"><a href="/acm/archieve/results">Результати Тестувань</a></td></tr> + <tr><td><img border="0" src="images/arrow.gif" width="8" height="8" hspace="5"><a href="/acm/archieve/ranks">Рейтинг Учасників</a></td></tr> <tr><td><hr></td></tr> </table> Modified: website/application/modules/acm/controllers/ArchieveController.php =================================================================== --- website/application/modules/acm/controllers/ArchieveController.php 2008-12-06 13:12:31 UTC (rev 434) +++ website/application/modules/acm/controllers/ArchieveController.php 2008-12-06 23:13:21 UTC (rev 435) @@ -15,11 +15,76 @@ if (!$problem) return $this->_forward('index', null, null, $this->_getAllParams() + array('message' => 'noProblem')); - $this->view->problem = $problem; + $this->view->assign($problem); } public function submitAction() { + $this->_helper->getHelper('viewRenderer')->setNoRender(true); + $form = $this->_model->getSubmitForm(array( + 'action' => $this->view->url(array('action' => 'upload', 'id' => $this->_getParam('id')), null), + 'method' => 'post', + 'name' => 'submitform', + )); + + $this->view->dojo()->addOnLoad('function(){ changeEditor('.$form->type->getValue().'); }'); + + echo $form; } + + public function uploadAction() + { + $this->_helper->getHelper('viewRenderer')->setNoRender(true); + $form = $this->_model->getSubmitForm(array( + 'action' => $this->view->url(array('action' => 'upload', 'id' => $this->_getParam('id')), null), + 'method' => 'post', + 'name' => 'submitform', + )); + + if (!$this->getRequest()->isPost()) + { + return $this->_forward('submit', null, null, $this->_getAllParams()); + } + + if ($_POST['type'] == 0) + { + $form->code->setRequired(true); + } + elseif ($_POST['type'] == 1) + { + $form->codefile->setRequired(true); + } + + $result = $form->isValid($this->getRequest()->getPost()); + $this->view->dojo()->addOnLoad('function(){ changeEditor('.$form->type->getValue().'); }'); + + if ($form->type->getValue() == 0) + { + $form->code->setRequired(false); + } + elseif ($form->type->getValue() == 1) + { + $form->codefile->setRequired(false); + } + + if (!$result) + { + echo $form; + return; + } + + $values = $form->getValues(); + $values += $this->_getAllParams(); + $id = $this->_model->addSubmit($values); + + if ($values['type'] == 0) + { + file_put_contents(Application::getDocRoot().'/other/submits/'.$id.'.cpp', $values['code']); + } + elseif ($values['type'] == 1) + { + rename($form->codefile->getFileName(), Application::getDocRoot().'/other/submits/'.$id.'.cpp'); + } + } } \ No newline at end of file Modified: website/application/modules/acm/controllers/IndexController.php =================================================================== --- website/application/modules/acm/controllers/IndexController.php 2008-12-06 13:12:31 UTC (rev 434) +++ website/application/modules/acm/controllers/IndexController.php 2008-12-06 23:13:21 UTC (rev 435) @@ -58,7 +58,7 @@ protected function getLoginForm() { return new Form_Login(array( - 'action' => $this->getRequest()->getBaseUrl() . 'acm/index/login', + 'action' => $this->view->url(array('action' => 'login'), null), 'method' => 'post', 'name' => 'loginform', )); Modified: website/application/modules/acm/models/Archieve.php =================================================================== --- website/application/modules/acm/models/Archieve.php 2008-12-06 13:12:31 UTC (rev 434) +++ website/application/modules/acm/models/Archieve.php 2008-12-06 23:13:21 UTC (rev 435) @@ -13,6 +13,37 @@ $challenges = new Challenges(); return $challenges->get($id); } + + public function getCodeLanguages() + { + return $this->_db->fetchPairs($this->_db->select()->from('code_languages', array('id', 'name'))); + } + + public function addSubmit($values) + { + $data = array( + 'username' => Zend_Auth::getInstance()->getStorage()->read()->username, + 'challengeid' => $values['id'], + 'languageid' => $values['languageid'], + 'firsttest' => $values['firsttest'], + 'when' => time() + ); + + $submits = new Submits(); + return $submits->insert($data); + } + + public function getSubmitForm($options = array()) + { + $form = new Form_Submit($options); + $user = Zend_Auth::getInstance()->getStorage()->read(); + + $languageid = $form->getElement('languageid'); + $languageid->addMultiOptions($this->getCodeLanguages()); + $languageid->setValue($user->codelangid); + + return $form; + } } class Challenges extends Ostacium_Db_Table @@ -20,8 +51,19 @@ protected $_name = 'challenges'; protected $_primary = 'id'; + public function get($id) + { + return $this->selectLang(array('name', 'description'))->where($this->_name.'.id = ?', $id)->query()->fetch(); + } + public function getAll() { - return $this->select()->from($this)->where('enabled = ?', 1)->query()->fetchAll(); + return $this->selectLang(array('name', 'description'))->where('enabled = ?', 1)->query()->fetchAll(); } +} + +class Submits extends Ostacium_Db_Table +{ + protected $_name = 'archieve_submits'; + protected $_primary = 'id'; } \ No newline at end of file Added: website/application/modules/acm/models/Form/Submit.php =================================================================== --- website/application/modules/acm/models/Form/Submit.php (rev 0) +++ website/application/modules/acm/models/Form/Submit.php 2008-12-06 23:13:21 UTC (rev 435) @@ -0,0 +1,82 @@ +<?php + +class Form_Submit extends Zend_Dojo_Form +{ + public $elementDecorators = array( + 'DijitElement', + 'Errors', + array('Label', array('class' => 'overlabel')), + array('HtmlTag', array('tag' => 'div', 'class' => 'elcontainer')) + ); + + public $simpleDecorators = array( + 'Errors', + array('Label', array('class' => 'overlabel')), + array('HtmlTag', array('tag' => 'div', 'class' => 'elcontainer')) + ); + + public $buttonDecorators = array( + 'DijitElement', + ); + + public function init() + { + $translate = Zend_Registry::get('Zend_Translate'); + + $this->setAttrib('enctype', 'multipart/form-data'); + + $this->addElement('FilteringSelect', 'languageid', array( + 'decorators' => $this->elementDecorators, + 'required' => true, + 'style' => 'height: 18px; width: 100px;', + 'title' => $translate->_('code_language'), + 'label' => $translate->_('code_language').': ', + )); + + $this->addElement('RadioButton', 'type', array( + 'decorators' => $this->elementDecorators, + 'required' => true, + 'title' => $translate->_('upload_type'), + 'label' => $translate->_('upload_type ').': ', + 'multiOptions' => array($translate->_('editor'), $translate->_('file_upload')), + 'onclick' => 'changeEditor(this.value);', + 'value' => 0 + )); + + $this->addElement('SimpleTextarea', 'code', array( + 'decorators' => $this->elementDecorators, + 'style' => 'height: 400px; width: 500px;', + 'title' => $translate->_('enter_code'), + 'label' => $translate->_('enter_code'), + )); + + $this->addElement('File', 'codefile', array( + 'decorators' => array_merge(array('File'), $this->simpleDecorators), + 'validators' => array(array('Count', false, 1)), + 'destination' => Application::getDocRoot().'/other/uploads/', + 'label' => $translate->_('enter_code'), + )); + + $this->addElement('Checkbox', 'firsttest', array( + 'decorators' => $this->elementDecorators, + 'title' => $translate->_('first_test'), + 'label' => $translate->_('first_test ').': ' + )); + + $this->addElement('SubmitButton', 'submitbutton', array( + 'decorators' => $this->buttonDecorators, + 'required' => false, + 'ignore' => true, + 'label' => $translate->_('submit'), + )); + } + + public function loadDefaultDecorators() + { + $this->setDecorators(array( + 'FormElements', + 'DijitForm', + array('Description', array('placement' => 'prepend', 'tag' => 'div', 'class' => 'error')), + )); + } +} \ No newline at end of file Modified: website/application/modules/acm/views/scripts/archieve/entry.phtml =================================================================== --- website/application/modules/acm/views/scripts/archieve/entry.phtml 2008-12-06 13:12:31 UTC (rev 434) +++ website/application/modules/acm/views/scripts/archieve/entry.phtml 2008-12-06 23:13:21 UTC (rev 435) @@ -12,7 +12,7 @@ <td style="border-left: 0px none; border-right: 1px solid rgb(196, 196, 219);"><?= $this->accepted ?></td> <td style="border-left: 0px none; border-right: 0px solid rgb(196, 196, 219);"> - <img height="17" width="22" alt="Здати" src="images/b_find.gif"/> - <img height="17" width="22" alt="Показати як здають" src="images/probstatus.png"/> + <a href="<?= $this->url( array('action' => 'submit', 'id' => $this->id), null) ?>"><img height="17" width="22" alt="Здати" title="Здати" src="images/b_find.gif"/></a> + <a href="<?= $this->url( array('action' => 'status', 'id' => $this->id), null) ?>"><img height="17" width="22" alt="Показати як здають" src="images/probstatus.png"/> </td> </tr> \ No newline at end of file Modified: website/application/modules/acm/views/scripts/archieve/index.phtml =================================================================== --- website/application/modules/acm/views/scripts/archieve/index.phtml 2008-12-06 13:12:31 UTC (rev 434) +++ website/application/modules/acm/views/scripts/archieve/index.phtml 2008-12-06 23:13:21 UTC (rev 435) @@ -1,5 +1,10 @@ -<table cellspacing="1" cellpadding="8" border="0" width="100%"><tbody><tr><td width="100%" valign="top" class="name"><table cellspacing="0" cellpadding="0" border="0" width="100%"><tbody><tr><td bgcolor="#d0d4de" width="4" class="name"><img height="18" width="4" src="http://web.archive.org/web/20070323032706/http://acm.lviv.ua/"/></td><td nowrap="" bgcolor="#122a5b" width="*" class="name"> <font color="#d4d0e2"><b><small>Набiр задач</small></b><small/></font></td><td nowrap="" bgcolor="#122a5b" align="right" class="name"> <font color="#d4d0e2"><b><small> 05:26 23 березня 2007 року </small></b><small/></font></td></tr></tbody></table> <table cellspacing="0" cellpadding="0" border="0" width="100%" summary=""><tbody><tr><td bgcolor="#f4f3f8" align="middle" colspan="14"><b>Архів задач</b></td></tr><tr><td bgcolor="#c4c4db" colspan="20"><img height="1" width="1" src="http://web.archive.org/web/20070323032706/http://acm.lviv.ua/" alt=""/></td></tr><tr bgcolor="#e1e1e1" align="middle"> -<th width="70">Задача</th><th align="left" width="*"> Назва</th><th width="70">Спробували</th><th width="70">Здали</th><th align="middle" width="70">Дії</th></tr><tr><td height="1" bgcolor="#c4c4db" colspan="20"><img height="1" width="1" src="http://web.archive.org/web/20070323032706/http://acm.lviv.ua/" alt=""/></td></tr> +<table cellspacing="1" cellpadding="8" border="0" width="100%"><tbody><tr><td width="100%" valign="top" class="name"> + +<table cellspacing="0" cellpadding="0" border="0" width="100%"><tbody><tr><td bgcolor="#d0d4de" width="4" class="name"> + +<img height="18" width="4" src="http://web.archive.org/web/20070323032706/http://acm.lviv.ua/"/></td> + +<td nowrap="" bgcolor="#122a5b" width="*" class="name"> <font color="#d4d0e2"><b><small>Набiр задач</small></b><small/></font></td><td nowrap="" bgcolor="#122a5b" align="right" class="name"> <font color="#d4d0e2"><b><small> 05:26 23 березня 2007 року </small></b><small/></font></td></tr></tbody></table> <table cellspacing="0" cellpadding="0" border="0" summary="" align="center"><tbody><tr><td bgcolor="#f4f3f8" align="middle" colspan="14"><b>Архів задач</b></td></tr><tr><td bgcolor="#c4c4db" colspan="20"><img height="1" width="1" src="http://web.archive.org/web/20070323032706/http://acm.lviv.ua/" alt=""/></td></tr><tr bgcolor="#e1e1e1" align="middle"> +<th width="70">Задача</th><th align="left" width="270"> Назва</th><th width="70">Спробували</th><th width="70">Здали</th><th align="middle" width="70">Дії</th></tr><tr><td height="1" bgcolor="#c4c4db" colspan="20"><img height="1" width="1" src="http://web.archive.org/web/20070323032706/http://acm.lviv.ua/" alt=""/></td></tr> <?= $this->partialLoop('archieve/entry.phtml', $this->challenges) ?> - </table><br/></td></tr></table> \ No newline at end of file Modified: website/application/modules/acm/views/scripts/archieve/view.phtml =================================================================== --- website/application/modules/acm/views/scripts/archieve/view.phtml 2008-12-06 13:12:31 UTC (rev 434) +++ website/application/modules/acm/views/scripts/archieve/view.phtml 2008-12-06 23:13:21 UTC (rev 435) @@ -1,5 +1,12 @@ -<?php +<h2 align="center"><?= $this->id.' - '.$this->name ?></h2> +<div align="center"> + <?= $this->translate('timelimit') ?>: <?= $this->measure("Time", $this->timelimit, Zend_Measure_Time::MILLISECOND, Zend_Measure_Time::SECOND, 0 ) ?><br /> + <?= $this->translate('memorylimit') ?>: <?= $this->measure("Binary", $this->memorylimit, Zend_Measure_Binary::BYTE, Zend_Measure_Binary::KILOBYTE ) ?><br /> + <?= $this->translate('outputlimit') ?>: <?= $this->measure("Binary", $this->outputlimit, Zend_Measure_Binary::BYTE, Zend_Measure_Binary::KILOBYTE ) ?><br /> +</div> +<br /> +<p><?= $this->description ?></p> -var_dump($this->problem); - -?> \ No newline at end of file +<div> + <a href="<?= $this->url(array('action' => 'submit', 'id' => $this->id), null) ?>"><?= $this->translate('submit') ?></a> +</div> \ No newline at end of file Modified: website/application/modules/acm/views/scripts/index/index.phtml =================================================================== --- website/application/modules/acm/views/scripts/index/index.phtml 2008-12-06 13:12:31 UTC (rev 434) +++ website/application/modules/acm/views/scripts/index/index.phtml 2008-12-06 23:13:21 UTC (rev 435) @@ -1 +1,9 @@ -<table cellspacing="1" cellpadding="8" border="0" width="100%"><tbody><tr><td width="100%" valign="top" class="name"><table cellspacing="0" cellpadding="0" border="0" width="100%"><tbody><tr><td bgcolor="#d0d4de" width="4" class="name"><img height="18" width="4" src="http://web.archive.org/web/20070323032459/http://acm.lviv.ua/"/></td><td nowrap="" bgcolor="#122a5b" width="*" class="name"> <font color="#d4d0e2"><b><small>Про систему</small></b><small/></font></td><td nowrap="" bgcolor="#122a5b" align="right" class="name"> <font color="#d4d0e2"><b><small> 05:24 23 березня 2007 року </small></b><small/></font></td></tr></tbody></table> <p style="font-size: 20px; font-family: arial; text-align: center;"><b>ACM Contester</b></p><p align="justify" style="font-size: 20px; font-family: arial; text-align: justify;"><font size="3">Ми, команда розробників цієї системи, дуже раді вітати Вас - учасників цієї системи. </font></p><p align="justify" style="font-size: 20px; font-family: arial; text-align: justify;"><font size="3">Тут Ви маєте можливість спробувати свої сили у розв'язанні різних типів задач. Змагайтесь!!!</font></p><p> </p></td></tr></tbody></table> \ No newline at end of file +<table cellspacing="1" cellpadding="8" border="0" width="100%"> +<tbody> + <tr> + <td width="100%" valign="top" class="name"> + <table cellspacing="0" cellpadding="0" border="0" width="100%"> + <tbody> + <tr> + <td bgcolor="#d0d4de" width="4" class="name"> + <img height="18" width="4" src="http://web.archive.org/web/20070323032459/http://acm.lviv.ua/"/></td><td nowrap="" bgcolor="#122a5b" width="*" class="name"> <font color="#d4d0e2"><b><small>Про систему</small></b><small/></font></td><td nowrap="" bgcolor="#122a5b" align="right" class="name"> <font color="#d4d0e2"><b><small> 05:24 23 березня 2007 року </small></b><small/></font></td></tr></tbody></table> <p style="font-size: 20px; font-family: arial; text-align: center;"><b>ACM Contester</b></p><p align="justify" style="font-size: 20px; font-family: arial; text-align: justify;"><font size="3">Ми, команда розробників цієї системи, дуже раді вітати Вас - учасників цієї системи. </font></p><p align="justify" style="font-size: 20px; font-family: arial; text-align: justify;"><font size="3">Тут Ви маєте можливість спробувати свої сили у розв'язанні різних типів задач. Змагайтесь!!!</font></p><p> </p></td></tr></tbody></table> \ No newline at end of file Modified: website/config/config.ini =================================================================== --- website/config/config.ini 2008-12-06 13:12:31 UTC (rev 434) +++ website/config/config.ini 2008-12-06 23:13:21 UTC (rev 435) @@ -65,8 +65,9 @@ #currency.precision = "2" currency.display = "2" -title = "ACM Contester" -titlesep = " - " +general.title = "ACM Contester" +general.titlesep = " - " +general.extention = "html" [development: general] @@ -76,7 +77,8 @@ db.params.dbname = "acm" db.params.username = "acm" db.params.password = "c0nt3st3r" +db.params.profiler.label = Db Profiler db.params.profiler.enabled = true -db.params.profiler.class = Zend_Db_Profiler_Firebug +db.params.profiler.class = Ostacium_Db_Profiler_Firebug [stable: genral] \ No newline at end of file Modified: website/httpdocs/scripts/main.js =================================================================== --- website/httpdocs/scripts/main.js 2008-12-06 13:12:31 UTC (rev 434) +++ website/httpdocs/scripts/main.js 2008-12-06 23:13:21 UTC (rev 435) @@ -1 +1,19 @@ +function changeEditor(value) +{ + if (!dojo.byId('code') || !dojo.byId('codefile')) return false; + + if (value == 0) + { + dojo.byId('code').parentNode.style.display = 'block'; + dojo.byId('codefile').parentNode.style.display = 'none'; + } + else if(value == 1) + { + dojo.byId('code').parentNode.style.display = 'none'; + dojo.byId('codefile').parentNode.style.display = 'block'; + } + + return false; +} + function checkForm(form){if(form.lgn.value.length<3){alert('Логін повинен мати як мінімум 3 символи!');return false;}} \ No newline at end of file Property changes on: website/library ___________________________________________________________________ Modified: svn:ignore - Zend + Zend ZendX Modified: website/library/Application.php =================================================================== --- website/library/Application.php 2008-12-06 13:12:31 UTC (rev 434) +++ website/library/Application.php 2008-12-06 23:13:21 UTC (rev 435) @@ -5,12 +5,12 @@ protected $_environment; protected static $_approot; protected static $_start; - protected $_docroot; + protected static $_docroot; public function __construct($_approot) { self::$_approot = $_approot; - $this->_docroot = dirname($_SERVER["DOCUMENT_ROOT"]); + self::$_docroot = dirname($_SERVER["DOCUMENT_ROOT"]); self::$_start = microtime(true); } @@ -19,6 +19,11 @@ return self::$_approot; } + public static function getDocRoot() + { + return self::$_docroot; + } + public static function getRunTime() { return (microtime(true) - self::$_start); @@ -58,9 +63,9 @@ { // Set Include paths set_include_path( - $this->_docroot . PATH_SEPARATOR - . $this->_docroot . '/application' . PATH_SEPARATOR - . $this->_docroot . '/library' . PATH_SEPARATOR + self::$_docroot . PATH_SEPARATOR + . self::$_docroot . '/application' . PATH_SEPARATOR + . self::$_docroot . '/library' . PATH_SEPARATOR . get_include_path() ); @@ -74,15 +79,15 @@ // Setup Config $_config = $this->_setupConfig(); + // Setup DB + $this->_setupDB(); + // Setup Front Controller $frontController = $this->_setupFrontController(); // Setup Date Ostacium_Date::setOptions($_config->date->toArray()); //date_default_timezone_set($_config->date->timezone); - - // Setup DB - $this->_setupDB(); // Setup Helpers Ostacium_View_Helper_Truncate::setDefault($_config->truncate->toArray()); @@ -90,9 +95,6 @@ // Setup Log $this->_setupLog(); - - // Setup Authorication - $acl = $this->_setupAuth(); // Setup Languages $this->_setupLang(); @@ -108,8 +110,8 @@ Zend_Mail::setDefaultTransport($mail); // Setup Plugins - $routerPlugin = new Ostacium_Controller_Plugin_Router($acl, $_config->auth->noauth->toArray(), $_config->auth->noacl->toArray()); - $frontController->registerPlugin($routerPlugin, -1); + //$routerPlugin = new Ostacium_Controller_Plugin_Router($acl, $_config->auth->noauth->toArray(), $_config->auth->noacl->toArray()); + //$frontController->registerPlugin($routerPlugin, -1); return $frontController; } @@ -131,7 +133,7 @@ protected function _setupConfig() { - $_config = new Zend_Config_Ini($this->_docroot . '/config/config.ini', $this->getEnvironment()); + $_config = new Zend_Config_Ini(self::$_docroot . '/config/config.ini', $this->getEnvironment()); error_reporting((int)$_config->error->report); ini_set('display_errors', (int)$_config->error->display); @@ -162,16 +164,15 @@ $frontController->throwExceptions((bool) $_config->error->throw); $frontController->setParam('environment', $this->_environment); $frontController->setModuleControllerDirectoryName('controllers'); - $frontController->addModuleDirectory($this->_docroot . '/application/modules/'); + $frontController->addModuleDirectory(self::$_docroot . '/application/modules/'); $frontController->setRequest('Ostacium_Controller_Request_Http'); + // Setup Authorication + $acl = $this->_setupAuth(); + // Error Handler $frontController->setParam('noErrorHandler', 1); - $frontController->registerPlugin(new Ostacium_Controller_Plugin_ErrorHandler(array( - 'module' => $_config->auth->noacl->module, - 'controller' => $_config->auth->noacl->controller, - 'action' => $_config->auth->noacl->action - ))); + $frontController->registerPlugin(new Ostacium_Controller_Plugin_ErrorHandler($acl, $_config->auth->noauth->toArray())); return $frontController; } @@ -181,18 +182,20 @@ $_config = Zend_Registry::get('config'); $options = $_config->view->toArray(); - $options['helperPath'] = $this->_docroot . '/' . $options['helperPath']; + $options['helperPath'] = self::$_docroot . '/' . $options['helperPath']; $view = new Zend_View($options); // Setup DocType $view->doctype('XHTML1_TRANSITIONAL'); + // Setup Title - $view->headTitle($_config->title)->setSeparator($_config->titlesep); + $view->headTitle($_config->general->title)->setSeparator($_config->general->titlesep); + // Setup Dojo Zend_Dojo::enableView($view); $options = $_config->layout->toArray(); - $options['layoutpath'] = $this->_docroot . '/' . $options['layoutpath']; + $options['layoutpath'] = self::$_docroot . '/' . $options['layoutpath']; Zend_Layout::startMvc($options + array('view' => $view)); $viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view); @@ -205,6 +208,7 @@ $acl = new Ostacium_Acl($_config->auth->order); $auth = new Ostacium_Auth_Adapter_DbTable(Zend_Registry::get('db'), $_config->auth->table, $_config->auth->user, $_config->auth->pass, $_config->auth->passtreat); + $auth->setReferenceMap($_config->auth->referenceMap->toArray()); Zend_Registry::set('auth', $auth); @@ -219,11 +223,11 @@ $_db = Zend_Registry::get('db'); $_auth = Zend_Auth::getInstance(); - $translate = new Zend_Translate('csv', $this->_docroot . '/' . $_config->lang->path . $_config->lang->default . '.csv', $_config->lang->default); - foreach($_config->lang->langs as $lang) + $translate = new Zend_Translate('csv', self::$_docroot . '/' . $_config->lang->path . $_config->lang->default . '.csv', $_config->lang->default); + foreach ($_config->lang->langs as $lang) { if ($lang != $_config->lang->default) - $translate->addTranslation($this->_docroot . '/' . $_config->lang->path . $lang .'.csv', 'en'); + $translate->addTranslation(self::$_docroot . '/' . $_config->lang->path . $lang .'.csv', 'en'); } if ($_auth->hasIdentity()) @@ -240,7 +244,7 @@ $_config = Zend_Registry::get('config'); $router = $frontController->getRouter(); - $router->addRoute('default', new Ostacium_Controller_Router_Route_Language(array(), $frontController->getDispatcher(), $frontController->getRequest())); + $router->addRoute('default', new Ostacium_Controller_Router_Route_Language(array(), $frontController->getDispatcher(), $frontController->getRequest(), $_config->general->extention)); if ($_config->routes) $router->addConfig($_config->routes); Modified: website/library/Ostacium/Controller/Plugin/ErrorHandler.php =================================================================== --- website/library/Ostacium/Controller/Plugin/ErrorHandler.php 2008-12-06 13:12:31 UTC (rev 434) +++ website/library/Ostacium/Controller/Plugin/ErrorHandler.php 2008-12-06 23:13:21 UTC (rev 435) @@ -3,33 +3,50 @@ class Ostacium_Controller_Plugin_ErrorHandler extends Zend_Controller_Plugin_ErrorHandler { protected $_isPreDispatch = false; + protected $_acl; + protected $_noauth = array( + 'controller' => 'index', + 'action' => 'login' + ); + + public function __construct($acl, $noauth = null) { + $this->_acl = $acl; + $this->_noauth = is_array($noauth) ? $noauth : $this->_noauth; + } const EXCEPTION_NOTALLOWED = 'EXCEPTION_NOTALLOWED'; public function preDispatch(Zend_Controller_Request_Abstract $request) - { + { $frontController = Zend_Controller_Front::getInstance(); $dispatcher = $frontController->getDispatcher(); $response = $this->getResponse(); $error = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS); $error->exception = current($response->getException()); - + if (!$dispatcher->isDispatchable($request)) { $error->type = self::EXCEPTION_NO_CONTROLLER; if (!$error->exception) $error->exception = new Zend_Controller_Dispatcher_Exception("Resource doesn't exist", 404); - } elseif (!$this->isProperAction($dispatcher, $request)) { + } elseif (!$this->isProperAction($dispatcher, $request) || !$this->existsResource($dispatcher, $request)) { $error->type = self::EXCEPTION_NO_ACTION; if (!$error->exception) $error->exception = new Zend_Controller_Dispatcher_Exception("Resource doesn't exist", 404); + } elseif (!$this->isAllowed($request)) { + if (!$auth->hasIdentity()) { + $request->setControllerName($this->_noauth['controller']); + $request->setActionName($this->_noauth['action']); + $request->setParam('message', 'nologin'); + + return $request; + } + + $error->type = self::EXCEPTION_NOTALLOWED; + if (!$error->exception) + $error->exception = new Zend_Controller_Dispatcher_Exception("No rights to access the resouce", 403); } elseif ($error->exception) { $error->type = self::EXCEPTION_OTHER; - } elseif ($request->getParam('error_message') != "") - { - $error->type = self::EXCEPTION_NOTALLOWED; - if (!$error->exception) - $error->exception = new Ostacium_Controller_Plugin_Router_Exception("No rights to access the resouce", 403); } if (isset($error->type)) { @@ -103,7 +120,7 @@ } } - public function isProperAction($dispatcher, $request) + public function isProperAction($dispatcher, Zend_Controller_Request_Abstract $request) { $className = $dispatcher->loadClass($dispatcher->getControllerClass($request)); $actionName = $request->getActionName(); @@ -121,4 +138,42 @@ return false; } + + public function existsResource($dispatcher, Zend_Controller_Request_Abstract $request) + { + $controller = $request->getControllerName(); + $action = $request->getActionName(); + $module = $request->getModuleName(); + $resource = ($module != 'default' ? $module . ':' . $controller : $controller); + + if (!$this->_acl->has($resource) || !$dispatcher->isDispatchable($request) || !$this->isProperAction($dispatcher, $request)) + { + return false; + } + + return true; + } + + public function isAllowed(Zend_Controller_Request_Abstract $request) + { + $auth = Zend_Auth::getInstance(); + $dispatcher = Zend_Controller_Front::getInstance()->getDispatcher(); + + if ($auth->hasIdentity()) { + $role = $this->_acl->getRoleById($auth->getIdentity()->roleid) ? $this->_acl->getRoleById($auth->getIdentity()->roleid) : 'guest'; + } else { + $role = 'guest'; + } + + $controller = $request->getControllerName(); + $action = $request->getActionName(); + $module = $request->getModuleName(); + $resource = ($module != 'default' ? $module . ':' . $controller : $controller); + + + if (!$this->_acl->isAllowed($role, $resource, $action)) + return false; + + return true; + } } \ No newline at end of file Modified: website/library/Ostacium/Controller/Router/Route/Language.php =================================================================== --- website/library/Ostacium/Controller/Router/Route/Language.php 2008-12-06 13:12:31 UTC (rev 434) +++ website/library/Ostacium/Controller/Router/Route/Language.php 2008-12-06 23:13:21 UTC (rev 435) @@ -4,17 +4,20 @@ { protected $translate; protected $config; + protected $extention; protected $_languageKey = 'language'; public function __construct(array $defaults = array(), Zend_Controller_Dispatcher_Interface $dispatcher = null, - Zend_Controller_Request_Abstract $request = null) + Zend_Controller_Request_Abstract $request = null, + $extention = null) { parent::__construct($defaults, $dispatcher, $request); $this->translate = Zend_Registry::get('Zend_Translate'); $this->config = Zend_Registry::get('config'); + $this->extention = $extention; } protected function _setRequestKeys() @@ -36,6 +39,13 @@ $values = array(); $params = array(); $path = trim($path, self::URI_DELIMITER); + + if ($this->extention) + { + $ext = strrchr($path, '.' . $this->extention); + if ($ext) $path = substr($path, 0, -strlen($ext)); + //else $path = ''; + } if ($path != '') { $path = explode(self::URI_DELIMITER, $path); @@ -133,6 +143,11 @@ if ($encode) $language = urlencode($language); $url = '/' . $language . $url; } + + if (!empty($url) && substr($url, 0, -1) != '/' && $this->extention) + { + $url .= '.' . $this->extention; + } return ltrim($url, self::URI_DELIMITER); } Modified: website/library/Ostacium/Db/Table.php =================================================================== --- website/library/Ostacium/Db/Table.php 2008-12-06 13:12:31 UTC (rev 434) +++ website/library/Ostacium/Db/Table.php 2008-12-06 23:13:21 UTC (rev 435) @@ -49,10 +49,26 @@ return $query->fetchColumn(); } + public function selectLang(array $cols = array()) + { + $translate = Zend_Registry::get('Zend_Translate'); + $_config = Zend_Registry::get('config'); + $columns = array(); + + foreach ($cols as $col) + { + $columns[] = 'IF (l.id, l.'.$col.', d.'.$col.') AS '.$col; + } + + return $this->select()->setIntegrityCheck(false)->from($this->_name, array('*', implode(', ', $columns))) + ->joinLeft(array('d' => $this->_name.'_lang'), 'd.id = '.$this->_name.'.id AND d.langcode = \''.$_config->lang->default.'\'', array()) + ->joinLeft(array('l' => $this->_name.'_lang'), 'l.id = '.$this->_name.'.id AND l.langcode = \''.$translate->getLocale().'\'', array()); + } + protected function _dataFilter(&$data) { if(empty($this->_cols)) { - $this->_setupMetadata(); + $this->_getCols(); } $data = array_intersect_key($data, array_flip($this->_cols)); Property changes on: website/other/submits ___________________________________________________________________ Added: tsvn:logminsize + 5 Modified: website/other/todo.txt =================================================================== --- website/other/todo.txt 2008-12-06 13:12:31 UTC (rev 434) +++ website/other/todo.txt 2008-12-06 23:13:21 UTC (rev 435) @@ -1,10 +1,10 @@ -1. Add Zend_Log, write - undecided, FILE? DB? ++/-1. Add Zend_Log, write - undecided, FILE? DB? 2. Design Change 3. Ostacium_CrudAction redesign 4. Ostacium_View_Helper_listTable redesign 5. Front_Controller => catch Exception => go to Error Controller 6. Caching for DB, VIEW, etc. -7. Table Prefix - відложено +-7. Table Prefix - відложено 8. Custom Admin Email 9. Add mb_ support to everything 10!. _authenticateCreateSelect - quote the reference! how? Property changes on: website/other/uploads ___________________________________________________________________ Added: tsvn:logminsize + 5 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |