ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPCDataTableGUI.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.ilPCDataTable.php");
5 require_once("./Services/COPage/classes/class.ilPCTableGUI.php");
6 require_once("./Services/COPage/classes/class.ilPageContentGUI.php");
7 
19 {
20 
25  function ilPCDataTableGUI(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id = "")
26  {
27  parent::ilPageContentGUI($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
28  $this->setCharacteristics(array("StandardTable" => $this->lng->txt("cont_StandardTable")));
29  }
30 
34  function &executeCommand()
35  {
36  $this->getCharacteristicsOfCurrentStyle("table"); // scorm-2004
37 
38  // get next class that processes or forwards current command
39  $next_class = $this->ctrl->getNextClass($this);
40 
41  // get current command
42  $cmd = $this->ctrl->getCmd();
43 
44  switch($next_class)
45  {
46  default:
47  $ret =& $this->$cmd();
48  break;
49  }
50 
51  return $ret;
52  }
53 
54 
58 
62  function editDataCl()
63  {
64  global $lng, $ilCtrl;
65 //var_dump($_GET);
66 //var_dump($_POST);
67 
68  $this->setTabs();
69 
70  $this->displayValidationError();
71 
72  include_once("./Services/COPage/classes/class.ilPCParagraph.php");
73 
74  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.tabledata.html", "Services/COPage");
75  $dtpl = $this->tpl;
76  //$dtpl = new ilTemplate("tpl.tabledata.html", true, true, "Services/COPage");
77  $dtpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "tableAction"));
78  $dtpl->setVariable("BB_MENU", $this->getBBMenu("cell_0_0"));
79 
80  $this->tpl->addJavascript("./Services/COPage/phpBB/3_0_5/editor.js");
81  $this->tpl->addJavascript("./Services/COPage/js/page_editing.js");
82  $this->tpl->addJavascript("./Services/COPage/js/paragraph_editing.js");
83 
84  // get all rows
85  $xpc = xpath_new_context($this->dom);
86  $path = "//PageContent[@HierId='".$this->getHierId()."']".
87  "/Table/TableRow";
88  $res =& xpath_eval($xpc, $path);
89 
90  for($i = 0; $i < count($res->nodeset); $i++)
91  {
92 
93  $xpc2 = xpath_new_context($this->dom);
94  $path2 = "//PageContent[@HierId='".$this->getHierId()."']".
95  "/Table/TableRow[$i+1]/TableData";
96  $res2 =& xpath_eval($xpc2, $path2);
97 
98  // if this is the first row -> col icons
99  if ($i == 0)
100  {
101  for($j = 0; $j < count($res2->nodeset); $j++)
102  {
103  if ($j == 0)
104  {
105  $dtpl->touchBlock("empty_td");
106  }
107 
108  if ($j == 0)
109  {
110  if (count($res2->nodeset) == 1)
111  {
112  $move_type = "none";
113  }
114  else
115  {
116  $move_type = "forward";
117  }
118  }
119  else if ($j == (count($res2->nodeset) - 1))
120  {
121  $move_type = "backward";
122  }
123  else
124  {
125  $move_type = "both";
126  }
127  $dtpl->setCurrentBlock("col_icon");
128  $dtpl->setVariable("COL_ICON_ALT", $lng->txt("content_column"));
129  $dtpl->setVariable("COL_ICON", ilUtil::getImagePath("col.svg"));
130  $dtpl->setVariable("COL_ONCLICK", "COL_".$move_type);
131  $dtpl->setVariable("NR", $j);
132  $dtpl->parseCurrentBlock();
133  }
134  $dtpl->setCurrentBlock("row");
135  $dtpl->parseCurrentBlock();
136  }
137 
138 
139  for($j = 0; $j < count($res2->nodeset); $j++)
140  {
141  // first col: row icons
142  if ($j == 0)
143  {
144  if ($i == 0)
145  {
146  if (count($res->nodeset) == 1)
147  {
148  $move_type = "none";
149  }
150  else
151  {
152  $move_type = "forward";
153  }
154  }
155  else if ($i == (count($res->nodeset) - 1))
156  {
157  $move_type = "backward";
158  }
159  else
160  {
161  $move_type = "both";
162  }
163  $dtpl->setCurrentBlock("row_icon");
164  $dtpl->setVariable("ROW_ICON_ALT", $lng->txt("content_row"));
165  $dtpl->setVariable("ROW_ICON", ilUtil::getImagePath("row.svg"));
166  $dtpl->setVariable("ROW_ONCLICK", "ROW_".$move_type);
167  $dtpl->setVariable("NR", $i);
168  $dtpl->parseCurrentBlock();
169  }
170 
171  // cell
172  if ($res2->nodeset[$j]->get_attribute("Hidden") != "Y")
173  {
174  $dtpl->setCurrentBlock("cell");
175 
176  if (is_array($_POST["cmd"]) && key($_POST["cmd"]) == "update")
177  {
178  $s_text = ilUtil::stripSlashes("cell_".$i."_".$j, false);
179  }
180  else
181  {
182  $s_text = ilPCParagraph::xml2output($this->content_obj->getCellText($i, $j));
183  }
184 
185  $dtpl->setVariable("PAR_TA_NAME", "cell[".$i."][".$j."]");
186  $dtpl->setVariable("PAR_TA_ID", "cell_".$i."_".$j);
187  $dtpl->setVariable("PAR_TA_CONTENT", $s_text);
188 
189  $cs = $res2->nodeset[$j]->get_attribute("ColSpan");
190  $rs = $res2->nodeset[$j]->get_attribute("RowSpan");
191 // $dtpl->setVariable("WIDTH", "140");
192 // $dtpl->setVariable("HEIGHT", "80");
193  if ($cs > 1)
194  {
195  $dtpl->setVariable("COLSPAN", 'colspan="'.$cs.'"');
196  $dtpl->setVariable("WIDTH", (140 + ($cs - 1) * 146));
197  }
198  if ($rs > 1)
199  {
200  $dtpl->setVariable("ROWSPAN", 'rowspan="'.$rs.'"');
201  $dtpl->setVariable("HEIGHT", (80 + ($rs - 1) * 86));
202  }
203  $dtpl->parseCurrentBlock();
204  }
205  }
206  $dtpl->setCurrentBlock("row");
207  $dtpl->parseCurrentBlock();
208  }
209 
210  // init menues
211  $types = array("row", "col");
212  $moves = array("none", "backward", "both", "forward");
213  $commands = array(
214  "row" => array( "newRowAfter" => "cont_ed_new_row_after",
215  "newRowBefore" => "cont_ed_new_row_before",
216  "moveRowUp" => "cont_ed_row_up",
217  "moveRowDown" => "cont_ed_row_down",
218  "deleteRow" => "cont_ed_delete_row"),
219  "col" => array( "newColAfter" => "cont_ed_new_col_after",
220  "newColBefore" => "cont_ed_new_col_before",
221  "moveColLeft" => "cont_ed_col_left",
222  "moveColRight" => "cont_ed_col_right",
223  "deleteCol" => "cont_ed_delete_col")
224  );
225 
226  foreach($types as $type)
227  {
228  foreach($moves as $move)
229  {
230  foreach($commands[$type] as $command => $lang_var)
231  {
232  if ($move == "none" && (substr($command, 0, 4) == "move"))
233  {
234  continue;
235  }
236  if (($move == "backward" && (in_array($command, array("movedown", "moveright")))) ||
237  ($move == "forward" && (in_array($command, array("moveup", "moveleft")))))
238  {
239  continue;
240  }
241  $this->tpl->setCurrentBlock("menu_item");
242  $this->tpl->setVariable("MENU_ITEM_TITLE", $lng->txt($lang_var));
243  $this->tpl->setVariable("CMD", $command);
244  $this->tpl->setVariable("TYPE", $type);
245  $this->tpl->parseCurrentBlock();
246  }
247  $this->tpl->setCurrentBlock("menu");
248  $this->tpl->setVariable("TYPE", $type);
249  $this->tpl->setVariable("MOVE", $move);
250  $this->tpl->parseCurrentBlock();
251  }
252  }
253 
254  // update/cancel
255  $this->tpl->setCurrentBlock("commands");
256  $this->tpl->setVariable("BTN_NAME", "update");
257  $this->tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
258  $this->tpl->parseCurrentBlock();
259 
260  $this->tpl->setVariable("FORMACTION2",
261  $ilCtrl->getFormAction($this, "tableAction"));
262  $this->tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_table"));
263 
264  }
265 
269  function update($a_redirect = true)
270  {
271  global $ilBench, $lng;
272 
273  $ilBench->start("Editor","Data_Table_update");
274 
275  // handle input data
276  include_once("./Services/COPage/classes/class.ilPCParagraph.php");
277  $data = array();
278 //var_dump($_POST["cell"]);
279 //var_dump($_GET);
280  if (is_array($_POST["cell"]))
281  {
282  foreach ($_POST["cell"] as $i => $row)
283  {
284  if (is_array($row))
285  {
286  foreach ($row as $j => $cell)
287  {
288  $data[$i][$j] =
290  $this->content_obj->getLanguage());
291  }
292  }
293  }
294  }
295 
296  $this->updated = $this->content_obj->setData($data);
297 
298  if ($this->updated !== true)
299  {
300  $ilBench->stop("Editor","Data_Table_update");
301  $this->editData();
302  return;
303  }
304 
305  $this->updated = $this->pg_obj->update();
306  $ilBench->stop("Editor","Data_Table_update");
307 
308  if ($a_redirect)
309  {
310  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
311  $this->ctrl->redirect($this, "editData");
312  }
313  }
314 
318  function updateJS()
319  {
320  global $ilBench, $lng, $ilCtrl;
321 
322  if ($_POST["cancel_update"])
323  {
324 // $this->ctrl->redirect($this, "editData");
325  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
326  }
327 
328  // handle input data
329  include_once("./Services/COPage/classes/class.ilPCParagraph.php");
330  include_once("./Services/COPage/classes/class.ilPCParagraphGUI.php");
331  $data = array();
332  foreach ($_POST as $k => $content)
333  {
334  if (substr($k, 0, 5) != "cell_")
335  {
336  continue;
337  }
338 
339  // determine cell content
340  $div = ilUtil::stripSlashes($content, false);
341  $p1 = strpos($div, '>');
342  $div = substr($div, $p1 + 1);
343  $div = "<div class='ilc_text_block_TableContent'>".$div;
344  $text = ilPCParagraph::handleAjaxContent($div);
345  if ($text === false)
346  {
347  $ilCtrl->returnToParent($this, "jump".$this->hier_id);
348  }
349  $text = $text["text"];
350 
351  $text = ilPCParagraph::_input2xml($text,
352  $this->content_obj->getLanguage(), true, false);
354 
355  // set content in data array
356  $id = explode("_", $k);
357  $data[(int) $id[1]][(int) $id[2]] = $text;
358  }
359 
360  // update data
361  $this->updated = $this->content_obj->setData($data);
362 
363  if ($this->updated !== true)
364  {
365  $this->editData();
366  return;
367  }
368 
369  $this->updated = $this->pg_obj->update();
370 
371 
372  // perform table action? (move...?)
373  //$this->update(false);
374  $this->pg_obj->addHierIDs();
375 
376  if ($_POST["tab_cmd"] != "")
377  {
378  $cell_hier_id = ($_POST["tab_cmd_type"] == "col")
379  ? $this->hier_id."_1_".($_POST["tab_cmd_id"] + 1)
380  : $this->hier_id."_".($_POST["tab_cmd_id"] + 1)."_1";
381  $cell_obj = $this->pg_obj->getContentObject($cell_hier_id);
382  if (is_object($cell_obj))
383  {
384  $cell_obj->$_POST["tab_cmd"]();
385  $_SESSION["il_pg_error"] = $this->pg_obj->update();
386  }
387  }
388 
389  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
390  if ($_POST["save_return"])
391  {
392  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
393  }
394  else
395  {
396  $this->ctrl->redirect($this, "editData");
397  }
398  }
399 
400 
404  function getNewTableObject()
405  {
406  return new ilPCDataTable($this->getPage());
407  }
408 
412  function afterCreation()
413  {
414  global $ilCtrl;
415 
416  $this->pg_obj->stripHierIDs();
417  $this->pg_obj->addHierIDs();
418  $ilCtrl->setParameter($this, "hier_id", $this->content_obj->readHierId());
419  $ilCtrl->setParameter($this, "pc_id", $this->content_obj->readPCId());
420  $this->content_obj->setHierId($this->content_obj->readHierId());
421  $this->setHierId($this->content_obj->readHierId());
422  $this->content_obj->setPCId($this->content_obj->readPCId());
423  $this->editData();
424  }
425 
429  function tableAction()
430  {
431  global $ilCtrl;
432 
433  $this->update(false);
434  $this->pg_obj->addHierIDs();
435 
436  $cell_hier_id = ($_POST["type"] == "col")
437  ? $this->hier_id."_1_".($_POST["id"] + 1)
438  : $this->hier_id."_".($_POST["id"] + 1)."_1";
439  $cell_obj = $this->pg_obj->getContentObject($cell_hier_id);
440  if (is_object($cell_obj))
441  {
442  $cell_obj->$_POST["action"]();
443  $_SESSION["il_pg_error"] = $this->pg_obj->update();
444  }
445  $ilCtrl->redirect($this, "editData");
446  }
447 
451  function setTabs()
452  {
453  global $ilCtrl, $ilTabs;
454 
455  parent::setTabs();
456 
457  $ilTabs->addTarget("cont_ed_edit_data",
458  $ilCtrl->getLinkTarget($this, "editData"), "editData",
459  get_class($this));
460 
461  }
462 
463 
467 
471  function editData()
472  {
473  global $lng, $ilCtrl;
474 
475 
477  {
478  return $this->editDataCl();
479  }
480 
481 //var_dump($_GET);
482 //var_dump($_POST);
483 
484  $this->setTabs();
485 
486  $this->displayValidationError();
487 
488 
489  include_once("./Services/COPage/classes/class.ilPCParagraph.php");
490 
491  //$this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.tabledata2.html", "Services/COPage");
492  //$dtpl = $this->tpl;
493  $dtpl = new ilTemplate("tpl.tabledata2.html", true, true, "Services/COPage");
494  $dtpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "tableAction"));
495 
496 
497  $dtpl->setVariable("WYSIWYG_ACTION",
498  $ilCtrl->getFormAction($this, "updateJS"));
499 
500  // get all rows
501  $xpc = xpath_new_context($this->dom);
502  $path = "//PageContent[@HierId='".$this->getHierId()."']".
503  "/Table/TableRow";
504  $res =& xpath_eval($xpc, $path);
505 
506  for($i = 0; $i < count($res->nodeset); $i++)
507  {
508 
509  $xpc2 = xpath_new_context($this->dom);
510  $path2 = "//PageContent[@HierId='".$this->getHierId()."']".
511  "/Table/TableRow[$i+1]/TableData";
512  $res2 =& xpath_eval($xpc2, $path2);
513 
514  // if this is the first row -> col icons
515  if ($i == 0)
516  {
517  for($j = 0; $j < count($res2->nodeset); $j++)
518  {
519  if ($j == 0)
520  {
521  $dtpl->touchBlock("empty_td");
522  }
523 
524  if ($j == 0)
525  {
526  if (count($res2->nodeset) == 1)
527  {
528  $move_type = "none";
529  }
530  else
531  {
532  $move_type = "forward";
533  }
534  }
535  else if ($j == (count($res2->nodeset) - 1))
536  {
537  $move_type = "backward";
538  }
539  else
540  {
541  $move_type = "both";
542  }
543  $dtpl->setCurrentBlock("col_icon");
544  $dtpl->setVariable("COL_ICON_ALT", $lng->txt("content_column"));
545  $dtpl->setVariable("COL_ICON", ilUtil::getImagePath("col.svg"));
546  $dtpl->setVariable("COL_ONCLICK", "COL_".$move_type);
547  $dtpl->setVariable("NR", $j);
548  $dtpl->parseCurrentBlock();
549  }
550  $dtpl->setCurrentBlock("row");
551  $dtpl->parseCurrentBlock();
552  }
553 
554 
555  for($j = 0; $j < count($res2->nodeset); $j++)
556  {
557  // first col: row icons
558  if ($j == 0)
559  {
560  if ($i == 0)
561  {
562  if (count($res->nodeset) == 1)
563  {
564  $move_type = "none";
565  }
566  else
567  {
568  $move_type = "forward";
569  }
570  }
571  else if ($i == (count($res->nodeset) - 1))
572  {
573  $move_type = "backward";
574  }
575  else
576  {
577  $move_type = "both";
578  }
579  $dtpl->setCurrentBlock("row_icon");
580  $dtpl->setVariable("ROW_ICON_ALT", $lng->txt("content_row"));
581  $dtpl->setVariable("ROW_ICON", ilUtil::getImagePath("row.svg"));
582  $dtpl->setVariable("ROW_ONCLICK", "ROW_".$move_type);
583  $dtpl->setVariable("NR", $i);
584  $dtpl->parseCurrentBlock();
585  }
586 
587  // cell
588  if ($res2->nodeset[$j]->get_attribute("Hidden") != "Y")
589  {
590  $dtpl->setCurrentBlock("cell");
591 
592  if (is_array($_POST["cmd"]) && key($_POST["cmd"]) == "update")
593  {
594  $s_text = ilUtil::stripSlashes("cell_".$i."_".$j, false);
595  }
596  else
597  {
598  $s_text = ilPCParagraph::xml2output($this->content_obj->getCellText($i, $j),
599  true, false);
600  include_once("./Services/COPage/classes/class.ilPCParagraphGUI.php");
601  $s_text = ilPCParagraphGUI::xml2outputJS($s_text, "TableContent",
602  $this->content_obj->readPCId()."_".$i."_".$j);
603  }
604 
605  $dtpl->setVariable("PAR_TA_NAME", "cell[".$i."][".$j."]");
606  $dtpl->setVariable("PAR_TA_ID", "cell_".$i."_".$j);
607  $dtpl->setVariable("PAR_TA_CONTENT", $s_text);
608 
609  $cs = $res2->nodeset[$j]->get_attribute("ColSpan");
610  $rs = $res2->nodeset[$j]->get_attribute("RowSpan");
611  $dtpl->setVariable("WIDTH", "140");
612  $dtpl->setVariable("HEIGHT", "80");
613  if ($cs > 1)
614  {
615  $dtpl->setVariable("COLSPAN", 'colspan="'.$cs.'"');
616  $dtpl->setVariable("WIDTH", (140 + ($cs - 1) * 146));
617  }
618  if ($rs > 1)
619  {
620  $dtpl->setVariable("ROWSPAN", 'rowspan="'.$rs.'"');
621  $dtpl->setVariable("HEIGHT", (80 + ($rs - 1) * 86));
622  }
623  $dtpl->parseCurrentBlock();
624  }
625  }
626  $dtpl->setCurrentBlock("row");
627  $dtpl->parseCurrentBlock();
628  }
629 
630  // init menues
631  $types = array("row", "col");
632  $moves = array("none", "backward", "both", "forward");
633  $commands = array(
634  "row" => array( "newRowAfter" => "cont_ed_new_row_after",
635  "newRowBefore" => "cont_ed_new_row_before",
636  "moveRowUp" => "cont_ed_row_up",
637  "moveRowDown" => "cont_ed_row_down",
638  "deleteRow" => "cont_ed_delete_row"),
639  "col" => array( "newColAfter" => "cont_ed_new_col_after",
640  "newColBefore" => "cont_ed_new_col_before",
641  "moveColLeft" => "cont_ed_col_left",
642  "moveColRight" => "cont_ed_col_right",
643  "deleteCol" => "cont_ed_delete_col")
644  );
645 
646  foreach($types as $type)
647  {
648  foreach($moves as $move)
649  {
650  foreach($commands[$type] as $command => $lang_var)
651  {
652  if ($move == "none" && (substr($command, 0, 4) == "move"))
653  {
654  continue;
655  }
656  if (($move == "backward" && (in_array($command, array("movedown", "moveright")))) ||
657  ($move == "forward" && (in_array($command, array("moveup", "moveleft")))))
658  {
659  continue;
660  }
661  $dtpl->setCurrentBlock("menu_item");
662  $dtpl->setVariable("MENU_ITEM_TITLE", $lng->txt($lang_var));
663  $dtpl->setVariable("CMD", $command);
664  $dtpl->setVariable("TYPE", $type);
665  $dtpl->parseCurrentBlock();
666  }
667  $dtpl->setCurrentBlock("menu");
668  $dtpl->setVariable("TYPE", $type);
669  $dtpl->setVariable("MOVE", $move);
670  $dtpl->parseCurrentBlock();
671  }
672  }
673 
674 
675  $dtpl->setVariable("FORMACTION2",
676  $ilCtrl->getFormAction($this, "tableAction"));
677  $dtpl->setVariable("TXT_ACTION", $this->lng->txt("cont_table"));
678 
679  // js editing preparation
680  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
683  ilYuiUtil::initPanel(false);
684  $GLOBALS["tpl"]->addJavascript("Services/COPage/tiny/4_1_5/tinymce.js");
685  $GLOBALS["tpl"]->addJavaScript("./Services/COPage/js/ilcopagecallback.js");
686  $GLOBALS["tpl"]->addJavascript("Services/COPage/js/page_editing.js");
687 
688  $GLOBALS["tpl"]->addOnloadCode("var preloader = new Image();
689  preloader.src = './templates/default/images/loader.svg';
690  ilCOPage.setContentCss('".
692  ", ".ilUtil::getStyleSheetLocation().", ./Services/COPage/css/tiny_extra.css');
693  ilCOPage.editTD('cell_0_0');
694  ");
695 
696  $cfg = $this->getPageConfig();
697  /*$tpl->setVariable("IL_TINY_MENU",
698  self::getTinyMenu(
699  $this->getPageObject()->getParentType(),
700  $cfg->getEnableInternalLinks(),
701  $cfg->getEnableWikiLinks(),
702  $cfg->getEnableKeywords(),
703  $this->getStyleId(), true, true,
704  $cfg->getEnableAnchors()
705  ));*/
706 
707  $dtpl->setVariable("IL_TINY_MENU",
709  $this->pg_obj->getParentType(),
710  $cfg->getEnableInternalLinks(),
711  $cfg->getEnableWikiLinks(),
712  $cfg->getEnableKeywords(),
713  $this->getStyleId(),
714  false, true, $cfg->getEnableAnchors(), false));
715 
716  // add int link parts
717  if ($cfg->getEnableInternalLinks() || $cfg->getEnableWikiLinks())
718  {
719  include_once("./Services/Link/classes/class.ilInternalLinkGUI.php");
720  $dtpl->setCurrentBlock("int_link_prep");
721  $dtpl->setVariable("INT_LINK_PREP", ilInternalLinkGUI::getInitHTML(
722  $ilCtrl->getLinkTargetByClass(array("ilpageeditorgui", "ilinternallinkgui"),
723  "", false, true, false)));
724  }
725 
726  $this->tpl->setContent($dtpl->get());
727  }
728 
729 
730 }
731 ?>