ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjNewsSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 include_once("./classes/class.ilObjectGUI.php");
24 
25 
37 {
38  private static $ERROR_MESSAGE;
44  public function __construct($a_data, $a_id, $a_call_by_reference = true, $a_prepare_output = true)
45  {
46  $this->type = 'nwss';
47  parent::ilObjectGUI($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
48 
49  $this->lng->loadLanguageModule('news');
50  $this->lng->loadLanguageModule('feed');
51 
52  }
53 
60  public function executeCommand()
61  {
62  global $rbacsystem,$ilErr,$ilAccess;
63 
64  $next_class = $this->ctrl->getNextClass($this);
65  $cmd = $this->ctrl->getCmd();
66 
67  $this->prepareOutput();
68 
69  if(!$ilAccess->checkAccess('read','',$this->object->getRefId()))
70  {
71  $ilErr->raiseError($this->lng->txt('no_permission'),$ilErr->WARNING);
72  }
73 
74  switch($next_class)
75  {
76  case 'ilpermissiongui':
77  $this->tabs_gui->setTabActive('perm_settings');
78  include_once("./classes/class.ilPermissionGUI.php");
79  $perm_gui =& new ilPermissionGUI($this);
80  $ret =& $this->ctrl->forwardCommand($perm_gui);
81  break;
82 
83  default:
84  if(!$cmd || $cmd == 'view')
85  {
86  $cmd = "editSettings";
87  }
88 
89  $this->$cmd();
90  break;
91  }
92  return true;
93  }
94 
101  public function getAdminTabs()
102  {
103  global $rbacsystem, $ilAccess;
104 
105  if ($rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
106  {
107  $this->tabs_gui->addTarget("news_edit_news_settings",
108  $this->ctrl->getLinkTarget($this, "editSettings"),
109  array("editSettings", "view"));
110  }
111 
112  if ($rbacsystem->checkAccess('edit_permission',$this->object->getRefId()))
113  {
114  $this->tabs_gui->addTarget("perm_settings",
115  $this->ctrl->getLinkTargetByClass('ilpermissiongui',"perm"),
116  array(),'ilpermissiongui');
117  }
118  }
119 
123  public function editSettings()
124  {
125  global $ilCtrl, $lng, $ilSetting;
126 
127  $news_set = new ilSetting("news");
128  $feed_set = new ilSetting("feed");
129 
130  $enable_internal_news = $ilSetting->get("block_activated_news");
131  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
132  $enable_private_feed = $news_set->get("enable_private_feed");
133  $news_default_visibility = ($news_set->get("default_visibility") != "")
134  ? $news_set->get("default_visibility")
135  : "users";
136  $disable_repository_feeds = $feed_set->get("disable_rep_feeds");
137  $nr_personal_desktop_feeds = $ilSetting->get("block_limit_pdfeed");
138 
139  $allow_shorter_periods = $news_set->get("allow_shorter_periods");
140  $allow_longer_periods = $news_set->get("allow_longer_periods");
141 
142  include_once("./Services/News/classes/class.ilNewsItem.php");
143  $rss_period = ilNewsItem::_lookupRSSPeriod();
144 
145  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
146  $form = new ilPropertyFormGUI();
147  $form->setFormAction($ilCtrl->getFormAction($this));
148  $form->setTitle($lng->txt("news_settings"));
149 
150  // Enable internal news
151  $cb_prop = new ilCheckboxInputGUI($lng->txt("news_enable_internal_news"),
152  "enable_internal_news");
153  $cb_prop->setValue("1");
154  $cb_prop->setInfo($lng->txt("news_enable_internal_news_info"));
155  $cb_prop->setChecked($enable_internal_news);
156  $form->addItem($cb_prop);
157 
158  // Enable rss for internal news
159  $cb_prop = new ilCheckboxInputGUI($lng->txt("news_enable_internal_rss"),
160  "enable_internal_rss");
161  $cb_prop->setValue("1");
162  $cb_prop->setInfo($lng->txt("news_enable_internal_rss_info"));
163  $cb_prop->setChecked($enable_internal_rss);
164 
165  // RSS News Period
166  $rssp_opts = array(
167  2 => "2 ".$lng->txt("days"),
168  3 => "3 ".$lng->txt("days"),
169  5 => "5 ".$lng->txt("days"),
170  7 => "1 ".$lng->txt("week"),
171  14 => "2 ".$lng->txt("weeks"),
172  30 => "1 ".$lng->txt("month"),
173  60 => "2 ".$lng->txt("months"));
174  $rssp_sel = new ilSelectInputGUI($lng->txt("news_rss_period"),
175  "news_rss_period");
176  $rssp_sel->setOptions($rssp_opts);
177  $rssp_sel->setValue((int) $rss_period);
178  $cb_prop->addSubItem($rssp_sel);
179 
180  $form->addItem($cb_prop);
181 
182  // Enable private news feed
183  $cb_prop = new ilCheckboxInputGUI($lng->txt("news_enable_private_feed"),
184  "enable_private_feed");
185  $cb_prop->setValue("1");
186  $cb_prop->setInfo($lng->txt("news_enable_private_feed_info"));
187  $cb_prop->setChecked($enable_private_feed);
188  $form->addItem($cb_prop);
189 
190  // Default Visibility
191  $radio_group = new ilRadioGroupInputGUI($lng->txt("news_default_visibility"), "news_default_visibility");
192  $radio_option = new ilRadioOption($lng->txt("news_visibility_users"), "users");
193  $radio_group->addOption($radio_option);
194  $radio_option = new ilRadioOption($lng->txt("news_visibility_public"), "public");
195  $radio_group->addOption($radio_option);
196  $radio_group->setInfo($lng->txt("news_news_item_visibility_info"));
197  $radio_group->setRequired(false);
198  $radio_group->setValue($news_default_visibility);
199  $form->addItem($radio_group);
200 
201  // Number of news items per object
202  $nr_opts = array(50 => 50, 100 => 100, 200 => 200);
203  $nr_sel = new ilSelectInputGUI($lng->txt("news_nr_of_items"),
204  "news_max_items");
205  $nr_sel->setInfo($lng->txt("news_nr_of_items_info"));
206  $nr_sel->setOptions($nr_opts);
207  $nr_sel->setValue($news_set->get("max_items"));
208  $form->addItem($nr_sel);
209 
210  // Access Cache
211  $min_opts = array(0 => 0, 1 => 1, 2 => 2, 5 => 5, 10 => 10, 20 => 20, 30 => 30, 60 => 60);
212  $min_sel = new ilSelectInputGUI($lng->txt("news_acc_cache"),
213  "news_acc_cache_mins");
214  $min_sel->setInfo($lng->txt("news_acc_cache_info"));
215  $min_sel->setOptions($min_opts);
216  $min_sel->setValue($news_set->get("acc_cache_mins"));
217  $form->addItem($min_sel);
218 
219  // PD News Period
220  $per_opts = array(
221  2 => "2 ".$lng->txt("days"),
222  3 => "3 ".$lng->txt("days"),
223  5 => "5 ".$lng->txt("days"),
224  7 => "1 ".$lng->txt("week"),
225  14 => "2 ".$lng->txt("weeks"),
226  30 => "1 ".$lng->txt("month"),
227  60 => "2 ".$lng->txt("months"),
228  120 => "4 ".$lng->txt("months"),
229  180 => "6 ".$lng->txt("months"),
230  366 => "1 ".$lng->txt("year"));
231  $per_sel = new ilSelectInputGUI($lng->txt("news_pd_period"),
232  "news_pd_period");
233  $per_sel->setInfo($lng->txt("news_pd_period_info"));
234  $per_sel->setOptions($per_opts);
235  $per_sel->setValue((int) ilNewsItem::_lookupDefaultPDPeriod());
236  $form->addItem($per_sel);
237 
238  // Allow user to choose lower values
239  $sp_prop = new ilCheckboxInputGUI($lng->txt("news_allow_shorter_periods"),
240  "allow_shorter_periods");
241  $sp_prop->setValue("1");
242  $sp_prop->setInfo($lng->txt("news_allow_shorter_periods_info"));
243  $sp_prop->setChecked($allow_shorter_periods);
244  $form->addItem($sp_prop);
245 
246  // Allow user to choose higher values
247  $lp_prop = new ilCheckboxInputGUI($lng->txt("news_allow_longer_periods"),
248  "allow_longer_periods");
249  $lp_prop->setValue("1");
250  $lp_prop->setInfo($lng->txt("news_allow_longer_periods_info"));
251  $lp_prop->setChecked($allow_longer_periods);
252  $form->addItem($lp_prop);
253 
254  // Section Header: External Web Feeds Settings
255  $sh = new ilFormSectionHeaderGUI();
256  $sh->setTitle($lng->txt("feed_settings"));
257  $form->addItem($sh);
258 
259  // Disable External Web Feeds in catetegories
260  $cb_prop = new ilCheckboxInputGUI($lng->txt("feed_disable_rep_feeds"),
261  "disable_repository_feeds");
262  $cb_prop->setValue("1");
263  $cb_prop->setInfo($lng->txt("feed_disable_rep_feeds_info"));
264  $cb_prop->setChecked($disable_repository_feeds);
265  $form->addItem($cb_prop);
266 
267  // Number of External Feeds on personal desktop
268  $sel = new ilSelectInputGUI($lng->txt("feed_nr_pd_feeds"), "nr_pd_feeds");
269  $sel->setInfo($lng->txt("feed_nr_pd_feeds_info"));
270  $sel->setOptions(array(0 => "0",
271  1 => "1",
272  2 => "2",
273  3 => "3",
274  4 => "4",
275  5 => "5"));
276  $sel->setValue($nr_personal_desktop_feeds);
277  $form->addItem($sel);
278 
279  // Proxy
280  $prox = new ilTextInputGUI($lng->txt("feed_proxy"), "proxy");
281  $prox->setInfo($lng->txt("feed_proxy_info"));
282  $prox->setValue($feed_set->get("proxy"));
283  $form->addItem($prox);
284 
285  // Proxy Port
286  $proxp = new ilTextInputGUI($lng->txt("feed_proxy_port"), "proxy_port");
287  $proxp->setInfo($lng->txt("feed_proxy_port_info"));
288  $proxp->setSize(10);
289  $proxp->setMaxLength(10);
290  $proxp->setValue($feed_set->get("proxy_port"));
291  $form->addItem($proxp);
292 
293  // command buttons
294  $form->addCommandButton("saveSettings", $lng->txt("save"));
295  $form->addCommandButton("view", $lng->txt("cancel"));
296 
297  $this->tpl->setContent($form->getHTML());
298  }
299 
303  public function saveSettings()
304  {
305  global $ilCtrl, $ilSetting;
306 
307  $news_set = new ilSetting("news");
308  $feed_set = new ilSetting("feed");
309  $ilSetting->set("block_activated_news", $_POST["enable_internal_news"]);
310  $ilSetting->set("block_activated_pdnews", $_POST["enable_internal_news"]);
311  $news_set->set("enable_rss_for_internal", $_POST["enable_internal_rss"]);
312  $news_set->set("max_items", $_POST["news_max_items"]);
313  $news_set->set("acc_cache_mins", $_POST["news_acc_cache_mins"]);
314  $news_set->set("pd_period", $_POST["news_pd_period"]);
315  $news_set->set("default_visibility", $_POST["news_default_visibility"]);
316  $news_set->set("allow_shorter_periods", $_POST["allow_shorter_periods"]);
317  $news_set->set("allow_longer_periods", $_POST["allow_longer_periods"]);
318  $news_set->set("rss_period", $_POST["news_rss_period"]);
319 
320  $feed_set->set("disable_rep_feeds", $_POST["disable_repository_feeds"]);
321  $ilSetting->set("block_limit_pdfeed", $_POST["nr_pd_feeds"]);
322  if ($_POST["nr_pd_feeds"] > 0)
323  {
324  $ilSetting->set("block_activated_pdfeed", 1);
325  }
326  else
327  {
328  $ilSetting->set("block_activated_pdfeed", 0);
329  }
330 
331  if ($_POST["enable_internal_rss"]!=0)
332  {
333  $news_set->set("enable_private_feed", $_POST["enable_private_feed"]);
334  }
335  else
336  {
337  $news_set->set("enable_private_feed", 0);
338  }
339  $feed_set->set("proxy", trim($_POST["proxy"]));
340  $feed_set->set("proxy_port", trim($_POST["proxy_port"]));
341 
342  ilUtil::sendInfo($this->lng->txt("settings_saved"),true);
343 
344  $ilCtrl->redirect($this, "view");
345  }
346 }
347 ?>