ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 {
52  protected $lng;
53 
57  protected $ctrl;
58 
62  protected $tpl;
63 
67  protected $user;
68 
72  protected $settings;
73 
74  private $buttons = array();
75  private $items = array();
76  protected $mode = "std";
77  protected $check_input_called = false;
78  protected $disable_standard_message = false;
79  protected $top_anchor = "il_form_top";
80  protected $titleicon = false;
81  protected $description = "";
82  protected $tbl_width = false;
83  protected $show_top_buttons = true;
84  protected $hide_labels = false;
85 
86 
92  public function __construct()
93  {
94  global $DIC;
95 
96  $this->lng = $DIC->language();
97  $this->ctrl = $DIC->ctrl();
98 
99  $this->user = null;
100  if (isset($DIC["ilUser"])) {
101  $this->user = $DIC["ilUser"];
102  }
103 
104  $this->settings = null;
105  if (isset($DIC["ilSetting"])) {
106  $this->settings = $DIC["ilSetting"];
107  }
108 
109  $lng = $DIC->language();
110 
111  $lng->loadLanguageModule("form");
112 
113  // avoid double submission
114  $this->setPreventDoubleSubmission(true);
115 
116  // do it as early as possible
117  $this->rebuildUploadedFiles();
118  }
119 
123  public function executeCommand()
124  {
126 
127  $next_class = $ilCtrl->getNextClass($this);
128  $cmd = $ilCtrl->getCmd();
129 
130  switch ($next_class) {
131  case 'ilformpropertydispatchgui':
132  $ilCtrl->saveParameter($this, 'postvar');
133  include_once './Services/Form/classes/class.ilFormPropertyDispatchGUI.php';
134  $form_prop_dispatch = new ilFormPropertyDispatchGUI();
135  $item = $this->getItemByPostVar($_REQUEST["postvar"]);
136  $form_prop_dispatch->setItem($item);
137  return $ilCtrl->forwardCommand($form_prop_dispatch);
138  break;
139 
140  }
141  return false;
142  }
143 
151  final public function setTableWidth($a_width)
152  {
153  $this->tbl_width = $a_width;
154  }
155 
162  final public function getTableWidth()
163  {
164  return $this->tbl_width;
165  }
166 
172  public function setMode($a_mode)
173  {
174  $this->mode = $a_mode;
175  }
176 
182  public function getMode()
183  {
184  return $this->mode;
185  }
186 
192  public function setTitle($a_title)
193  {
194  $this->title = $a_title;
195  }
196 
202  public function getTitle()
203  {
204  return $this->title;
205  }
206 
212  public function setTitleIcon($a_titleicon)
213  {
214  $this->titleicon = $a_titleicon;
215  }
216 
222  public function getTitleIcon()
223  {
224  return $this->titleicon;
225  }
226 
232  public function setDescription($a_val)
233  {
234  $this->description = $a_val;
235  }
236 
242  public function getDescription()
243  {
244  return $this->description;
245  }
246 
252  public function setTopAnchor($a_val)
253  {
254  $this->top_anchor = $a_val;
255  }
256 
262  public function getTopAnchor()
263  {
264  return $this->top_anchor;
265  }
266 
270  public function setShowTopButtons($a_val)
271  {
272  $this->show_top_buttons = $a_val;
273  }
274 
278  public function getShowTopButtons()
279  {
281  }
282 
288  public function addItem($a_item)
289  {
290  $a_item->setParentForm($this);
291  return $this->items[] = $a_item;
292  }
293 
299  public function removeItemByPostVar($a_post_var, $a_remove_unused_headers = false)
300  {
301  foreach ($this->items as $key => $item) {
302  if (method_exists($item, "getPostVar") && $item->getPostVar() == $a_post_var) {
303  unset($this->items[$key]);
304  }
305  }
306 
307  // remove section headers if they do not contain any items anymore
308  if ($a_remove_unused_headers) {
309  $unset_keys = array();
310  $last_item = null;
311  $last_key = null;
312  foreach ($this->items as $key => $item) {
313  if ($item instanceof ilFormSectionHeaderGUI && $last_item instanceof ilFormSectionHeaderGUI) {
314  $unset_keys[] = $last_key;
315  }
316  $last_item = $item;
317  $last_key = $key;
318  }
319  if ($last_item instanceof ilFormSectionHeaderGUI) {
320  $unset_keys[] = $last_key;
321  }
322  foreach ($unset_keys as $key) {
323  unset($this->items[$key]);
324  }
325  }
326  }
327 
333  public function getItemByPostVar($a_post_var)
334  {
335  foreach ($this->items as $key => $item) {
336  if ($item->getType() != "section_header") {
337  //if ($item->getPostVar() == $a_post_var)
338  $ret = $item->getItemByPostVar($a_post_var);
339  if (is_object($ret)) {
340  return $ret;
341  }
342  }
343  }
344 
345  return false;
346  }
347 
353  public function setItems($a_items)
354  {
355  $this->items = $a_items;
356  }
357 
363  public function getItems()
364  {
365  return $this->items;
366  }
367 
374  public function getInputItemsRecursive()
375  {
376  $inputItems = array();
377 
378  foreach ($this->items as $item) {
379  if ($item->getType() == 'section_header') {
380  continue;
381  }
382 
383  $inputItems[] = $item;
384 
385  if ($item instanceof ilSubEnabledFormPropertyGUI) {
386  $inputItems = array_merge($inputItems, $item->getSubInputItemsRecursive());
387  }
388  }
389 
390  return $inputItems;
391  }
392 
398  public function setDisableStandardMessage($a_val)
399  {
400  $this->disable_standard_message = $a_val;
401  }
402 
408  public function getDisableStandardMessage()
409  {
411  }
412 
418  public function getHideLabels()
419  {
420  return $this->hide_labels;
421  }
422 
428  public function setHideLabels($a_value = true)
429  {
430  $this->hide_labels = $a_value;
431  }
432 
438  public function setValuesByArray($a_values, $a_restrict_to_value_keys = false)
439  {
440  foreach ($this->items as $item) {
441  if (!($a_restrict_to_value_keys) ||
442  in_array($item->getPostVar(), array_keys($a_values))) {
443  $item->setValueByArray($a_values);
444  }
445  }
446  }
447 
452  public function setValuesByPost()
453  {
454  foreach ($this->items as $item) {
455  $item->setValueByArray($_POST);
456  }
457  }
458 
465  public function checkInput()
466  {
467  global $DIC;
468 
469  if ($this->check_input_called) {
470  die("Error: ilPropertyFormGUI->checkInput() called twice.");
471  }
472 
473  $ok = true;
474  foreach ($this->items as $item) {
475  $item_ok = $item->checkInput();
476  if (!$item_ok) {
477  $ok = false;
478  }
479  }
480 
481  // check if POST is missint completely (if post_max_size exceeded)
482  if (count($this->items) > 0 && !is_array($_POST)) {
483  $ok = false;
484  }
485 
486  $this->check_input_called = true;
487 
488 
489 
490  // try to keep uploads for another try
491  if (!$ok && $_POST["ilfilehash"] && sizeof($_FILES)) {
492  $hash = $_POST["ilfilehash"];
493 
494  foreach ($_FILES as $field => $data) {
495  // we support up to 2 nesting levels (see test/assesment)
496  if (is_array($data["tmp_name"])) {
497  foreach ($data["tmp_name"] as $idx => $upload) {
498  if (is_array($upload)) {
499  foreach ($upload as $idx2 => $file) {
500  if ($file && is_uploaded_file($file)) {
501  $file_name = $data["name"][$idx][$idx2];
502  $file_type = $data["type"][$idx][$idx2];
503  $this->keepFileUpload($hash, $field, $file, $file_name, $file_type, $idx, $idx2);
504  }
505  }
506  } elseif ($upload && is_uploaded_file($upload)) {
507  $file_name = $data["name"][$idx];
508  $file_type = $data["type"][$idx];
509  $this->keepFileUpload($hash, $field, $upload, $file_name, $file_type, $idx);
510  }
511  }
512  } else {
513  $this->keepFileUpload($hash, $field, $data["tmp_name"], $data["name"], $data["type"]);
514  }
515  }
516  }
517  $http = $DIC->http();
518  $txt = $DIC->language()->txt("form_input_not_valid");
519  switch ($http->request()->getHeaderLine('Accept')) {
520  // When JS asks for a valid JSON-Response, we send the success and message as JSON
521  case 'application/json':
523  'success' => $ok,
524  'message' => $txt,
525  ]));
526  $http->saveResponse($http->response()->withBody($stream));
527 
528  return $ok;
529 
530  // Otherwise we send it using ilUtil and it will be rendered in the Template
531  default:
532 
533  if (!$ok && !$this->getDisableStandardMessage()) {
535  }
536 
537  return $ok;
538  }
539  }
540 
551  public function getInput($a_post_var, $ensureValidation = true)
552  {
553  // this check ensures, that checkInput has been called (incl. stripSlashes())
554  if (!$this->check_input_called && $ensureValidation) {
555  die("Error: ilPropertyFormGUI->getInput() called without calling checkInput() first.");
556  }
557 
558  return $_POST[$a_post_var];
559  }
560 
570  public function addCustomProperty(
571  $a_title,
572  $a_html,
573  $a_info = "",
574  $a_alert = "",
575  $a_required = false
576  ) {
577  $this->properties[] = array("type" => "custom",
578  "title" => $a_title,
579  "html" => $a_html,
580  "info" => $a_info);
581  }
582 
589  public function addCommandButton($a_cmd, $a_text, $a_id = "")
590  {
591  $this->buttons[] = array("cmd" => $a_cmd, "text" => $a_text, "id" => $a_id);
592  }
593 
594 
600  public function getCommandButtons()
601  {
602  return $this->buttons;
603  }
604 
608  public function clearCommandButtons()
609  {
610  $this->buttons = array();
611  }
612 
616  public function getContent()
617  {
618  global $DIC;
619  $lng = $this->lng;
620  $tpl = $DIC["tpl"];
622 
623  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
627 
628  $tpl->addJavaScript("./Services/JavaScript/js/Basic.js");
629  $tpl->addJavaScript("Services/Form/js/Form.js");
630 
631  $this->tpl = new ilTemplate("tpl.property_form.html", true, true, "Services/Form");
632 
633  // check if form has not title and first item is a section header
634  // -> use section header for title and remove section header
635  // -> command buttons are presented on top
636  $fi = $this->items[0];
637  if ($this->getMode() == "std" &&
638  $this->getTitle() == "" &&
639  is_object($fi) && $fi->getType() == "section_header"
640  ) {
641  $this->setTitle($fi->getTitle());
642  unset($this->items[0]);
643  }
644 
645 
646  // title icon
647  if ($this->getTitleIcon() != "" && @is_file($this->getTitleIcon())) {
648  $this->tpl->setCurrentBlock("title_icon");
649  $this->tpl->setVariable("IMG_ICON", $this->getTitleIcon());
650  $this->tpl->parseCurrentBlock();
651  }
652 
653  // title
654  if ($this->getTitle() != "") {
655  // commands on top
656  if (count($this->buttons) > 0 && $this->getShowTopButtons() && count($this->items) > 2) {
657  // command buttons
658  foreach ($this->buttons as $button) {
659  $this->tpl->setCurrentBlock("cmd2");
660  $this->tpl->setVariable("CMD", $button["cmd"]);
661  $this->tpl->setVariable("CMD_TXT", $button["text"]);
662  if ($button["id"] != "") {
663  $this->tpl->setVariable("CMD2_ID", " id='" . $button["id"] . "_top'");
664  }
665  $this->tpl->parseCurrentBlock();
666  }
667  $this->tpl->setCurrentBlock("commands2");
668  $this->tpl->parseCurrentBlock();
669  }
670 
671  if (is_object($ilSetting)) {
672  if ($ilSetting->get('char_selector_availability') > 0) {
673  require_once 'Services/UIComponent/CharSelector/classes/class.ilCharSelectorGUI.php';
675  $char_selector = ilCharSelectorGUI::_getCurrentGUI();
676  if ($char_selector->getConfig()->getAvailability() == ilCharSelectorConfig::ENABLED) {
677  $char_selector->addToPage();
678  $this->tpl->TouchBlock('char_selector');
679  }
680  }
681  }
682  }
683 
684  $this->tpl->setCurrentBlock("header");
685  $this->tpl->setVariable("TXT_TITLE", $this->getTitle());
686  $this->tpl->setVariable("LABEL", $this->getTopAnchor());
687  $this->tpl->setVariable("TXT_DESCRIPTION", $this->getDescription());
688  $this->tpl->parseCurrentBlock();
689  }
690  $this->tpl->touchBlock("item");
691 
692  // properties
693  $this->required_text = false;
694  foreach ($this->items as $item) {
695  if ($item->getType() != "hidden") {
696  $this->insertItem($item);
697  }
698  }
699 
700  // required
701  if ($this->required_text && $this->getMode() == "std") {
702  $this->tpl->setCurrentBlock("required_text");
703  $this->tpl->setVariable("TXT_REQUIRED", $lng->txt("required_field"));
704  $this->tpl->parseCurrentBlock();
705  }
706 
707  // command buttons
708  foreach ($this->buttons as $button) {
709  $this->tpl->setCurrentBlock("cmd");
710  $this->tpl->setVariable("CMD", $button["cmd"]);
711  $this->tpl->setVariable("CMD_TXT", $button["text"]);
712 
713  if ($button["id"] != "") {
714  $this->tpl->setVariable("CMD_ID", " id='" . $button["id"] . "'");
715  }
716 
717  $this->tpl->parseCurrentBlock();
718  }
719 
720  // #18808
721  if ($this->getMode() != "subform") {
722  // try to keep uploads even if checking input fails
723  if ($this->getMultipart()) {
724  $hash = $_POST["ilfilehash"];
725  if (!$hash) {
726  $hash = md5(uniqid(mt_rand(), true));
727  }
728  $fhash = new ilHiddenInputGUI("ilfilehash");
729  $fhash->setValue($hash);
730  $this->addItem($fhash);
731  }
732  }
733 
734  // hidden properties
735  $hidden_fields = false;
736  foreach ($this->items as $item) {
737  if ($item->getType() == "hidden") {
738  $item->insert($this->tpl);
739  $hidden_fields = true;
740  }
741  }
742 
743  if ($this->required_text || count($this->buttons) > 0 || $hidden_fields) {
744  $this->tpl->setCurrentBlock("commands");
745  $this->tpl->parseCurrentBlock();
746  }
747 
748 
749  if ($this->getMode() == "subform") {
750  $this->tpl->touchBlock("sub_table");
751  } else {
752  $this->tpl->touchBlock("std_table");
753  $this->tpl->setVariable('STD_TABLE_WIDTH', $this->getTableWidth());
754  }
755 
756  return $this->tpl->get();
757  }
758 
759  protected function hideRequired($a_type)
760  {
761  // #15818
762  return in_array($a_type, array("non_editable_value"));
763  }
764 
765  public function insertItem($item, $a_sub_item = false)
766  {
767  global $DIC;
768  $tpl = $DIC["tpl"];
769  ;
770  $lng = $this->lng;
771 
772 
773  $cfg = array();
774 
775  //if(method_exists($item, "getMulti") && $item->getMulti())
776  if ($item instanceof ilMultiValuesItem && $item->getMulti()) {
777  $tpl->addJavascript("./Services/Form/js/ServiceFormMulti.js");
778 
779  $this->tpl->setCurrentBlock("multi_in");
780  $this->tpl->setVariable("ID", $item->getFieldId());
781  $this->tpl->parseCurrentBlock();
782 
783  $this->tpl->touchBlock("multi_out");
784 
785 
786  // add hidden item to enable preset multi items
787  // not used yet, should replace hidden field stuff
788  $multi_values = $item->getMultiValues();
789  if (is_array($multi_values) && sizeof($multi_values) > 1) {
790  $multi_value = new ilHiddenInputGUI("ilMultiValues~" . $item->getPostVar());
791  $multi_value->setValue(implode("~", $multi_values));
792  $this->addItem($multi_value);
793  }
794  $cfg["multi_values"] = $multi_values;
795  }
796 
797  $item->insert($this->tpl);
798 
799  if ($item->getType() == "file" || $item->getType() == "image_file") {
800  $this->setMultipart(true);
801  }
802 
803  if ($item->getType() != "section_header") {
804  $cfg["id"] = $item->getFieldId();
805 
806  // info text
807  if ($item->getInfo() != "") {
808  $this->tpl->setCurrentBlock("description");
809  $this->tpl->setVariable(
810  "PROPERTY_DESCRIPTION",
811  $item->getInfo()
812  );
813  $this->tpl->parseCurrentBlock();
814  }
815 
816  if ($this->getMode() == "subform") {
817  // required
818  if (!$this->hideRequired($item->getType())) {
819  if ($item->getRequired()) {
820  $this->tpl->touchBlock("sub_required");
821  $this->required_text = true;
822  }
823  }
824 
825  // hidden title (for accessibility, e.g. file upload)
826  if ($item->getHiddenTitle() != "") {
827  $this->tpl->setCurrentBlock("sub_hid_title");
828  $this->tpl->setVariable(
829  "SPHID_TITLE",
830  $item->getHiddenTitle()
831  );
832  $this->tpl->parseCurrentBlock();
833  }
834 
835  $this->tpl->setCurrentBlock("sub_prop_start");
836  $this->tpl->setVariable("PROPERTY_TITLE", $item->getTitle());
837  $this->tpl->setVariable("PROPERTY_CLASS", "il_" . $item->getType());
838  if ($item->getType() != "non_editable_value") {
839  $this->tpl->setVariable("LAB_ID", $item->getFieldId());
840  }
841  $this->tpl->parseCurrentBlock();
842  } else {
843  // required
844  if (!$this->hideRequired($item->getType())) {
845  if ($item->getRequired()) {
846  $this->tpl->touchBlock("required");
847  $this->required_text = true;
848  }
849  }
850 
851  // hidden title (for accessibility, e.g. file upload)
852  if ($item->getHiddenTitle() != "") {
853  $this->tpl->setCurrentBlock("std_hid_title");
854  $this->tpl->setVariable(
855  "PHID_TITLE",
856  $item->getHiddenTitle()
857  );
858  $this->tpl->parseCurrentBlock();
859  }
860 
861  $this->tpl->setCurrentBlock("std_prop_start");
862  $this->tpl->setVariable("PROPERTY_TITLE", $item->getTitle());
863  if ($item->getType() != "non_editable_value") {
864  $this->tpl->setVariable("LAB_ID", $item->getFieldId());
865  }
866  if ($this->getHideLabels()) {
867  $this->tpl->setVariable("HIDE_LABELS_STYLE", " ilFormOptionHidden");
868  }
869  $this->tpl->parseCurrentBlock();
870  }
871 
872  // alert
873  if ($item->getType() != "non_editable_value" && $item->getAlert() != "") {
874  $this->tpl->setCurrentBlock("alert");
875  $this->tpl->setVariable(
876  "IMG_ALERT",
877  ilUtil::getImagePath("icon_alert.svg")
878  );
879  $this->tpl->setVariable(
880  "ALT_ALERT",
881  $lng->txt("alert")
882  );
883  $this->tpl->setVariable(
884  "TXT_ALERT",
885  $item->getAlert()
886  );
887  $this->tpl->parseCurrentBlock();
888  }
889 
890  // subitems
891  $sf = null;
892  if ($item->getType() != "non_editable_value" or 1) {
893  $sf = $item->getSubForm();
894  if ($item->hideSubForm() && is_object($sf)) {
895  $this->tpl->setCurrentBlock("sub_form_hide");
896  $this->tpl->setVariable("DSFID", $item->getFieldId());
897  $this->tpl->parseCurrentBlock();
898  }
899  }
900 
901 
902  $sf_content = "";
903  if (is_object($sf)) {
904  $sf_content = $sf->getContent();
905  if ($sf->getMultipart()) {
906  $this->setMultipart(true);
907  }
908  $this->tpl->setCurrentBlock("sub_form");
909  $this->tpl->setVariable("PROP_SUB_FORM", $sf_content);
910  $this->tpl->setVariable("SFID", $item->getFieldId());
911  $this->tpl->parseCurrentBlock();
912  }
913 
914  $this->tpl->setCurrentBlock("prop");
915  /* not used yet
916  $this->tpl->setVariable("ID", $item->getFieldId());
917  $this->tpl->setVariable("CFG", ilJsonUtil::encode($cfg));*/
918  $this->tpl->parseCurrentBlock();
919  }
920 
921 
922  $this->tpl->touchBlock("item");
923  }
924 
925  public function getHTML()
926  {
927  $html = parent::getHTML();
928 
929  // #13531 - get content that has to reside outside of the parent form tag, e.g. panels/layers
930  foreach ($this->items as $item) {
931  // #13536 - ilFormSectionHeaderGUI does NOT extend ilFormPropertyGUI ?!
932  if (method_exists($item, "getContentOutsideFormTag")) {
933  $outside = $item->getContentOutsideFormTag();
934  if ($outside) {
935  $html .= $outside;
936  }
937  }
938  }
939 
940  return $html;
941  }
942 
943 
944  //
945  // UPLOAD HANDLING
946  //
947 
960  protected function keepFileUpload($a_hash, $a_field, $a_tmp_name, $a_name, $a_type, $a_index = null, $a_sub_index = null)
961  {
962  if (trim($a_tmp_name) == "") {
963  return;
964  }
965 
966  $a_name = ilUtil::getAsciiFileName($a_name);
967 
968  $tmp_file_name = implode("~~", array(session_id(),
969  $a_hash,
970  $a_field,
971  $a_index,
972  $a_sub_index,
973  str_replace("/", "~~", $a_type),
974  str_replace("~~", "_", $a_name)));
975 
976  // make sure temp directory exists
977  $temp_path = ilUtil::getDataDir() . "/temp";
978  if (!is_dir($temp_path)) {
979  ilUtil::createDirectory($temp_path);
980  }
981 
982  ilUtil::moveUploadedFile($a_tmp_name, $tmp_file_name, $temp_path . "/" . $tmp_file_name);
983 
985  $file_input = $this->getItemByPostVar($a_field);
986  $file_input->setPending($a_name);
987  }
988 
997  public function getFileUpload($a_field, $a_index = null, $a_sub_index = null)
998  {
999  $res = array();
1000  if ($a_index) {
1001  if ($_FILES[$a_field]["tmp_name"][$a_index][$a_sub_index]) {
1002  $res = array(
1003  "tmp_name" => $_FILES[$a_field]["tmp_name"][$a_index][$a_sub_index],
1004  "name" => $_FILES[$a_field]["name"][$a_index][$a_sub_index],
1005  "type" => $_FILES[$a_field]["type"][$a_index][$a_sub_index],
1006  "error" => $_FILES[$a_field]["error"][$a_index][$a_sub_index],
1007  "size" => $_FILES[$a_field]["size"][$a_index][$a_sub_index],
1008  "is_upload" => true
1009  );
1010  }
1011  } elseif ($a_sub_index) {
1012  if ($_FILES[$a_field]["tmp_name"][$a_index]) {
1013  $res = array(
1014  "tmp_name" => $_FILES[$a_field]["tmp_name"][$a_index],
1015  "name" => $_FILES[$a_field]["name"][$a_index],
1016  "type" => $_FILES[$a_field]["type"][$a_index],
1017  "error" => $_FILES[$a_field]["error"][$a_index],
1018  "size" => $_FILES[$a_field]["size"][$a_index],
1019  "is_upload" => true
1020  );
1021  }
1022  } else {
1023  if ($_FILES[$a_field]["tmp_name"]) {
1024  $res = array(
1025  "tmp_name" => $_FILES[$a_field]["tmp_name"],
1026  "name" => $_FILES[$a_field]["name"],
1027  "type" => $_FILES[$a_field]["type"],
1028  "error" => $_FILES[$a_field]["error"],
1029  "size" => $_FILES[$a_field]["size"],
1030  "is_upload" => true
1031  );
1032  }
1033  }
1034  return $res;
1035  }
1036 
1045  public function hasFileUpload($a_field, $a_index = null, $a_sub_index = null)
1046  {
1047  $data = $this->getFileUpload($a_field, $a_index, $a_sub_index);
1048  return (bool) $data["tmp_name"];
1049  }
1050 
1061  public function moveFileUpload($a_target_directory, $a_field, $a_target_name = null, $a_index = null, $a_sub_index = null)
1062  {
1063  if (!is_dir($a_target_directory)) {
1064  return;
1065  }
1066 
1067  $data = $this->getFileUpload($a_field, $a_index, $a_sub_index);
1068  if ($data["tmp_name"] && file_exists($data["tmp_name"])) {
1069  if ($a_target_name) {
1070  $data["name"] = $a_target_name;
1071  }
1072 
1073  $target_file = $a_target_directory . "/" . $data["name"];
1074  $target_file = str_replace("//", "/", $target_file);
1075 
1076  if ($data["is_upload"]) {
1077  if (!ilUtil::moveUploadedFile($data["tmp_name"], $data["name"], $target_file)) {
1078  return;
1079  }
1080  } else {
1081  if (!rename($data["tmp_name"], $target_file)) {
1082  return;
1083  }
1084  }
1085 
1086  return $target_file;
1087  }
1088  }
1089 
1093  protected function rebuildUploadedFiles()
1094  {
1095  if (isset($_POST["ilfilehash"]) && $_POST["ilfilehash"]) {
1096  $temp_path = ilUtil::getDataDir() . "/temp";
1097  if (is_dir($temp_path)) {
1098  $temp_files = glob($temp_path . "/" . session_id() . "~~" . $_POST["ilfilehash"] . "~~*");
1099  if (is_array($temp_files)) {
1100  foreach ($temp_files as $full_file) {
1101  $file = explode("~~", basename($full_file));
1102  $field = $file[2];
1103  $idx = $file[3];
1104  $idx2 = $file[4];
1105  $type = $file[5] . "/" . $file[6];
1106  $name = $file[7];
1107 
1108  if ($idx2 != "") {
1109  if (!$_FILES[$field]["tmp_name"][$idx][$idx2]) {
1110  $_FILES[$field]["tmp_name"][$idx][$idx2] = $full_file;
1111  $_FILES[$field]["name"][$idx][$idx2] = $name;
1112  $_FILES[$field]["type"][$idx][$idx2] = $type;
1113  $_FILES[$field]["error"][$idx][$idx2] = 0;
1114  $_FILES[$field]["size"][$idx][$idx2] = filesize($full_file);
1115  }
1116  } elseif ($idx != "") {
1117  if (!$_FILES[$field]["tmp_name"][$idx]) {
1118  $_FILES[$field]["tmp_name"][$idx] = $full_file;
1119  $_FILES[$field]["name"][$idx] = $name;
1120  $_FILES[$field]["type"][$idx] = $type;
1121  $_FILES[$field]["error"][$idx] = 0;
1122  $_FILES[$field]["size"][$idx] = filesize($full_file);
1123  }
1124  } else {
1125  if (!$_FILES[$field]["tmp_name"]) {
1126  $_FILES[$field]["tmp_name"] = $full_file;
1127  $_FILES[$field]["name"] = $name;
1128  $_FILES[$field]["type"] = $type;
1129  $_FILES[$field]["error"] = 0;
1130  $_FILES[$field]["size"] = filesize($full_file);
1131  }
1132  }
1133  }
1134  }
1135  }
1136  }
1137  }
1138 }
setPreventDoubleSubmission($a_val)
Set prevent double submission.
hasFileUpload($a_field, $a_index=null, $a_sub_index=null)
Was any file uploaded?
addCustomProperty( $a_title, $a_html, $a_info="", $a_alert="", $a_required=false)
Add a custom property.
static _isAllowed()
Check if the CharSelector is allowed for the current GUI.
setTitleIcon($a_titleicon)
Set TitleIcon.
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.
$type
setItems($a_items)
Set Items.
global $DIC
Definition: saml.php:7
This class represents a section header in a property form.
getTableWidth()
get table width
This class represents a form user interface.
getTitleIcon()
Get TitleIcon.
addItem($a_item)
Add Item (Property, SectionHeader).
$stream
PHP stream implementation.
setShowTopButtons($a_val)
Get show top buttons.
user()
Definition: user.php:4
setValue($a_value)
Set Value.
getMode()
Get Mode (&#39;std&#39;, &#39;subform&#39;).
setMultipart($a_multipart)
Set Enctype Multipart/Formdata true/false.
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:92
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;).
setTitle($a_title)
Set Title.
foreach($_POST as $key=> $value) $res
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)
special template class to simplify handling of ITX/PEAR
addCommandButton($a_cmd, $a_text, $a_id="")
Add Command button.
static ofString($string)
Creates a new stream with an initial value.
Definition: Streams.php:29
checkInput()
Check Post Input.
catch(Exception $e) if(isset($_POST['cancel'])) if(isset($_POST['continue'])) $cfg
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.
$http
Definition: raiseError.php:7
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)
$txt
Definition: error.php:11
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.
settings()
Definition: settings.php:2
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.
removeItemByPostVar($a_post_var, $a_remove_unused_headers=false)
Remove Item.
$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.
$key
Definition: croninfo.php:18
$_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.