/** * Settings screen for role and restriction choice. * * @param object $sender SettingsController. * @return void. * @package ReadOnly * @since 0.1 */ public function settingsController_readOnly_create($sender) { // Define general settings properties. $sender->permission('Garden.Settings.Manage'); $sender->addSideMenu('/dashboard/settings/plugins'); $sender->setData('Title', t('ReadOnly Settings')); $sender->setData('Description', t('ReadOnly Settings Description', 'Choose which roles and actions should be restricted.<br/>You should inform your users about the read only state by ' . anchor('adding a message', '/dashboard/message/add') . ' to the forum.')); // Consolidate/prepare permissions. $permissionModel = Gdn::PermissionModel(); $perms = $permissionModel->PermissionColumns(); unset($perms['PermissionID']); $permissions = array(); foreach ($perms as $key => $value) { $action = substr($key, strrpos($key, '.') + 1); $permissions[$action] .= $key . ', '; } $permissionItems = array(); foreach ($permissions as $key => $value) { $text = $key . '<span>' . trim($value, ', ') . '</span>'; $permissionItems[$text] = $key; } // Consolidate/prepare roles. $roleModel = new RoleModel(); $roles = $roleModel->roles(); $roleItems = array(); foreach ($roles as $role) { $roleItems[$role['Name']] = $role['RoleID']; } // Build form info. $configurationModule = new configurationModule($sender); $configurationModule->initialize(array('ReadOnly.Restrictions' => array('Control' => 'CheckBoxList', 'Description' => t('ReadOnly Settings Restrictions', 'Choose the actions that should be restricted. Below each action is a list of all the current permissions with that action."Add" and "Edit" is recommended.'), 'Items' => $permissionItems, 'LabelCode' => 'Restrictions'), 'ReadOnly.Roles' => array('Control' => 'CheckBoxList', 'Description' => t('Choose the roles that should <strong>not</strong> be restricted (Admin users will always have all permissions).'), 'Items' => $roleItems, 'LabelCode' => 'Roles'), 'ReadOnly.Message' => array('Control' => 'TextBox', 'LabelCode' => 'Message Text', 'Description' => 'It is a good idea to ' . anchor('inform your users', '/dashboard/message') . ' about the restrictions so that they now what\'s going on...', 'Options' => array('MultiLine' => true)), 'ReadOnly.ShowAlert' => array('Control' => 'Checkbox', 'Description' => 'You can choose show or deactivate the message, however.', 'LabelCode' => 'Show Message'))); // Handle alert message. if ($sender->Request->isPostBack()) { $post = $sender->Request->getRequestArguments('post'); $messageModel = new MessageModel(); $messageID = c('ReadOnly.MessageID'); $message = $messageModel->getID($messageID); if (!$post['ReadOnly-dot-Message']) { // Delete message when no text is given. if ($message) { $messageModel->delete(array('MessageID' => $messageID)); removeFromConfig('ReadOnly.MessageID'); } } else { // Check if message already exists. if ($message) { // Set MessageID so that existing message gets updated $formPostValues['MessageID'] = $messageID; } $formPostValues['Location'] = '[Base]'; $formPostValues['AssetTarget'] = 'Content'; $formPostValues['Content'] = $post['ReadOnly-dot-Message']; $formPostValues['CssClass'] = 'AlertMessage'; $formPostValues['Enabled'] = $post['ReadOnly-dot-ShowAlert']; $formPostValues['AllowDismiss'] = false; $formPostValues['TransientKey'] = Gdn::session()->transientKey(); saveToConfig('ReadOnly.MessageID', $messageModel->save($formPostValues)); } } // Show form. $configurationModule->renderAll(); }