| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * Karamelo e-Learning Platform |
|---|
| 4 | * Chipotle Software TM 2002-2008 |
|---|
| 5 | * GPLv3 |
|---|
| 6 | * @author Manuel Montoya manuel<arroba>mononeurona<punto>org |
|---|
| 7 | * @version 0.3 |
|---|
| 8 | * @package Karamelo |
|---|
| 9 | */ |
|---|
| 10 | //file: app_controller.php |
|---|
| 11 | |
|---|
| 12 | uses('L10n'); |
|---|
| 13 | |
|---|
| 14 | class AppController extends Controller { |
|---|
| 15 | |
|---|
| 16 | public $components = array('Auth', 'Cookie', 'Session'); // set Security component later |
|---|
| 17 | |
|---|
| 18 | public $helpers = array('Html', 'Form', 'Session'); |
|---|
| 19 | |
|---|
| 20 | public function beforeFilter() |
|---|
| 21 | { |
|---|
| 22 | //set locale (es or en by now) |
|---|
| 23 | $this->__setLocale(); |
|---|
| 24 | |
|---|
| 25 | // Auth configuratin |
|---|
| 26 | $this->Auth->fields = array('username' => 'email', 'password' => 'pwd'); |
|---|
| 27 | $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login'); |
|---|
| 28 | $this->Auth->loginRedirect = array('controller' => 'news', 'action' => 'display'); |
|---|
| 29 | $this->Auth->logoutRedirect = array('controller' => 'news', 'action' => 'display'); |
|---|
| 30 | $this->Auth->loginError = __('wrong_pass_or_email', true); |
|---|
| 31 | $this->Auth->authorize = 'controller'; |
|---|
| 32 | $this->Auth->deny('*'); |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | public function isAuthorized() |
|---|
| 36 | { |
|---|
| 37 | if (isset( $this->params[Configure::read('Routing.admin')] )): |
|---|
| 38 | if ($this->Auth->user('group_id') == 1 || $this->Auth->user('group_id') == 2 ): // admin and teachers |
|---|
| 39 | return true; |
|---|
| 40 | else: |
|---|
| 41 | return false; |
|---|
| 42 | endif; |
|---|
| 43 | endif; |
|---|
| 44 | |
|---|
| 45 | return true; |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | public function msgFlash($msg, $to) |
|---|
| 49 | { |
|---|
| 50 | $this->Session->setFlash($msg); // http://manual.cakephp.org/chapter/session |
|---|
| 51 | $this->redirect($to); |
|---|
| 52 | return true; |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | private function __setLocale() |
|---|
| 56 | { |
|---|
| 57 | $this->L10n = new L10n(); |
|---|
| 58 | /* $languages = array('es','en'); // 'nah' for nahuatl |
|---|
| 59 | $paramLang = strtok($_SERVER['HTTP_HOST'],'.'); |
|---|
| 60 | $lang = $this->Session->check('lang') ? $this->Session->read('lang'):'en'; |
|---|
| 61 | |
|---|
| 62 | if (isset($paramLang) && in_array($paramLang,$languages) ): |
|---|
| 63 | $lang = $paramLang; |
|---|
| 64 | $this->Session->write('lang',$lang); |
|---|
| 65 | else: |
|---|
| 66 | $this->Session->write('lang',$lang); |
|---|
| 67 | endif; */ |
|---|
| 68 | $lang = 'en'; |
|---|
| 69 | $this->L10n->get($lang); |
|---|
| 70 | Configure::write('Config.language', $lang); |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | protected function getSupport() |
|---|
| 74 | { |
|---|
| 75 | $this->flash(__('An error has been encountered, please ask Chipotle Software (www.chipotle-software.com) for support', true),'/',15); |
|---|
| 76 | } |
|---|
| 77 | } |
|---|
| 78 | ?> |
|---|