ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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.ilTextWizardInputGUI.php');
35 include_once './Services/Form/classes/class.ilFileWizardInputGUI.php';
36 include_once './Services/Form/classes/class.ilFormulaInputGUI.php';
37 include_once './Services/Form/classes/class.ilBirthdayInputGUI.php';
38 
48 {
49  private $buttons = array();
50  private $items = array();
51  protected $mode = "std";
52  protected $check_input_called = false;
53  protected $disable_standard_message = false;
54  protected $top_anchor = "il_form_top";
55  protected $titleicon = false;
56  protected $description = "";
57  protected $tbl_width = false;
58  protected $show_top_buttons = true;
59  protected $hide_labels = false;
60 
66  function __construct()
67  {
68  global $lng;
69 
70  $lng->loadLanguageModule("form");
71 
72  // avoid double submission
73  $this->setPreventDoubleSubmission(true);
74 
75  // do it as early as possible
76  $this->rebuildUploadedFiles();
77  }
78 
82  function executeCommand()
83  {
84  global $ilCtrl;
85 
86  $next_class = $ilCtrl->getNextClass($this);
87  $cmd = $ilCtrl->getCmd();
88 
89  switch($next_class)
90  {
91  case 'ilformpropertydispatchgui':
92  $ilCtrl->saveParameter($this, 'postvar');
93  include_once './Services/Form/classes/class.ilFormPropertyDispatchGUI.php';
94  $form_prop_dispatch = new ilFormPropertyDispatchGUI();
95  $item = $this->getItemByPostVar($_REQUEST["postvar"]);
96  $form_prop_dispatch->setItem($item);
97  return $ilCtrl->forwardCommand($form_prop_dispatch);
98  break;
99 
100  }
101  return false;
102  }
103 
111  final public function setTableWidth($a_width)
112  {
113  $this->tbl_width = $a_width;
114  }
115 
122  final public function getTableWidth()
123  {
124  return $this->tbl_width;
125  }
126 
132  function setMode($a_mode)
133  {
134  $this->mode = $a_mode;
135  }
136 
142  function getMode()
143  {
144  return $this->mode;
145  }
146 
152  function setTitle($a_title)
153  {
154  $this->title = $a_title;
155  }
156 
162  function getTitle()
163  {
164  return $this->title;
165  }
166 
172  function setTitleIcon($a_titleicon)
173  {
174  $this->titleicon = $a_titleicon;
175  }
176 
182  function getTitleIcon()
183  {
184  return $this->titleicon;
185  }
186 
192  function setDescription($a_val)
193  {
194  $this->description = $a_val;
195  }
196 
202  function getDescription()
203  {
204  return $this->description;
205  }
206 
212  function setTopAnchor($a_val)
213  {
214  $this->top_anchor = $a_val;
215  }
216 
222  function getTopAnchor()
223  {
224  return $this->top_anchor;
225  }
226 
230  public function setShowTopButtons($a_val)
231  {
232  $this->show_top_buttons = $a_val;
233  }
234 
238  public function getShowTopButtons()
239  {
241  }
242 
248  function addItem($a_item)
249  {
250  $a_item->setParentForm($this);
251  return $this->items[] = $a_item;
252  }
253 
259  function removeItemByPostVar($a_post_var)
260  {
261  foreach ($this->items as $key => $item)
262  {
263  if (method_exists($item, "getPostVar") && $item->getPostVar() == $a_post_var)
264  {
265  unset($this->items[$key]);
266  }
267  }
268  }
269 
275  function getItemByPostVar($a_post_var)
276  {
277  foreach ($this->items as $key => $item)
278  {
279  if ($item->getType() != "section_header")
280  {
281  //if ($item->getPostVar() == $a_post_var)
282  $ret = $item->getItemByPostVar($a_post_var);
283  if (is_object($ret))
284  {
285  return $ret;
286  }
287  }
288  }
289 
290  return false;
291  }
292 
298  function setItems($a_items)
299  {
300  $this->items = $a_items;
301  }
302 
308  function getItems()
309  {
310  return $this->items;
311  }
312 
319  public function getInputItemsRecursive()
320  {
321  $inputItems = array();
322 
323  foreach($this->items as $item)
324  {
325  if( $item->getType() == 'section_header' )
326  {
327  continue;
328  }
329 
330  $inputItems[] = $item;
331 
332  if( $item instanceof ilSubEnabledFormPropertyGUI )
333  {
334  $inputItems = array_merge( $inputItems, $item->getSubInputItemsRecursive() );
335  }
336  }
337 
338  return $inputItems;
339  }
340 
346  function setDisableStandardMessage($a_val)
347  {
348  $this->disable_standard_message = $a_val;
349  }
350 
357  {
359  }
360 
366  function getHideLabels()
367  {
368  return $this->hide_labels;
369  }
370 
376  function setHideLabels($a_value = true)
377  {
378  $this->hide_labels = $a_value;
379  }
380 
386  function setValuesByArray($a_values, $a_restrict_to_value_keys = false)
387  {
388  foreach($this->items as $item)
389  {
390  if(!($a_restrict_to_value_keys) ||
391  in_array($item->getPostVar(), array_keys($a_values)))
392  {
393  $item->setValueByArray($a_values);
394  }
395  }
396  }
397 
402  function setValuesByPost()
403  {
404  foreach ($this->items as $item)
405  {
406  $item->setValueByArray($_POST);
407  }
408  }
409 
416  function checkInput()
417  {
418  global $lng;
419 
420  if ($this->check_input_called)
421  {
422  die ("Error: ilPropertyFormGUI->checkInput() called twice.");
423  }
424 
425  $ok = true;
426  foreach($this->items as $item)
427  {
428  $item_ok = $item->checkInput();
429  if(!$item_ok)
430  {
431  $ok = false;
432  }
433  }
434 
435  // check if POST is missint completely (if post_max_size exceeded)
436  if (count($this->items) > 0 && !is_array($_POST))
437  {
438  $ok = false;
439  }
440 
441  $this->check_input_called = true;
442 
443 
444 
445  // try to keep uploads for another try
446  if(!$ok && $_POST["ilfilehash"] && sizeof($_FILES))
447  {
448  $hash = $_POST["ilfilehash"];
449 
450  foreach($_FILES as $field => $data)
451  {
452  // we support up to 2 nesting levels (see test/assesment)
453  if(is_array($data["tmp_name"]))
454  {
455  foreach($data["tmp_name"] as $idx => $upload)
456  {
457  if(is_array($upload))
458  {
459  foreach($upload as $idx2 => $file)
460  {
461  if($file && is_uploaded_file($file))
462  {
463  $file_name = $data["name"][$idx][$idx2];
464  $file_type = $data["type"][$idx][$idx2];
465  $this->keepFileUpload($hash, $field, $file, $file_name, $file_type, $idx, $idx2);
466  }
467  }
468  }
469  else if($upload && is_uploaded_file($upload))
470  {
471  $file_name = $data["name"][$idx];
472  $file_type = $data["type"][$idx];
473  $this->keepFileUpload($hash, $field, $upload, $file_name, $file_type, $idx);
474  }
475  }
476  }
477  else
478  {
479  $this->keepFileUpload($hash, $field, $data["tmp_name"], $data["name"], $data["type"]);
480  }
481  }
482  }
483 
484 
485  if (!$ok && !$this->getDisableStandardMessage())
486  {
487  ilUtil::sendFailure($lng->txt("form_input_not_valid"));
488  }
489  return $ok;
490  }
491 
502  public function getInput($a_post_var, $ensureValidation = true)
503  {
504  // this check ensures, that checkInput has been called (incl. stripSlashes())
505  if (!$this->check_input_called && $ensureValidation)
506  {
507  die ("Error: ilPropertyFormGUI->getInput() called without calling checkInput() first.");
508  }
509 
510  return $_POST[$a_post_var];
511  }
512 
522  function addCustomProperty($a_title, $a_html, $a_info = "",
523  $a_alert = "", $a_required = false)
524  {
525  $this->properties[] = array ("type" => "custom",
526  "title" => $a_title,
527  "html" => $a_html,
528  "info" => $a_info);
529  }
530 
537  function addCommandButton($a_cmd, $a_text, $a_id = "")
538  {
539  $this->buttons[] = array("cmd" => $a_cmd, "text" => $a_text, "id" => $a_id);
540  }
541 
542 
548  public function getCommandButtons() {
549  return $this->buttons;
550  }
551 
556  {
557  $this->buttons = array();
558  }
559 
563  function getContent()
564  {
565  global $lng, $tpl, $ilUser, $ilSetting;
566 
567  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
571 
572  $tpl->addJavaScript("./Services/JavaScript/js/Basic.js");
573  $tpl->addJavaScript("Services/Form/js/Form.js");
574 
575  $this->tpl = new ilTemplate("tpl.property_form.html", true, true, "Services/Form");
576 
577  // check if form has not title and first item is a section header
578  // -> use section header for title and remove section header
579  // -> command buttons are presented on top
580  $fi = $this->items[0];
581  if ($this->getMode() == "std" &&
582  $this->getTitle() == "" &&
583  is_object($fi) && $fi->getType() == "section_header"
584  )
585  {
586  $this->setTitle($fi->getTitle());
587  unset($this->items[0]);
588  }
589 
590 
591  // title icon
592  if ($this->getTitleIcon() != "" && @is_file($this->getTitleIcon()))
593  {
594  $this->tpl->setCurrentBlock("title_icon");
595  $this->tpl->setVariable("IMG_ICON", $this->getTitleIcon());
596  $this->tpl->parseCurrentBlock();
597  }
598 
599  // title
600  if ($this->getTitle() != "")
601  {
602  // commands on top
603  if (count($this->buttons) > 0 && $this->getShowTopButtons() && count($this->items) > 2)
604  {
605  // command buttons
606  foreach($this->buttons as $button)
607  {
608  $this->tpl->setCurrentBlock("cmd2");
609  $this->tpl->setVariable("CMD", $button["cmd"]);
610  $this->tpl->setVariable("CMD_TXT", $button["text"]);
611  if ($button["id"] != "")
612  {
613  $this->tpl->setVariable("CMD2_ID", " id='".$button["id"]."_top'");
614  }
615  $this->tpl->parseCurrentBlock();
616  }
617  $this->tpl->setCurrentBlock("commands2");
618  $this->tpl->parseCurrentBlock();
619  }
620 
621  if (is_object($ilSetting))
622  {
623  if ($ilSetting->get('char_selector_availability') > 0)
624  {
625  require_once 'Services/UIComponent/CharSelector/classes/class.ilCharSelectorGUI.php';
627  {
628  $char_selector = ilCharSelectorGUI::_getCurrentGUI();
629  if ($char_selector->getConfig()->getAvailability() == ilCharSelectorConfig::ENABLED)
630  {
631  $char_selector->addToPage();
632  $this->tpl->TouchBlock('char_selector');
633  }
634  }
635  }
636  }
637 
638  $this->tpl->setCurrentBlock("header");
639  $this->tpl->setVariable("TXT_TITLE", $this->getTitle());
640  $this->tpl->setVariable("LABEL", $this->getTopAnchor());
641  $this->tpl->setVariable("TXT_DESCRIPTION", $this->getDescription());
642  $this->tpl->parseCurrentBlock();
643  }
644  $this->tpl->touchBlock("item");
645 
646  // properties
647  $this->required_text = false;
648  foreach($this->items as $item)
649  {
650  if ($item->getType() != "hidden")
651  {
652  $this->insertItem($item);
653  }
654  }
655 
656  // required
657  if ($this->required_text && $this->getMode() == "std")
658  {
659  $this->tpl->setCurrentBlock("required_text");
660  $this->tpl->setVariable("TXT_REQUIRED", $lng->txt("required_field"));
661  $this->tpl->parseCurrentBlock();
662  }
663 
664  // command buttons
665  foreach($this->buttons as $button)
666  {
667  $this->tpl->setCurrentBlock("cmd");
668  $this->tpl->setVariable("CMD", $button["cmd"]);
669  $this->tpl->setVariable("CMD_TXT", $button["text"]);
670 
671  if ($button["id"] != "")
672  {
673  $this->tpl->setVariable("CMD_ID", " id='".$button["id"]."'");
674  }
675 
676  $this->tpl->parseCurrentBlock();
677  }
678 
679  // #18808
680  if ($this->getMode() != "subform")
681  {
682  // try to keep uploads even if checking input fails
683  if($this->getMultipart())
684  {
685  $hash = $_POST["ilfilehash"];
686  if(!$hash)
687  {
688  $hash = md5(uniqid(mt_rand(), true));
689  }
690  $fhash = new ilHiddenInputGUI("ilfilehash");
691  $fhash->setValue($hash);
692  $this->addItem($fhash);
693  }
694  }
695 
696  // hidden properties
697  $hidden_fields = false;
698  foreach($this->items as $item)
699  {
700  if ($item->getType() == "hidden")
701  {
702  $item->insert($this->tpl);
703  $hidden_fields = true;
704  }
705  }
706 
707  if ($this->required_text || count($this->buttons) > 0 || $hidden_fields)
708  {
709  $this->tpl->setCurrentBlock("commands");
710  $this->tpl->parseCurrentBlock();
711  }
712 
713 
714  if ($this->getMode() == "subform")
715  {
716  $this->tpl->touchBlock("sub_table");
717  }
718  else
719  {
720  $this->tpl->touchBlock("std_table");
721  $this->tpl->setVariable('STD_TABLE_WIDTH',$this->getTableWidth());
722  }
723 
724  return $this->tpl->get();
725  }
726 
727  protected function hideRequired($a_type)
728  {
729  // #15818
730  return in_array($a_type, array("non_editable_value"));
731  }
732 
733  function insertItem($item, $a_sub_item = false)
734  {
735  global $tpl, $lng;
736 
737 
738  $cfg = array();
739 
740  //if(method_exists($item, "getMulti") && $item->getMulti())
741  if ($item instanceof ilMultiValuesItem && $item->getMulti())
742  {
743  $tpl->addJavascript("./Services/Form/js/ServiceFormMulti.js");
744 
745  $this->tpl->setCurrentBlock("multi_in");
746  $this->tpl->setVariable("ID", $item->getFieldId());
747  $this->tpl->parseCurrentBlock();
748 
749  $this->tpl->touchBlock("multi_out");
750 
751 
752  // add hidden item to enable preset multi items
753  // not used yet, should replace hidden field stuff
754  $multi_values = $item->getMultiValues();
755  if(is_array($multi_values) && sizeof($multi_values) > 1)
756  {
757  $multi_value = new ilHiddenInputGUI("ilMultiValues~".$item->getPostVar());
758  $multi_value->setValue(implode("~", $multi_values));
759  $this->addItem($multi_value);
760  }
761  $cfg["multi_values"] = $multi_values;
762  }
763 
764  $item->insert($this->tpl);
765 
766  if ($item->getType() == "file" || $item->getType() == "image_file")
767  {
768  $this->setMultipart(true);
769  }
770 
771  if ($item->getType() != "section_header")
772  {
773  $cfg["id"] = $item->getFieldId();
774 
775  // info text
776  if ($item->getInfo() != "")
777  {
778  $this->tpl->setCurrentBlock("description");
779  $this->tpl->setVariable("PROPERTY_DESCRIPTION",
780  $item->getInfo());
781  $this->tpl->parseCurrentBlock();
782  }
783 
784  if ($this->getMode() == "subform")
785  {
786  // required
787  if (!$this->hideRequired($item->getType()))
788  {
789  if ($item->getRequired())
790  {
791  $this->tpl->touchBlock("sub_required");
792  $this->required_text = true;
793  }
794  }
795 
796  // hidden title (for accessibility, e.g. file upload)
797  if ($item->getHiddenTitle() != "")
798  {
799  $this->tpl->setCurrentBlock("sub_hid_title");
800  $this->tpl->setVariable("SPHID_TITLE",
801  $item->getHiddenTitle());
802  $this->tpl->parseCurrentBlock();
803  }
804 
805  $this->tpl->setCurrentBlock("sub_prop_start");
806  $this->tpl->setVariable("PROPERTY_TITLE", $item->getTitle());
807  $this->tpl->setVariable("PROPERTY_CLASS", "il_".$item->getType());
808  if ($item->getType() != "non_editable_value")
809  {
810  $this->tpl->setVariable("LAB_ID", $item->getFieldId());
811  }
812  $this->tpl->parseCurrentBlock();
813  }
814  else
815  {
816  // required
817  if (!$this->hideRequired($item->getType()))
818  {
819  if ($item->getRequired())
820  {
821  $this->tpl->touchBlock("required");
822  $this->required_text = true;
823  }
824  }
825 
826  // hidden title (for accessibility, e.g. file upload)
827  if ($item->getHiddenTitle() != "")
828  {
829  $this->tpl->setCurrentBlock("std_hid_title");
830  $this->tpl->setVariable("PHID_TITLE",
831  $item->getHiddenTitle());
832  $this->tpl->parseCurrentBlock();
833  }
834 
835  $this->tpl->setCurrentBlock("std_prop_start");
836  $this->tpl->setVariable("PROPERTY_TITLE", $item->getTitle());
837  if ($item->getType() != "non_editable_value")
838  {
839  $this->tpl->setVariable("LAB_ID", $item->getFieldId());
840  }
841  if ($this->getHideLabels())
842  {
843  $this->tpl->setVariable("HIDE_LABELS_STYLE", " ilFormOptionHidden");
844  }
845  $this->tpl->parseCurrentBlock();
846  }
847 
848  // alert
849  if ($item->getType() != "non_editable_value" && $item->getAlert() != "")
850  {
851  $this->tpl->setCurrentBlock("alert");
852  $this->tpl->setVariable("IMG_ALERT",
853  ilUtil::getImagePath("icon_alert.svg"));
854  $this->tpl->setVariable("ALT_ALERT",
855  $lng->txt("alert"));
856  $this->tpl->setVariable("TXT_ALERT",
857  $item->getAlert());
858  $this->tpl->parseCurrentBlock();
859  }
860 
861  // subitems
862  $sf = null;
863  if ($item->getType() != "non_editable_value" or 1)
864  {
865  $sf = $item->getSubForm();
866  if ($item->hideSubForm() && is_object($sf))
867  {
868  $this->tpl->setCurrentBlock("sub_form_hide");
869  $this->tpl->setVariable("DSFID", $item->getFieldId());
870  $this->tpl->parseCurrentBlock();
871  }
872  }
873 
874 
875  $sf_content = "";
876  if (is_object($sf))
877  {
878  $sf_content = $sf->getContent();
879  if ($sf->getMultipart())
880  {
881  $this->setMultipart(true);
882  }
883  $this->tpl->setCurrentBlock("sub_form");
884  $this->tpl->setVariable("PROP_SUB_FORM", $sf_content);
885  $this->tpl->setVariable("SFID", $item->getFieldId());
886  $this->tpl->parseCurrentBlock();
887  }
888 
889  $this->tpl->setCurrentBlock("prop");
890  /* not used yet
891  $this->tpl->setVariable("ID", $item->getFieldId());
892  $this->tpl->setVariable("CFG", ilJsonUtil::encode($cfg));*/
893  $this->tpl->parseCurrentBlock();
894  }
895 
896 
897  $this->tpl->touchBlock("item");
898  }
899 
900  public function getHTML()
901  {
902  $html = parent::getHTML();
903 
904  // #13531 - get content that has to reside outside of the parent form tag, e.g. panels/layers
905  foreach($this->items as $item)
906  {
907  // #13536 - ilFormSectionHeaderGUI does NOT extend ilFormPropertyGUI ?!
908  if(method_exists($item, "getContentOutsideFormTag"))
909  {
910  $outside = $item->getContentOutsideFormTag();
911  if($outside)
912  {
913  $html .= $outside;
914  }
915  }
916  }
917 
918  return $html;
919  }
920 
921 
922  //
923  // UPLOAD HANDLING
924  //
925 
938  protected function keepFileUpload($a_hash, $a_field, $a_tmp_name, $a_name, $a_type, $a_index = null, $a_sub_index = null)
939  {
940  if (trim($a_tmp_name) == "")
941  {
942  return;
943  }
944  $a_name = ilUtil::getAsciiFileName($a_name);
945 
946  $tmp_file_name = implode("~~", array(session_id(),
947  $a_hash,
948  $a_field,
949  $a_index,
950  $a_sub_index,
951  str_replace("/", "~~", $a_type),
952  str_replace("~~", "_", $a_name)));
953 
954  // make sure temp directory exists
955  $temp_path = ilUtil::getDataDir() . "/temp";
956  if (!is_dir($temp_path))
957  {
958  ilUtil::createDirectory($temp_path);
959  }
960 
961  ilUtil::moveUploadedFile($a_tmp_name, $tmp_file_name, $temp_path . "/" . $tmp_file_name);
962 
964  $file_input = $this->getItemByPostVar($a_field);
965  $file_input->setPending($a_name);
966  }
967 
976  function getFileUpload($a_field, $a_index = null, $a_sub_index = null)
977  {
978  $res = array();
979  if($a_index)
980  {
981  if($_FILES[$a_field]["tmp_name"][$a_index][$a_sub_index])
982  {
983  $res = array(
984  "tmp_name" => $_FILES[$a_field]["tmp_name"][$a_index][$a_sub_index],
985  "name" => $_FILES[$a_field]["name"][$a_index][$a_sub_index],
986  "type" => $_FILES[$a_field]["type"][$a_index][$a_sub_index],
987  "error" => $_FILES[$a_field]["error"][$a_index][$a_sub_index],
988  "size" => $_FILES[$a_field]["size"][$a_index][$a_sub_index],
989  "is_upload" => true
990  );
991  }
992  }
993  else if($a_sub_index)
994  {
995  if($_FILES[$a_field]["tmp_name"][$a_index])
996  {
997  $res = array(
998  "tmp_name" => $_FILES[$a_field]["tmp_name"][$a_index],
999  "name" => $_FILES[$a_field]["name"][$a_index],
1000  "type" => $_FILES[$a_field]["type"][$a_index],
1001  "error" => $_FILES[$a_field]["error"][$a_index],
1002  "size" => $_FILES[$a_field]["size"][$a_index],
1003  "is_upload" => true
1004  );
1005  }
1006  }
1007  else
1008  {
1009  if($_FILES[$a_field]["tmp_name"])
1010  {
1011  $res = array(
1012  "tmp_name" => $_FILES[$a_field]["tmp_name"],
1013  "name" => $_FILES[$a_field]["name"],
1014  "type" => $_FILES[$a_field]["type"],
1015  "error" => $_FILES[$a_field]["error"],
1016  "size" => $_FILES[$a_field]["size"],
1017  "is_upload" => true
1018  );
1019  }
1020  }
1021  return $res;
1022  }
1023 
1032  function hasFileUpload($a_field, $a_index = null, $a_sub_index = null)
1033  {
1034  $data = $this->getFileUpload($a_field, $a_index, $a_sub_index);
1035  return (bool)$data["tmp_name"];
1036  }
1037 
1048  function moveFileUpload($a_target_directory, $a_field, $a_target_name = null, $a_index = null, $a_sub_index = null)
1049  {
1050  if(!is_dir($a_target_directory))
1051  {
1052  return;
1053  }
1054 
1055  $data = $this->getFileUpload($a_field, $a_index, $a_sub_index);
1056  if($data["tmp_name"] && file_exists($data["tmp_name"]))
1057  {
1058  if($a_target_name)
1059  {
1060  $data["name"] = $a_target_name;
1061  }
1062 
1063  $target_file = $a_target_directory."/".$data["name"];
1064  $target_file = str_replace("//", "/", $target_file);
1065 
1066  if($data["is_upload"])
1067  {
1068  if (!ilUtil::moveUploadedFile($data["tmp_name"], $data["name"], $target_file))
1069  {
1070  return;
1071  }
1072  }
1073  else
1074  {
1075  if (!rename($data["tmp_name"], $target_file))
1076  {
1077  return;
1078  }
1079  }
1080 
1081  return $target_file;
1082  }
1083  }
1084 
1088  protected function rebuildUploadedFiles()
1089  {
1090  if(isset($_POST["ilfilehash"]) && $_POST["ilfilehash"])
1091  {
1092  $temp_path = ilUtil::getDataDir() . "/temp";
1093  if(is_dir($temp_path))
1094  {
1095  $temp_files = glob($temp_path."/".session_id()."~~".$_POST["ilfilehash"]."~~*");
1096  if(is_array($temp_files))
1097  {
1098  foreach($temp_files as $full_file)
1099  {
1100  $file = explode("~~", basename($full_file));
1101  $field = $file[2];
1102  $idx = $file[3];
1103  $idx2 = $file[4];
1104  $type = $file[5]."/".$file[6];
1105  $name = $file[7];
1106 
1107  if($idx2 != "")
1108  {
1109  if(!$_FILES[$field]["tmp_name"][$idx][$idx2])
1110  {
1111  $_FILES[$field]["tmp_name"][$idx][$idx2] = $full_file;
1112  $_FILES[$field]["name"][$idx][$idx2] = $name;
1113  $_FILES[$field]["type"][$idx][$idx2] = $type;
1114  $_FILES[$field]["error"][$idx][$idx2] = 0;
1115  $_FILES[$field]["size"][$idx][$idx2] = filesize($full_file);
1116  }
1117  }
1118  else if($idx != "")
1119  {
1120  if(!$_FILES[$field]["tmp_name"][$idx])
1121  {
1122  $_FILES[$field]["tmp_name"][$idx] = $full_file;
1123  $_FILES[$field]["name"][$idx] = $name;
1124  $_FILES[$field]["type"][$idx] = $type;
1125  $_FILES[$field]["error"][$idx] = 0;
1126  $_FILES[$field]["size"][$idx] = filesize($full_file);
1127  }
1128  }
1129  else
1130  {
1131  if(!$_FILES[$field]["tmp_name"])
1132  {
1133  $_FILES[$field]["tmp_name"] = $full_file;
1134  $_FILES[$field]["name"] = $name;
1135  $_FILES[$field]["type"] = $type;
1136  $_FILES[$field]["error"] = 0;
1137  $_FILES[$field]["size"] = filesize($full_file);
1138  }
1139  }
1140  }
1141  }
1142  }
1143  }
1144  }
1145 }
1146 
1147 ?>
setPreventDoubleSubmission($a_val)
Set prevent double submission.
hasFileUpload($a_field, $a_index=null, $a_sub_index=null)
Was any file uploaded?
static _isAllowed()
Check if the CharSelector is allowed for the current GUI.
setTitleIcon($a_titleicon)
Set TitleIcon.
removeItemByPostVar($a_post_var)
Remove Item.
getDisableStandardMessage()
Get disable standard message.
getItemByPostVar($a_post_var)
Get Item by POST variable.
This class represents a property form user interface.
static initAnimation()
Init YUI Animation.
setItems($a_items)
Set Items.
getTableWidth()
get table width
$cmd
Definition: sahs_server.php:35
This class represents a form user interface.
getTitleIcon()
Get TitleIcon.
addItem($a_item)
Add Item (Property, SectionHeader).
setShowTopButtons($a_val)
Get show top buttons.
setValue($a_value)
Set Value.
getMode()
Get Mode (&#39;std&#39;, &#39;subform&#39;).
setMultipart($a_multipart)
Set Enctype Multipart/Formdata true/false.
global $tpl
Definition: ilias.php:8
getDescription()
Get description.
clearCommandButtons()
Remove all command buttons.
global $ilCtrl
Definition: ilias.php:18
executeCommand()
Execute command.
static initDom()
Init YUI Dom.
$a_type
Definition: workflow.php:93
moveFileUpload($a_target_directory, $a_field, $a_target_name=null, $a_index=null, $a_sub_index=null)
Move upload to target directory.
This class represents a hidden form property in a property form.
getTopAnchor()
Get top anchor.
setMode($a_mode)
Set Mode (&#39;std&#39;, &#39;subform&#39;).
addCustomProperty($a_title, $a_html, $a_info="", $a_alert="", $a_required=false)
Add a custom property.
setTitle($a_title)
Set Title.
setTopAnchor($a_val)
Set top anchor.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
special template class to simplify handling of ITX/PEAR
addCommandButton($a_cmd, $a_text, $a_id="")
Add Command button.
checkInput()
Check Post Input.
$ilUser
Definition: imgupload.php:18
setDisableStandardMessage($a_val)
Set disable standard message.
static _getCurrentGUI(ilObjTest $a_test_obj=null)
Get the GUI that is used for the currently available selector (other GUI instances may exist for conf...
static createDirectory($a_dir, $a_mod=0755)
create directory
getCommandButtons()
Return all Command buttons.
getShowTopButtons()
Set show top buttons.
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
static initEvent()
Init YUI Event.
insertItem($item, $a_sub_item=false)
Create styles array
The data for the language used.
setValuesByPost()
Set form values from POST values.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
Interface for multi values support.
getFileUpload($a_field, $a_index=null, $a_sub_index=null)
Get file upload data.
static getDataDir()
get data directory (outside webspace)
setHideLabels($a_value=true)
Set a value indicating whether the labels should be hidden or not.
getInputItemsRecursive()
returns a flat array of all input items including the possibly existing subitems recursively ...
global $ilSetting
Definition: privfeed.php:17
getHideLabels()
Get a value indicating whether the labels should be hidden or not.
This class represents a property that may include a sub form.
global $lng
Definition: privfeed.php:17
$ret
Definition: parser.php:6
setTableWidth($a_width)
Set table width.
Set document properties
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
rebuildUploadedFiles()
try to rebuild files
setDescription($a_val)
Set description.
$_POST["username"]
setValuesByArray($a_values, $a_restrict_to_value_keys=false)
Set form values from an array.
$html
Definition: example_001.php:87
getMultipart()
Get Enctype Multipart/Formdata true/false.