PHP User::allowed Examples

PHP User::allowed - 8 examples found. These are the top rated real world PHP examples of User::allowed extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
 /**
  * undocumented function
  *
  * @return void
  * @access public
  */
 function admin_index()
 {
     Assert::true(User::allowed($this->name, $this->action), '403');
     $defaults = array('model' => null, 'user_id' => null, 'my_limit' => 20, 'custom_limit' => false, 'start_date_day' => '01', 'start_date_year' => date('Y'), 'start_date_month' => '01', 'end_date_day' => '31', 'end_date_year' => date('Y'), 'end_date_month' => '12');
     $params = am($defaults, $this->params['url'], $this->params['named']);
     unset($params['ext']);
     unset($params['url']);
     if (is_numeric($params['custom_limit'])) {
         if ($params['custom_limit'] > 75) {
             $params['custom_limit'] = 75;
         }
         if ($params['custom_limit'] == 0) {
             $params['custom_limit'] = 50;
         }
         $params['my_limit'] = $params['custom_limit'];
     }
     $conditions = array();
     if (!empty($params['model'])) {
         $conditions['Log.model'] = $params['model'];
     }
     if (!empty($params['user_id'])) {
         $conditions['Log.user_id'] = $params['user_id'];
     }
     $conditions = $this->Log->dateRange($conditions, $params, 'created');
     $this->Session->write('logs_filter_conditions', $conditions);
     $userOptions = ClassRegistry::init('User')->find('list', array('conditions' => array('User.office_id' => $this->Session->read('Office.id'))));
     $this->paginate['Log'] = array('conditions' => $conditions, 'contain' => array('User', 'Gift', 'Transaction'), 'limit' => $params['my_limit'], 'order' => array('Log.continuous_id' => 'desc'));
     $logs = $this->paginate($this->Log);
     $this->set(compact('logs', 'params', 'userOptions'));
 }
