ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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{
17 const BOTH = "both";
18 const INT = "int";
19 const EXT = "ext";
21 protected $int_link_default_type = "RepositoryItem";
22 protected $int_link_default_obj = 0;
23 protected $int_link_filter_types = array("RepositoryItem");
24
31 function __construct($a_title = "", $a_postvar = "")
32 {
33 parent::__construct($a_title, $a_postvar);
34 $this->setType("link");
35 }
36
42 function setAllowedLinkTypes($a_val)
43 {
44 $this->allowed_link_types = $a_val;
45 }
46
53 {
55 }
56
63 function setInternalLinkDefault($a_type, $a_obj = 0)
64 {
65 $this->int_link_default_type = $a_type;
66 $this->int_link_default_obj = $a_obj;
67 }
68
74 function setInternalLinkFilterTypes(array $a_val)
75 {
76 $this->int_link_filter_types = $a_val;
77 }
78
82 function executeCommand()
83 {
84 global $ilCtrl, $lng;
85
86 $next_class = $ilCtrl->getNextClass($this);
87 $cmd = $ilCtrl->getCmd();
88
89 switch($next_class)
90 {
91 case "ilinternallinkgui":
92 $lng->loadLanguageModule("content");
93 require_once("./Services/Link/classes/class.ilInternalLinkGUI.php");
94 $link_gui = new ilInternalLinkGUI($this->int_link_default_type,
95 $this->int_link_default_obj);
96 foreach ($this->int_link_filter_types as $t)
97 {
98 $link_gui->filterLinkType($t);
99 }
100 $link_gui->setFilterWhiteList(true);
101 $link_gui->setMode("asynch");
102
103 $ret = $ilCtrl->forwardCommand($link_gui);
104 break;
105
106 default:
107 var_dump($cmd);
108 //exit();
109 }
110
111 return $ret;
112 }
113
119 function setValue($a_value)
120 {
121 $this->value = $a_value;
122 }
123
129 function getValue()
130 {
131 return $this->value;
132 }
133
139 function setValueByArray($a_values)
140 {
141 switch($a_values[$this->getPostVar()."_mode"])
142 {
143 case "int":
144 if($a_values[$this->getPostVar()."_ajax_type"] &&
145 $a_values[$this->getPostVar()."_ajax_id"])
146 {
147 $val = $a_values[$this->getPostVar()."_ajax_type"]."|".
148 $a_values[$this->getPostVar()."_ajax_id"];
149 if ($a_values[$this->getPostVar()."_ajax_target"] != "")
150 {
151 $val.= "|".$a_values[$this->getPostVar()."_ajax_target"];
152 }
153 $this->setValue($val);
154 }
155 break;
156
157 default:
158 if($a_values[$this->getPostVar()])
159 {
160 $this->setValue($a_values[$this->getPostVar()]);
161 }
162 break;
163 }
164 }
165
171 function checkInput()
172 {
173 global $lng;
174
175 // debugging
176 // return false;
177
178 if($this->getRequired())
179 {
180 switch($_POST[$this->getPostVar()."_mode"])
181 {
182 case "ext":
183 if(!$_POST[$this->getPostVar()])
184 {
185 $this->setAlert($lng->txt("msg_input_is_required"));
186 return false;
187 }
188 break;
189
190 case "int":
191 if(!$_POST[$this->getPostVar()."_ajax_type"] ||
192 !$_POST[$this->getPostVar()."_ajax_id"])
193 {
194 $this->setAlert($lng->txt("msg_input_is_required"));
195 return false;
196 }
197 break;
198
199 default:
200 $this->setAlert($lng->txt("msg_input_is_required"));
201 return false;
202 }
203 }
204
205 if($_POST[$this->getPostVar()."_mode"] == "int")
206 {
207 $_POST[$this->getPostVar()."_ajax_type"] = ilUtil::stripSlashes($_POST[$this->getPostVar()."_ajax_type"]);
208 $_POST[$this->getPostVar()."_ajax_id"] = ilUtil::stripSlashes($_POST[$this->getPostVar()."_ajax_id"]);
209 $_POST[$this->getPostVar()."_ajax_target"] = ilUtil::stripSlashes($_POST[$this->getPostVar()."_ajax_target"]);
210
211 // overwriting post-data so getInput() will work
212 $val = $_POST[$this->getPostVar()."_ajax_type"]."|".
213 $_POST[$this->getPostVar()."_ajax_id"];
214 if ($_POST[$this->getPostVar()."_ajax_target"] != "")
215 {
216 $val.= "|".$_POST[$this->getPostVar()."_ajax_target"];
217 }
218
219 $_POST[$this->getPostVar()] = $val;
220 }
221 else
222 {
224 }
225
226 return true;
227 }
228
232 function render()
233 {
234 global $lng, $ilCtrl;
235
236 // parse settings
237 $has_int = $has_ext = $has_radio = false;
238 switch($this->getAllowedLinkTypes())
239 {
240 case self::EXT:
241 $has_ext = true;
242 break;
243
244 case self::INT:
245 $has_int = true;
246 break;
247
248 case self::BOTH:
249 $has_int = true;
250 $has_ext = true;
251 $has_radio = true;
252 break;
253 }
254
255 // external
256 if($has_ext)
257 {
258 $title = $has_radio ? $lng->txt("url") : "";
259
260 // external
261 $ti = new ilTextInputGUI($title, $this->getPostVar());
262 $ti->setMaxLength(200);
263 $ti->setSize(50);
264 }
265
266 // internal
267 if($has_int)
268 {
269 $ilCtrl->setParameterByClass("ilformpropertydispatchgui", "postvar", $this->getPostVar());
270 $link = array(get_class($this->getParent()), "ilformpropertydispatchgui", get_class($this), "ilinternallinkgui");
271 $link = $ilCtrl->getLinkTargetByClass($link, "", false, true, false);
272 $ilCtrl->setParameterByClass("ilformpropertydispatchgui", "postvar", "");
273
274 $no_disp_class = (strpos($this->getValue(), "|"))
275 ? ""
276 : " ilNoDisplay";
277
278 $itpl = new ilTemplate('tpl.prop_link.html',true,true,'Services/Form');
279 $itpl->setVariable("VAL_ID", $this->getPostVar());
280 $itpl->setVariable("URL_EDIT", $link);
281 $itpl->setVariable("TXT_EDIT", $lng->txt("form_get_link"));
282 $itpl->setVariable("CSS_REMOVE", $no_disp_class);
283 $itpl->setVariable("TXT_REMOVE", $lng->txt("remove"));
284
285 $ne = new ilNonEditableValueGUI($lng->txt("object"), $this->getPostVar()."_val", true);
286
287 // hidden field for selected value
288 $hidden_type = new ilHiddenInputGUI($this->getPostVar()."_ajax_type");
289 $hidden_id = new ilHiddenInputGUI($this->getPostVar()."_ajax_id");
290 $hidden_target = new ilHiddenInputGUI($this->getPostVar()."_ajax_target");
291 }
292
293 // mode
294 if ($has_radio)
295 {
296 $ext = new ilRadioOption($lng->txt("form_link_external"), "ext");
297 $ext->addSubItem($ti);
298
299 $int = new ilRadioOption($lng->txt("form_link_internal"), "int");
300 $int->addSubItem($ne);
301
302 $mode = new ilRadioGroupInputGUI("", $this->getPostVar()."_mode");
303 $mode->addOption($ext);
304 $mode->addOption($int);
305 }
306 else
307 {
308 $mode = new ilHiddenInputGUI($this->getPostVar()."_mode");
309 if ($has_int)
310 {
311 $mode->setValue("int");
312 }
313 else
314 {
315 $mode->setValue("ext");
316 }
317 }
318
319 // value
320 $value = $this->getValue();
321 if($value)
322 {
323 // #15647
324 if($has_int && self::isInternalLink($value))
325 {
326 $mode->setValue("int");
327
328 $value_trans = self::getTranslatedValue($value);
329
330 $value = explode("|", $value);
331 $hidden_type->setValue($value[0]);
332 $hidden_id->setValue($value[1]);
333 $hidden_target->setValue($value[2]);
334
335 $itpl->setVariable("VAL_OBJECT_TYPE", $value_trans["type"]);
336 $itpl->setVariable("VAL_OBJECT_NAME", $value_trans["name"]);
337 }
338 else if($has_ext)
339 {
340 $mode->setValue("ext");
341
342 $ti->setValue($value);
343 }
344 }
345
346 // #10185 - default for external urls
347 if($has_ext && !$ti->getValue())
348 {
349 $ti->setValue("http://");
350 }
351
352 $ne->setValue($itpl->get());
353
354 // to html
355 if ($has_radio)
356 {
357 $html = $mode->render();
358 }
359 else
360 {
361 $html = $mode->getToolbarHTML();
362
363 if ($has_ext)
364 {
365 $html.= $ti->getToolbarHTML();
366 }
367 else
368 {
369 $html.= $ne->render().
370 '<div class="help-block">'.$ne->getInfo().'</div>';
371 }
372 }
373
374 // js for internal link
375 if($has_int)
376 {
377 include_once("./Services/Link/classes/class.ilInternalLinkGUI.php");
378 $html.= $hidden_type->getToolbarHTML().
379 $hidden_id->getToolbarHTML().
380 $hidden_target->getToolbarHTML();
381 }
382
383 return $html;
384 }
385
386 public function getContentOutsideFormTag()
387 {
388 if($this->getAllowedLinkTypes() == self::INT ||
389 $this->getAllowedLinkTypes() == self::BOTH)
390 {
391 // as the ajax-panel uses a form it has to be outside of the parent form!
393 }
394 }
395
396 public static function isInternalLink($a_value)
397 {
398 if(strpos($a_value, "|"))
399 {
400 $parts = explode("|", $a_value);
401 if(sizeof($parts) == 2 || sizeof($parts) == 3)
402 {
403 // numeric id
404 if(is_numeric($parts[1]))
405 {
406 // simple type
407 if(preg_match("/^[a-zA-Z_]+$/", $parts[0], $matches))
408 {
409 return true;
410 }
411 }
412 }
413 }
414 return false;
415 }
416
417 public static function getTranslatedValue($a_value)
418 {
419 global $lng;
420
421 $value = explode("|", $a_value);
422
423 switch($value[0])
424 {
425 case "media":
426 $type = $lng->txt("obj_mob");
427 $name = ilObject::_lookupTitle($value[1]);
428 break;
429
430 case "page":
431 include_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
432 $type = $lng->txt("obj_pg");
433 $name = ilLMPageObject::_lookupTitle($value[1]);
434 break;
435
436 case "term":
437 include_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
438 $type = $lng->txt("term");
439 $name = ilGlossaryTerm::_lookGlossaryTerm($value[1]);
440 break;
441
442 default:
443 $type = $lng->txt("obj_".$value[0]);
445 break;
446 }
447
448 return array("type"=>$type, "name"=>$name);
449 }
450
456 function insert(&$a_tpl)
457 {
458 $html = $this->render();
459
460 $a_tpl->setCurrentBlock("prop_generic");
461 $a_tpl->setVariable("PROP_GENERIC", $html);
462 $a_tpl->parseCurrentBlock();
463 }
464}
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.
getInitHTML($a_url, $a_move_to_body=false)
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.
getAllowedLinkTypes()
Get allowed link types (BOTH, INT, EXT)
setInternalLinkFilterTypes(array $a_val)
Set internal link filter types.
setValue($a_value)
Set Value.
static getTranslatedValue($a_value)
insert(&$a_tpl)
Insert property html.
executeCommand()
Execute current command.
__construct($a_title="", $a_postvar="")
Constructor.
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.
setValueByArray($a_values)
Set value by array.
static isInternalLink($a_value)
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
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
$_POST['username']
Definition: cron.php:12
$html
Definition: example_001.php:87
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:40
$cmd
Definition: sahs_server.php:35