Example #1
0
 /**
  * Save the permission
  * @param $id
  */
 public static function SaveAll($data, $id = null)
 {
     if (!empty($data) && is_array($data)) {
         if (is_numeric($id)) {
             $role = Doctrine::getTable('AdminRoles')->find($id);
         } else {
             $role = new AdminRoles();
         }
         // Save the role label
         if (!empty($data['name'])) {
             $role['name'] = Shineisp_Commons_UrlRewrites::format($data['name']);
             $role->save();
         }
         // Set the new Role ID to the users selected
         if (!empty($data['users'])) {
             foreach ($data['users'] as $user) {
                 AdminUser::setUserRoleID($user, $id);
             }
         }
         // Clear old permissions
         AdminPermissions::clearPermissionByRoleID($id);
         if (!empty($data['resources'])) {
             // Explode the string into an array
             $resources = explode("/", $data['resources']);
             // Add the new permissions
             foreach ($resources as $resource) {
                 list($module, $controller) = explode(':', $resource);
                 AdminPermissions::addPermission($id, $module, $controller);
             }
         }
         return $role;
     }
     return false;
 }
Example #2
0
 public function init()
 {
     $registry = Shineisp_Registry::getInstance();
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $logged_user = $auth->getIdentity();
     }
     // Set the custom decorator
     $this->addElementPrefixPath('Shineisp_Decorator', 'Shineisp/Decorator/', 'decorator');
     $translate = Shineisp_Registry::get('Zend_Translate');
     $this->addElement('text', 'firstname', array('filters' => array('StringTrim'), 'required' => true, 'label' => $translate->_('Firstname'), 'decorators' => array('Bootstrap'), 'class' => 'form-control'));
     $this->addElement('text', 'lastname', array('filters' => array('StringTrim'), 'required' => true, 'label' => $translate->_('Lastname'), 'decorators' => array('Bootstrap'), 'class' => 'form-control'));
     // Check if the user is an administrator, if not the select role object will become an hidden field
     if (AdminRoles::isAdministrator($logged_user['user_id'])) {
         $this->addElement('select', 'role_id', array('required' => true, 'label' => $translate->_('Role'), 'decorators' => array('Bootstrap'), 'class' => 'form-control'));
         $this->getElement('role_id')->setAllowEmpty(false)->setRegisterInArrayValidator(false)->setMultiOptions(AdminRoles::getList());
         $this->addElement('select', 'isp_id', array('required' => true, 'label' => $translate->_('Isp Company'), 'decorators' => array('Bootstrap'), 'class' => 'form-control'));
         $this->getElement('isp_id')->setAllowEmpty(false)->setRegisterInArrayValidator(false)->setMultiOptions(Isp::getList());
     } else {
         $this->addElement('hidden', 'role_id');
         $this->addElement('hidden', 'isp_id');
     }
     $this->addElement('text', 'email', array('filters' => array('StringTrim', 'StringToLower'), 'decorators' => array('Bootstrap'), 'validators' => array(array('validator' => 'EmailAddress')), 'required' => true, 'label' => $translate->_('Email'), 'class' => 'form-control'));
     $this->addElement('password', 'password', array('filters' => array('StringTrim'), 'decorators' => array('Bootstrap'), 'validators' => array(array('regex', false, '/^[a-zA-Z0-9\\-\\_\\.\\%\\!\\$]{6,20}$/')), 'label' => $translate->_('Password'), 'class' => 'form-control'));
     $this->addElement('hidden', 'user_id');
 }
Example #3
0
 /**
  * Check all the resources and roles
  */
 protected function roleResource()
 {
     self::initResources();
     $acl = AdminRoles::getAll();
     foreach ($acl as $data) {
         foreach ($data['AdminPermissions'] as $permission) {
             $theresource = $permission['AdminResources']['module'] . ":" . $permission['AdminResources']['controller'];
             // 				echo "> " . $permission['permission'] . " " . $data['name'] . " access for the $theresource resource <br/>";
             $this->allow($data['name'], $theresource, $permission['permission']);
         }
     }
 }
