function beforeFilter() { $this->Auth->loginRedirect = '/'; // for the authorizations $this->Auth->authorize = 'actions'; $this->Auth->actionPath = 'controllers/'; // if the user is not logged and it requests the root '/' url // redirects to '/login' if (!$this->Session->read('Auth.User.id')) { if ($this->params['url']['url'] == '/') { $this->redirect('/login'); } } App::import('Model', 'User'); if ($this->Session->read('Auth.User.id')) { if ($this->params['url']['url'] == '/') { $user = new User(); $user = $user->read(null, $this->Session->read('Auth.User.id')); $this->redirect($user['UserGroup']['home_url']); } } if ($this->layout == 'default' && $this->Session->read('Auth.User.id')) { // creating an array with all the permissions for this user // and in the view we check if it has permissions to show the link // getting all the acos with permissions App::import('Model', 'Aco'); App::import('Model', 'Aro'); App::import('Model', 'ArosAco'); $aco = new Aco(); $aro = new Aro(); $aros_aco = new ArosAco(); $acos = $aco->find('threaded', array('recursive' => 0)); // consulta el id del aro $aro_row = $aro->find('first', array('conditions' => array('model' => 'UserGroup', 'foreign_key' => $this->Session->read('Auth.User.user_group_id')))); // consulta la relacion de aros_acos $aros_acos = $aros_aco->find('all', array('conditions' => array('aro_id' => $aro_row['Aro']['id']))); $this->set('acl_lists', $this->AclGetList->get($this->Session->read('Auth.User.user_group_id'), $acos, $aros_acos)); } // rendering the menu for "default" layout // checking if there is a logged user if ($this->layout == 'default' && $this->Session->read('Auth.User.id')) { // renders the menu according the user group App::import('Model', 'Menu'); $menu = new Menu(); $this->set('layout_menus', $menu->find_for_show($this->Session->read('Auth.User.user_group_id'))); // selecting the current menu $this->set('layout_current', $this->params['url']['url']); //$route = Router::parse('/'.$this->params['url']['url']); //$aco_alias = 'controllers/'.$route['controller'].'/'.$route['action']; //$this->set('layout_acos', $this->Acl->Aco->node('controllers/'.$route['controller'].'/'.$route['action'])); // asks the controller for selecting the correct link in the menu $cont = split('_', $this->params['controller']); $newcont = ''; foreach ($cont as $c) { $newcont .= ucfirst($c); } $current_aco = $this->Acl->Aco->node('controllers/' . $newcont . '/' . $this->params['action']); $this->set('layout_aco_id', $current_aco[0]['Aco']['id']); //$route = Router::parse('/profile'); //$this->set('menu_url', '/'.$this->params['controller'].'/'.$this->params['action']); if ($this->Session->read('Auth.User.type') == 'web') { $user = new User(); $user->id = $this->Session->read('Auth.User.id'); $user->updatecredit_expiration(); $this->set('user_balance', $user->getBalance()); $this->set('user_expirationdate', $user->getExpirationDate()); } } }
function getexpirationdate($id = null) { $this->layout = "ajax"; // ajax method if ($this->Session->read('Auth.User.type') == 'web') { $id = $this->Session->read('Auth.User.id'); } if (!$id) { $this->redirect('/'); } $user = new User(); $user->read(null, $id); $this->set('expiration', $user->getExpirationDate()); }