Example #2
0
 /**
  * This function logs an activity of a given $activityType together with an array of $data related to it
  *
  * @param mixed $activityTypeId Either the numeric foreign key value for the activity_type or a string to look it up / create
  * @param array $data An array of data that will be serialized for later reference
  * @param $repeatWithin Either false or a timestamp in the past / array of conditions for this to qualify as a repeated activity
  * @return boolean True on success
  * @access public
  */
 function get($navGroup = null)
 {
     $Session = Common::getComponent('Session');
     $navigations = array('Guests' => array(), 'Admin' => array(__('Home', true) => array('/admin/home', '#/^\\/admin(\\/statistics|\\/home).*$/iU'), __('Appeals', true) => array('/admin/appeals/index', '#/^\\/admin\\/appeals.*$/iU'), __('Templates', true) => array('/admin/templates', '#/^\\/admin\\/templates.*$/iU'), __('Gifts', true) => array('/admin/gifts/index/all', '#/\\/admin(\\/gifts|\\/exports\\/gifts).*/iU'), __('Transactions', true) => array('/admin/transactions/index/all', '#/\\/admin\\/transactions.*/iU'), __('Supporters', true) => array('/admin/supporters', '#/\\/admin\\/supporters.*/iU'), __('Office Config', true) => array('/admin/offices/edit', '#/\\/admin\\/offices(\\/edit|\\/view).*/iU', '#/\\/admin\\/(offices|users).*/iU', 'role' => 'office_manager'), __('Help', true) => array('/admin/help', '#/\\/admin\\/help.*/iU')), 'appeal_sub' => array(__('All', true) => array('/admin/appeals/index', '#/^\\/admin\\/appeals\\/index.*$/iU')), 'template_sub' => array(__('All', true) => array('/admin/appeals/index', '#/^\\/admin\\/templates.*$/iU')), 'gift_sub' => array(__('All', true) => array('/admin/gifts/index/all', '#/^\\/admin\\/gifts\\/index\\/all.*$/iU'), __('Onetime', true) => array('/admin/gifts/index/onetime', '#/^\\/admin\\/gifts\\/index\\/onetime.*$/iU'), __('Recurring', true) => array('/admin/gifts/index/recurring', '#/^\\/admin\\/gifts\\/index\\/recurring.*$/iU'), __('Favorites', true) => array('/admin/gifts/index/favorites', '#/^\\/admin\\/gifts\\/index\\/favorites.*$/iU'), __('Archived', true) => array('/admin/gifts/index/archived', '#/^\\/admin\\/gifts\\/index\\/archived.*$/iU'), __('Statistics', true) => array('/admin/gifts/stats', '#/^\\/admin\\/gifts\\/stats.*$/iU')), 'transaction_sub' => array(__('All', true) => array('/admin/transactions/index/all', '#/^\\/admin\\/transactions\\/index\\/all.*$/iU'), __('Favorites', true) => array('/admin/transactions/index/favorites', '#/^\\/admin\\/gifts\\/transactions\\/index\\/favorites.*$/iU'), __('Archived', true) => array('/admin/transactions/index/archived', '#/^\\/admin\\/gifts\\/transactions\\/index\\/archived.*$/iU')), 'user_sub' => array(__('All', true) => array('/admin/users/index/all', '#/^\\/admin\\/users\\/index\\/all.*$/iU'), __('My Office Colleagues', true) => array('/admin/users/index/colleagues', '#/^\\/admin\\/users\\/index\\/colleagues.*$/iU')), 'supporter_sub' => array(__('All', true) => array('/admin/supporters', '#/^\\/admin\\/supporters$/iU'), __('One-off', true) => array('/admin/supporters/index/oneoff', '#/^\\/admin\\/supporters\\/index\\/oneoff.*$/iU'), __('Recurring', true) => array('/admin/supporters/index/recurring', '#/^\\/admin\\/supporters\\/index\\/recurring.*$/iU'), __('Favorites', true) => array('/admin/supporters/index/favorites', '#/^\\/admin\\/supporters\\/favorites.*$/iU'), __('Signups', true) => array('/admin/supporters/index/signups', '#/^\\/admin\\/supporters\\/signups.*$/iU')), 'user_preferences' => array(__('Preferences', true) => array('/admin/users/preferences', '#/^\\/admin\\/users\\/preferences.*$/iU'), __('Edit Password', true) => array('/admin/users/edit_password', '#/^\\/admin\\/users\\/edit_password.*$/iU'), __('Public Key', true) => array('/admin/users/public_key', '#/^\\/admin\\/users\\/public_key.*$/iU'), __('Email Reports', true) => array('/admin/users/email_reports', '#/^\\/admin\\/users\\/email_reports.*$/iU', 'condition' => User::allowed('Users', 'admin_email_reports'))), 'admin_auth_sub' => array(__('Login', true) => array('/admin/auth/login', '#/^\\/admin\\/(auth\\/|)login.*$/iU'), __('Lost Password', true) => array('/admin/users/forgot_pw', '#/^\\/admin\\/users\\/forgot_pw.*$/iU')), 'admin_config_sub' => array(__('Config', true) => array('/admin/offices/edit/', '#/\\/admin\\/offices(\\/edit|\\/view)\\/.*/iU', 'role' => array('office_manager')), __('Team & Permissions', true) => array('/admin/users', '#/\\/admin\\/users\\/(index\\/[^unactivated]|view).*/iU', 'role' => array('office_manager')), __('Unactivated Users', true) => array('/admin/users/index/unactivated', '#/\\/admin\\/users\\/index\\/unactivated.*/iU', 'role' => array('office_manager'))), 'admin_help_sub' => array(__('Getting started', true) => array('/admin/help', '#/\\/admin\\/help(\\/start)/'), __('Faq', true) => array('/admin/help/faq', '#/\\/admin\\/help\\/faq\\/.*/iU')), 'admin_root_admin_sub' => array(__('Dashboard', true) => array('/admin/dashboards', '#/\\/admin\\/dashboards.*/iU'), __('Offices', true) => array('/admin/offices', '#/\\/admin\\/offices.*/iU', 'role' => 'root'), __('Users', true) => array('/admin/users', '#/\\/admin\\/users.*/iU', 'role' => 'root'), __('Roles', true) => array('/admin/roles', '#/\\/admin\\/roles.*/iU', 'role' => 'root'), __('Activity Log', true) => array('/admin/logs', '#/\\/admin\\/logs.*/iU', 'role' => 'root'), __('Smileys', true) => array('/admin/smileys', '#/\\/admin\\/smileys.*/iU', 'role' => 'root')));
     if (!empty($navGroup) && isset($navigations[$navGroup])) {
         return $navigations[$navGroup];
     }
     $navigation = $navigations['Guests'];
     if (class_exists('User') && !User::is('guest')) {
         $navigation = $navigations['Admin'];
     }
     return $navigation;
 }
