1<?php
2/*
3    +-----------------------------------------------------------------------------+
4    | ILIAS open source                                                           |
5    +-----------------------------------------------------------------------------+
6    | Copyright (c) 1998-2007 ILIAS open source, University of Cologne            |
7    |                                                                             |
8    | This program is free software; you can redistribute it and/or               |
9    | modify it under the terms of the GNU General Public License                 |
10    | as published by the Free Software Foundation; either version 2              |
11    | of the License, or (at your option) any later version.                      |
12    |                                                                             |
13    | This program is distributed in the hope that it will be useful,             |
14    | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
15    | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
16    | GNU General Public License for more details.                                |
17    |                                                                             |
18    | You should have received a copy of the GNU General Public License           |
19    | along with this program; if not, write to the Free Software                 |
20    | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
21    +-----------------------------------------------------------------------------+
22*/
23
24/**
25* This class represents a text wizard property in a property form.
26*
27* @author Helmut Schottmüller <ilias@aurealis.de>
28* @version $Id$
29* @ingroup	ServicesForm
30*/
31class ilTextWizardInputGUI extends ilTextInputGUI
32{
33    /**
34     * @var ilTemplate
35     */
36    protected $tpl;
37
38    protected $values = array();
39    protected $allowMove = false;
40
41    /**
42    * Constructor
43    *
44    * @param	string	$a_title	Title
45    * @param	string	$a_postvar	Post Variable
46    */
47    public function __construct($a_title = "", $a_postvar = "")
48    {
49        global $DIC;
50
51        $this->lng = $DIC->language();
52        $this->tpl = $DIC["tpl"];
53        parent::__construct($a_title, $a_postvar);
54        $this->validationRegexp = "";
55    }
56
57    /**
58    * Set Values
59    *
60    * @param	array	$a_value	Value
61    */
62    public function setValues($a_values)
63    {
64        $this->values = $a_values;
65    }
66
67    /**
68    * Set Value
69    *
70    * @param	array	$a_value	Value
71    */
72    public function setValue($a_value)
73    {
74        $this->values = $a_value;
75    }
76
77    /**
78    * Get Values
79    *
80    * @return	array	Values
81    */
82    public function getValues()
83    {
84        return $this->values;
85    }
86
87    /**
88    * Set allow move
89    *
90    * @param	boolean	$a_allow_move Allow move
91    */
92    public function setAllowMove($a_allow_move)
93    {
94        $this->allowMove = $a_allow_move;
95    }
96
97    /**
98    * Get allow move
99    *
100    * @return	boolean	Allow move
101    */
102    public function getAllowMove()
103    {
104        return $this->allowMove;
105    }
106
107    /**
108    * Check input, strip slashes etc. set alert, if input is not ok.
109    *
110    * @return	boolean		Input ok, true/false
111    */
112    public function checkInput()
113    {
114        $lng = $this->lng;
115
116        $foundvalues = $_POST[$this->getPostVar()];
117        if (is_array($foundvalues)) {
118            foreach ($foundvalues as $idx => $value) {
119                $_POST[$this->getPostVar()][$idx] = ilUtil::stripSlashes($value);
120                if ($this->getRequired() && trim($value) == "") {
121                    $this->setAlert($lng->txt("msg_input_is_required"));
122
123                    return false;
124                } elseif (strlen($this->getValidationRegexp())) {
125                    if (!preg_match($this->getValidationRegexp(), $value)) {
126                        $this->setAlert($lng->txt("msg_wrong_format"));
127                        return false;
128                    }
129                }
130            }
131        } elseif ($this->getRequired()) {
132            $this->setAlert($lng->txt("msg_input_is_required"));
133            return false;
134        }
135
136        return $this->checkSubItemsInput();
137    }
138
139    /**
140    * Insert property html
141    *
142    * @return	int	Size
143    */
144    public function insert($a_tpl)
145    {
146        $a_tpl->setCurrentBlock("prop_generic");
147        $a_tpl->setVariable("PROP_GENERIC", $this->render());
148        $a_tpl->parseCurrentBlock();
149    }
150
151    public function render($a_mode = "")
152    {
153        $tpl = new ilTemplate("tpl.prop_textwizardinput.html", true, true, "Services/Form");
154        $i = 0;
155        foreach ($this->values as $value) {
156            if (strlen($value)) {
157                $tpl->setCurrentBlock("prop_text_propval");
158                $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value));
159                $tpl->parseCurrentBlock();
160            }
161            if ($this->getAllowMove()) {
162                $tpl->setCurrentBlock("move");
163                $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
164                $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
165                $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
166                $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
167                $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
168                $tpl->parseCurrentBlock();
169            }
170            $tpl->setCurrentBlock("row");
171            $tpl->setVariable("POST_VAR", $this->getPostVar() . "[$i]");
172            $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
173            $tpl->setVariable("SIZE", $this->getSize());
174            $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
175
176            if ($this->getDisabled()) {
177                $tpl->setVariable(
178                    "DISABLED",
179                    " disabled=\"disabled\""
180                );
181            } else {
182                $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
183                $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
184                $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
185                $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
186            }
187
188            $tpl->parseCurrentBlock();
189            $i++;
190        }
191
192        $tpl->setVariable("ELEMENT_ID", $this->getFieldId());
193
194        if (!$this->getDisabled()) {
195            $this->tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
196            $this->tpl->addJavascript("./Services/Form/templates/default/textwizard.js");
197        }
198
199        return $tpl->get();
200    }
201}
202