1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
<?php
/**
* files.php - controller to display files in a course
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* @author Moritz Strohm <strohm@data-quest.de>
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
* @category Stud.IP
* @since 4.0
*/
class Institute_FilesController extends AuthenticatedController
{
protected $allow_nobody = true;
public function before_filter(&$action, &$args)
{
parent::before_filter($action, $args);
checkObject();
$this->studip_module = checkObjectModule('documents');
if (!Context::isInstitute()) {
throw new CheckObjectException(_('Es wurde keine passende Einrichtung gefunden.'));
}
$this->institute = Context::get();
object_set_visit_module($this->studip_module->getPluginId());
PageLayout::setHelpKeyword("Basis.Dateien");
PageLayout::setTitle($this->institute->getFullname() . " - " . _("Dateien"));
$this->last_visitdate = object_get_visit($this->institute->id, $this->studip_module->getPluginId());
Navigation::activateItem('/course/files');
if (is_object($GLOBALS['user']) && $GLOBALS['user']->id !== 'nobody') {
$constraints = FileManager::getUploadTypeConfig($this->institute->id);
PageLayout::addHeadElement('script', ['type' => 'text/javascript'], sprintf(
'STUDIP.Files.setUploadConstraints(%s);',
json_encode($constraints)
));
}
}
private function buildSidebar()
{
$sidebar = Sidebar::get();
$actions = new ActionsWidget();
if ($this->topFolder->isEditable($GLOBALS['user']->id) && $this->topFolder->parent_id) {
$actions->addLink(
_("Ordner bearbeiten"),
$this->url_for("file/edit_folder/".$this->topFolder->getId()),
Icon::create("edit", "clickable"),
['data-dialog' => 1]
);
}
if ($this->topFolder && $this->topFolder->isSubfolderAllowed($GLOBALS['user']->id)) {
$actions->addLink(
_('Neuer Ordner'),
URLHelper::getUrl(
'dispatch.php/file/new_folder/' . $this->topFolder ->getId()
),
Icon::create('folder-empty+add', 'clickable')
)->asDialog();
}
if ($this->topFolder && $this->topFolder->isWritable($GLOBALS['user']->id)) {
$actions->addLink(
_('Dokument hinzufügen'),
'#',
Icon::create('file+add', 'clickable'),
['onclick' => "STUDIP.Files.openAddFilesWindow(); return false;"]
);
}
$sidebar->addWidget($actions);
$views = new ViewsWidget();
$views->addLink(
_('Ordneransicht'),
$this->url_for('institute/files/index'),
null,
[],
'index'
)->setActive(true);
$views->addLink(
_('Alle Dateien'),
$this->url_for('institute/files/flat'),
null,
[],
'flat'
);
$sidebar->addWidget($views);
}
/**
* Displays the files in tree view
**/
public function index_action($topFolderId = '')
{
$this->marked_element_ids = [];
if (!$topFolderId) {
$folder = Folder::findTopFolder($this->institute->id);
} else {
$folder = Folder::find($topFolderId);
}
if (!$folder) {
throw new Exception(_('Fehler beim Laden des Hauptordners!'));
}
$this->topFolder = $folder->getTypedFolder();
if (!$this->topFolder->isVisible($GLOBALS['user']->id) || $this->topFolder->range_id !== $this->institute->id) {
throw new AccessDeniedException();
}
$this->buildSidebar();
$this->render_template('files/index.php', $this->layout);
}
/**
* Displays the files in flat view
**/
public function flat_action()
{
$this->marked_element_ids = [];
$folder = Folder::findTopFolder($this->institute->id);
if (!$folder) {
throw new Exception(_('Fehler beim Laden des Hauptordners!'));
}
$this->topFolder = $folder->getTypedFolder();
//find all files in all subdirectories:
list($this->files, $this->folders) = array_values(FileManager::getFolderFilesRecursive($this->topFolder, $GLOBALS['user']->id));
$this->range_type = 'institute';
$this->show_default_sidebar = true;
$this->form_action = $this->url_for('file/bulk/' . $folder->getId());
$this->render_template('files/flat.php', $this->layout);
}
}
|