ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPCParagraphGUI.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 require_once("./Services/COPage/classes/class.ilPCParagraph.php");
25 require_once("./Services/COPage/classes/class.ilPageContentGUI.php");
26 require_once("./Services/COPage/classes/class.ilWysiwygUtil.php");
27 
39 {
40 
45  function ilPCParagraphGUI(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id = "")
46  {
47  $this->setEnableWikiLinks(false);
48  parent::ilPageContentGUI($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
49  }
50 
51 
55  function &executeCommand()
56  {
57  // get next class that processes or forwards current command
58  $next_class = $this->ctrl->getNextClass($this);
59 
60  // get current command
61  $cmd = $this->ctrl->getCmd();
62 
63  switch($next_class)
64  {
65  default:
66  $ret =& $this->$cmd();
67  break;
68  }
69 
70  return $ret;
71  }
72 
78  function setEnableWikiLinks($a_enablewikilinks)
79  {
80  $this->enablewikilinks = $a_enablewikilinks;
81  }
82 
88  function getEnableWikiLinks()
89  {
90  return $this->enablewikilinks;
91  }
92 
96  function edit($a_insert = false)
97  {
98  global $ilUser, $ilias;
99 
100  // add paragraph edit template
101  $tpl = new ilTemplate("tpl.paragraph_edit.html", true, true, "Services/COPage");
102 
103  // help text
104  $this->insertHelp($tpl);
105 
106  // operations
107  if ($a_insert)
108  {
109  $tpl->setCurrentBlock("commands");
110  $tpl->setVariable("BTN_NAME", "create_par");
111  $tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
112  $tpl->setVariable("BTN_CANCEL", "cancelCreate");
113  $tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
114  $tpl->parseCurrentBlock();
115  $tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_insert_par"));
116  }
117  else
118  {
119  $tpl->setCurrentBlock("commands");
120  $tpl->setVariable("BTN_NAME", "update");
121  $tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
122  $tpl->setVariable("BTN_CANCEL", "cancelUpdate");
123  $tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
124  $tpl->parseCurrentBlock();
125  $tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_edit_par"));
126  }
127  $tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
128 
129  $tpl->setVariable("PAR_TA_NAME", "par_content");
130  $tpl->setVariable("BB_MENU", $this->getBBMenu());
131  $this->tpl->addJavascript("./Services/COPage/phpBB/3_0_0/editor.js");
132  $this->tpl->addJavascript("./Services/COPage/js/paragraph_editing.js");
133  $this->setStyle();
134 
135  $this->displayValidationError();
136 
137  // language and characteristic selection
138  if (!$a_insert)
139  {
140  if (key($_POST["cmd"]) == "update")
141  {
142  $s_lang = $_POST["par_language"];
143  $s_char = $_POST["par_characteristic"];
144  }
145  else
146  {
147  $s_lang = $this->content_obj->getLanguage();
148  $s_char = $this->content_obj->getCharacteristic();
149  }
150  }
151  else
152  {
153  if (key($_POST["cmd"]) == "create_par")
154  {
155  $s_lang = $_POST["par_language"];
156  $s_char = $_POST["par_characteristic"];
157  }
158  else
159  {
160  if ($_SESSION["il_text_lang_".$_GET["ref_id"]] != "")
161  {
162  $s_lang = $_SESSION["il_text_lang_".$_GET["ref_id"]];
163  }
164  else
165  {
166  $s_lang = $ilUser->getLanguage();
167  }
168 
169  // set characteristic of new paragraphs in list items to "List"
170  $cont_obj =& $this->pg_obj->getContentObject($this->getHierId());
171  if (is_object($cont_obj))
172  {
173  if ($cont_obj->getType() == "li" ||
174  ($cont_obj->getType() == "par" && $cont_obj->getCharacteristic() == "List"))
175  {
176  $s_char = "List";
177  }
178 
179  if ($cont_obj->getType() == "td" ||
180  ($cont_obj->getType() == "par" && $cont_obj->getCharacteristic() == "TableContent"))
181  {
182  $s_char = "TableContent";
183  }
184 
185  }
186  }
187  }
188 
189  $tpl->setVariable("TXT_LANGUAGE", $this->lng->txt("language"));
190  require_once("Services/MetaData/classes/class.ilMDLanguageItem.php");
192  $select_lang = ilUtil::formSelect ($s_lang,"par_language",$lang,false,true);
193  $tpl->setVariable("SELECT_LANGUAGE", $select_lang);
194 
195  // characteristic
196  $char = array("" => $this->lng->txt("none"),
197  "Headline1" => $this->lng->txt("cont_Headline1"),
198  "Headline2" => $this->lng->txt("cont_Headline2"),
199  "Headline3" => $this->lng->txt("cont_Headline3"),
200  "Example" => $this->lng->txt("cont_Example"),
201  "Citation" => $this->lng->txt("cont_Citation"),
202  "Mnemonic" => $this->lng->txt("cont_Mnemonic"),
203  "Additional" => $this->lng->txt("cont_Additional"),
204  "List" => $this->lng->txt("cont_List"),
205  "Remark" => $this->lng->txt("cont_Remark"),
206  "TableContent" => $this->lng->txt("cont_TableContent")
207  );
208  $tpl->setVariable("TXT_CHARACTERISTIC", $this->lng->txt("cont_characteristic"));
209  $select_char = ilUtil::formSelect ($s_char,
210  "par_characteristic",$char,false,true);
211  $tpl->setVariable("SELECT_CHARACTERISTIC", $select_char);
212 
213  if (key($_POST["cmd"]) == "update" || key($_POST["cmd"]) == "create_par")
214  {
215  $s_text = ilUtil::stripSlashes($_POST["par_content"], false);
216  // prevent curly brackets from being swallowed up by template engine
217  $s_text = str_replace("{", "&#123;", $s_text);
218  $s_text = str_replace("}", "&#125;", $s_text);
219  }
220  else if (!$a_insert)
221  {
222  $s_text = $this->content_obj->xml2output($this->content_obj->getText());
223  }
224 
225  $tpl->setVariable("PAR_TA_CONTENT", $s_text);
226 
227  $tpl->parseCurrentBlock();
228 
229  $this->tpl->setContent($tpl->get());
230  return $tpl->get();
231  }
232 
236  private function setStyle()
237  {
238  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
239 
240  if ($this->pg_obj->getParentType() == "gdf" ||
241  $this->pg_obj->getParentType() == "lm" ||
242  $this->pg_obj->getParentType() == "dbk")
243  {
244  if ($this->pg_obj->getParentType() != "gdf")
245  {
246  $this->tpl->setContentStylesheet(ilObjStyleSheet::getContentStylePath(
247  ilObjContentObject::_lookupStyleSheetId($this->pg_obj->getParentId())));
248  }
249  else
250  {
251  $this->tpl->setContentStylesheet(ilObjStyleSheet::getContentStylePath(0));
252  }
253  }
254  else
255  {
256  $this->tpl->setContentStylesheet(ilObjStyleSheet::getContentStylePath(0));
257  }
258  }
259 
263  function insert()
264  {
265  return $this->edit(true);
266  }
267 
271  function update()
272  {
273  global $ilBench;
274 
275  $ilBench->start("Editor","Paragraph_update");
276  // set language and characteristic
277  $this->content_obj->setLanguage($_POST["par_language"]);
278  $this->content_obj->setCharacteristic($_POST["par_characteristic"]);
279 
280 //echo "<br>PARupdate1:".$_POST["par_content"].":";
281 //echo "<br>PARupdate2:".htmlentities($_POST["par_content"]).":";
282 //echo "<br>PARupdate3:".htmlentities($this->content_obj->input2xml($_POST["par_content"])).":";
283 //echo "<br>PARupdate4:".$this->content_obj->input2xml($_POST["par_content"]).":";
284 
285  //$this->updated = $this->content_obj->setText(
286  // $this->content_obj->input2xml(stripslashes($_POST["par_content"]),
287  // $_POST["usedwsiwygeditor"]));
288  $this->updated = $this->content_obj->setText(
289  $this->content_obj->input2xml($_POST["par_content"],
290  $_POST["usedwsiwygeditor"]), true);
291 //echo "<br>PARupdate2";
292  if ($this->updated !== true)
293  {
294  $ilBench->stop("Editor","Paragraph_update");
295  $this->edit();
296  return;
297  }
298 
299  $this->updated = $this->pg_obj->update();
300 //echo "<br>PARupdate_after:".htmlentities($this->pg_obj->dom->dump_mem(0, "UTF-8")).":";
301 
302  $ilBench->stop("Editor","Paragraph_update");
303 
304  if ($this->updated === true)
305  {
306  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
307  }
308  else
309  {
310  $this->edit();
311  }
312  }
313 
314 
318  function create()
319  {
320  $this->content_obj =& new ilPCParagraph($this->dom);
321 //echo "+".$this->pc_id."+";
322  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
323  $this->content_obj->setLanguage($_POST["par_language"]);
324  $_SESSION["il_text_lang_".$_GET["ref_id"]] = $_POST["par_language"];
325  $this->content_obj->setCharacteristic($_POST["par_characteristic"]);
326 
327  $this->updated = $this->content_obj->setText(
328  $this->content_obj->input2xml($_POST["par_content"],
329  $_POST["usedwsiwygeditor"]), true);
330 
331  if ($this->updated !== true)
332  {
333  $this->insert();
334  return;
335  }
336  $this->updated = $this->pg_obj->update();
337 
338  if ($this->updated === true)
339  {
340  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
341  }
342  else
343  {
344  $this->insert();
345  }
346  }
347 
351  function insertHelp($a_tpl)
352  {
353  global $lng;
354 
355  $a_tpl->setCurrentBlock("help_item");
356  $a_tpl->setVariable("TXT_HELP", "<b>".$lng->txt("cont_syntax_help")."</b>");
357  $a_tpl->parseCurrentBlock();
358  $a_tpl->setCurrentBlock("help_item");
359  $a_tpl->setVariable("TXT_HELP", "* ".$lng->txt("cont_bullet_list"));
360  $a_tpl->parseCurrentBlock();
361  $a_tpl->setCurrentBlock("help_item");
362  $a_tpl->setVariable("TXT_HELP", "# ".$lng->txt("cont_numbered_list"));
363  $a_tpl->parseCurrentBlock();
364  $a_tpl->setCurrentBlock("help_item");
365  $a_tpl->setVariable("TXT_HELP", "=".$lng->txt("cont_Headline1")."=<br />".
366  "==".$lng->txt("cont_Headline2")."==<br />".
367  "===".$lng->txt("cont_Headline3")."===");
368  $a_tpl->parseCurrentBlock();
369 
370  if ($this->getEnableWikiLinks())
371  {
372  $a_tpl->setCurrentBlock("help_item");
373  $a_tpl->setVariable("TXT_HELP", "[[".$lng->txt("cont_wiki_page_link")."]]");
374  $a_tpl->parseCurrentBlock();
375  }
376 
377  $a_tpl->setCurrentBlock("help");
378  $a_tpl->parseCurrentBlock();
379  }
380 
381 }
382 ?>