1<?php 2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */ 3 4/** 5 * Class ilChatroomSettingsGUI 6 * @author Jan Posselt <jposselt@databay.de> 7 * @version $Id$ 8 * @ingroup ModulesChatroom 9 */ 10class ilChatroomSettingsGUI extends ilChatroomGUIHandler 11{ 12 /** 13 * Constructor 14 * Requires ilChatroomFormFactory, ilChatroom and ilChatroomInstaller, 15 * sets $this->gui using given $gui and calls ilChatroomInstaller::install() 16 * method. 17 * @param ilChatroomObjectGUI $gui 18 */ 19 public function __construct(ilChatroomObjectGUI $gui) 20 { 21 parent::__construct($gui); 22 23 require_once 'Modules/Chatroom/classes/class.ilChatroomFormFactory.php'; 24 require_once 'Modules/Chatroom/classes/class.ilChatroom.php'; 25 require_once 'Modules/Chatroom/classes/class.ilChatroomInstaller.php'; 26 } 27 28 /** 29 * Saves settings fetched from $_POST. 30 */ 31 public function saveGeneral() 32 { 33 $formFactory = new ilChatroomFormFactory(); 34 $settingsForm = $formFactory->getSettingsForm(); 35 36 if (!$settingsForm->checkInput()) { 37 $settingsForm->setValuesByPost(); 38 $this->general($settingsForm); 39 } else { 40 $this->gui->object->setTitle($settingsForm->getInput('title')); 41 $this->gui->object->setDescription($settingsForm->getInput('desc')); 42 43 require_once 'Services/Object/classes/class.ilObjectActivation.php'; 44 45 $period = $settingsForm->getItemByPostVar('access_period'); 46 if ($period->getStart() && $period->getEnd()) { 47 $this->gui->object->setAccessType(ilObjectActivation::TIMINGS_ACTIVATION); 48 $this->gui->object->setAccessBegin($period->getStart()->get(IL_CAL_UNIX)); 49 $this->gui->object->setAccessEnd($period->getEnd()->get(IL_CAL_UNIX)); 50 $this->gui->object->setAccessVisibility((int) $settingsForm->getInput('access_visibility')); 51 } else { 52 $this->gui->object->setAccessType(ilObjectActivation::TIMINGS_DEACTIVATED); 53 } 54 55 $this->gui->object->update(); 56 // @todo: Do not rely on raw post data 57 $settings = $_POST; 58 $room = ilChatRoom::byObjectId($this->gui->object->getId()); 59 60 if (!$room) { 61 $room = new ilChatRoom(); 62 $settings['object_id'] = $this->gui->object->getId(); 63 } 64 $room->saveSettings($settings); 65 66 ilUtil::sendSuccess($this->ilLng->txt('saved_successfully'), true); 67 $this->ilCtrl->redirect($this->gui, 'settings-general'); 68 } 69 } 70 71 /** 72 * Prepares and displays settings form. 73 * @param ilPropertyFormGUI $settingsForm 74 */ 75 public function general(ilPropertyFormGUI $settingsForm = null) 76 { 77 if (!ilChatroom::checkUserPermissions(array( 78 'read', 79 'write' 80 ), $this->gui->ref_id) 81 ) { 82 $this->ilCtrl->setParameterByClass('ilrepositorygui', 'ref_id', ROOT_FOLDER_ID); 83 $this->ilCtrl->redirectByClass('ilrepositorygui', ''); 84 } 85 86 $chatSettings = new ilSetting('chatroom'); 87 if (!$chatSettings->get('chat_enabled')) { 88 ilUtil::sendInfo($this->ilLng->txt('server_disabled'), true); 89 } 90 91 $this->gui->switchToVisibleMode(); 92 93 $formFactory = new ilChatroomFormFactory(); 94 95 $room = ilChatRoom::byObjectId($this->gui->object->getId()); 96 97 if (!$settingsForm) { 98 $settingsForm = $formFactory->getSettingsForm(); 99 100 require_once 'Services/Object/classes/class.ilObjectActivation.php'; 101 $settings = array( 102 'title' => $this->gui->object->getTitle(), 103 'desc' => $this->gui->object->getDescription(), 104 'access_period' => array( 105 'start' => $this->gui->object->getAccessBegin() ? new ilDateTime($this->gui->object->getAccessBegin(), IL_CAL_UNIX) : null, 106 'end' => $this->gui->object->getAccessEnd() ? new ilDateTime($this->gui->object->getAccessEnd(), IL_CAL_UNIX) : null 107 ), 108 'access_visibility' => $this->gui->object->getAccessVisibility() 109 ); 110 111 if ($room) { 112 ilChatroomFormFactory::applyValues( 113 $settingsForm, 114 array_merge($settings, $room->getSettings()) 115 ); 116 } else { 117 ilChatroomFormFactory::applyValues($settingsForm, $settings); 118 } 119 } 120 121 $settingsForm->setTitle($this->ilLng->txt('settings_title')); 122 $settingsForm->addCommandButton('settings-saveGeneral', $this->ilLng->txt('save')); 123 $settingsForm->setFormAction($this->ilCtrl->getFormAction($this->gui, 'settings-saveGeneral')); 124 125 $this->mainTpl->setVariable('ADM_CONTENT', $settingsForm->getHtml()); 126 } 127 128 /** 129 * @param string $requestedMethod 130 * @return void 131 */ 132 public function executeDefault($requestedMethod) 133 { 134 $this->general(); 135 } 136} 137