Example #3
0
 /**
  * undocumented function
  *
  * @param string $model 
  * @param string $contain 
  * @return void
  * @access public
  */
 function _process($model, $contain = array())
 {
     Assert::true(User::allowed($this->name, $this->action), '403');
     Assert::true($this->isPost() || $this->Session->read($this->sessKeyModel) == $model, '404');
     if (isset($this->data[$model]) && !isset($this->data[$model]['process'])) {
         $this->saveModel($model);
         return $this->saveSelection($model);
     }
     $plural = low(Inflector::pluralize($model));
     $conditions = $this->Session->read($plural . '_filter_conditions');
     $selection = $this->loadSelection();
     if (!empty($selection)) {
         $conditions[$model . '.id'] = $selection;
     }
     // remove gift id from csv fields, although cake fetched it to do joins
     $addedGiftId = false;
     if (!in_array($model . '.id', (array) $this->data[$model]['fields'])) {
         $addedGiftId = true;
         $this->data[$model]['fields'][] = $model . '.id';
     }
     $items = $this->{$model}->find('all', array('conditions' => $conditions, 'contain' => $contain, 'fields' => am($this->data[$model]['fields'], array('Currency.iso_code'))));
     // remove the gift id from fields list now if needed
     if ($addedGiftId) {
         $key = array_search($model . '.id', $this->data[$model]['fields']);
         unset($this->data[$model]['fields'][$key]);
     }
     if ($this->data[$model]['softdelete']) {
         $this->{$model}->softdelete($items);
     }
     $items = $this->filterFields($model, $items, $contain);
     foreach ($items as $i => $item) {
         $items[$i][$model]['amount'] .= ' ' . $items[$i]['Currency']['iso_code'];
         unset($items[$i]['Currency']);
     }
     if (isset($this->data[$model]['download']) && $this->data[$model]['download']) {
         $name = $plural . '_export_' . date('Y_m_d_H_i');
         $path = '/admin/exports/' . $plural . '.' . $this->data[$model]['format'];
         $this->ForceDownload->forceDownload($path, $name);
     }
     $Export = ClassRegistry::init('Export');
     $Export->create(array('user_id' => User::get('id'), 'nb_exported' => count($items), 'model' => $model));
     $Export->save();
     $this->set(compact('items'));
     $this->RequestHandler->renderAs($this, $this->data[$model]['format']);
 }
 /**
  * undocumented function
  *
  * @return void
  * @access public
  */
 function admin_index($type = 'all')
 {
     Assert::true(User::allowed($this->name, 'admin_view'), '403');
     $giftConditions = array('Gift.office_id' => $this->Session->read('Office.id'));
     $onetime = $this->Frequency->lookup('onetime', 'id', false);
     switch ($type) {
         case 'signups':
             // doesn't have gift
             break;
         case 'oneoff':
             $giftConditions['Gift.frequency_id'] = $onetime;
             break;
         case 'recurring':
             $giftConditions['Gift.frequency_id <>'] = $onetime;
             $myParams = array('start_date_day' => '01', 'start_date_month' => date('m', strtotime('-1 month')), 'start_date_year' => date('Y', strtotime('-1 month')), 'end_date_day' => date('d'), 'end_date_month' => date('m'), 'end_date_year' => date('Y'));
             $giftConditions = $this->Gift->dateRange($giftConditions, $myParams, 'created');
             break;
         case 'favorites':
         case 'starred':
             $conditions['Contact.id'] = $this->Session->read('favorites');
             break;
     }
     if (!empty($giftConditions)) {
         $gifts = $this->Gift->find('all', array('conditions' => $giftConditions, 'contain' => false, 'fields' => array('contact_id')));
         $ids = Set::extract('/Gift/contact_id', $gifts);
         if (isset($conditions['Contact.id'])) {
             $conditions['Contact.id'] = array_intersect($conditions['Contact.id'], $ids);
         } else {
             $conditions['Contact.id'] = $ids;
         }
     }
     $params = $this->_parseGridParams();
     $conditions = $this->_conditions($params, $conditions);
     $this->Session->write('gifts_filter_conditions', $conditions);
     $this->paginate['Contact'] = array('conditions' => $conditions, 'recursive' => 4, 'contain' => array('Address.City', 'Address.Country', 'Address.Phone'), 'limit' => $params['my_limit'], 'order' => array("CONCAT(Contact.fname,' ',Contact.lname)" => 'asc'));
     $supporters = $this->paginate('Contact');
     $this->set(compact('supporters', 'type', 'params'));
 }
 /**
  * delete action
  *
  * @param string $id the transaction id
  * @return void
  * @access public
  */
 function admin_delete($id = null)
 {
     $transaction = $this->Transaction->find('first', array('conditions' => array('Transaction.id' => $id), 'contain' => array('Gift')));
     Assert::notEmpty($transaction, '404');
     Assert::true(User::allowed($this->name, $this->action, $transaction), '403');
     $this->Transaction->set(array('id' => $id, 'archived' => '1'));
     $this->Transaction->save();
     $msg = __('The Transaction has been deleted.', true);
     $this->Message->add($msg, 'ok', true, array('action' => 'admin_index'));
 }
