ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjNewsSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 include_once("./classes/class.ilObjectGUI.php");
4 
5 
17 {
18  private static $ERROR_MESSAGE;
24  public function __construct($a_data, $a_id, $a_call_by_reference = true, $a_prepare_output = true)
25  {
26  $this->type = 'nwss';
27  parent::ilObjectGUI($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
28 
29  $this->lng->loadLanguageModule('news');
30  $this->lng->loadLanguageModule('feed');
31 
32  }
33 
40  public function executeCommand()
41  {
42  global $rbacsystem,$ilErr,$ilAccess;
43 
44  $next_class = $this->ctrl->getNextClass($this);
45  $cmd = $this->ctrl->getCmd();
46 
47  $this->prepareOutput();
48 
49  if(!$ilAccess->checkAccess('read','',$this->object->getRefId()))
50  {
51  $ilErr->raiseError($this->lng->txt('no_permission'),$ilErr->WARNING);
52  }
53 
54  switch($next_class)
55  {
56  case 'ilpermissiongui':
57  $this->tabs_gui->setTabActive('perm_settings');
58  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
59  $perm_gui =& new ilPermissionGUI($this);
60  $ret =& $this->ctrl->forwardCommand($perm_gui);
61  break;
62 
63  default:
64  if(!$cmd || $cmd == 'view')
65  {
66  $cmd = "editSettings";
67  }
68 
69  $this->$cmd();
70  break;
71  }
72  return true;
73  }
74 
81  public function getAdminTabs()
82  {
83  global $rbacsystem, $ilAccess;
84 
85  if ($rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
86  {
87  $this->tabs_gui->addTarget("news_edit_news_settings",
88  $this->ctrl->getLinkTarget($this, "editSettings"),
89  array("editSettings", "view"));
90  }
91 
92  if ($rbacsystem->checkAccess('edit_permission',$this->object->getRefId()))
93  {
94  $this->tabs_gui->addTarget("perm_settings",
95  $this->ctrl->getLinkTargetByClass('ilpermissiongui',"perm"),
96  array(),'ilpermissiongui');
97  }
98  }
99 
103  public function editSettings()
104  {
105  global $ilCtrl, $lng, $ilSetting;
106 
107  $news_set = new ilSetting("news");
108  $feed_set = new ilSetting("feed");
109 
110  $enable_internal_news = $ilSetting->get("block_activated_news");
111  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
112  $enable_private_feed = $news_set->get("enable_private_feed");
113  $news_default_visibility = ($news_set->get("default_visibility") != "")
114  ? $news_set->get("default_visibility")
115  : "users";
116  $disable_repository_feeds = $feed_set->get("disable_rep_feeds");
117  $nr_personal_desktop_feeds = $ilSetting->get("block_limit_pdfeed");
118 
119  $allow_shorter_periods = $news_set->get("allow_shorter_periods");
120  $allow_longer_periods = $news_set->get("allow_longer_periods");
121 
122  include_once("./Services/News/classes/class.ilNewsItem.php");
123  $rss_period = ilNewsItem::_lookupRSSPeriod();
124 
125  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
126  $form = new ilPropertyFormGUI();
127  $form->setFormAction($ilCtrl->getFormAction($this));
128  $form->setTitle($lng->txt("news_settings"));
129 
130  // Enable internal news
131  $cb_prop = new ilCheckboxInputGUI($lng->txt("news_enable_internal_news"),
132  "enable_internal_news");
133  $cb_prop->setValue("1");
134  $cb_prop->setInfo($lng->txt("news_enable_internal_news_info"));
135  $cb_prop->setChecked($enable_internal_news);
136  $form->addItem($cb_prop);
137 
138  // Enable rss for internal news
139  $cb_prop = new ilCheckboxInputGUI($lng->txt("news_enable_internal_rss"),
140  "enable_internal_rss");
141  $cb_prop->setValue("1");
142  $cb_prop->setInfo($lng->txt("news_enable_internal_rss_info"));
143  $cb_prop->setChecked($enable_internal_rss);
144 
145  // RSS News Period
146  $rssp_opts = array(
147  2 => "2 ".$lng->txt("days"),
148  3 => "3 ".$lng->txt("days"),
149  5 => "5 ".$lng->txt("days"),
150  7 => "1 ".$lng->txt("week"),
151  14 => "2 ".$lng->txt("weeks"),
152  30 => "1 ".$lng->txt("month"),
153  60 => "2 ".$lng->txt("months"));
154  $rssp_sel = new ilSelectInputGUI($lng->txt("news_rss_period"),
155  "news_rss_period");
156  $rssp_sel->setOptions($rssp_opts);
157  $rssp_sel->setValue((int) $rss_period);
158  $cb_prop->addSubItem($rssp_sel);
159 
160  $form->addItem($cb_prop);
161 
162  // Enable private news feed
163  $cb_prop = new ilCheckboxInputGUI($lng->txt("news_enable_private_feed"),
164  "enable_private_feed");
165  $cb_prop->setValue("1");
166  $cb_prop->setInfo($lng->txt("news_enable_private_feed_info"));
167  $cb_prop->setChecked($enable_private_feed);
168  $form->addItem($cb_prop);
169 
170  // Default Visibility
171  $radio_group = new ilRadioGroupInputGUI($lng->txt("news_default_visibility"), "news_default_visibility");
172  $radio_option = new ilRadioOption($lng->txt("news_visibility_users"), "users");
173  $radio_group->addOption($radio_option);
174  $radio_option = new ilRadioOption($lng->txt("news_visibility_public"), "public");
175  $radio_group->addOption($radio_option);
176  $radio_group->setInfo($lng->txt("news_news_item_visibility_info"));
177  $radio_group->setRequired(false);
178  $radio_group->setValue($news_default_visibility);
179  $form->addItem($radio_group);
180 
181  // Number of news items per object
182  $nr_opts = array(50 => 50, 100 => 100, 200 => 200);
183  $nr_sel = new ilSelectInputGUI($lng->txt("news_nr_of_items"),
184  "news_max_items");
185  $nr_sel->setInfo($lng->txt("news_nr_of_items_info"));
186  $nr_sel->setOptions($nr_opts);
187  $nr_sel->setValue($news_set->get("max_items"));
188  $form->addItem($nr_sel);
189 
190  // Access Cache
191  $min_opts = array(0 => 0, 1 => 1, 2 => 2, 5 => 5, 10 => 10, 20 => 20, 30 => 30, 60 => 60);
192  $min_sel = new ilSelectInputGUI($lng->txt("news_cache"),
193  "news_acc_cache_mins");
194  $min_sel->setInfo($lng->txt("news_cache_info"));
195  $min_sel->setOptions($min_opts);
196  $min_sel->setValue($news_set->get("acc_cache_mins"));
197  $form->addItem($min_sel);
198 
199  // PD News Period
200  $per_opts = array(
201  2 => "2 ".$lng->txt("days"),
202  3 => "3 ".$lng->txt("days"),
203  5 => "5 ".$lng->txt("days"),
204  7 => "1 ".$lng->txt("week"),
205  14 => "2 ".$lng->txt("weeks"),
206  30 => "1 ".$lng->txt("month"),
207  60 => "2 ".$lng->txt("months"),
208  120 => "4 ".$lng->txt("months"),
209  180 => "6 ".$lng->txt("months"),
210  366 => "1 ".$lng->txt("year"));
211  $per_sel = new ilSelectInputGUI($lng->txt("news_pd_period"),
212  "news_pd_period");
213  $per_sel->setInfo($lng->txt("news_pd_period_info"));
214  $per_sel->setOptions($per_opts);
215  $per_sel->setValue((int) ilNewsItem::_lookupDefaultPDPeriod());
216  $form->addItem($per_sel);
217 
218  // Allow user to choose lower values
219  $sp_prop = new ilCheckboxInputGUI($lng->txt("news_allow_shorter_periods"),
220  "allow_shorter_periods");
221  $sp_prop->setValue("1");
222  $sp_prop->setInfo($lng->txt("news_allow_shorter_periods_info"));
223  $sp_prop->setChecked($allow_shorter_periods);
224  $form->addItem($sp_prop);
225 
226  // Allow user to choose higher values
227  $lp_prop = new ilCheckboxInputGUI($lng->txt("news_allow_longer_periods"),
228  "allow_longer_periods");
229  $lp_prop->setValue("1");
230  $lp_prop->setInfo($lng->txt("news_allow_longer_periods_info"));
231  $lp_prop->setChecked($allow_longer_periods);
232  $form->addItem($lp_prop);
233 
234  // Section Header: External Web Feeds Settings
235  $sh = new ilFormSectionHeaderGUI();
236  $sh->setTitle($lng->txt("feed_settings"));
237  $form->addItem($sh);
238 
239  // Disable External Web Feeds in catetegories
240  $cb_prop = new ilCheckboxInputGUI($lng->txt("feed_disable_rep_feeds"),
241  "disable_repository_feeds");
242  $cb_prop->setValue("1");
243  $cb_prop->setInfo($lng->txt("feed_disable_rep_feeds_info"));
244  $cb_prop->setChecked($disable_repository_feeds);
245  $form->addItem($cb_prop);
246 
247  // Number of External Feeds on personal desktop
248  $sel = new ilSelectInputGUI($lng->txt("feed_nr_pd_feeds"), "nr_pd_feeds");
249  $sel->setInfo($lng->txt("feed_nr_pd_feeds_info"));
250  $sel->setOptions(array(0 => "0",
251  1 => "1",
252  2 => "2",
253  3 => "3",
254  4 => "4",
255  5 => "5"));
256  $sel->setValue($nr_personal_desktop_feeds);
257  $form->addItem($sel);
258 
259  // Proxy
260  $prox = new ilTextInputGUI($lng->txt("feed_proxy"), "proxy");
261  $prox->setInfo($lng->txt("feed_proxy_info"));
262  $prox->setValue($feed_set->get("proxy"));
263  $form->addItem($prox);
264 
265  // Proxy Port
266  $proxp = new ilTextInputGUI($lng->txt("feed_proxy_port"), "proxy_port");
267  $proxp->setInfo($lng->txt("feed_proxy_port_info"));
268  $proxp->setSize(10);
269  $proxp->setMaxLength(10);
270  $proxp->setValue($feed_set->get("proxy_port"));
271  $form->addItem($proxp);
272 
273  // command buttons
274  $form->addCommandButton("saveSettings", $lng->txt("save"));
275  $form->addCommandButton("view", $lng->txt("cancel"));
276 
277  $this->tpl->setContent($form->getHTML());
278  }
279 
283  public function saveSettings()
284  {
285  global $ilCtrl, $ilSetting;
286 
287  // empty news cache
288  include_once("./Services/News/classes/class.ilNewsCache.php");
289  $this->acache = new ilNewsCache();
290  $this->acache->deleteAllEntries();
291 
292  $news_set = new ilSetting("news");
293  $feed_set = new ilSetting("feed");
294  $ilSetting->set("block_activated_news", $_POST["enable_internal_news"]);
295  $ilSetting->set("block_activated_pdnews", $_POST["enable_internal_news"]);
296  $news_set->set("enable_rss_for_internal", $_POST["enable_internal_rss"]);
297  $news_set->set("max_items", $_POST["news_max_items"]);
298  $news_set->set("acc_cache_mins", $_POST["news_acc_cache_mins"]);
299  $news_set->set("pd_period", $_POST["news_pd_period"]);
300  $news_set->set("default_visibility", $_POST["news_default_visibility"]);
301  $news_set->set("allow_shorter_periods", $_POST["allow_shorter_periods"]);
302  $news_set->set("allow_longer_periods", $_POST["allow_longer_periods"]);
303  $news_set->set("rss_period", $_POST["news_rss_period"]);
304 
305  $feed_set->set("disable_rep_feeds", $_POST["disable_repository_feeds"]);
306  $ilSetting->set("block_limit_pdfeed", $_POST["nr_pd_feeds"]);
307  if ($_POST["nr_pd_feeds"] > 0)
308  {
309  $ilSetting->set("block_activated_pdfeed", 1);
310  }
311  else
312  {
313  $ilSetting->set("block_activated_pdfeed", 0);
314  }
315 
316  if ($_POST["enable_internal_rss"]!=0)
317  {
318  $news_set->set("enable_private_feed", $_POST["enable_private_feed"]);
319  }
320  else
321  {
322  $news_set->set("enable_private_feed", 0);
323  }
324  $feed_set->set("proxy", trim($_POST["proxy"]));
325  $feed_set->set("proxy_port", trim($_POST["proxy_port"]));
326 
327  ilUtil::sendSuccess($this->lng->txt("settings_saved"),true);
328 
329  $ilCtrl->redirect($this, "view");
330  }
331 }
332 ?>