ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPCParagraphGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once("./Services/COPage/classes/class.ilPCParagraph.php");
5 require_once("./Services/COPage/classes/class.ilPageContentGUI.php");
6 require_once("./Services/COPage/classes/class.ilWysiwygUtil.php");
7 
19 {
24  function ilPCParagraphGUI(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id = "")
25  {
26  $this->setEnableWikiLinks(false);
27  parent::ilPageContentGUI($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
28 
29  // characteristics (should be flexible in the future)
31  }
32 
36  static function _getStandardCharacteristics()
37  {
38  global $lng;
39 
40  return array("" => $lng->txt("none"),
41  "Headline1" => $lng->txt("cont_Headline1"),
42  "Headline2" => $lng->txt("cont_Headline2"),
43  "Headline3" => $lng->txt("cont_Headline3"),
44  "Citation" => $lng->txt("cont_Citation"),
45  "Mnemonic" => $lng->txt("cont_Mnemonic"),
46  "Example" => $lng->txt("cont_Example"),
47  "Additional" => $lng->txt("cont_Additional"),
48  "Remark" => $lng->txt("cont_Remark"),
49  "List" => $lng->txt("cont_List"),
50  "TableContent" => $lng->txt("cont_TableContent")
51  );
52  }
53 
57  static function _getCharacteristics($a_style_id)
58  {
61 
62  if ($a_style_id > 0 &&
63  ilObject::_lookupType($a_style_id) == "sty")
64  {
65  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
66  $style = new ilObjStyleSheet($a_style_id);
67  $types = array("text_block", "heading1", "heading2", "heading3");
68  $chars = array();
69  foreach ($types as $t)
70  {
71  $chars = array_merge($chars, $style->getCharacteristics($t));
72  }
73  $new_chars = array();
74  foreach ($chars as $char)
75  {
76  if ($st_chars[$char] != "") // keep lang vars for standard chars
77  {
78  $new_chars[$char] = $st_chars[$char];
79  }
80  else
81  {
82  $new_chars[$char] = $char;
83  }
84  asort($new_chars);
85  }
86  $chars = $new_chars;
87  }
88 
89  return $chars;
90  }
91 
95  function &executeCommand()
96  {
97  // get next class that processes or forwards current command
98  $next_class = $this->ctrl->getNextClass($this);
99 
101  array("text_block", "heading1", "heading2", "heading3")); // scorm-2004
102 
103  // get current command
104  $cmd = $this->ctrl->getCmd();
105 
106  switch($next_class)
107  {
108  default:
109  $ret =& $this->$cmd();
110  break;
111  }
112 
113  return $ret;
114  }
115 
121  function setEnableWikiLinks($a_enablewikilinks)
122  {
123  $this->enablewikilinks = $a_enablewikilinks;
124  }
125 
132  {
133  return $this->enablewikilinks;
134  }
135 
139  function edit($a_insert = false)
140  {
141  global $ilUser, $ilias;
142 
143  // add paragraph edit template
144  $tpl = new ilTemplate("tpl.paragraph_edit.html", true, true, "Services/COPage");
145 
146  // help text
147  $this->insertHelp($tpl);
148 
149  // operations
150  if ($a_insert)
151  {
152  $tpl->setCurrentBlock("commands");
153  $tpl->setVariable("BTN_NAME", "create_par");
154  $tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
155  $tpl->setVariable("BTN_CANCEL", "cancelCreate");
156  $tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
157  $tpl->parseCurrentBlock();
158  $tpl->setCurrentBlock("commands2");
159  $tpl->setVariable("BTN_NAME", "create_par");
160  $tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
161  $tpl->setVariable("BTN_CANCEL", "cancelCreate");
162  $tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
163  $tpl->parseCurrentBlock();
164  $tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_insert_par"));
165  }
166  else
167  {
168  $tpl->setCurrentBlock("commands");
169  $tpl->setVariable("BTN_NAME", "update");
170  $tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
171  $tpl->setVariable("BTN_CANCEL", "cancelUpdate");
172  $tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
173  $tpl->parseCurrentBlock();
174  $tpl->setCurrentBlock("commands2");
175  $tpl->setVariable("BTN_NAME", "update");
176  $tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
177  $tpl->setVariable("BTN_CANCEL", "cancelUpdate");
178  $tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
179  $tpl->parseCurrentBlock();
180  $tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_edit_par"));
181  }
182 
183  // language and characteristic selection
184  if (!$a_insert)
185  {
186  if (key($_POST["cmd"]) == "update")
187  {
188  $s_lang = $_POST["par_language"];
189  $s_char = $_POST["par_characteristic"];
190  }
191  else
192  {
193  $s_lang = $this->content_obj->getLanguage();
194  $s_char = $this->content_obj->getCharacteristic();
195  if ($s_char == "")
196  {
197  $s_char = "Standard";
198  }
199  }
200  }
201  else
202  {
203  if (key($_POST["cmd"]) == "create_par")
204  {
205  $s_lang = $_POST["par_language"];
206  $s_char = $_POST["par_characteristic"];
207  }
208  else
209  {
210  $s_char = "Standard";
211  if ($_SESSION["il_text_lang_".$_GET["ref_id"]] != "")
212  {
213  $s_lang = $_SESSION["il_text_lang_".$_GET["ref_id"]];
214  }
215  else
216  {
217  $s_lang = $ilUser->getLanguage();
218  }
219 
220  // set characteristic of new paragraphs in list items to "List"
221  $cont_obj =& $this->pg_obj->getContentObject($this->getHierId());
222  if (is_object($cont_obj))
223  {
224  if ($cont_obj->getType() == "li" ||
225  ($cont_obj->getType() == "par" && $cont_obj->getCharacteristic() == "List"))
226  {
227  $s_char = "List";
228  }
229 
230  if ($cont_obj->getType() == "td" ||
231  ($cont_obj->getType() == "par" && $cont_obj->getCharacteristic() == "TableContent"))
232  {
233  $s_char = "TableContent";
234  }
235 
236  }
237  }
238  }
239 
240  $this->insertStyleSelectionList($tpl, $s_char);
241 // $this->insertCharacteristicTable($tpl, $s_char);
242 
243 
244  $tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
245 
246  $tpl->setVariable("PAR_TA_NAME", "par_content");
247  $tpl->setVariable("BB_MENU", $this->getBBMenu());
248  $this->tpl->addJavascript("./Services/COPage/phpBB/3_0_5/editor.js");
249  $this->tpl->addJavascript("./Services/COPage/js/paragraph_editing.js");
250  $this->setStyle();
251 
252  $this->displayValidationError();
253 
254  $tpl->setVariable("TXT_LANGUAGE", $this->lng->txt("language"));
255  $tpl->setVariable("TXT_ANCHOR", $this->lng->txt("cont_anchor"));
256 
257  require_once("Services/MetaData/classes/class.ilMDLanguageItem.php");
259  $select_lang = ilUtil::formSelect ($s_lang,"par_language",$lang,false,true);
260  $tpl->setVariable("SELECT_LANGUAGE", $select_lang);
261 
262  $tpl->setVariable("TXT_CHARACTERISTIC", $this->lng->txt("cont_characteristic"));
263 // $select_char = ilUtil::formSelect ($s_char,
264 // "par_characteristic",$this->chars,false,true);
265 // $tpl->setVariable("SELECT_CHARACTERISTIC", $select_char);
266 
267  if (key($_POST["cmd"]) == "update" || key($_POST["cmd"]) == "create_par")
268  {
269  $s_text = ilUtil::stripSlashes($_POST["par_content"], false);
270  // prevent curly brackets from being swallowed up by template engine
271  $s_text = str_replace("{", "&#123;", $s_text);
272  $s_text = str_replace("}", "&#125;", $s_text);
273  }
274  else if (!$a_insert)
275  {
276  $s_text = $this->content_obj->xml2output($this->content_obj->getText());
277  }
278 
279  $tpl->setVariable("PAR_TA_CONTENT", $s_text);
280 
281  $tpl->parseCurrentBlock();
282 
283  $this->tpl->setContent($tpl->get());
284  return $tpl->get();
285  }
286 
290  function insertCharacteristicTable($a_tpl, $a_seleted_value)
291  {
292  $i = 0;
293 
294  $chars = $this->getCharacteristics();
295 
296  if ($chars[$a_seleted_value] == "" && ($a_seleted_value != ""))
297  {
298  $chars = array_merge(array($a_seleted_value => $a_seleted_value),
299  $chars);
300  }
301 
302  foreach ($chars as $char => $char_lang)
303  {
304  $a_tpl->setCurrentBlock("characteristic_cell");
305  $a_tpl->setVariable("CHAR_HTML",
306  '<div class="ilc_text_block_'.$char.'" style="margin-top:2px; margin-bottom:2px; position:static;">'.$char_lang."</div>");
307  $a_tpl->setVariable("CHAR_VALUE", $char);
308  if ($char == $a_seleted_value)
309  {
310  $a_tpl->setVariable("SELECTED",
311  ' checked="checked" ');
312  }
313  $a_tpl->parseCurrentBlock();
314  if ((($i+1) % 3) == 0) //
315  {
316  $a_tpl->touchBlock("characteristic_row");
317  }
318  $i++;
319  }
320  $a_tpl->touchBlock("characteristic_table");
321  }
322 
323  function insertStyleSelectionList($a_tpl, $a_s_char)
324  {
325  include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
326  $selection = new ilAdvancedSelectionListGUI();
327  $selection->setFormSelectMode("par_characteristic", "", false,
328  "", "", "",
329  "", "", "", "");
330  $selection->setId("style_selection");
331  //$selection->setSelectionHeaderClass("MMInactive");
332  $selection->setHeaderIcon(ilAdvancedSelectionListGUI::DOWN_ARROW_DARK);
333  $selection->setSelectedValue($a_s_char);
334  //$selection->setItemLinkClass("small");
335  $selection->setUseImages(false);
336  $selection->setOnClickMode(ilAdvancedSelectionListGUI::ON_ITEM_CLICK_FORM_SELECT);
337 
338  $chars = $this->getCharacteristics();
339  $title_char = $chars[$a_s_char] != ""
340  ? $chars[$a_s_char]
341  : $a_s_char;
342  $selection->setListTitle($title_char);
343 
344  if ($chars[$a_seleted_value] == "" && ($a_seleted_value != ""))
345  {
346  $chars = array_merge(array($a_seleted_value => $a_seleted_value),
347  $chars);
348  }
349 
350  foreach ($chars as $char => $char_lang)
351  {
352  $t = "text_block";
353  $tag = "div";
354 //echo "-".$char;
355  switch($char)
356  {
357  case "Headline1": $t = "heading1"; $tag = "h1"; break;
358  case "Headline2": $t = "heading2"; $tag = "h2"; break;
359  case "Headline3": $t = "heading3"; $tag = "h3"; break;
360  }
361  $html = '<'.$tag.' class="ilc_'.$t.'_'.$char.'" style="margin-top:2px; margin-bottom:2px; position:static;">'.$char_lang."</".$tag.">";
362  $selection->addItem($char_lang, $char, "",
363  "", $char, "", $html);
364  }
365  $a_tpl->setVariable("ADV_SEL_STYLE", $selection->getHTML());
366  }
367 
371  private function setStyle()
372  {
373  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
374 
375  if ($this->pg_obj->getParentType() == "gdf" ||
376  $this->pg_obj->getParentType() == "lm" ||
377  $this->pg_obj->getParentType() == "dbk")
378  {
379  if ($this->pg_obj->getParentType() != "gdf")
380  {
381  $this->tpl->setContentStylesheet(ilObjStyleSheet::getContentStylePath(
382  ilObjContentObject::_lookupStyleSheetId($this->pg_obj->getParentId())));
383  }
384  else
385  {
386  $this->tpl->setContentStylesheet(ilObjStyleSheet::getContentStylePath(0));
387  }
388  }
389  else
390  {
391  if ($this->pg_obj->getParentType() != "sahs")
392  {
393 // $this->tpl->setContentStylesheet(ilObjStyleSheet::getContentStylePath(0));
394  }
395  }
396  }
397 
401  function insert()
402  {
403  return $this->edit(true);
404  }
405 
409  function update()
410  {
411  global $ilBench;
412 
413  $ilBench->start("Editor","Paragraph_update");
414  // set language and characteristic
415  $this->content_obj->setLanguage($_POST["par_language"]);
416  $this->content_obj->setCharacteristic($_POST["par_characteristic"]);
417  //$this->content_obj->setAnchor(ilUtil::stripSlashes($_POST["anchor"]));
418 
419 //echo "<br>PARupdate1:".$_POST["par_content"].":";
420 //echo "<br>PARupdate2:".htmlentities($_POST["par_content"]).":";
421 //echo "<br>PARupdate3:".htmlentities($this->content_obj->input2xml($_POST["par_content"])).":";
422 //echo "<br>PARupdate4:".$this->content_obj->input2xml($_POST["par_content"]).":";
423 
424  //$this->updated = $this->content_obj->setText(
425  // $this->content_obj->input2xml(stripslashes($_POST["par_content"]),
426  // $_POST["usedwsiwygeditor"]));
427  $this->updated = $this->content_obj->setText(
428  $this->content_obj->input2xml($_POST["par_content"],
429  $_POST["usedwsiwygeditor"]), true);
430 //echo "<br>PARupdate2";
431  if ($this->updated !== true)
432  {
433  $ilBench->stop("Editor","Paragraph_update");
434  $this->edit();
435  return;
436  }
437 
438  $this->updated = $this->pg_obj->update();
439 //echo "<br>PARupdate_after:".htmlentities($this->pg_obj->dom->dump_mem(0, "UTF-8")).":";
440 
441  $ilBench->stop("Editor","Paragraph_update");
442 
443  if ($this->updated === true)
444  {
445  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
446  }
447  else
448  {
449  $this->edit();
450  }
451  }
452 
453 
457  function create()
458  {
459  $this->content_obj =& new ilPCParagraph($this->dom);
460 //echo "+".$this->pc_id."+";
461  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
462  $this->content_obj->setLanguage($_POST["par_language"]);
463  $_SESSION["il_text_lang_".$_GET["ref_id"]] = $_POST["par_language"];
464  $this->content_obj->setCharacteristic($_POST["par_characteristic"]);
465 
466  $this->updated = $this->content_obj->setText(
467  $this->content_obj->input2xml($_POST["par_content"],
468  $_POST["usedwsiwygeditor"]), true);
469 
470  if ($this->updated !== true)
471  {
472  $this->insert();
473  return;
474  }
475  $this->updated = $this->pg_obj->update();
476 
477  if ($this->updated === true)
478  {
479  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
480  }
481  else
482  {
483  $this->insert();
484  }
485  }
486 
490  function insertHelp($a_tpl)
491  {
492  global $lng;
493 
494  $a_tpl->setCurrentBlock("help_item");
495  $a_tpl->setVariable("TXT_HELP", "<b>".$lng->txt("cont_syntax_help")."</b>");
496  $a_tpl->parseCurrentBlock();
497  $a_tpl->setCurrentBlock("help_item");
498  $a_tpl->setVariable("TXT_HELP", "* ".$lng->txt("cont_bullet_list"));
499  $a_tpl->parseCurrentBlock();
500  $a_tpl->setCurrentBlock("help_item");
501  $a_tpl->setVariable("TXT_HELP", "# ".$lng->txt("cont_numbered_list"));
502  $a_tpl->parseCurrentBlock();
503  $a_tpl->setCurrentBlock("help_item");
504  $a_tpl->setVariable("TXT_HELP", "=".$lng->txt("cont_Headline1")."=<br />".
505  "==".$lng->txt("cont_Headline2")."==<br />".
506  "===".$lng->txt("cont_Headline3")."===");
507  $a_tpl->parseCurrentBlock();
508 
509  if ($this->getEnableWikiLinks())
510  {
511  $a_tpl->setCurrentBlock("help_item");
512  $a_tpl->setVariable("TXT_HELP", "[[".$lng->txt("cont_wiki_page_link")."]]");
513  $a_tpl->parseCurrentBlock();
514  }
515 
516  $a_tpl->setCurrentBlock("help");
517  $a_tpl->parseCurrentBlock();
518  }
519 
520 }
521 ?>