ILIAS  eassessment Revision 61809
 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  $jsMathSetting = new ilSetting("jsMath");
276  $style = $this->getStyle();
277 //echo URL_TO_LATEX;
278  foreach (self::$common_bb_buttons as $c => $st)
279  {
280  if (ilPageEditorSettings::lookupSettingByParentType($this->pg_obj->getParentType(), "active_".$c, true))
281  {
282  if ($c != "tex" || $jsMathSetting->get("enable") || defined("URL_TO_LATEX"))
283  {
284  $btpl->touchBlock("bb_".$c."_button");
285  $btpl->setVariable("TXT_".strtoupper($c), $this->lng->txt("cont_text_".$c));
286  }
287  }
288  }
289 
290  if ($this->getEnableAnchors())
291  {
292  $btpl->touchBlock("bb_anc_button");
293  $btpl->setVariable("TXT_ANC", $lng->txt("cont_anchor").":");
294  }
295 
296  // footnote
297 // $btpl->setVariable("TXT_FN", $this->lng->txt("cont_text_fn"));
298 
299 // $btpl->setVariable("TXT_CODE", $this->lng->txt("cont_text_code"));
300  $btpl->setVariable("TXT_ILN", $this->lng->txt("cont_text_iln"));
301 // $btpl->setVariable("TXT_XLN", $this->lng->txt("cont_text_xln"));
302 // $btpl->setVariable("TXT_TEX", $this->lng->txt("cont_text_tex"));
303  $btpl->setVariable("TXT_BB_TIP", $this->lng->txt("cont_bb_tip"));
304  $btpl->setVariable("TXT_WLN", $lng->txt("wiki_wiki_page"));
305 
306  $btpl->setVariable("PAR_TA_NAME", $a_ta_name);
307 
308  return $btpl->get();
309  }
310 
314  function delete()
315  {
316  $updated = $this->pg_obj->deleteContent($this->hier_id);
317  if($updated !== true)
318  {
319  $_SESSION["il_pg_error"] = $updated;
320  }
321  else
322  {
323  unset($_SESSION["il_pg_error"]);
324  }
325  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
326  }
327 
331  function moveAfter()
332  {
333  // check if a target is selected
334  if(!isset($_POST["target"]))
335  {
336  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
337  }
338 
339  // check if only one target is selected
340  if(count($_POST["target"]) > 1)
341  {
342  $this->ilias->raiseError($this->lng->txt("only_one_target"),$this->ilias->error_obj->MESSAGE);
343  }
344 
345  $a_hid = explode(":", $_POST["target"][0]);
346 //echo "-".$a_hid[0]."-".$a_hid[1]."-";
347 
348  // check if target is within source
349  if($this->hier_id == substr($a_hid[0], 0, strlen($this->hier_id)))
350  {
351  $this->ilias->raiseError($this->lng->txt("cont_target_within_source"),$this->ilias->error_obj->MESSAGE);
352  }
353 
354  // check whether target is allowed
355  $curr_node =& $this->pg_obj->getContentNode($a_hid[0], $a_hid[1]);
356  if (is_object($curr_node) && $curr_node->node_name() == "FileItem")
357  {
358  $this->ilias->raiseError($this->lng->txt("cont_operation_not_allowed"),$this->ilias->error_obj->MESSAGE);
359  }
360 
361  // strip "c" "r" of table ids from hierarchical id
362  $first_hier_character = substr($a_hid[0], 0, 1);
363  if ($first_hier_character == "c" ||
364  $first_hier_character == "r" ||
365  $first_hier_character == "i")
366  {
367  $a_hid[0] = substr($a_hid[0], 1);
368  }
369 
370  // move
371  $updated = $this->pg_obj->moveContentAfter($this->hier_id, $a_hid[0],
372  $this->content_obj->getPcId(), $a_hid[1]);
373  if($updated !== true)
374  {
375  $_SESSION["il_pg_error"] = $updated;
376  }
377  else
378  {
379  unset($_SESSION["il_pg_error"]);
380  }
381 
382  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
383  }
384 
388  function moveBefore()
389  {
390  // check if a target is selected
391  if(!isset($_POST["target"]))
392  {
393  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
394  }
395 
396  // check if target is within source
397  if(count($_POST["target"]) > 1)
398  {
399  $this->ilias->raiseError($this->lng->txt("only_one_target"),$this->ilias->error_obj->MESSAGE);
400  }
401 
402  $a_hid = explode(":", $_POST["target"][0]);
403 
404  // check if target is within source
405  if($this->hier_id == substr($a_hid[0], 0, strlen($this->hier_id)))
406  {
407  $this->ilias->raiseError($this->lng->txt("cont_target_within_source"),$this->ilias->error_obj->MESSAGE);
408  }
409 
410  // check whether target is allowed
411  $curr_node =& $this->pg_obj->getContentNode($a_hid[0], $a_hid[1]);
412  if (is_object($curr_node) && $curr_node->node_name() == "FileItem")
413  {
414  $this->ilias->raiseError($this->lng->txt("cont_operation_not_allowed"),$this->ilias->error_obj->MESSAGE);
415  }
416 
417  // strip "c" "r" of table ids from hierarchical id
418  $first_hier_character = substr($a_hid[0], 0, 1);
419  if ($first_hier_character == "c" ||
420  $first_hier_character == "r" ||
421  $first_hier_character == "i")
422  {
423  $a_hid[0] = substr($a_hid[0], 1);
424  }
425 
426  // move
427  $updated = $this->pg_obj->moveContentBefore($this->hier_id, $a_hid[0],
428  $this->content_obj->getPcId(), $a_hid[1]);
429  if($updated !== true)
430  {
431  $_SESSION["il_pg_error"] = $updated;
432  }
433  else
434  {
435  unset($_SESSION["il_pg_error"]);
436  }
437  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
438  }
439 
440 
444  function splitPage()
445  {
446  global $ilErr;
447 
448  if ($this->pg_obj->getParentType() != "lm" &&
449  $this->pg_obj->getParentType() != "dbk")
450  {
451  $ilErr->raiseError("Split method called for wrong parent type (".
452  $this->pg_obj->getParentType().")", $ilErr->FATAL);
453  }
454  else
455  {
456  $lm_page =& ilLMPageObject::_splitPage($this->pg_obj->getId(),
457  $this->pg_obj->getParentType(), $this->hier_id);
458 
459  // jump to new page
460  $this->ctrl->setParameterByClass("illmpageobjectgui", "obj_id", $lm_page->getId());
461  $this->ctrl->redirectByClass("illmpageobjectgui", "edit");
462  }
463 
464  $this->ctrl->returnToParent($this, "jump".($this->hier_id - 1));
465  }
466 
470  function splitPageNext()
471  {
472  global $ilErr;
473 
474  if ($this->pg_obj->getParentType() != "lm" &&
475  $this->pg_obj->getParentType() != "dbk")
476  {
477  $ilErr->raiseError("Split method called for wrong parent type (".
478  $this->pg_obj->getParentType().")", $ilErr->FATAL);
479  }
480  else
481  {
482  $succ_id = ilLMPageObject::_splitPageNext($this->pg_obj->getId(),
483  $this->pg_obj->getParentType(), $this->hier_id);
484 
485  // jump to successor page
486  if ($succ_id > 0)
487  {
488  $this->ctrl->setParameterByClass("illmpageobjectgui", "obj_id", $succ_id);
489  $this->ctrl->redirectByClass("illmpageobjectgui", "edit");
490  }
491 
492  }
493  $this->ctrl->returnToParent($this, "jump".($this->hier_id - 1));
494  }
495 
500  {
501  if(is_array($this->updated))
502  {
503  $error_str = "<b>Validation Error(s):</b><br>";
504  foreach ($this->updated as $error)
505  {
506  $err_mess = implode($error, " - ");
507  if (!is_int(strpos($err_mess, ":0:")))
508  {
509  $error_str .= htmlentities($err_mess)."<br />";
510  }
511  }
512  $this->tpl->setVariable("MESSAGE", $error_str);
513  }
514  else if($this->updated != "" && $this->updated !== true)
515  {
516  $this->tpl->setVariable("MESSAGE", "<b>Validation Error(s):</b><br />".
517  $this->updated."<br />");
518  }
519  }
520 
524  function cancelCreate()
525  {
526  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
527  }
528 
532  function cancelUpdate()
533  {
534  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
535  }
536 
537 
542  function deactivate()
543  {
544  $obj = & $this->content_obj;
545 
546  if ($obj->isEnabled ())
547  $obj->disable ();
548  else
549  $obj->enable ();
550 
551  $updated = $this->pg_obj->update($this->hier_id);
552  if($updated !== true)
553  {
554  $_SESSION["il_pg_error"] = $updated;
555  }
556  else
557  {
558  unset($_SESSION["il_pg_error"]);
559  }
560 
561  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
562  }
563 
567  function getTemplateOptions($a_type)
568  {
569  $style = $this->getStyle();
570 
571  if (is_object($style))
572  {
573  $ts = $style->getTemplates($a_type);
574  $options = array();
575  foreach ($ts as $t)
576  {
577  $options["t:".$t["id"].":".$t["name"]] = $t["name"];
578  }
579  return $options;
580  }
581  return array();
582  }
583 
584 }
585 ?>