1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5/** @defgroup ServicesForm Services/Form
6 */
7
8/**
9* This class represents a form user interface
10*
11* @author 	Alex Killing <alex.killing@gmx.de>
12* @version 	$Id$
13* @ingroup	ServicesForm
14*/
15class ilFormGUI
16{
17    protected $formaction;
18    protected $multipart = false;
19    protected $keepopen = false;
20    protected $opentag = true;
21    protected $id;
22    protected $name;
23    protected $prevent_double_submission = false;
24
25    /**
26    * Set FormAction.
27    *
28    * @param	string	$a_formaction	FormAction
29    */
30    public function setFormAction($a_formaction)
31    {
32        $this->formaction = $a_formaction;
33    }
34
35    /**
36    * Get FormAction.
37    *
38    * @return	string	FormAction
39    */
40    public function getFormAction()
41    {
42        return $this->formaction;
43    }
44
45    /**
46    * Set Target.
47    *
48    * @param	string	$a_target	Target
49    */
50    public function setTarget($a_target)
51    {
52        $this->target = $a_target;
53    }
54
55    /**
56    * Get Target.
57    *
58    * @return	string	Target
59    */
60    public function getTarget()
61    {
62        return $this->target;
63    }
64
65    /**
66    * Set Enctype Multipart/Formdata true/false.
67    *
68    * @param	boolean	$a_multipart	Enctype Multipart/Formdata true/false
69    */
70    public function setMultipart($a_multipart)
71    {
72        $this->multipart = $a_multipart;
73    }
74
75    /**
76    * Get Enctype Multipart/Formdata true/false.
77    *
78    * @return	boolean	Enctype Multipart/Formdata true/false
79    */
80    public function getMultipart()
81    {
82        return $this->multipart;
83    }
84
85    /**
86    * Set Id. If you use multiple forms on a screen you should set this value.
87    *
88    * @param	string	$a_id	Id
89    */
90    public function setId($a_id)
91    {
92        $this->id = $a_id;
93    }
94
95    /**
96    * Get Id.
97    *
98    * @return	string	Id
99    */
100    public function getId()
101    {
102        return $this->id;
103    }
104
105    /**
106    * Set Name. Useful for Javascript
107    *
108    * @param	string	$a_name	Name
109    */
110    public function setName($a_name)
111    {
112        $this->name = $a_name;
113    }
114
115    /**
116    * Get Name.
117    *
118    * @return	string	Name
119    */
120    public function getName()
121    {
122        return $this->name;
123    }
124
125    /**
126    * Set Keep Form Tag Open.
127    *
128    * @param	boolean	$a_keepopen	Keep Form Tag Open
129    */
130    public function setKeepOpen($a_keepopen)
131    {
132        $this->keepopen = $a_keepopen;
133    }
134
135    /**
136    * Get Keep Form Tag Open.
137    *
138    * @return	boolean	Keep Form Tag Open
139    */
140    public function getKeepOpen()
141    {
142        return $this->keepopen;
143    }
144
145    /**
146    * Enable/Disable Open Form Tag.
147    *
148    * @param	boolean	$a_keepopen	enable/disable form open tag
149    */
150    public function setOpenTag($a_open)
151    {
152        $this->opentag = $a_open;
153    }
154
155    /**
156    * Get Open Form Tag Enabled.
157    *
158    * @return	boolean	open form tag enabled
159    */
160    public function getOpenTag()
161    {
162        return $this->opentag;
163    }
164
165    /**
166    * Set close tag
167    *
168    * @param	boolean		close tag true/false
169    */
170    public function setCloseTag($a_val)
171    {
172        $this->setKeepOpen(!$a_val);
173    }
174
175    /**
176    * Get close tag
177    *
178    * @return	boolean		close tag true/false
179    */
180    public function getCloseTag()
181    {
182        return !$this->getKeepOpen();
183    }
184
185    /**
186     * Set prevent double submission
187     *
188     * @param bool $a_val prevent double submission
189     */
190    public function setPreventDoubleSubmission($a_val)
191    {
192        $this->prevent_double_submission = $a_val;
193    }
194
195    /**
196     * Get prevent double submission
197     *
198     * @return bool prevent double submission
199     */
200    public function getPreventDoubleSubmission()
201    {
202        return $this->prevent_double_submission;
203    }
204
205    /**
206    * Get HTML.
207    */
208    public function getHTML()
209    {
210        $tpl = new ilTemplate("tpl.form.html", true, true, "Services/Form");
211
212        // this line also sets multipart, so it must be before the multipart check
213        $content = $this->getContent();
214        if ($this->getOpenTag()) {
215            $opentpl = new ilTemplate('tpl.form_open.html', true, true, "Services/Form");
216            if ($this->getTarget() != "") {
217                $opentpl->setCurrentBlock("form_target");
218                $opentpl->setVariable("FORM_TARGET", $this->getTarget());
219                $opentpl->parseCurrentBlock();
220            }
221            if ($this->getName() != "") {
222                $opentpl->setCurrentBlock("form_name");
223                $opentpl->setVariable("FORM_NAME", $this->getName());
224                $opentpl->parseCurrentBlock();
225            }
226            if ($this->getPreventDoubleSubmission()) {
227                $opentpl->setVariable("FORM_CLASS", "preventDoubleSubmission");
228            }
229
230            if ($this->getMultipart()) {
231                $opentpl->touchBlock("multipart");
232                /*if (function_exists("apc_fetch"))
233                //
234                // Progress bar would need additional browser window (popup)
235                // to not be stopped, when form is submitted  (we can't work
236                // with an iframe or httprequest solution here)
237                //
238                {
239                    $tpl->touchBlock("onsubmit");
240
241                    //onsubmit="postForm('{ON_ACT}','form_{F_ID}',1); return false;"
242                    $tpl->setCurrentBlock("onsubmit");
243                    $tpl->setVariable("ON_ACT", $this->getFormAction());
244                    $tpl->setVariable("F_ID", $this->getId());
245                    $tpl->setVariable("F_ID", $this->getId());
246                    $tpl->parseCurrentBlock();
247
248                    $tpl->setCurrentBlock("hidden_progress");
249                    $tpl->setVariable("APC_PROGRESS_ID", uniqid());
250                    $tpl->setVariable("APC_FORM_ID", $this->getId());
251                    $tpl->parseCurrentBlock();
252                }*/
253            }
254            $opentpl->setVariable("FORM_ACTION", $this->getFormAction());
255            if ($this->getId() != "") {
256                $opentpl->setVariable("FORM_ID", $this->getId());
257            }
258            $opentpl->parseCurrentBlock();
259            $tpl->setVariable('FORM_OPEN_TAG', $opentpl->get());
260        }
261        $tpl->setVariable("FORM_CONTENT", $content);
262        if (!$this->getKeepOpen()) {
263            $tpl->setVariable("FORM_CLOSE_TAG", "</form>");
264        }
265        return $tpl->get();
266    }
267
268    /**
269    * Get Content.
270    */
271    public function getContent()
272    {
273        return "";
274    }
275}
276