Newer
Older
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
<?php
/**
* files.php - controller to display personal files of a user
*
* The FilesController controller provides actions for the personal file area.
*
* 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 FilesController extends AuthenticatedController
{
public function validate_args(&$args, $types = NULL)
{
reset($args);
}
/**
* Create a link to a folder's range.
* @param \FolderType $folder the folder
* @return string the link to the folder's range
*/
public static function getRangeLink($folder)
{
return FileManager::getFolderLink($folder);
}
public function before_filter(&$action, &$args)
{
parent::before_filter($action, $args);
PageLayout::setHelpKeyword('Basis.Dateien');
$this->user = User::findCurrent();
$this->last_visitdate = time();
//Actions in this controller are not accessible for nobody.
if ($GLOBALS['user']->id == 'nobody') {
throw new AccessDeniedException();
}
$constraints = FileManager::getUploadTypeConfig($this->user->id);
PageLayout::addHeadElement('script', ['type' => 'text/javascript'], sprintf(
'STUDIP.Files.setUploadConstraints(%s);',
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
));
}
/**
* Helper method for filling the sidebar with actions.
*/
private function buildSidebar(FolderType $folder, $view = true)
{
$sidebar = Sidebar::get();
$sources = new LinksWidget();
$sources->setTitle(_("Dateiquellen"));
$sources->addLink(
_("Stud.IP-Dateien"),
$this->url_for("files/index"),
Icon::create("files", "clickable")
);
foreach (PluginManager::getInstance()->getPlugins('FilesystemPlugin') as $plugin) {
if ($plugin->isPersonalFileArea()) {
$subnav = $plugin->getFileSelectNavigation();
$sources->addLink(
$subnav->getTitle(),
URLHelper::getURL("dispatch.php/files/system/".$plugin->getPluginId()),
$subnav->getImage()
);
}
}
$sidebar->addWidget($sources);
$actions = new ActionsWidget();
if ($folder->isEditable($GLOBALS['user']->id) && $folder->parent_id) {
$actions->addLink(
_('Ordner bearbeiten'),
$this->url_for('file/edit_folder/'.$folder->getId()),
Icon::create("edit", "clickable"),
['data-dialog' => 1]
);
}
if ($folder->isSubfolderAllowed($GLOBALS['user']->id)) {
$actions->addLink(
_('Neuer Ordner'),
URLHelper::getUrl('dispatch.php/file/new_folder/' . $folder->getId()),
Icon::create('folder-empty+add', 'clickable'), ['data-dialog' => 1]
);
}
$actions->addLink(
_('Bildergalerie öffnen'),
'#g',
Icon::create('file-pic', 'clickable'),
[
'onClick' => "STUDIP.Files.openGallery(); return false;"
]
);
if ($folder->isWritable($GLOBALS['user']->id)) {
$actions->addLink(
_('Dokument hinzufügen'),
'#',
Icon::create('file+add', 'clickable'),
['onClick' => "STUDIP.Files.openAddFilesWindow(); return false;"]
);
}
$config_urls = [];
foreach (PluginManager::getInstance()->getPlugins('FilesystemPlugin') as $plugin) {
$url = $plugin->filesystemConfigurationURL();
if ($url) {
$navigation = $plugin->getFileSelectNavigation();
$config_urls[] = [
'name' => $navigation->getTitle(),
'icon' => $navigation->getImage(),
'url' => $url,
];
}
}
if (count($config_urls)) {
if (count($config_urls) > 1) {
$actions->addLink(
_('Dateibereiche konfigurieren'),
$this->url_for('files/configure'),
Icon::create('admin', 'clickable')
)->asDialog();
} else {
$actions->addLink(
sprintf(_('%s konfigurieren'), $config_urls[0]['name']),
$config_urls[0]['url'],
$config_urls[0]['icon']
)->asDialog();
}
}
$sidebar->addWidget($actions);
if ($folder->isWritable($GLOBALS['user']->id)) {
$sidebar->addWidget(new TemplateWidget(
_('Dateien hinzufügen'),
$this->get_template_factory()->open('files/upload-drag-and-drop')
))->addLayoutCSSClass('hidden-medium-down');
}
if ($view) {
$views = new ViewsWidget();
$views->addLink(
_('Ordneransicht'),
$this->url_for('files/index'),
null,
[],
'index'
)->setActive(true);
$views->addLink(
_('Alle Dateien'),
$this->url_for('files/flat'),
null,
[],
'flat'
);
$sidebar->addWidget($views);
}
}
protected function addFiltersToOverviewSidebar(array $filters = [])
{
if (!$filters) {
return;
}
$sidebar = Sidebar::get();
if (in_array('time_range', $filters)) {
$template = $GLOBALS['template_factory']->open('sidebar/time-range-filter');
$attributes = [];
if (($this->begin instanceof DateTime) && ($this->end instanceof DateTime)) {
$attributes['begin'] = $this->begin->format('d.m.Y');
$attributes['end'] = $this->end->format('d.m.Y');
}
}
if (in_array('course', $filters)) {
//Find all courses of the user and add those courses to the course
//list that have files in it.
$user_courses = Course::findByUser($GLOBALS['user']->id);
$this->course_ids = [];
$courses_with_files = [];
$user_courses = $user_courses ?: [];
foreach ($user_courses as $course) {
//Check if the course has files whose modification dates
//lie in the specified time range:
$db = DBManager::get();
$sql = 'SELECT DISTINCT 1 FROM file_refs INNER JOIN `folders`
ON `file_refs`.`folder_id` = `folders`.`id`
WHERE `folders`.`range_id` = :course_id';
$sql_params = ['course_id' => $course->id];
if (($this->begin instanceof DateTime) && ($this->end instanceof DateTime)) {
$sql .= ' AND `file_refs`.`chdate` BETWEEN :begin AND :end';
$sql_params['begin'] = $this->begin->getTimestamp();
$sql_params['end'] = $this->end->getTimestamp();
}
$stmt = $db->prepare($sql);
$stmt->execute($sql_params);
$files_exist = $stmt->fetchColumn();
if ($files_exist) {
$courses_with_files[] = $course;
}
}
if ($courses_with_files) {
foreach ($courses_with_files as $course) {
$key = $course->id;
$course_options[$key] = $course->getFullName();
}
$attributes['course_options'] = $course_options;
}
$attributes['selected_course_id'] = $this->course_id;
}
$time_range_filter = new TemplateWidget(_('Filter'), $template, $attributes);
$sidebar->addWidget($time_range_filter);
}
private function countChildren(FolderType $folder)
{
$file_count = count($folder->getFiles());
$folder_count = count($folder->getSubfolders());
foreach ($folder->getSubfolders() as $subfolder) {
$subs = $this->countChildren($subfolder);
$file_count += $subs[0];
$folder_count += $subs[1];
}
return [$file_count, $folder_count];
}
protected function addViewsToOverview(string $current_view)
{
$sidebar = Sidebar::get();
$views = new ViewsWidget();
$views->addLink(
_('Übersicht'),
$this->url_for('files/overview'),
null,
[],
'overview'
)->setActive($current_view == 'overview');
$views->addLink(
_('Alle Dateien'),
$this->url_for('files/overview', ['view' => 'all_files']),
null,
[],
'all_files'
)->setActive($current_view == 'all_files');
$views->addLink(
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
$this->url_for('files/overview', ['view' => 'my_uploaded_files']),
null,
[],
'my_uploaded_files'
)->setActive($current_view == 'my_uploaded_files');
$views->addLink(
_('Meine öffentlichen Dateien'),
$this->url_for('files/overview', ['view' => 'my_public_files']),
null,
[],
'my_public_files'
)->setActive($current_view == 'my_public_files');
$views->addLink(
_('Meine Dateien mit ungeklärter Lizenz'),
$this->url_for('files/overview', ['view' => 'my_uploaded_files_unknown_license']),
null,
[],
'my_uploaded_files_unknown_license'
)->setActive($current_view == 'my_uploaded_files_unknown_license');
$sidebar->addWidget($views);
}
/**
* Displays an overview page with widgets showing a current selection
* of files. This is practically a new version of the former file dashboard.
*/
public function overview_action()
{
if (Navigation::hasItem('/contents/files/overview')) {
Navigation::activateItem('/contents/files/overview');
}
PageLayout::setTitle(_('Übersicht'));
$this->begin = null;
$this->end = null;
$this->course_id = null;
$user_id = $GLOBALS['user']->id;
$this->show_download_column = Config::get()->DISPLAY_DOWNLOAD_COUNTER === 'always';
$this->current_view = Request::get('view', 'overview');
//Use the top folder of the user's file area for the link
//to the file/bulk action. That action neets a folder-ID
//to work properly.
$folder = Folder::findTopFolder($this->user->id);
$this->topFolder = null;
if ($folder) {
$this->topFolder = $folder->getTypedFolder();
$this->vue_topfolder = FilesystemVueDataManager::getFolderVueData(
$this->topFolder,
$this->topFolder
);
}
$this->form_action = $this->link_for('file/bulk/' . $folder->id);
$course_did_change = false;
if ($this->current_view != 'overview') {
$tzdt = new DateTime();
if (Request::submitted('filter')) {
CSRFProtection::verifyUnsafeRequest();
if (Request::get('begin') && Request::get('end')) {
$this->begin = Request::getDateTime('begin', 'd.m.Y');
$this->end = Request::getDateTime('end', 'd.m.Y');
if ($this->begin > $this->end) {
$this->begin = clone $this->end;
}
if ($this->begin instanceof DateTime) {
$this->begin->setTime(0,0,0);
}
if ($this->end instanceof DateTime) {
$this->end->setTime(23,59,59);
}
if (!is_array($_SESSION['files_overview'])) {
$_SESSION['files_overview'] = [];
}
$_SESSION['files_overview']['begin'] = $this->begin;
$_SESSION['files_overview']['end'] = $this->end;
}
if (Request::submitted('course_id')) {
$course_did_change = true;
$this->course_id = Request::get('course_id');
if (!is_array($_SESSION['files_overview'])) {
$_SESSION['files_overview'] = [];
}
$_SESSION['files_overview']['course_id'] = $this->course_id;
}
} else {
$this->begin = $_SESSION['files_overview']['begin'];
$this->end = $_SESSION['files_overview']['end'];
$this->course_id = $_SESSION['files_overview']['course_id'];
}
}
if ($this->course_id) {
if (!$GLOBALS['perm']->have_studip_perm('user', $this->course_id)) {
throw new AccessDeniedException();
}
}
$this->addViewsToOverview($this->current_view);
if ($this->current_view == 'overview') {
$this->all_files_c = FileRef::countAll($GLOBALS['user']->id, $this->begin, $this->end);
$all_file_refs = FileRef::findAll($GLOBALS['user']->id, $this->begin, $this->end, '', 100, 0);
$this->all_files = [];
$count_visible = 0;
foreach ($all_file_refs as $file_ref) {
if ($file_ref->getFileType()->isVisible($GLOBALS['user']->id)) {
$vue_data = FilesystemVueDataManager::getFileVueData(
$file_ref->getFileType(),
$this->topFolder
);
}
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
if (isset($vue_data['download_url'])) {
$this->all_files[] = $vue_data;
if (++$count_visible === 5) break;
}
}
$this->public_files_c = FileRef::countPublicFiles($GLOBALS['user']->id, $this->begin, $this->end);
$public_file_refs = FileRef::findPublicFiles($GLOBALS['user']->id, $this->begin, $this->end, 5, 0);
$this->public_files = [];
foreach ($public_file_refs as $file_ref) {
$this->public_files[] = FilesystemVueDataManager::getFileVueData(
$file_ref->getFileType(),
$this->topFolder
);
}
$this->uploaded_files_c = FileRef::countUploadedFiles($GLOBALS['user']->id, $this->begin, $this->end, '', false);
$uploaded_file_refs = FileRef::findUploadedFiles($GLOBALS['user']->id, $this->begin, $this->end, '', false, 5, 0);
$this->uploaded_files = [];
foreach ($uploaded_file_refs as $file_ref) {
$this->uploaded_files[] = FilesystemVueDataManager::getFileVueData(
$file_ref->getFileType(),
$this->topFolder
);
}
$this->uploaded_unlic_files_c = FileRef::countUploadedFiles($GLOBALS['user']->id, $this->begin, $this->end, '', true);
$uploaded_unlic_file_refs = FileRef::findUploadedFiles($GLOBALS['user']->id, $this->begin, $this->end, '', true, 5, 0);
$this->uploaded_unlic_files = [];
foreach ($uploaded_unlic_file_refs as $file_ref) {
if ($file_ref->getFileType()->isVisible($GLOBALS['user']->id)) {
$this->uploaded_unlic_files[] = FilesystemVueDataManager::getFileVueData(
$file_ref->getFileType(),
$this->topFolder
);
}
}
if (!$this->all_files_c) {
$this->no_files = true;
}
} elseif ($this->current_view == 'all_files') {
$this->table_title = _('Alle Dateien');
$this->page_size = 25;
$this->page = 1;
if (!$course_did_change) {
$this->page = Request::get('page') + 1;
}
if (($this->page < 1) || !$this->page) {
$this->page = 1;
}
$offset = $this->page_size * ($this->page - 1);
$this->addFiltersToOverviewSidebar(['time_range', 'course']);
$this->file_ref_c = FileRef::countAll($GLOBALS['user']->id, $this->begin, $this->end, $this->course_id);
$pagination = Pagination::create(
$this->file_ref_c,
$this->page - 1,
$this->page_size
);
$this->pagination_html = $pagination->asLinks(
function ($page_id) {
return URLHelper::getLink(
'dispatch.php/files/overview',
[
'view' => 'all_files',
'page' => $page_id
]
);
}
);
//To optimise performance, the folders of the files are collected
//in an array with all relevant files of the folder attached to it.
//This way, we don't need to each file's folder separately and can
//instead load it once.
//Each item in the folders array has the following structure:
//[
// 'folder' => The folder object.
// 'file_refs' => The file refs attached to it.
//]
$folders = [];
$new_file_refs = FileRef::findAll($GLOBALS['user']->id, $this->begin, $this->end, $this->course_id, $this->page_size, $offset);
//Group the file refs by their folder:
foreach ($new_file_refs as $file_ref) {
if (!is_array($folders[$file_ref->folder_id])) {
$folders[$file_ref->folder_id] = [
'folder' => $file_ref->folder->getTypedFolder(),
'file_refs' => []
];
}
$folders[$file_ref->folder_id]['file_refs'][] = $file_ref;
}
$this->files = [];
foreach ($folders as $folder_data) {
$folder = $folder_data['folder'];
if (!$folder instanceof FolderType) {
//We cannot work with unknown folder types.
continue;
}
foreach ($folder_data['file_refs'] as $file_ref) {
//Check if the current user may download the file.
//If so, it is included in the new_files array.
if ($folder->isFileDownloadable($file_ref->id, $user_id)) {
$this->files[] = $file_ref->getFileType();
}
}
}
} elseif ($this->current_view == 'my_public_files') {
$this->table_title = _('Meine öffentlichen Dateien');
$this->addFiltersToOverviewSidebar(['time_range']);
$file_refs = FileRef::findPublicFiles($GLOBALS['user']->id, $this->begin, $this->end);
$this->files = [];
foreach ($file_refs as $file_ref) {
$this->files[] = $file_ref->getFileType();
}
} elseif ($this->current_view == 'my_uploaded_files') {
$this->page_size = 25;
$this->page = 1;
if (!$course_did_change) {
$this->page = Request::get('page') + 1;
}
if (($this->page < 1) || !$this->page) {
$this->page = 1;
}
$offset = $this->page_size * ($this->page - 1);
$this->addFiltersToOverviewSidebar(['time_range', 'course']);
$this->table_title = _('Meine hochgeladenen Dateien');
$file_refs = FileRef::findUploadedFiles($GLOBALS['user']->id, $this->begin, $this->end, $this->course_id, $this->page_size, $offset);
$this->files_c = FileRef::countUploadedFiles($GLOBALS['user']->id, $this->begin, $this->end, $this->course_id);
$pagination = Pagination::create(
$this->files_c,
$this->page - 1,
$this->page_size
);
$this->pagination_html = $pagination->asLinks(
function ($page_id) {
return URLHelper::getLink(
'dispatch.php/files/overview',
[
'view' => 'my_uploaded_files',
'page' => $page_id
]
);
}
);
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
$this->files = [];
foreach ($file_refs as $file_ref) {
$this->files[] = $file_ref->getFileType();
}
} elseif ($this->current_view == 'my_uploaded_files_unknown_license') {
$this->addFiltersToOverviewSidebar(['time_range', 'course']);
$this->table_title = _('Meine Dateien mit ungeklärter Lizenz');
$file_refs = FileRef::findUploadedFiles($GLOBALS['user']->id, $this->begin, $this->end, $this->course_id, true);
$this->files_c = FileRef::countUploadedFiles($GLOBALS['user']->id, $this->begin, $this->end, $this->course_id, true);
$this->files = [];
foreach ($file_refs as $file_ref) {
$this->files[] = $file_ref->getFileType();
}
} else {
PageLayout::postError(_('Die gewählte Ansicht ist nicht verfügbar!'));
}
$this->show_file_search = true;
}
/**
* Displays the files from the personal file area in a tree view.
*/
public function index_action($topFolderId = '')
{
if (Request::get("from_plugin")) {
$this->redirect("files/index/".$topFolderId);
}
if (Navigation::hasItem('/contents/files/my_files')) {
Navigation::activateItem('/contents/files/my_files');
}
PageLayout::setTitle(_('Persönliche Dateien'));
$this->marked_element_ids = [];
if (!$topFolderId) {
$folder = Folder::findTopFolder($this->user->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 !== $GLOBALS['user']->id) {
throw new AccessDeniedException();
}
$this->buildSidebar($this->topFolder);
//check for INBOX and OUTBOX folder:
$inbox_folder = FileManager::getInboxFolder($this->user);
$outbox_folder = FileManager::getOutboxFolder($this->user);
$this->show_file_search = true;
}
/**
* Displays the files from the personal file area in a flat view
**/
public function flat_action()
{
if (Navigation::hasItem('/contents/files/my_files')) {
Navigation::activateItem('/contents/files/my_files');
}
$sidebar = Sidebar::get();
$actions = new ActionsWidget();
$actions->addLink(
_('Bildergalerie öffnen'),
'#g',
Icon::create('file-pic', 'clickable'),
[
'onClick' => "STUDIP.Files.openGallery(); return false;",
'v-if' => "hasFilesOfType('image')"
]
);
$sidebar->addWidget($actions);
$this->marked_element_ids = [];
$folder = Folder::findTopFolder($this->user->id);
if (!$folder) {
throw new Exception(_('Fehler beim Laden des Hauptordners!'));
}
$this->topFolder = $folder->getTypedFolder();
$this->form_action = $this->link_for('file/bulk/' . $this->topFolder->getId());
$this->show_default_sidebar = true;
$this->enable_table_filter = true;
//find all files in all subdirectories:
list($this->files, $this->folders) = array_values(FileManager::getFolderFilesRecursive($this->topFolder, $GLOBALS['user']->id));
}
/**
* Action to configure the different FileSystem-plugins
*/
public function configure_action()
{
PageLayout::setTitle(_('Dateibereich zur Konfiguration auswählen'));
$this->configure_urls = [];
foreach (PluginManager::getInstance()->getPlugins('FilesystemPlugin') as $plugin) {
$url = $plugin->filesystemConfigurationURL();
if ($url) {
$navigation = $plugin->getFileSelectNavigation();
$this->configure_urls[] = [
'name' => $navigation->getTitle(),
'icon' => $navigation->getImage(),
'url' => $url,
];
}
}
}
public function system_action($plugin_id, $folder_id = null)
{
$this->plugin = PluginManager::getInstance()->getPluginById($plugin_id);
if (!$this->plugin->isPersonalFileArea()) {
throw new Exception(_('Dieser Bereich ist nicht verfügbar.'));
}
$navigation = $this->plugin->getFileSelectNavigation();
PageLayout::setTitle($navigation->getTitle());
URLHelper::addLinkParam('to_plugin', get_class($this->plugin));
URLHelper::addLinkParam('from_plugin', get_class($this->plugin));
$folder_id = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], "dispatch.php/files/system/".$this->plugin->getPluginId()) + strlen("dispatch.php/files/system/".$this->plugin->getPluginId()));
if (strpos($folder_id, "?") !== false) {
$folder_id = substr($folder_id, 0, strpos($folder_id, "?"));
}
$this->topFolder = $this->plugin->getFolder($folder_id);
$this->controllerpath = 'files/system/' . $plugin_id;
if (!$this->topFolder) {
PageLayout::postError(
_('Ordner nicht gefunden!')
);
} else {
$this->buildSidebar($this->topFolder, false);
}
$this->render_action('index');
}
public function copyhandler_action($destination_id)
{
$to_plugin = Request::get('to_plugin');
$from_plugin = Request::get('from_plugin');
$fileref_id = Request::getArray('fileref_id');
$copymode = Request::get('copymode');
$user = User::findCurrent();
if ($to_plugin) {
$destination_id = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], "dispatch.php/files/copyhandler/") + strlen("dispatch.php/files/copyhandler/"));
if (strpos($destination_id, "?") !== false) {
$destination_id = substr($destination_id, 0, strpos($destination_id, "?"));
}
$destination_plugin = PluginManager::getInstance()->getPlugin($to_plugin);
if (!$destination_plugin) {
throw new Trails_Exception(404, _('Plugin existiert nicht.'));
}
$destination_folder = $destination_plugin->getFolder($destination_id);
} else {
$destination_folder = Folder::find($destination_id)->getTypedFolder();
}
$errors = [];
$count_files = 0;
$count_folders = 0;
$filerefs = $fileref_id;
if (!empty($filerefs)) {
foreach ($filerefs as $fileref) {
if ($from_plugin) {
$source_plugin = PluginManager::getInstance()->getPlugin($from_plugin);
if (!$source_plugin) {
throw new Trails_Exception(404, _('Plugin existiert nicht.'));
}
if (Request::get("isfolder")) {
if ($source_folder = $source_plugin->getFolder($fileref)) {
if ($copymode === 'move') {
$result = FileManager::moveFolder($source_folder, $destination_folder, $user);
} else {
$result = FileManager::copyFolder($source_folder, $destination_folder, $user);
}
if (!is_array($result)) {
$count_folders += 1;
$children = $this->countChildren($result);
$count_files += $children[0];
$count_folders += $children[1];
}
}
} else {
if ($source = $source_plugin->getPreparedFile($fileref, true)) {
if ($copymode === 'move') {
$result = FileManager::moveFile($source, $destination_folder, $user);
} else {
$result = FileManager::copyFile($source, $destination_folder, $user);
}
if (!is_array($result)) {
$count_files += 1;
}
}
}
} else {
if ($source = FileRef::find($fileref)) {
if ($copymode === 'move') {
$result = FileManager::moveFile($source->getFileType(), $destination_folder, $user);
} else {
$result = FileManager::copyFile($source->getFiletype(), $destination_folder, $user);
}
if (!is_array($result)) {
$count_files += 1;
}
} elseif ($source = Folder::find($fileref)) {
$source_folder = $source->getTypedFolder();
if ($copymode === 'move') {
$result = FileManager::moveFolder($source_folder, $destination_folder, $user);
} else {
$result = FileManager::copyFolder($source_folder, $destination_folder, $user);
}
if (!is_array($result)) {
$count_folders += 1;
$children = $this->countChildren($result);
$count_files += $children[0];
$count_folders += $children[1];
}
}
}
if (is_array($result)) {
$errors = array_merge($errors, $result);
}
}
}
if (empty($errors) || $count_files > 0 || $count_folders > 0) {
if (count($filerefs) == 1) {
if ($source_folder) {
if ($copymode == 'copy') {
PageLayout::postSuccess(_('Der Ordner wurde kopiert!'));
} else {
PageLayout::postSuccess(_('Der Ordner wurde verschoben!'));
}
} else {
if ($copymode == 'copy') {
PageLayout::postSuccess(_('Die Datei wurde kopiert!'));
} else {
PageLayout::postSuccess(_('Die Datei wurde verschoben!'));
}
}
} else {
if ($count_files > 0 && $count_folders > 0) {
if ($copymode === 'copy') {
PageLayout::postSuccess(sprintf(_('Es wurden %u Ordner und %u Dateien kopiert.'), $count_folders, $count_files));
} else {
PageLayout::postSuccess(sprintf(_('Es wurden %u Ordner und %u Dateien verschoben.'), $count_folders, $count_files));
}
} elseif ($count_files > 0) {
if ($copymode === 'copy') {
PageLayout::postSuccess(sprintf(_('Es wurden %u Dateien kopiert.'), $count_files));
} else {
PageLayout::postSuccess(sprintf(_('Es wurden %u Dateien verschoben.'), $count_files));
}
} else {
if ($copymode === 'copy') {
PageLayout::postSuccess(sprintf(_('Es wurden %u Ordner kopiert.'), $count_folders));
} else {
PageLayout::postSuccess(sprintf(_('Es wurden %u Ordner verschoben.'), $count_folders));
}
}
}
} else {
PageLayout::postError(_('Es ist ein Fehler aufgetreten.'), array_map('htmlReady', $errors));
}
$dest_range = $destination_folder->range_id;
switch ($destination_folder->range_type) {
case 'course':
return $this->redirect(URLHelper::getURL('dispatch.php/course/files/index/' . $destination_folder->getId() . '?cid=' . $dest_range));
case 'institute':
return $this->redirect(URLHelper::getURL('dispatch.php/institute/files/index/' . $destination_folder->getId() . '?cid=' . $dest_range));
case 'user':
return $this->redirect(URLHelper::getURL('dispatch.php/files/index/' . $destination_folder->getId()));
default:
if ($destination_plugin) {
return $this->redirect(URLHelper::getURL('dispatch.php/files/system/' . $destination_plugin->getPluginId() .'/'. $destination_folder->getId()));
} else {
return $this->redirect(URLHelper::getURL('dispatch.php/course/files/index/' . $destination_folder->getId()));
}
}
}
}