ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilMultipleTextsInputGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Services/Form/classes/class.ilIdentifiedMultiValuesInputGUI.php';
5
13{
18
22 protected $editElementOrderEnabled = false;
23
30 function __construct($a_title = "", $a_postvar = "")
31 {
32 parent::__construct($a_title, $a_postvar);
33 $this->validationRegexp = "";
34 }
35
40 {
42 }
43
48 {
49 $this->editElementOccuranceEnabled = $editElementOccuranceEnabled;
50 }
51
55 public function isEditElementOrderEnabled()
56 {
58 }
59
64 {
65 $this->editElementOrderEnabled = $editElementOrderEnabled;
66 }
67
73 function onCheckInput()
74 {
75 global $lng;
76
77 $submittedElements = $_POST[$this->getPostVar()];
78
79 if( !is_array($submittedElements) && $this->getRequired() )
80 {
81 $this->setAlert($lng->txt("msg_input_is_required"));
82 return false;
83 }
84
85 foreach($submittedElements as $submittedValue)
86 {
87 $submittedContentText = $this->fetchContentTextFromValue($submittedValue);
88
89 if ($this->getRequired() && trim($submittedContentText) == "")
90 {
91 $this->setAlert($lng->txt('msg_input_is_required'));
92 return false;
93 }
94
95 if( strlen($this->getValidationRegexp()) )
96 {
97 if( !preg_match($this->getValidationRegexp(), $submittedContentText) )
98 {
99 $this->setAlert($lng->txt('msg_wrong_format'));
100 return false;
101 }
102 }
103 }
104
105 return $this->checkSubItemsInput();
106 }
107
112 public function render($a_mode = "")
113 {
114 $tpl = new ilTemplate("tpl.prop_multi_text_inp.html", true, true, "Services/Form");
115 $i = 0;
116 foreach ($this->getIdentifiedMultiValues() as $identifier => $value)
117 {
118 if (strlen($value))
119 {
120 $tpl->setCurrentBlock("prop_text_propval");
121 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value));
122 $tpl->parseCurrentBlock();
123 }
124 if ($this->isEditElementOrderEnabled())
125 {
126 $tpl->setCurrentBlock("move");
127 $tpl->setVariable("ID_UP", $this->getMultiValuePosIndexedSubFieldId($identifier, 'up', $i));
128 $tpl->setVariable("ID_DOWN", $this->getMultiValuePosIndexedSubFieldId($identifier, 'down', $i));
129 $tpl->setVariable("CMD_UP", $this->buildMultiValueSubmitVar($identifier, $i, 'up'));
130 $tpl->setVariable("CMD_DOWN", $this->buildMultiValueSubmitVar($identifier, $i, 'down'));
131 $tpl->setVariable("ID", $this->getMultiValuePosIndexedFieldId($identifier, $i));
132 include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
133 $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
134 $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
135 $tpl->parseCurrentBlock();
136 }
137 $tpl->setCurrentBlock("row");
138 $tpl->setVariable("POST_VAR", $this->getMultiValuePostVarPosIndexed($identifier, $i));
139 $tpl->setVariable("ID", $this->getMultiValuePosIndexedFieldId($identifier, $i));
140 $tpl->setVariable("SIZE", $this->getSize());
141 $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
142
143 if ($this->getDisabled())
144 {
145 $tpl->setVariable("DISABLED",
146 " disabled=\"disabled\"");
147 }
148 elseif( $this->isEditElementOccuranceEnabled() )
149 {
150 $tpl->setVariable("ID_ADD", $this->getMultiValuePosIndexedSubFieldId($identifier, 'add', $i));
151 $tpl->setVariable("ID_REMOVE", $this->getMultiValuePosIndexedSubFieldId($identifier, 'remove', $i));
152 $tpl->setVariable("CMD_ADD", $this->buildMultiValueSubmitVar($identifier, $i, 'add'));
153 $tpl->setVariable("CMD_REMOVE", $this->buildMultiValueSubmitVar($identifier, $i, 'remove'));
154 include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
155 $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
156 $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
157 }
158
159 $tpl->parseCurrentBlock();
160 $i++;
161 }
162 $tpl->setVariable("ELEMENT_ID", $this->getFieldId());
163
164 if (!$this->getDisabled())
165 {
166 $tpl->setCurrentBlock('js_engine_initialisation');
167 $tpl->touchBlock('js_engine_initialisation');
168 $tpl->parseCurrentBlock();
169
170 $globalTpl = $GLOBALS['DIC'] ? $GLOBALS['DIC']['tpl'] : $GLOBALS['tpl'];
171 $globalTpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
172 $globalTpl->addJavascript("./Services/Form/js/ServiceFormIdentifiedWizardInputExtend.js");
173 }
174
175 return $tpl->get();
176 }
177
182 protected function valueHasContentText($value)
183 {
184 if( $value === null || is_array($value) || is_object($value) )
185 {
186 return false;
187 }
188
189 return (bool)strlen($value);
190 }
191
197 {
198 if( $this->valueHasContentText($value) )
199 {
200 return $value;
201 }
202
203 return null;
204 }
205}
global $tpl
Definition: ilias.php:8
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
getPostVar()
Get Post Variable.
setAlert($a_alert)
Set Alert Text.
getFieldId()
Get Post Variable.
static get($a_glyph, $a_text="")
Get glyph html.
getMultiValuePosIndexedSubFieldId($identifier, $subFieldIndex, $positionIndex)
buildMultiValueSubmitVar($identifier, $positionIndex, $submitCommand)
setEditElementOccuranceEnabled($editElementOccuranceEnabled)
onCheckInput()
Check input, strip slashes etc.
__construct($a_title="", $a_postvar="")
Constructor.
setEditElementOrderEnabled($editElementOrderEnabled)
special template class to simplify handling of ITX/PEAR
getMaxLength()
Get Max Length.
getValidationRegexp()
Get validation regexp.
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
global $lng
Definition: privfeed.php:17