ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
PageContentGUI.php
Go to the documentation of this file.
2 
3 use ilTemplate;
4 
11 {
12 
16  private $template_file;
17 
21  private $hiddenTitle = false;
22 
26  public function __construct(string $file, bool $flag1, bool $flag2, bool $in_module = false, $vars = "DEFAULT", bool $plugin = false, bool $a_use_cache = true)
27  {
28  $this->template_file = new ilTemplate($file, $flag1, $flag2, $in_module, $vars, $plugin, $a_use_cache);
29  }
30 
31 
32  const MESSAGE_TYPE_FAILURE = 'failure';
33  const MESSAGE_TYPE_INFO = "info";
34  const MESSAGE_TYPE_SUCCESS = "success";
35  const MESSAGE_TYPE_QUESTION = "question";
39  protected static $message_types
40  = array(
41  self::MESSAGE_TYPE_FAILURE,
42  self::MESSAGE_TYPE_INFO,
43  self::MESSAGE_TYPE_SUCCESS,
44  self::MESSAGE_TYPE_QUESTION,
45  );
46  // Not used (derived from old ilGlobalTemplate)
47  private $tree_flat_link;
49  private $show_footer;
50  private $main_menu;
52  private $js_files;
53  private $js_files_vp;
54  private $js_files_batch;
55  private $css_files;
56  private $inline_css;
57  private $tree_flat_mode;
58  private $body_class;
59  private $on_load_code;
60  // needed for content-area
62  private $permanent_link;
63  private $main_content;
64  private $lightbox = [];
66  private $message;
68  private $title;
69  private $title_desc;
70  private $title_alerts;
71  private $header_action;
72  private $tabs_html;
73  private $sub_tabs_html;
77  private $right_content;
78  private $left_content;
79  private $icon_path;
80  private $icon_desc;
82  private $filter;
83  private $banner;
84  //
85  // Needed Methods for communication from the outside
86  //
87 
96  public function addBlockFile($var, $block, $tplname, $in_module = false)
97  {
98  return $this->template_file->addBlockFile($var, $block, $tplname, $in_module);
99  }
100 
101 
107  public function blockExists($blockname)
108  {
109  return $this->template_file->blockExists($blockname);
110  }
111 
112 
116  public function removeBlockData($block)
117  {
118  $this->template_file->removeBlockData($block);
119  }
120 
121 
126  public function setVariable($variable, $value = '')
127  {
128  $this->template_file->setVariable($variable, $value);
129  }
130 
131 
135  public function setCurrentBlock($part = "DEFAULT")
136  {
137  $this->template_file->setCurrentBlock($part);
138  }
139 
140 
144  public function touchBlock($block)
145  {
146  $this->template_file->touchBlock($block);
147  }
148 
149 
153  public function parseCurrentBlock($part = "DEFAULT")
154  {
155  $this->template_file->parseCurrentBlock($part);
156  }
157 
158 
159 
160 
161 
162 
163 
164 
165 
166  //
167  // BEGIN needed Setters
168  //
169 
174  {
175  $this->page_form_action = $page_form_action;
176  }
177 
178 
183  {
184  $this->permanent_link = $permanent_link;
185  }
186 
187 
191  public function setMainContent($main_content)
192  {
193  $this->main_content = $main_content;
194  }
195 
196 
201  public function addLightbox($a_html, $a_id)
202  {
203  $this->lightbox[$a_id] = $a_html;
204  }
205 
206 
211  {
212  $this->header_page_title = $header_page_title;
213  }
214 
220  public function setBanner($a_val)
221  {
222  $this->banner = $a_val;
223  }
224 
230  public function getBanner()
231  {
232  return $this->banner;
233  }
234 
235 
240  public function setTitle($title, bool $hidden = false)
241  {
242  $this->title = $title;
243  $this->hiddenTitle = $hidden;
244  }
245 
246 
250  public function setTitleDesc($title_desc)
251  {
252  $this->title_desc = $title_desc;
253  }
254 
255 
259  public function setTitleAlerts($title_alerts)
260  {
261  $this->title_alerts = $title_alerts;
262  }
263 
264 
269  {
270  $this->header_action = $header_action;
271  }
272 
273 
278  {
279  $this->admin_panel_commands_toolbar = $admin_panel_commands_toolbar;
280  }
281 
282 
287  {
288  $this->admin_panel_arrow = $admin_panel_arrow;
289  }
290 
291 
296  {
297  $this->admin_panel_bottom = $admin_panel_bottom;
298  }
299 
300 
304  public function setRightContent($a_html)
305  {
306  $this->right_content = $a_html;
307  }
308 
309 
313  public function setLeftContent($left_content)
314  {
315  $this->left_content = $left_content;
316  }
317 
318 
322  public function setFilter(string $filter)
323  {
324  $this->filter = $filter;
325  }
326 
327 
328  private function fillFilter()
329  {
330  if (trim($this->filter) != "") {
331  $this->template_file->setCurrentBlock("filter");
332  $this->template_file->setVariable("FILTER", $this->filter);
333  $this->template_file->parseCurrentBlock();
334  }
335  }
336 
337 
341  public function setIconPath($icon_path)
342  {
343  $this->icon_path = $icon_path;
344  }
345 
346 
350  public function setIconDesc($icon_desc)
351  {
352  $this->icon_desc = $icon_desc;
353  }
354 
355 
360  {
361  $this->enable_fileupload = $enable_fileupload;
362  }
363 
364 
376  public function setOnScreenMessage($a_type, $a_txt, $a_keep = false)
377  {
378  if (!in_array($a_type, self::$message_types) || $a_txt == "") {
379  return;
380  }
381  if (!$a_keep) {
382  $this->message[$a_type] = $a_txt;
383  } else {
384  $_SESSION[$a_type] = $a_txt;
385  }
386  }
387 
388 
389  //
390  // END needed Setters
391  //
392 
393  public function renderPage($part, $a_fill_tabs, $a_skip_main_menu) : string
394  {
395  //
396  // Copied from old ilGlobalTemplate and modified
397  //
398  $this->fillMessage();
399 
400  // display ILIAS footer
401  // if ($part !== false) {
402  // $this->fillFooter();
403  // }
404 
405  // set standard parts (tabs and title icon)
406  // $this->fillBodyClass();
407 
408  // see #22992
409  // $this->fillContentLanguage();
410 
411  $this->fillPageFormAction();
412 
413  if ($a_fill_tabs) {
414  if ($this->template_file->blockExists("content")) {
415  // determine default screen id
416  $this->getTabsHTML();
417  }
418 
419  // to get also the js files for the main menu
420  if (!$a_skip_main_menu) {
421  // $this->getMainMenu();
422  //$this->initHelp();
423  }
424 
425  //$this->initHelp();
426 
427  // these fill blocks in tpl.main.html
428  // $this->fillCssFiles();
429  // $this->fillInlineCss();
430  //$this->fillJavaScriptFiles();
431 
432  // these fill just plain placeholder variables in tpl.main.html
433  // $this->setCurrentBlock("DEFAULT");
434  // $this->fillNewContentStyle();
435  // $this->fillWindowTitle();
436 
437  // these fill blocks in tpl.adm_content.html
438  $this->fillHeader();
439  // $this->fillSideIcons();
440  // $this->fillScreenReaderFocus(); // TODO
441  $this->fillLeftContent();
442  // $this->fillLeftNav();
443  $this->fillRightContent();
444  $this->fillAdminPanel();
445  $this->fillToolbar();
446  $this->fillFilter();
447  // $this->fillPermanentLink(); //TODO
448 
449  $this->setCenterColumnClass();
450 
451  // late loading of javascipr files, since operations above may add files
452  // $this->fillJavaScriptFiles();
453  // $this->fillOnLoadCode();
454 
455  // these fill just plain placeholder variables in tpl.adm_content.html
456  if ($this->template_file->blockExists("content")) {
457  $this->template_file->setCurrentBlock("content");
458  $this->fillTabs();
459  $this->fillMainContent();
460  // $this->fillMainMenu();
461  $this->fillLightbox();
462  $this->template_file->parseCurrentBlock();
463  }
464  }
465 
466  if ($part == "DEFAULT" or is_bool($part)) {
467  $html = $this->template_file->getUnmodified();
468  } else {
469  $html = $this->template_file->getUnmodified($part);
470  }
471 
472  global $DIC;
473 
474  // Modification of html is done inline here and can't be done
475  // by ilTemplate, because the "phase" is template_show in this
476  // case here.
477  $ilPluginAdmin = $DIC["ilPluginAdmin"];
478  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_SERVICE, "UIComponent", "uihk");
479  foreach ($pl_names as $pl) {
480  $ui_plugin = \ilPluginAdmin::getPluginObject(IL_COMP_SERVICE, "UIComponent", "uihk", $pl);
481  $gui_class = $ui_plugin->getUIClassInstance();
482 
483  $resp = $gui_class->getHTML(
484  "",
485  "template_show",
486  array("tpl_id" => $this->tplIdentifier, "tpl_obj" => $this, "html" => $html)
487  );
488 
489  if ($resp["mode"] != \ilUIHookPluginGUI::KEEP) {
490  $html = $gui_class->modifyHTML($html, $resp);
491  }
492  }
493 
494  // save language usages as late as possible
496 
497  return $html;
498  }
499 
500 
501  private function fillMessage()
502  {
503  global $DIC;
504 
505  $out = "";
506 
507  foreach (self::$message_types as $m) {
508  $txt = $this->getMessageTextForType($m);
509 
510  if ($txt != "") {
512  }
513 
514  $request = $DIC->http()->request();
515  $accept_header = $request->getHeaderLine('Accept');
516  if (isset($_SESSION[$m]) && $_SESSION[$m] && ($accept_header !== 'application/json')) {
517  unset($_SESSION[$m]);
518  }
519  }
520 
521  if ($out != "") {
522  $this->template_file->setVariable("MESSAGE", $out);
523  }
524  }
525 
526 
532  private function getMessageTextForType($m)
533  {
534  $txt = "";
535  if (isset($_SESSION[$m]) && $_SESSION[$m] != "") {
536  $txt = $_SESSION[$m];
537  } else {
538  if (isset($this->message[$m])) {
539  $txt = $this->message[$m];
540  }
541  }
542 
543  return $txt;
544  }
545 
546 
547  private function getTabsHTML()
548  {
549  global $DIC;
550 
551  $ilTabs = $DIC["ilTabs"];
552 
553  if ($this->template_file->blockExists("tabs_outer_start")) {
554  $this->sub_tabs_html = $ilTabs->getSubTabHTML();
555  $this->tabs_html = $ilTabs->getHTML(true);
556  }
557  }
558 
559 
563  private function initHelp()
564  {
565  include_once("./Services/Help/classes/class.ilHelpGUI.php");
566  //\ilHelpGUI::initHelp($this);
567  }
568 
569 
570  private function fillHeader()
571  {
572  global $DIC;
573 
574  $lng = $DIC->language();
575 
576 
577  if ($this->banner != "" && $this->template_file->blockExists("banner_bl")) {
578  $this->template_file->setCurrentBlock("banner_bl");
579  $this->template_file->setVariable("BANNER_URL", $this->banner);
580  $header = true;
581  $this->template_file->parseCurrentBlock();
582  }
583 
584 
585  $icon = false;
586  if ($this->icon_path != "") {
587  $icon = true;
588  $this->template_file->setCurrentBlock("header_image");
589  if ($this->icon_desc != "") {
590  $this->template_file->setVariable("IMAGE_DESC", $lng->txt("icon") . " " . $this->icon_desc);
591  $this->template_file->setVariable("IMAGE_ALT", $lng->txt("icon") . " " . $this->icon_desc);
592  }
593 
594  $this->template_file->setVariable("IMG_HEADER", $this->icon_path);
595  $this->template_file->parseCurrentBlock();
596  $header = true;
597  }
598 
599  if ($this->title != "") {
600  $title = \ilUtil::stripScriptHTML($this->title);
601  $this->template_file->setVariable("HEADER", $title);
602  if ($this->hiddenTitle) {
603  $this->template_file->touchBlock("hidden_title");
604  }
605 
606  $header = true;
607  }
608 
609  if ($header && !$this->hiddenTitle) {
610  $this->template_file->setCurrentBlock("header_image");
611  $this->template_file->parseCurrentBlock();
612  }
613 
614  if ($this->title_desc != "") {
615  $this->template_file->setCurrentBlock("header_desc");
616  $this->template_file->setVariable("H_DESCRIPTION", $this->title_desc);
617  $this->template_file->parseCurrentBlock();
618  }
619 
620  $header = $this->header_action;
621  if ($header) {
622  $this->template_file->setCurrentBlock("head_action_inner");
623  $this->template_file->setVariable("HEAD_ACTION", $header);
624  $this->template_file->parseCurrentBlock();
625  }
626 
627  if (count((array) $this->title_alerts)) {
628  foreach ($this->title_alerts as $alert) {
629  $this->template_file->setCurrentBlock('header_alert');
630  if (!($alert['propertyNameVisible'] === false)) {
631  $this->template_file->setVariable('H_PROP', $alert['property'] . ':');
632  }
633  $this->template_file->setVariable('H_VALUE', $alert['value']);
634  $this->template_file->parseCurrentBlock();
635  }
636  }
637 
638  // add file upload drop zone in header
639  if ($this->enable_fileupload != null) {
640  $ref_id = $this->enable_fileupload;
641  $upload_id = "dropzone_" . $ref_id;
642 
643  include_once("./Services/FileUpload/classes/class.ilFileUploadGUI.php");
644  $upload = new \ilFileUploadGUI($upload_id, $ref_id, true);
645 
646  $this->template_file->setVariable("FILEUPLOAD_DROPZONE_ID", " id=\"$upload_id\"");
647 
648  $this->template_file->setCurrentBlock("header_fileupload");
649  $this->template_file->setVariable("HEADER_FILEUPLOAD_SCRIPT", $upload->getHTML());
650  $this->template_file->parseCurrentBlock();
651  }
652  }
653 
654 
655  private function setCenterColumnClass()
656  {
657  if (!$this->template_file->blockExists("center_col_width")) {
658  return;
659  }
660  $center_column_class = "";
661  if (trim($this->right_content) != "" && trim($this->left_content) != "") {
662  $center_column_class = "two_side_col";
663  } else {
664  if (trim($this->right_content) != "" || trim($this->left_content) != "") {
665  $center_column_class = "one_side_col";
666  }
667  }
668 
669  switch ($center_column_class) {
670  case "one_side_col":
671  $center_column_class = "col-sm-9";
672  break;
673  case "two_side_col":
674  $center_column_class = "col-sm-6";
675  break;
676  default:
677  $center_column_class = "col-sm-12";
678  break;
679  }
680  if (trim($this->left_content) != "") {
681  $center_column_class .= " col-sm-push-3";
682  }
683 
684  $this->template_file->setCurrentBlock("center_col_width");
685  $this->template_file->setVariable("CENTER_COL", $center_column_class);
686  $this->template_file->parseCurrentBlock();
687  }
688 
689 
690  private function fillMainContent()
691  {
692  if (trim($this->main_content) != "") {
693  $this->template_file->setVariable("ADM_CONTENT", $this->main_content);
694  }
695  }
696 
697 
698  private function fillLeftContent()
699  {
700  if (trim($this->left_content) != "") {
701  $this->template_file->setCurrentBlock("left_column");
702  $this->template_file->setVariable("LEFT_CONTENT", $this->left_content);
703  $left_col_class = (trim($this->right_content) == "")
704  ? "col-sm-3 col-sm-pull-9"
705  : "col-sm-3 col-sm-pull-6";
706  $this->template_file->setVariable("LEFT_COL_CLASS", $left_col_class);
707  $this->template_file->parseCurrentBlock();
708  }
709  }
710 
711 
712  private function fillRightContent()
713  {
714  if (trim($this->right_content) != "") {
715  $this->template_file->setCurrentBlock("right_column");
716  $this->template_file->setVariable("RIGHT_CONTENT", $this->right_content);
717  $this->template_file->parseCurrentBlock();
718  }
719  }
720 
721 
722  private function fillAdminPanel()
723  {
724  global $DIC;
725  $lng = $DIC->language();
726 
727  if ($this->admin_panel_commands_toolbar === null) {
728  return;
729  }
730 
732  assert($toolb instanceof \ilToolbarGUI);
733 
734  // Add arrow if desired.
735  if ($this->admin_panel_arrow) {
736  $toolb->setLeadingImage(\ilUtil::getImagePath("arrow_upright.svg"), $lng->txt("actions"));
737  }
738 
739  $this->fillPageFormAction();
740 
741  // Add top admin bar.
742  $this->template_file->setCurrentBlock("adm_view_components");
743  $this->template_file->setVariable("ADM_PANEL1", $toolb->getHTML());
744  $this->template_file->parseCurrentBlock();
745 
746  // Add bottom admin bar if user wants one.
747  if ($this->admin_panel_bottom) {
748  $this->template_file->setCurrentBlock("adm_view_components2");
749 
750  // Replace previously set arrow image.
751  if ($this->admin_panel_arrow) {
752  $toolb->setLeadingImage(\ilUtil::getImagePath("arrow_downright.svg"), $lng->txt("actions"));
753  }
754  $toolb->setId($toolb->getId() . "2");
755  $this->template_file->setVariable("ADM_PANEL2", $toolb->getHTML());
756  $this->template_file->parseCurrentBlock();
757  }
758  }
759 
760 
761  private function fillPageFormAction()
762  {
763  if ($this->page_form_action != "") {
764  $this->template_file->setCurrentBlock("page_form_start");
765  $this->template_file->setVariable("PAGE_FORM_ACTION", $this->page_form_action);
766  $this->template_file->parseCurrentBlock();
767  $this->template_file->touchBlock("page_form_end");
768  }
769  }
770 
771 
772  private function fillToolbar()
773  {
774  global $DIC;
775 
776  $ilToolbar = $DIC["ilToolbar"];
777  ;
778 
779  $thtml = $ilToolbar->getHTML();
780  if ($thtml != "") {
781  $this->template_file->setCurrentBlock("toolbar_buttons");
782  $this->template_file->setVariable("BUTTONS", $thtml);
783  $this->template_file->parseCurrentBlock();
784  }
785  }
786 
787 
788  private function fillTabs()
789  {
790  if ($this->template_file->blockExists("tabs_outer_start")) {
791  $this->template_file->touchBlock("tabs_outer_start");
792  $this->template_file->touchBlock("tabs_outer_end");
793  $this->template_file->touchBlock("tabs_inner_start");
794  $this->template_file->touchBlock("tabs_inner_end");
795 
796  if ($this->tabs_html != "") {
797  $this->template_file->setVariable("TABS", $this->tabs_html);
798  }
799  $this->template_file->setVariable("SUB_TABS", $this->sub_tabs_html);
800  }
801  }
802 
803 
804  private function fillLightbox()
805  {
806  $this->template_file->setVariable('LIGHTBOX', implode('', $this->lightbox));
807  }
808 }
$_SESSION["AccountId"]
static getSystemMessageHTML($a_txt, $a_type="info")
Get HTML for a system message.
static stripScriptHTML($a_str, $a_allow="", $a_rm_js=true)
strip only html tags (4.0) from text $allowed contains tags to be allowed, in format tags a and b ar...
setOnScreenMessage($a_type, $a_txt, $a_keep=false)
Set a message to be displayed to the user.
$lng
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
static getPluginObject($a_ctype, $a_cname, $a_slot_id, $a_pname)
Get Plugin Object.
$txt
Definition: error.php:13
__construct(string $file, bool $flag1, bool $flag2, bool $in_module=false, $vars="DEFAULT", bool $plugin=false, bool $a_use_cache=true)
static _saveUsages()
Store the collected language variable usages in the user session This should be called as late as pos...
filter()
Definition: filter.php:2
const IL_COMP_SERVICE