1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5/**
6* User Interface Class for Navigation History
7*
8* @author Alex Killing <alex.killing@gmx.de>
9* @version $Id$
10*
11* @ilCtrl_Calls ilNavigationHistoryGUI:
12*/
13class ilNavigationHistoryGUI
14{
15    /**
16     * @var ilCtrl
17     */
18    protected $ctrl;
19
20    /**
21     * @var ilNavigationHistory
22     */
23    protected $nav_history;
24
25    /**
26     * @var ilLanguage
27     */
28    protected $lng;
29
30
31    private $items;
32
33    /**
34     * Constructor.
35     *
36     */
37    public function __construct()
38    {
39        global $DIC;
40
41        $this->ctrl = $DIC->ctrl();
42        $this->nav_history = $DIC["ilNavigationHistory"];
43        $this->lng = $DIC->language();
44    }
45
46    /**
47     * Execute command
48     */
49    public function executeCommand()
50    {
51        $ilCtrl = $this->ctrl;
52
53        $next_class = $ilCtrl->getNextClass();
54        $cmd = $ilCtrl->getCmd();
55
56        switch ($next_class) {
57            default:
58                $this->$cmd();
59                break;
60        }
61    }
62
63    /**
64    * Get HTML for navigation history
65    */
66    public function getHTML()
67    {
68        $ilNavigationHistory = $this->nav_history;
69        $lng = $this->lng;
70
71        include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
72        $selection = new ilAdvancedSelectionListGUI();
73        $selection->setFormSelectMode(
74            "url_ref_id",
75            "ilNavHistorySelect",
76            true,
77            "goto.php?target=navi_request",
78            "ilNavHistory",
79            "ilNavHistoryForm",
80            "_top",
81            $lng->txt("go"),
82            "ilNavHistorySubmit"
83        );
84        $selection->setListTitle($lng->txt("last_visited"));
85        $selection->setId("lastvisited");
86        $selection->setSelectionHeaderClass("MMInactive");
87        $selection->setHeaderIcon(ilAdvancedSelectionListGUI::NO_ICON);
88        $selection->setItemLinkClass("small");
89        $selection->setUseImages(true);
90        include_once("./Services/Accessibility/classes/class.ilAccessKey.php");
91        $selection->setAccessKey(ilAccessKey::LAST_VISITED);
92
93        $items = $ilNavigationHistory->getItems();
94        //$sel_arr = array(0 => "-- ".$lng->txt("last_visited")." --");
95        reset($items);
96        $cnt = 0;
97        foreach ($items as $k => $item) {
98            if ($cnt++ > 20) {
99                break;
100            }
101            if (!isset($item["ref_id"]) || !isset($_GET["ref_id"]) ||
102                $item["ref_id"] != $_GET["ref_id"] || $k > 0) {			// do not list current item
103                $obj_id = ilObject::_lookupObjId($item["ref_id"]);
104                $selection->addItem(
105                    $item["title"],
106                    $item["ref_id"],
107                    $item["link"],
108                    ilObject::_getIcon($obj_id, "tiny", $item["type"]),
109                    $lng->txt("obj_" . $item["type"]),
110                    "_top"
111                );
112            }
113        }
114        $html = $selection->getHTML();
115
116        if ($html == "") {
117            $selection->addItem(
118                $lng->txt("no_items"),
119                "",
120                "#",
121                "",
122                "",
123                "_top"
124            );
125            $selection->setUseImages(false);
126            $html = $selection->getHTML();
127        }
128        return $html;
129    }
130
131    /**
132    * Handle navigation request
133    */
134    public function handleNavigationRequest()
135    {
136        $ilNavigationHistory = $this->nav_history;
137        $ilCtrl = $this->ctrl;
138
139        if ($_GET["target"] == "navi_request") {
140            $items = $ilNavigationHistory->getItems();
141            foreach ($items as $item) {
142                if ($item["ref_id"] == $_POST["url_ref_id"]) {
143                    ilUtil::redirect($item["link"]);
144                }
145            }
146            reset($items);
147            $item = current($items);
148            if ($_POST["url_ref_id"] == 0 && $item["ref_id"] == $_GET["ref_id"]) {
149                $item = next($items);		// omit current item
150            }
151            if ($_POST["url_ref_id"] == 0 && $item["link"] != "") {
152                ilUtil::redirect($item["link"]);
153            }
154
155            $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", "");
156            $ilCtrl->setParameterByClass("ilrepositorygui", "getlast", "true");
157            $ilCtrl->redirectByClass("ilrepositorygui", "frameset");
158        }
159    }
160
161    /**
162     * Remove all entries form list
163     *
164     * @param
165     * @return
166     */
167    public function removeEntries()
168    {
169        $ilNavigationHistory = $this->nav_history;
170
171        $ilNavigationHistory->deleteDBEntries();
172        $ilNavigationHistory->deleteSessionEntries();
173    }
174}
175