Ejemplo n.º 1
0
 /**
  * Add permissions for a contact on members
  * @param array $members_id  Array with the ids of members
  * @param array $rol_permissions Array with the permissions for the user type of the contact
  * @return null
  */
 function addPermissions($members_id, $rol_permissions)
 {
     //permissions
     $permissions = "";
     foreach ($rol_permissions as $permission) {
         if ($permissions != "") {
             $permissions .= ',';
         }
         $permissions .= '{"pg":"' . $this->getId() . '","o":' . $permission['object_type_id'] . ',"d":' . $permission['can_delete'] . ',"w":' . $permission['can_write'] . ',"r":1}';
     }
     $permissions = "[" . $permissions . "]";
     //members
     $members = array();
     foreach ($members_id as $member_id) {
         $mem = Members::findById($member_id);
         if (!$mem instanceof Member) {
             continue;
         }
         $members[] = $mem;
     }
     //save permissions
     foreach ($members as $member) {
         save_member_permissions_background(logged_user(), $member, $permissions);
     }
 }
Ejemplo n.º 2
0
 /**
  * After drag and drop
  */
 function add_default_permissions()
 {
     ajx_current("empty");
     $mem_id = array_var($_REQUEST, 'member_id');
     $user_ids = explode(',', array_var($_REQUEST, 'user_ids'));
     foreach ($user_ids as $k => &$uid) {
         if (!is_numeric($uid)) {
             unset($user_ids[$k]);
         }
     }
     if (can_manage_security(logged_user()) && is_numeric($mem_id)) {
         $member = Members::findById($mem_id);
         $users = Contacts::findAll(array('conditions' => 'id IN (' . implode(',', $user_ids) . ')'));
         if ($member instanceof Member && is_array($users) && count($users) > 0) {
             $permissions_decoded = array();
             foreach ($users as $user) {
                 $role_perms = RoleObjectTypePermissions::findAll(array('conditions' => array("role_id=?", $user->getUserType())));
                 foreach ($role_perms as $role_perm) {
                     $pg_obj = new stdClass();
                     $pg_obj->pg = $user->getPermissionGroupId();
                     $pg_obj->o = $role_perm->getObjectTypeId();
                     $pg_obj->d = $role_perm->getCanDelete();
                     $pg_obj->w = $role_perm->getCanWrite();
                     $pg_obj->r = 1;
                     $permissions_decoded[] = $pg_obj;
                 }
             }
             $permissions = json_encode($permissions_decoded);
             Env::useHelper('permissions');
             try {
                 DB::beginWork();
                 save_member_permissions_background(logged_user(), $member, $permissions);
                 DB::commit();
             } catch (Exception $e) {
                 DB::rollback();
                 flash_error($e->getMessage());
             }
         }
     }
 }