Example #6
0
 /**
  * undocumented function
  *
  * @param string $id 
  * @return void
  * @access public
  */
 function admin_view($id = null)
 {
     $gift = $this->Gift->find('first', array('conditions' => array('Gift.id' => $id), 'contain' => array('Contact.Address.Phone', 'Contact.Address.Country(id, name)', 'Contact.Address.State(id, name)', 'Contact.Address.City(id, name)', 'GiftType(humanized)', 'Office(id, name)', 'Appeal', 'Frequency', 'Currency(iso_code)')));
     Assert::notEmpty($gift, '404');
     Assert::true(User::allowed($this->name, $this->action, $gift), '403');
     $this->paginate['Transaction'] = array('conditions' => array('Transaction.gift_id' => $id), 'contain' => array('Gateway(name)', 'Currency(iso_code)'), 'order' => array('Transaction.created' => 'asc'));
     $transactions = $this->paginate('Transaction');
     $this->Gift = ClassRegistry::init('Gift');
     $commentMethod = $this->Gift->hasMany['Comment']['threaded'] ? 'threaded' : 'all';
     $comments = $this->Gift->Comment->find($commentMethod, array('conditions' => array('Comment.foreign_id' => $id), 'contain' => array('User(login, id)')));
     $this->set(compact('gift', 'comments', 'commentMethod', 'transactions'));
 }
Example #7
0
 /**
  * undocumented function
  *
  * @param string $id 
  * @return void
  * @access public
  */
 function admin_edit($id = null)
 {
     $action = 'add';
     if ($this->action == 'admin_edit') {
         if (!User::is('root')) {
             $id = $this->Session->read('Office.id');
         }
         $office = $this->Office->find('first', array('conditions' => array('Office.id' => $id), 'contain' => array('GatewaysOffice(gateway_id)', 'FrequenciesOffice(frequency_id)', 'LanguagesOffice(language_id)', 'CurrenciesOffice(currency_id)')));
         Assert::notEmpty($office, '404');
         Assert::true(User::allowed($this->name, $this->action, $office));
         $action = 'edit';
     } else {
         $office = $this->Office->create();
     }
     $frequencyOptions = $this->Frequency->find('list', array('fields' => array('id', 'humanized')));
     $languageOptions = $this->Language->find('list', array('fields' => array('id', 'code')));
     $currencyOptions = $this->Currency->find('list', array('fields' => array('id', 'iso_code')));
     $gatewayOptions = $this->Gateway->find('list');
     $this->set(compact('action', 'office', 'gatewayOptions', 'frequencyOptions', 'languageOptions', 'currencyOptions'));
     $this->action = 'admin_edit';
     if ($this->isGet()) {
         return $this->data = $office;
     }
     if ($action == 'add') {
         $this->data['Office']['user_id'] = User::get('id');
     }
     $this->Office->set($this->data);
     if (!$this->Office->save()) {
         return $this->Message->add(__('Please fill out all fields', true), 'error');
     }
     $msg = __('Office was saved successfully.', true);
     $url = User::allowed('Offices', 'admin_index') ? array('action' => 'index') : $this->referer();
     $this->Message->add($msg, 'ok', true, $url);
 }
 /**
  * Admin delete an template action
  *
  * @param string $id the template id
  * @return void
  * @access public
  */
 function admin_delete($id = null, $undelete = false)
 {
     $template = $this->Template->find('first', array('conditions' => compact('id')));
     Assert::notEmpty($template, '404');
     Assert::true(User::allowed($this->name, $this->action, $template), '403');
     $this->Template->del($id);
     $msg = __('The Template has been deleted.', true);
     $this->Message->add($msg, 'ok', true, array('action' => 'admin_index'));
 }