ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPropertyFormGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/Form/classes/class.ilFormGUI.php");
5 
6 // please do not add any more includes here if things are not really
7 // highly re-used
8 include_once("./Services/Form/classes/class.ilFormPropertyGUI.php");
9 include_once("./Services/Form/classes/class.ilSubEnabledFormPropertyGUI.php");
10 include_once("./Services/Form/classes/class.ilCheckboxInputGUI.php");
11 include_once("./Services/Form/classes/class.ilCustomInputGUI.php");
12 include_once("./Services/Form/classes/class.ilDateTimeInputGUI.php");
13 include_once("./Services/Form/classes/class.ilFileInputGUI.php");
14 include_once("./Services/Form/classes/class.ilImageFileInputGUI.php");
15 include_once('./Services/Form/classes/class.ilFlashFileInputGUI.php');
16 include_once("./Services/Form/classes/class.ilLocationInputGUI.php");
17 include_once("./Services/Form/classes/class.ilRadioGroupInputGUI.php");
18 include_once("./Services/Form/classes/class.ilCheckboxGroupInputGUI.php");
19 include_once("./Services/Form/classes/class.ilFormSectionHeaderGUI.php");
20 include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
21 include_once("./Services/Form/classes/class.ilTextAreaInputGUI.php");
22 include_once("./Services/Form/classes/class.ilTextInputGUI.php");
23 include_once("./Services/Form/classes/class.ilDurationInputGUI.php");
24 include_once("./Services/Form/classes/class.ilFeedUrlInputGUI.php");
25 include_once("./Services/Form/classes/class.ilNonEditableValueGUI.php");
26 include_once("./Services/Form/classes/class.ilRegExpInputGUI.php");
27 include_once('./Services/Form/classes/class.ilColorPickerInputGUI.php');
28 include_once('./Services/Form/classes/class.ilPasswordInputGUI.php');
29 include_once('./Services/Form/classes/class.ilUserLoginInputGUI.php');
30 include_once('./Services/Form/classes/class.ilEMailInputGUI.php');
31 include_once('./Services/Form/classes/class.ilHiddenInputGUI.php');
32 include_once('./Services/Form/classes/class.ilNumberInputGUI.php');
33 include_once('./Services/Form/classes/class.ilCSSRectInputGUI.php');
34 include_once('./Services/Form/classes/class.ilRadioMatrixInputGUI.php');
35 include_once('./Services/Form/classes/class.ilTextWizardInputGUI.php');
36 include_once './Services/Form/classes/class.ilFileWizardInputGUI.php';
37 include_once './Services/Form/classes/class.ilFormulaInputGUI.php';
38 include_once './Services/Form/classes/class.ilBirthdayInputGUI.php';
39 
49 {
50  private $buttons = array();
51  private $items = array();
52  protected $mode = "std";
53  protected $check_input_called = false;
54  protected $disable_standard_message = false;
55  protected $top_anchor = "il_form_top";
56  protected $titleicon = false;
57  protected $description = "";
58  protected $tbl_width = false;
59 
65  function ilPropertyFormGUI()
66  {
67  global $lng;
68 
69  $lng->loadLanguageModule("form");
71  }
72 
76  function &executeCommand()
77  {
78  global $ilCtrl;
79 
80  $next_class = $ilCtrl->getNextClass($this);
81  $cmd = $ilCtrl->getCmd();
82 
83  switch($next_class)
84  {
85  case 'ilformpropertydispatchgui':
86  include_once './Services/Form/classes/class.ilFormPropertyDispatchGUI.php';
87  $form_prop_dispatch = new ilFormPropertyDispatchGUI();
88  $item = $this->getItemByPostVar($_GET["postvar"]);
89  $form_prop_dispatch->setItem($item);
90  return $ilCtrl->forwardCommand($form_prop_dispatch);
91  break;
92 
93  }
94  return false;
95  }
96 
104  final public function setTableWidth($a_width)
105  {
106  $this->tbl_width = $a_width;
107  }
108 
115  final public function getTableWidth()
116  {
117  return $this->tbl_width;
118  }
119 
125  function setMode($a_mode)
126  {
127  $this->mode = $a_mode;
128  }
129 
135  function getMode()
136  {
137  return $this->mode;
138  }
139 
145  function setTitle($a_title)
146  {
147  $this->title = $a_title;
148  }
149 
155  function getTitle()
156  {
157  return $this->title;
158  }
159 
165  function setTitleIcon($a_titleicon)
166  {
167  $this->titleicon = $a_titleicon;
168  }
169 
175  function getTitleIcon()
176  {
177  return $this->titleicon;
178  }
179 
185  function setDescription($a_val)
186  {
187  $this->description = $a_val;
188  }
189 
195  function getDescription()
196  {
197  return $this->description;
198  }
199 
205  function setTopAnchor($a_val)
206  {
207  $this->top_anchor = $a_val;
208  }
209 
215  function getTopAnchor()
216  {
217  return $this->top_anchor;
218  }
219 
225  function addItem($a_item)
226  {
227  $a_item->setParentForm($this);
228  return $this->items[] = $a_item;
229  }
230 
236  function removeItemByPostVar($a_post_var)
237  {
238  foreach ($this->items as $key => $item)
239  {
240  if ($item->getPostVar() == $a_post_var)
241  {
242  unset($this->items[$key]);
243  }
244  }
245  }
246 
252  function getItemByPostVar($a_post_var)
253  {
254  foreach ($this->items as $key => $item)
255  {
256  if ($item->getType() != "section_header")
257  {
258  //if ($item->getPostVar() == $a_post_var)
259  $ret = $item->getItemByPostVar($a_post_var);
260  if (is_object($ret))
261  {
262  return $ret;
263  }
264  }
265  }
266 
267  return false;
268  }
269 
275  function setItems($a_items)
276  {
277  $this->items = $a_items;
278  }
279 
285  function getItems()
286  {
287  return $this->items;
288  }
289 
295  function setDisableStandardMessage($a_val)
296  {
297  $this->disable_standard_message = $a_val;
298  }
299 
306  {
308  }
309 
315  function setValuesByArray($a_values)
316  {
317  foreach($this->items as $item)
318  {
319  $item->setValueByArray($a_values);
320  }
321  }
322 
327  function setValuesByPost()
328  {
329  foreach($this->items as $item)
330  {
331  $item->setValueByArray($_POST);
332  }
333  }
334 
341  function checkInput()
342  {
343  global $lng;
344 
345  if ($this->check_input_called)
346  {
347  die ("Error: ilPropertyFormGUI->checkInput() called twice.");
348  }
349 
350  $ok = true;
351  foreach($this->items as $item)
352  {
353  $item_ok = $item->checkInput();
354  if(!$item_ok)
355  {
356  $ok = false;
357  }
358  }
359 
360  $this->check_input_called = true;
361 
362  if (!$ok && !$this->getDisableStandardMessage())
363  {
364  ilUtil::sendFailure($lng->txt("form_input_not_valid"));
365  }
366  return $ok;
367  }
368 
369  function getInput($a_post_var)
370  {
371  // this check ensures, that checkInput has been called (incl. stripSlashes())
372  if (!$this->check_input_called)
373  {
374  die ("Error: ilPropertyFormGUI->getInput() called without calling checkInput() first.");
375  }
376 
377  return $_POST[$a_post_var];
378  }
379 
389  function addCustomProperty($a_title, $a_html, $a_info = "",
390  $a_alert = "", $a_required = false)
391  {
392  $this->properties[] = array ("type" => "custom",
393  "title" => $a_title,
394  "html" => $a_html,
395  "info" => $a_info);
396  }
397 
404  function addCommandButton($a_cmd, $a_text)
405  {
406  $this->buttons[] = array("cmd" => $a_cmd, "text" => $a_text);
407  }
408 
413  {
414  $this->buttons = array();
415  }
416 
420  function getContent()
421  {
422  global $lng, $tpl;
423 
424  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
428 
429  $tpl->addJavaScript("Services/JavaScript/js/Basic.js");
430  $tpl->addJavaScript("Services/Form/js/ServiceForm.js");
431 
432  $this->tpl = new ilTemplate("tpl.property_form.html", true, true, "Services/Form");
433 
434  // title icon
435  if ($this->getTitleIcon() != "" && @is_file($this->getTitleIcon()))
436  {
437  $this->tpl->setCurrentBlock("title_icon");
438  $this->tpl->setVariable("IMG_ICON", $this->getTitleIcon());
439  $this->tpl->parseCurrentBlock();
440  }
441 
442  // title
443  if ($this->getTitle() != "")
444  {
445  $this->tpl->setCurrentBlock("header");
446  $this->tpl->setVariable("TXT_TITLE", $this->getTitle());
447  $this->tpl->setVariable("LABEL", $this->getTopAnchor());
448  $this->tpl->setVariable("TXT_DESCRIPTION", $this->getDescription());
449  $this->tpl->parseCurrentBlock();
450  }
451  $this->tpl->touchBlock("item");
452 
453  // properties
454  $this->required_text = false;
455  foreach($this->items as $item)
456  {
457  if ($item->getType() != "hidden")
458  {
459  $this->insertItem($item);
460  }
461  }
462 
463  // required
464  if ($this->required_text && $this->getMode() == "std")
465  {
466  $this->tpl->setCurrentBlock("required_text");
467  $this->tpl->setVariable("TXT_REQUIRED", $lng->txt("required_field"));
468  $this->tpl->parseCurrentBlock();
469  }
470 
471  // command buttons
472  foreach($this->buttons as $button)
473  {
474  $this->tpl->setCurrentBlock("cmd");
475  $this->tpl->setVariable("CMD", $button["cmd"]);
476  $this->tpl->setVariable("CMD_TXT", $button["text"]);
477  $this->tpl->parseCurrentBlock();
478  }
479 
480  // hidden properties
481  $hidden_fields = false;
482  foreach($this->items as $item)
483  {
484  if ($item->getType() == "hidden")
485  {
486  $item->insert($this->tpl);
487  $hidden_fields = true;
488  }
489  }
490 
491  if ($this->required_text || count($this->buttons) > 0 || $hidden_fields)
492  {
493  $this->tpl->setCurrentBlock("commands");
494  $this->tpl->parseCurrentBlock();
495  }
496 
497  if ($this->getMode() == "subform")
498  {
499  $this->tpl->touchBlock("sub_table");
500  }
501  else
502  {
503  $this->tpl->touchBlock("std_table");
504  $this->tpl->setVariable('STD_TABLE_WIDTH',$this->getTableWidth());
505  }
506 
507  return $this->tpl->get();
508  }
509 
510  function insertItem($item, $a_sub_item = false)
511  {
512  global $tpl, $lng;
513 
514  $item->insert($this->tpl);
515 
516  if ($item->getType() == "file" || $item->getType() == "image_file")
517  {
518  $this->setMultipart(true);
519  }
520 
521  if ($item->getType() != "section_header")
522  {
523  // info text
524  if ($item->getInfo() != "")
525  {
526  $this->tpl->setCurrentBlock("description");
527  //$this->tpl->setVariable("IMG_INFO",
528  // ilUtil::getImagePath("icon_info_s.gif"));
529  //$this->tpl->setVariable("ALT_INFO",
530  // $lng->txt("info_short"));
531  $this->tpl->setVariable("PROPERTY_DESCRIPTION",
532  $item->getInfo());
533  $this->tpl->parseCurrentBlock();
534  }
535 
536  if ($this->getMode() == "subform")
537  {
538  // required
539  if ($item->getType() != "non_editable_value")
540  {
541  if ($item->getRequired())
542  {
543  $this->tpl->touchBlock("sub_required");
544  $this->required_text = true;
545  }
546  }
547 
548  // hidden title (for accessibility, e.g. file upload)
549  if ($item->getHiddenTitle() != "")
550  {
551  $this->tpl->setCurrentBlock("sub_hid_title");
552  $this->tpl->setVariable("SPHID_TITLE",
553  $item->getHiddenTitle());
554  $this->tpl->parseCurrentBlock();
555  }
556 
557  $this->tpl->setCurrentBlock("sub_prop_start");
558  $this->tpl->setVariable("PROPERTY_TITLE", $item->getTitle());
559  if ($item->getType() != "non_editable_value")
560  {
561  $this->tpl->setVariable("LAB_ID", $item->getFieldId());
562  }
563  $this->tpl->parseCurrentBlock();
564  }
565  else
566  {
567  // required
568  if ($item->getType() != "non_editable_value")
569  {
570  if ($item->getRequired())
571  {
572  $this->tpl->touchBlock("required");
573  $this->required_text = true;
574  }
575  }
576 
577  // hidden title (for accessibility, e.g. file upload)
578  if ($item->getHiddenTitle() != "")
579  {
580  $this->tpl->setCurrentBlock("std_hid_title");
581  $this->tpl->setVariable("PHID_TITLE",
582  $item->getHiddenTitle());
583  $this->tpl->parseCurrentBlock();
584  }
585 
586  $this->tpl->setCurrentBlock("std_prop_start");
587  $this->tpl->setVariable("PROPERTY_TITLE", $item->getTitle());
588  if ($item->getType() != "non_editable_value")
589  {
590  $this->tpl->setVariable("LAB_ID", $item->getFieldId());
591  }
592  $this->tpl->parseCurrentBlock();
593  }
594 
595  // alert
596  if ($item->getType() != "non_editable_value" && $item->getAlert() != "")
597  {
598  $this->tpl->setCurrentBlock("alert");
599  $this->tpl->setVariable("IMG_ALERT",
600  ilUtil::getImagePath("icon_alert_s.gif"));
601  $this->tpl->setVariable("ALT_ALERT",
602  $lng->txt("alert"));
603  $this->tpl->setVariable("TXT_ALERT",
604  $item->getAlert());
605  $this->tpl->parseCurrentBlock();
606  }
607 
608  // subitems
609  $sf = null;
610  if ($item->getType() != "non_editable_value" or 1)
611  {
612  $sf = $item->getSubForm();
613  if ($item->hideSubForm() && is_object($sf))
614  {
615  $this->tpl->setCurrentBlock("sub_form_hide");
616  $this->tpl->setVariable("DSFID", $item->getFieldId());
617  $this->tpl->parseCurrentBlock();
618  }
619  }
620 
621 
622  $sf_content = "";
623  if (is_object($sf))
624  {
625  $sf_content = $sf->getContent();
626  if ($sf->getMultipart())
627  {
628  $this->setMultipart(true);
629  }
630  $this->tpl->setCurrentBlock("sub_form");
631  $this->tpl->setVariable("PROP_SUB_FORM", $sf_content);
632  $this->tpl->setVariable("SFID", $item->getFieldId());
633  $this->tpl->parseCurrentBlock();
634  }
635 
636  $this->tpl->setCurrentBlock("prop");
637 
638  $this->tpl->parseCurrentBlock();
639  }
640 
641  $this->tpl->touchBlock("item");
642  }
643 }