ILIAS  release_7 Revision v7.30-3-g800a261c036
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 {
23  protected $tabs;
24 
25 
29  protected $main_tpl;
30 
31 
36  public function __construct(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id = "")
37  {
38  global $DIC;
39 
40  $this->main_tpl = $DIC->ui()->mainTemplate();
41  $this->lng = $DIC->language();
42  $this->ctrl = $DIC->ctrl();
43  $this->tabs = $DIC->tabs();
44  parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
45  $this->setCharacteristics(array("StandardTable" => $this->lng->txt("cont_StandardTable")));
46  $this->tool_context = $DIC->globalScreen()->tool()->context();
47  }
48 
52  public function executeCommand()
53  {
54  $this->getCharacteristicsOfCurrentStyle("table"); // scorm-2004
55 
56  // get next class that processes or forwards current command
57  $next_class = $this->ctrl->getNextClass($this);
58 
59  // get current command
60  $cmd = $this->ctrl->getCmd();
61 
62  switch ($next_class) {
63  default:
64  $ret = $this->$cmd();
65  break;
66  }
67 
68  return $ret;
69  }
70 
71 
75 
79  public function editDataCl()
80  {
81  $lng = $this->lng;
82  $ilCtrl = $this->ctrl;
83  //var_dump($_GET);
84  //var_dump($_POST);
85 
86  $this->setTabs();
87 
88  $this->displayValidationError();
89 
90  include_once("./Services/COPage/classes/class.ilPCParagraph.php");
91 
92  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.tabledata.html", "Services/COPage");
93  $dtpl = $this->tpl;
94  //$dtpl = new ilTemplate("tpl.tabledata.html", true, true, "Services/COPage");
95  $dtpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "tableAction"));
96  $dtpl->setVariable("BB_MENU", $this->getBBMenu("cell_0_0"));
97 
100  ilYuiUtil::initPanel(false);
101  $this->tpl->addJavascript("./Services/COPage/phpBB/3_0_5/editor.js");
102  //$this->tpl->addJavascript("./Services/COPage/js/page_editing.js");
103  $this->tpl->addJavascript("./Services/COPage/js/paragraph_editing.js");
104 
105  // get all rows
106  $xpc = xpath_new_context($this->dom);
107  $path = "//PageContent[@HierId='" . $this->getHierId() . "']" .
108  "/Table/TableRow";
109  $res = xpath_eval($xpc, $path);
110 
111  for ($i = 0; $i < count($res->nodeset); $i++) {
112  $xpc2 = xpath_new_context($this->dom);
113  $path2 = "//PageContent[@HierId='" . $this->getHierId() . "']" .
114  "/Table/TableRow[$i+1]/TableData";
115  $res2 = xpath_eval($xpc2, $path2);
116 
117  // if this is the first row -> col icons
118  if ($i == 0) {
119  for ($j = 0; $j < count($res2->nodeset); $j++) {
120  if ($j == 0) {
121  $dtpl->touchBlock("empty_td");
122  }
123 
124  if ($j == 0) {
125  if (count($res2->nodeset) == 1) {
126  $move_type = "none";
127  } else {
128  $move_type = "forward";
129  }
130  } elseif ($j == (count($res2->nodeset) - 1)) {
131  $move_type = "backward";
132  } else {
133  $move_type = "both";
134  }
135  $dtpl->setCurrentBlock("col_icon");
136  $dtpl->setVariable("COL_ICON_ALT", $lng->txt("content_column"));
137  $dtpl->setVariable("COL_ICON", ilUtil::getImagePath("col.svg"));
138  $dtpl->setVariable("COL_ONCLICK", "COL_" . $move_type);
139  $dtpl->setVariable("NR", $j);
140  $dtpl->parseCurrentBlock();
141  }
142  $dtpl->setCurrentBlock("row");
143  $dtpl->parseCurrentBlock();
144  }
145 
146 
147  for ($j = 0; $j < count($res2->nodeset); $j++) {
148  // first col: row icons
149  if ($j == 0) {
150  if ($i == 0) {
151  if (count($res->nodeset) == 1) {
152  $move_type = "none";
153  } else {
154  $move_type = "forward";
155  }
156  } elseif ($i == (count($res->nodeset) - 1)) {
157  $move_type = "backward";
158  } else {
159  $move_type = "both";
160  }
161  $dtpl->setCurrentBlock("row_icon");
162  $dtpl->setVariable("ROW_ICON_ALT", $lng->txt("content_row"));
163  $dtpl->setVariable("ROW_ICON", ilUtil::getImagePath("row.svg"));
164  $dtpl->setVariable("ROW_ONCLICK", "ROW_" . $move_type);
165  $dtpl->setVariable("NR", $i);
166  $dtpl->parseCurrentBlock();
167  }
168 
169  // cell
170  if ($res2->nodeset[$j]->get_attribute("Hidden") != "Y") {
171  $dtpl->setCurrentBlock("cell");
172 
173  if (is_array($_POST["cmd"]) && key($_POST["cmd"]) == "update") {
174  $s_text = ilUtil::stripSlashes("cell_" . $i . "_" . $j, false);
175  } else {
176  $s_text = ilPCParagraph::xml2output($this->content_obj->getCellText($i, $j));
177  }
178 
179  $dtpl->setVariable("PAR_TA_NAME", "cell[" . $i . "][" . $j . "]");
180  $dtpl->setVariable("PAR_TA_ID", "cell_" . $i . "_" . $j);
181  $dtpl->setVariable("PAR_TA_CONTENT", $s_text);
182 
183  $cs = $res2->nodeset[$j]->get_attribute("ColSpan");
184  $rs = $res2->nodeset[$j]->get_attribute("RowSpan");
185  // $dtpl->setVariable("WIDTH", "140");
186  // $dtpl->setVariable("HEIGHT", "80");
187  if ($cs > 1) {
188  $dtpl->setVariable("COLSPAN", 'colspan="' . $cs . '"');
189  $dtpl->setVariable("WIDTH", (140 + ($cs - 1) * 146));
190  }
191  if ($rs > 1) {
192  $dtpl->setVariable("ROWSPAN", 'rowspan="' . $rs . '"');
193  $dtpl->setVariable("HEIGHT", (80 + ($rs - 1) * 86));
194  }
195  $dtpl->parseCurrentBlock();
196  }
197  }
198  $dtpl->setCurrentBlock("row");
199  $dtpl->parseCurrentBlock();
200  }
201 
202  // init menues
203  $types = array("row", "col");
204  $moves = array("none", "backward", "both", "forward");
205  $commands = array(
206  "row" => array( "newRowAfter" => "cont_ed_new_row_after",
207  "newRowBefore" => "cont_ed_new_row_before",
208  "moveRowUp" => "cont_ed_row_up",
209  "moveRowDown" => "cont_ed_row_down",
210  "deleteRow" => "cont_ed_delete_row"),
211  "col" => array( "newColAfter" => "cont_ed_new_col_after",
212  "newColBefore" => "cont_ed_new_col_before",
213  "moveColLeft" => "cont_ed_col_left",
214  "moveColRight" => "cont_ed_col_right",
215  "deleteCol" => "cont_ed_delete_col")
216  );
217  foreach ($types as $type) {
218  foreach ($moves as $move) {
219  foreach ($commands[$type] as $command => $lang_var) {
220  if ($move == "none" && (substr($command, 0, 4) == "move" || substr($command, 0, 6) == "delete")) {
221  continue;
222  }
223  if (($move == "backward" && (in_array($command, array("movedown", "moveright")))) ||
224  ($move == "forward" && (in_array($command, array("moveup", "moveleft"))))) {
225  continue;
226  }
227  $this->tpl->setCurrentBlock("menu_item");
228  $this->tpl->setVariable("MENU_ITEM_TITLE", $lng->txt($lang_var));
229  $this->tpl->setVariable("CMD", $command);
230  $this->tpl->setVariable("TYPE", $type);
231  $this->tpl->parseCurrentBlock();
232  }
233  $this->tpl->setCurrentBlock("menu");
234  $this->tpl->setVariable("TYPE", $type);
235  $this->tpl->setVariable("MOVE", $move);
236  $this->tpl->parseCurrentBlock();
237  }
238  }
239 
240  // update/cancel
241  $this->tpl->setCurrentBlock("commands");
242  $this->tpl->setVariable("BTN_NAME", "update");
243  $this->tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
244  $this->tpl->parseCurrentBlock();
245 
246  $this->tpl->setVariable(
247  "FORMACTION2",
248  $ilCtrl->getFormAction($this, "tableAction")
249  );
250  $this->tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_table"));
251  }
252 
256  public function update($a_redirect = true)
257  {
258  $lng = $this->lng;
259 
260  // handle input data
261  include_once("./Services/COPage/classes/class.ilPCParagraph.php");
262  $data = array();
263  //var_dump($_POST["cell"]);
264  //var_dump($_GET);
265  if (is_array($_POST["cell"])) {
266  foreach ($_POST["cell"] as $i => $row) {
267  if (is_array($row)) {
268  foreach ($row as $j => $cell) {
269  $data[$i][$j] =
271  $cell,
272  $this->content_obj->getLanguage()
273  );
274  }
275  }
276  }
277  }
278 
279  $this->updated = $this->content_obj->setData($data);
280 
281  if ($this->updated !== true) {
282  $this->editData();
283  return;
284  }
285 
286  $this->updated = $this->pg_obj->update();
287 
288  if ($a_redirect) {
289  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
290  $this->ctrl->redirect($this, "editData");
291  }
292  }
293 
297  public function updateJS()
298  {
299  $lng = $this->lng;
300  $ilCtrl = $this->ctrl;
301 
302  if ($_POST["cancel_update"]) {
303  // $this->ctrl->redirect($this, "editData");
304  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
305  }
306 
307  // handle input data
308  include_once("./Services/COPage/classes/class.ilPCParagraph.php");
309  include_once("./Services/COPage/classes/class.ilPCParagraphGUI.php");
310  $data = array();
311  foreach ($_POST as $k => $content) {
312  if (substr($k, 0, 5) != "cell_") {
313  continue;
314  }
315 
316  // determine cell content
317  $div = ilUtil::stripSlashes($content, false);
318  $p1 = strpos($div, '>');
319  $div = substr($div, $p1 + 1);
320  $div = "<div class='ilc_text_block_TableContent'>" . $div;
321  $text = ilPCParagraph::handleAjaxContent($div);
322  if ($text === false) {
323  $ilCtrl->returnToParent($this, "jump" . $this->hier_id);
324  }
325  $text = $text["text"];
326 
328  $text,
329  $this->content_obj->getLanguage(),
330  true,
331  false
332  );
334 
335  // set content in data array
336  $id = explode("_", $k);
337  $data[(int) $id[1]][(int) $id[2]] = $text;
338  }
339 
340  // update data
341  $this->updated = $this->content_obj->setData($data);
342 
343  if ($this->updated !== true) {
344  $this->editData();
345  return;
346  }
347 
348  $this->updated = $this->pg_obj->update();
349 
350 
351  // perform table action? (move...?)
352  //$this->update(false);
353  $this->pg_obj->addHierIDs();
354  $failed = false;
355  if ($_POST["tab_cmd"] != "") {
356  $cell_hier_id = ($_POST["tab_cmd_type"] == "col")
357  ? $this->hier_id . "_1_" . ($_POST["tab_cmd_id"] + 1)
358  : $this->hier_id . "_" . ($_POST["tab_cmd_id"] + 1) . "_1";
359  $cell_obj = $this->pg_obj->getContentObject($cell_hier_id);
360  if (is_object($cell_obj)) {
361  $tab_cmd = $_POST["tab_cmd"];
362  $cell_obj->$tab_cmd();
363  $ret = $this->pg_obj->update();
364  if ($ret !== true) {
365  ilUtil::sendFailure($ret[0][1], true);
366  $failed = true;
367  }
368  }
369  }
370 
371  if (!$failed) {
372  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
373  }
374  if ($_POST["save_return"]) {
375  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
376  } else {
377  $this->ctrl->redirect($this, "editData");
378  }
379  }
380 
381 
385  public function getNewTableObject()
386  {
387  return new ilPCDataTable($this->getPage());
388  }
389 
393  public function afterCreation()
394  {
395  $ilCtrl = $this->ctrl;
396 
397  $this->pg_obj->stripHierIDs();
398  $this->pg_obj->addHierIDs();
399  $ilCtrl->setParameter($this, "hier_id", $this->content_obj->readHierId());
400  $ilCtrl->setParameter($this, "pc_id", $this->content_obj->readPCId());
401  $ilCtrl->redirect($this, "editData");
402  }
403 
407  public function tableAction()
408  {
409  $ilCtrl = $this->ctrl;
410 
411  $this->update(false);
412  $this->pg_obj->addHierIDs();
413 
414  $cell_hier_id = ($_POST["type"] == "col")
415  ? $this->hier_id . "_1_" . ($_POST["id"] + 1)
416  : $this->hier_id . "_" . ($_POST["id"] + 1) . "_1";
417  $cell_obj = $this->pg_obj->getContentObject($cell_hier_id);
418  if (is_object($cell_obj)) {
419  $action = (string) ($_POST["action"]);
420  $cell_obj->$action();
421  $_SESSION["il_pg_error"] = $this->pg_obj->update();
422  }
423  $ilCtrl->redirect($this, "editData");
424  }
425 
429  public function setTabs($data_tab_txt_key = "")
430  {
431  $ilCtrl = $this->ctrl;
432  $ilTabs = $this->tabs;
433 
434  parent::setTabs("cont_ed_edit_data");
435  }
436 
437  protected function getCellContent(int $i, int $j) : string
438  {
439  if (is_array($_POST["cmd"]) && key($_POST["cmd"]) == "update") {
440  $s_text = ilUtil::stripSlashes("cell_" . $i . "_" . $j, false);
441  } else {
442  $s_text = ilPCParagraph::xml2output(
443  $this->content_obj->getCellText($i, $j),
444  true,
445  false
446  );
447  include_once("./Services/COPage/classes/class.ilPCParagraphGUI.php");
449  $s_text,
450  "TableContent",
451  $this->content_obj->readPCId() . "_" . $i . "_" . $j
452  );
453  }
454 
455  // #20628
456  $s_text = str_replace("{", "&#123;", $s_text);
457  $s_text = str_replace("}", "&#125;", $s_text);
458  return $s_text;
459  }
460 }
__construct(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id="")
Constructor public.
tableAction()
Perform operation on table (adding, moving, deleting rows/cols)
editData()
Edit data of table.
getCharacteristicsOfCurrentStyle($a_type)
Get characteristics of current style.
updateJS()
Update via JavaScript.
executeCommand()
execute command
$data
Definition: storeScorm.php:23
$_SESSION["AccountId"]
xpath_new_context($dom_document)
$type
setTabs($data_tab_txt_key="")
Set tabs.
static xml2outputJS($s_text)
Prepare content for js output.
static handleAjaxContentPost($text)
Post input2xml handling of ajax content.
xpath_eval($xpath_context, $eval_str, $contextnode=null)
update($a_redirect=true)
Update table data in dom and update page in db.
getHierId()
get hierarchical id in dom object
static initConnection(ilGlobalTemplateInterface $a_main_tpl=null)
Init YUI Connection module.
static initPanel($a_resize=false, ilGlobalTemplateInterface $a_main_tpl=null)
Init yui panel.
static xml2output($a_text, $a_wysiwyg=false, $a_replace_lists=true, $unmask=true)
Converts xml from DB to output in edit textarea.
setCharacteristics($a_chars)
Set Characteristics.
getBBMenu($a_ta_name="par_content")
Get the bb menu incl.
foreach($_POST as $key=> $value) $res
afterCreation()
After creation processing.
static handleAjaxContent($a_content)
Handle ajax content.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
global $DIC
Definition: goto.php:24
displayValidationError()
display validation errors
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
Class ilPCTableGUI.
$failed
Definition: Utf8Test.php:85
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static initDragDrop(ilGlobalTemplateInterface $a_main_tpl=null)
Init YUI Drag and Drop.
editDataCl()
Edit data of table.
static _input2xml($a_text, $a_lang, $a_wysiwyg=0, $a_handle_lists=true)
converts user input to xml
getNewTableObject()
Get new table object.
__construct(Container $dic, ilPlugin $plugin)
$ret
Definition: parser.php:6
Class ilPCTableGUI.
$_POST["username"]
getCellContent(int $i, int $j)
$i
Definition: metadata.php:24
Class ilPCDataTable.