ILIAS  Release_4_1_x_branch Revision 61804
 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;
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 
270  if ($this->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  $jsMathSetting = new ilSetting("jsMath");
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" || $jsMathSetting->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->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>Validation 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>Validation 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 
543 
548  function deactivate()
549  {
550  $obj = & $this->content_obj;
551 
552  if ($obj->isEnabled ())
553  $obj->disable ();
554  else
555  $obj->enable ();
556 
557  $updated = $this->pg_obj->update($this->hier_id);
558  if($updated !== true)
559  {
560  $_SESSION["il_pg_error"] = $updated;
561  }
562  else
563  {
564  unset($_SESSION["il_pg_error"]);
565  }
566 
567  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
568  }
569 
573  function getTemplateOptions($a_type)
574  {
575  $style = $this->getStyle();
576 
577  if (is_object($style))
578  {
579  $ts = $style->getTemplates($a_type);
580  $options = array();
581  foreach ($ts as $t)
582  {
583  $options["t:".$t["id"].":".$t["name"]] = $t["name"];
584  }
585  return $options;
586  }
587  return array();
588  }
589 
590 }
591 ?>