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