1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4/** @defgroup ServicesInfoScreen Services/InfoScreen
5 */
6
7/**
8* Class ilInfoScreenGUI
9*
10* @author Alex Killing <alex.killing@gmx.de>
11* @version $Id$
12*
13* @ilCtrl_Calls ilInfoScreenGUI: ilNoteGUI, ilColumnGUI, ilPublicUserProfileGUI
14* @ilCtrl_Calls ilInfoScreenGUI: ilCommonActionDispatcherGUI
15*
16* @ingroup ServicesInfoScreen
17*/
18class ilInfoScreenGUI
19{
20    /**
21     * @var ilTabsGUI
22     */
23    protected $tabs_gui;
24
25    /**
26     * @var ilRbacSystem
27     */
28    protected $rbacsystem;
29
30    /**
31     * @var ilTemplate
32     */
33    protected $tpl;
34
35    /**
36     * @var ilAccessHandler
37     */
38    protected $access;
39
40    /**
41     * @var ilObjUser
42     */
43    protected $user;
44
45    /**
46     * @var ilTree
47     */
48    protected $tree;
49
50    /**
51     * @var ilSetting
52     */
53    protected $settings;
54
55    public $lng;
56    public $ctrl;
57    public $gui_object;
58    public $top_buttons = array();
59    public $top_formbuttons = array();
60    public $hiddenelements = array();
61    public $table_class = "il_InfoScreen";
62    public $open_form_tag = true;
63    public $close_form_tag = true;
64
65    /**
66     * @var int|null
67     */
68    protected $contextRefId = null;
69
70    /**
71     * @var int|null
72     */
73    protected $contextObjId = null;
74
75    /**
76     * @var string|null
77     */
78    protected $contentObjType = null;
79
80    /**
81    * a form action parameter. if set a form is generated
82    */
83    public $form_action;
84
85    /**
86     * @var bool
87     */
88    protected $booking_enabled = false;
89
90    /**
91     * @var bool
92     */
93    protected $availability_enabled = true;
94
95
96    /**
97    * Constructor
98    *
99    * @param	object	$a_gui_object	GUI instance of related object
100    * 									(ilCouseGUI, ilTestGUI, ...)
101    */
102    public function __construct($a_gui_object)
103    {
104        global $DIC;
105
106        $this->rbacsystem = $DIC->rbac()->system();
107        $this->tpl = $DIC["tpl"];
108        $this->access = $DIC->access();
109        $this->user = $DIC->user();
110        $this->tree = $DIC->repositoryTree();
111        $this->settings = $DIC->settings();
112        $ilCtrl = $DIC->ctrl();
113        $lng = $DIC->language();
114        $ilTabs = $DIC->tabs();
115
116        $this->ctrl = $ilCtrl;
117        $this->lng = $lng;
118        $this->tabs_gui = $ilTabs;
119        $this->gui_object = $a_gui_object;
120        $this->sec_nr = 0;
121        $this->private_notes_enabled = false;
122        $this->news_enabled = false;
123        $this->feedback_enabled = false;
124        $this->learning_progress_enabled = false;
125        $this->form_action = "";
126        $this->top_formbuttons = array();
127        $this->hiddenelements = array();
128    }
129
130    /**
131    * execute command
132    */
133    public function executeCommand()
134    {
135        $rbacsystem = $this->rbacsystem;
136        $tpl = $this->tpl;
137        $ilAccess = $this->access;
138
139        $next_class = $this->ctrl->getNextClass($this);
140
141        $cmd = $this->ctrl->getCmd("showSummary");
142        $this->ctrl->setReturn($this, "showSummary");
143
144        $this->setTabs();
145
146        switch ($next_class) {
147            case "ilnotegui":
148                $this->showSummary();	// forwards command
149                break;
150
151            case "ilcolumngui":
152                $this->showSummary();
153                break;
154
155            case "ilpublicuserprofilegui":
156                include_once("./Services/User/classes/class.ilPublicUserProfileGUI.php");
157                $user_profile = new ilPublicUserProfileGUI($_GET["user_id"]);
158                $user_profile->setBackUrl($this->ctrl->getLinkTarget($this, "showSummary"));
159                $html = $this->ctrl->forwardCommand($user_profile);
160                $tpl->setContent($html);
161                break;
162
163            case "ilcommonactiondispatchergui":
164                include_once("Services/Object/classes/class.ilCommonActionDispatcherGUI.php");
165                $gui = ilCommonActionDispatcherGUI::getInstanceFromAjaxCall();
166                $this->ctrl->forwardCommand($gui);
167                break;
168
169            default:
170                return $this->$cmd();
171                break;
172        }
173        return true;
174    }
175
176    /**
177     * Set table class
178     *
179     * @param	string	table class
180     */
181    public function setTableClass($a_val)
182    {
183        $this->table_class = $a_val;
184    }
185
186    /**
187     * Get table class
188     *
189     * @return	string	table class
190     */
191    public function getTableClass()
192    {
193        return $this->table_class;
194    }
195
196    /**
197    * enable notes
198    */
199    public function enablePrivateNotes($a_enable = true)
200    {
201        $this->private_notes_enabled = $a_enable;
202    }
203
204    /**
205    * enable learning progress
206    */
207    public function enableLearningProgress($a_enable = true)
208    {
209        $this->learning_progress_enabled = $a_enable;
210    }
211
212    /**
213    * enable availability
214    */
215    public function enableAvailability($a_enable = true)
216    {
217        $this->availability_enabled = $a_enable;
218    }
219
220    /**
221     * booking info
222     * @param bool $a_enable
223     */
224    public function enableBookingInfo($a_enable = true)
225    {
226        $this->booking_enabled = $a_enable;
227    }
228
229
230    /**
231    * enable feedback
232    */
233    public function enableFeedback($a_enable = true)
234    {
235        $this->feedback_enabled = $a_enable;
236    }
237
238    /**
239    * enable news
240    */
241    public function enableNews($a_enable = true)
242    {
243        $this->news_enabled = $a_enable;
244    }
245
246    /**
247    * enable news editing
248    */
249    public function enableNewsEditing($a_enable = true)
250    {
251        $this->news_editing = $a_enable;
252    }
253
254    /**
255    * This function is supposed to be used for block type specific
256    * properties, that should be passed to ilBlockGUI->setProperty
257    *
258    * @param	string	$a_property		property name
259    * @param	string	$a_value		property value
260    */
261    public function setBlockProperty($a_block_type, $a_property, $a_value)
262    {
263        $this->block_property[$a_block_type][$a_property] = $a_value;
264    }
265
266    public function getAllBlockProperties()
267    {
268        return $this->block_property;
269    }
270
271    /**
272    * add a new section
273    */
274    public function addSection($a_title)
275    {
276        $this->sec_nr++;
277        $this->section[$this->sec_nr]["title"] = $a_title;
278        $this->section[$this->sec_nr]["hidden"] = (bool) $this->hidden;
279    }
280
281    /**
282    * set a form action
283    */
284    public function setFormAction($a_form_action)
285    {
286        $this->form_action = $a_form_action;
287    }
288
289    /**
290    * remove form action
291    */
292    public function removeFormAction()
293    {
294        $this->form_action = "";
295    }
296
297    /**
298    * add a property to current section
299    *
300    * @param	string	$a_name		property name string
301    * @param	string	$a_value	property value
302    * @param	string	$a_link		link (will link the property value string)
303    */
304    public function addProperty($a_name, $a_value, $a_link = "")
305    {
306        $this->section[$this->sec_nr]["properties"][] =
307            array("name" => $a_name, "value" => $a_value,
308                "link" => $a_link);
309    }
310
311    /**
312    * add a property to current section
313    */
314    public function addPropertyCheckbox($a_name, $a_checkbox_name, $a_checkbox_value, $a_checkbox_label = "", $a_checkbox_checked = false)
315    {
316        $checkbox = "<input type=\"checkbox\" name=\"$a_checkbox_name\" value=\"$a_checkbox_value\" id=\"$a_checkbox_name$a_checkbox_value\"";
317        if ($a_checkbox_checked) {
318            $checkbox .= " checked=\"checked\"";
319        }
320        $checkbox .= " />";
321        if (strlen($a_checkbox_label)) {
322            $checkbox .= "&nbsp;<label for=\"$a_checkbox_name$a_checkbox_value\">$a_checkbox_label</label>";
323        }
324        $this->section[$this->sec_nr]["properties"][] =
325            array("name" => $a_name, "value" => $checkbox);
326    }
327
328    /**
329    * add a property to current section
330    */
331    public function addPropertyTextinput($a_name, $a_input_name, $a_input_value = "", $a_input_size = "", $direct_button_command = "", $direct_button_label = "", $direct_button_primary = false)
332    {
333        $input = "<span class=\"form-inline\"><input class=\"form-control\" type=\"text\" name=\"$a_input_name\" id=\"$a_input_name\"";
334        if (strlen($a_input_value)) {
335            $input .= " value=\"" . ilUtil::prepareFormOutput($a_input_value) . "\"";
336        }
337        if (strlen($a_input_size)) {
338            $input .= " size=\"" . $a_input_size . "\"";
339        }
340        $input .= " />";
341        if (strlen($direct_button_command) && strlen($direct_button_label)) {
342            $css = "";
343            if ($direct_button_primary) {
344                $css = " btn-primary";
345            }
346            $input .= " <input type=\"submit\" class=\"btn btn-default" . $css . "\" name=\"cmd[$direct_button_command]\" value=\"$direct_button_label\" />";
347        }
348        $input .= "</span>";
349        $this->section[$this->sec_nr]["properties"][] =
350            array("name" => "<label for=\"$a_input_name\">$a_name</label>", "value" => $input);
351    }
352
353    /**
354    * add a property to current section
355    */
356    public function addButton($a_title, $a_link, $a_frame = "", $a_position = "top", $a_primary = false)
357    {
358        if ($a_position == "top") {
359            $this->top_buttons[] =
360                array("title" => $a_title,"link" => $a_link,"target" => $a_frame,"primary" => $a_primary);
361        }
362    }
363
364    /**
365    * add a form button to the info screen
366    * the form buttons are only valid if a form action is set
367    */
368    public function addFormButton($a_command, $a_title, $a_position = "top")
369    {
370        if ($a_position == "top") {
371            array_push(
372                $this->top_formbuttons,
373                array("command" => $a_command, "title" => $a_title)
374            );
375        }
376    }
377
378    public function addHiddenElement($a_name, $a_value)
379    {
380        array_push($this->hiddenelements, array("name" => $a_name, "value" => $a_value));
381    }
382
383    /**
384    * add standard meta data sections
385    */
386    public function addMetaDataSections($a_rep_obj_id, $a_obj_id, $a_type)
387    {
388        $lng = $this->lng;
389
390        $lng->loadLanguageModule("meta");
391
392        include_once("./Services/MetaData/classes/class.ilMD.php");
393        $md = new ilMD($a_rep_obj_id, $a_obj_id, $a_type);
394
395        if ($md_gen = $md->getGeneral()) {
396            // get first descrption
397            // The description is shown on the top of the page.
398            // Thus it is not necessary to show it again.
399            foreach ($md_gen->getDescriptionIds() as $id) {
400                $md_des = $md_gen->getDescription($id);
401                $description = $md_des->getDescription();
402                break;
403            }
404
405            // get language(s)
406            $langs = array();
407            foreach ($ids = $md_gen->getLanguageIds() as $id) {
408                $md_lan = $md_gen->getLanguage($id);
409                if ($md_lan->getLanguageCode() != "") {
410                    $langs[] = $lng->txt("meta_l_" . $md_lan->getLanguageCode());
411                }
412            }
413            $langs = implode(", ", $langs);
414
415            // keywords
416            $keywords = array();
417            foreach ($ids = $md_gen->getKeywordIds() as $id) {
418                $md_key = $md_gen->getKeyword($id);
419                $keywords[] = $md_key->getKeyword();
420            }
421            $keywords = implode(", ", $keywords);
422        }
423
424        // authors
425        if (is_object($lifecycle = $md->getLifecycle())) {
426            $sep = $author = "";
427            foreach (($ids = $lifecycle->getContributeIds()) as $con_id) {
428                $md_con = $lifecycle->getContribute($con_id);
429                if ($md_con->getRole() == "Author") {
430                    foreach ($ent_ids = $md_con->getEntityIds() as $ent_id) {
431                        $md_ent = $md_con->getEntity($ent_id);
432                        $author = $author . $sep . $md_ent->getEntity();
433                        $sep = ", ";
434                    }
435                }
436            }
437        }
438
439        // copyright
440        $copyright = "";
441        if (is_object($rights = $md->getRights())) {
442            include_once('Services/MetaData/classes/class.ilMDUtils.php');
443            $copyright = ilMDUtils::_parseCopyright($rights->getDescription());
444        }
445
446        // learning time
447        #if(is_object($educational = $md->getEducational()))
448        #{
449        #	$learning_time = $educational->getTypicalLearningTime();
450        #}
451        $learning_time = "";
452        if (is_object($educational = $md->getEducational())) {
453            if ($seconds = $educational->getTypicalLearningTimeSeconds()) {
454                $learning_time = ilDatePresentation::secondsToString($seconds);
455            }
456        }
457
458
459        // output
460
461        // description
462        if ($description != "") {
463            $this->addSection($lng->txt("description"));
464            $this->addProperty("", nl2br($description));
465        }
466
467        // general section
468        $this->addSection($lng->txt("meta_general"));
469        if ($langs != "") {	// language
470            $this->addProperty(
471                $lng->txt("language"),
472                $langs
473            );
474        }
475        if ($keywords != "") {	// keywords
476            $this->addProperty(
477                $lng->txt("keywords"),
478                $keywords
479            );
480        }
481        if ($author != "") {		// author
482            $this->addProperty(
483                $lng->txt("author"),
484                $author
485            );
486        }
487        if ($copyright != "") {		// copyright
488            $this->addProperty(
489                $lng->txt("meta_copyright"),
490                $copyright
491            );
492        }
493        if ($learning_time != "") {		// typical learning time
494            $this->addProperty(
495                $lng->txt("meta_typical_learning_time"),
496                $learning_time
497            );
498        }
499    }
500
501    /**
502    * add standard object section
503    */
504    public function addObjectSections()
505    {
506        $lng = $this->lng;
507        $ilCtrl = $this->ctrl;
508        $ilUser = $this->user;
509        $ilAccess = $this->access;
510        $tree = $this->tree;
511
512        // ressource bookings
513        if ($this->booking_enabled) {
514            $booking_adapter = new ilBookingInfoScreenAdapter($this);
515            $booking_adapter->add();
516        }
517
518        $this->addSection($lng->txt("additional_info"));
519        $a_obj = $this->gui_object->object;
520
521        // links to the object
522        if (is_object($a_obj)) {
523            // permanent link
524            $type = $a_obj->getType();
525            $ref_id = $a_obj->getRefId();
526
527            if ($ref_id) {
528                include_once 'Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
529                if (ilECSServerSettings::getInstance()->activeServerExists()) {
530                    $this->addProperty(
531                        $lng->txt("object_id"),
532                        $a_obj->getId()
533                        );
534                }
535
536                include_once 'Services/PermanentLink/classes/class.ilPermanentLinkGUI.php';
537                $pm = new ilPermanentLinkGUI($type, $ref_id);
538                $pm->setIncludePermanentLinkText(false);
539                $pm->setAlignCenter(false);
540                $this->addProperty(
541                    $lng->txt("perma_link"),
542                    $pm->getHTML(),
543                    ""
544                    );
545
546                // links to resource
547                if ($ilAccess->checkAccess("write", "", $ref_id) ||
548                    $ilAccess->checkAccess("edit_permissions", "", $ref_id)) {
549                    $obj_id = $a_obj->getId();
550                    $rs = ilObject::_getAllReferences($obj_id);
551                    $refs = array();
552                    foreach ($rs as $r) {
553                        if ($tree->isInTree($r)) {
554                            $refs[] = $r;
555                        }
556                    }
557                    if (count($refs) > 1) {
558                        $links = $sep = "";
559                        foreach ($refs as $r) {
560                            $cont_loc = new ilLocatorGUI();
561                            $cont_loc->addContextItems($r, true);
562                            $links .= $sep . $cont_loc->getHTML();
563                            $sep = "<br />";
564                        }
565
566                        $this->addProperty(
567                            $lng->txt("res_links"),
568                            '<div class="small">' . $links . '</div>'
569                            );
570                    }
571                }
572            }
573        }
574
575
576        // creation date
577        $this->addProperty(
578            $lng->txt("create_date"),
579            ilDatePresentation::formatDate(new ilDateTime($a_obj->getCreateDate(), IL_CAL_DATETIME))
580        );
581
582        // owner
583        if ($ilUser->getId() != ANONYMOUS_USER_ID and $a_obj->getOwner()) {
584            include_once './Services/Object/classes/class.ilObjectFactory.php';
585            include_once './Services/User/classes/class.ilObjUser.php';
586
587            if (ilObjUser::userExists(array($a_obj->getOwner()))) {
588                $ownerObj = ilObjectFactory::getInstanceByObjId($a_obj->getOwner(), false);
589            } else {
590                $ownerObj = ilObjectFactory::getInstanceByObjId(6, false);
591            }
592
593            if (!is_object($ownerObj) || $ownerObj->getType() != "usr") {		// root user deleted
594                $this->addProperty($lng->txt("owner"), $lng->txt("no_owner"));
595            } elseif ($ownerObj->hasPublicProfile()) {
596                $ilCtrl->setParameterByClass("ilpublicuserprofilegui", "user_id", $ownerObj->getId());
597                $this->addProperty($lng->txt("owner"), $ownerObj->getPublicName(), $ilCtrl->getLinkTargetByClass("ilpublicuserprofilegui", "getHTML"));
598            } else {
599                $this->addProperty($lng->txt("owner"), $ownerObj->getPublicName());
600            }
601        }
602
603        // disk usage
604        if ($ilUser->getId() != ANONYMOUS_USER_ID &&
605            ilDiskQuotaActivationChecker::_isActive()) {
606            $size = $a_obj->getDiskUsage();
607            if ($size !== null) {
608                $this->addProperty($lng->txt("disk_usage"), ilUtil::formatSize($size, 'long'));
609            }
610        }
611        // change event
612        require_once 'Services/Tracking/classes/class.ilChangeEvent.php';
613        if (ilChangeEvent::_isActive()) {
614            if ($ilUser->getId() != ANONYMOUS_USER_ID) {
615                $readEvents = ilChangeEvent::_lookupReadEvents($a_obj->getId());
616                $count_users = 0;
617                $count_members = 0;
618                $count_user_reads = 0;
619                $count_anonymous_reads = 0;
620                foreach ($readEvents as $evt) {
621                    if ($evt['usr_id'] == ANONYMOUS_USER_ID) {
622                        $count_anonymous_reads += $evt['read_count'];
623                    } else {
624                        $count_user_reads += $evt['read_count'];
625                        $count_users++;
626                        /* to do: if ($evt['user_id'] is member of $this->getRefId())
627                        {
628                            $count_members++;
629                        }*/
630                    }
631                }
632                if ($count_anonymous_reads > 0) {
633                    $this->addProperty($this->lng->txt("readcount_anonymous_users"), $count_anonymous_reads);
634                }
635                if ($count_user_reads > 0) {
636                    $this->addProperty($this->lng->txt("readcount_users"), $count_user_reads);
637                }
638                if ($count_users > 0) {
639                    $this->addProperty($this->lng->txt("accesscount_registered_users"), $count_users);
640                }
641            }
642        }
643        // END ChangeEvent: Display change event info
644
645        // WebDAV: Display locking information
646        require_once('Services/WebDAV/classes/class.ilDAVActivationChecker.php');
647        if (ilDAVActivationChecker::_isActive()) {
648            if ($ilUser->getId() != ANONYMOUS_USER_ID) {
649                require_once 'Services/WebDAV/classes/lock/class.ilWebDAVLockBackend.php';
650                $webdav_lock_backend = new ilWebDAVLockBackend();
651
652                // Show lock info
653                if ($ilUser->getId() != ANONYMOUS_USER_ID) {
654                    if ($lock = $webdav_lock_backend->getLocksOnObjectId($this->gui_object->object->getId())) {
655                        $lock_user = new ilObjUser($lock->getIliasOwner());
656                        $this->addProperty(
657                            $this->lng->txt("in_use_by"),
658                            $lock_user->getPublicName(),
659                            "./ilias.php?user=" . $lock_user->getId() . '&cmd=showUserProfile&cmdClass=ildashboardgui&cmdNode=1&baseClass=ilDashboardGUI'
660                        );
661                    }
662                }
663            }
664        }
665    }
666    // END ChangeEvent: Display standard object info
667    /**
668    * show summary page
669    */
670    public function showSummary()
671    {
672        $tpl = $this->tpl;
673        $ilAccess = $this->access;
674
675        $tpl->setContent($this->getCenterColumnHTML());
676        $tpl->setRightContent($this->getRightColumnHTML());
677    }
678
679
680    /**
681    * Display center column
682    */
683    public function getCenterColumnHTML()
684    {
685        $ilCtrl = $this->ctrl;
686
687        include_once("Services/Block/classes/class.ilColumnGUI.php");
688        $column_gui = new ilColumnGUI("info", IL_COL_CENTER);
689        $this->setColumnSettings($column_gui);
690
691        if (!$ilCtrl->isAsynch()) {
692            if ($column_gui->getScreenMode() != IL_SCREEN_SIDE) {
693                // right column wants center
694                if ($column_gui->getCmdSide() == IL_COL_RIGHT) {
695                    $column_gui = new ilColumnGUI("info", IL_COL_RIGHT);
696                    $this->setColumnSettings($column_gui);
697                    $html = $ilCtrl->forwardCommand($column_gui);
698                }
699                // left column wants center
700                if ($column_gui->getCmdSide() == IL_COL_LEFT) {
701                    $column_gui = new ilColumnGUI("info", IL_COL_LEFT);
702                    $this->setColumnSettings($column_gui);
703                    $html = $ilCtrl->forwardCommand($column_gui);
704                }
705            } else {
706                $html = $this->getHTML();
707            }
708        }
709
710        return $html;
711    }
712
713    /**
714    * Display right column
715    */
716    public function getRightColumnHTML()
717    {
718        $ilUser = $this->user;
719        $lng = $this->lng;
720        $ilCtrl = $this->ctrl;
721
722        include_once("Services/Block/classes/class.ilColumnGUI.php");
723        $column_gui = new ilColumnGUI("info", IL_COL_RIGHT);
724        $this->setColumnSettings($column_gui);
725
726        if ($ilCtrl->getNextClass() == "ilcolumngui" &&
727            $column_gui->getCmdSide() == IL_COL_RIGHT &&
728            $column_gui->getScreenMode() == IL_SCREEN_SIDE) {
729            $html = $ilCtrl->forwardCommand($column_gui);
730        } else {
731            if (!$ilCtrl->isAsynch()) {
732                if ($this->news_enabled) {
733                    $html = $ilCtrl->getHTML($column_gui);
734                }
735            }
736        }
737
738        return $html;
739    }
740
741    /**
742    * Set column settings.
743    */
744    public function setColumnSettings($column_gui)
745    {
746        $lng = $this->lng;
747        $ilAccess = $this->access;
748
749        $column_gui->setEnableEdit($this->news_editing);
750        $column_gui->setRepositoryMode(true);
751        $column_gui->setAllBlockProperties($this->getAllBlockProperties());
752    }
753
754    public function setOpenFormTag($a_val)
755    {
756        $this->open_form_tag = $a_val;
757    }
758
759    public function setCloseFormTag($a_val)
760    {
761        $this->close_form_tag = $a_val;
762    }
763
764    /**
765    * get html
766    */
767    public function getHTML()
768    {
769        $lng = $this->lng;
770        $ilSetting = $this->settings;
771        $tree = $this->tree;
772        $ilAccess = $this->access;
773        $ilCtrl = $this->ctrl;
774        $ilUser = $this->user;
775
776        $tpl = new ilTemplate("tpl.infoscreen.html", true, true, "Services/InfoScreen");
777
778        // other class handles form action (@todo: this is not implemented/tested)
779        if ($this->form_action == "") {
780            $this->setFormAction($ilCtrl->getFormAction($this));
781        }
782
783        require_once 'Services/jQuery/classes/class.iljQueryUtil.php';
784        iljQueryUtil::initjQuery();
785
786        if ($this->hidden) {
787            $tpl->touchBlock("hidden_js");
788            if ($this->show_hidden_toggle) {
789                $this->addButton($lng->txt("show_hidden_sections"), "JavaScript:toggleSections(this, '" . $lng->txt("show_hidden_sections") . "', '" . $lng->txt("hide_visible_sections") . "');");
790            }
791        }
792
793
794        // DEPRECATED - use ilToolbarGUI
795
796        // add top buttons
797        if (count($this->top_buttons) > 0) {
798            $tpl->addBlockfile("TOP_BUTTONS", "top_buttons", "tpl.buttons.html");
799
800            foreach ($this->top_buttons as $button) {
801                // view button
802                $tpl->setCurrentBlock("btn_cell");
803                $tpl->setVariable("BTN_LINK", $button["link"]);
804                $tpl->setVariable("BTN_TARGET", $button["target"]);
805                $tpl->setVariable("BTN_TXT", $button["title"]);
806                if ($button["primary"]) {
807                    $tpl->setVariable("BTN_CLASS", " btn-primary");
808                }
809                $tpl->parseCurrentBlock();
810            }
811        }
812
813        // add top formbuttons
814        if ((count($this->top_formbuttons) > 0) && (strlen($this->form_action) > 0)) {
815            $tpl->addBlockfile("TOP_FORMBUTTONS", "top_submitbuttons", "tpl.submitbuttons.html", "Services/InfoScreen");
816
817            foreach ($this->top_formbuttons as $button) {
818                // view button
819                $tpl->setCurrentBlock("btn_submit_cell");
820                $tpl->setVariable("BTN_COMMAND", $button["command"]);
821                $tpl->setVariable("BTN_NAME", $button["title"]);
822                $tpl->parseCurrentBlock();
823            }
824        }
825
826        // add form action
827        if (strlen($this->form_action) > 0) {
828            if ($this->open_form_tag) {
829                $tpl->setCurrentBlock("formtop");
830                $tpl->setVariable("FORMACTION", $this->form_action);
831                $tpl->parseCurrentBlock();
832            }
833
834            if ($this->close_form_tag) {
835                $tpl->touchBlock("formbottom");
836            }
837        }
838
839        if (count($this->hiddenelements)) {
840            foreach ($this->hiddenelements as $hidden) {
841                $tpl->setCurrentBlock("hidden_element");
842                $tpl->setVariable("HIDDEN_NAME", $hidden["name"]);
843                $tpl->setVariable("HIDDEN_VALUE", $hidden["value"]);
844                $tpl->parseCurrentBlock();
845            }
846        }
847
848        if ($this->availability_enabled) {
849            $this->addAvailability();
850        }
851
852        $this->addPreconditions();
853
854        // learning progress
855        if ($this->learning_progress_enabled and $html = $this->showLearningProgress($tpl)) {
856            $tpl->setCurrentBlock("learning_progress");
857            $tpl->setVariable("LP_TABLE", $html);
858            $tpl->parseCurrentBlock();
859        }
860
861        // notes section
862        if ($this->private_notes_enabled && !$ilSetting->get('disable_notes')) {
863            $html = $this->showNotesSection();
864            $tpl->setCurrentBlock("notes");
865            $tpl->setVariable("NOTES", $html);
866            $tpl->parseCurrentBlock();
867        }
868
869        // tagging
870        if (is_object($this->gui_object->object)) {
871            $tags_set = new ilSetting("tags");
872            if ($tags_set->get("enable") && $ilUser->getId() != ANONYMOUS_USER_ID) {
873                $this->addTagging();
874            }
875        }
876
877        if (is_object($this->gui_object->object)) {
878            $this->addObjectSections();
879        }
880
881        // render all sections
882        for ($i = 1; $i <= $this->sec_nr; $i++) {
883            if (is_array($this->section[$i]["properties"])) {
884                // section properties
885                foreach ($this->section[$i]["properties"] as $property) {
886                    if ($property["name"] != "") {
887                        if ($property["link"] == "") {
888                            $tpl->setCurrentBlock("pv");
889                            $tpl->setVariable("TXT_PROPERTY_VALUE", $property["value"]);
890                            $tpl->parseCurrentBlock();
891                        } else {
892                            $tpl->setCurrentBlock("lpv");
893                            $tpl->setVariable("TXT_PROPERTY_LVALUE", $property["value"]);
894                            $tpl->setVariable("LINK_PROPERTY_VALUE", $property["link"]);
895                            $tpl->parseCurrentBlock();
896                        }
897                        $tpl->setCurrentBlock("property_row");
898                        $tpl->setVariable("TXT_PROPERTY", $property["name"]);
899                        $tpl->parseCurrentBlock();
900                    } else {
901                        $tpl->setCurrentBlock("property_full_row");
902                        $tpl->setVariable("TXT_PROPERTY_FULL_VALUE", $property["value"]);
903                        $tpl->parseCurrentBlock();
904                    }
905                }
906
907                // section header
908                if ($this->section[$i]["hidden"]) {
909                    $tpl->setVariable("SECTION_HIDDEN", " style=\"display:none;\"");
910                    $tpl->setVariable("SECTION_ID", "hidable_" . $i);
911                } else {
912                    $tpl->setVariable("SECTION_ID", $i);
913                }
914                $tpl->setVariable("TCLASS", $this->getTableClass());
915                $tpl->setVariable("TXT_SECTION", $this->section[$i]["title"]);
916                $tpl->setCurrentBlock("row");
917                $tpl->parseCurrentBlock();
918            }
919        }
920
921        return $tpl->get();
922    }
923
924    /**
925     * @return int|null
926     */
927    public function getContextRefId() : int
928    {
929        if ($this->contextRefId !== null) {
930            return $this->contextRefId;
931        }
932
933        return $this->gui_object->object->getRefId();
934    }
935
936    /**
937     * @param int|null $contextRefId
938     */
939    public function setContextRefId(int $contextRefId)
940    {
941        $this->contextRefId = $contextRefId;
942    }
943
944    /**
945     * @return int|null
946     */
947    public function getContextObjId() : int
948    {
949        if ($this->contextObjId !== null) {
950            return $this->contextObjId;
951        }
952
953        return $this->gui_object->object->getId();
954    }
955
956    /**
957     * @param int|null $contextObjId
958     */
959    public function setContextObjId(int $contextObjId)
960    {
961        $this->contextObjId = $contextObjId;
962    }
963
964    /**
965     * @return null|string
966     */
967    public function getContentObjType() : string
968    {
969        if ($this->contentObjType !== null) {
970            return $this->contentObjType;
971        }
972
973        return $this->gui_object->object->getType();
974    }
975
976    /**
977     * @param null|string $contentObjType
978     */
979    public function setContentObjType(string $contentObjType)
980    {
981        $this->contentObjType = $contentObjType;
982    }
983
984    public function showLearningProgress($a_tpl)
985    {
986        $ilUser = $this->user;
987        $rbacsystem = $this->rbacsystem;
988
989        if (!$rbacsystem->checkAccess('read', $this->getContextRefId())) {
990            return false;
991        }
992        if ($ilUser->getId() == ANONYMOUS_USER_ID) {
993            return false;
994        }
995
996        include_once("Services/Tracking/classes/class.ilObjUserTracking.php");
997        if (!ilObjUserTracking::_enabledLearningProgress()) {
998            return false;
999        }
1000
1001        include_once './Services/Object/classes/class.ilObjectLP.php';
1002        $olp = ilObjectLP::getInstance($this->getContextObjId());
1003        if ($olp->getCurrentMode() != ilLPObjSettings::LP_MODE_MANUAL) {
1004            return false;
1005        }
1006
1007        include_once 'Services/Tracking/classes/class.ilLPMarks.php';
1008
1009        $this->lng->loadLanguageModule('trac');
1010
1011        // section header
1012        //		$a_tpl->setCurrentBlock("header_row");
1013        $a_tpl->setVariable(
1014            "TXT_SECTION",
1015            $this->lng->txt('learning_progress')
1016        );
1017        $a_tpl->parseCurrentBlock();
1018        // $a_tpl->touchBlock("row");
1019
1020        // status
1021        $i_tpl = new ilTemplate("tpl.lp_edit_manual_info_page.html", true, true, "Services/Tracking");
1022        $i_tpl->setVariable("INFO_EDITED", $this->lng->txt("trac_info_edited"));
1023        $i_tpl->setVariable("SELECT_STATUS", ilUtil::formSelect(
1024            (int) ilLPMarks::_hasCompleted(
1025                $ilUser->getId(),
1026                $this->getContextObjId()
1027        ),
1028            'lp_edit',
1029            array(0 => $this->lng->txt('trac_not_completed'),
1030                      1 => $this->lng->txt('trac_completed')),
1031            false,
1032            true
1033        ));
1034        $i_tpl->setVariable("TXT_SAVE", $this->lng->txt("save"));
1035        $a_tpl->setCurrentBlock("pv");
1036        $a_tpl->setVariable("TXT_PROPERTY_VALUE", $i_tpl->get());
1037        $a_tpl->parseCurrentBlock();
1038        $a_tpl->setCurrentBlock("property_row");
1039        $a_tpl->setVariable("TXT_PROPERTY", $this->lng->txt('trac_status'));
1040        $a_tpl->parseCurrentBlock();
1041        // $a_tpl->touchBlock("row");
1042
1043
1044        // More infos for lm's
1045        if ($this->getContentObjType() == 'lm' ||
1046            $this->getContentObjType() == 'htlm') {
1047            $a_tpl->setCurrentBlock("pv");
1048
1049            include_once 'Services/Tracking/classes/class.ilLearningProgress.php';
1050            $progress = ilLearningProgress::_getProgress($ilUser->getId(), $this->getContextObjId());
1051            if ($progress['access_time']) {
1052                $a_tpl->setVariable(
1053                    "TXT_PROPERTY_VALUE",
1054                    ilDatePresentation::formatDate(new ilDateTime($progress['access_time'], IL_CAL_UNIX))
1055                );
1056            } else {
1057                $a_tpl->setVariable(
1058                    "TXT_PROPERTY_VALUE",
1059                    $this->lng->txt('trac_not_accessed')
1060                );
1061            }
1062
1063            $a_tpl->parseCurrentBlock();
1064            $a_tpl->setCurrentBlock("property_row");
1065            $a_tpl->setVariable("TXT_PROPERTY", $this->lng->txt('trac_last_access'));
1066            $a_tpl->parseCurrentBlock();
1067            // $a_tpl->touchBlock("row");
1068
1069            // tags of all users
1070            $a_tpl->setCurrentBlock("pv");
1071            $a_tpl->setVariable(
1072                "TXT_PROPERTY_VALUE",
1073                (int) $progress['visits']
1074            );
1075            $a_tpl->parseCurrentBlock();
1076            $a_tpl->setCurrentBlock("property_row");
1077            $a_tpl->setVariable("TXT_PROPERTY", $this->lng->txt('trac_visits'));
1078            $a_tpl->parseCurrentBlock();
1079            // $a_tpl->touchBlock("row");
1080
1081
1082            if ($this->getContentObjType() == 'lm') {
1083                // tags of all users
1084                $a_tpl->setCurrentBlock("pv");
1085                $a_tpl->setVariable(
1086                    "TXT_PROPERTY_VALUE",
1087                    ilDatePresentation::secondsToString($progress['spent_seconds'])
1088                );
1089                $a_tpl->parseCurrentBlock();
1090                $a_tpl->setCurrentBlock("property_row");
1091                $a_tpl->setVariable("TXT_PROPERTY", $this->lng->txt('trac_spent_time'));
1092                $a_tpl->parseCurrentBlock();
1093                // $a_tpl->touchBlock("row");
1094            }
1095        }
1096
1097        // #10493
1098        $a_tpl->touchBlock("row");
1099    }
1100
1101    public function saveProgress($redirect = true)
1102    {
1103        $ilUser = $this->user;
1104
1105        include_once 'Services/Tracking/classes/class.ilLPMarks.php';
1106
1107        $lp_marks = new ilLPMarks($this->getContextObjId(), $ilUser->getId());
1108        $lp_marks->setCompleted((bool) $_POST['lp_edit']);
1109        $lp_marks->update();
1110
1111        require_once 'Services/Tracking/classes/class.ilLPStatusWrapper.php';
1112        ilLPStatusWrapper::_updateStatus($this->getContextObjId(), $ilUser->getId());
1113
1114        $this->lng->loadLanguageModule('trac');
1115        ilUtil::sendSuccess($this->lng->txt('trac_updated_status'), true);
1116
1117        if ($redirect) {
1118            $this->ctrl->redirect($this, ""); // #14993
1119        }
1120    }
1121
1122
1123    /**
1124    * show notes section
1125    */
1126    public function showNotesSection()
1127    {
1128        $ilAccess = $this->access;
1129        $ilSetting = $this->settings;
1130
1131        $next_class = $this->ctrl->getNextClass($this);
1132        include_once("Services/Notes/classes/class.ilNoteGUI.php");
1133        $notes_gui = new ilNoteGUI(
1134            $this->gui_object->object->getId(),
1135            0,
1136            $this->gui_object->object->getType()
1137        );
1138
1139        // global switch
1140        if ($ilSetting->get("disable_comments")) {
1141            $notes_gui->enablePublicNotes(false);
1142        } else {
1143            $ref_id = $this->gui_object->object->getRefId();
1144            $has_write = $ilAccess->checkAccess("write", "", $ref_id);
1145
1146            if ($has_write && $ilSetting->get("comments_del_tutor", 1)) {
1147                $notes_gui->enablePublicNotesDeletion(true);
1148            }
1149
1150            /* should probably be discussed further
1151            for now this will only work properly with comments settings
1152            (see ilNoteGUI constructor)
1153            */
1154            if ($has_write ||
1155                $ilAccess->checkAccess("edit_permissions", "", $ref_id)) {
1156                $notes_gui->enableCommentsSettings();
1157            }
1158        }
1159
1160        /* moved to action menu
1161        $notes_gui->enablePrivateNotes();
1162        */
1163
1164        if ($next_class == "ilnotegui") {
1165            $html = $this->ctrl->forwardCommand($notes_gui);
1166        } else {
1167            $html = $notes_gui->getNotesHTML();
1168        }
1169
1170        return $html;
1171    }
1172
1173    /**
1174     * show LDAP role group mapping info
1175     *
1176     * @access public
1177     * @param string section name. Leave empty to place this info string inside a section
1178     *
1179     */
1180    public function showLDAPRoleGroupMappingInfo($a_section = '')
1181    {
1182        if (strlen($a_section)) {
1183            $this->addSection($a_section);
1184        }
1185        include_once('Services/LDAP/classes/class.ilLDAPRoleGroupMapping.php');
1186        $ldap_mapping = ilLDAPRoleGroupMapping::_getInstance();
1187        if ($infos = $ldap_mapping->getInfoStrings($this->gui_object->object->getId())) {
1188            $info_combined = '<div style="color:green;">';
1189            $counter = 0;
1190            foreach ($infos as $info_string) {
1191                if ($counter++) {
1192                    $info_combined .= '<br />';
1193                }
1194                $info_combined .= $info_string;
1195            }
1196            $info_combined .= '</div>';
1197            $this->addProperty($this->lng->txt('applications'), $info_combined);
1198        }
1199        return true;
1200    }
1201
1202    public function setTabs()
1203    {
1204        $tpl = $this->tpl;
1205
1206        $this->getTabs($this->tabs_gui);
1207    }
1208
1209    /**
1210    * get tabs
1211    */
1212    public function getTabs(&$tabs_gui)
1213    {
1214        $rbacsystem = $this->rbacsystem;
1215        $ilUser = $this->user;
1216        $ilAccess = $this->access;
1217
1218        $next_class = $this->ctrl->getNextClass($this);
1219        $force_active = ($next_class == "ilnotegui")
1220            ? true
1221            : false;
1222
1223        $tabs_gui->addSubTabTarget(
1224            'summary',
1225            $this->ctrl->getLinkTarget($this, "showSummary"),
1226            array("showSummary", ""),
1227            get_class($this),
1228            "",
1229            $force_active
1230        );
1231    }
1232
1233
1234    /**
1235    * Add tagging
1236    */
1237    public function addTagging()
1238    {
1239        $lng = $this->lng;
1240        $ilCtrl = $this->ctrl;
1241
1242        $lng->loadLanguageModule("tagging");
1243        $tags_set = new ilSetting("tags");
1244
1245        include_once("Services/Tagging/classes/class.ilTaggingGUI.php");
1246        $tagging_gui = new ilTaggingGUI();
1247        $tagging_gui->setObject(
1248            $this->gui_object->object->getId(),
1249            $this->gui_object->object->getType()
1250        );
1251
1252        $this->addSection($lng->txt("tagging_tags"));
1253
1254        if ($tags_set->get("enable_all_users")) {
1255            $this->addProperty(
1256                $lng->txt("tagging_all_users"),
1257                $tagging_gui->getAllUserTagsForObjectHTML()
1258            );
1259        }
1260
1261        $this->addProperty(
1262            $lng->txt("tagging_my_tags"),
1263            $tagging_gui->getTaggingInputHTML()
1264        );
1265    }
1266
1267    public function saveTags()
1268    {
1269        include_once("Services/Tagging/classes/class.ilTaggingGUI.php");
1270        $tagging_gui = new ilTaggingGUI();
1271        $tagging_gui->setObject(
1272            $this->gui_object->object->getId(),
1273            $this->gui_object->object->getType()
1274        );
1275        $tagging_gui->saveInput();
1276
1277        ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'), true);
1278        $this->ctrl->redirect($this, ""); // #14993
1279
1280        // return $this->showSummary();
1281    }
1282
1283    public function hideFurtherSections($a_add_toggle = true)
1284    {
1285        $this->hidden = true;
1286        $this->show_hidden_toggle = (bool) $a_add_toggle;
1287    }
1288
1289    public function getHiddenToggleButton()
1290    {
1291        $lng = $this->lng;
1292
1293        return "<a onClick=\"toggleSections(this, '" . $lng->txt("show_hidden_sections") . "', '" . $lng->txt("hide_visible_sections") . "'); return false;\" href=\"#\">" . $lng->txt("show_hidden_sections") . "</a>";
1294    }
1295
1296
1297    /**
1298     * Add preconditions
1299     */
1300    protected function addAvailability()
1301    {
1302        if (!is_object($this->gui_object) || !is_object($this->gui_object->object)) {
1303            return;
1304        }
1305
1306        $obj = $this->gui_object->object;
1307        if ($obj->getRefId() <= 0) {
1308            return;
1309        }
1310
1311        $act = new ilObjectActivation();
1312        $act->read($obj->getRefId());
1313        if ($act->getTimingType() == ilObjectActivation::TIMINGS_ACTIVATION) {
1314            $this->lng->loadLanguageModule("rep");
1315            $this->addSection($this->lng->txt("rep_activation_availability"));
1316            $this->addAccessPeriodProperty();
1317        }
1318    }
1319
1320    /**
1321     * Add preconditions
1322     */
1323    protected function addPreconditions()
1324    {
1325        if (!is_object($this->gui_object) || !is_object($this->gui_object->object)) {
1326            return;
1327        }
1328
1329        $obj = $this->gui_object->object;
1330        if ($obj->getRefId() <= 0) {
1331            return;
1332        }
1333
1334        $conditions = ilConditionHandler::_getEffectiveConditionsOfTarget($obj->getRefId(), $obj->getId());
1335
1336        if (sizeof($conditions)) {
1337            for ($i = 0; $i < count($conditions); $i++) {
1338                $conditions[$i]['title'] = ilObject::_lookupTitle($conditions[$i]['trigger_obj_id']);
1339            }
1340            $conditions = ilUtil::sortArray($conditions, 'title', 'DESC');
1341
1342            // Show obligatory and optional preconditions seperated
1343            $this->addPreconditionSection($obj, $conditions, true);
1344            $this->addPreconditionSection($obj, $conditions, false);
1345        }
1346    }
1347
1348    protected function addPreconditionSection($obj, $conditions, $obligatory = true)
1349    {
1350        $lng = $this->lng;
1351        $tree = $this->tree;
1352
1353        $num_required = ilConditionHandler::calculateEffectiveRequiredTriggers($obj->getRefId(), $obj->getId());
1354        $num_optional_required =
1355            $num_required - count($conditions) + count(ilConditionHandler::getEffectiveOptionalConditionsOfTarget($obj->getRefId(), $obj->getId()));
1356
1357        // Check if all conditions are fullfilled
1358        $visible_conditions = array();
1359        $passed_optional = 0;
1360        foreach ($conditions as $condition) {
1361            if ($obligatory and !$condition['obligatory']) {
1362                continue;
1363            }
1364            if (!$obligatory and $condition['obligatory']) {
1365                continue;
1366            }
1367
1368            if ($tree->isDeleted($condition['trigger_ref_id'])) {
1369                continue;
1370            }
1371
1372            $ok = ilConditionHandler::_checkCondition($condition) and
1373            !ilMemberViewSettings::getInstance()->isActive();
1374
1375            if (!$ok) {
1376                $visible_conditions[] = $condition['id'];
1377            }
1378
1379            if (!$obligatory and $ok) {
1380                ++$passed_optional;
1381                // optional passed
1382                if ($passed_optional >= $num_optional_required) {
1383                    return true;
1384                }
1385            }
1386        }
1387
1388        $properties = [];
1389
1390        foreach ($conditions as $condition) {
1391            if (!in_array($condition['id'], $visible_conditions)) {
1392                continue;
1393            }
1394
1395            $missing_cond_exist = true;
1396
1397            $properties[] = [
1398                "condition" => ilConditionHandlerGUI::translateOperator(
1399                    $condition['trigger_obj_id'],
1400                    $condition['operator']
1401                    ) . ' ' . $condition['value'],
1402                "title" => ilObject::_lookupTitle($condition['trigger_obj_id']),
1403                "link" => ilLink::_getLink($condition['trigger_ref_id'])
1404            ];
1405        }
1406
1407        if (count($properties) > 0) {
1408            if ($obligatory) {
1409                $this->addSection($lng->txt("preconditions_obligatory_hint"));
1410            } else {
1411                $this->addSection(sprintf($lng->txt("preconditions_optional_hint"), $num_optional_required));
1412            }
1413
1414            foreach ($properties as $p) {
1415                $this->addProperty(
1416                    $p["condition"],
1417                    "<a href='".$p["link"]."'>".$p["title"]."</a>"
1418                );
1419            }
1420
1421        }
1422    }
1423
1424    /**
1425     * Add access period property
1426     */
1427    public function addAccessPeriodProperty() : void
1428    {
1429        $a_obj = $this->gui_object->object;
1430
1431        $this->lng->loadLanguageModule("rep");
1432        $this->lng->loadLanguageModule("crs");
1433
1434        // links to the object
1435        if (is_object($a_obj)) {
1436            $act = new ilObjectActivation();
1437            $act->read($a_obj->getRefId());
1438            if ($act->getTimingType() == ilObjectActivation::TIMINGS_ACTIVATION)
1439            {
1440                $this->addProperty(
1441                    $this->lng->txt('rep_activation_access'),
1442                    ilDatePresentation::formatPeriod(
1443                        new ilDateTime($act->getTimingStart(), IL_CAL_UNIX),
1444                        new ilDateTime($act->getTimingEnd(), IL_CAL_UNIX)
1445                    )
1446                );
1447            } else {
1448                $this->addProperty(
1449                    $this->lng->txt('rep_activation_access'),
1450                    $this->lng->txt('crs_visibility_limitless')
1451                );
1452            }
1453        }
1454    }
1455
1456}
1457