ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilLinkInputGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3
16{
18
19 const BOTH = "both";
20 const INT = "int";
21 const EXT = "ext";
23 protected $int_link_default_type = "RepositoryItem";
24 protected $int_link_default_obj = 0;
25 protected $int_link_filter_types = array("RepositoryItem");
26 protected $filter_white_list = true;
27
29
30 static protected $iltypemap = array(
31 "page" => "PageObject",
32 "chap" => "StructureObject",
33 "term" => "GlossaryItem",
34 "wpage" => "WikiPage"
35 );
36
40 protected $obj_definition;
41
48 function __construct($a_title = "", $a_postvar = "")
49 {
50 global $DIC;
51 parent::__construct($a_title, $a_postvar);
52 $this->setType("link");
53
54 $this->obj_definition = $DIC["objDefinition"];
55 }
56
62 function setAllowedLinkTypes($a_val)
63 {
64 $this->allowed_link_types = $a_val;
65 }
66
73 {
75 }
76
83 function setInternalLinkDefault($a_type, $a_obj = 0)
84 {
85 $this->int_link_default_type = $a_type;
86 $this->int_link_default_obj = $a_obj;
87 }
88
94 function setInternalLinkFilterTypes(array $a_val)
95 {
96 $this->int_link_filter_types = $a_val;
97 }
98
104 static function getTypeToAttrType()
105 {
106 return self::$iltypemap;
107 }
108
114 static function getAttrTypeToType()
115 {
116 return array_flip(self::$iltypemap);
117 }
118
124 function setFilterWhiteList($a_val)
125 {
126 $this->filter_white_list = $a_val;
127 }
128
135 {
137 }
138
142 public function setExternalLinkMaxLength($a_max)
143 {
144 $this->external_link_max_length = $a_max;
145 }
146
150 public function getExternalLinkMaxLength()
151 {
153 }
154
158 function executeCommand()
159 {
160 global $ilCtrl, $lng;
161
162 $next_class = $ilCtrl->getNextClass($this);
163 $cmd = $ilCtrl->getCmd();
164
165 switch($next_class)
166 {
167 case "ilinternallinkgui":
168 $lng->loadLanguageModule("content");
169 require_once("./Services/Link/classes/class.ilInternalLinkGUI.php");
170 $link_gui = new ilInternalLinkGUI($this->int_link_default_type,
171 $this->int_link_default_obj);
172 foreach ($this->int_link_filter_types as $t)
173 {
174 $link_gui->filterLinkType($t);
175 }
176 $link_gui->setFilterWhiteList($this->getFilterWhiteList());
177 $link_gui->setMode("asynch");
178
179 $ret = $ilCtrl->forwardCommand($link_gui);
180 break;
181
182 default:
183 var_dump($cmd);
184 //exit();
185 }
186
187 return $ret;
188 }
189
195 function setValue($a_value)
196 {
197 $this->value = $a_value;
198 }
199
205 function getValue()
206 {
207 return $this->value;
208 }
209
215 function setValueByArray($a_values)
216 {
217 switch($a_values[$this->getPostVar()."_mode"])
218 {
219 case "int":
220 if($a_values[$this->getPostVar()."_ajax_type"] &&
221 $a_values[$this->getPostVar()."_ajax_id"])
222 {
223 $val = $a_values[$this->getPostVar()."_ajax_type"]."|".
224 $a_values[$this->getPostVar()."_ajax_id"];
225 if ($a_values[$this->getPostVar()."_ajax_target"] != "")
226 {
227 $val.= "|".$a_values[$this->getPostVar()."_ajax_target"];
228 }
229 $this->setValue($val);
230 }
231 break;
232
233 case "no":
234 break;
235
236 default:
237 if($a_values[$this->getPostVar()])
238 {
239 $this->setValue($a_values[$this->getPostVar()]);
240 }
241 break;
242 }
243 }
244
250 function checkInput()
251 {
252 global $lng;
253
254 // debugging
255 // return false;
256
257 if($this->getRequired())
258 {
259 switch($_POST[$this->getPostVar()."_mode"])
260 {
261 case "ext":
262 if(!$_POST[$this->getPostVar()])
263 {
264 $this->setAlert($lng->txt("msg_input_is_required"));
265 return false;
266 }
267 break;
268
269 case "int":
270 if(!$_POST[$this->getPostVar()."_ajax_type"] ||
271 !$_POST[$this->getPostVar()."_ajax_id"])
272 {
273 $this->setAlert($lng->txt("msg_input_is_required"));
274 return false;
275 }
276 break;
277
278 case "no":
279 default:
280 $this->setAlert($lng->txt("msg_input_is_required"));
281 return false;
282 }
283 }
284
285 if($_POST[$this->getPostVar()."_mode"] == "int")
286 {
287 $_POST[$this->getPostVar()."_ajax_type"] = ilUtil::stripSlashes($_POST[$this->getPostVar()."_ajax_type"]);
288 $_POST[$this->getPostVar()."_ajax_id"] = ilUtil::stripSlashes($_POST[$this->getPostVar()."_ajax_id"]);
289 $_POST[$this->getPostVar()."_ajax_target"] = ilUtil::stripSlashes($_POST[$this->getPostVar()."_ajax_target"]);
290
291 // overwriting post-data so getInput() will work
292 $val = $_POST[$this->getPostVar()."_ajax_type"]."|".
293 $_POST[$this->getPostVar()."_ajax_id"];
294 if ($_POST[$this->getPostVar()."_ajax_target"] != "")
295 {
296 $val.= "|".$_POST[$this->getPostVar()."_ajax_target"];
297 }
298
299 $_POST[$this->getPostVar()] = $val;
300 }
301 else if($_POST[$this->getPostVar()."_mode"] == "no")
302 {
303 $_POST[$this->getPostVar()] = "";
304 }
305 else
306 {
308 }
309
310 return true;
311 }
312
316 function render()
317 {
318 global $lng, $ilCtrl;
319
320 // parse settings
321 $has_int = $has_ext = $has_radio = false;
322 switch($this->getAllowedLinkTypes())
323 {
324 case self::EXT:
325 $has_ext = true;
326 break;
327
328 case self::INT:
329 $has_int = true;
330 break;
331
332 case self::BOTH:
333 $has_int = true;
334 $has_ext = true;
335 $has_radio = true;
336 break;
337 }
338 if (!$this->getRequired())
339 {
340 // see #0021274
341// $has_radio = true;
342 }
343
344 // external
345 if($has_ext)
346 {
347 $title = $has_radio ? $lng->txt("url") : "";
348
349 // external
350 $ti = new ilTextInputGUI($title, $this->getPostVar());
351 $ti->setMaxLength($this->getExternalLinkMaxLength());
352 }
353
354 // internal
355 if($has_int)
356 {
357 $ilCtrl->setParameterByClass("ilformpropertydispatchgui", "postvar", $this->getPostVar());
358 $link = array(get_class($this->getParent()), "ilformpropertydispatchgui", get_class($this), "ilinternallinkgui");
359 $link = $ilCtrl->getLinkTargetByClass($link, "", false, true, false);
360 $ilCtrl->setParameterByClass("ilformpropertydispatchgui", "postvar", $_REQUEST["postvar"]);
361
362 $no_disp_class = (strpos($this->getValue(), "|"))
363 ? ""
364 : " ilNoDisplay";
365
366 $itpl = new ilTemplate('tpl.prop_link.html',true,true,'Services/Form');
367 $itpl->setVariable("VAL_ID", $this->getPostVar());
368 $itpl->setVariable("URL_EDIT", $link);
369 $itpl->setVariable("TXT_EDIT", $lng->txt("form_get_link"));
370 $itpl->setVariable("CSS_REMOVE", $no_disp_class);
371 $itpl->setVariable("TXT_REMOVE", $lng->txt("remove"));
372
373 $ne = new ilNonEditableValueGUI($lng->txt("object"), $this->getPostVar()."_val", true);
374
375 // hidden field for selected value
376 $hidden_type = new ilHiddenInputGUI($this->getPostVar()."_ajax_type");
377 $hidden_id = new ilHiddenInputGUI($this->getPostVar()."_ajax_id");
378 $hidden_target = new ilHiddenInputGUI($this->getPostVar()."_ajax_target");
379 }
380
381 // mode
382 if ($has_radio)
383 {
384 $ext = new ilRadioOption($lng->txt("form_link_external"), "ext");
385 $ext->addSubItem($ti);
386
387 $int = new ilRadioOption($lng->txt("form_link_internal"), "int");
388 $int->addSubItem($ne);
389
390 $mode = new ilRadioGroupInputGUI("", $this->getPostVar()."_mode");
391 if (!$this->getRequired())
392 {
393 $no = new ilRadioOption($lng->txt("form_no_link"), "no");
394 $mode->addOption($no);
395 }
396 $mode->addOption($ext);
397 $mode->addOption($int);
398 }
399 else
400 {
401 $mode = new ilHiddenInputGUI($this->getPostVar()."_mode");
402 if ($has_int)
403 {
404 $mode->setValue("int");
405 }
406 else
407 {
408 $mode->setValue("ext");
409 }
410 }
411
412 // value
413 $value = $this->getValue();
414 if($value)
415 {
416 // #15647
417 if($has_int && self::isInternalLink($value))
418 {
419 $mode->setValue("int");
420
421 $value_trans = self::getTranslatedValue($value);
422
423 $value = explode("|", $value);
424 $hidden_type->setValue($value[0]);
425 $hidden_id->setValue($value[1]);
426 $hidden_target->setValue($value[2]);
427
428 $itpl->setVariable("VAL_OBJECT_TYPE", $value_trans["type"]);
429 $itpl->setVariable("VAL_OBJECT_NAME", $value_trans["name"]);
430 if ($value[2] != "")
431 {
432 $itpl->setVariable("VAL_TARGET_FRAME", "(" . $value[2].")");
433 }
434 }
435 else if($has_ext)
436 {
437 $mode->setValue("ext");
438
439 $ti->setValue($value);
440 }
441 }
442 else if (!$this->getRequired())
443 {
444 $mode->setValue("no");
445 }
446
447 // #10185 - default for external urls
448 if($has_ext && !$ti->getValue())
449 {
450 $ti->setValue("http://");
451 }
452
453 $ne->setValue($itpl->get());
454
455 // to html
456 if ($has_radio)
457 {
458 $html = $mode->render();
459 }
460 else
461 {
462 $html = $mode->getToolbarHTML();
463
464 if ($has_ext)
465 {
466 $html.= $ti->getToolbarHTML();
467 }
468 else
469 {
470 $html.= $ne->render().
471 '<div class="help-block">'.$ne->getInfo().'</div>';
472 }
473 }
474
475 // js for internal link
476 if($has_int)
477 {
478 include_once("./Services/Link/classes/class.ilInternalLinkGUI.php");
479 $html.= $hidden_type->getToolbarHTML().
480 $hidden_id->getToolbarHTML().
481 $hidden_target->getToolbarHTML();
482 }
483
484 return $html;
485 }
486
487 public function getContentOutsideFormTag()
488 {
489 if($this->getAllowedLinkTypes() == self::INT ||
490 $this->getAllowedLinkTypes() == self::BOTH)
491 {
492 // as the ajax-panel uses a form it has to be outside of the parent form!
494 }
495 }
496
497 public static function isInternalLink($a_value)
498 {
499 if(strpos($a_value, "|"))
500 {
501 $parts = explode("|", $a_value);
502 if(sizeof($parts) == 2 || sizeof($parts) == 3)
503 {
504 // numeric id
505 if(is_numeric($parts[1]))
506 {
507 // simple type
508 if(preg_match("/^[a-zA-Z_]+$/", $parts[0], $matches))
509 {
510 return true;
511 }
512 }
513 }
514 }
515 return false;
516 }
517
518 public static function getTranslatedValue($a_value)
519 {
520 global $lng;
521
522 $value = explode("|", $a_value);
523
524 switch($value[0])
525 {
526 case "media":
527 $type = $lng->txt("obj_mob");
528 $name = ilObject::_lookupTitle($value[1]);
529 break;
530
531 case "page":
532 include_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
533 $type = $lng->txt("obj_pg");
534 $name = ilLMPageObject::_lookupTitle($value[1]);
535 break;
536
537 case "chap":
538 include_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
539 $type = $lng->txt("obj_st");
540 $name = ilStructureObject::_lookupTitle($value[1]);
541 break;
542
543 case "term":
544 include_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
545 $type = $lng->txt("term");
546 $name = ilGlossaryTerm::_lookGlossaryTerm($value[1]);
547 break;
548
549 default:
550 $type = $lng->txt("obj_".$value[0]);
552 break;
553 }
554
555 return array("type"=>$type, "name"=>$name);
556 }
557
563 function insert($a_tpl)
564 {
565 $html = $this->render();
566
567 $a_tpl->setCurrentBlock("prop_generic");
568 $a_tpl->setVariable("PROP_GENERIC", $html);
569 $a_tpl->parseCurrentBlock();
570 }
571
578 {
579 $val = explode("|", $_POST[$this->getPostVar()]);
580
581 $ret = false;
582 $type = "";
583 $target = "";
584 if (self::isInternalLink($_POST[$this->getPostVar()]))
585 {
586 $target_frame = $val[2];
588 if (isset($map[$val[0]]))
589 {
590 $type = $map[$val[0]];
591 $target_type = $val[0];
592 if ($val[0] == "chap")
593 {
594 $target_type = "st";
595 }
596 if ($val[0] == "term")
597 {
598 $target_type = "git";
599 }
600 if ($val[0] == "page")
601 {
602 $target_type = "pg";
603 }
604 $target = "il__".$target_type."_".$val[1];
605 }
606 else if ($this->obj_definition->isRBACObject($val[0]))
607 {
608 $type = "RepositoryItem";
609 $target = "il__obj_".$val[1];
610 }
611 if ($type != "")
612 {
613 $ret = array(
614 "Target" => $target,
615 "Type" => $type,
616 "TargetFrame" => $target_frame
617 );
618 }
619 }
620 return $ret;
621 }
622
629 function setValueByIntLinkAttributes($a_type, $a_target, $a_target_frame = "")
630 {
631 $t = explode("_", $a_target);
632 $target_id = $t[3];
633 $type = "";
635 if ($a_type == "RepositoryItem")
636 {
638 }
639 else if (isset($map[$a_type]))
640 {
641 $type = $map[$a_type];
642 }
643 if ($type != "" && $target_id != "")
644 {
645 $val = $type."|".$target_id;
646 if ($a_target_frame != "")
647 {
648 $val.= "|".$a_target_frame;
649 }
650 $this->setValue($val);
651 }
652 }
653
654
655}
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
This class represents a property in a property form.
setType($a_type)
Set Type.
getPostVar()
Get Post Variable.
setAlert($a_alert)
Set Alert Text.
getParent()
Get Parent GUI object.
static _lookGlossaryTerm($term_id)
get glossary term
This class represents a hidden form property in a property form.
Class ilInternalLinkGUI.
static getInitHTML($a_url)
Get initialisation HTML to use interna link editing.
static _lookupTitle($a_obj_id)
Lookup title.
This class represents a external and/or internal link in a property form.
checkInput()
Check input, strip slashes etc.
getFilterWhiteList()
Get filter white list.
getAllowedLinkTypes()
Get allowed link types (BOTH, INT, EXT)
setInternalLinkFilterTypes(array $a_val)
Set internal link filter types.
setValueByIntLinkAttributes($a_type, $a_target, $a_target_frame="")
Set value by internal links attributes.
setValue($a_value)
Set Value.
static getTranslatedValue($a_value)
executeCommand()
Execute current command.
setFilterWhiteList($a_val)
Set filter white list.
__construct($a_title="", $a_postvar="")
Constructor.
insert($a_tpl)
Insert property html.
getContentOutsideFormTag()
Get content that has to reside outside of the parent form tag, e.g.
setInternalLinkDefault($a_type, $a_obj=0)
Set internal link default.
static getAttrTypeToType()
Get internal types to xml attribute types map (reverse)
static getTypeToAttrType()
Get internal types to xml attribute types map.
setValueByArray($a_values)
Set value by array.
static isInternalLink($a_value)
getIntLinkAttributes()
Get value as internal link attributes.
setAllowedLinkTypes($a_val)
Set allowed link types (BOTH, INT, EXT)
This class represents a non editable value in a property form.
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
static _lookupType($a_id, $a_reference=false)
lookup object type
This class represents a property in a property form.
This class represents an option in a radio group.
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
$html
Definition: example_001.php:87
$target_id
Definition: goto.php:51
$target_type
Definition: goto.php:50
global $ilCtrl
Definition: ilias.php:18
$ret
Definition: parser.php:6
global $lng
Definition: privfeed.php:17
$cmd
Definition: sahs_server.php:35
global $DIC
$a_type
Definition: workflow.php:93