ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjLinkResourceGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 require_once "./Services/Object/classes/class.ilObject2GUI.php";
6 include_once('./Modules/WebResource/classes/class.ilParameterAppender.php');
7 require_once 'Services/LinkChecker/interfaces/interface.ilLinkCheckerGUIRowHandling.php';
8 
22 {
23  const VIEW_MODE_VIEW = 1;
24  const VIEW_MODE_MANAGE = 2;
25  const VIEW_MODE_SORT = 3;
26 
27  const LINK_MOD_CREATE = 1;
28  const LINK_MOD_EDIT = 2;
29  const LINK_MOD_ADD = 3;
30 
31  function getType()
32  {
33  return "webr";
34  }
35 
36  public function executeCommand()
37  {
38  global $ilCtrl, $ilTabs, $ilErr, $ilAccess;
39 
40 
41  //if($this->ctrl->getTargetScript() == 'link_resources.php')
42  if($_GET["baseClass"] == 'ilLinkResourceHandlerGUI')
43  {
44  $_GET['view_mode'] = isset($_GET['switch_mode']) ? $_GET['switch_mode'] : $_GET['view_mode'];
45  $ilCtrl->saveParameter($this, 'view_mode');
46  $this->__prepareOutput();
47  }
48 
49  $this->lng->loadLanguageModule("webr");
50 
51  $next_class = $this->ctrl->getNextClass($this);
52  $cmd = $this->ctrl->getCmd();
53 
54  switch($next_class)
55  {
56  case "ilinfoscreengui":
57  $this->infoScreenForward(); // forwards command
58  break;
59 
60  case 'ilmdeditorgui':
61  if(!$ilAccess->checkAccess('write','',$this->object->getRefId()))
62  {
63  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->WARNING);
64  }
65 
66  $this->prepareOutput();
67  $ilTabs->activateTab('id_meta_data');
68  include_once 'Services/MetaData/classes/class.ilMDEditorGUI.php';
69  $md_gui =& new ilMDEditorGUI($this->object->getId(), 0, $this->object->getType());
70  $md_gui->addObserver($this->object,'MDUpdateListener','General');
71  $this->ctrl->forwardCommand($md_gui);
72  break;
73 
74  case 'ilpermissiongui':
75  $this->prepareOutput();
76  $ilTabs->activateTab('id_permissions');
77  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
78  $perm_gui =& new ilPermissionGUI($this);
79  $ret =& $this->ctrl->forwardCommand($perm_gui);
80  break;
81 
82  case 'ilobjectcopygui':
83  $this->prepareOutput();
84  include_once './Services/Object/classes/class.ilObjectCopyGUI.php';
85  $cp = new ilObjectCopyGUI($this);
86  $cp->setType('webr');
87  $this->ctrl->forwardCommand($cp);
88  break;
89 
90  case 'ilexportgui':
91  $this->prepareOutput();
92  $this->tabs_gui->setTabActive('export');
93  include_once './Services/Export/classes/class.ilExportGUI.php';
94  $exp = new ilExportGUI($this);
95  $exp->addFormat('xml');
96  $this->ctrl->forwardCommand($exp);
97  break;
98 
99  case "ilcommonactiondispatchergui":
100  include_once("Services/Object/classes/class.ilCommonActionDispatcherGUI.php");
102  $this->ctrl->forwardCommand($gui);
103  break;
104 
105  default:
106  if(!$cmd)
107  {
108  $this->ctrl->setCmd("view");
109  }
111  }
112 
113  if(!$this->getCreationMode())
114  {
115  // Fill meta header tags
116  include_once('Services/MetaData/classes/class.ilMDUtils.php');
117  ilMDUtils::_fillHTMLMetaTags($this->object->getId(),$this->object->getId(),'webr');
118 
119  $this->addHeaderAction();
120  }
121  return true;
122  }
123 
124  protected function initCreateForm($a_new_type)
125  {
126  $this->initFormLink(self::LINK_MOD_CREATE);
127  return $this->form;
128  }
129 
134  public function save()
135  {
136  global $ilCtrl;
137 
138  $this->initFormLink(self::LINK_MOD_CREATE);
139  if($this->checkLinkInput(self::LINK_MOD_CREATE,0,0))
140  {
141  // Save new object
142  $_POST['title'] = $_POST['tit'];
143  $_POST['desc'] = $_POST['des'];
144  parent::save();
145  }
146  else
147  {
148  // Data incomplete or invalid
149  ilUtil::sendFailure($this->lng->txt('err_check_input'));
150  $this->form->setValuesByPost();
151  $this->tpl->setContent($this->form->getHTML());
152  }
153  }
154 
155  protected function afterSave(ilObject $a_new_object)
156  {
157  // Save link
158  $this->link->setLinkResourceId($a_new_object->getId());
159  $link_id = $this->link->add();
160 
161  // Dynamic params
162  if(ilParameterAppender::_isEnabled() and is_object($this->dynamic))
163  {
164  $this->dynamic->setObjId($a_new_object->getId());
165  $this->dynamic->add($link_id);
166  }
167 
168  ilUtil::sendSuccess($this->lng->txt('webr_link_added'));
169 
170  // personal workspace
171  if($this->id_type == self::WORKSPACE_NODE_ID)
172  {
173  $this->ctrl->redirect($this, "editLinks");
174  }
175  // repository
176  else
177  {
178  ilUtil::redirect("ilias.php?baseClass=ilLinkResourceHandlerGUI&ref_id=".
179  $a_new_object->getRefId()."&cmd=view");
180  }
181  }
182 
188  protected function settings()
189  {
190  global $ilTabs;
191 
192  $this->checkPermission('write');
193  $ilTabs->activateTab('id_settings');
194 
195  $this->initFormSettings();
196  $this->tpl->setContent($this->form->getHTML());
197  }
198 
203  protected function saveSettings()
204  {
205  global $ilTabs;
206 
207  $this->checkPermission('write');
208  $ilTabs->activateTab('id_settings');
209 
210  $this->initFormSettings();
211  if($this->form->checkInput())
212  {
213  $this->object->setTitle($this->form->getInput('tit'));
214  $this->object->setDescription($this->form->getInput('des'));
215  $this->object->update();
216 
217  include_once './Services/Container/classes/class.ilContainerSortingSettings.php';
218  $sort = new ilContainerSortingSettings($this->object->getId());
219  $sort->setSortMode($this->form->getInput('sor'));
220  $sort->update();
221 
222  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
223  $this->ctrl->redirect($this,'settings');
224  }
225 
226  $this->form->setValuesByPost();
227  ilUtil::sendFailure($this->lng->txt('err_check_input'));
228  $this->tpl->setContent($this->form->getHTML());
229  }
230 
231 
236  protected function initFormSettings()
237  {
238  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
239  $this->form = new ilPropertyFormGUI();
240  $this->form->setFormAction($this->ctrl->getFormAction($this,'saveSettings'));
241  $this->form->setTitle($this->lng->txt('webr_edit_settings'));
242 
243  // Title
244  $tit = new ilTextInputGUI($this->lng->txt('webr_list_title'),'tit');
245  $tit->setValue($this->object->getTitle());
246  $tit->setRequired(true);
247  $tit->setSize(40);
248  $tit->setMaxLength(127);
249  $this->form->addItem($tit);
250 
251  // Description
252  $des = new ilTextAreaInputGUI($this->lng->txt('webr_list_desc'),'des');
253  $des->setValue($this->object->getDescription());
254  $des->setCols(40);
255  $des->setRows(3);
256  $this->form->addItem($des);
257 
258  // Sorting
259  include_once './Services/Container/classes/class.ilContainerSortingSettings.php';
260  include_once './Services/Container/classes/class.ilContainer.php';
261 
262  $sor = new ilRadioGroupInputGUI($this->lng->txt('webr_sorting'),'sor');
263  $sor->setRequired(true);
264  include_once './Services/Container/classes/class.ilContainerSortingSettings.php';
265  $sor->setValue(ilContainerSortingSettings::_lookupSortMode($this->object->getId()));
266 
267  $opt = new ilRadioOption(
268  $this->lng->txt('webr_sort_title'),
270  );
271  $sor->addOption($opt);
272 
273  $opm = new ilRadioOption(
274  $this->lng->txt('webr_sort_manual'),
276  );
277  $sor->addOption($opm);
278  $this->form->addItem($sor);
279 
280  $this->form->addCommandButton('saveSettings', $this->lng->txt('save'));
281  $this->form->addCommandButton('view', $this->lng->txt('cancel'));
282  }
283 
284 
289  public function editLink()
290  {
291  global $ilCtrl;
292 
293  $this->checkPermission('write');
294  $this->activateTabs('content','id_content_view');
295 
296  if(!(int) $_GET['link_id'])
297  {
298  ilUtil::sendFailure($this->lng->txt('select_one'),true);
299  $ilCtrl->redirect($this,'view');
300  }
301 
302  $this->initFormLink(self::LINK_MOD_EDIT);
303  $this->setValuesFromLink((int) $_GET['link_id']);
304  $this->tpl->setContent($this->form->getHTML());
305  }
306 
311  public function updateLink()
312  {
313  global $ilCtrl;
314 
315  $this->initFormLink(self::LINK_MOD_EDIT);
316  if($this->checkLinkInput(self::LINK_MOD_EDIT,$this->object->getId(),(int) $_REQUEST['link_id']))
317  {
318  $this->link->setLinkId((int) $_REQUEST['link_id']);
319  $this->link->update();
320  if(ilParameterAppender::_isEnabled() and is_object($this->dynamic))
321  {
322  $this->dynamic->add((int) $_REQUEST['link_id']);
323  }
324 
325  if($this->isContainerMetaDataRequired())
326  {
327  $this->object->setTitle($this->form->getInput('tit'));
328  $this->object->setDescription($this->form->getInput('des'));
329  $this->object->update();
330  }
331 
332  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
333  $ilCtrl->redirect($this,'view');
334  }
335  ilUtil::sendFailure($this->lng->txt('err_check_input'));
336  $this->form->setValuesByPost();
337  $this->tpl->setContent($this->form->getHTML());
338  }
339 
344  public function addLink()
345  {
346  $this->checkPermission('write');
347  $this->activateTabs('content','id_content_view');
348 
349  $this->initFormLink(self::LINK_MOD_ADD);
350  $this->tpl->setContent($this->form->getHTML());
351  }
352 
357  public function saveAddLink()
358  {
359  global $ilCtrl;
360 
361  $this->checkPermission('write');
362 
363  $this->initFormLink(self::LINK_MOD_ADD);
364  if($this->checkLinkInput(self::LINK_MOD_ADD,$this->object->getId(),0))
365  {
366  if($this->isContainerMetaDataRequired())
367  {
368  // Save list data
369  $this->object->setTitle($this->form->getInput('lti'));
370  $this->object->setDescription($this->form->getInput('tde'));
371  $this->object->update();
372  }
373 
374  // Save Link
375  $link_id = $this->link->add();
376 
377  // Dynamic parameters
378  if(ilParameterAppender::_isEnabled() and is_object($this->dynamic))
379  {
380  $this->dynamic->add($link_id);
381  }
382  ilUtil::sendSuccess($this->lng->txt('webr_link_added'),true);
383  $ilCtrl->redirect($this,'view');
384  }
385  // Error handling
386  ilUtil::sendFailure($this->lng->txt('err_check_input'));
387  $this->form->setValuesByPost();
388 
389  $this->activateTabs('content','id_content_view');
390  $this->tpl->setContent($this->form->getHTML());
391  }
392 
397  protected function deleteParameter()
398  {
399  global $ilCtrl;
400 
401  $this->checkPermission('write');
402 
403  $this->ctrl->setParameter($this,'link_id',(int) $_GET['link_id']);
404 
405  if(!isset($_GET['param_id']))
406  {
407  ilUtil::sendFailure($this->lng->txt('select_one'),TRUE);
408  $ilCtrl->redirect($this,'view');
409  }
410 
411  include_once './Modules/WebResource/classes/class.ilParameterAppender.php';
412  $param = new ilParameterAppender($this->object->getId());
413  $param->delete((int) $_GET['param_id']);
414 
415  ilUtil::sendSuccess($this->lng->txt('links_parameter_deleted'),true);
416  $ilCtrl->redirect($this,'editLink');
417  }
418 
419  protected function deleteParameterForm()
420  {
421  global $ilCtrl;
422 
423  $this->checkPermission('write');
424 
425  if(!isset($_GET['param_id']))
426  {
427  ilUtil::sendFailure($this->lng->txt('select_one'),TRUE);
428  $ilCtrl->redirect($this,'view');
429  }
430 
431  include_once './Modules/WebResource/classes/class.ilParameterAppender.php';
432  $param = new ilParameterAppender($this->object->getId());
433  $param->delete((int) $_GET['param_id']);
434 
435  ilUtil::sendSuccess($this->lng->txt('links_parameter_deleted'),true);
436  $ilCtrl->redirect($this,'view');
437 
438  }
439 
440 
445  protected function updateLinks()
446  {
447  global $ilCtrl;
448 
449  $this->checkPermission('write');
450  $this->activateTabs('content','');
451 
452  if(!is_array($_POST['ids']))
453  {
454  ilUtil::sendFailure($this->lng->txt('select_one'),TRUE);
455  $ilCtrl->redirect($this,'view');
456  }
457 
458  // Validate
459  $invalid = array();
460  foreach($_POST['ids'] as $link_id)
461  {
462  $data = $_POST['links'][$link_id];
463 
464  if(!strlen($data['tit']))
465  {
466  $invalid[] = $link_id;
467  continue;
468  }
469  if(!strlen($data['tar']))
470  {
471  $invalid[] = $link_id;
472  continue;
473  }
474  if($data['nam'] and !$data['val'])
475  {
476  $invalid[] = $link_id;
477  continue;
478  }
479  if(!$data['nam'] and $data['val'])
480  {
481  $invalid[] = $link_id;
482  continue;
483  }
484  }
485 
486  if(count($invalid))
487  {
488  ilUtil::sendFailure($this->lng->txt('err_check_input'));
489  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.webr_manage.html','Modules/WebResource');
490 
491  include_once './Modules/WebResource/classes/class.ilWebResourceEditableLinkTableGUI.php';
492  $table = new ilWebResourceEditableLinkTableGUI($this,'view');
493  $table->setInvalidLinks($invalid);
494  $table->parseSelectedLinks($_POST['ids']);
495  $table->updateFromPost();
496  $this->tpl->setVariable('TABLE_LINKS',$table->getHTML());
497  return false;
498  }
499 
500  include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php';
501  $links = new ilLinkResourceItems($this->object->getId());
502 
503  // Save Settings
504  foreach($_POST['ids'] as $link_id)
505  {
506  $data = $_POST['links'][$link_id];
507 
508  $links->setLinkId($link_id);
509  $links->setTitle(ilUtil::stripSlashes($data['tit']));
510  $links->setDescription(ilUtil::stripSlashes($data['des']));
511  $links->setTarget(ilUtil::stripSlashes($data['tar']));
512  $links->setActiveStatus((int) $data['act']);
513  $links->setDisableCheckStatus((int) $data['che']);
514  $links->setValidStatus((int) $data['vali']);
515  $links->update();
516 
517  if(strlen($data['nam']) and $data['val'])
518  {
519  $param = new ilParameterAppender($this->object->getId());
520  $param->setName(ilUtil::stripSlashes($data['nam']));
521  $param->setValue((int) $data['val']);
522  $param->add($link_id);
523  }
524 
525  if($this->isContainerMetaDataRequired())
526  {
527  $this->object->setTitle(ilUtil::stripSlashes($data['tit']));
528  $this->object->setDescription(ilUtil::stripSlashes($data['des']));
529  $this->object->update();
530  }
531 
532  // TODO: Dynamic parameters
533  }
534 
535  ilUtil::sendSuccess($this->lng->txt('settings_saved'),TRUE);
536  $ilCtrl->redirect($this,'view');
537  }
538 
544  protected function setValuesFromLink($a_link_id)
545  {
546  include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php';
547  $link = new ilLinkResourceItems($this->object->getId());
548 
549  $values = $link->getItem($a_link_id);
550 
552  {
553  }
554 
555  $this->form->setValuesByArray(
556  array(
557  'tit' => $values['title'],
558  'tar' => $values['target'],
559  'des' => $values['description'],
560  'act' => (int) $values['active'],
561  'che' => (int) $values['disable_check'],
562  'vali' => (int) $values['valid']
563  )
564  );
565  }
566 
567 
575  protected function checkLinkInput($a_mode,$a_webr_id = 0,$a_link_id = 0)
576  {
577  $valid = $this->form->checkInput();
578 
579  include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php';
580  $this->link = new ilLinkResourceItems($a_webr_id);
581  $this->link->setTarget($this->form->getInput('tar'));
582  $this->link->setTitle($this->form->getInput('tit'));
583  $this->link->setDescription($this->form->getInput('des'));
584  $this->link->setDisableCheckStatus($this->form->getInput('che'));
585  $this->link->setActiveStatus($this->form->getInput('act'));
586 
587  if($a_mode == self::LINK_MOD_EDIT)
588  {
589  $this->link->setValidStatus($this->form->getInput('val'));
590  }
591 
593  {
594  return $valid;
595  }
596 
597  $this->dynamic = new ilParameterAppender($a_webr_id);
598  $this->dynamic->setName($this->form->getInput('nam'));
599  $this->dynamic->setValue($this->form->getInput('val'));
600  if(!$this->dynamic->validate())
601  {
602  switch($this->dynamic->getErrorCode())
603  {
604  case LINKS_ERR_NO_NAME:
605  $this->form->getItemByPostVar('nam')->setAlert($this->lng->txt('links_no_name_given'));
606  return false;
607 
608  case LINKS_ERR_NO_VALUE:
609  $this->form->getItemByPostVar('val')->setAlert($this->lng->txt('links_no_value_given'));
610  return false;
611 
613  // Nothing entered => no error
614  return $valid;
615  }
616  $this->dynamic = null;
617  }
618  return $valid;
619  }
620 
621 
627  protected function initFormLink($a_mode)
628  {
629  global $ilTabs;
630 
631  $ilTabs->activateTab("id_content");
632 
633  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
634  $this->form = new ilPropertyFormGUI();
635 
636  switch($a_mode)
637  {
638  case self::LINK_MOD_CREATE:
639  // Header
640  $this->ctrl->setParameter($this,'new_type','webr');
641  $this->form->setTitle($this->lng->txt('webr_new_link'));
642  $this->form->setTableWidth('600px');
643 
644  // Buttons
645  $this->form->addCommandButton('save', $this->lng->txt('webr_add'));
646  $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
647  break;
648 
649  case self::LINK_MOD_ADD:
650  // Header
651  $this->form->setTitle($this->lng->txt('webr_new_link'));
652 
653  // Buttons
654  $this->form->addCommandButton('saveAddLink', $this->lng->txt('webr_add'));
655  $this->form->addCommandButton('view', $this->lng->txt('cancel'));
656  break;
657 
658  case self::LINK_MOD_EDIT:
659  // Header
660  $this->ctrl->setParameter($this,'link_id',(int) $_REQUEST['link_id']);
661  $this->form->setTitle($this->lng->txt('webr_edit'));
662 
663  // Buttons
664  $this->form->addCommandButton('updateLink', $this->lng->txt('save'));
665  $this->form->addCommandButton('view', $this->lng->txt('cancel'));
666  break;
667  }
668 
669 
670  $this->form->setFormAction($this->ctrl->getFormAction($this));
671 
672  if($a_mode == self::LINK_MOD_ADD and $this->isContainerMetaDataRequired())
673  {
674  ilUtil::sendInfo($this->lng->txt('webr_container_info'));
675 
676 
677  $this->form->setTitle($this->lng->txt('webr_edit_list'));
678 
679  // List Title
680  $title = new ilTextInputGUI($this->lng->txt('webr_list_title'),'lti');
681  $title->setRequired(true);
682  $title->setSize(40);
683  $title->setMaxLength(127);
684  $this->form->addItem($title);
685 
686  // List Description
687  $desc = new ilTextAreaInputGUI($this->lng->txt('webr_list_desc'),'tde');
688  $desc->setRows(3);
689  $desc->setCols(40);
690  $this->form->addItem($desc);
691 
692  // Addtional section
693  $sect = new ilFormSectionHeaderGUI();
694  $sect->setTitle($this->lng->txt('webr_add'));
695  $this->form->addItem($sect);
696  }
697 
698  // Target
699  $tar = new ilTextInputGUI($this->lng->txt('webr_link_target'),'tar');
700  $tar->setValue("http://");
701  $tar->setRequired(true);
702  $tar->setSize(40);
703  $tar->setMaxLength(500);
704  $this->form->addItem($tar);
705 
706  // Title
707  $tit = new ilTextInputGUI($this->lng->txt('webr_link_title'),'tit');
708  $tit->setRequired(true);
709  $tit->setSize(40);
710  $tit->setMaxLength(127);
711  $this->form->addItem($tit);
712 
713  // Description
714  $des = new ilTextAreaInputGUI($this->lng->txt('description'),'des');
715  $des->setRows(3);
716  $des->setCols(40);
717  $this->form->addItem($des);
718 
719  // Active
720  $act = new ilCheckboxInputGUI($this->lng->txt('active'),'act');
721  $act->setChecked(true);
722  $act->setValue(1);
723  $this->form->addItem($act);
724 
725  // Check
726  $che = new ilCheckboxInputGUI($this->lng->txt('webr_disable_check'),'che');
727  $che->setValue(1);
728  $this->form->addItem($che);
729 
730  // Valid
731  if($a_mode == self::LINK_MOD_EDIT)
732  {
733  $val = new ilCheckboxInputGUI($this->lng->txt('valid'),'vali');
734  $this->form->addItem($val);
735  }
736 
738  {
739  $dyn = new ilNonEditableValueGUI($this->lng->txt('links_dyn_parameter'));
740  $dyn->setInfo($this->lng->txt('links_dynamic_info'));
741 
742 
743  if(count($links = ilParameterAppender::_getParams((int) $_GET['link_id'])))
744  {
745  $ex = new ilCustomInputGUI($this->lng->txt('links_existing_params'),'ex');
746  $dyn->addSubItem($ex);
747 
748  foreach($links as $id => $link)
749  {
750  $p = new ilCustomInputGUI();
751 
752  $ptpl = new ilTemplate('tpl.link_dyn_param_edit.html',true,true,'Modules/WebResource');
753  $ptpl->setVariable('INFO_TXT',ilParameterAppender::parameterToInfo($link['name'], $link['value']));
754  $this->ctrl->setParameter($this,'param_id',$id);
755  $ptpl->setVariable('LINK_DEL',$this->ctrl->getLinkTarget($this,'deleteParameterForm'));
756  $ptpl->setVariable('LINK_TXT',$this->lng->txt('delete'));
757  $p->setHtml($ptpl->get());
758  $dyn->addSubItem($p);
759  }
760  }
761 
762  // Existing parameters
763 
764  // New parameter
765  if($a_mode == self::LINK_MOD_EDIT)
766  {
767  #$new = new ilCustomInputGUI($this->lng->txt('links_add_param'),'');
768  #$dyn->addSubItem($new);
769  }
770 
771  // Dynyamic name
772  $nam = new ilTextInputGUI($this->lng->txt('links_name'),'nam');
773  $nam->setSize(12);
774  $nam->setMaxLength(128);
775  $dyn->addSubItem($nam);
776 
777  // Dynamic value
778  $val = new ilSelectInputGUI($this->lng->txt('links_value'),'val');
780  $val->setValue(0);
781  $dyn->addSubItem($val);
782 
783  $this->form->addItem($dyn);
784  }
785  }
786 
792  protected function isContainerMetaDataRequired()
793  {
794  include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php';
795  return ilLinkResourceItems::lookupNumberOfLinks($this->object->getId()) == 1;
796  }
797 
802  protected function switchViewMode()
803  {
804  global $ilCtrl;
805 
806  $_REQUEST['view_mode'] = $_GET['view_mode'] = (int) $_GET['switch_mode'];
807  $this->view();
808  }
809 
814  protected function editLinks()
815  {
816  $_GET['switch_mode'] = self::VIEW_MODE_MANAGE;
817  $this->switchViewMode();
818  }
819 
820 
825  public function view()
826  {
827  global $ilErr, $ilTabs;
828 
829  $ilTabs->activateTab("id_content");
830 
831  $this->checkPermission('read');
832 
833  if (strtolower($_GET["baseClass"]) == "iladministrationgui")
834  {
835  parent::view();
836  return true;
837  }
838  else
839  {
840  switch((int) $_REQUEST['view_mode'])
841  {
842  case self::VIEW_MODE_MANAGE:
843  $this->manage();
844  break;
845 
846  case self::VIEW_MODE_SORT:
847  $this->sort();
848  break;
849 
850  default:
851  $this->showLinks();
852  break;
853  }
854  }
855  return true;
856  }
857 
862  protected function manage()
863  {
864  $this->checkPermission('write');
865  $this->activateTabs('content','id_content_manage');
866 
867  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.webr_manage.html','Modules/WebResource');
868  $this->showToolbar('ACTION_BUTTONS');
869 
870  include_once './Modules/WebResource/classes/class.ilWebResourceEditableLinkTableGUI.php';
871  $table = new ilWebResourceEditableLinkTableGUI($this,'view');
872  $table->parse();
873 
874  $this->tpl->setVariable('TABLE_LINKS',$table->getHTML());
875  }
876 
881  protected function showLinks()
882  {
883  $this->checkPermission('read');
884  $this->activateTabs('content','id_content_view');
885 
886  include_once './Modules/WebResource/classes/class.ilWebResourceLinkTableGUI.php';
887  $table = new ilWebResourceLinkTableGUI($this,'showLinks');
888  $table->parse();
889 
890  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.webr_view.html','Modules/WebResource');
891  $this->showToolbar('ACTION_BUTTONS');
892  $this->tpl->setVariable('LINK_TABLE',$table->getHTML());
893  }
894 
899  protected function sort()
900  {
901  $this->checkPermission('write');
902  $this->activateTabs('content','id_content_ordering');
903 
904  include_once './Modules/WebResource/classes/class.ilWebResourceLinkTableGUI.php';
905  $table = new ilWebResourceLinkTableGUI($this,'sort',true);
906  $table->parse();
907 
908  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.webr_view.html','Modules/WebResource');
909  $this->showToolbar('ACTION_BUTTONS');
910  $this->tpl->setVariable('LINK_TABLE',$table->getHTML());
911  }
912 
917  protected function saveSorting()
918  {
919  $this->checkPermission('write');
920 
921  include_once './Services/Container/classes/class.ilContainerSorting.php';
922  $sort = ilContainerSorting::_getInstance($this->object->getId());
923  $sort->savePost((array) $_POST['position']);
924 
925  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
926  $this->view();
927  }
928 
929 
935  protected function showToolbar($a_tpl_var)
936  {
937  if(!$this->checkPermissionBool('write'))
938  {
939  return;
940  }
941 
942  include_once './Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php';
943  $tool = new ilToolbarGUI();
944  $tool->setFormAction($this->ctrl->getFormAction($this));
945  $tool->addButton(
946  $this->lng->txt('webr_add'),
947  $this->ctrl->getLinkTarget($this,'addLink')
948  );
949 
950  $this->tpl->setVariable($a_tpl_var,$tool->getHTML());
951  return;
952  }
953 
958  protected function confirmDeleteLink()
959  {
960  $this->checkPermission('write');
961  $this->activateTabs('content','id_content_view');
962 
963  $link_ids = is_array($_POST['link_ids']) ?
964  $_POST['link_ids'] :
965  array($_GET['link_id']);
966 
967  if(!$link_ids)
968  {
969  ilUtil::sendFailure($this->lng->txt('select_one'));
970  $this->view();
971  return false;
972  }
973 
974  include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php';
975  $links = new ilLinkResourceItems($this->object->getId());
976 
977  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
978  $confirm = new ilConfirmationGUI();
979  $confirm->setFormAction($this->ctrl->getFormAction($this,'view'));
980  $confirm->setHeaderText($this->lng->txt('webr_sure_delete_items'));
981  $confirm->setConfirm($this->lng->txt('delete'), 'deleteLinks');
982  $confirm->setCancel($this->lng->txt('cancel'), 'view');
983 
984  foreach($link_ids as $link_id)
985  {
986  $link = $links->getItem($link_id);
987  $confirm->addItem('link_ids[]', $link_id,$link['title']);
988  }
989  $this->tpl->setContent($confirm->getHTML());
990  }
991 
996  protected function deleteLinks()
997  {
998  global $ilCtrl;
999 
1000  $this->checkPermission('write');
1001 
1002  include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php';
1003  $links = new ilLinkResourceItems($this->object->getId());
1004 
1005  foreach($_POST['link_ids'] as $link_id)
1006  {
1007  $links->delete($link_id);
1008  }
1009  ilUtil::sendSuccess($this->lng->txt('webr_deleted_items'),true);
1010  $ilCtrl->redirect($this,'view');
1011  }
1012 
1017  protected function deactivateLink()
1018  {
1019  global $ilCtrl;
1020 
1021  $this->checkPermission('write');
1022 
1023  include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php';
1024  $links = new ilLinkResourceItems($this->object->getId());
1025 
1026  if(!$_GET['link_id'])
1027  {
1028  ilUtil::sendFailure($this->lng->txt('select_one'),true);
1029  $ilCtrl->redirect($this,'view');
1030  }
1031 
1032  $links->setLinkId((int) $_GET['link_id']);
1033  $links->updateActive(false);
1034 
1035  ilUtil::sendSuccess($this->lng->txt('webr_inactive_success'),true);
1036  $ilCtrl->redirect($this,'view');
1037  }
1038 
1039 
1045  function infoScreen()
1046  {
1047  $this->ctrl->setCmd("showSummary");
1048  $this->ctrl->setCmdClass("ilinfoscreengui");
1049  $this->infoScreenForward();
1050  }
1051 
1056  {
1057  global $ilTabs;
1058 
1059  $this->checkPermission('visible');
1060  $ilTabs->activateTab('id_info');
1061 
1062  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
1063  $info = new ilInfoScreenGUI($this);
1064 
1065  $info->enablePrivateNotes();
1066 
1067  // standard meta data
1068  $info->addMetaDataSections($this->object->getId(),0, $this->object->getType());
1069 
1070  if($this->id_type == self::WORKSPACE_NODE_ID)
1071  {
1072  $info->addProperty($this->lng->txt("perma_link"), $this->getPermanentLinkWidget());
1073  }
1074 
1075  // forward the command
1076  $this->ctrl->forwardCommand($info);
1077  }
1078 
1079 
1080  function history()
1081  {
1082  global $ilTabs;
1083 
1084  $this->checkPermission('write');
1085  $ilTabs->activateTab('id_history');
1086 
1087  include_once("classes/class.ilHistoryGUI.php");
1088 
1089  $hist_gui =& new ilHistoryGUI($this->object->getId());
1090 
1091  $hist_html = $hist_gui->getHistoryTable(array("ref_id" => $_GET["ref_id"],
1092  "cmd" => "history",
1093  "cmdClass" =>$_GET["cmdClass"],
1094  "cmdNode" =>$_GET["cmdNode"]));
1095 
1096  $this->tpl->setVariable("ADM_CONTENT", $hist_html);
1097  }
1098 
1107  public function formatInvalidLinkArray(Array $row)
1108  {
1109  $this->object->items_obj->readItem($row['page_id']);
1110  $row['title'] = $this->object->items_obj->getTitle();
1111 
1112  require_once 'Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php';
1114  $actions->setSelectionHeaderClass('small');
1115  $actions->setItemLinkClass('xsmall');
1116  $actions->setListTitle($this->lng->txt('actions'));
1117  $actions->setId($row['page_id']);
1118  $this->ctrl->setParameter($this, 'link_id', $row['page_id']);
1119  $actions->addItem(
1120  $this->lng->txt('edit'),
1121  '',
1122  $this->ctrl->getLinkTarget($this, 'editLink')
1123  );
1124  $this->ctrl->clearParameters($this);
1125  $row['action_html'] = $actions->getHTML();
1126 
1127  return $row;
1128  }
1129 
1134  protected function linkChecker()
1135  {
1136  global $ilias, $ilUser, $tpl, $ilTabs;
1137 
1138  $this->checkPermission('write');
1139  $ilTabs->activateTab('id_link_check');
1140 
1141  $this->__initLinkChecker();
1142  $this->object->initLinkResourceItemsObject();
1143 
1144  require_once 'Services/LinkChecker/classes/class.ilLinkCheckerTableGUI.php';
1145 
1146  $toolbar = new ilToolbarGUI();
1147 
1148  if((bool)$ilias->getSetting('cron_web_resource_check'))
1149  {
1150  include_once 'classes/class.ilLinkCheckNotify.php';
1151  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
1152 
1153  $chb = new ilCheckboxInputGUI($this->lng->txt('link_check_message_a'), 'link_check_message');
1154  $chb->setValue(1);
1155  $chb->setChecked((bool)ilLinkCheckNotify::_getNotifyStatus($ilUser->getId(), $this->object->getId()));
1156  $chb->setOptionTitle($this->lng->txt('link_check_message_b'));
1157 
1158  $toolbar->addInputItem($chb);
1159  $toolbar->addFormButton($this->lng->txt('save'), 'saveLinkCheck');
1160  $toolbar->setFormAction($this->ctrl->getLinkTarget($this, 'saveLinkCheck'));
1161  }
1162 
1163  $tgui = new ilLinkCheckerTableGUI($this, 'linkChecker');
1164  $tgui->setLinkChecker($this->link_checker_obj)
1165  ->setRowHandler($this)
1166  ->setRefreshButton($this->lng->txt('refresh'), 'refreshLinkCheck');
1167 
1168  return $tpl->setContent($tgui->prepareHTML()->getHTML().$toolbar->getHTML());
1169  }
1170 
1171  function saveLinkCheck()
1172  {
1173  global $ilDB,$ilUser;
1174 
1175  include_once './classes/class.ilLinkCheckNotify.php';
1176 
1177  $link_check_notify =& new ilLinkCheckNotify($ilDB);
1178  $link_check_notify->setUserId($ilUser->getId());
1179  $link_check_notify->setObjId($this->object->getId());
1180 
1181  if($_POST['link_check_message'])
1182  {
1183  ilUtil::sendSuccess($this->lng->txt('link_check_message_enabled'));
1184  $link_check_notify->addNotifier();
1185  }
1186  else
1187  {
1188  ilUtil::sendSuccess($this->lng->txt('link_check_message_disabled'));
1189  $link_check_notify->deleteNotifier();
1190  }
1191  $this->linkChecker();
1192 
1193  return true;
1194  }
1195 
1196 
1197 
1198  function refreshLinkCheck()
1199  {
1200  $this->__initLinkChecker();
1201 
1202  if(!$this->link_checker_obj->checkPear())
1203  {
1204  ilUtil::sendFailure($this->lng->txt('missing_pear_library'));
1205  $this->linkChecker();
1206 
1207  return false;
1208  }
1209 
1210 
1211  $this->object->initLinkResourceItemsObject();
1212 
1213  // Set all link to valid. After check invalid links will be set to invalid
1214  $this->object->items_obj->updateValidByCheck();
1215 
1216  foreach($this->link_checker_obj->checkWebResourceLinks() as $invalid)
1217  {
1218  $this->object->items_obj->readItem($invalid['page_id']);
1219  $this->object->items_obj->setActiveStatus(false);
1220  $this->object->items_obj->setValidStatus(false);
1221  $this->object->items_obj->update(false);
1222  }
1223 
1224  $this->object->items_obj->updateLastCheck();
1225  ilUtil::sendSuccess($this->lng->txt('link_checker_refreshed'));
1226 
1227  $this->linkChecker();
1228 
1229  return true;
1230  }
1231 
1233  {
1234  global $ilDB;
1235 
1236  include_once './classes/class.ilLinkChecker.php';
1237 
1238  $this->link_checker_obj =& new ilLinkChecker($ilDB,false);
1239  $this->link_checker_obj->setObjId($this->object->getId());
1240 
1241  return true;
1242  }
1243 
1244 
1251  protected function activateTabs($a_active_tab,$a_active_subtab = '')
1252  {
1253  global $ilCtrl, $ilTabs, $lng;
1254 
1255  switch($a_active_tab)
1256  {
1257  case 'content':
1258  if($this->checkPermissionBool('write'))
1259  {
1260  $this->lng->loadLanguageModule('cntr');
1261 
1262  $this->ctrl->setParameter($this,'switch_mode',self::VIEW_MODE_VIEW);
1263  $ilTabs->addSubTab('id_content_view',
1264  $lng->txt('view'),
1265  $this->ctrl->getLinkTarget($this,'switchViewMode')
1266  );
1267  $this->ctrl->setParameter($this,'switch_mode',self::VIEW_MODE_MANAGE);
1268  $ilTabs->addSubTab('id_content_manage',
1269  $lng->txt('cntr_manage'),
1270  $this->ctrl->getLinkTarget($this,'switchViewMode')
1271  );
1272  include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php';
1273  include_once './Services/Container/classes/class.ilContainerSortingSettings.php';
1274  include_once './Services/Container/classes/class.ilContainer.php';
1275  if((ilLinkResourceItems::lookupNumberOfLinks($this->object->getId()) > 1)
1277  {
1278  $this->ctrl->setParameter($this,'switch_mode',self::VIEW_MODE_SORT);
1279  $ilTabs->addSubTab('id_content_ordering',
1280  $this->lng->txt('cntr_ordering'),
1281  $this->ctrl->getLinkTarget($this,'switchViewMode')
1282  );
1283  }
1284 
1285  $ilCtrl->clearParameters($this);
1286  $ilTabs->activateSubTab($a_active_subtab);
1287  }
1288  }
1289 
1290  $ilTabs->activateTab('id_content');
1291  }
1292 
1293 
1298  function setTabs()
1299  {
1300  global $ilTabs, $lng;
1301 
1302  if ($this->checkPermissionBool('read'))
1303  {
1304  $ilTabs->addTab("id_content",
1305  $lng->txt("content"),
1306  $this->ctrl->getLinkTarget($this, "view"));
1307  }
1308 
1309  if ($this->checkPermissionBool('visible'))
1310  {
1311  $ilTabs->addTab("id_info",
1312  $lng->txt("info_short"),
1313  $this->ctrl->getLinkTarget($this, "infoScreen"));
1314  }
1315 
1316  if($this->checkPermissionBool('write') and !$this->getCreationMode())
1317  {
1318  include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php';
1319  if(ilLinkResourceItems::lookupNumberOfLinks($this->object->getId()) > 1)
1320  {
1321  $ilTabs->addTab("id_settings",
1322  $lng->txt("settings"),
1323  $this->ctrl->getLinkTarget($this, "settings"));
1324  }
1325 
1326  }
1327 
1328  if ($this->checkPermissionBool('write'))
1329  {
1330  $ilTabs->addTab("id_history",
1331  $lng->txt("history"),
1332  $this->ctrl->getLinkTarget($this, "history"));
1333  }
1334 
1335  if ($this->checkPermissionBool('write'))
1336  {
1337  // Check if pear library is available
1338  if(@include_once('HTTP/Request.php'))
1339  {
1340  $ilTabs->addTab("id_link_check",
1341  $lng->txt("link_check"),
1342  $this->ctrl->getLinkTarget($this, "linkChecker"));
1343  }
1344  }
1345 
1346  if ($this->checkPermissionBool('write'))
1347  {
1348  $ilTabs->addTab("id_meta_data",
1349  $lng->txt("meta_data"),
1350  $this->ctrl->getLinkTargetByClass('ilmdeditorgui','listSection'));
1351  }
1352 
1353  if($this->checkPermissionBool('write'))
1354  {
1355  $ilTabs->addTab(
1356  'export',
1357  $this->lng->txt('export'),
1358  $this->ctrl->getLinkTargetByClass('ilexportgui','')
1359  );
1360  }
1361 
1362  // will add permission tab if needed
1363  parent::setTabs();
1364  }
1365 
1366  // PRIVATE
1367  function __prepareOutput()
1368  {
1369  // output objects
1370  $this->tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
1371  $this->tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
1372 
1373  // output locator
1374  $this->__setLocator();
1375 
1376  // output message
1377  if ($this->message)
1378  {
1379  ilUtil::sendInfo($this->message);
1380  }
1381 
1382  // display infopanel if something happened
1383  ilUtil::infoPanel();;
1384  }
1385 
1386  function __setLocator()
1387  {
1388  global $tree;
1389  global $ilias_locator, $lng;
1390 
1391  $this->tpl->addBlockFile("LOCATOR", "locator", "tpl.locator.html", "Services/Locator");
1392 
1393  $counter = 0;
1394 
1395  //$this->tpl->touchBlock('locator_separator');
1396  //$this->tpl->touchBlock('locator_item');
1397 
1398  foreach ($tree->getPathFull($this->object->getRefId()) as $key => $row)
1399  {
1400 
1401  //if ($row["child"] == $tree->getRootId())
1402  //{
1403  // continue;
1404  //}
1405 
1406  if($counter++)
1407  {
1408  $this->tpl->touchBlock('locator_separator_prefix');
1409  }
1410 
1411  if ($row["child"] > 0)
1412  {
1413  $this->tpl->setCurrentBlock("locator_img");
1414  $this->tpl->setVariable("IMG_SRC",
1415  ilUtil::getImagePath("icon_".$row["type"]."_s.gif"));
1416  $this->tpl->setVariable("IMG_ALT",
1417  $lng->txt("obj_".$type));
1418  $this->tpl->parseCurrentBlock();
1419  }
1420 
1421  $this->tpl->setCurrentBlock("locator_item");
1422 
1423  if($row["type"] == 'webr')
1424  {
1425  $this->tpl->setVariable("ITEM",$this->object->getTitle());
1426  $this->tpl->setVariable("LINK_ITEM",$this->ctrl->getLinkTarget($this));
1427  }
1428  elseif ($row["child"] != $tree->getRootId())
1429  {
1430  $this->tpl->setVariable("ITEM", $row["title"]);
1431  $this->tpl->setVariable("LINK_ITEM","./repository.php?ref_id=".$row["child"]);
1432  }
1433  else
1434  {
1435  $this->tpl->setVariable("ITEM", $this->lng->txt("repository"));
1436  $this->tpl->setVariable("LINK_ITEM","./repository.php?ref_id=".$row["child"]);
1437  }
1438 
1439  $this->tpl->parseCurrentBlock();
1440  }
1441 
1442  $this->tpl->setVariable("TXT_LOCATOR",$this->lng->txt("locator"));
1443  $this->tpl->parseCurrentBlock();
1444  }
1445 
1446  function callDirectLink()
1447  {
1448  $obj_id = $this->object->getId();
1449 
1450  include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php';
1452  {
1454 
1455  include_once './Modules/WebResource/classes/class.ilParameterAppender.php';
1457  {
1458  $url = ilParameterAppender::_append($url);
1459  }
1460 
1461  $this->redirectToLink($this->ref_id, $obj_id, $url["target"]);
1462  }
1463  }
1464 
1465  function callLink()
1466  {
1467  if($_REQUEST["link_id"])
1468  {
1469  $obj_id = $this->object->getId();
1470 
1471  include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php';
1472  $items = new ilLinkResourceItems($obj_id);
1473  $item = $items->getItem($_REQUEST["link_id"]);
1474  if($item["target"])
1475  {
1476  include_once './Modules/WebResource/classes/class.ilParameterAppender.php';
1478  {
1479  $item = ilParameterAppender::_append($item);
1480  }
1481  $this->redirectToLink($this->ref_id, $obj_id, $item["target"]);
1482  }
1483  }
1484  }
1485 
1486  protected function redirectToLink($a_ref_id, $a_obj_id, $a_url)
1487  {
1488  global $ilUser;
1489 
1490  if($a_url)
1491  {
1492  require_once('Services/Tracking/classes/class.ilChangeEvent.php');
1493  ilChangeEvent::_recordReadEvent("webr", $a_ref_id, $a_obj_id,
1494  $ilUser->getId());
1495 
1496  ilUtil::redirect($a_url);
1497  }
1498  }
1499 
1500  function _goto($a_target, $a_additional = null)
1501  {
1502  global $ilAccess, $ilErr, $lng;
1503 
1504  if($a_additional && substr($a_additional, -3) == "wsp")
1505  {
1506  $_GET["baseClass"] = "ilsharedresourceGUI";
1507  $_GET["wsp_id"] = $a_target;
1508  include("ilias.php");
1509  exit;
1510  }
1511 
1512  // Will be replaced in future releases by ilAccess::checkAccess()
1513  if ($ilAccess->checkAccess("read", "", $a_target))
1514  {
1515  ilUtil::redirect("ilias.php?baseClass=ilLinkResourceHandlerGUI&ref_id=$a_target");
1516  }
1517  else
1518  {
1519  // to do: force flat view
1520  if ($ilAccess->checkAccess("visible", "", $a_target))
1521  {
1522  ilUtil::redirect("ilias.php?baseClass=ilLinkResourceHandlerGUI&ref_id=".$a_target."&cmd=infoScreen");
1523  }
1524  else
1525  {
1526  if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
1527  {
1528  $_GET["cmd"] = "frameset";
1529  $_GET["target"] = "";
1530  $_GET["ref_id"] = ROOT_FOLDER_ID;
1531  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
1532  ilObject::_lookupTitle(ilObject::_lookupObjId($a_target))), true);
1533  include("repository.php");
1534  exit;
1535  }
1536  }
1537  }
1538 
1539  $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
1540  }
1541 } // END class.ilObjLinkResource
1542 ?>