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