private function restoreRoleSettings($restore_roles, $_msg = null)
 {
     try {
         if (count($restore_roles) > 0) {
             $roles = new Roles();
             $roles_info = $roles->get_multiple(null);
             foreach ($roles_info as $_role) {
                 $role = $roles->get($_role->id);
                 if (is_object($role)) {
                     if (!$role->read_only) {
                         $roles->delete((int) $_role->id);
                     }
                 }
             }
             foreach ($restore_roles as $role) {
                 $_role = Roles::getRoleInfoByID($role['id'], $fetch_mode = DB_FETCHMODE_ASSOC);
                 if (isset($_role['id'])) {
                     // existing role, need to update only
                     $new_role = new Roles();
                     $new_role->id = $role['id'];
                     $new_role->description = $role['description'];
                     $new_role->name = $role['name'];
                     $new_role->type = $role['type'];
                     $new_role->update();
                     Roles::delete_role_tasks($new_role->id);
                     if (!empty($role['tasks'])) {
                         $tasks = array();
                         foreach ($role['tasks'] as $task) {
                             $tasks[] = $task['id'];
                         }
                         Roles::assign_tasks_to_role($tasks, $new_role->id);
                     }
                 } else {
                     $new_role = new Roles();
                     $new_role->description = $role['description'];
                     $new_role->name = $role['name'];
                     $role_id = $new_role->create();
                     if ($role_id && !empty($role['tasks'])) {
                         $tasks = array();
                         foreach ($role['tasks'] as $task) {
                             $tasks[] = $task['id'];
                         }
                         Roles::assign_tasks_to_role($tasks, $role_id);
                     }
                 }
             }
             $error_msg = $_msg ? $_msg : __('Default Roles settings sucessfully restored.');
         } else {
             $error_msg = __('There is no Roles data in default XML settings file.');
         }
     } catch (Exception $e) {
         $error = TRUE;
         $error_msg = $e->getMessage();
     }
     return $error_msg;
 }
Ejemplo n.º 2
0
 function deleteAction()
 {
     $request = new Bolts_Request($this->getRequest());
     $roles_table = new Roles();
     if ($request->has('id')) {
         $id = $request->id;
         $role = $roles_table->fetchRow("id = " . $id);
         if (is_null($role)) {
             $this->_redirect('/bolts/role');
         }
     } else {
         $this->_redirect('/bolts/role');
     }
     if ($this->getRequest()->isPost() and $request->has("delete")) {
         $errors = array();
         // can't be last admin
         if ((bool) $role->isadmin and $roles_table->getCountByWhereClause("isadmin = 1") == 1) {
             $errors[] = $this->_T("This is the only admin role. It cannot be deleted.");
         }
         // can't be guest
         if ((bool) $role->isguest) {
             $errors[] = $this->_T("This is the guest role. It cannot be deleted.");
         }
         // can't be default
         if ((bool) $role->isdefault) {
             $errors[] = $this->_T("This is the default role. It cannot be deleted.");
         }
         // can't have any users
         $userwhereclause = "role_id = " . $role->id;
         $users_table = new UsersRoles();
         if ($users_table->getCountByWhereClause($userwhereclause) > 0) {
             $errors[] = $this->_T("This role cannot be deleted because there are users assigned to it.");
         }
         // can't have children
         $inherited_by = $roles_table->fetchImmediateChildren($role->id);
         if (count($inherited_by) > 0) {
             $error = $this->_T("This role is inherited by role(s) ");
             $firstpass = true;
             foreach ($inherited_by as $role_i) {
                 if ($firstpass) {
                     $firstpass = false;
                 } else {
                     $error .= ", ";
                 }
                 $error .= $role_i->shortname;
             }
             $error .= $this->_T(". It cannot be deleted.");
             $errors[] = $error;
         }
         if ($request->delete == "Yes") {
             if (count($errors) > 0) {
                 $this->view->errors = $errors;
             } else {
                 $roles_table->delete("id = " . $id);
                 $this->view->success = $this->_T("Role deleted.");
             }
         } else {
             $this->_redirect("/bolts/role");
         }
     }
     $this->view->role = $role->toArray();
 }
<?php

/** !
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* [filename] is a part of PeopleAggregator.
* [description including history]
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* @author [creator, or "Original Author"]
* @license http://bit.ly/aVWqRV PayAsYouGo License
* @copyright Copyright (c) 2010 Broadband Mechanics
* @package PeopleAggregator
*/
$login_required = TRUE;
require_once dirname(__FILE__) . '/../../config.inc';
include_once "web/includes/page.php";
require_once "api/Roles/Roles.php";
if ($_POST['id']) {
    $msg = __("Role can't be deleted.");
    $role = new Roles();
    if ($role->delete((int) $_POST['id'])) {
        $msg = __("Successfully deleted.");
    }
}
echo $msg;