ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilHtmlBlockGUIGen.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 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 include_once("Services/Block/classes/class.ilBlockGUI.php");
25 define("IL_FORM_EDIT", 0);
26 define("IL_FORM_CREATE", 1);
27 define("IL_FORM_RE_EDIT", 2);
28 define("IL_FORM_RE_CREATE", 3);
29 
37 {
38 
39  protected $form_edit_mode;
40 
45  public function __construct()
46  {
47  global $ilCtrl;
48 
49  $this->ctrl = $ilCtrl;
50 
51 
52  include_once("Services/Block/classes/class.ilHtmlBlock.php");
53  if ($_GET["html_block_id"] > 0)
54  {
55  $this->html_block = new ilHtmlBlock($_GET["html_block_id"]);
56  }
57 
58  $this->ctrl->saveParameter($this, array("html_block_id"));
59 
60 
61  }
62 
67  public function &executeCommand()
68  {
69  global $ilCtrl;
70 
71  // get next class and command
72  $next_class = $this->ctrl->getNextClass($this);
73  $cmd = $this->ctrl->getCmd();
74 
75  switch ($next_class)
76  {
77  default:
78  $html = $this->$cmd();
79  break;
80  }
81 
82  return $html;
83 
84  }
85 
91  public function setFormEditMode($a_form_edit_mode)
92  {
93  $this->form_edit_mode = $a_form_edit_mode;
94  }
95 
101  public function getFormEditMode()
102  {
103  return $this->form_edit_mode;
104  }
105 
110  public function outputFormHtmlBlock()
111  {
112  global $lng;
113 
114  $lng->loadLanguageModule("block");
115 
116  include("Services/Form/classes/class.ilPropertyFormGUI.php");
117 
118  $form_gui = new ilPropertyFormGUI();
119 
120  $values = $this->getValuesHtmlBlock();
121 
122  // Property Title
123  $alert = ($this->form_check["HtmlBlock"]["Title"]["error"] != "")
124  ? $this->form_check["HtmlBlock"]["Title"]["error"]
125  : "";
126  $form_gui->addTextProperty($lng->txt("block_html_block_title"),
127  "block_title",
128  $values["Title"],
129  "", $alert, true
130  , "200");
131 
132  // Property Content
133  $alert = ($this->form_check["HtmlBlock"]["Content"]["error"] != "")
134  ? $this->form_check["HtmlBlock"]["Content"]["error"]
135  : "";
136  $form_gui->addTextAreaProperty($lng->txt("block_html_block_content"),
137  "block_content",
138  $values["Content"],
139  "", $alert, false
140  , "40", "8", true);
141 
142  // save and cancel commands
143  if (in_array($this->getFormEditMode(), array(IL_FORM_CREATE,IL_FORM_RE_CREATE)))
144  {
145  $form_gui->addCommandButton("saveHtmlBlock", $lng->txt("save"));
146  $form_gui->addCommandButton("cancelSaveHtmlBlock", $lng->txt("cancel"));
147  }
148  else
149  {
150  $form_gui->addCommandButton("updateHtmlBlock", $lng->txt("save"));
151  $form_gui->addCommandButton("cancelUpdateHtmlBlock", $lng->txt("cancel"));
152  }
153 
154  $form_gui->setTitle($lng->txt("block_html_block_head"));
155  $form_gui->setFormAction($this->ctrl->getFormAction($this));
156 
157  // individual preparation of form
158  $this->prepareFormHtmlBlock($form_gui);
159 
160  return $form_gui->getHTML();
161 
162  }
163 
168  public function editHtmlBlock()
169  {
171  return $this->outputFormHtmlBlock();
172 
173  }
174 
179  public function createHtmlBlock()
180  {
182  return $this->outputFormHtmlBlock();
183 
184  }
185 
190  public function saveHtmlBlock()
191  {
192  include_once("./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php");
193  if ($this->checkInputHtmlBlock())
194  {
195  $this->html_block = new ilHtmlBlock();
196  $this->html_block->setTitle(ilUtil::stripSlashes($_POST["block_title"]));
197  $this->html_block->setContent(ilUtil::stripSlashes($_POST["block_content"]
199  $this->prepareSaveHtmlBlock($this->html_block);
200  $this->html_block->create();
201  }
202  else
203  {
205  return $this->outputFormHtmlBlock();
206  }
207 
208  }
209 
214  public function updateHtmlBlock()
215  {
216  include_once("./classes/class.ilObjAdvancedEditing.php");
217  if ($this->checkInputHtmlBlock())
218  {
219 
220  $this->html_block->setTitle(ilUtil::stripSlashes($_POST["block_title"]));
221  $this->html_block->setContent(ilUtil::stripSlashes($_POST["block_content"]
223  $this->html_block->update();
224  }
225  else
226  {
228  return $this->outputFormHtmlBlock();
229  }
230 
231  }
232 
237  public function getValuesHtmlBlock()
238  {
239  $values = array();
240 
241  switch ($this->getFormEditMode())
242  {
243  case IL_FORM_CREATE:
244  $values["Title"] = "";
245  $values["Content"] = "";
246  break;
247 
248  case IL_FORM_EDIT:
249  $values["Title"] = $this->html_block->getTitle();
250  $values["Content"] = $this->html_block->getContent();
251  break;
252 
253  case IL_FORM_RE_EDIT:
254  case IL_FORM_RE_CREATE:
255  $values["Title"] = ilUtil::stripSlashes($_POST["block_title"]);
256  $values["Content"] = ilUtil::stripSlashes($_POST["block_content"]
258  break;
259  }
260 
261  return $values;
262 
263  }
264 
269  public function checkInputHtmlBlock()
270  {
271 
272  include_once("./Services/Utilities/classes/class.ilTypeCheck.php");
273  $ilTypeCheck = new ilTypeCheck();
274 
275  $this->form_check["HtmlBlock"] = array();
276  $this->form_check["HtmlBlock"]["Title"] =
277  ilTypeCheck::check("varchar", $_POST["block_title"], true);
278  $this->form_check["HtmlBlock"]["Content"] =
279  ilTypeCheck::check("text", $_POST["block_content"], false);
280 
281  foreach($this->form_check["HtmlBlock"] as $prop_check)
282  {
283  if (!$prop_check["ok"])
284  {
285  return false;
286  }
287  }
288  return true;
289 
290  }
291 
297  public function prepareSaveHtmlBlock(&$a_html_block)
298  {
299 
300  }
301 
307  public function prepareFormHtmlBlock(&$a_form_gui)
308  {
309 
310  }
311 
312 
313 }
314 ?>