ILIAS  Release_4_0_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 
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 
43  $this->ilias =& $ilias;
44  $this->tpl =& $tpl;
45  $this->lng =& $lng;
46  $this->pg_obj =& $a_pg_obj;
47  $this->ctrl =& $ilCtrl;
48 
49  $this->content_obj =& $a_content_obj;
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 
62  static function _getCommonBBButtons()
63  {
65  }
66 
67  // scorm2004-start
73  function setStyleId($a_styleid)
74  {
75  $this->styleid = $a_styleid;
76  }
77 
83  function getStyleId()
84  {
85  return $this->styleid;
86  }
87 
91  function getStyle()
92  {
93  if ((!is_object($this->style) || $this->getStyleId() != $this->style->getId()) && $this->getStyleId() > 0)
94  {
95  if (ilObject::_lookupType($this->getStyleId()) == "sty")
96  {
97  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
98  $this->style = new ilObjStyleSheet($this->getStyleId());
99  }
100  }
101 
102  return $this->style;
103  }
104 
108  protected function getCharacteristicsOfCurrentStyle($a_type)
109  {
110  if ($this->getStyleId() > 0 &&
111  ilObject::_lookupType($this->getStyleId()) == "sty")
112  {
113  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
114  $style = new ilObjStyleSheet($this->getStyleId());
115  $chars = array();
116  if (!is_array($a_type))
117  {
118  $a_type = array($a_type);
119  }
120  foreach ($a_type as $at)
121  {
122  $chars = array_merge($chars, $style->getCharacteristics($at, true));
123  }
124  $new_chars = array();
125  if (is_array($chars))
126  {
127  foreach ($chars as $char)
128  {
129  if ($this->chars[$char] != "") // keep lang vars for standard chars
130  {
131  $new_chars[$char] = $this->chars[$char];
132  }
133  else
134  {
135  $new_chars[$char] = $char;
136  }
137  asort($new_chars);
138  }
139  }
140  $this->setCharacteristics($new_chars);
141  }
142  }
143 
147  function setCharacteristics($a_chars)
148  {
149  $this->chars = $a_chars;
150  }
151 
156  {
157  return $this->chars ? $this->chars : array();
158  }
159  // scorm2004-end
160 
161  /*
162  function setReturnLocation($a_location)
163  {
164  $this->return_location = $a_location;
165  }
166 
167  function getReturnLocation()
168  {
169  return $this->return_location;
170  }*/
171 
175  function getHierId()
176  {
177  return $this->hier_id;
178  }
179 
183  function setHierId($a_hier_id)
184  {
185  $this->hier_id = $a_hier_id;
186  }
187 
191  function getBBMenu($a_ta_name = "par_content")
192  {
193  global $lng;
194 
195  include_once("./Services/COPage/classes/class.ilPageEditorSettings.php");
196 
197  $btpl = new ilTemplate("tpl.bb_menu.html", true, true, "Services/COPage");
198 
199  // not nice, should be set by context per method
200  if ($this->pg_obj->getParentType() == "gdf" ||
201  $this->pg_obj->getParentType() == "lm" ||
202  $this->pg_obj->getParentType() == "dbk")
203  {
204  $btpl->setCurrentBlock("bb_ilink_button");
205  $btpl->setVariable("BB_LINK_ILINK",
206  $this->ctrl->getLinkTargetByClass("ilInternalLinkGUI", "showLinkHelp"));
207  $btpl->parseCurrentBlock();
208  $btpl->touchBlock("bb_kw_button");
209  $btpl->setVariable("TXT_KW", $this->lng->txt("cont_text_keyword"));
210  }
211  if ($this->pg_obj->getParentType() == "wpg")
212  {
213  $btpl->setCurrentBlock("bb_wikilink_button");
214  $btpl->setVariable("TXT_WLN2", $lng->txt("wiki_wiki_page"));
215  $btpl->parseCurrentBlock();
216  }
217  $jsMathSetting = new ilSetting("jsMath");
218  $style = $this->getStyle();
219 //echo URL_TO_LATEX;
220  foreach (self::$common_bb_buttons as $c => $st)
221  {
222  if (ilPageEditorSettings::lookupSettingByParentType($this->pg_obj->getParentType(), "active_".$c, true))
223  {
224  if ($c != "tex" || $jsMathSetting->get("enable") || defined("URL_TO_LATEX"))
225  {
226  $btpl->touchBlock("bb_".$c."_button");
227  $btpl->setVariable("TXT_".strtoupper($c), $this->lng->txt("cont_text_".$c));
228  }
229  }
230  }
231 
232  // footnote
233 // $btpl->setVariable("TXT_FN", $this->lng->txt("cont_text_fn"));
234 
235 // $btpl->setVariable("TXT_CODE", $this->lng->txt("cont_text_code"));
236  $btpl->setVariable("TXT_ILN", $this->lng->txt("cont_text_iln"));
237 // $btpl->setVariable("TXT_XLN", $this->lng->txt("cont_text_xln"));
238 // $btpl->setVariable("TXT_TEX", $this->lng->txt("cont_text_tex"));
239  $btpl->setVariable("TXT_BB_TIP", $this->lng->txt("cont_bb_tip"));
240  $btpl->setVariable("TXT_WLN", $lng->txt("wiki_wiki_page"));
241  $btpl->setVariable("TXT_ANC", $lng->txt("cont_anchor").":");
242 
243  $btpl->setVariable("PAR_TA_NAME", $a_ta_name);
244 
245  return $btpl->get();
246  }
247 
251  function delete()
252  {
253  $updated = $this->pg_obj->deleteContent($this->hier_id);
254  if($updated !== true)
255  {
256  $_SESSION["il_pg_error"] = $updated;
257  }
258  else
259  {
260  unset($_SESSION["il_pg_error"]);
261  }
262  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
263  }
264 
268  function moveAfter()
269  {
270  // check if a target is selected
271  if(!isset($_POST["target"]))
272  {
273  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
274  }
275 
276  // check if only one target is selected
277  if(count($_POST["target"]) > 1)
278  {
279  $this->ilias->raiseError($this->lng->txt("only_one_target"),$this->ilias->error_obj->MESSAGE);
280  }
281 
282  $a_hid = explode(":", $_POST["target"][0]);
283 //echo "-".$a_hid[0]."-".$a_hid[1]."-";
284 
285  // check if target is within source
286  if($this->hier_id == substr($a_hid[0], 0, strlen($this->hier_id)))
287  {
288  $this->ilias->raiseError($this->lng->txt("cont_target_within_source"),$this->ilias->error_obj->MESSAGE);
289  }
290 
291  // check whether target is allowed
292  $curr_node =& $this->pg_obj->getContentNode($a_hid[0], $a_hid[1]);
293  if (is_object($curr_node) && $curr_node->node_name() == "FileItem")
294  {
295  $this->ilias->raiseError($this->lng->txt("cont_operation_not_allowed"),$this->ilias->error_obj->MESSAGE);
296  }
297 
298  // strip "c" "r" of table ids from hierarchical id
299  $first_hier_character = substr($a_hid[0], 0, 1);
300  if ($first_hier_character == "c" ||
301  $first_hier_character == "r" ||
302  $first_hier_character == "i")
303  {
304  $a_hid[0] = substr($a_hid[0], 1);
305  }
306 
307  // move
308  $updated = $this->pg_obj->moveContentAfter($this->hier_id, $a_hid[0],
309  $this->content_obj->getPcId(), $a_hid[1]);
310  if($updated !== true)
311  {
312  $_SESSION["il_pg_error"] = $updated;
313  }
314  else
315  {
316  unset($_SESSION["il_pg_error"]);
317  }
318 
319  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
320  }
321 
325  function moveBefore()
326  {
327  // check if a target is selected
328  if(!isset($_POST["target"]))
329  {
330  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
331  }
332 
333  // check if target is within source
334  if(count($_POST["target"]) > 1)
335  {
336  $this->ilias->raiseError($this->lng->txt("only_one_target"),$this->ilias->error_obj->MESSAGE);
337  }
338 
339  $a_hid = explode(":", $_POST["target"][0]);
340 
341  // check if target is within source
342  if($this->hier_id == substr($a_hid[0], 0, strlen($this->hier_id)))
343  {
344  $this->ilias->raiseError($this->lng->txt("cont_target_within_source"),$this->ilias->error_obj->MESSAGE);
345  }
346 
347  // check whether target is allowed
348  $curr_node =& $this->pg_obj->getContentNode($a_hid[0], $a_hid[1]);
349  if (is_object($curr_node) && $curr_node->node_name() == "FileItem")
350  {
351  $this->ilias->raiseError($this->lng->txt("cont_operation_not_allowed"),$this->ilias->error_obj->MESSAGE);
352  }
353 
354  // strip "c" "r" of table ids from hierarchical id
355  $first_hier_character = substr($a_hid[0], 0, 1);
356  if ($first_hier_character == "c" ||
357  $first_hier_character == "r" ||
358  $first_hier_character == "i")
359  {
360  $a_hid[0] = substr($a_hid[0], 1);
361  }
362 
363  // move
364  $updated = $this->pg_obj->moveContentBefore($this->hier_id, $a_hid[0],
365  $this->content_obj->getPcId(), $a_hid[1]);
366  if($updated !== true)
367  {
368  $_SESSION["il_pg_error"] = $updated;
369  }
370  else
371  {
372  unset($_SESSION["il_pg_error"]);
373  }
374  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
375  }
376 
377 
381  function splitPage()
382  {
383  global $ilErr;
384 
385  if ($this->pg_obj->getParentType() != "lm" &&
386  $this->pg_obj->getParentType() != "dbk")
387  {
388  $ilErr->raiseError("Split method called for wrong parent type (".
389  $this->pg_obj->getParentType().")", $ilErr->FATAL);
390  }
391  else
392  {
393  $lm_page =& ilLMPageObject::_splitPage($this->pg_obj->getId(),
394  $this->pg_obj->getParentType(), $this->hier_id);
395 
396  // jump to new page
397  $this->ctrl->setParameterByClass("illmpageobjectgui", "obj_id", $lm_page->getId());
398  $this->ctrl->redirectByClass("illmpageobjectgui", "edit");
399  }
400 
401  $this->ctrl->returnToParent($this, "jump".($this->hier_id - 1));
402  }
403 
407  function splitPageNext()
408  {
409  global $ilErr;
410 
411  if ($this->pg_obj->getParentType() != "lm" &&
412  $this->pg_obj->getParentType() != "dbk")
413  {
414  $ilErr->raiseError("Split method called for wrong parent type (".
415  $this->pg_obj->getParentType().")", $ilErr->FATAL);
416  }
417  else
418  {
419  $succ_id = ilLMPageObject::_splitPageNext($this->pg_obj->getId(),
420  $this->pg_obj->getParentType(), $this->hier_id);
421 
422  // jump to successor page
423  if ($succ_id > 0)
424  {
425  $this->ctrl->setParameterByClass("illmpageobjectgui", "obj_id", $succ_id);
426  $this->ctrl->redirectByClass("illmpageobjectgui", "edit");
427  }
428 
429  }
430  $this->ctrl->returnToParent($this, "jump".($this->hier_id - 1));
431  }
432 
437  {
438  if(is_array($this->updated))
439  {
440  $error_str = "<b>Validation Error(s):</b><br>";
441  foreach ($this->updated as $error)
442  {
443  $err_mess = implode($error, " - ");
444  if (!is_int(strpos($err_mess, ":0:")))
445  {
446  $error_str .= htmlentities($err_mess)."<br />";
447  }
448  }
449  $this->tpl->setVariable("MESSAGE", $error_str);
450  }
451  else if($this->updated != "" && $this->updated !== true)
452  {
453  $this->tpl->setVariable("MESSAGE", "<b>Validation Error(s):</b><br />".
454  $this->updated."<br />");
455  }
456  }
457 
461  function cancelCreate()
462  {
463  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
464  }
465 
469  function cancelUpdate()
470  {
471  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
472  }
473 
474 
479  function deactivate()
480  {
481  $obj = & $this->content_obj;
482 
483  if ($obj->isEnabled ())
484  $obj->disable ();
485  else
486  $obj->enable ();
487 
488  $updated = $this->pg_obj->update($this->hier_id);
489  if($updated !== true)
490  {
491  $_SESSION["il_pg_error"] = $updated;
492  }
493  else
494  {
495  unset($_SESSION["il_pg_error"]);
496  }
497 
498  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
499  }
500 
504  function getTemplateOptions($a_type)
505  {
506  $style = $this->getStyle();
507 
508  if (is_object($style))
509  {
510  $ts = $style->getTemplates($a_type);
511  $options = array();
512  foreach ($ts as $t)
513  {
514  $options["t:".$t["id"].":".$t["name"]] = $t["name"];
515  }
516  return $options;
517  }
518  return array();
519  }
520 
521 }
522 ?>