ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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 $reloaded_files;
60  protected $hide_labels = false;
61 
67  function ilPropertyFormGUI()
68  {
69  global $lng;
70 
71  $lng->loadLanguageModule("form");
72  parent::ilFormGUI();
73 
74  // avoid double submission
75  $this->setPreventDoubleSubmission(true);
76 
77  // do it as early as possible
78  $this->rebuildUploadedFiles();
79  }
80 
84  function &executeCommand()
85  {
86  global $ilCtrl;
87 
88  $next_class = $ilCtrl->getNextClass($this);
89  $cmd = $ilCtrl->getCmd();
90 
91  switch($next_class)
92  {
93  case 'ilformpropertydispatchgui':
94  $ilCtrl->saveParameter($this, 'postvar');
95  include_once './Services/Form/classes/class.ilFormPropertyDispatchGUI.php';
96  $form_prop_dispatch = new ilFormPropertyDispatchGUI();
97  $item = $this->getItemByPostVar($_REQUEST["postvar"]);
98  $form_prop_dispatch->setItem($item);
99  return $ilCtrl->forwardCommand($form_prop_dispatch);
100  break;
101 
102  }
103  return false;
104  }
105 
113  final public function setTableWidth($a_width)
114  {
115  $this->tbl_width = $a_width;
116  }
117 
124  final public function getTableWidth()
125  {
126  return $this->tbl_width;
127  }
128 
134  function setMode($a_mode)
135  {
136  $this->mode = $a_mode;
137  }
138 
144  function getMode()
145  {
146  return $this->mode;
147  }
148 
154  function setTitle($a_title)
155  {
156  $this->title = $a_title;
157  }
158 
164  function getTitle()
165  {
166  return $this->title;
167  }
168 
174  function setTitleIcon($a_titleicon)
175  {
176  $this->titleicon = $a_titleicon;
177  }
178 
184  function getTitleIcon()
185  {
186  return $this->titleicon;
187  }
188 
194  function setDescription($a_val)
195  {
196  $this->description = $a_val;
197  }
198 
204  function getDescription()
205  {
206  return $this->description;
207  }
208 
214  function setTopAnchor($a_val)
215  {
216  $this->top_anchor = $a_val;
217  }
218 
224  function getTopAnchor()
225  {
226  return $this->top_anchor;
227  }
228 
232  public function setShowTopButtons($a_val)
233  {
234  $this->show_top_buttons = $a_val;
235  }
236 
240  public function getShowTopButtons()
241  {
243  }
244 
250  function addItem($a_item)
251  {
252  $a_item->setParentForm($this);
253  return $this->items[] = $a_item;
254  }
255 
261  function removeItemByPostVar($a_post_var)
262  {
263  foreach ($this->items as $key => $item)
264  {
265  if (method_exists($item, "getPostVar") && $item->getPostVar() == $a_post_var)
266  {
267  unset($this->items[$key]);
268  }
269  }
270  }
271 
277  function getItemByPostVar($a_post_var)
278  {
279  foreach ($this->items as $key => $item)
280  {
281  if ($item->getType() != "section_header")
282  {
283  //if ($item->getPostVar() == $a_post_var)
284  $ret = $item->getItemByPostVar($a_post_var);
285  if (is_object($ret))
286  {
287  return $ret;
288  }
289  }
290  }
291 
292  return false;
293  }
294 
300  function setItems($a_items)
301  {
302  $this->items = $a_items;
303  }
304 
310  function getItems()
311  {
312  return $this->items;
313  }
314 
321  public function getInputItemsRecursive()
322  {
323  $inputItems = array();
324 
325  foreach($this->items as $item)
326  {
327  if( $item->getType() == 'section_header' )
328  {
329  continue;
330  }
331 
332  $inputItems[] = $item;
333 
334  if( $item instanceof ilSubEnabledFormPropertyGUI )
335  {
336  $inputItems = array_merge( $inputItems, $item->getSubInputItemsRecursive() );
337  }
338  }
339 
340  return $inputItems;
341  }
342 
348  function setDisableStandardMessage($a_val)
349  {
350  $this->disable_standard_message = $a_val;
351  }
352 
359  {
361  }
362 
368  function getHideLabels()
369  {
370  return $this->hide_labels;
371  }
372 
378  function setHideLabels($a_value = true)
379  {
380  $this->hide_labels = $a_value;
381  }
382 
388  function setValuesByArray($a_values, $a_restrict_to_value_keys = false)
389  {
390  foreach($this->items as $item)
391  {
392  if(!($a_restrict_to_value_keys) ||
393  in_array($item->getPostVar(), array_keys($a_values)))
394  {
395  $item->setValueByArray($a_values);
396  }
397  }
398  }
399 
404  function setValuesByPost()
405  {
406  foreach($this->items as $item)
407  {
408  $item->setValueByArray($_POST);
409  }
410  }
411 
418  function checkInput()
419  {
420  global $lng;
421 
422  if ($this->check_input_called)
423  {
424  die ("Error: ilPropertyFormGUI->checkInput() called twice.");
425  }
426 
427  $ok = true;
428  foreach($this->items as $item)
429  {
430  $item_ok = $item->checkInput();
431  if(!$item_ok)
432  {
433  $ok = false;
434  }
435  }
436 
437  // check if POST is missint completely (if post_max_size exceeded)
438  if (count($this->items) > 0 && !is_array($_POST))
439  {
440  $ok = false;
441  }
442 
443  $this->check_input_called = true;
444 
445 
446 
447  // try to keep uploads for another try
448  if(!$ok && $_POST["ilfilehash"] && sizeof($_FILES))
449  {
450  $hash = $_POST["ilfilehash"];
451 
452  foreach($_FILES as $field => $data)
453  {
454  // we support up to 2 nesting levels (see test/assesment)
455  if(is_array($data["tmp_name"]))
456  {
457  foreach($data["tmp_name"] as $idx => $upload)
458  {
459  if(is_array($upload))
460  {
461  foreach($upload as $idx2 => $file)
462  {
463  if($file && is_uploaded_file($file))
464  {
465  $file_name = $data["name"][$idx][$idx2];
466  $file_type = $data["type"][$idx][$idx2];
467  $this->keepFileUpload($hash, $field, $file, $file_name, $file_type, $idx, $idx2);
468  }
469  }
470  }
471  else if($upload && is_uploaded_file($upload))
472  {
473  $file_name = $data["name"][$idx];
474  $file_type = $data["type"][$idx];
475  $this->keepFileUpload($hash, $field, $upload, $file_name, $file_type, $idx);
476  }
477  }
478  }
479  else
480  {
481  $this->keepFileUpload($hash, $field, $data["tmp_name"], $data["name"], $data["type"]);
482  }
483  }
484  }
485 
486 
487  if (!$ok && !$this->getDisableStandardMessage())
488  {
489  ilUtil::sendFailure($lng->txt("form_input_not_valid"));
490  }
491  return $ok;
492  }
493 
504  public function getInput($a_post_var, $ensureValidation = true)
505  {
506  // this check ensures, that checkInput has been called (incl. stripSlashes())
507  if (!$this->check_input_called && $ensureValidation)
508  {
509  die ("Error: ilPropertyFormGUI->getInput() called without calling checkInput() first.");
510  }
511 
512  return $_POST[$a_post_var];
513  }
514 
524  function addCustomProperty($a_title, $a_html, $a_info = "",
525  $a_alert = "", $a_required = false)
526  {
527  $this->properties[] = array ("type" => "custom",
528  "title" => $a_title,
529  "html" => $a_html,
530  "info" => $a_info);
531  }
532 
539  function addCommandButton($a_cmd, $a_text)
540  {
541  $this->buttons[] = array("cmd" => $a_cmd, "text" => $a_text);
542  }
543 
548  {
549  $this->buttons = array();
550  }
551 
555  function getContent()
556  {
557  global $lng, $tpl, $ilUser, $ilSetting;
558 
559  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
563 
564  $tpl->addJavaScript("./Services/JavaScript/js/Basic.js");
565  $tpl->addJavaScript("Services/Form/js/Form.js");
566 
567  $this->tpl = new ilTemplate("tpl.property_form.html", true, true, "Services/Form");
568 
569  // check if form has not title and first item is a section header
570  // -> use section header for title and remove section header
571  // -> command buttons are presented on top
572  $fi = $this->items[0];
573  if ($this->getMode() == "std" &&
574  $this->getTitle() == "" &&
575  is_object($fi) && $fi->getType() == "section_header"
576  )
577  {
578  $this->setTitle($fi->getTitle());
579  unset($this->items[0]);
580  }
581 
582 
583  // title icon
584  if ($this->getTitleIcon() != "" && @is_file($this->getTitleIcon()))
585  {
586  $this->tpl->setCurrentBlock("title_icon");
587  $this->tpl->setVariable("IMG_ICON", $this->getTitleIcon());
588  $this->tpl->parseCurrentBlock();
589  }
590 
591  // title
592  if ($this->getTitle() != "")
593  {
594  // commands on top
595  if (count($this->buttons) > 0 && $this->getShowTopButtons() && count($this->items) > 2)
596  {
597  // command buttons
598  foreach($this->buttons as $button)
599  {
600  $this->tpl->setCurrentBlock("cmd2");
601  $this->tpl->setVariable("CMD", $button["cmd"]);
602  $this->tpl->setVariable("CMD_TXT", $button["text"]);
603  $this->tpl->parseCurrentBlock();
604  }
605  $this->tpl->setCurrentBlock("commands2");
606  $this->tpl->parseCurrentBlock();
607  }
608 
609  if (is_object($ilSetting))
610  {
611  if ($ilSetting->get('char_selector_availability') > 0)
612  {
613  require_once 'Services/UIComponent/CharSelector/classes/class.ilCharSelectorGUI.php';
615  {
616  $char_selector = ilCharSelectorGUI::_getCurrentGUI();
617  if ($char_selector->getConfig()->getAvailability() == ilCharSelectorConfig::ENABLED)
618  {
619  $char_selector->addToPage();
620  $this->tpl->TouchBlock('char_selector');
621  }
622  }
623  }
624  }
625 
626  $this->tpl->setCurrentBlock("header");
627  $this->tpl->setVariable("TXT_TITLE", $this->getTitle());
628  $this->tpl->setVariable("LABEL", $this->getTopAnchor());
629  $this->tpl->setVariable("TXT_DESCRIPTION", $this->getDescription());
630  $this->tpl->parseCurrentBlock();
631  }
632  $this->tpl->touchBlock("item");
633 
634  // properties
635  $this->required_text = false;
636  foreach($this->items as $item)
637  {
638  if ($item->getType() != "hidden")
639  {
640  $this->insertItem($item);
641  }
642  }
643 
644  // required
645  if ($this->required_text && $this->getMode() == "std")
646  {
647  $this->tpl->setCurrentBlock("required_text");
648  $this->tpl->setVariable("TXT_REQUIRED", $lng->txt("required_field"));
649  $this->tpl->parseCurrentBlock();
650  }
651 
652  // command buttons
653  foreach($this->buttons as $button)
654  {
655  $this->tpl->setCurrentBlock("cmd");
656  $this->tpl->setVariable("CMD", $button["cmd"]);
657  $this->tpl->setVariable("CMD_TXT", $button["text"]);
658  $this->tpl->parseCurrentBlock();
659  }
660 
661  // try to keep uploads even if checking input fails
662  if($this->getMultipart())
663  {
664  $hash = $_POST["ilfilehash"];
665  if(!$hash)
666  {
667  $hash = md5(uniqid(mt_rand(), true));
668  }
669  $fhash = new ilHiddenInputGUI("ilfilehash");
670  $fhash->setValue($hash);
671  $this->addItem($fhash);
672  }
673 
674  // hidden properties
675  $hidden_fields = false;
676  foreach($this->items as $item)
677  {
678  if ($item->getType() == "hidden")
679  {
680  $item->insert($this->tpl);
681  $hidden_fields = true;
682  }
683  }
684 
685  if ($this->required_text || count($this->buttons) > 0 || $hidden_fields)
686  {
687  $this->tpl->setCurrentBlock("commands");
688  $this->tpl->parseCurrentBlock();
689  }
690 
691 
692  if ($this->getMode() == "subform")
693  {
694  $this->tpl->touchBlock("sub_table");
695  }
696  else
697  {
698  $this->tpl->touchBlock("std_table");
699  $this->tpl->setVariable('STD_TABLE_WIDTH',$this->getTableWidth());
700  }
701 
702  return $this->tpl->get();
703  }
704 
705  function insertItem($item, $a_sub_item = false)
706  {
707  global $tpl, $lng;
708 
709 
710  $cfg = array();
711 
712  //if(method_exists($item, "getMulti") && $item->getMulti())
713  if ($item instanceof ilMultiValuesItem && $item->getMulti())
714  {
715  $tpl->addJavascript("./Services/Form/js/ServiceFormMulti.js");
716 
717  $this->tpl->setCurrentBlock("multi_in");
718  $this->tpl->setVariable("ID", $item->getFieldId());
719  $this->tpl->parseCurrentBlock();
720 
721  $this->tpl->touchBlock("multi_out");
722 
723 
724  // add hidden item to enable preset multi items
725  // not used yet, should replace hidden field stuff
726  $multi_values = $item->getMultiValues();
727  if(is_array($multi_values) && sizeof($multi_values) > 1)
728  {
729  $multi_value = new ilHiddenInputGUI("ilMultiValues~".$item->getPostVar());
730  $multi_value->setValue(implode("~", $multi_values));
731  $this->addItem($multi_value);
732  }
733  $cfg["multi_values"] = $multi_values;
734  }
735 
736  $item->insert($this->tpl);
737 
738  if ($item->getType() == "file" || $item->getType() == "image_file")
739  {
740  $this->setMultipart(true);
741  }
742 
743  if ($item->getType() != "section_header")
744  {
745  $cfg["id"] = $item->getFieldId();
746 
747  // info text
748  if ($item->getInfo() != "")
749  {
750  $this->tpl->setCurrentBlock("description");
751  $this->tpl->setVariable("PROPERTY_DESCRIPTION",
752  $item->getInfo());
753  $this->tpl->parseCurrentBlock();
754  }
755 
756  if ($this->getMode() == "subform")
757  {
758  // required
759  if ($item->getType() != "non_editable_value")
760  {
761  if ($item->getRequired())
762  {
763  $this->tpl->touchBlock("sub_required");
764  $this->required_text = true;
765  }
766  }
767 
768  // hidden title (for accessibility, e.g. file upload)
769  if ($item->getHiddenTitle() != "")
770  {
771  $this->tpl->setCurrentBlock("sub_hid_title");
772  $this->tpl->setVariable("SPHID_TITLE",
773  $item->getHiddenTitle());
774  $this->tpl->parseCurrentBlock();
775  }
776 
777  $this->tpl->setCurrentBlock("sub_prop_start");
778  $this->tpl->setVariable("PROPERTY_TITLE", $item->getTitle());
779  $this->tpl->setVariable("PROPERTY_CLASS", "il_".$item->getType());
780  if ($item->getType() != "non_editable_value")
781  {
782  $this->tpl->setVariable("LAB_ID", $item->getFieldId());
783  }
784  $this->tpl->parseCurrentBlock();
785  }
786  else
787  {
788  // required
789  if ($item->getType() != "non_editable_value")
790  {
791  if ($item->getRequired())
792  {
793  $this->tpl->touchBlock("required");
794  $this->required_text = true;
795  }
796  }
797 
798  // hidden title (for accessibility, e.g. file upload)
799  if ($item->getHiddenTitle() != "")
800  {
801  $this->tpl->setCurrentBlock("std_hid_title");
802  $this->tpl->setVariable("PHID_TITLE",
803  $item->getHiddenTitle());
804  $this->tpl->parseCurrentBlock();
805  }
806 
807  $this->tpl->setCurrentBlock("std_prop_start");
808  $this->tpl->setVariable("PROPERTY_TITLE", $item->getTitle());
809  if ($item->getType() != "non_editable_value")
810  {
811  $this->tpl->setVariable("LAB_ID", $item->getFieldId());
812  }
813  if ($this->getHideLabels())
814  {
815  $this->tpl->setVariable("HIDE_LABELS_STYLE", " ilFormOptionHidden");
816  }
817  $this->tpl->parseCurrentBlock();
818  }
819 
820  // alert
821  if ($item->getType() != "non_editable_value" && $item->getAlert() != "")
822  {
823  $this->tpl->setCurrentBlock("alert");
824  $this->tpl->setVariable("IMG_ALERT",
825  ilUtil::getImagePath("icon_alert.svg"));
826  $this->tpl->setVariable("ALT_ALERT",
827  $lng->txt("alert"));
828  $this->tpl->setVariable("TXT_ALERT",
829  $item->getAlert());
830  $this->tpl->parseCurrentBlock();
831  }
832 
833  // subitems
834  $sf = null;
835  if ($item->getType() != "non_editable_value" or 1)
836  {
837  $sf = $item->getSubForm();
838  if ($item->hideSubForm() && is_object($sf))
839  {
840  $this->tpl->setCurrentBlock("sub_form_hide");
841  $this->tpl->setVariable("DSFID", $item->getFieldId());
842  $this->tpl->parseCurrentBlock();
843  }
844  }
845 
846 
847  $sf_content = "";
848  if (is_object($sf))
849  {
850  $sf_content = $sf->getContent();
851  if ($sf->getMultipart())
852  {
853  $this->setMultipart(true);
854  }
855  $this->tpl->setCurrentBlock("sub_form");
856  $this->tpl->setVariable("PROP_SUB_FORM", $sf_content);
857  $this->tpl->setVariable("SFID", $item->getFieldId());
858  $this->tpl->parseCurrentBlock();
859  }
860 
861  $this->tpl->setCurrentBlock("prop");
862  /* not used yet
863  include_once("./Services/JSON/classes/class.ilJsonUtil.php");
864  $this->tpl->setVariable("ID", $item->getFieldId());
865  $this->tpl->setVariable("CFG", ilJsonUtil::encode($cfg));*/
866  $this->tpl->parseCurrentBlock();
867  }
868 
869 
870  $this->tpl->touchBlock("item");
871  }
872 
873  public function getHTML()
874  {
875  $html = parent::getHTML();
876 
877  // #13531 - get content that has to reside outside of the parent form tag, e.g. panels/layers
878  foreach($this->items as $item)
879  {
880  // #13536 - ilFormSectionHeaderGUI does NOT extend ilFormPropertyGUI ?!
881  if(method_exists($item, "getContentOutsideFormTag"))
882  {
883  $outside = $item->getContentOutsideFormTag();
884  if($outside)
885  {
886  $html .= $outside;
887  }
888  }
889  }
890 
891  return $html;
892  }
893 
894 
895  //
896  // UPLOAD HANDLING
897  //
898 
911  protected function keepFileUpload($a_hash, $a_field, $a_tmp_name, $a_name, $a_type, $a_index = null, $a_sub_index = null)
912  {
913  global $ilUser;
914 
915  $user_id = $ilUser->getId();
916  if(!$user_id || $user_id == ANONYMOUS_USER_ID)
917  {
918  return;
919  }
920 
921  $a_name = ilUtil::getAsciiFileName($a_name);
922 
923  $tmp_file_name = implode("~~", array($user_id,
924  $a_hash,
925  $a_field,
926  $a_index,
927  $a_sub_index,
928  str_replace("/", "~~", $a_type),
929  str_replace("~~", "_", $a_name)));
930 
931  // make sure temp directory exists
932  $temp_path = ilUtil::getDataDir() . "/temp";
933  if (!is_dir($temp_path))
934  {
935  ilUtil::createDirectory($temp_path);
936  }
937 
938  move_uploaded_file($a_tmp_name, $temp_path."/".$tmp_file_name);
939  }
940 
949  function getFileUpload($a_field, $a_index = null, $a_sub_index = null)
950  {
951  $res = array();
952  if($a_index)
953  {
954  if($_FILES[$a_field]["tmp_name"][$a_index][$a_sub_index])
955  {
956  $res = array(
957  "tmp_name" => $_FILES[$a_field]["tmp_name"][$a_index][$a_sub_index],
958  "name" => $_FILES[$a_field]["name"][$a_index][$a_sub_index],
959  "type" => $_FILES[$a_field]["type"][$a_index][$a_sub_index],
960  "error" => $_FILES[$a_field]["error"][$a_index][$a_sub_index],
961  "size" => $_FILES[$a_field]["size"][$a_index][$a_sub_index],
962  "is_upload" => true
963  );
964  }
965  else if($this->reloaded_files[$a_field]["tmp_name"][$a_index][$a_sub_index])
966  {
967  $res = array(
968  "tmp_name" => $this->reloaded_files["tmp_name"][$a_index][$a_sub_index],
969  "name" => $this->reloaded_files["name"][$a_index][$a_sub_index],
970  "type" => $this->reloaded_files["type"][$a_index][$a_sub_index],
971  "error" => $this->reloaded_files["error"][$a_index][$a_sub_index],
972  "size" => $this->reloaded_files["size"][$a_index][$a_sub_index],
973  "is_upload" => false
974  );
975  }
976  }
977  else if($a_sub_index)
978  {
979  if($_FILES[$a_field]["tmp_name"][$a_index])
980  {
981  $res = array(
982  "tmp_name" => $_FILES[$a_field]["tmp_name"][$a_index],
983  "name" => $_FILES[$a_field]["name"][$a_index],
984  "type" => $_FILES[$a_field]["type"][$a_index],
985  "error" => $_FILES[$a_field]["error"][$a_index],
986  "size" => $_FILES[$a_field]["size"][$a_index],
987  "is_upload" => true
988  );
989  }
990  else if($this->reloaded_files[$a_field]["tmp_name"][$a_index])
991  {
992  $res = array(
993  "tmp_name" => $this->reloaded_files[$a_field]["tmp_name"][$a_index],
994  "name" => $this->reloaded_files[$a_field]["name"][$a_index],
995  "type" => $this->reloaded_files[$a_field]["type"][$a_index],
996  "error" => $this->reloaded_files[$a_field]["error"][$a_index],
997  "size" => $this->reloaded_files[$a_field]["size"][$a_index],
998  "is_upload" => false
999  );
1000  }
1001  }
1002  else
1003  {
1004  if($_FILES[$a_field]["tmp_name"])
1005  {
1006  $res = array(
1007  "tmp_name" => $_FILES[$a_field]["tmp_name"],
1008  "name" => $_FILES[$a_field]["name"],
1009  "type" => $_FILES[$a_field]["type"],
1010  "error" => $_FILES[$a_field]["error"],
1011  "size" => $_FILES[$a_field]["size"],
1012  "is_upload" => true
1013  );
1014  }
1015  else if($this->reloaded_files[$a_field]["tmp_name"])
1016  {
1017  $res = array(
1018  "tmp_name" => $this->reloaded_files[$a_field]["tmp_name"],
1019  "name" => $this->reloaded_files[$a_field]["name"],
1020  "type" => $this->reloaded_files[$a_field]["type"],
1021  "error" => $this->reloaded_files[$a_field]["error"],
1022  "size" => $this->reloaded_files[$a_field]["size"],
1023  "is_upload" => false
1024  );
1025  }
1026  }
1027  return $res;
1028  }
1029 
1038  function hasFileUpload($a_field, $a_index = null, $a_sub_index = null)
1039  {
1040  $data = $this->getFileUpload($a_field, $a_index, $a_sub_index);
1041  return (bool)$data["tmp_name"];
1042  }
1043 
1054  function moveFileUpload($a_target_directory, $a_field, $a_target_name = null, $a_index = null, $a_sub_index = null)
1055  {
1056  if(!is_dir($a_target_directory))
1057  {
1058  return;
1059  }
1060 
1061  $data = $this->getFileUpload($a_field, $a_index, $a_sub_index);
1062  if($data["tmp_name"] && file_exists($data["tmp_name"]))
1063  {
1064  if($a_target_name)
1065  {
1066  $data["name"] = $a_target_name;
1067  }
1068 
1069  $target_file = $a_target_directory."/".$data["name"];
1070  $target_file = str_replace("//", "/", $target_file);
1071 
1072  if($data["is_upload"])
1073  {
1074  if (!move_uploaded_file($data["tmp_name"], $target_file))
1075  {
1076  return;
1077  }
1078  }
1079  else
1080  {
1081  if (!rename($data["tmp_name"], $target_file))
1082  {
1083  return;
1084  }
1085  }
1086 
1087  return $target_file;
1088  }
1089  }
1090 
1094  protected function rebuildUploadedFiles()
1095  {
1096  global $ilUser;
1097 
1098  if($_POST["ilfilehash"])
1099  {
1100  $user_id = $ilUser->getId();
1101  $temp_path = ilUtil::getDataDir() . "/temp";
1102  if(is_dir($temp_path) && $user_id && $user_id != ANONYMOUS_USER_ID)
1103  {
1104  $reload = array();
1105 
1106  $temp_files = glob($temp_path."/".$ilUser->getId()."~~".$_POST["ilfilehash"]."~~*");
1107  if(is_array($temp_files))
1108  {
1109  foreach($temp_files as $full_file)
1110  {
1111  $file = explode("~~", basename($full_file));
1112  $field = $file[2];
1113  $idx = $file[3];
1114  $idx2 = $file[4];
1115  $type = $file[5]."/".$file[6];
1116  $name = $file[7];
1117 
1118  if($idx2 != "")
1119  {
1120  if(!$_FILES[$field]["tmp_name"][$idx][$idx2])
1121  {
1122  $reload[$field]["tmp_name"][$idx][$idx2] = $full_file;
1123  $reload[$field]["name"][$idx][$idx2] = $name;
1124  $reload[$field]["type"][$idx][$idx2] = $type;
1125  $reload[$field]["error"][$idx][$idx2] = 0;
1126  $reload[$field]["size"][$idx][$idx2] = filesize($full_file);
1127  }
1128  }
1129  else if($idx != "")
1130  {
1131  if(!$_FILES[$field]["tmp_name"][$idx])
1132  {
1133  $reload[$field]["tmp_name"][$idx] = $full_file;
1134  $reload[$field]["name"][$idx] = $name;
1135  $reload[$field]["type"][$idx] = $type;
1136  $reload[$field]["error"][$idx] = 0;
1137  $reload[$field]["size"][$idx] = filesize($full_file);
1138  }
1139  }
1140  else
1141  {
1142  if(!$_FILES[$field]["tmp_name"])
1143  {
1144  $reload[$field]["tmp_name"] = $full_file;
1145  $reload[$field]["name"] = $name;
1146  $reload[$field]["type"] = $type;
1147  $reload[$field]["error"] = 0;
1148  $reload[$field]["size"] = filesize($full_file);
1149  }
1150  }
1151  }
1152  }
1153 
1154  $this->reloaded_files = $reload;
1155  }
1156  }
1157  }
1158 }
1159 
1160 ?>
setPreventDoubleSubmission($a_val)
Set prevent double submission.
print $file
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.
$_POST['username']
Definition: cron.php:12
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.
ilPropertyFormGUI()
Constructor.
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
static initDom()
Init YUI Dom.
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)
keepFileUpload($a_hash, $a_field, $a_tmp_name, $a_name, $a_type, $a_index=null, $a_sub_index=null)
Import upload into temp directory.
special template class to simplify handling of ITX/PEAR
checkInput()
Check Post Input.
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
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)
addCommandButton($a_cmd, $a_text)
Add Command button.
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.
global $ilUser
Definition: imgupload.php:15
getInputItemsRecursive()
returns a flat array of all input items including the possibly existing subitems recursively ...
global $ilSetting
Definition: privfeed.php:40
getHideLabels()
Get a value indicating whether the labels should be hidden or not.
& executeCommand()
Execute command.
This class represents a property that may include a sub form.
global $lng
Definition: privfeed.php:40
setTableWidth($a_width)
Set table width.
if($_REQUEST['ilias_path']) define('ILIAS_HTTP_PATH' $_REQUEST['ilias_path']
Definition: index.php:7
rebuildUploadedFiles()
try to rebuild files
setDescription($a_val)
Set description.
setValuesByArray($a_values, $a_restrict_to_value_keys=false)
Set form values from an array.
getMultipart()
Get Enctype Multipart/Formdata true/false.