public function __construct()
 {
     /*
      * fetch all roles
      */
     $table = new Wbroles();
     $roles = $table->fetchAllRoles();
     unset($table);
     // Loop roles and put them in an assoc array by ID
     $roleArray = array();
     foreach ($roles as $r) {
         $role = new Zend_Acl_Role($r['name']);
         // If inherit_name isn't null, have the role inherit from that, otherwise no inheriting
         if ($r['inherit_name'] !== null && $r['inherit_name'] !== $r['name']) {
             $this->addRole($role, $r['inherit_name']);
         } else {
             $this->addRole($role);
         }
         $roleArray[$r['id']] = $role;
     }
     /*
      *  fetch all resources
      *  because the Resource must be unique identifier
      */
     $table = new Wbresources();
     $resources = $table->fetchAllResources();
     foreach ($resources as $r) {
         $resource = new Zend_Acl_Resource($r['name']);
         $this->addResource($resource);
     }
     /*
      * establish a correspondence: roles => resources
      */
     $resources_roles = $table->fetchAllResourcesAndRoles();
     foreach ($resources_roles as $r) {
         if ($r['role_id'] !== null) {
             $role = $roleArray[$r['role_id']];
             // the Resource must be unique identifier
             $this->allow($role, $r['resource_name']);
         }
     }
     // Администратор не наследует ни от кого, но обладает всеми привилегиями
     $this->allow('root_role');
 }
