ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilSelectBuilderInputGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
13{
17 protected $tpl;
18
19
20 protected $open_answer_indexes = array();
21
22
23 // constructor
24 public function __construct($a_title = "", $a_postvar = "")
25 {
26 global $DIC;
27
28 $this->lng = $DIC->language();
29 $this->tpl = $DIC["tpl"];
30 parent::__construct($a_title, $a_postvar);
31 }
32
33
37 public function getOpenAnswerIndexes()
38 {
40 }
41
45 public function setOpenAnswerIndexes($a_indexes)
46 {
47 $this->open_answer_indexes = $a_indexes;
48 }
49
53 public function addOpenAnswerIndex($a_idx)
54 {
55 $this->open_answer_indexes[] = $a_idx;
56 }
57
63 public function isOpenAnswerIndex($a_idx)
64 {
65 return in_array($a_idx, (array) $this->open_answer_indexes);
66 }
67
73 public function checkInput()
74 {
76
77 $foundvalues = $_POST[$this->getPostVar()];
78
79
80
81 $this->setOpenAnswerIndexes(array());
82 if (is_array($foundvalues)) {
83 foreach ($foundvalues as $idx => $value) {
85 if ($this->getRequired() && trim($value) == "") {
86 $this->setAlert($lng->txt("msg_input_is_required"));
87
88 return false;
89 } elseif (strlen($this->getValidationRegexp())) {
90 if (!preg_match($this->getValidationRegexp(), $value)) {
91 $this->setAlert($lng->txt("msg_wrong_format"));
92 return false;
93 }
94 }
95 }
96 } else {
97 $this->setAlert($lng->txt("msg_input_is_required"));
98 return false;
99 }
100
101 foreach ((array) $_POST[$this->getPostVar() . '_open'] as $oindex => $ovalue) {
102 $this->addOpenAnswerIndex($oindex);
103 }
104
105
106 return $this->checkSubItemsInput();
107 }
108
109 public function setValueByArray($a_values)
110 {
111 parent::setValueByArray($a_values);
112
113 foreach ((array) $_POST[$this->getPostVar() . '_open'] as $oindex => $ovalue) {
114 $this->addOpenAnswerIndex($oindex);
115 }
116 }
117
123 public function insert($a_tpl)
124 {
126
127 $tpl = new ilTemplate("tpl.prop_selectbuilder.html", true, true, "Services/Form");
128 $i = 0;
129 foreach ($this->values as $value) {
130 if (!is_string($value)) {
131 continue;
132 }
133
134 if (strlen((string) $value)) {
135 $tpl->setCurrentBlock("prop_text_propval");
136 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput((string) $value));
137 $tpl->parseCurrentBlock();
138 }
139 if ($this->getAllowMove()) {
140 $tpl->setCurrentBlock("move");
141 $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
142 $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
143 $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
144 include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
145 $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
146 $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
147
148 $tpl->parseCurrentBlock();
149 }
150 $tpl->setCurrentBlock("row");
151 $tpl->setVariable("POST_VAR", $this->getPostVar() . "[$i]");
152 #$tpl->setVariable('POST_VAR_OPEN',$this->getPostVar().'[open]'.'['.$i.']');
153 $tpl->setVariable('POST_VAR_OPEN', $this->getPostVar() . '_open' . '[' . $i . ']');
154 $tpl->setVariable('POST_VAR_OPEN_ID', $this->getPostVar() . '_open[' . $i . ']');
155 $tpl->setVariable('TXT_OPEN', $lng->txt("form_open_answer"));
156
157 if ($this->isOpenAnswerIndex($i)) {
158 $tpl->setVariable('PROP_OPEN_CHECKED', 'checked="checked"');
159 }
160 if ($this->getDisabled()) {
161 $tpl->setVariable('PROP_OPEN_DISABLED', 'disabled="disabled"');
162 }
163
164 $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
165 $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
166 $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
167 $tpl->setVariable("SIZE", $this->getSize());
168 $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
169 if ($this->getDisabled()) {
170 $tpl->setVariable(
171 "DISABLED",
172 " disabled=\"disabled\""
173 );
174 }
175 include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
176 $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
177 $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
178 $tpl->parseCurrentBlock();
179 $i++;
180 }
181 $tpl->setVariable("ELEMENT_ID", $this->getFieldId());
182
183 $a_tpl->setCurrentBlock("prop_generic");
184 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
185 $a_tpl->parseCurrentBlock();
186
188 $tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
189 $tpl->addJavascript("./Services/Form/templates/default/textwizard.js");
190 }
191}
$_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.
Input GUI for the configuration of select input elements.
isOpenAnswerIndex($a_idx)
Check if an index is an open answer index.
checkInput()
Check input, strip slashes etc.
insert($a_tpl)
Insert property html.
setValueByArray($a_values)
Set value by array.
getOpenAnswerIndexes()
Get open answer indexes.
setOpenAnswerIndexes($a_indexes)
Set open answer indexes.
addOpenAnswerIndex($a_idx)
Mark an index as open answer.
__construct($a_title="", $a_postvar="")
Constructor.
special template class to simplify handling of ITX/PEAR
getMaxLength()
Get Max Length.
getValidationRegexp()
Get validation regexp.
This class represents a text wizard property in a property form.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
$i
Definition: disco.tpl.php:19
global $DIC
Definition: saml.php:7