1<?php 2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */ 3 4 5/** 6 * Forum Administration Settings. 7 * @author Nadia Matuschek <nmatuschek@databay.de> 8 * @version $Id:$ 9 * @ilCtrl_Calls ilObjForumAdministrationGUI: ilPermissionGUI 10 * @ilCtrl_IsCalledBy ilObjForumAdministrationGUI: ilAdministrationGUI 11 * @ingroup ModulesForum 12 */ 13class ilObjForumAdministrationGUI extends ilObjectGUI 14{ 15 private $rbac; 16 17 /** 18 * Contructor 19 * @access public 20 */ 21 public function __construct($a_data, $a_id, $a_call_by_reference = true, $a_prepare_output = true) 22 { 23 global $DIC; 24 $this->rbac = $DIC->rbac(); 25 26 $this->type = 'frma'; 27 parent::__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output); 28 $this->lng->loadLanguageModule('forum'); 29 } 30 31 /** 32 * @return bool 33 */ 34 public function executeCommand() 35 { 36 $next_class = $this->ctrl->getNextClass($this); 37 $cmd = $this->ctrl->getCmd(); 38 39 $this->prepareOutput(); 40 41 switch ($next_class) { 42 case 'ilpermissiongui': 43 $this->tabs_gui->setTabActive('perm_settings'); 44 $this->ctrl->forwardCommand(new ilPermissionGUI($this)); 45 break; 46 47 default: 48 if (!$cmd || $cmd == 'view') { 49 $cmd = 'editSettings'; 50 } 51 52 $this->$cmd(); 53 break; 54 } 55 return true; 56 } 57 58 /** 59 * 60 */ 61 public function getAdminTabs() 62 { 63 if ($this->rbac->system()->checkAccess('visible,read', $this->object->getRefId())) { 64 $this->tabs_gui->addTarget( 65 'settings', 66 $this->ctrl->getLinkTarget($this, 'editSettings'), 67 array('editSettings', 'view') 68 ); 69 } 70 71 if ($this->rbac->system()->checkAccess('edit_permission', $this->object->getRefId())) { 72 $this->tabs_gui->addTarget( 73 'perm_settings', 74 $this->ctrl->getLinkTargetByClass('ilpermissiongui', 'perm'), 75 array(), 76 'ilpermissiongui' 77 ); 78 } 79 } 80 81 /** 82 * @param ilPropertyFormGUI $form 83 */ 84 public function editSettings(ilPropertyFormGUI $form = null) 85 { 86 $this->tabs_gui->activateTab('settings'); 87 88 if (!$form) { 89 $form = $this->getSettingsForm(); 90 $this->populateForm($form); 91 } 92 93 $this->tpl->setContent($form->getHtml()); 94 } 95 96 /** 97 * Save settings 98 */ 99 public function saveSettings() 100 { 101 $this->checkPermission("write"); 102 103 $form = $this->getSettingsForm(); 104 if (!$form->checkInput()) { 105 $form->setValuesByPost(); 106 $this->editSettings($form); 107 return; 108 } 109 110 $frma_set = new ilSetting('frma'); 111 $frma_set->set('forum_overview', $form->getInput('forum_overview')); 112 $this->settings->set('file_upload_allowed_fora', (int) $form->getInput('file_upload_allowed_fora')); 113 $this->settings->set('send_attachments_by_mail', (int) $form->getInput('send_attachments_by_mail')); 114 $this->settings->set('enable_fora_statistics', (int) $form->getInput('fora_statistics')); 115 $this->settings->set('enable_anonymous_fora', (int) $form->getInput('anonymous_fora')); 116 117 if (!ilCronManager::isJobActive('frm_notification')) { 118 $this->settings->set('forum_notification', (int) $form->getInput('forum_notification')); 119 } 120 121 ilCaptchaUtil::setActiveForForum((bool) $form->getInput('activate_captcha_anonym')); 122 123 $this->settings->set('save_post_drafts', (int) $form->getInput('save_post_drafts')); 124 $this->settings->set('autosave_drafts', (int) $form->getInput('autosave_drafts')); 125 $this->settings->set('autosave_drafts_ival', (int) $form->getInput('autosave_drafts_ival')); 126 127 ilUtil::sendSuccess($this->lng->txt('settings_saved')); 128 $form->setValuesByPost(); 129 $this->editSettings($form); 130 } 131 132 /** 133 * @param ilPropertyFormGUI $form 134 */ 135 protected function populateForm(ilPropertyFormGUI $form) 136 { 137 $frma_set = new ilSetting('frma'); 138 139 $form->setValuesByArray(array( 140 'forum_overview' => (bool) $frma_set->get('forum_overview', false), 141 'fora_statistics' => (bool) $this->settings->get('enable_fora_statistics', false), 142 'anonymous_fora' => (bool) $this->settings->get('enable_anonymous_fora', false), 143 'forum_notification' => (int) $this->settings->get('forum_notification') === 1 ? true : false, 144 'activate_captcha_anonym' => ilCaptchaUtil::isActiveForForum(), 145 'file_upload_allowed_fora' => (int) $this->settings->get('file_upload_allowed_fora', ilForumProperties::FILE_UPLOAD_GLOBALLY_ALLOWED), 146 'save_post_drafts' => (int) $this->settings->get('save_post_drafts', 0), 147 'autosave_drafts' => (int) $this->settings->get('autosave_drafts', 0), 148 'autosave_drafts_ival' => (int) $this->settings->get('autosave_drafts_ival', 30), 149 'send_attachments_by_mail' => (bool) $this->settings->get('send_attachments_by_mail', false) 150 )); 151 } 152 153 /** 154 * @return ilPropertyFormGUI 155 */ 156 protected function getSettingsForm() 157 { 158 $form = new ilPropertyFormGUI(); 159 $form->setFormAction($this->ctrl->getFormAction($this, 'saveSettings')); 160 $form->setTitle($this->lng->txt('settings')); 161 162 $frm_radio = new ilRadioGroupInputGUI($this->lng->txt('frm_displayed_infos'), 'forum_overview'); 163 $frm_radio->addOption(new ilRadioOption($this->lng->txt('new') . ', ' . $this->lng->txt('is_read') . ', ' . $this->lng->txt('unread'), '0')); 164 $frm_radio->addOption(new ilRadioOption($this->lng->txt('is_read') . ', ' . $this->lng->txt('unread'), '1')); 165 $frm_radio->setInfo($this->lng->txt('frm_disp_info_desc')); 166 $form->addItem($frm_radio); 167 168 $check = new ilCheckboxInputGui($this->lng->txt('enable_fora_statistics'), 'fora_statistics'); 169 $check->setInfo($this->lng->txt('enable_fora_statistics_desc')); 170 $form->addItem($check); 171 172 $check = new ilCheckboxInputGui($this->lng->txt('enable_anonymous_fora'), 'anonymous_fora'); 173 $check->setInfo($this->lng->txt('enable_anonymous_fora_desc')); 174 $form->addItem($check); 175 176 $file_upload = new ilRadioGroupInputGUI($this->lng->txt('file_upload_allowed_fora'), 'file_upload_allowed_fora'); 177 $file_upload->addOption(new ilRadioOption($this->lng->txt('file_upload_option_allow'), ilForumProperties::FILE_UPLOAD_GLOBALLY_ALLOWED)); 178 $file_upload->addOption(new ilRadioOption($this->lng->txt('file_upload_option_disallow'), ilForumProperties::FILE_UPLOAD_INDIVIDUAL)); 179 $file_upload->setInfo($this->lng->txt('file_upload_allowed_fora_desc')); 180 $form->addItem($file_upload); 181 182 if (ilCronManager::isJobActive('frm_notification')) { 183 ilAdministrationSettingsFormHandler::addFieldsToForm( 184 ilAdministrationSettingsFormHandler::FORM_FORUM, 185 $form, 186 $this 187 ); 188 } else { 189 $notifications = new ilCheckboxInputGui($this->lng->txt('cron_forum_notification'), 'forum_notification'); 190 $notifications->setInfo($this->lng->txt('cron_forum_notification_desc')); 191 $notifications->setValue(1); 192 $form->addItem($notifications); 193 } 194 195 $check = new ilCheckboxInputGui($this->lng->txt('enable_send_attachments'), 'send_attachments_by_mail'); 196 $check->setInfo($this->lng->txt('enable_send_attachments_desc')); 197 $check->setValue(1); 198 $form->addItem($check); 199 200 $cap = new ilCheckboxInputGUI($this->lng->txt('adm_captcha_anonymous_short'), 'activate_captcha_anonym'); 201 $cap->setInfo($this->lng->txt('adm_captcha_anonymous_frm')); 202 $cap->setValue(1); 203 if (!ilCaptchaUtil::checkFreetype()) { 204 $cap->setAlert(ilCaptchaUtil::getPreconditionsMessage()); 205 } 206 $form->addItem($cap); 207 208 $drafts = new ilCheckboxInputGUI($this->lng->txt('adm_save_drafts'), 'save_post_drafts'); 209 $drafts->setInfo($this->lng->txt('adm_save_drafts_desc')); 210 $drafts->setValue(1); 211 212 $autosave_drafts = new ilCheckboxInputGUI($this->lng->txt('adm_autosave_drafts'), 'autosave_drafts'); 213 $autosave_drafts->setInfo($this->lng->txt('adm_autosave_drafts_desc')); 214 $autosave_drafts->setValue(1); 215 216 $autosave_interval = new ilNumberInputGUI($this->lng->txt('adm_autosave_ival'), 'autosave_drafts_ival'); 217 $autosave_interval->allowDecimals(false); 218 $autosave_interval->setMinValue(30); 219 $autosave_interval->setMaxValue(60 * 60); 220 $autosave_interval->setSize(10); 221 $autosave_interval->setSuffix($this->lng->txt('seconds')); 222 $autosave_drafts->addSubItem($autosave_interval); 223 $drafts->addSubItem($autosave_drafts); 224 $form->addItem($drafts); 225 226 if ($this->checkPermissionBool("write")) { 227 $form->addCommandButton('saveSettings', $this->lng->txt('save')); 228 } 229 230 return $form; 231 } 232 233 /** 234 * @param string $a_form_id 235 * @return array 236 */ 237 public function addToExternalSettingsForm($a_form_id) 238 { 239 switch ($a_form_id) { 240 case ilAdministrationSettingsFormHandler::FORM_PRIVACY: 241 242 $fields = array( 243 'enable_fora_statistics' => array($this->settings->get('enable_fora_statistics', false), ilAdministrationSettingsFormHandler::VALUE_BOOL), 244 'enable_anonymous_fora' => array($this->settings->get('enable_anonymous_fora', false), ilAdministrationSettingsFormHandler::VALUE_BOOL) 245 ); 246 247 return array(array("editSettings", $fields)); 248 249 case ilAdministrationSettingsFormHandler::FORM_ACCESSIBILITY: 250 $fields = array( 251 'adm_captcha_anonymous_short' => array(ilCaptchaUtil::isActiveForForum(), ilAdministrationSettingsFormHandler::VALUE_BOOL) 252 ); 253 254 return array('obj_frma' => array('editSettings', $fields)); 255 } 256 } 257} 258