ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPageContentGUI.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.ilPageContent.php");
5 
15 {
17  var $ilias;
18  var $tpl;
19  var $lng;
20  var $ctrl;
21  var $pg_obj;
22  var $hier_id;
23  var $dom;
24  var $updated;
27  var $page_config = null;
28 
29  // common bb buttons (special ones are iln and wln)
30  protected static $common_bb_buttons = array(
31  "str" => "Strong", "emp" => "Emph", "imp" => "Important", "com" => "Comment",
32  "quot" => "Quotation", "acc" => "Accent", "code" => "Code", "tex" => "Tex",
33  "fn" => "Footnote", "xln" => "ExternalLink"
34  );
35 
40  function ilPageContentGUI($a_pg_obj, $a_content_obj, $a_hier_id = 0, $a_pc_id = "")
41  {
42  global $ilias, $tpl, $lng, $ilCtrl;
43  $this->ilias = $ilias;
44  $this->tpl = $tpl;
45  $this->lng = $lng;
46  $this->pg_obj = $a_pg_obj;
47  $this->ctrl = $ilCtrl;
48  $this->content_obj = $a_content_obj;
49 
50  if($a_hier_id !== 0)
51  {
52  $this->hier_id = $a_hier_id;
53  $this->pc_id = $a_pc_id;
54 //echo "-".$this->pc_id."-";
55  $this->dom = $a_pg_obj->getDom();
56  }
57  }
58 
64  function setContentObject($a_val)
65  {
66  $this->content_obj = $a_val;
67  }
68 
74  function getContentObject()
75  {
76  return $this->content_obj;
77  }
78 
84  function setPage($a_val)
85  {
86  $this->pg_obj = $a_val;
87  }
88 
94  function getPage()
95  {
96  return $this->pg_obj;
97  }
98 
104  function setPageConfig($a_val)
105  {
106  $this->page_config = $a_val;
107  }
108 
114  function getPageConfig()
115  {
116  return $this->page_config;
117  }
118 
122  static function _getCommonBBButtons()
123  {
125  }
126 
127  // scorm2004-start
133  function setStyleId($a_styleid)
134  {
135  $this->styleid = $a_styleid;
136  }
137 
143  function getStyleId()
144  {
145  return $this->styleid;
146  }
147 
151  function getStyle()
152  {
153  if ((!is_object($this->style) || $this->getStyleId() != $this->style->getId()) && $this->getStyleId() > 0)
154  {
155  if (ilObject::_lookupType($this->getStyleId()) == "sty")
156  {
157  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
158  $this->style = new ilObjStyleSheet($this->getStyleId());
159  }
160  }
161 
162  return $this->style;
163  }
164 
168  protected function getCharacteristicsOfCurrentStyle($a_type)
169  {
170  if ($this->getStyleId() > 0 &&
171  ilObject::_lookupType($this->getStyleId()) == "sty")
172  {
173  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
174  $style = new ilObjStyleSheet($this->getStyleId());
175  $chars = array();
176  if (!is_array($a_type))
177  {
178  $a_type = array($a_type);
179  }
180  foreach ($a_type as $at)
181  {
182  $chars = array_merge($chars, $style->getCharacteristics($at, true));
183  }
184  $new_chars = array();
185  if (is_array($chars))
186  {
187  foreach ($chars as $char)
188  {
189  if ($this->chars[$char] != "") // keep lang vars for standard chars
190  {
191  $new_chars[$char] = $this->chars[$char];
192  }
193  else
194  {
195  $new_chars[$char] = $char;
196  }
197  asort($new_chars);
198  }
199  }
200  $this->setCharacteristics($new_chars);
201  }
202  }
203 
207  function setCharacteristics($a_chars)
208  {
209  $this->chars = $a_chars;
210  }
211 
216  {
217  return $this->chars ? $this->chars : array();
218  }
219  // scorm2004-end
220 
221 
225  function getHierId()
226  {
227  return $this->hier_id;
228  }
229 
233  function setHierId($a_hier_id)
234  {
235  $this->hier_id = $a_hier_id;
236  }
237 
241  function getBBMenu($a_ta_name = "par_content")
242  {
243  global $lng, $ilCtrl;
244 
245  include_once("./Services/COPage/classes/class.ilPageEditorSettings.php");
246 
247  $btpl = new ilTemplate("tpl.bb_menu.html", true, true, "Services/COPage");
248 
249  // not nice, should be set by context per method
250  //if ($this->pg_obj->getParentType() == "gdf" ||
251  // $this->pg_obj->getParentType() == "lm" ||
252  // $this->pg_obj->getParentType() == "dbk")
253  if ($this->getPageConfig()->getEnableInternalLinks())
254  {
255  $btpl->setCurrentBlock("bb_ilink_button");
256  $btpl->setVariable("BB_LINK_ILINK",
257  $this->ctrl->getLinkTargetByClass("ilInternalLinkGUI", "showLinkHelp"));
258  $btpl->parseCurrentBlock();
259 
260  // add int link parts
261  include_once("./Modules/LearningModule/classes/class.ilInternalLinkGUI.php");
262  $btpl->setCurrentBlock("int_link_prep");
263  $btpl->setVariable("INT_LINK_PREP", ilInternalLinkGUI::getInitHTML(
264  $ilCtrl->getLinkTargetByClass(array("ilpageeditorgui", "ilinternallinkgui"),
265  "", false, true, false), true));
266  $btpl->parseCurrentBlock();
267 
268  }
269 
270  if ($this->getPageConfig()->getEnableKeywords())
271  {
272  $btpl->touchBlock("bb_kw_button");
273  $btpl->setVariable("TXT_KW", $this->lng->txt("cont_text_keyword"));
274  }
275  if ($this->pg_obj->getParentType() == "wpg")
276  {
277  $btpl->setCurrentBlock("bb_wikilink_button");
278  $btpl->setVariable("TXT_WLN2", $lng->txt("wiki_wiki_page"));
279  $btpl->parseCurrentBlock();
280  }
281  $mathJaxSetting = new ilSetting("MathJax");
282  $style = $this->getStyle();
283 //echo URL_TO_LATEX;
284  foreach (self::$common_bb_buttons as $c => $st)
285  {
286  if (ilPageEditorSettings::lookupSettingByParentType($this->pg_obj->getParentType(), "active_".$c, true))
287  {
288  if ($c != "tex" || $mathJaxSetting->get("enable") || defined("URL_TO_LATEX"))
289  {
290  $btpl->touchBlock("bb_".$c."_button");
291  $btpl->setVariable("TXT_".strtoupper($c), $this->lng->txt("cont_text_".$c));
292  }
293  }
294  }
295 
296  if ($this->getPageConfig()->getEnableAnchors())
297  {
298  $btpl->touchBlock("bb_anc_button");
299  $btpl->setVariable("TXT_ANC", $lng->txt("cont_anchor").":");
300  }
301 
302  // footnote
303 // $btpl->setVariable("TXT_FN", $this->lng->txt("cont_text_fn"));
304 
305 // $btpl->setVariable("TXT_CODE", $this->lng->txt("cont_text_code"));
306  $btpl->setVariable("TXT_ILN", $this->lng->txt("cont_text_iln"));
307 // $btpl->setVariable("TXT_XLN", $this->lng->txt("cont_text_xln"));
308 // $btpl->setVariable("TXT_TEX", $this->lng->txt("cont_text_tex"));
309  $btpl->setVariable("TXT_BB_TIP", $this->lng->txt("cont_bb_tip"));
310  $btpl->setVariable("TXT_WLN", $lng->txt("wiki_wiki_page"));
311 
312  $btpl->setVariable("PAR_TA_NAME", $a_ta_name);
313 
314  return $btpl->get();
315  }
316 
320  function delete()
321  {
322  $updated = $this->pg_obj->deleteContent($this->hier_id);
323  if($updated !== true)
324  {
325  $_SESSION["il_pg_error"] = $updated;
326  }
327  else
328  {
329  unset($_SESSION["il_pg_error"]);
330  }
331  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
332  }
333 
337  function moveAfter()
338  {
339  // check if a target is selected
340  if(!isset($_POST["target"]))
341  {
342  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
343  }
344 
345  // check if only one target is selected
346  if(count($_POST["target"]) > 1)
347  {
348  $this->ilias->raiseError($this->lng->txt("only_one_target"),$this->ilias->error_obj->MESSAGE);
349  }
350 
351  $a_hid = explode(":", $_POST["target"][0]);
352 //echo "-".$a_hid[0]."-".$a_hid[1]."-";
353 
354  // check if target is within source
355  if($this->hier_id == substr($a_hid[0], 0, strlen($this->hier_id)))
356  {
357  $this->ilias->raiseError($this->lng->txt("cont_target_within_source"),$this->ilias->error_obj->MESSAGE);
358  }
359 
360  // check whether target is allowed
361  $curr_node =& $this->pg_obj->getContentNode($a_hid[0], $a_hid[1]);
362  if (is_object($curr_node) && $curr_node->node_name() == "FileItem")
363  {
364  $this->ilias->raiseError($this->lng->txt("cont_operation_not_allowed"),$this->ilias->error_obj->MESSAGE);
365  }
366 
367  // strip "c" "r" of table ids from hierarchical id
368  $first_hier_character = substr($a_hid[0], 0, 1);
369  if ($first_hier_character == "c" ||
370  $first_hier_character == "r" ||
371  $first_hier_character == "i")
372  {
373  $a_hid[0] = substr($a_hid[0], 1);
374  }
375 
376  // move
377  $updated = $this->pg_obj->moveContentAfter($this->hier_id, $a_hid[0],
378  $this->content_obj->getPcId(), $a_hid[1]);
379  if($updated !== true)
380  {
381  $_SESSION["il_pg_error"] = $updated;
382  }
383  else
384  {
385  unset($_SESSION["il_pg_error"]);
386  }
387 
388  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
389  }
390 
394  function moveBefore()
395  {
396  // check if a target is selected
397  if(!isset($_POST["target"]))
398  {
399  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
400  }
401 
402  // check if target is within source
403  if(count($_POST["target"]) > 1)
404  {
405  $this->ilias->raiseError($this->lng->txt("only_one_target"),$this->ilias->error_obj->MESSAGE);
406  }
407 
408  $a_hid = explode(":", $_POST["target"][0]);
409 
410  // check if target is within source
411  if($this->hier_id == substr($a_hid[0], 0, strlen($this->hier_id)))
412  {
413  $this->ilias->raiseError($this->lng->txt("cont_target_within_source"),$this->ilias->error_obj->MESSAGE);
414  }
415 
416  // check whether target is allowed
417  $curr_node =& $this->pg_obj->getContentNode($a_hid[0], $a_hid[1]);
418  if (is_object($curr_node) && $curr_node->node_name() == "FileItem")
419  {
420  $this->ilias->raiseError($this->lng->txt("cont_operation_not_allowed"),$this->ilias->error_obj->MESSAGE);
421  }
422 
423  // strip "c" "r" of table ids from hierarchical id
424  $first_hier_character = substr($a_hid[0], 0, 1);
425  if ($first_hier_character == "c" ||
426  $first_hier_character == "r" ||
427  $first_hier_character == "i")
428  {
429  $a_hid[0] = substr($a_hid[0], 1);
430  }
431 
432  // move
433  $updated = $this->pg_obj->moveContentBefore($this->hier_id, $a_hid[0],
434  $this->content_obj->getPcId(), $a_hid[1]);
435  if($updated !== true)
436  {
437  $_SESSION["il_pg_error"] = $updated;
438  }
439  else
440  {
441  unset($_SESSION["il_pg_error"]);
442  }
443  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
444  }
445 
446 
450  function splitPage()
451  {
452  global $ilErr;
453 
454  if ($this->pg_obj->getParentType() != "lm" &&
455  $this->pg_obj->getParentType() != "dbk")
456  {
457  $ilErr->raiseError("Split method called for wrong parent type (".
458  $this->pg_obj->getParentType().")", $ilErr->FATAL);
459  }
460  else
461  {
462  $lm_page =& ilLMPageObject::_splitPage($this->pg_obj->getId(),
463  $this->pg_obj->getParentType(), $this->hier_id);
464 
465  // jump to new page
466  $this->ctrl->setParameterByClass("illmpageobjectgui", "obj_id", $lm_page->getId());
467  $this->ctrl->redirectByClass("illmpageobjectgui", "edit");
468  }
469 
470  $this->ctrl->returnToParent($this, "jump".($this->hier_id - 1));
471  }
472 
476  function splitPageNext()
477  {
478  global $ilErr;
479 
480  if ($this->pg_obj->getParentType() != "lm" &&
481  $this->pg_obj->getParentType() != "dbk")
482  {
483  $ilErr->raiseError("Split method called for wrong parent type (".
484  $this->pg_obj->getParentType().")", $ilErr->FATAL);
485  }
486  else
487  {
488  $succ_id = ilLMPageObject::_splitPageNext($this->pg_obj->getId(),
489  $this->pg_obj->getParentType(), $this->hier_id);
490 
491  // jump to successor page
492  if ($succ_id > 0)
493  {
494  $this->ctrl->setParameterByClass("illmpageobjectgui", "obj_id", $succ_id);
495  $this->ctrl->redirectByClass("illmpageobjectgui", "edit");
496  }
497 
498  }
499  $this->ctrl->returnToParent($this, "jump".($this->hier_id - 1));
500  }
501 
506  {
507  if(is_array($this->updated))
508  {
509  $error_str = "<b>Error(s):</b><br>";
510  foreach ($this->updated as $error)
511  {
512  $err_mess = implode($error, " - ");
513  if (!is_int(strpos($err_mess, ":0:")))
514  {
515  $error_str .= htmlentities($err_mess)."<br />";
516  }
517  }
518  $this->tpl->setVariable("MESSAGE", $error_str);
519  }
520  else if($this->updated != "" && $this->updated !== true)
521  {
522  $this->tpl->setVariable("MESSAGE", "<b>Error(s):</b><br />".
523  $this->updated."<br />");
524  }
525  }
526 
530  function cancelCreate()
531  {
532  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
533  }
534 
538  function cancelUpdate()
539  {
540  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
541  }
542 
546  function cancel()
547  {
548  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
549  }
550 
555  function deactivate()
556  {
557  $obj = & $this->content_obj;
558 
559  if ($obj->isEnabled ())
560  $obj->disable ();
561  else
562  $obj->enable ();
563 
564  $updated = $this->pg_obj->update($this->hier_id);
565  if($updated !== true)
566  {
567  $_SESSION["il_pg_error"] = $updated;
568  }
569  else
570  {
571  unset($_SESSION["il_pg_error"]);
572  }
573 
574  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
575  }
576 
580  function cut()
581  {
582  global $lng;
583 
584  $obj = $this->content_obj;
585 
586  $updated = $this->pg_obj->cutContents(array($this->hier_id.":".$this->pc_id));
587  if($updated !== true)
588  {
589  $_SESSION["il_pg_error"] = $updated;
590  }
591  else
592  {
593  unset($_SESSION["il_pg_error"]);
594  }
595 
596  ilUtil::sendSuccess($lng->txt("cont_sel_el_cut_use_paste"), true);
597  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
598  }
599 
603  function copy()
604  {
605  global $lng;
606 
607  $obj = $this->content_obj;
608 
609  ilUtil::sendSuccess($lng->txt("cont_sel_el_copied_use_paste"), true);
610  $this->pg_obj->copyContents(array($this->hier_id.":".$this->pc_id));
611 
612  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
613  }
614 
615 
619  function getTemplateOptions($a_type)
620  {
621  $style = $this->getStyle();
622 
623  if (is_object($style))
624  {
625  $ts = $style->getTemplates($a_type);
626  $options = array();
627  foreach ($ts as $t)
628  {
629  $options["t:".$t["id"].":".$t["name"]] = $t["name"];
630  }
631  return $options;
632  }
633  return array();
634  }
635 
636 }
637 ?>