ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilShopNewsGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4
5include_once 'Services/Payment/classes/class.ilShopBaseGUI.php';
6include_once 'Services/Payment/classes/class.ilShopNewsItem.php';
7include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
8
9
18{
19 private $form_gui = null;
20 private $settings_form = null;
21 private $oCurrentNewsItem = null;
22
23 public $ilErr = null;
24
25 public function __construct()
26 {
27 global $ilErr;
28 parent::__construct();
29
30 $this->oCurrentNewsItem = new ilShopNewsItem((int)$_GET['news_id']);
31
32 $this->lng->loadLanguageModule('news');
33 $this->ilErr = $ilErr;
34 }
35
36 public function executeCommand()
37 {
38// $next_class = $this->ctrl->getNextClass($this);
39 $cmd = $this->ctrl->getCmd();
40
41 switch($cmd)
42 {
43 default:
44 if(!$cmd)
45 {
46 $cmd = 'showNews';
47 }
48 $this->prepareOutput();
49 $this->$cmd();
50 break;
51 }
52
53 return true;
54 }
55
56 protected function buildSubTabs()
57 {
58 global $ilTabs, $ilUser, $rbacreview;
59
60 $ilTabs->addSubTabTarget('news', $this->ctrl->getLinkTarget($this, 'showNews'), '', '', '','showNews');
61 $ilTabs->addSubTabTarget('archive', $this->ctrl->getLinkTarget($this, 'showArchive'), '', '', '','archive');
62
63 if($rbacreview->isAssigned($ilUser->getId(), SYSTEM_ROLE_ID))
64 {
65 $ilTabs->addSubTabTarget('settings', $this->ctrl->getLinkTarget($this, 'showSettings'), '', '', '','settings');
66 }
67 }
68
69 public function saveSettings()
70 {
71 global $ilTabs, $ilSetting, $rbacreview, $ilUser;
72
73 if(!$rbacreview->isAssigned($ilUser->getId(), SYSTEM_ROLE_ID))
74 {
75 $this->ilErr->raiseError($this->lng->txt('permission_denied'), $this->ilErr->MESSAGE);
76 }
77
78 $ilTabs->setSubTabActive('settings');
79
80 $this->initSettingsForm('edit');
81 if($this->settings_form->checkInput())
82 {
83 $ilSetting->set('payment_news_archive_period', $this->settings_form->getInput('archive_period'));
84 $this->getSettingsValues();
85 ilUtil::sendInfo($this->lng->txt('payment_news_settings_saved'));
86
87 return $this->tpl->setVariable('ADM_CONTENT', $this->settings_form->getHtml());
88 }
89 else
90 {
91 $this->form_gui->setValuesByPost();
92 return $this->tpl->setVariable('ADM_CONTENT', $this->settings_form->getHtml());
93 }
94 }
95
96 public function initSettingsForm($a_mode = 'edit')
97 {
98
99 $this->settings_form = new ilPropertyFormGUI();
100 $this->settings_form->setTitle($this->lng->txt('payment_news_settings'));
101
102 $oSelectBox = new ilSelectInputGUI($this->lng->txt('payment_news_archive_period'), 'archive_period');
103 $oSelectBox->setInfo($this->lng->txt('payment_news_archive_period_info'));
104 $options = array();
105 for($i = 5; $i <= 100; $i += 5)
106 {
107 $options[$i] = $i;
108 }
109 $oSelectBox->setOptions($options);
110 $this->settings_form->addItem($oSelectBox);
111
112 $this->settings_form->addCommandButton('saveSettings', $this->lng->txt('save'));
113 $this->settings_form->addCommandButton('showNews', $this->lng->txt('cancel'));
114 $this->settings_form->setFormAction($this->ctrl->getFormaction($this, 'saveSettings'));
115 }
116
117 public function showSettings()
118 {
119 global $ilTabs, $ilUser, $rbacreview;
120
121 if(!$rbacreview->isAssigned($ilUser->getId(), SYSTEM_ROLE_ID))
122 {
123 $this->ilErr->raiseError($this->lng->txt('permission_denied'),$this->ilErr->MESSAGE);
124 }
125
126 $ilTabs->setSubTabActive('settings');
127
128 $this->initSettingsForm('edit');
129 $this->getSettingsValues();
130
131 return $this->tpl->setVariable('ADM_CONTENT', $this->settings_form->getHtml());
132 }
133
134 public function saveNews()
135 {
136 global $ilUser, $rbacreview;
137
138 if(!$rbacreview->isAssigned($ilUser->getId(), SYSTEM_ROLE_ID))
139 {
140 $this->ilErr->raiseError($this->lng->txt('permission_denied'),$this->ilErr->MESSAGE);
141 }
142
143 $this->initNewsForm('create');
144 if ($this->form_gui->checkInput())
145 {
146 $this->oCurrentNewsItem->setTitle($this->form_gui->getInput('news_title'));
147 $this->oCurrentNewsItem->setContent($this->form_gui->getInput('news_content'));
148 $this->oCurrentNewsItem->setVisibility($this->form_gui->getInput('news_visibility'));
149 $this->oCurrentNewsItem->setUserId($ilUser->getId());
150 $this->oCurrentNewsItem->create();
151
152 ilUtil::sendInfo($this->lng->txt('payment_news_created'));
153 return $this->showNews();
154 }
155 else
156 {
157 $this->form_gui->setValuesByPost();
158 return $this->tpl->setVariable('ADM_CONTENT', $this->form_gui->getHtml());
159 }
160 }
161
162 public function updateArchiveNews()
163 {
164 return $this->update('archive');
165 }
166
167 public function updateNews()
168 {
169 return $this->update('news');
170 }
171
172 public function update($view)
173 {
174 global $ilUser, $rbacreview;
175
176 if(!$rbacreview->isAssigned($ilUser->getId(), SYSTEM_ROLE_ID))
177 {
178 $this->ilErr->raiseError($this->lng->txt('permission_denied'),$this->ilErr->MESSAGE);
179 }
180
181 $this->initNewsForm('edit', $view);
182
183 if ($this->form_gui->checkInput())
184 {
185 $this->oCurrentNewsItem->setTitle($this->form_gui->getInput('news_title'));
186 $this->oCurrentNewsItem->setContent($this->form_gui->getInput('news_content'));
187 $this->oCurrentNewsItem->setVisibility($this->form_gui->getInput('news_visibility'));
188 $this->oCurrentNewsItem->setUserId($ilUser->getId());
189
190 $this->oCurrentNewsItem->update();
191
192 ilUtil::sendInfo($this->lng->txt('payment_news_updated'));
193
194 if($view == 'archive')
195 {
196 return $this->showArchive();
197 }
198 else
199 {
200 return $this->showNews();
201 }
202
203 }
204 else
205 {
206 $this->form_gui->setValuesByPost();
207 return $this->tpl->setVariable('ADM_CONTENT', $this->form_gui->getHtml());
208 }
209 }
210
211 public function performDeleteNews()
212 {
213 return $this->performDelete('news');
214 }
215
216 public function performDeleteArchiveNews()
217 {
218 return $this->performDelete('archive');
219 }
220
221 public function performDelete($view)
222 {
223 global $ilUser, $rbacreview;
224
225 if(!$rbacreview->isAssigned($ilUser->getId(), SYSTEM_ROLE_ID))
226 {
227 $this->ilErr->raiseError($this->lng->txt('permission_denied'),$this->ilErr->MESSAGE);
228 }
229
230 if(!(int)$_POST['news_id'])
231 {
232 ilUtil::sendInfo($this->lng->txt('payment_news_missing_id'));
233 switch($view)
234 {
235 case 'archive':
236 return $this->showArchive();
237 break;
238
239 case 'news':
240 default:
241 return $this->showNews();
242 break;
243 }
244 }
245 else
246 {
247 $this->oCurrentNewsItem->setId($_POST['news_id']);
248 $this->oCurrentNewsItem->delete();
249 ilUtil::sendInfo($this->lng->txt('payment_news_deleted'));
250 }
251
252 switch($view)
253 {
254 case 'archive':
255 return $this->showArchive();
256 break;
257
258 case 'news':
259 default:
260 return $this->showNews();
261 break;
262 }
263 }
264
265 public function confirmDeleteNews()
266 {
267 $this->confirmDelete('news');
268 }
269
270 public function confirmDeleteArchiveNews()
271 {
272 $this->confirmDelete('archive');
273 }
274
275 public function confirmDelete($view)
276 {
277 global $ilUser, $rbacreview;
278
279 if(!$rbacreview->isAssigned($ilUser->getId(), SYSTEM_ROLE_ID))
280 {
281 $this->ilErr->raiseError($this->lng->txt('permission_denied'),$this->ilErr->MESSAGE);
282 }
283
284 if(!isset($_GET['news_id']))
285 {
286 ilUtil::sendInfo($this->lng->txt('payment_news_missing_id'));
287 switch($view)
288 {
289 case 'archive':
290 return $this->showArchive();
291 break;
292
293 case 'news':
294 default:
295 return $this->showNews();
296 break;
297 }
298 }
299
300 include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
301 $c_gui = new ilConfirmationGUI();
302 $c_gui->setHeaderText($this->lng->txt('payment_news_delete_sure'));
303 $c_gui->addHiddenItem('news_id', (int)$_GET['news_id']);
304
305 $oNewsItem = new ilShopNewsItem($_GET['news_id']);
306 $title=$oNewsItem->getTitle();
307 $c_gui->addItem($title, $_GET['news_id'],$title);
308
309
310 switch($view)
311 {
312 case 'archive':
313 $c_gui->setFormAction($this->ctrl->getFormAction($this, 'performDeleteArchiveNews'));
314 $c_gui->setConfirm($this->lng->txt('confirm'), 'performDeleteArchiveNews');
315 $c_gui->setCancel($this->lng->txt('cancel'), 'showArchive');
316 $this->showArchive($c_gui->getHTML());
317 break;
318
319 case 'news':
320 default:
321 $c_gui->setFormAction($this->ctrl->getFormAction($this, 'performDeleteNews'));
322 $c_gui->setConfirm($this->lng->txt('confirm'), 'performDeleteNews');
323 $c_gui->setCancel($this->lng->txt('cancel'), 'showNews');
324 $this->showNews($c_gui->getHTML());
325 break;
326 }
327
328 return true;
329 }
330
331 public function initNewsForm($a_mode = 'create', $view = 'news')
332 {
333 global $ilTabs, $rbacreview, $ilUser;
334
335 if(!$rbacreview->isAssigned($ilUser->getId(), SYSTEM_ROLE_ID))
336 {
337 $this->ilErr->raiseError($this->lng->txt('permission_denied'),$this->ilErr->MESSAGE);
338 }
339
340 if($view == 'archive')
341 {
342 $ilTabs->setSubTabActive('archive');
343 }
344 else
345 {
346 $ilTabs->setSubTabActive('news');
347 }
348
349 $this->form_gui = new ilPropertyFormGUI();
350 $this->form_gui->setTitle($this->lng->txt('shopnews_settings'));
351
352 // Property Title
353 $text_input = new ilTextInputGUI($this->lng->txt('news_news_item_title'), 'news_title');
354 $text_input->setInfo('');
355 $text_input->setRequired(true);
356 $text_input->setMaxLength(200);
357 $text_input->setSize(93);
358
359 $this->form_gui->addItem($text_input);
360
361 // Property Content
362 $text_area = new ilTextAreaInputGUI($this->lng->txt('news_news_item_content'), 'news_content');
363 $text_area->setInfo('');
364 $text_area->setRequired(false);
365 $text_area->setCols(90);
366 $text_area->setRows(10);
367 $this->form_gui->addItem($text_area);
368
369 // Property Visibility
370 $radio_group = new ilRadioGroupInputGUI($this->lng->txt('news_news_item_visibility'), 'news_visibility');
371 $radio_option = new ilRadioOption($this->lng->txt('news_visibility_users'), 'users');
372 $radio_group->addOption($radio_option);
373 $radio_option = new ilRadioOption($this->lng->txt('news_visibility_public'), 'public');
374 $radio_group->addOption($radio_option);
375 $radio_group->setInfo($this->lng->txt('news_news_item_visibility_info'));
376 $radio_group->setRequired(false);
377 $radio_group->setValue('users');
378 $this->form_gui->addItem($radio_group);
379
380 // save and cancel commands
381 if($a_mode == 'create')
382 {
383 $this->form_gui->addCommandButton('saveNews', $this->lng->txt('save'));
384 $this->form_gui->addCommandButton('showNews', $this->lng->txt('cancel'));
385 $this->form_gui->setFormAction($this->ctrl->getFormAction($this, 'saveNews'));
386 }
387 else
388 {
389 $this->ctrl->setParameter($this, 'news_id', $this->oCurrentNewsItem->getId());
390
391 if($view == 'archive')
392 {
393 $this->form_gui->addCommandButton('updateArchiveNews', $this->lng->txt('save'));
394 $this->form_gui->addCommandButton('showArchive', $this->lng->txt('cancel'));
395 $this->form_gui->setFormAction($this->ctrl->getFormAction($this, 'updateArchiveNews'));
396 }
397 else
398 {
399 $this->form_gui->addCommandButton('updateNews', $this->lng->txt('save'));
400 $this->form_gui->addCommandButton('showNews', $this->lng->txt('cancel'));
401 $this->form_gui->setFormAction($this->ctrl->getFormAction($this, 'updateNews'));
402 }
403 }
404
405 $this->form_gui->setTitle($this->lng->txt('news_news_item_head'));
406 $this->tpl->setVariable('ADM_CONTENT', $this->form_gui->getHtml());
407 }
408
409 public function addNewsForm()
410 {
411 $this->initNewsForm('create');
412 $this->tpl->setVariable('ADM_CONTENT', $this->form_gui->getHtml());
413 }
414
415 public function editNews()
416 {
417 return $this->editNewsForm('news');
418 }
419
420 public function editArchiveNews()
421 {
422 return $this->editNewsForm('archive');
423 }
424
425 public function editNewsForm($view)
426 {
427 $this->initNewsForm('edit', $view);
428 $this->getPropertiesValues();
429 $this->tpl->setVariable('ADM_CONTENT', $this->form_gui->getHtml());
430 }
431
432 public function getPropertiesValues()
433 {
434 $this->form_gui->setValuesByArray(array(
435 'news_creation_date' => $this->oCurrentNewsItem->getCreationDate(),
436 'news_title' => $this->oCurrentNewsItem->getTitle(),
437 'news_content' => $this->oCurrentNewsItem->getContent(),
438 'news_visibility' =>$this->oCurrentNewsItem->getVisibility()
439 ));
440 }
441
442 public function getSettingsValues()
443 {
444 global $ilSetting;
445
446 $this->settings_form->setValuesByArray(array(
447 'archive_period' => $ilSetting->get('payment_news_archive_period')
448 ));
449 }
450
451 public function showNews($confirmation_gui = '')
452 {
453 global $ilUser, $tpl, $ilTabs, $ilSetting, $rbacreview, $ilToolbar;
454
455 $ilTabs->setSubTabActive('news');
456
457 include_once 'Services/Payment/classes/class.ilShopNewsItemList.php';
458 include_once 'Services/Table/classes/class.ilTable2GUI.php';
459
460 if($rbacreview->isAssigned($ilUser->getId(), SYSTEM_ROLE_ID) == true)
461 {
462 $ilToolbar->addButton($this->lng->txt('payment_news_add_news'), $this->ctrl->getLinkTarget($this, 'addNewsForm'));
463 }
464
465 $news_tpl = new ilTemplate('tpl.main_view.html', true, true, 'Services/Payment');
466
467 if((int)strlen($confirmation_gui))
468 {
469 $news_tpl->setVariable('CONFIRMATION', $confirmation_gui);
470 }
471
472 $tbl = new ilTable2GUI($this);
473 $tbl->setId('shop_news_tbl');
474 $tbl->setTitle($this->lng->txt('news'), 0, $this->lng->txt('news'));
475 $tbl->setRowTemplate('tpl.shop_news_row.html', 'Services/Payment');
476 $tbl->setFormAction($this->ctrl->getFormAction($this), 'showNews');
477 $tbl->addColumn($this->lng->txt('news'), 'title', '100%');
478
480 $oNewsList->setMode(ilShopNewsItemList::TYPE_NEWS)
481 ->setPublicSection($ilUser->getId() == ANONYMOUS_USER_ID)
482 ->setArchiveDate(time() - ($ilSetting->get('payment_news_archive_period') * 24 * 60 * 60))
483 ->read();
484
485 $result = array();
486 if($oNewsList->hasItems())
487 {
488 $tbl->setEnableHeader(true);
489 $tbl->setEnableTitle(true);
490
491 $counter = 0;
492 foreach($oNewsList as $entry)
493 {
494 if($rbacreview->isAssigned($ilUser->getId(), SYSTEM_ROLE_ID) == true)
495 {
496 $this->ctrl->setParameter($this, 'news_id', $entry->getId());
497
498 $result[$counter]['news_id'] = $entry->getId();
499 $result[$counter]['edit_src'] = $this->ctrl->getLinkTarget($this, 'editNews');
500 $result[$counter]['edit_txt'] = $this->lng->txt('edit');
501 $result[$counter]['delete_src'] = $this->ctrl->getLinkTarget($this, 'confirmDeleteNews');
502 $result[$counter]['delete_txt'] = $this->lng->txt('delete');
503
504 $this->ctrl->clearParameters($this);
505 }
506
507 $result[$counter]['title'] = $entry->getTitle();
508 $result[$counter]['content'] = $entry->getContent();
509 $result[$counter]['user_id'] = $entry->getUserId();
510
511 $result[$counter]['txt_author'] = $this->lng->txt('author');
512 $result[$counter]['author'] = $ilUser->getLogin();
513
514 $result[$counter]['txt_creation_date'] = $this->lng->txt('create_date');
515 $result[$counter]['creation_date'] = ilDatePresentation::formatDate(
516 new ilDateTime($entry->getCreationDate(), IL_CAL_DATETIME));
517
518 $result[$counter]['txt_update_date'] = $this->lng->txt('last_update');
519 $result[$counter]['update_date'] = ilDatePresentation::formatDate(
520 new ilDateTime($entry->getUpdateDate(), IL_CAL_DATETIME));
521
522 $result[$counter]['txt_access'] = $this->lng->txt('access');
523 $result[$counter]['access'] = $entry->getVisibility();
524
525 ++$counter;
526 }
527 }
528 else
529 {
530
531 $tbl->setNoEntriesText($this->lng->txt('payment_news_no_news_items'));
532 }
533
534 $tbl->setData($result);
535 $news_tpl->setVariable('TABLE', $tbl->getHTML());
536 $tpl->setContent($news_tpl->get());
537 }
538
539 public function showArchive($confirmation_gui = '')
540 {
541 global $ilUser, $tpl, $ilTabs, $ilSetting, $rbacreview;
542
543 $ilTabs->setSubTabActive('archive');
544
545 include_once 'Services/Payment/classes/class.ilShopNewsItemList.php';
546 include_once 'Services/Table/classes/class.ilTable2GUI.php';
547
548 $news_tpl = new ilTemplate('tpl.main_view.html', true, true, 'Services/Payment');
549
550 if((int)strlen($confirmation_gui))
551 {
552 $news_tpl->setVariable('CONFIRMATION', $confirmation_gui);
553 }
554
555 $tbl = new ilTable2GUI($this);
556 $tbl->setId('shop_news_archive_tbl');
557 $tbl->setTitle($this->lng->txt('archive'), 0 ,$this->lng->txt('news'));
558 $tbl->setRowTemplate('tpl.shop_news_row.html', 'Services/Payment');
559 $tbl->setFormAction($this->ctrl->getFormAction($this), 'showArchive');
560 $tbl->addColumn($this->lng->txt('archive'), 'title', '100%');
561
563 $oNewsList->setMode(ilShopNewsItemList::TYPE_ARCHIVE)
564 ->setPublicSection($ilUser->getId() == ANONYMOUS_USER_ID)
565 ->setArchiveDate(time() - ($ilSetting->get('payment_news_archive_period') * 24 * 60 * 60))
566 ->read();
567 $result = array();
568 if($oNewsList->hasItems())
569 {
570 $tbl->setEnableTitle(true);
571 $tbl->setEnableHeader(true);
572
573 $counter = 0;
574 foreach($oNewsList as $entry)
575 {
576 if($entry->getVisibility() != 'public' && $ilUser->getId() == ANONYMOUS_USER_ID) continue;
577 if(strtotime($entry->getCreationDate()) > time() - ($ilSetting->get('payment_news_archive_period') * 24 * 60 * 60)) continue;
578
579 if($rbacreview->isAssigned($ilUser->getId(), SYSTEM_ROLE_ID) == true)
580 {
581 $this->ctrl->setParameter($this, 'news_id', $entry->getId());
582
583 $result[$counter]['news_id']= $entry->getId();
584 $result[$counter]['edit_src'] = $this->ctrl->getLinkTarget($this, 'editArchiveNews');
585 $result[$counter]['edit_txt'] = $this->lng->txt('edit');
586 $result[$counter]['delete_src'] = $this->ctrl->getLinkTarget($this, 'confirmDeleteArchiveNews');
587 $result[$counter]['delete_txt'] = $this->lng->txt('delete');
588
589 $this->ctrl->clearParameters($this);
590 }
591
592 $result[$counter]['creation_date'] = ilDatePresentation::formatDate(
593 new ilDateTime($entry->getCreationDate(), IL_CAL_DATETIME));
594 $result[$counter]['title'] = $entry->getTitle();
595 $result[$counter]['content'] = $entry->getContent();
596 $result[$counter]['user_id'] = $entry->getUserId();
597
598 $result[$counter]['author'] = $ilUser->getLogin();
599 $result[$counter]['creation_date'] = ilDatePresentation::formatDate(
600 new ilDateTime($entry->getCreationDate(), IL_CAL_DATETIME));
601
602 $result[$counter]['update_date'] = ilDatePresentation::formatDate(
603 new ilDateTime($entry->getCreationDate(), IL_CAL_DATETIME));
604
605 $result[$counter]['txt_author'] = $this->lng->txt('author');
606 $result[$counter]['txt_creation_date'] = $this->lng->txt('create_date');
607 $result[$counter]['txt_update_date'] = $this->lng->txt('last_update');
608
609 $this->ctrl->clearParameters($this);
610
611 ++$counter;
612 }
613 }
614 else
615 {
616 $tbl->setNoEntriesText($this->lng->txt('payment_news_no_news_items'));
617 }
618 $tbl->setData($result);
619 $news_tpl->setVariable('TABLE', $tbl->getHTML());
620 $tpl->setContent($news_tpl->get());
621 }
622
623 protected function prepareOutput()
624 {
625 global $ilTabs;
626
627 parent::prepareOutput();
628
629 $ilTabs->setTabActive('payment_news');
630
631 }
632}
633?>
$result
$_GET["client_id"]
const IL_CAL_DATETIME
Confirmation screen class.
static formatDate(ilDateTime $date)
Format a date @access public.
@classDescription Date and time handling
This class represents a property form user interface.
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a selection list property in a property form.
Class ilShopBaseGUI.
Class ilShopNewsGUI.
showNews($confirmation_gui='')
initSettingsForm($a_mode='edit')
initNewsForm($a_mode='create', $view='news')
showArchive($confirmation_gui='')
Class ilTable2GUI.
special template class to simplify handling of ITX/PEAR
This class represents a text area property in a property form.
This class represents a text property in a property form.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$_POST['username']
Definition: cron.php:12
$tbl
Definition: example_048.php:81
global $ilSetting
Definition: privfeed.php:40
$cmd
Definition: sahs_server.php:35
if(!is_array($argv)) $options
global $ilUser
Definition: imgupload.php:15