1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once("class.ilCloudPluginGUI.php");
5
6/**
7 * Class ilCloudPluginInitGUI
8 *
9 * GUI Class for initialization of the object. Can be extended if needed.
10 *
11 * @author  Timon Amstutz timon.amstutz@ilub.unibe.ch
12 * @version $Id$
13 * @extends ilCloudPluginGUI
14 * @ingroup ModulesCloud
15 */
16class ilCloudPluginInitGUI extends ilCloudPluginGUI
17{
18
19    /**
20     * @var ilObjCloudGUI
21     */
22    protected $gui_class = null;
23    /**
24     * @var bool
25     */
26    protected $perm_upload_items = false;
27    /**
28     * @var bool
29     */
30    protected $perm_create_folders = false;
31    /**
32     * @var bool
33     */
34    protected $perm_delete_files = false;
35    /**
36     * @var bool
37     */
38    protected $perm_delete_folders = false;
39    /**
40     * @var bool
41     */
42    protected $perm_download = false;
43    /**
44     * @var bool
45     */
46    protected $perm_files_visible = false;
47    /**
48     * @var bool
49     */
50    protected $perm_folders_visible = false;
51
52
53    /**
54     * @param \ilObjCloudGUI $gui_class
55     */
56    public function setGuiClass($gui_class)
57    {
58        $this->gui_class = $gui_class;
59    }
60
61
62    /**
63     * @return \ilObjCloudGUI
64     */
65    public function getGuiClass()
66    {
67        return $this->gui_class;
68    }
69
70
71    /**
72     * @param boolean $perm_create_folders
73     */
74    public function setPermCreateFolders($perm_create_folders)
75    {
76        $this->perm_create_folders = $perm_create_folders;
77    }
78
79
80    /**
81     * @return boolean
82     */
83    public function getPermCreateFolders()
84    {
85        return $this->perm_create_folders;
86    }
87
88
89    /**
90     * @param boolean $perm_delete_files
91     */
92    public function setPermDeleteFiles($perm_delete_files)
93    {
94        $this->perm_delete_files = $perm_delete_files;
95    }
96
97
98    /**
99     * @return boolean
100     */
101    public function getPermDeleteFiles()
102    {
103        return $this->perm_delete_files;
104    }
105
106
107    /**
108     * @param boolean $perm_delete_folders
109     */
110    public function setPermDeleteFolders($perm_delete_folders)
111    {
112        $this->perm_delete_folders = $perm_delete_folders;
113    }
114
115
116    /**
117     * @return boolean
118     */
119    public function getPermDeleteFolders()
120    {
121        return $this->perm_delete_folders;
122    }
123
124
125    /**
126     * @param boolean $perm_download
127     */
128    public function setPermDownload($perm_download)
129    {
130        $this->perm_download = $perm_download;
131    }
132
133
134    /**
135     * @return boolean
136     */
137    public function getPermDownload()
138    {
139        return $this->perm_download;
140    }
141
142
143    /**
144     * @param boolean $perm_files_visible
145     */
146    public function setPermFilesVisible($perm_files_visible)
147    {
148        $this->perm_files_visible = $perm_files_visible;
149    }
150
151
152    /**
153     * @return boolean
154     */
155    public function getPermFilesVisible()
156    {
157        return $this->perm_files_visible;
158    }
159
160
161    /**
162     * @param boolean $perm_folders_visible
163     */
164    public function setPermFoldersVisible($perm_folders_visible)
165    {
166        $this->perm_folders_visible = $perm_folders_visible;
167    }
168
169
170    /**
171     * @return boolean
172     */
173    public function getPermFoldersVisible()
174    {
175        return $this->perm_folders_visible;
176    }
177
178
179    /**
180     * @param boolean $perm_upload_items
181     */
182    public function setPermUploadItems($perm_upload_items)
183    {
184        $this->perm_upload_items = $perm_upload_items;
185    }
186
187
188    /**
189     * @return boolean
190     */
191    public function getPermUploadItems()
192    {
193        return $this->perm_upload_items;
194    }
195
196
197    /**
198     * @param \ilTemplate $tpl_file_tree
199     */
200    public function setTplFileTree($tpl_file_tree)
201    {
202        $this->tpl_file_tree = $tpl_file_tree;
203    }
204
205
206    /**
207     * @return \ilTemplate
208     */
209    public function getTplFileTree()
210    {
211        return $this->tpl_file_tree;
212    }
213
214
215    /**
216     * @var ilTemplate
217     */
218    protected $tpl_file_tree = null;
219
220
221    /**
222     * @param ilObjCloudGUI $gui_class
223     * @param               $perm_create_folder
224     * @param               $perm_upload_items
225     * @param               $perm_delete_files
226     * @param               $perm_delete_folders
227     * @param               $perm_download
228     * @param               $perm_files_visible
229     * @param               $perm_folders_visible
230     */
231    public function initGUI(ilObjCloudGUI $gui_class, $perm_create_folder, $perm_upload_items, $perm_delete_files, $perm_delete_folders, $perm_download, $perm_files_visible, $perm_folders_visible)
232    {
233        global $DIC;
234        $ilTabs = $DIC['ilTabs'];
235        $lng = $DIC['lng'];
236        $tpl = $DIC['tpl'];
237
238        $ilTabs->activateTab("content");
239
240        $this->setGuiClass($gui_class);
241        $this->setPermUploadItems($perm_upload_items);
242        $this->setPermCreateFolders($perm_create_folder);
243        $this->setPermDeleteFiles($perm_delete_files);
244        $this->setPermDeleteFolders($perm_delete_folders);
245        $this->setPermDownload($perm_download);
246        $this->setPermFilesVisible($perm_files_visible);
247        $this->setPermFoldersVisible($perm_folders_visible);
248
249        try {
250            ilCloudConnector::checkServiceActive($this->getGUIClass()->object->getServiceName());
251            $this->beforeInitGUI();
252
253            //if($this->getPluginObject()->getAsyncDrawing())
254            {
255                $tpl->addJavaScript("./Modules/Cloud/js/ilCloudFileList.js");
256                $tpl->addJavaScript("./Modules/Cloud/js/jquery.address.js");
257                $tpl->addJavascript("./Services/UIComponent/AdvancedSelectionList/js/AdvancedSelectionList.js");
258                $tpl->addCss("./Modules/Cloud/templates/css/cloud.css");
259
260                include_once("./Services/YUI/classes/class.ilYuiUtil.php");
261                ilYuiUtil::initConnection();
262
263                $this->tpl_file_tree = new ilTemplate("tpl.cloud_file_tree.html", true, true, "Modules/Cloud");
264
265                $file_tree = new ilCloudFileTree(
266                    $this->getGUIClass()->object->getRootFolder(),
267                    $this->getGUIClass()->object->getRootId(),
268                    $this->getGUIClass()->object->getId(),
269                    $this->getGUIClass()->object->getServiceName()
270                );
271                $file_tree->storeFileTreeToSession();
272
273                $this->addToolbar($file_tree->getRootNode());
274
275                $this->tpl_file_tree->setVariable("ASYNC_GET_BLOCK", json_encode($this->getGUIClass()->getCtrl()->getLinkTargetByClass("ilobjcloudgui", "asyncGetBlock", true)));
276                $this->tpl_file_tree->setVariable("ASYNC_CREATE_FOLDER", json_encode($this->getGUIClass()->getCtrl()->getLinkTargetByClass("ilcloudplugincreatefoldergui", "asyncCreateFolder", true)));
277                $this->tpl_file_tree->setVariable("ASYNC_UPLOAD_FILE", json_encode($this->getGUIClass()->getCtrl()->getLinkTargetByClass("ilcloudpluginuploadgui", "asyncUploadFile", true)));
278                $this->tpl_file_tree->setVariable("ASYNC_DELETE_ITEM", json_encode($this->getGUIClass()->getCtrl()->getLinkTargetByClass("ilcloudplugindeletegui", "asyncDeleteItem", true)));
279                $this->tpl_file_tree->setVariable("ROOT_ID", json_encode($file_tree->getRootNode()->getId()));
280                $this->tpl_file_tree->setVariable("ROOT_PATH", json_encode($file_tree->getRootNode()->getPath()));
281                if (isset($_POST["path"])) {
282                    $this->tpl_file_tree->setVariable("CURRENT_PATH", json_encode($_POST["path"]));
283                    $file_tree->updateFileTree($_POST["path"]);
284                    $node = $file_tree->getNodeFromPath($_POST["path"]);
285                    $this->tpl_file_tree->setVariable("CURRENT_ID", json_encode($node->getId()));
286                } else {
287                    $this->tpl_file_tree->setVariable("CURRENT_PATH", json_encode($file_tree->getRootNode()->getPath()));
288                    $this->tpl_file_tree->setVariable("CURRENT_ID", json_encode($file_tree->getRootNode()->getID()));
289                }
290                $txt_max_file_size = $lng->txt("file_notice") . " "
291                    . ilCloudConnector::getPluginClass($this->getGUIClass()->object->getServiceName(), $this->getGUIClass()->object->getId())
292                        ->getMaxFileSize() . " MB";
293                $this->tpl_file_tree->setVariable("MAX_FILE_SIZE", json_encode($txt_max_file_size));
294                $this->beforeSetContent();
295                $tpl->setContent($this->tpl_file_tree->get());
296                $tpl->setPermanentLink("cld", $this->getGuiClass()->object->getRefId(), "_path__endPath");
297            }
298
299            /**
300             * else
301             * {
302             * $file_tree = ilCloudFileTree::getFileTreeFromSession();
303             * if($_GET["current_path"] && $_GET["current_id"] && $file_tree && $file_tree->getId() == $this->getGUIClass()->object->getId())
304             * {
305             * $path = $_GET["current_path"];
306             * $id = $_GET["current_id"];
307             *
308             * }
309             * else
310             * {
311             * $path = $gui_class->object->getRootFolder();
312             * $id = $gui_class->object->getRootId();
313             * ilCloudFileTree::clearFileTreeSession();
314             * $file_tree = new ilCloudFileTree($this->getGUIClass()->object->getRootFolder(), $this->getGUIClass()->object->getRootId(), $this->getGUIClass()->object->getId(), $this->getGUIClass()->object->getServiceName());
315             * }
316             *
317             *
318             * $file_tree->updateFileTree($path);
319             * $file_tree_gui = ilCloudConnector::getFileTreeGUIClass($this->getService(), $file_tree);
320             * $this->content = $file_tree_gui->getFolderHtml($this->getGuiClass(), $id, $this->getPermDeleteFiles(), $this->getPermDeleteFolders(), $this->getPermDownload(), $this->getPermFilesVisible(), $this->getPermCreateFolders());
321             * $tpl->setContent($this->content);
322             * }**/
323            $this->afterInitGUI();
324        } catch (Exception $e) {
325            if ($e->getCode() == ilCloudException::AUTHENTICATION_FAILED) {
326                $this->getGUIClass()->object->setAuthComplete(false);
327                $this->getGUIClass()->object->doUpdate();
328            }
329            ilUtil::sendFailure($e->getMessage());
330        }
331    }
332
333
334    /**
335     * @param $root_node
336     */
337    public function addToolbar($root_node)
338    {
339        global $DIC;
340        $lng = $DIC['lng'];
341        $ilToolbar = $DIC['ilToolbar'];
342        $ilLog = $DIC['ilLog'];
343
344        $create_list_gui = ilCloudConnector::getItemCreationListGUIClass($this->getService());
345
346        $list_gui_html = $create_list_gui->getGroupedListItemsHTML($this->getPermUploadItems(), $this->getPermCreateFolders());
347        if ($list_gui_html) {
348            //toolbar
349            $toolbar_locator = new ilLocatorGUI();
350            $toolbar_locator->addItem($this->getGuiClass()->object->getTitle(), ilCloudPluginFileTreeGUI::getLinkToFolder($root_node));
351            $ilToolbar->setId('xcld_toolbar');
352            $ilToolbar->addText("<div class='xcld_locator'>" . $toolbar_locator->getHtml() . "</div>");
353            $ilToolbar->addSeparator();
354
355            include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
356            $adv = new ilAdvancedSelectionListGUI();
357            $adv->setListTitle($lng->txt("cld_add_new_item"));
358
359            $ilCloudGroupedListGUI = $create_list_gui->getGroupedListItems($this->getPermUploadItems(), $this->getPermCreateFolders());
360
361            if ($ilCloudGroupedListGUI->hasItems()) {
362                $adv->setGroupedList($ilCloudGroupedListGUI);
363            }
364
365            $adv->setStyle(ilAdvancedSelectionListGUI::STYLE_EMPH);
366            $ilToolbar->addText($adv->getHTML());
367        }
368    }
369
370
371    public function beforeInitGUI()
372    {
373    }
374
375
376    public function beforeSetContent()
377    {
378    }
379
380
381    public function afterInitGUI()
382    {
383    }
384}
385