Example #4
0
 /**
  * grid
  * create the configuration of the grid
  */
 public static function grid($rowNum = 10)
 {
     $translator = Shineisp_Registry::getInstance()->Zend_Translate;
     $config['datagrid']['columns'][] = array('label' => $translator->translate('Module'), 'field' => 'r.module', 'alias' => 'mymodule', 'sortable' => true, 'searchable' => true, 'type' => 'string');
     $config['datagrid']['columns'][] = array('label' => $translator->translate('Controller'), 'field' => 'r.controller', 'alias' => 'mycontroller', 'sortable' => true, 'searchable' => true, 'type' => 'string');
     $config['datagrid']['columns'][] = array('label' => $translator->translate('Resource'), 'field' => 'r.resource_id', 'alias' => 'resource', 'sortable' => true, 'searchable' => true, 'type' => 'string');
     $config['datagrid']['columns'][] = array('label' => $translator->translate('Role'), 'field' => 'ro.role_id', 'alias' => 'role', 'sortable' => true, 'type' => 'index', 'searchable' => true, 'filterdata' => AdminRoles::getList());
     $config['datagrid']['columns'][] = array('label' => $translator->translate('Permission'), 'field' => 'p.permission', 'alias' => 'permission', 'sortable' => true, 'type' => 'index', 'searchable' => true, 'filterdata' => array('deny' => 'Deny', 'allow' => 'Allow'));
     $config['datagrid']['fields'] = "permission_id, r.resource_id, p.permission as permission, ro.role_id, r.module as mymodule, r.controller as mycontroller, ro.name as role, r.name as resource";
     $config['datagrid']['dqrecordset'] = Doctrine_Query::create()->select($config['datagrid']['fields'])->from('AdminPermissions p')->leftJoin('p.AdminResources r')->leftJoin('p.AdminRoles ro');
     $config['datagrid']['rownum'] = $rowNum;
     $config['datagrid']['basepath'] = "/admin/permissions/";
     $config['datagrid']['index'] = "permission_id";
     $config['datagrid']['rowlist'] = array('10', '50', '100', '1000');
     $config['datagrid']['buttons']['edit']['label'] = $translator->translate('Edit');
     $config['datagrid']['buttons']['edit']['cssicon'] = "edit";
     $config['datagrid']['buttons']['edit']['action'] = "/admin/permissions/edit/id/%d";
     $config['datagrid']['buttons']['delete']['label'] = $translator->translate('Delete');
     $config['datagrid']['buttons']['delete']['cssicon'] = "delete";
     $config['datagrid']['buttons']['delete']['action'] = "/admin/permissions/delete/id/%d";
     return $config;
 }
Example #5
0
 /**
  * processAction
  * Update the record previously selected
  * @return unknown_type
  */
 public function processAction()
 {
     $request = $this->getRequest();
     $user_id = $request->getParam('user_id');
     $adminbuttons = array();
     // Get our form and validate it
     $form = $this->getForm('/admin/profile/process');
     // Create the buttons in the edit form
     if (AdminRoles::isAdministrator($this->logged_user['user_id'])) {
         $this->view->buttons = array(array("url" => "#", "label" => $this->translator->translate('Save'), "params" => array('css' => null, 'id' => 'submit')), array("url" => "/admin/profile/list", "label" => $this->translator->translate('List'), "params" => array('css' => null, 'id' => 'submit')));
     } else {
         $this->view->buttons = array(array("url" => "#", "label" => $this->translator->translate('Save'), "params" => array('css' => null, 'id' => 'submit')));
     }
     // Check if the email already exists only when a new record is created
     if (empty($user_id)) {
         $form->getElement('email')->addValidator(new Shineisp_Validate_NoRecordExists('AdminUser', 'email'), true);
     }
     // Check if we have a POST request
     if (!$request->isPost()) {
         return $this->_helper->redirector('index');
     }
     if (!$form->isValid($request->getPost())) {
         // Invalid entries
         $this->view->form = $form;
         $this->view->title = $this->translator->translate("User Account");
         $this->view->description = $this->translator->translate("Some information must be checked again before saving them.");
         return $this->render('applicantform');
         // re-render the login form
     }
     // Save the data
     AdminUser::saveAll($request->getPost(), $request->getParam('user_id'));
     // Redirection
     if (AdminRoles::isAdministrator($this->logged_user['user_id'])) {
         return $this->_helper->redirector('list', 'profile', 'admin');
     } else {
         return $this->_helper->redirector('account', 'profile', 'admin');
     }
 }
Example #6
0
 /**
  * processAction
  * Update the record previously selected
  * @return unknown_type
  */
 public function processAction()
 {
     $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
     $form = $this->getForm("/admin/roles/process");
     $request = $this->getRequest();
     // Create the buttons in the edit form
     $this->view->buttons = array(array("url" => "#", "label" => $this->translator->translate('Save'), "params" => array('css' => null, 'id' => 'submit')), array("url" => "/admin/roles/list", "label" => $this->translator->translate('List'), "params" => array('css' => null)), array("url" => "/admin/roles/new/", "label" => $this->translator->translate('New'), "params" => array('css' => null)));
     // Check if we have a POST request
     if (!$request->isPost()) {
         return $this->_helper->redirector('list', 'roles', 'admin');
     }
     if ($form->isValid($request->getPost())) {
         $params = $request->getPost();
         $role = AdminRoles::SaveAll($params, $params['role_id']);
         if ($role) {
             $this->_helper->redirector('edit', 'roles', 'admin', array('id' => (string) $role->role_id, 'mex' => $this->translator->translate("The task requested has been executed successfully."), 'status' => 'success'));
         } else {
             $this->_helper->redirector('list', 'roles', 'admin', array('mex' => $this->translator->translate("There was an error saving the data. Please try again."), 'status' => 'danger'));
         }
     } else {
         $this->view->form = $form;
         $this->view->title = "Role edit";
         $this->view->description = "Here you can edit the role data.";
         return $this->render('applicantform');
     }
 }