Esempio n. 2
0
 public function roleMainFormAction()
 {
     $role_id = $this->_request->getParam('role_id');
     if (empty($role_id)) {
         throw new Exception(__METHOD__ . ' : Empty $role_id parameter');
     }
     /**********************************
      * Role form
      **********************************/
     // get Role name, inherited id
     $table = new Wbroles();
     $role = $table->fetchRow($table->getAdapter()->quoteInto('id = ?', $role_id));
     unset($table);
     // form
     $form_role = new FormRole(null, $role_id);
     // fill form
     $form_role->populate(array('acl' => 'role', 'role_id' => $role_id, 'role_name' => $role->name, 'description' => $role->description, 'order' => $role->order_role, 'inherit_id' => $role->inherit_id));
     $form_role->setAction($this->view->baseUrl . '/admin/role-update');
     $this->view->form_role = $form_role;
     /**********************************
      * Webacula ACL form
      **********************************/
     $form_webacula = new FormWebaculaACL();
     // get resources
     $table = new Wbresources();
     $wbresources = $table->fetchAll($table->getAdapter()->quoteInto('role_id = ?', $role_id), 'id');
     unset($table);
     $webacula_resources = null;
     foreach ($wbresources as $v) {
         $webacula_resources[] = $v->dt_id;
     }
     // fill form
     $form_webacula->populate(array('acl' => 'webacula', 'role_id' => $role_id, 'role_name' => $role->name));
     if (isset($webacula_resources)) {
         $form_webacula->populate(array('webacula_resources' => $webacula_resources, 'role_id' => $role_id));
     }
     $form_webacula->setAction($this->view->baseUrl . '/admin/webacula-update');
     $this->view->form_webacula = $form_webacula;
     /**********************************
      * Command ACL form
      **********************************/
     $form_commands = new FormBaculaCommandACL();
     // get resources
     $table = new WbCommandACL();
     $wbcommands = $table->fetchAll($table->getAdapter()->quoteInto('role_id = ?', $role_id), 'id');
     unset($table);
     $bacula_commands = null;
     foreach ($wbcommands as $v) {
         $bacula_commands[] = $v->dt_id;
     }
     // fill form
     $form_commands->populate(array('acl' => 'command', 'role_id' => $role_id, 'role_name' => $role->name));
     if (isset($bacula_commands)) {
         $form_commands->populate(array('bacula_commands' => $bacula_commands, 'role_id' => $role_id));
     }
     $form_commands->setAction($this->view->baseUrl . '/admin/commands-update');
     $this->view->form_commands = $form_commands;
     /**********************************
      * Client ACL form
      **********************************/
     $table = new WbClientACL();
     $this->view->rows_client = $table->fetchAll($table->getAdapter()->quoteInto('role_id = ?', $role_id), 'order_acl');
     unset($table);
     // form
     $form_client = new FormBaculaACL();
     // fill form
     $form_client->populate(array('acl' => 'client', 'role_id' => $role_id, 'role_name' => $role->name));
     $form_client->setAction($this->view->baseUrl . '/admin/client-add');
     $this->view->form_client = $form_client;
     // Fill data from Bacula database
     $this->view->form_bacula_fill_client = new FormBaculaFill('Client', 'webacula_client_acl', $role_id, $role->name);
     $this->view->form_bacula_fill_client->setAction($this->view->baseUrl . '/admin/fill/acl/client');
     /**********************************
      * Fileset ACL form
      **********************************/
     $table = new WbFilesetACL();
     $this->view->rows_fileset = $table->fetchAll($table->getAdapter()->quoteInto('role_id = ?', $role_id), 'order_acl');
     unset($table);
     // form
     $form_fileset = new FormBaculaACL();
     // fill form
     $form_fileset->populate(array('acl' => 'fileset', 'role_id' => $role_id, 'role_name' => $role->name));
     $form_fileset->setAction($this->view->baseUrl . '/admin/fileset-add');
     $this->view->form_fileset = $form_fileset;
     // Fill data from Bacula database
     $this->view->form_bacula_fill_fileset = new FormBaculaFill('FileSet', 'webacula_fileset_acl', $role_id, $role->name);
     $this->view->form_bacula_fill_fileset->setAction($this->view->baseUrl . '/admin/fill/acl/fileset');
     /**********************************
      * Job ACL form
      **********************************/
     $table = new WbJobACL();
     $this->view->rows_job = $table->fetchAll($table->getAdapter()->quoteInto('role_id = ?', $role_id), 'order_acl');
     unset($table);
     // form
     $form_job = new FormBaculaACL();
     // fill form
     $form_job->populate(array('acl' => 'job', 'role_id' => $role_id, 'role_name' => $role->name));
     $form_job->setAction($this->view->baseUrl . '/admin/job-add');
     $this->view->form_job = $form_job;
     // Fill data from Bacula database
     $this->view->form_bacula_fill_job = new FormBaculaFill('Job', 'webacula_job_acl', $role_id, $role->name);
     $this->view->form_bacula_fill_job->setAction($this->view->baseUrl . '/admin/fill/acl/job');
     /**********************************
      * Pool ACL form
      **********************************/
     $table = new WbPoolACL();
     $this->view->rows_pool = $table->fetchAll($table->getAdapter()->quoteInto('role_id = ?', $role_id), 'order_acl');
     unset($table);
     // form
     $form_pool = new FormBaculaACL();
     // fill form
     $form_pool->populate(array('acl' => 'pool', 'role_id' => $role_id, 'role_name' => $role->name));
     $form_pool->setAction($this->view->baseUrl . '/admin/pool-add');
     $this->view->form_pool = $form_pool;
     // Fill data from Bacula database
     $this->view->form_bacula_fill_pool = new FormBaculaFill('Pool', 'webacula_pool_acl', $role_id, $role->name);
     $this->view->form_bacula_fill_pool->setAction($this->view->baseUrl . '/admin/fill/acl/pool');
     /**********************************
      * Storage ACL form
      **********************************/
     $table = new WbStorageACL();
     $this->view->rows_storage = $table->fetchAll($table->getAdapter()->quoteInto('role_id = ?', $role_id), 'order_acl');
     unset($table);
     // form
     $form_storage = new FormBaculaACL();
     // fill form
     $form_storage->populate(array('acl' => 'storage', 'role_id' => $role_id, 'role_name' => $role->name));
     $form_storage->setAction($this->view->baseUrl . '/admin/storage-add');
     $this->view->form_storage = $form_storage;
     // Fill data from Bacula database
     $this->view->form_bacula_fill_storage = new FormBaculaFill('Storage', 'webacula_storage_acl', $role_id, $role->name);
     $this->view->form_bacula_fill_storage->setAction($this->view->baseUrl . '/admin/fill/acl/storage');
     /**********************************
      * Where ACL form
      **********************************/
     $table = new WbWhereACL();
     $this->view->rows_where = $table->fetchAll($table->getAdapter()->quoteInto('role_id = ?', $role_id), 'order_acl');
     unset($table);
     // form
     $form_where = new FormBaculaACL();
     // fill form
     $form_where->populate(array('acl' => 'where', 'role_id' => $role_id, 'role_name' => $role->name));
     $form_where->setAction($this->view->baseUrl . '/admin/where-add');
     $this->view->form_where = $form_where;
     /**********************************
      * view
      **********************************/
     // title
     $this->view->title = 'Webacula :: ' . $this->view->translate->_('Role') . ' :: ' . $role->name;
     $this->view->role_id = $role_id;
     // jQuery UI Tabs
     $tabs_selected = $this->_request->getParam('tabs_selected', 'role');
     $this->view->tabs_selected = $this->_jQueryUItabSelected[$tabs_selected];
 }