/** * Permissions Edit */ public function Permissions() { $db =& $this->db; $user =& $this->user; $response = new ResponseManager(); Kit::ClassLoader('mediagroupsecurity'); Kit::ClassLoader('layoutmediagroupsecurity'); $layoutId = Kit::GetParam('layoutid', _POST, _INT); $regionId = Kit::GetParam('regionid', _POST, _STRING); $mediaId = Kit::GetParam('mediaid', _POST, _STRING); $groupIds = Kit::GetParam('groupids', _POST, _ARRAY); if (!$this->auth->modifyPermissions) { trigger_error(__('You do not have permissions to edit this layout'), E_USER_ERROR); } // Unlink all if ($this->assignedMedia) { $layoutMediaSecurity = new LayoutMediaGroupSecurity($db); if (!$layoutMediaSecurity->UnlinkAll($layoutId, $regionId, $mediaId)) { trigger_error(__('Unable to set permissions')); } } else { $mediaSecurity = new MediaGroupSecurity($db); if (!$mediaSecurity->UnlinkAll($mediaId)) { 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 ($this->assignedMedia) { if (!$layoutMediaSecurity->Link($layoutId, $regionId, $mediaId, $lastGroupId, $view, $edit, $del)) { trigger_error(__('Unable to set permissions')); } } else { if (!$mediaSecurity->Link($mediaId, $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 ($this->assignedMedia) { if (!$layoutMediaSecurity->Link($layoutId, $regionId, $mediaId, $lastGroupId, $view, $edit, $del)) { trigger_error(__('Unable to set permissions')); } } else { if (!$mediaSecurity->Link($mediaId, $lastGroupId, $view, $edit, $del)) { trigger_error(__('Unable to set permissions')); } } } $response->SetFormSubmitResponse(__('Permissions Changed')); return $response; }
public function Delete($mediaId, $newRevisionMediaId = NULL) { Debug::LogEntry('audit', 'IN', 'Media', 'Delete'); try { $dbh = PDOConnect::init(); // Check for links $sth = $dbh->prepare('SELECT * FROM lklayoutmedia WHERE MediaID = :mediaid'); $sth->execute(array('mediaid' => $mediaId)); if ($sth->fetch()) { $this->ThrowError(21, __('This media is in use, please retire it instead.')); } // Get the file name $sth = $dbh->prepare('SELECT StoredAs FROM media WHERE mediaID = :mediaid'); $sth->execute(array('mediaid' => $mediaId)); if (!($row = $sth->fetch())) { $this->ThrowError(22, __('Cannot locate the files for this media. Unable to delete.')); } // This will be used to delete the actual file (stored on disk) $fileName = Kit::ValidateParam($row['StoredAs'], _STRING); // Remove permission assignments $security = new MediaGroupSecurity($this->db); if (!$security->UnlinkAll($mediaId)) { throw new Exception("Error Processing Request", 1); } // Delete any assignments $link = new LkMediaDisplayGroup($this->db); if (!$link->UnlinkAllFromDisplayGroup($mediaId)) { $this->ThrowError(__('Unable to drop file assignments during display delete.')); } // Delete the media $sth = $dbh->prepare('DELETE FROM media WHERE MediaID = :mediaid'); $sth->execute(array('mediaid' => $mediaId)); // Delete the file itself (and any thumbs, etc) if (!$this->DeleteMediaFile($fileName)) { throw new Exception("Error Processing Request", 1); } // Bring back the previous revision of this media (if there is one) $sth = $dbh->prepare('SELECT IFNULL(MediaID, 0) AS MediaID FROM media WHERE EditedMediaID = :mediaid'); $sth->execute(array('mediaid' => $mediaId)); if ($editedMediaRow = $sth->fetch()) { // Unretire this edited record $editedMediaId = Kit::ValidateParam($editedMediaRow['MediaID'], _INT); if ($newRevisionMediaId == null) { // Bring back the old one $sth = $dbh->prepare('UPDATE media SET IsEdited = 0, EditedMediaID = NULL WHERE mediaid = :mediaid'); $sth->execute(array('mediaid' => $editedMediaId)); } else { // Link up the old one $sth = $dbh->prepare('UPDATE media SET EditedMediaID = :newRevisionMediaId WHERE mediaid = :mediaid'); $sth->execute(array('mediaid' => $editedMediaId, 'newRevisionMediaId' => $newRevisionMediaId)); } } return true; } catch (Exception $e) { Debug::LogEntry('error', $e->getMessage()); if (!$this->IsError()) { $this->SetError(23, __('Error deleting media.')); } return false; } }