forked from noackorama/ZensusPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UniZensusAdminPlugin.class.php
704 lines (666 loc) · 39.3 KB
/
UniZensusAdminPlugin.class.php
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
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
273
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
388
389
390
391
392
393
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
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
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
<?php
/**
* UniZensusAdminPlugin.class.php
*
*
*
*
* @author André Noack <[email protected]>, Suchi & Berg GmbH <[email protected]>
* @version $Id: UniZensusAdminPlugin.class.php,v 1.6 2013/04/04 15:17:49 anoack Exp $
*/
// +---------------------------------------------------------------------------+
// This file is part of Stud.IP
// UniZensusAdminPlugin.class.php
//
// Copyright (C) 2007 André Noack <[email protected]>
// Suchi & Berg GmbH <[email protected]>
// +---------------------------------------------------------------------------+
// 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 any later version.
// +---------------------------------------------------------------------------+
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// +---------------------------------------------------------------------------+
require_once "lib/classes/StudipForm.class.php";
require_once "UniZensusPlugin.class.php";
require_once 'zensus_xml_func.php'; // XML-Funktionen
if (!function_exists('get_route')) {
include 'get_route.php';
}
class UniZensusAdminPlugin extends StudipPlugin implements SystemPlugin {
private $user_is_eval_admin;
private $zensuspluginid;
public function __construct() {
parent::__construct();
if ($this->hasPermission()) {
$navigation = new Navigation($this->getDisplayname(), PluginEngine::getLink($this, array(), 'show'));
if (strpos(get_route(),'unizensusadminplugin') !== false) {
//Navigation::addItem('/UniZensusAdmin/show', clone $navigation);
$token_navigation = new Navigation(_("Export Token"), PluginEngine::getLink($this, array(), 'token'));
$subnav = clone $navigation;
$subnav->addSubNavigation('show', clone $navigation);
$subnav->addSubNavigation('token', $token_navigation);
$navigation->addSubNavigation('sub', $subnav);
Navigation::addItem('/UniZensusAdmin', $navigation);
} else {
Navigation::addItem('/start/UniZensusAdmin', clone $navigation);
}
$info = PluginManager::getInstance()->getPluginInfo('unizensusplugin');
$this->zensuspluginid = $info['id'];
}
}
function getDisplayname() {
return _("Lehrevaluation-Administration");
}
private function hasPermission() {
return $GLOBALS['perm']->have_perm('root') ||
($this->user_is_eval_admin = RolePersistence::isAssignedRole($GLOBALS['user']->id, 'ZensusAdmin'));
}
function token_action()
{
if (!$this->hasPermission()) {
throw new AccessDeniedException("Nur Root und ausgewählte Admins dürfen dieses Plugin sehen.");
}
Navigation::activateItem('/UniZensusAdmin/sub/token');
if (Request::submitted('generate_token')) {
UserConfig::get($GLOBALS['user']->id)->store('UNIZENSUSPLUGIN_AUTH_TOKEN', md5(uniqid('ZensusToken',1)));
}
ob_start();
echo '<p>';
echo _("Für den Import der Veranstaltungsdaten in das Zensus System müssen sie dort ein Authentifizierungstoken hinterlegen.");
echo '<br>' . _("Hier können Sie ein Token für Ihre aktuelle Nutzerkennung generieren.");
echo '</p>';
echo '<div>';
echo '<span style="font-weight:bold; padding-right:10px;">' . _("Nutzerkennung:") . '</span>';
echo $GLOBALS['auth']->auth['uname'] . ' (' . $GLOBALS['auth']->auth['perm'] . ')';
echo '</div>';
echo '<div>';
echo '<span style="font-weight:bold; padding-right:10px;">' . _("Token:") . '</span>';
echo htmlReady(UserConfig::get($GLOBALS['user']->id)->UNIZENSUSPLUGIN_AUTH_TOKEN);
echo '</div>';
echo '<div>';
echo '<form method="post" action="?" class="default">';
echo '<button class="button" type="submit" name="generate_token">' . _("neues Token erzeugen") . '</button>';
echo '</form>';
echo '</div>';
PageLayout::setTitle($this->getDisplayname());
$layout = $GLOBALS['template_factory']->open('layouts/base');
$layout->content_for_layout = ob_get_clean();
echo $layout->render();
}
function show_action() {
if (!$this->hasPermission()) {
throw new AccessDeniedException("Nur Root und ausgewählte Admins dürfen dieses Plugin sehen.");
}
Navigation::activateItem('/UniZensusAdmin/sub/show');
ob_start();
$cols = array();
$cols[] = array(1,'','');
$cols[] = array(10,_("Nr."),'VeranstaltungsNummer');
$cols[] = array(20,_("Veranstaltung"),'Name');
$cols[] = array(15,_("Dozenten"),'dozenten');
$cols[] = array(5,_("∑ Stud.IP"),'teilnehmer_anzahl_aktuell');
$cols[] = array(5,_("Zensus Status"),'zensus_status');
$cols[] = array(5,_("∑ Zensus"),'zensus_numvotes');
$cols[] = array(5,_("Plugin aktiv"),'plugin_activated');
$cols[] = array(10,_("Startzeit manuell"),'begin_evaluation');
$cols[] = array(10,_("Endzeit manuell"),'end_evaluation');
$cols[] = array(10,_("Startzeit automatisch"),'time_frame_begin');
$cols[] = array(10,_("Endzeit automatisch"),'time_frame_end');
$form_fields['starttime'] = array('type' => 'text');
$form_fields['starttime']['attributes'] = array('size'=>10, 'onMouseOver' => 'jQuery(this).datepicker();');
$form_fields['endtime'] = array('type' => 'text');
$form_fields['endtime']['attributes'] = array('size'=>10, 'onMouseOver' => 'jQuery(this).datepicker();');
$form_fields['plugin_status'] = array('type' => 'radio', 'separator' => ' ', 'default_value' => 1, 'options' => array(array('name'=>_("Ein"),'value'=>'1'),array('name'=>_("Aus"),'value'=>'0')));
$form_buttons['set_plugin_status'] = array('name' => 'uebernehmen', 'caption' => _("Plugin ein/ausschalten"));
$form_buttons['set_starttime'] = array('name' => 'uebernehmen', 'caption' => _("Startzeit übernehmen"));
$form_buttons['set_endtime'] = array('name' => 'uebernehmen', 'caption' => _("Endzeit übernehmen"));
$form = new StudipForm($form_fields, $form_buttons, 'studipform', false);
if($form->isClicked('set_starttime') || $form->isClicked('set_endtime')){
if(is_array($_REQUEST['sem_choosen'])){
if ($form->isClicked('set_starttime')){
$datafield_value = $form->getFormFieldValue('starttime');
if ($datafield_value) {
$datafield_value = strftime('%Y-%m-%d', strtotime($datafield_value));
}
$datafield_id = md5('UNIZENSUSPLUGIN_BEGIN_EVALUATION');
} else {
$datafield_value = $form->getFormFieldValue('endtime');
if ($datafield_value) {
$datafield_value = strftime('%Y-%m-%d', strtotime($datafield_value));
}
$datafield_id = md5('UNIZENSUSPLUGIN_END_EVALUATION');
}
$db = new DB_Seminar();
foreach(array_keys($_REQUEST['sem_choosen']) as $seminar_id){
$db->queryf("REPLACE INTO datafields_entries (range_id, datafield_id, content, chdate) VALUES ('%s','%s','%s',UNIX_TIMESTAMP())",
$seminar_id, $datafield_id , $datafield_value);
}
$form->doFormReset();
}
}
if($form->isClicked('set_plugin_status')){
if(is_array($_REQUEST['sem_choosen'])){
$set_to_status = $form->getFormFieldValue('plugin_status') ? 'on' : 'off';
$db = new DB_Seminar();
foreach(array_keys($_REQUEST['sem_choosen']) as $seminar_id){
$db->queryf("REPLACE INTO plugins_activated (pluginid,poiid,state) VALUES ('%s','%s','%s')",
$this->zensuspluginid, 'sem' . $seminar_id, $set_to_status);
}
$form->doFormReset();
}
}
if (Request::submitted('reset_search')) {
$_SESSION['_default_sem'] = Semester::findCurrent()->semester_id;
$_SESSION['zensus_admin']['check_eval'] = false;
$_SESSION['zensus_admin']['plugin_activated'] = false;
$_SESSION['zensus_admin']['filter_name'] = "";
$_SESSION['zensus_admin']['show_sem_class'] = null;
}
if (Request::submitted('choose_institut') || Request::submitted('export')) {
$_SESSION['_default_sem'] = Request::option('select_sem', $_SESSION['_default_sem']);
$_SESSION['zensus_admin']['check_eval'] = isset($_REQUEST['check_eval']);
$_SESSION['zensus_admin']['plugin_activated'] = isset($_REQUEST['plugin_activated']);
$_SESSION['zensus_admin']['filter_name'] = trim(Request::get('filter_name'));
$_SESSION['zensus_admin']['show_sem_class'] = Request::optionArray('show_sem_class');
}
if(!$_SESSION['_default_sem'] || $_SESSION['_default_sem'] == 'all'){
$semester = SemesterData::GetInstance();
$one_semester = $semester->getCurrentSemesterData();
$_SESSION['_default_sem'] = $one_semester['semester_id'];
}
if ($_SESSION['_default_sem']){
$semester = SemesterData::GetInstance();
$one_semester = $semester->getSemesterData($_SESSION['_default_sem']);
if($one_semester["beginn"]){
$sem_condition = "AND seminare.start_time <=".$one_semester["beginn"]." AND (".$one_semester["beginn"]." <= (seminare.start_time + seminare.duration_time) OR seminare.duration_time = -1) ";
}
}
if ($_SESSION['zensus_admin']['filter_name']) {
$sem_condition .= " AND (seminare.Name LIKE '%".addslashes($_SESSION['zensus_admin']['filter_name'])."%' ";
$sem_condition .= " OR seminare.VeranstaltungsNummer LIKE '%".addslashes($_SESSION['zensus_admin']['filter_name'])."%') ";
}
if (!is_array($_SESSION['zensus_admin']['show_sem_class'])){
$_SESSION['zensus_admin']['show_sem_class'] = array();
$_SESSION['zensus_admin']['show_sem_class'][1] = true;
}
$show_types = array();
foreach (array_keys($_SESSION['zensus_admin']['show_sem_class']) as $show_class) {
$show_types = array_merge($show_types , array_keys(SeminarCategories::get($show_class)->getTypes()));
}
$sem_condition .= " AND seminare.status IN (". DbManager::get()->quote($show_types).") ";
if(isset($_REQUEST['sortby'])){
foreach($cols as $col){
if($_REQUEST['sortby'] == $col[2]){
if($_SESSION['zensus_admin']['sortby']['field'] == $_REQUEST['sortby']){
$_SESSION['zensus_admin']['sortby']['direction'] = (int)!$_SESSION['zensus_admin']['sortby']['direction'];
} else {
$_SESSION['zensus_admin']['sortby']['field'] = $_REQUEST['sortby'];
$_SESSION['zensus_admin']['sortby']['direction'] = 0;
}
break;
}
}
}
$_my_inst = $this->getInstitute($sem_condition);
if (is_array($_my_inst)){
$_my_inst_arr = array_keys($_my_inst);
if(!$_SESSION['zensus_admin']['institut_id']){
$_SESSION['zensus_admin']['institut_id'] = $_my_inst_arr[1];
}
if($_REQUEST['institut_id']){
$_SESSION['zensus_admin']['institut_id'] = ($_my_inst[$_REQUEST['institut_id']]) ? $_REQUEST['institut_id'] : $_my_inst_arr[1];
}
?>
<form action="<?=PluginEngine::getLink($this)?>" method="post" class="default">
<?= (class_exists('CSRFProtection') ? CSRFProtection::tokenTag() : '') ?>
<?=_("Bitte wählen Sie eine Einrichtung aus:")?>
<br>
<div>
<select name="institut_id" style="vertical-align:middle;">
<?
reset($_my_inst);
$num_all = 0;
while (list($key,$value) = each($_my_inst)){
if ($key == 'all') $num_all = $value["num_sem"];
if ($value["num_sem"] == '0' && $num_all > 0 && $key != $_SESSION['zensus_admin']['institut_id'] ) continue;
printf ("<option %s value=\"%s\" style=\"%s\">%s (%s)</option>\n",
($key == $_SESSION['zensus_admin']['institut_id']) ? "selected" : "" , $key,($value["is_fak"] ? "font-weight:bold;" : ""),
htmlReady($value["name"]), $value["num_sem"]);
if ($value["is_fak"] == 'all'){
$num_inst = $value["num_inst"];
for ($i = 0; $i < $num_inst; ++$i){
list($key,$value) = each($_my_inst);
if ($value["num_sem"] == '0') continue;
printf("<option %s value=\"%s\"> %s (%s)</option>\n",
($key == $_SESSION['zensus_admin']['institut_id']) ? "selected" : "", $key,
htmlReady($value["name"]), $value["num_sem"]);
}
}
}
list($institut_id,) = explode('_', $_SESSION['zensus_admin']['institut_id']);
if($institut_id == 'all') $institut_id = 'root';
?>
</select>
<?=SemesterData::GetSemesterSelector(
array(
'name'=>'select_sem'
),
$_SESSION['_default_sem'],
'semester_id',
false
)?>
</div>
<div>
<?=Studip\Button::create(_('Auswählen'), "choose_institut")?>
<?=Studip\Button::create(_('Zurücksetzen'), "reset_search")?>
</div>
<div style="font-size:80%;">
ausgewählte ID:
<mark style="background-color:yellow;">
<?= htmlReady($institut_id) ?>
</mark>
</div>
<b><?=_("Angezeigte Veranstaltungen einschränken:")?></b>
<label><?=_("Name/Nummer der Veranstaltung")?>
<input type="text" id="filter_name" name="filter_name"
value="<?=htmlReady($_SESSION['zensus_admin']['filter_name'])?>"
style="vertical-align:middle;">
</label>
<label for="check_eval">
<input type="checkbox" id="check_eval" name="check_eval"
<?=$_SESSION['zensus_admin']['check_eval'] ? 'checked' : ''?>
value="1" style="vertical-align:middle;">
<?=_("Evaluation in Zensus aktiviert")?>
</label>
<label for="plugin_activated">
<input type="checkbox" id="plugin_activated" name="plugin_activated"
<?=$_SESSION['zensus_admin']['plugin_activated'] ? 'checked' : ''?>
value="1" style="vertical-align:middle;">
<?=_("Plugin eingeschaltet")?>
</label>
<? foreach(array_filter(SeminarCategories::getAll(), function($s) {return !$s->studygroup_mode;}) as $sc) :?>
<label>
<input type="checkbox" id="show_sem_class_<?= htmlReady($sc->id) ?>"
name="show_sem_class[<?php echo $sc->id?>]"
<?=$_SESSION['zensus_admin']['show_sem_class'][$sc->id] ? 'checked' : ''?>
value="1" style="vertical-align:middle;">
<?=htmlready($sc->name)?>
</label>
<? endforeach ?>
<b><?=_("Angezeigte Veranstaltungen exportieren:")?></b>
<?= \Studip\Button::create(_("Export"), 'export'); ?>
</form>
<hr>
<?
$data = $this->getSeminareData($sem_condition);
if (count($data)) {
if($form->isClicked('switch')){
foreach($data as $seminar_id => $semdata) {
if(!isset($_REQUEST['sem_choosen'][$seminar_id])) $data[$seminar_id]['choosen'] = true;
}
} else if(is_array($_REQUEST['sem_choosen'])){
foreach($data as $seminar_id => $semdata) {
if(isset($_REQUEST['sem_choosen'][$seminar_id])) $data[$seminar_id]['choosen'] = true;
}
}
echo chr(10).$form->getFormStart(PluginEngine::getLink($this));
echo chr(10).'<div style="margin:10px;font-size:10pt;font-weight:bold">';
echo _("Start- und Endzeiten für ausgewählte Veranstaltungen setzen:");
echo chr(10). '</div>';
echo chr(10).'<div style="margin:10px;font-size:10pt;">';
echo '<span>' . _("Startzeit:") . '</span>';
echo chr(10) .'<span style="padding-left:10px;">' . $form->getFormField('starttime');
echo '</span><span style="padding-left:10px;">'. $form->getFormButton('set_starttime', array('style' => 'vertical-align:middle'));
echo chr(10). '</span></div>';
echo chr(10).'<div style="margin:10px;font-size:10pt;">';
echo '<span>' ._("Endzeit:") . '</span>';
echo chr(10) .'<span style="padding-left:10px;">' . $form->getFormField('endtime');
echo '</span><span style="padding-left:10px;">'. $form->getFormButton('set_endtime', array('style' => 'vertical-align:middle'));
echo chr(10). '</span></div>';
echo chr(10).'<div style="margin:10px;font-size:10pt;font-weight:bold">';
echo _("Evaluationsplugin für ausgewählte Veranstaltungen ein/ausschalten:") .'</div>';
echo chr(10).'<div style="margin:10px;font-size:10pt;">';
echo chr(10) . $form->getFormField('plugin_status');
echo ' '. $form->getFormButton('set_plugin_status', array('style' => 'vertical-align:middle'));
echo chr(10). '</div>';
echo chr(10). '<a name="zensustable"></a>';
echo '<table class="default">';
echo '<tr style="font-size:80%;">';
foreach($cols as $i => $col) {
echo "<th width=\"{$col[0]}%\">";
if (!$i) {
echo '<input type="checkbox" data-proxyfor=":checkbox.CourseSelector">';
} else {
if($col[1]){
echo '<a class="tree" href="';
echo PluginEngine::getLink($this,array('sortby' => $col[2], 'foo' => rand())) . '#zensustable';
echo '">'.$col[1].' ';
if($col[2] == $_SESSION['zensus_admin']['sortby']['field']){
printf('<img src="%s/images/%s" border="0" align="top">', $this->getPluginUrl(),$_SESSION['zensus_admin']['sortby']['direction'] ? 'dreieck_up.png' : 'dreieck_down.png');
}
echo '</a>';
}
}
echo "</th>";
}
echo "</tr>";
}
foreach($data as $seminar_id => $semdata) {
if($semdata['activated_by_sem'] == 'on' || ($semdata['activated_by_sem'] != 'off' && $semdata['activated_by_default'] == 'on')){
$plugin = PluginManager::getInstance()->getPluginById($this->zensuspluginid);
$plugin->setId($seminar_id);
$plugin->getCourseStatus();
$plugin->semester_id = $_SESSION['_default_sem'] ? $_SESSION['_default_sem'] : null;
if($_SESSION['zensus_admin']['check_eval'] && !in_array($plugin->course_status['status'], array('prepare','run','analyze','finished'))){
unset($data[$seminar_id]);
continue;
}
$data[$seminar_id]['link'] = "<a href=\"".PluginEngine::GetLink($plugin,array('cid' => $seminar_id)) . "\">"
. htmlReady($plugin->course_status['status'])."</a>";
$data[$seminar_id]['zensus_status'] = $plugin->course_status['status'];
$data[$seminar_id]['zensus_numvotes'] = $plugin->course_status['numvotes'];
$data[$seminar_id]['time_frame_begin'] = $plugin->course_status['time_frame']['begin'];
$data[$seminar_id]['time_frame_end'] = $plugin->course_status['time_frame']['end'];
$data[$seminar_id]['plugin_activated'] = true;
} else {
$plugin = null;
if($_SESSION['zensus_admin']['check_eval'] || $_SESSION['zensus_admin']['plugin_activated']){
unset($data[$seminar_id]);
continue;
}
$data[$seminar_id]['plugin_activated'] = false;
}
$data[$seminar_id]['dozenten'] = join(', ',(array)$semdata['dozenten']);
$sorter[$seminar_id] = $data[$seminar_id][$_SESSION['zensus_admin']['sortby']['field']];
}
if($_SESSION['zensus_admin']['sortby']['field'] && count($data) && count($data) == count($sorter)){
array_multisort($sorter, ($_SESSION['zensus_admin']['sortby']['direction'] ? SORT_ASC : SORT_DESC), $data);
}
if (Request::submitted('export')) {
ob_end_clean();
$captions = array('Veranstaltung', 'Dozenten', 'Teilnehmer Stud.IP', 'Zensus Status', 'Teilnehmer Zensus', 'Plugin aktiv', 'Startzeit','Endzeit');
$csvdata = array();
$c = 0;
foreach($data as $seminar_id => $semdata) {
$csvdata[$c][] = $semdata['Name'];
$csvdata[$c][] = $semdata['dozenten'];
$csvdata[$c][] = $semdata['teilnehmer_anzahl_aktuell'];
$csvdata[$c][] = $semdata['zensus_status'];
$csvdata[$c][] = (int)$semdata['zensus_numvotes'];
$csvdata[$c][] = $semdata['plugin_activated'] ? 'ja' : 'nein';
$csvdata[$c][] = $semdata['begin_evaluation'] ? date("d.m.Y", $semdata['begin_evaluation']) : ($semdata['time_frame_begin'] ? date("d.m.Y", $semdata['time_frame_begin']) : '');
$csvdata[$c][] = $semdata['end_evaluation'] ? date("d.m.Y", $semdata['end_evaluation']) : ($semdata['time_frame_end'] ? date("d.m.Y", $semdata['time_frame_end']) : '');
++$c;
}
$tmpname = md5(uniqid('tmp'));
if (array_to_csv($csvdata, $GLOBALS['TMP_PATH'] . '/' . $tmpname, $captions)) {
header('Location: ' . FileManager::getDownloadURLForTemporaryFile($tmpname, 'Veranstaltungen_Lehrevaluation.csv'));
page_close();
die();
}
}
$semlink = $GLOBALS['perm']->have_studip_perm('admin', $_SESSION['zensus_admin']['institut_id']) ? 'dispatch.php/course/dates?cid=' : 'dispatch.php/course/details?sem_id=';
foreach($data as $seminar_id => $semdata) {
$sem = new Seminar($seminar_id);
$dates = $sem->getDatesExport(array(
'semester_id' => $_SESSION['_default_sem'],
'show_room' => false
));
echo "<tr>\n";
echo '<td align="center"><input type="checkbox" class="CourseSelector" name="sem_choosen['.$seminar_id.']" value="1" '.($semdata['choosen'] ? 'checked':'').'></td>';
printf ("<td>
<a title=\"%s\" href=\"%s\">
%s
</a></td>
<td>
<a title=\"%s\" href=\"%s\">
%s%s%s
</a>
<a data-dialog href=\"" . URLHelper::getScriptLink('dispatch.php/course/details/index/') . "%s\">
". Icon::create('info-circle', 'inactive')->asImg(
'16px',
[
'title' => _("Veranstaltungsdetails"),
'class' => 'text-bottom'
]
) ."
</a>
</td>
<td align=\"center\">
%s</td>
<td align=\"center\">%s</td>
<td align=\"center\">%s</td>
<td align=\"center\">%s</td>
<td align=\"center\">%s</td>
<td align=\"center\">%s</td>
<td align=\"center\">%s</td>
<td align=\"center\">%s</td>
<td align=\"center\">%s</td>
",
htmlready($dates),
UrlHelper::getLink($semlink.$seminar_id),
htmlready($semdata['VeranstaltungsNummer']),
htmlready($dates),
UrlHelper::getLink($semlink.$seminar_id),
htmlready(substr($semdata['Name'], 0, 60)),
(strlen($semdata['Name'])>60) ? "..." : "",
!$semdata['visible'] ? ' ' . _("(versteckt)") : '',
$seminar_id,
htmlReady($semdata['dozenten']),
htmlReady($semdata['teilnehmer_anzahl_aktuell']),
$semdata['link'],
htmlReady($semdata['zensus_numvotes']),
($semdata['plugin_activated'] ? 'ja' : 'nein') ,
$semdata['begin_evaluation'] ? date("d.m.Y", $semdata['begin_evaluation']) : '-',
$semdata['end_evaluation'] ? date("d.m.Y", $semdata['end_evaluation']) : '-',
($semdata['time_frame_begin'] ? date("d.m.Y", $semdata['time_frame_begin']) : '-'),
($semdata['time_frame_end'] ? date("d.m.Y", $semdata['time_frame_end']) : '-')
);
echo "</tr>";
}
echo "</table>";
echo $form->getFormEnd();
if ($_SESSION['zensus_admin']['institut_id'] && !count($data)) {
echo MessageBox::info(_("Im gewählten Bereich existieren keine Veranstaltungen"));
}
} else {
echo MessageBox::info(_("Sie wurden noch keinen Einrichtungen zugeordnet."));
}
PageLayout::setTitle($this->getDisplayname());
$layout = $GLOBALS['template_factory']->open('layouts/base');
$layout->content_for_layout = ob_get_clean();
echo $layout->render();
}
function getInstitute($seminare_condition){
global $perm, $user;
$db = new DB_Seminar();
$db2 = new DB_Seminar();
if (!$perm->have_perm('root')) {
$z_role = current(array_filter(RolePersistence::getAssignedRoles($user->id), function ($r) {
return $r->rolename == 'ZensusAdmin';
}));
$z_institutes = array_filter(RolePersistence::getAssignedRoleInstitutes($user->id, $z_role->roleid));
}
if ($perm->have_perm('root') || !count($z_institutes)) {
$db->query("SELECT COUNT(*) FROM seminare WHERE 1 $seminare_condition");
$db->next_record();
$_my_inst['all'] = array("name" => _("alle") , "num_sem" => $db->f(0));
$db->query("SELECT a.Institut_id,a.Name, 1 AS is_fak, count(seminar_id) AS num_sem FROM Institute a
LEFT JOIN seminare ON(seminare.Institut_id=a.Institut_id $seminare_condition ) WHERE a.Institut_id=fakultaets_id GROUP BY a.Institut_id ORDER BY is_fak,Name,num_sem DESC");
} else {
$db->query("SELECT b.Institut_id,b.Name, IF(b.Institut_id=b.fakultaets_id,1,0) AS is_fak,count(seminar_id) AS num_sem FROM Institute b
LEFT JOIN seminare ON(seminare.Institut_id=b.Institut_id $seminare_condition ) WHERE b.Institut_id IN ('" . join("','", $z_institutes) ."') GROUP BY b.Institut_id ORDER BY is_fak,Name,num_sem DESC");
}
while($db->next_record()){
$_my_inst[$db->f("Institut_id")] = array("name" => $db->f("Name"), "is_fak" => $db->f("is_fak"), "num_sem" => $db->f("num_sem"));
if ($db->f("is_fak")){
$_my_inst[$db->f("Institut_id").'_all'] = array("name" => '[Alle unter '.$db->f("Name").']', "is_fak" => 'all', "num_sem" => $db->f("num_sem"));
$db2->query("SELECT a.Institut_id, a.Name,count(seminar_id) AS num_sem FROM Institute a
LEFT JOIN seminare ON(seminare.Institut_id=a.Institut_id $seminare_condition ) WHERE fakultaets_id='" . $db->f("Institut_id") . "' AND a.Institut_id!='" .$db->f("Institut_id") . "'
GROUP BY a.Institut_id ORDER BY a.Name,num_sem DESC");
$num_inst = 0;
$num_sem_alle = $db->f("num_sem");
while ($db2->next_record()){
if(!$_my_inst[$db2->f("Institut_id")]){
++$num_inst;
$num_sem_alle += $db2->f("num_sem");
}
$_my_inst[$db2->f("Institut_id")] = array("name" => $db2->f("Name"), "is_fak" => 0 , "num_sem" => $db2->f("num_sem"));
}
$_my_inst[$db->f("Institut_id")]["num_inst"] = $num_inst;
$_my_inst[$db->f("Institut_id").'_all']["num_inst"] = $num_inst;
$_my_inst[$db->f("Institut_id").'_all']["num_sem"] = $num_sem_alle;
}
}
return $_my_inst;
}
function getSeminareData($seminare_condition){
global $perm;
$db = new DB_Seminar();
$db2 = new DB_Seminar();
$datafield1 = md5('UNIZENSUSPLUGIN_BEGIN_EVALUATION');
$datafield2 = md5('UNIZENSUSPLUGIN_END_EVALUATION');
$pluginid = $this->zensuspluginid;
$ret = array();
list($institut_id, $all) = explode('_', $_SESSION['zensus_admin']['institut_id']);
if ($institut_id == "all" && $perm->have_perm("root"))
$query = "SELECT Name,Seminar_id as seminar_id, VeranstaltungsNummer, visible FROM seminare WHERE 1 $seminare_condition ORDER BY Name";
elseif ($all == 'all')
$query = "SELECT seminare.Name,seminare.Seminar_id as seminar_id, seminare.VeranstaltungsNummer, seminare.visible FROM seminare LEFT JOIN seminar_inst USING (Institut_id)
INNER JOIN Institute ON seminar_inst.institut_id = Institute.Institut_id WHERE Institute.fakultaets_id = '{$institut_id}' $seminare_condition
GROUP BY seminare.Seminar_id ORDER BY Name";
else
$query = "SELECT seminare.Name,seminare.Seminar_id as seminar_id, seminare.VeranstaltungsNummer, seminare.visible FROM seminare LEFT JOIN seminar_inst USING (Institut_id)
WHERE seminar_inst.institut_id = '{$institut_id}' $seminare_condition
GROUP BY seminare.Seminar_id ORDER BY Name";
$db->query($query);
while($db->next_record()){
$seminar_id = $db->f("seminar_id");
$ret[$seminar_id] = $db->Record;
$query2 = "SELECT seminar_user.user_id,username,Nachname FROM seminar_user LEFT JOIN auth_user_md5 USING (user_id) WHERE seminar_id='$seminar_id' AND status='dozent' ORDER BY position,Nachname";
$db2->query($query2);
$c = 0;
while($db2->next_record()){
$ret[$seminar_id]['dozenten'][$db2->f('username')] = $db2->f('Nachname');
if(++$c > 2) {
$ret[$seminar_id]['dozenten'][] = '...';
break;
}
}
$query2 = "SELECT COUNT(*) FROM seminar_user WHERE seminar_id='$seminar_id' AND status IN ('autor')";
$db2->query($query2);
$db2->next_record();
$ret[$seminar_id]['teilnehmer_anzahl_aktuell'] = $db2->f(0);
$query2 = "SELECT datafield_id,content FROM datafields_entries WHERE range_id='$seminar_id' AND datafield_id IN('$datafield1','$datafield2')";
$db2->query($query2);
while($db2->next_record()){
if($db2->f('datafield_id') == $datafield1) $ret[$seminar_id]['begin_evaluation'] = UniZensusPlugin::SQLDateToTimestamp($db2->f('content'));
if($db2->f('datafield_id') == $datafield2) $ret[$seminar_id]['end_evaluation'] = UniZensusPlugin::SQLDateToTimestamp($db2->f('content'));
}
$query2 = "SELECT state, 'sem' AS activated_by
FROM plugins_activated pat
WHERE pat.pluginid = '$pluginid'
AND pat.poiid = 'sem$seminar_id'
UNION SELECT 'on', 'default'
FROM seminar_inst s
JOIN Institute i ON i.Institut_id = s.institut_id
JOIN plugins_default_activations pa ON i.fakultaets_id = pa.institutid
OR i.Institut_id = pa.institutid
JOIN plugins p ON pa.pluginid = p.pluginid
WHERE s.seminar_id = '$seminar_id'
AND p.pluginid = '$pluginid'";
$db2->query($query2);
while($db2->next_record()){
$ret[$seminar_id]['activated_by_' . $db2->f('activated_by')] = $db2->f('state');
}
}
return $ret;
}
function getExportData($key, $seminar_id)
{
static $data = array();
if (!$data[$seminar_id]) {
$data = array();
$data[$seminar_id] = UniZensusPlugin::getAdditionalExportData($seminar_id);
}
if ($key == 'teilnehmer_anzahl_aktuell') {
if ($data[$seminar_id]['eval_participants']) {
return zensus_xmltag($key, $data[$seminar_id]['eval_participants']);
} else {
return zensus_xmltag($key,DbManager::get()->query("SELECT COUNT(*) FROM seminar_user WHERE seminar_id='".$seminar_id."' AND status='autor'")->fetchColumn());
}
}
if ($key == 'resultpublic') {
return zensus_xmltag($key, (int)$data[$seminar_id]['eval_public']);
}
if ($key == 'resultstore') {
return zensus_xmltag($key, (int)$data[$seminar_id]['eval_stored']);
}
}
function export_action()
{
global $ex_sem, $ex_only_homeinst,$ex_sem_class, $ex_only_visible;
global $xml_groupnames_fak,$xml_names_fak,$xml_groupnames_inst,$xml_names_inst
,$xml_groupnames_lecture,$xml_names_lecture,$xml_groupnames_person
,$xml_names_person,$xml_groupnames_studiengaenge,$xml_names_studiengaenge;
require_once ('lib/export/export_xml_vars.inc.php'); // XML-Variablen
//Uni OL
/*
$xml_names_lecture['teilnehmer_anzahl_aktuell'] = array($this, 'getExportData');
$xml_names_lecture['resultpublic'] = array($this, 'getExportData');
$xml_names_lecture['resultstore'] = array($this, 'getExportData');
*/
$authcode = Request::option('authcode');
if ($authcode) {
$auth_uid = DbManager::get()->query("SELECT user_id FROM user_config WHERE field='UNIZENSUSPLUGIN_AUTH_TOKEN' AND value='$authcode'")->fetchColumn();
if (!$auth_uid) $export_error = 'wrong authcode';
} else {
$export_error = 'missing authcode';
}
$ex_tstamp = Request::get('ex_tstamp');
list($y,$M,$d,$h,$m) = explode('-', $ex_tstamp);
$tstamp = mktime($h,$m,0,$M,$d,(int)$y);
$hash = md5(get_config('UNIZENSUSPLUGIN_SHARED_SECRET1') . $ex_tstamp . get_config('UNIZENSUSPLUGIN_SHARED_SECRET2'));
if ((Request::option('ex_hash') != $hash || $tstamp < (time() - 600))) {
$export_error = 'authorization failed';
} else {
if (Request::option('ex_sem') == 'next') {
$ex_sem = Semester::findNext()->semester_id;
} else {
$ex_sem = Semester::findCurrent()->semester_id;
}
if (!$ex_sem) {
$export_error = 'no valid semester found';
}
}
$range_id = Request::option('range_id', 'root');
$ex_only_visible = Request::int('ex_only_visible', 0);
$ex_only_homeinst = Request::int('ex_only_homeinst', 1);
$ex_sem_class = Request::intArray('ex_sem_class');
if (!count($ex_sem_class)) $ex_sem_class[] = 1;
ini_set('memory_limit', '256M');
while(ob_get_level()) ob_end_clean();
header("Content-type: text/xml; charset=utf-8");
if ($export_error) {
header('HTTP/1.1 403 Forbidden');
echo '<?xml version="1.0"?>' . chr(10);
echo zensus_xmltag('studip_export_error_msg', strip_tags($export_error));
exit();
}
zensus_export_range($range_id, $ex_sem, 'direct',$auth_uid);
}
public static function onEnable($plugin_id)
{
//allow for nobody
$rp = new RolePersistence();
$rp->assignPluginRoles($plugin_id, range(1,7));
}
}