ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjLinkResourceGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2009 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 
24 include_once "./classes/class.ilObjectGUI.php";
25 include_once('./Modules/WebResource/classes/class.ilParameterAppender.php');
26 
39 {
40  const VIEW_MODE_VIEW = 1;
41  const VIEW_MODE_MANAGE = 2;
42  const VIEW_MODE_SORT = 3;
43 
44  const LINK_MOD_CREATE = 1;
45  const LINK_MOD_EDIT = 2;
46  const LINK_MOD_ADD = 3;
47 
52  function __construct()
53  {
54  global $ilCtrl;
55 
56  $this->type = "webr";
57  parent::__construct('',(int) $_GET['ref_id'],true,false);
58 
59  // CONTROL OPTIONS
60  $this->ctrl = $ilCtrl;
61  $this->ctrl->saveParameter($this,array("ref_id","cmdClass"));
62 
63  $this->lng->loadLanguageModule('webr');
64  }
65 
66  public function executeCommand()
67  {
68  global $rbacsystem,$ilCtrl;
69 
70 
71  //if($this->ctrl->getTargetScript() == 'link_resources.php')
72  if($_GET["baseClass"] == 'ilLinkResourceHandlerGUI')
73  {
74  $_GET['view_mode'] = isset($_GET['switch_mode']) ? $_GET['switch_mode'] : $_GET['view_mode'];
75  $ilCtrl->saveParameter($this, 'view_mode');
76  $this->__prepareOutput();
77  }
78 
79  if (strtolower($_GET["baseClass"]) == "iladministrationgui" ||
80  $this->getCreationMode() == true)
81  {
82  $this->prepareOutput();
83  }
84 
85 
86  $next_class = $this->ctrl->getNextClass($this);
87  $cmd = $this->ctrl->getCmd();
88 
89  switch($next_class)
90  {
91  case "ilinfoscreengui":
92  $this->infoScreen(); // forwards command
93  break;
94 
95  case 'ilmdeditorgui':
96  $this->tabs_gui->setTabActive('meta_data');
97  include_once 'Services/MetaData/classes/class.ilMDEditorGUI.php';
98  $md_gui =& new ilMDEditorGUI($this->object->getId(), 0, $this->object->getType());
99  $md_gui->addObserver($this->object,'MDUpdateListener','General');
100  $this->ctrl->forwardCommand($md_gui);
101  break;
102 
103  case 'ilpermissiongui':
104  $this->tabs_gui->setTabActive('perm_settings');
105  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
106  $perm_gui =& new ilPermissionGUI($this);
107  $ret =& $this->ctrl->forwardCommand($perm_gui);
108  break;
109 
110  case 'ilobjectcopygui':
111  include_once './Services/Object/classes/class.ilObjectCopyGUI.php';
112  $cp = new ilObjectCopyGUI($this);
113  $cp->setType('webr');
114  $this->ctrl->forwardCommand($cp);
115  break;
116 
117  default:
118 
119  if(!$cmd)
120  {
121  $cmd = "view";
122  }
123  $cmd .= "Object";
124  $this->$cmd();
125 
126  break;
127  }
128 
129  if(!$this->getCreationMode())
130  {
131  // Fill meta header tags
132  include_once('Services/MetaData/classes/class.ilMDUtils.php');
133  ilMDUtils::_fillHTMLMetaTags($this->object->getId(),$this->object->getId(),'webr');
134  }
135  return true;
136  }
137 
145  public function createObject()
146  {
147  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.webr_create.html','Modules/WebResource');
148  $this->initFormLink(self::LINK_MOD_CREATE);
149  $this->tpl->setVariable('LINK_FORM',$this->form->getHTML());
150 
151  $this->fillCloneTemplate('CLONE_WIZARD',$_REQUEST['new_type']);
152 
153  }
154 
159  public function saveObject()
160  {
161  global $ilCtrl;
162 
163  $this->initFormLink(self::LINK_MOD_CREATE);
164  if($this->checkLinkInput(self::LINK_MOD_CREATE,0,0))
165  {
166  // Save new object
167  $_POST['Fobject']['title'] = $_POST['tit'];
168  $_POST['Fobject']['desc'] = $_POST['des'];
169  $link_list = parent::saveObject();
170 
171  // Save link
172  $this->link->setLinkResourceId($link_list->getId());
173  $link_id = $this->link->add();
174 
175  // Dynamic params
176  if(ilParameterAppender::_isEnabled() and is_object($this->dynamic))
177  {
178  $this->dynamic->setObjId($link_list->getId());
179  $this->dynamic->add($link_id);
180  }
181 
182  ilUtil::sendSuccess($this->lng->txt('webr_link_added'));
183  ilUtil::redirect("ilias.php?baseClass=ilLinkResourceHandlerGUI&ref_id=".
184  $link_list->getRefId()."&cmd=view");
185  return true;
186  }
187  // Data incomplete or invalid
188  ilUtil::sendFailure($this->lng->txt('err_check_input'));
189  $this->form->setValuesByPost();
190 
191  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.webr_create.html','Modules/WebResource');
192  $this->tpl->setVariable('LINK_FORM',$this->form->getHTML());
193 
194  $this->fillCloneTemplate('CLONE_WIZARD',$_REQUEST['new_type']);
195  return false;
196 
197 
198  if ($_POST["Fobject"]["title"] == "")
199  {
200  ilUtil::sendFailure($this->lng->txt('please_enter_title'));
201  $this->createObject();
202  return false;
203  }
204  }
205 
211  protected function settingsObject()
212  {
213  $this->checkPermission('write');
214  $this->tabs_gui->setTabActive('settings');
215 
216  $this->initFormSettings();
217  $this->tpl->setContent($this->form->getHTML());
218  }
219 
224  protected function saveSettingsObject()
225  {
226  $this->checkPermission('write');
227  $this->tabs_gui->setTabActive('settings');
228 
229  $this->initFormSettings();
230  if($this->form->checkInput())
231  {
232  $this->object->setTitle($this->form->getInput('tit'));
233  $this->object->setDescription($this->form->getInput('des'));
234  $this->object->update();
235 
236  include_once './Services/Container/classes/class.ilContainerSortingSettings.php';
237  $sort = new ilContainerSortingSettings($this->object->getId());
238  $sort->setSortMode($this->form->getInput('sor'));
239  $sort->update();
240 
241  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
242  $this->ctrl->redirect($this,'settings');
243  }
244 
245  $this->form->setValuesByPost();
246  ilUtil::sendFailure($this->lng->txt('err_check_input'));
247  $this->tpl->setContent($this->form->getHTML());
248  }
249 
250 
255  protected function initFormSettings()
256  {
257  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
258  $this->form = new ilPropertyFormGUI();
259  $this->form->setFormAction($this->ctrl->getFormAction($this,'saveSettings'));
260  $this->form->setTitle($this->lng->txt('webr_edit_settings'));
261 
262  // Title
263  $tit = new ilTextInputGUI($this->lng->txt('webr_list_title'),'tit');
264  $tit->setValue($this->object->getTitle());
265  $tit->setRequired(true);
266  $tit->setSize(40);
267  $tit->setMaxLength(127);
268  $this->form->addItem($tit);
269 
270  // Description
271  $des = new ilTextAreaInputGUI($this->lng->txt('webr_list_desc'),'des');
272  $des->setValue($this->object->getDescription());
273  $des->setCols(40);
274  $des->setRows(3);
275  $this->form->addItem($des);
276 
277  // Sorting
278  include_once './Services/Container/classes/class.ilContainerSortingSettings.php';
279  include_once './Services/Container/classes/class.ilContainer.php';
280 
281  $sor = new ilRadioGroupInputGUI($this->lng->txt('webr_sorting'),'sor');
282  $sor->setRequired(true);
283  include_once './Services/Container/classes/class.ilContainerSortingSettings.php';
284  $sor->setValue(ilContainerSortingSettings::readSortMode($this->object->getId()));
285 
286  $opt = new ilRadioOption(
287  $this->lng->txt('webr_sort_title'),
289  );
290  $sor->addOption($opt);
291 
292  $opm = new ilRadioOption(
293  $this->lng->txt('webr_sort_manual'),
295  );
296  $sor->addOption($opm);
297  $this->form->addItem($sor);
298 
299  $this->form->addCommandButton('saveSettings', $this->lng->txt('save'));
300  $this->form->addCommandButton('view', $this->lng->txt('cancel'));
301  }
302 
303 
308  public function editLinkObject()
309  {
310  global $ilCtrl;
311 
312  $this->checkPermission('write');
313  $this->activateTabs('content','view');
314 
315  if(!(int) $_GET['link_id'])
316  {
317  ilUtil::sendFailure($this->lng->txt('select_one'),true);
318  $ilCtrl->redirect($this,'view');
319  }
320 
321  $this->initFormLink(self::LINK_MOD_EDIT);
322  $this->setValuesFromLink((int) $_GET['link_id']);
323  $this->tpl->setContent($this->form->getHTML());
324  }
325 
330  public function updateLinkObject()
331  {
332  global $ilCtrl;
333 
334  $this->initFormLink(self::LINK_MOD_EDIT);
335  if($this->checkLinkInput(self::LINK_MOD_EDIT,$this->object->getId(),(int) $_REQUEST['link_id']))
336  {
337  $this->link->setLinkId((int) $_REQUEST['link_id']);
338  $this->link->update();
339  if(ilParameterAppender::_isEnabled() and is_object($this->dynamic))
340  {
341  $this->dynamic->add((int) $_REQUEST['link_id']);
342  }
343 
344  if($this->isContainerMetaDataRequired())
345  {
346  $this->object->setTitle($this->form->getInput('tit'));
347  $this->object->setDescription($this->form->getInput('des'));
348  $this->object->update();
349  }
350 
351  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
352  $ilCtrl->redirect($this,'view');
353  }
354  ilUtil::sendFailure($this->lng->txt('err_check_input'));
355  $this->form->setValuesByPost();
356  $this->tpl->setContent($this->form->getHTML());
357  }
358 
363  public function addLinkObject()
364  {
365  $this->checkPermission('write');
366  $this->activateTabs('content','view');
367 
368  $this->initFormLink(self::LINK_MOD_ADD);
369  $this->tpl->setContent($this->form->getHTML());
370  }
371 
376  public function saveAddLinkObject()
377  {
378  global $ilCtrl;
379 
380  $this->checkPermission('write');
381 
382  $this->initFormLink(self::LINK_MOD_ADD);
383  if($this->checkLinkInput(self::LINK_MOD_ADD,$this->object->getId(),0))
384  {
385  if($this->isContainerMetaDataRequired())
386  {
387  // Save list data
388  $this->object->setTitle($this->form->getInput('lti'));
389  $this->object->setDescription($this->form->getInput('lde'));
390  $this->object->update();
391  }
392 
393  // Save Link
394  $link_id = $this->link->add();
395 
396  // Dynamic parameters
397  if(ilParameterAppender::_isEnabled() and is_object($this->dynamic))
398  {
399  $this->dynamic->add($link_id);
400  }
401  ilUtil::sendSuccess($this->lng->txt('webr_link_added'),true);
402  $ilCtrl->redirect($this,'view');
403  }
404  // Error handling
405  ilUtil::sendFailure($this->lng->txt('err_check_input'));
406  $this->form->setValuesByPost();
407 
408  $this->activateTabs('content','view');
409  $this->tpl->setContent($this->form->getHTML());
410  }
411 
416  protected function deleteParameterObject()
417  {
418  global $ilCtrl;
419 
420  $this->checkPermission('write');
421 
422  $this->ctrl->setParameter($this,'link_id',(int) $_GET['link_id']);
423 
424  if(!isset($_GET['param_id']))
425  {
426  ilUtil::sendFailure($this->lng->txt('select_one'),TRUE);
427  $ilCtrl->redirect($this,'view');
428  }
429 
430  include_once './Modules/WebResource/classes/class.ilParameterAppender.php';
431  $param = new ilParameterAppender($this->object->getId());
432  $param->delete((int) $_GET['param_id']);
433 
434  ilUtil::sendSuccess($this->lng->txt('links_parameter_deleted'),true);
435  $ilCtrl->redirect($this,'editLink');
436  }
437 
438  protected function deleteParameterFormObject()
439  {
440  global $ilCtrl;
441 
442  $this->checkPermission('write');
443 
444  if(!isset($_GET['param_id']))
445  {
446  ilUtil::sendFailure($this->lng->txt('select_one'),TRUE);
447  $ilCtrl->redirect($this,'view');
448  }
449 
450  include_once './Modules/WebResource/classes/class.ilParameterAppender.php';
451  $param = new ilParameterAppender($this->object->getId());
452  $param->delete((int) $_GET['param_id']);
453 
454  ilUtil::sendSuccess($this->lng->txt('links_parameter_deleted'),true);
455  $ilCtrl->redirect($this,'view');
456 
457  }
458 
459 
464  protected function updateLinksObject()
465  {
466  global $ilCtrl;
467 
468  $this->checkPermission('write');
469  $this->activateTabs('content','');
470 
471  if(!is_array($_POST['ids']))
472  {
473  ilUtil::sendFailure($this->lng->txt('select_one'),TRUE);
474  $ilCtrl->redirect($this,'view');
475  }
476 
477  // Validate
478  $invalid = array();
479  foreach($_POST['ids'] as $link_id)
480  {
481  $data = $_POST['links'][$link_id];
482 
483  if(!strlen($data['tit']))
484  {
485  $invalid[] = $link_id;
486  continue;
487  }
488  if(!strlen($data['tar']))
489  {
490  $invalid[] = $link_id;
491  continue;
492  }
493  if($data['nam'] and !$data['val'])
494  {
495  $invalid[] = $link_id;
496  continue;
497  }
498  if(!$data['nam'] and $data['val'])
499  {
500  $invalid[] = $link_id;
501  continue;
502  }
503  }
504 
505  if(count($invalid))
506  {
507  ilUtil::sendFailure($this->lng->txt('err_check_input'));
508  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.webr_manage.html','Modules/WebResource');
509 
510  include_once './Modules/WebResource/classes/class.ilWebResourceEditableLinkTableGUI.php';
511  $table = new ilWebResourceEditableLinkTableGUI($this,'view');
512  $table->setInvalidLinks($invalid);
513  $table->parseSelectedLinks($_POST['ids']);
514  $table->updateFromPost();
515  $this->tpl->setVariable('TABLE_LINKS',$table->getHTML());
516  return false;
517  }
518 
519  include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php';
520  $links = new ilLinkResourceItems($this->object->getId());
521 
522  // Save Settings
523  foreach($_POST['ids'] as $link_id)
524  {
525  $data = $_POST['links'][$link_id];
526 
527  $links->setLinkId($link_id);
528  $links->setTitle(ilUtil::stripSlashes($data['tit']));
529  $links->setDescription(ilUtil::stripSlashes($data['des']));
530  $links->setTarget(ilUtil::stripSlashes($data['tar']));
531  $links->setActiveStatus((int) $data['act']);
532  $links->setDisableCheckStatus((int) $data['che']);
533  $links->setValidStatus((int) $data['vali']);
534  $links->update();
535 
536  if(strlen($data['nam']) and $data['val'])
537  {
538  $param = new ilParameterAppender($this->object->getId());
539  $param->setName(ilUtil::stripSlashes($data['nam']));
540  $param->setValue((int) $data['val']);
541  $param->add($link_id);
542  }
543 
544  if($this->isContainerMetaDataRequired())
545  {
546  $this->object->setTitle(ilUtil::stripSlashes($data['tit']));
547  $this->object->setDescription(ilUtil::stripSlashes($data['des']));
548  $this->object->update();
549  }
550 
551  // TODO: Dynamic parameters
552  }
553 
554  ilUtil::sendSuccess($this->lng->txt('settings_saved'),TRUE);
555  $ilCtrl->redirect($this,'view');
556  }
557 
563  protected function setValuesFromLink($a_link_id)
564  {
565  include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php';
566  $link = new ilLinkResourceItems($this->object->getId());
567 
568  $values = $link->getItem($a_link_id);
569 
571  {
572  }
573 
574  $this->form->setValuesByArray(
575  array(
576  'tit' => $values['title'],
577  'tar' => $values['target'],
578  'des' => $values['description'],
579  'act' => (int) $values['active'],
580  'che' => (int) $values['disable_check'],
581  'vali' => (int) $values['valid']
582  )
583  );
584  }
585 
586 
594  protected function checkLinkInput($a_mode,$a_webr_id = 0,$a_link_id = 0)
595  {
596  $valid = $this->form->checkInput();
597 
598  include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php';
599  $this->link = new ilLinkResourceItems($a_webr_id);
600  $this->link->setTarget($this->form->getInput('tar'));
601  $this->link->setTitle($this->form->getInput('tit'));
602  $this->link->setDescription($this->form->getInput('des'));
603  $this->link->setDisableCheckStatus($this->form->getInput('che'));
604  $this->link->setActiveStatus($this->form->getInput('act'));
605 
606  if($a_mode == self::LINK_MOD_EDIT)
607  {
608  $this->link->setValidStatus($this->form->getInput('val'));
609  }
610 
612  {
613  return $valid;
614  }
615 
616  $this->dynamic = new ilParameterAppender($a_webr_id);
617  $this->dynamic->setName($this->form->getInput('nam'));
618  $this->dynamic->setValue($this->form->getInput('val'));
619  if(!$this->dynamic->validate())
620  {
621  switch($this->dynamic->getErrorCode())
622  {
623  case LINKS_ERR_NO_NAME:
624  $this->form->getItemByPostVar('nam')->setAlert($this->lng->txt('links_no_name_given'));
625  return false;
626 
627  case LINKS_ERR_NO_VALUE:
628  $this->form->getItemByPostVar('val')->setAlert($this->lng->txt('links_no_value_given'));
629  return false;
630 
632  // Nothing entered => no error
633  return $valid;
634  }
635  $this->dynamic = null;
636  }
637  return $valid;
638  }
639 
640 
646  protected function initFormLink($a_mode)
647  {
648  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
649  $this->form = new ilPropertyFormGUI();
650 
651  switch($a_mode)
652  {
653  case self::LINK_MOD_CREATE:
654  // Header
655  $this->ctrl->setParameter($this,'new_type','webr');
656  $this->form->setTitle($this->lng->txt('webr_new_link'));
657  $this->form->setTableWidth('60%');
658 
659  // Buttons
660  $this->form->addCommandButton('save', $this->lng->txt('webr_add'));
661  $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
662  break;
663 
664  case self::LINK_MOD_ADD:
665  // Header
666  $this->form->setTitle($this->lng->txt('webr_new_link'));
667 
668  // Buttons
669  $this->form->addCommandButton('saveAddLink', $this->lng->txt('webr_add'));
670  $this->form->addCommandButton('view', $this->lng->txt('cancel'));
671  break;
672 
673  case self::LINK_MOD_EDIT:
674  // Header
675  $this->ctrl->setParameter($this,'link_id',(int) $_REQUEST['link_id']);
676  $this->form->setTitle($this->lng->txt('webr_edit'));
677 
678  // Buttons
679  $this->form->addCommandButton('updateLink', $this->lng->txt('save'));
680  $this->form->addCommandButton('view', $this->lng->txt('cancel'));
681  break;
682  }
683 
684 
685  $this->form->setFormAction($this->ctrl->getFormAction($this));
686 
687  if($a_mode == self::LINK_MOD_ADD and $this->isContainerMetaDataRequired())
688  {
689  ilUtil::sendInfo($this->lng->txt('webr_container_info'));
690 
691 
692  $this->form->setTitle($this->lng->txt('webr_edit_list'));
693 
694  // List Title
695  $title = new ilTextInputGUI($this->lng->txt('webr_list_title'),'lti');
696  $title->setRequired(true);
697  $title->setSize(40);
698  $title->setMaxLength(127);
699  $this->form->addItem($title);
700 
701  // List Description
702  $desc = new ilTextAreaInputGUI($this->lng->txt('webr_list_desc'),'tde');
703  $desc->setRows(3);
704  $desc->setCols(40);
705  $this->form->addItem($desc);
706 
707  // Addtional section
708  $sect = new ilFormSectionHeaderGUI();
709  $sect->setTitle($this->lng->txt('webr_add'));
710  $this->form->addItem($sect);
711  }
712 
713  // Target
714  $tar = new ilTextInputGUI($this->lng->txt('webr_link_target'),'tar');
715  $tar->setValue("http://");
716  $tar->setRequired(true);
717  $tar->setSize(40);
718  $tar->setMaxLength(500);
719  $this->form->addItem($tar);
720 
721  // Title
722  $tit = new ilTextInputGUI($this->lng->txt('webr_link_title'),'tit');
723  $tit->setRequired(true);
724  $tit->setSize(40);
725  $tit->setMaxLength(127);
726  $this->form->addItem($tit);
727 
728  // Description
729  $des = new ilTextAreaInputGUI($this->lng->txt('description'),'des');
730  $des->setRows(3);
731  $des->setCols(40);
732  $this->form->addItem($des);
733 
734  // Active
735  $act = new ilCheckboxInputGUI($this->lng->txt('active'),'act');
736  $act->setChecked(true);
737  $act->setValue(1);
738  $this->form->addItem($act);
739 
740  // Check
741  $che = new ilCheckboxInputGUI($this->lng->txt('webr_disable_check'),'che');
742  $che->setValue(1);
743  $this->form->addItem($che);
744 
745  // Valid
746  if($a_mode == self::LINK_MOD_EDIT)
747  {
748  $val = new ilCheckboxInputGUI($this->lng->txt('valid'),'vali');
749  $this->form->addItem($val);
750  }
751 
753  {
754  $dyn = new ilNonEditableValueGUI($this->lng->txt('links_dyn_parameter'));
755  $dyn->setInfo($this->lng->txt('links_dynamic_info'));
756 
757 
758  if(count($links = ilParameterAppender::_getParams((int) $_GET['link_id'])))
759  {
760  $ex = new ilCustomInputGUI($this->lng->txt('links_existing_params'),'ex');
761  $dyn->addSubItem($ex);
762 
763  foreach($links as $id => $link)
764  {
765  $p = new ilCustomInputGUI();
766 
767  $ptpl = new ilTemplate('tpl.link_dyn_param_edit.html',true,true,'Modules/WebResource');
768  $ptpl->setVariable('INFO_TXT',ilParameterAppender::parameterToInfo($link['name'], $link['value']));
769  $this->ctrl->setParameter($this,'param_id',$id);
770  $ptpl->setVariable('LINK_DEL',$this->ctrl->getLinkTarget($this,'deleteParameterForm'));
771  $ptpl->setVariable('LINK_TXT',$this->lng->txt('delete'));
772  $p->setHtml($ptpl->get());
773  $dyn->addSubItem($p);
774  }
775  }
776 
777  // Existing parameters
778 
779  // New parameter
780  if($a_mode == self::LINK_MOD_EDIT)
781  {
782  #$new = new ilCustomInputGUI($this->lng->txt('links_add_param'),'');
783  #$dyn->addSubItem($new);
784  }
785 
786  // Dynyamic name
787  $nam = new ilTextInputGUI($this->lng->txt('links_name'),'nam');
788  $nam->setSize(12);
789  $nam->setMaxLength(128);
790  $dyn->addSubItem($nam);
791 
792  // Dynamic value
793  $val = new ilSelectInputGUI($this->lng->txt('links_value'),'val');
795  $val->setValue(0);
796  $dyn->addSubItem($val);
797 
798  $this->form->addItem($dyn);
799  }
800  }
801 
807  protected function isContainerMetaDataRequired()
808  {
809  include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php';
810  return ilLinkResourceItems::lookupNumberOfLinks($this->object->getId()) == 1;
811  }
812 
817  protected function switchViewModeObject()
818  {
819  global $ilCtrl;
820 
821  $_REQUEST['view_mode'] = $_GET['view_mode'] = (int) $_GET['switch_mode'];
822  $this->viewObject();
823  }
824 
829  protected function editLinksObject()
830  {
831  $_GET['switch_mode'] = self::VIEW_MODE_MANAGE;
832  $this->switchViewModeObject();
833  }
834 
835 
840  public function viewObject()
841  {
842  global $ilAccess,$ilErr;
843 
844  $this->checkPermission('read');
845 
846  if (strtolower($_GET["baseClass"]) == "iladministrationgui")
847  {
849  return true;
850  }
851  else
852  {
853  switch((int) $_REQUEST['view_mode'])
854  {
855  case self::VIEW_MODE_MANAGE:
856  $this->manageObject();
857  break;
858 
859  case self::VIEW_MODE_SORT:
860  $this->sortObject();
861  break;
862 
863  default:
864  $this->showLinksObject();
865  break;
866  }
867  }
868  return true;
869  }
870 
875  protected function manageObject()
876  {
877  $this->checkPermission('write');
878  $this->activateTabs('content','cntr_manage');
879 
880  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.webr_manage.html','Modules/WebResource');
881  $this->showToolbar('ACTION_BUTTONS');
882 
883  include_once './Modules/WebResource/classes/class.ilWebResourceEditableLinkTableGUI.php';
884  $table = new ilWebResourceEditableLinkTableGUI($this,'view');
885  $table->parse();
886 
887  $this->tpl->setVariable('TABLE_LINKS',$table->getHTML());
888  }
889 
894  protected function showLinksObject()
895  {
896  $this->checkPermission('read');
897  $this->activateTabs('content','view');
898 
899  include_once './Modules/WebResource/classes/class.ilWebResourceLinkTableGUI.php';
900  $table = new ilWebResourceLinkTableGUI($this,'showLinks');
901  $table->parse();
902 
903  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.webr_view.html','Modules/WebResource');
904  $this->showToolbar('ACTION_BUTTONS');
905  $this->tpl->setVariable('LINK_TABLE',$table->getHTML());
906  }
907 
912  protected function sortObject()
913  {
914  $this->checkPermission('write');
915  $this->activateTabs('content','cntr_ordering');
916 
917  include_once './Modules/WebResource/classes/class.ilWebResourceLinkTableGUI.php';
918  $table = new ilWebResourceLinkTableGUI($this,'sort',true);
919  $table->parse();
920 
921  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.webr_view.html','Modules/WebResource');
922  $this->showToolbar('ACTION_BUTTONS');
923  $this->tpl->setVariable('LINK_TABLE',$table->getHTML());
924  }
925 
930  protected function saveSortingObject()
931  {
932  $this->checkPermission('write');
933 
934  include_once './Services/Container/classes/class.ilContainerSorting.php';
935  $sort = ilContainerSorting::_getInstance($this->object->getId());
936  $sort->savePost((array) $_POST['position']);
937 
938  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
939  $this->viewObject();
940  }
941 
942 
948  protected function showToolbar($a_tpl_var)
949  {
950  global $ilAccess;
951 
952  if(!$ilAccess->checkAccess('write','',$this->object->getRefId()))
953  {
954  return;
955  }
956 
957  include_once './Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php';
958  $tool = new ilToolbarGUI();
959  $tool->setFormAction($this->ctrl->getFormAction($this));
960  $tool->addButton(
961  $this->lng->txt('webr_add'),
962  $this->ctrl->getLinkTarget($this,'addLink')
963  );
964 
965  $this->tpl->setVariable($a_tpl_var,$tool->getHTML());
966  return;
967  }
968 
973  protected function confirmDeleteLinkObject()
974  {
975  $this->checkPermission('write');
976  $this->activateTabs('content','view');
977 
978  $link_ids = is_array($_POST['link_ids']) ?
979  $_POST['link_ids'] :
980  array($_GET['link_id']);
981 
982  if(!$link_ids)
983  {
984  ilUtil::sendFailure($this->lng->txt('select_one'));
985  $this->viewObject();
986  return false;
987  }
988 
989  include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php';
990  $links = new ilLinkResourceItems($this->object->getId());
991 
992  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
993  $confirm = new ilConfirmationGUI();
994  $confirm->setFormAction($this->ctrl->getFormAction($this,'view'));
995  $confirm->setHeaderText($this->lng->txt('webr_sure_delete_items'));
996  $confirm->setConfirm($this->lng->txt('delete'), 'deleteLinks');
997  $confirm->setCancel($this->lng->txt('cancel'), 'view');
998 
999  foreach($link_ids as $link_id)
1000  {
1001  $link = $links->getItem($link_id);
1002  $confirm->addItem('link_ids[]', $link_id,$link['title']);
1003  }
1004  $this->tpl->setContent($confirm->getHTML());
1005  }
1006 
1011  protected function deleteLinksObject()
1012  {
1013  global $ilCtrl;
1014 
1015  $this->checkPermission('write');
1016 
1017  include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php';
1018  $links = new ilLinkResourceItems($this->object->getId());
1019 
1020  foreach($_POST['link_ids'] as $link_id)
1021  {
1022  $links->delete($link_id);
1023  }
1024  ilUtil::sendSuccess($this->lng->txt('webr_deleted_items'),true);
1025  $ilCtrl->redirect($this,'view');
1026  }
1027 
1032  protected function deactivateLinkObject()
1033  {
1034  global $ilCtrl;
1035 
1036  $this->checkPermission('write');
1037 
1038  include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php';
1039  $links = new ilLinkResourceItems($this->object->getId());
1040 
1041  if(!$_GET['link_id'])
1042  {
1043  ilUtil::sendFailure($this->lng->txt('select_one'),true);
1044  $ilCtrl->redirect($this,'view');
1045  }
1046 
1047  $links->setLinkId((int) $_GET['link_id']);
1048  $links->updateActive(false);
1049 
1050  ilUtil::sendSuccess($this->lng->txt('webr_inactive_success'),true);
1051  $ilCtrl->redirect($this,'view');
1052  }
1053 
1054 
1060  function infoScreenObject()
1061  {
1062  $this->ctrl->setCmd("showSummary");
1063  $this->ctrl->setCmdClass("ilinfoscreengui");
1064  $this->infoScreen();
1065  }
1066 
1070  function infoScreen()
1071  {
1072  global $ilAccess;
1073 
1074  $this->checkPermission('visible');
1075  $this->tabs_gui->setTabActive('info_short');
1076 
1077  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
1078  $info = new ilInfoScreenGUI($this);
1079 
1080  $info->enablePrivateNotes();
1081 
1082  // standard meta data
1083  $info->addMetaDataSections($this->object->getId(),0, $this->object->getType());
1084 
1085  // forward the command
1086  $this->ctrl->forwardCommand($info);
1087  }
1088 
1089 
1090  function historyObject()
1091  {
1092  $this->checkPermission('write');
1093  $this->tabs_gui->setTabActive('history');
1094 
1095  include_once("classes/class.ilHistoryGUI.php");
1096 
1097  $hist_gui =& new ilHistoryGUI($this->object->getId());
1098 
1099  $hist_html = $hist_gui->getHistoryTable(array("ref_id" => $_GET["ref_id"],
1100  "cmd" => "history",
1101  "cmdClass" =>$_GET["cmdClass"],
1102  "cmdNode" =>$_GET["cmdNode"]));
1103 
1104  $this->tpl->setVariable("ADM_CONTENT", $hist_html);
1105  }
1106 
1111  protected function linkCheckerObject()
1112  {
1113  global $ilias,$ilUser;
1114 
1115  $this->checkPermission('write');
1116  $this->tabs_gui->setTabActive('link_check');
1117 
1118  $this->__initLinkChecker();
1119  $this->object->initLinkResourceItemsObject();
1120 
1121  $invalid_links = $this->link_checker_obj->getInvalidLinksFromDB();
1122 
1123 
1124  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.link_check.html",'Modules/WebResource');
1125 
1126  if($last_access = $this->link_checker_obj->getLastCheckTimestamp())
1127  {
1128  $this->tpl->setCurrentBlock("LAST_MODIFIED");
1129  $this->tpl->setVariable("AS_OF",$this->lng->txt('last_change').": ");
1130  $this->tpl->setVariable('LAST_CHECK',ilDatePresentation::formatDate(new ilDateTime($last_access,IL_CAL_UNIX)));
1131  $this->tpl->parseCurrentBlock();
1132  }
1133 
1134 
1135  $this->tpl->setVariable("F_ACTION",$this->ctrl->getFormAction($this, 'linkChecker'));
1136 
1137  $this->tpl->setVariable("TYPE_IMG",ilUtil::getImagePath('icon_webr.gif'));
1138  $this->tpl->setVariable("ALT_IMG",$this->lng->txt('obj_webr'));
1139  $this->tpl->setVariable("TITLE",$this->object->getTitle().' ('.$this->lng->txt('link_check').')');
1140  $this->tpl->setVariable("PAGE_TITLE",$this->lng->txt('title'));
1141  $this->tpl->setVariable("URL",$this->lng->txt('url'));
1142  $this->tpl->setVariable("OPTIONS",$this->lng->txt('edit'));
1143 
1144  if(!count($invalid_links))
1145  {
1146  $this->tpl->setCurrentBlock("no_invalid");
1147  $this->tpl->setVariable("TXT_NO_INVALID",$this->lng->txt('no_invalid_links'));
1148  $this->tpl->parseCurrentBlock();
1149  }
1150  else
1151  {
1152  $counter = 0;
1153  foreach($invalid_links as $invalid)
1154  {
1155  $this->object->items_obj->readItem($invalid['page_id']);
1156 
1157  $this->tpl->setCurrentBlock("invalid_row");
1158  $this->tpl->setVariable("ROW_COLOR",ilUtil::switchColor(++$counter,'tblrow1','tblrow2'));
1159  $this->tpl->setVariable("ROW_PAGE_TITLE",$this->object->items_obj->getTitle());
1160  $this->tpl->setVariable("ROW_URL",$invalid['url']);
1161 
1162 
1163  // EDIT IMAGE
1164  $this->ctrl->setParameter($this,'link_id',$invalid['page_id']);
1165  $this->tpl->setVariable("ROW_EDIT_LINK",$this->ctrl->getLinkTarget($this,'editLink'));
1166  $this->tpl->setVariable("ROW_IMG",ilUtil::getImagePath('icon_pencil.gif'));
1167  $this->tpl->setVariable("ROW_ALT_IMG",$this->lng->txt('edit'));
1168  $this->tpl->parseCurrentBlock();
1169  }
1170  }
1171  if((bool) $ilias->getSetting('cron_web_resource_check'))
1172  {
1173  include_once './classes/class.ilLinkCheckNotify.php';
1174 
1175  // Show message block
1176  $this->tpl->setCurrentBlock("MESSAGE_BLOCK");
1177  $this->tpl->setVariable("INFO_MESSAGE",$this->lng->txt('link_check_message_a'));
1178  $this->tpl->setVariable("CHECK_MESSAGE",ilUtil::formCheckbox(
1179  ilLinkCheckNotify::_getNotifyStatus($ilUser->getId(),$this->object->getId()),
1180  'link_check_message',
1181  1));
1182  $this->tpl->setVariable("INFO_MESSAGE_LONG",$this->lng->txt('link_check_message_b'));
1183  $this->tpl->parseCurrentBlock();
1184 
1185  // Show save button
1186  $this->tpl->setCurrentBlock("CRON_ENABLED");
1187  $this->tpl->setVariable("DOWNRIGHT_IMG",ilUtil::getImagePath('arrow_downright.gif'));
1188  $this->tpl->setVariable("BTN_SUBMIT_LINK_CHECK",$this->lng->txt('save'));
1189  $this->tpl->parseCurrentBlock();
1190  }
1191  $this->tpl->setVariable("BTN_REFRESH",$this->lng->txt('refresh'));
1192 
1193  return true;
1194 
1195  }
1197  {
1198  global $ilDB,$ilUser;
1199 
1200  include_once './classes/class.ilLinkCheckNotify.php';
1201 
1202  $link_check_notify =& new ilLinkCheckNotify($ilDB);
1203  $link_check_notify->setUserId($ilUser->getId());
1204  $link_check_notify->setObjId($this->object->getId());
1205 
1206  if($_POST['link_check_message'])
1207  {
1208  ilUtil::sendSuccess($this->lng->txt('link_check_message_enabled'));
1209  $link_check_notify->addNotifier();
1210  }
1211  else
1212  {
1213  ilUtil::sendSuccess($this->lng->txt('link_check_message_disabled'));
1214  $link_check_notify->deleteNotifier();
1215  }
1216  $this->linkCheckerObject();
1217 
1218  return true;
1219  }
1220 
1221 
1222 
1224  {
1225  $this->__initLinkChecker();
1226 
1227  if(!$this->link_checker_obj->checkPear())
1228  {
1229  ilUtil::sendFailure($this->lng->txt('missing_pear_library'));
1230  $this->linkCheckerObject();
1231 
1232  return false;
1233  }
1234 
1235 
1236  $this->object->initLinkResourceItemsObject();
1237 
1238  // Set all link to valid. After check invalid links will be set to invalid
1239  $this->object->items_obj->updateValidByCheck();
1240 
1241  foreach($this->link_checker_obj->checkWebResourceLinks() as $invalid)
1242  {
1243  $this->object->items_obj->readItem($invalid['page_id']);
1244  $this->object->items_obj->setActiveStatus(false);
1245  $this->object->items_obj->setValidStatus(false);
1246  $this->object->items_obj->update(false);
1247  }
1248 
1249  $this->object->items_obj->updateLastCheck();
1250  ilUtil::sendSuccess($this->lng->txt('link_checker_refreshed'));
1251 
1252  $this->linkCheckerObject();
1253 
1254  return true;
1255  }
1256 
1258  {
1259  global $ilDB;
1260 
1261  include_once './classes/class.ilLinkChecker.php';
1262 
1263  $this->link_checker_obj =& new ilLinkChecker($ilDB,false);
1264  $this->link_checker_obj->setObjId($this->object->getId());
1265 
1266  return true;
1267  }
1268 
1269 
1276  protected function activateTabs($a_active_tab,$a_active_subtab = '')
1277  {
1278  global $ilAccess,$ilCtrl;
1279 
1280  switch($a_active_tab)
1281  {
1282  case 'content':
1283  if($ilAccess->checkAccess('write','',$this->object->getRefId()))
1284  {
1285  $this->lng->loadLanguageModule('cntr');
1286 
1287  $this->ctrl->setParameter($this,'switch_mode',self::VIEW_MODE_VIEW);
1288  $this->tabs_gui->addSubTabTarget(
1289  'view',
1290  $this->ctrl->getLinkTarget($this,'switchViewMode')
1291  );
1292  $this->ctrl->setParameter($this,'switch_mode',self::VIEW_MODE_MANAGE);
1293  $this->tabs_gui->addSubTabTarget(
1294  'cntr_manage',
1295  $this->ctrl->getLinkTarget($this,'switchViewMode')
1296  );
1297  include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php';
1298  include_once './Services/Container/classes/class.ilContainerSortingSettings.php';
1299  include_once './Services/Container/classes/class.ilContainer.php';
1300  if((ilLinkResourceItems::lookupNumberOfLinks($this->object->getId()) > 1)
1302  {
1303  $this->ctrl->setParameter($this,'switch_mode',self::VIEW_MODE_SORT);
1304  $this->tabs_gui->addSubTabTarget(
1305  'cntr_ordering',
1306  $this->ctrl->getLinkTarget($this,'switchViewMode')
1307  );
1308  }
1309 
1310  $ilCtrl->clearParameters($this);
1311  $this->tabs_gui->setSubTabActive($a_active_subtab);
1312  }
1313 
1314  }
1315  $this->tabs_gui->setTabActive('content');
1316  }
1317 
1318 
1324  function getTabs($tabs_gui)
1325  {
1326  global $rbacreview,$ilAccess;
1327 
1328  if ($ilAccess->checkAccess('read','',$this->object->getRefId()))
1329  {
1330  $tabs_gui->addTarget(
1331  "content",
1332  $this->ctrl->getLinkTarget($this, "view"), array("", "view")
1333  );
1334  }
1335 
1336  if ($ilAccess->checkAccess('visible','',$this->ref_id))
1337  {
1338  $tabs_gui->addTarget(
1339  "info_short",
1340  $this->ctrl->getLinkTarget($this,'infoScreen')
1341  );
1342  }
1343 
1344  if($ilAccess->checkAccess('write','',$this->object->getRefId()) and !$this->getCreationMode())
1345  {
1346  include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php';
1347  if(ilLinkResourceItems::lookupNumberOfLinks($this->object->getId()) > 1)
1348  {
1349  $tabs_gui->addTarget(
1350  'settings',
1351  $this->ctrl->getLinkTarget($this,'settings')
1352  );
1353  }
1354 
1355  }
1356 
1357  if ($ilAccess->checkAccess('write','',$this->object->getRefId()))
1358  {
1359  $tabs_gui->addTarget("meta_data",
1360  $this->ctrl->getLinkTargetByClass('ilmdeditorgui','listSection'),
1361  "", 'ilmdeditorgui');
1362  }
1363 
1364  if ($ilAccess->checkAccess('write','',$this->object->getRefId()))
1365  {
1366  $tabs_gui->addTarget("history",
1367  $this->ctrl->getLinkTarget($this, "history"), "history", get_class($this));
1368  }
1369 
1370  if ($ilAccess->checkAccess('write','',$this->object->getRefId()))
1371  {
1372  // Check if pear library is available
1373  if(@include_once('HTTP/Request.php'))
1374  {
1375  $tabs_gui->addTarget("link_check",
1376  $this->ctrl->getLinkTarget($this, "linkChecker"),
1377  array("linkChecker", "refreshLinkCheck"), get_class($this));
1378  }
1379  }
1380 
1381  if ($ilAccess->checkAccess('edit_permission','',$this->object->getRefId()))
1382  {
1383  $tabs_gui->addTarget("perm_settings",
1384  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"), array("perm","info","owner"), 'ilpermissiongui');
1385  }
1386  }
1387 
1388  // PRIVATE
1389  function __prepareOutput()
1390  {
1391  // output objects
1392  $this->tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
1393  $this->tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
1394 
1395  // output locator
1396  $this->__setLocator();
1397 
1398  // output message
1399  if ($this->message)
1400  {
1401  ilUtil::sendInfo($this->message);
1402  }
1403 
1404  // display infopanel if something happened
1406 
1407  // set header
1408  $this->__setHeader();
1409  }
1410 
1411  function __setHeader()
1412  {
1413  include_once './classes/class.ilTabsGUI.php';
1414 
1415  $this->tpl->setCurrentBlock("header_image");
1416  $this->tpl->setVariable("IMG_HEADER", ilUtil::getImagePath("icon_webr_b.gif"));
1417  $this->tpl->parseCurrentBlock();
1418  $this->tpl->setVariable("HEADER",$this->object->getTitle());
1419  $this->tpl->setVariable("H_DESCRIPTION",$this->object->getDescription());
1420 
1421  #$tabs_gui =& new ilTabsGUI();
1422  $this->getTabs($this->tabs_gui);
1423 
1424  // output tabs
1425  #$this->tpl->setVariable("TABS", $tabs_gui->getHTML());
1426  }
1427 
1428  function __setLocator()
1429  {
1430  global $tree;
1431  global $ilias_locator, $lng;
1432 
1433  $this->tpl->addBlockFile("LOCATOR", "locator", "tpl.locator.html", "Services/Locator");
1434 
1435  $counter = 0;
1436 
1437  //$this->tpl->touchBlock('locator_separator');
1438  //$this->tpl->touchBlock('locator_item');
1439 
1440  foreach ($tree->getPathFull($this->object->getRefId()) as $key => $row)
1441  {
1442 
1443  //if ($row["child"] == $tree->getRootId())
1444  //{
1445  // continue;
1446  //}
1447 
1448  if($counter++)
1449  {
1450  $this->tpl->touchBlock('locator_separator_prefix');
1451  }
1452 
1453  if ($row["child"] > 0)
1454  {
1455  $this->tpl->setCurrentBlock("locator_img");
1456  $this->tpl->setVariable("IMG_SRC",
1457  ilUtil::getImagePath("icon_".$row["type"]."_s.gif"));
1458  $this->tpl->setVariable("IMG_ALT",
1459  $lng->txt("obj_".$type));
1460  $this->tpl->parseCurrentBlock();
1461  }
1462 
1463  $this->tpl->setCurrentBlock("locator_item");
1464 
1465  if($row["type"] == 'webr')
1466  {
1467  $this->tpl->setVariable("ITEM",$this->object->getTitle());
1468  $this->tpl->setVariable("LINK_ITEM",$this->ctrl->getLinkTarget($this));
1469  }
1470  elseif ($row["child"] != $tree->getRootId())
1471  {
1472  $this->tpl->setVariable("ITEM", $row["title"]);
1473  $this->tpl->setVariable("LINK_ITEM","./repository.php?ref_id=".$row["child"]);
1474  }
1475  else
1476  {
1477  $this->tpl->setVariable("ITEM", $this->lng->txt("repository"));
1478  $this->tpl->setVariable("LINK_ITEM","./repository.php?ref_id=".$row["child"]);
1479  }
1480 
1481  $this->tpl->parseCurrentBlock();
1482  }
1483 
1484  $this->tpl->setVariable("TXT_LOCATOR",$this->lng->txt("locator"));
1485  $this->tpl->parseCurrentBlock();
1486  }
1487 
1488  function _goto($a_target)
1489  {
1490  global $ilAccess, $ilErr, $lng;
1491 
1492  // Will be replaced in future releases by ilAccess::checkAccess()
1493  if ($ilAccess->checkAccess("read", "", $a_target))
1494  {
1495  ilUtil::redirect("ilias.php?baseClass=ilLinkResourceHandlerGUI&ref_id=$a_target");
1496  }
1497  else
1498  {
1499  // to do: force flat view
1500  if ($ilAccess->checkAccess("visible", "", $a_target))
1501  {
1502  ilUtil::redirect("ilias.php?baseClass=ilLinkResourceHandlerGUI&ref_id=".$a_target."&cmd=infoScreen");
1503  }
1504  else
1505  {
1506  if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
1507  {
1508  $_GET["cmd"] = "frameset";
1509  $_GET["target"] = "";
1510  $_GET["ref_id"] = ROOT_FOLDER_ID;
1511  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
1512  ilObject::_lookupTitle(ilObject::_lookupObjId($a_target))), true);
1513  include("repository.php");
1514  exit;
1515  }
1516  }
1517  }
1518 
1519  $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
1520  }
1521 } // END class.ilObjLinkResource
1522 ?>