Exemple #1
0
 public function Permissions()
 {
     // Check the token
     if (!Kit::CheckToken()) {
         trigger_error(__('Sorry the form has expired. Please refresh.'), E_USER_ERROR);
     }
     $db =& $this->db;
     $user =& $this->user;
     $response = new ResponseManager();
     $campaignId = Kit::GetParam('campaignId', _POST, _INT);
     $groupIds = Kit::GetParam('groupids', _POST, _ARRAY);
     $ownerId = Kit::GetParam('ownerId', _POST, _INT);
     $auth = $this->user->CampaignAuth($campaignId, true);
     if (!$auth->modifyPermissions) {
         trigger_error(__('You do not have permissions to edit this campaign'), E_USER_ERROR);
     }
     // Change the owner?
     if ($ownerId > 0) {
         // Update this Campaign with a new owner
         Campaign::setOwner($campaignId, $ownerId);
     }
     // Unlink all
     Kit::ClassLoader('campaignsecurity');
     $security = new CampaignSecurity($db);
     if (!$security->UnlinkAll($campaignId)) {
         trigger_error(__('Unable to set permissions'));
     }
     // Some assignments for the loop
     $lastGroupId = 0;
     $first = true;
     $view = 0;
     $edit = 0;
     $del = 0;
     $permissions = array();
     // List of groupIds with view, edit and del assignments
     foreach ($groupIds as $groupPermission) {
         $groupPermission = explode('_', $groupPermission);
         $groupId = $groupPermission[0];
         if ($first) {
             // First time through
             $first = false;
             $lastGroupId = $groupId;
         }
         if ($groupId != $lastGroupId) {
             // The groupId has changed, so we need to write the current settings to the db.
             // Link new permissions
             if (!$security->Link($campaignId, $lastGroupId, $view, $edit, $del)) {
                 trigger_error(__('Unable to set permissions'));
             }
             // Store
             $permissions[] = array('groupId' => $lastGroupId, 'view' => $view, 'edit' => $edit, 'del' => $del);
             // Reset
             $lastGroupId = $groupId;
             $view = 0;
             $edit = 0;
             $del = 0;
         }
         switch ($groupPermission[1]) {
             case 'view':
                 $view = 1;
                 break;
             case 'edit':
                 $edit = 1;
                 break;
             case 'del':
                 $del = 1;
                 break;
         }
     }
     // Need to do the last one
     if (!$first) {
         if (!$security->Link($campaignId, $lastGroupId, $view, $edit, $del)) {
             trigger_error(__('Unable to set permissions'));
         }
         $permissions[] = array('groupId' => $lastGroupId, 'view' => $view, 'edit' => $edit, 'del' => $del);
     }
     $replaceInLayouts = Kit::GetParam('replaceInLayouts', _POST, _CHECKBOX);
     if ($replaceInLayouts) {
         Debug::LogEntry('audit', 'Permissions to push down: ' . json_encode($permissions), get_class(), __FUNCTION__);
         // Layout object to deal with layout information
         Kit::ClassLoader('layout');
         $layoutObject = new Layout($db);
         // Get all layouts for this Campaign
         foreach ($this->user->LayoutList(NULL, array('campaignId' => $campaignId)) as $layout) {
             // Set for ease of use
             $layoutId = $layout['layoutid'];
             Debug::LogEntry('audit', 'Processing permissions for layout id' . $layoutId, get_class(), __FUNCTION__);
             // Set the permissions on this layout (if its not the same one!)
             if ($layout['campaignid'] != $campaignId) {
                 // Set permissions on this Layout
                 $auth = $this->user->CampaignAuth($layout['campaignid'], true);
                 if ($auth->modifyPermissions) {
                     if (!$security->UnlinkAll($layout['campaignid'])) {
                         continue;
                     }
                     foreach ($permissions as $permission) {
                         $security->Link($layout['campaignid'], $permission['groupId'], $permission['view'], $permission['edit'], $permission['del']);
                     }
                 }
             }
             // Get all regions and media and set permissions on those too
             $layoutInformation = $layoutObject->LayoutInformation($layoutId);
             // Region and Media Security Class
             Kit::ClassLoader('layoutregiongroupsecurity');
             Kit::ClassLoader('layoutmediagroupsecurity');
             $layoutSecurity = new LayoutRegionGroupSecurity($this->db);
             $layoutMediaSecurity = new LayoutMediaGroupSecurity($this->db);
             foreach ($layoutInformation['regions'] as $region) {
                 // Make sure we have permission
                 $regionAuth = $this->user->RegionAssignmentAuth($region['ownerid'], $layoutId, $region['regionid'], true);
                 if (!$regionAuth->modifyPermissions) {
                     continue;
                 }
                 // Set the permissions on the region
                 // Unlink all
                 if (!$layoutSecurity->UnlinkAll($layoutId, $region['regionid'])) {
                     continue;
                 }
                 foreach ($permissions as $permission) {
                     if (!$layoutSecurity->Link($layoutId, $region['regionid'], $permission['groupId'], $permission['view'], $permission['edit'], $permission['del'])) {
                         trigger_error($layoutSecurity->GetErrorMessage(), E_USER_ERROR);
                     }
                 }
                 // Find all media nodes
                 foreach ($region['media'] as $media) {
                     $originalUserId = $media['userid'] == '' ? $layout['ownerid'] : $media['userid'];
                     // Make sure we have permission
                     $mediaAuth = $this->user->MediaAssignmentAuth($originalUserId, $layoutId, $region['regionid'], $media['mediaid'], true);
                     if (!$mediaAuth->modifyPermissions) {
                         continue;
                     }
                     // Set the permissions on the media node
                     if (!$layoutMediaSecurity->UnlinkAll($layoutId, $region['regionid'], $media['mediaid'])) {
                         continue;
                     }
                     foreach ($permissions as $permission) {
                         if (!$layoutMediaSecurity->Link($layoutId, $region['regionid'], $media['mediaid'], $permission['groupId'], $permission['view'], $permission['edit'], $permission['del'])) {
                             trigger_error($layoutMediaSecurity->GetErrorMessage(), E_USER_ERROR);
                         }
                     }
                 }
             }
         }
     }
     $response->SetFormSubmitResponse(__('Permissions Changed'));
     $response->Respond();
 }
Exemple #2
0
 public function RegionPermissions()
 {
     $db =& $this->db;
     $user =& $this->user;
     $response = new ResponseManager();
     Kit::ClassLoader('layoutregiongroupsecurity');
     $layoutId = Kit::GetParam('layoutid', _POST, _INT);
     $regionId = Kit::GetParam('regionid', _POST, _STRING);
     $groupIds = Kit::GetParam('groupids', _POST, _ARRAY);
     Kit::ClassLoader('region');
     $region = new region($db);
     $ownerId = $region->GetOwnerId($layoutId, $regionId);
     $regionAuth = $this->user->RegionAssignmentAuth($ownerId, $layoutId, $regionId, true);
     if (!$regionAuth->modifyPermissions) {
         trigger_error(__('You do not have permissions to edit this regions permissions'), E_USER_ERROR);
     }
     // Unlink all
     $layoutSecurity = new LayoutRegionGroupSecurity($db);
     if (!$layoutSecurity->UnlinkAll($layoutId, $regionId)) {
         trigger_error(__('Unable to set permissions'));
     }
     // Some assignments for the loop
     $lastGroupId = 0;
     $first = true;
     $view = 0;
     $edit = 0;
     $del = 0;
     // List of groupIds with view, edit and del assignments
     foreach ($groupIds as $groupPermission) {
         $groupPermission = explode('_', $groupPermission);
         $groupId = $groupPermission[0];
         if ($first) {
             // First time through
             $first = false;
             $lastGroupId = $groupId;
         }
         if ($groupId != $lastGroupId) {
             // The groupId has changed, so we need to write the current settings to the db.
             // Link new permissions
             if (!$layoutSecurity->Link($layoutId, $regionId, $lastGroupId, $view, $edit, $del)) {
                 trigger_error(__('Unable to set permissions'));
             }
             // Reset
             $lastGroupId = $groupId;
             $view = 0;
             $edit = 0;
             $del = 0;
         }
         switch ($groupPermission[1]) {
             case 'view':
                 $view = 1;
                 break;
             case 'edit':
                 $edit = 1;
                 break;
             case 'del':
                 $del = 1;
                 break;
         }
     }
     // Need to do the last one
     if (!$first) {
         if (!$layoutSecurity->Link($layoutId, $regionId, $lastGroupId, $view, $edit, $del)) {
             trigger_error(__('Unable to set permissions'));
         }
     }
     $response->SetFormSubmitResponse(__('Permissions Changed'));
     $response->Respond();
 }