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
|
<?php
/**
* Settings_StudiesController - Administration of all user studies related
* settings
*
* 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 Jan-Hendrik Willms <tleilax+studip@gmail.com>
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
* @category Stud.IP
* @since 2.4
*/
require_once 'settings.php';
class Settings_StudiesController extends Settings_SettingsController
{
/**
* Set up this controller.
*
* @param String $action Name of the action to be invoked
* @param Array $args Arguments to be passed to the action method
*/
public function before_filter(&$action, &$args)
{
parent::before_filter($action, $args);
if (!in_array($this->user->perms, words('autor tutor dozent'))) {
throw new AccessDeniedException();
}
PageLayout::setHelpKeyword('Basis.HomepageUniversitäreDaten');
PageLayout::setTitle(_('Studiengang bearbeiten'));
Navigation::activateItem('/profile/edit/studies');
$this->allow_change = [
'sg' => !StudipAuthAbstract::CheckField('studiengang_id', $this->user->auth_plugin)
&& (Config::get()->ALLOW_SELFASSIGN_STUDYCOURSE || $GLOBALS['perm']->have_perm('admin')),
'in' => Config::get()->ALLOW_SELFASSIGN_INSTITUTE || $GLOBALS['perm']->have_perm('admin'),
];
}
/**
* Displays the study information of a user.
*/
public function index_action()
{
$this->faecher = StudyCourse::findBySQL('1 ORDER BY name');
$this->abschluesse = Abschluss::findBySQL('1 ORDER by name');
$this->available_institutes = Institute::getInstitutes();
$this->institutes = $this->user->institute_memberships->filter(function ($a) {
return $a->inst_perms === 'user';
});
}
/**
* Stores the study information of a user (subject and degree-wise).
*/
public function store_sg_action()
{
CSRFProtection::verifyUnsafeRequest();
$any_change = false;
$fach_abschluss_delete = Request::getArray('fach_abschluss_delete');
if (count($fach_abschluss_delete) > 0) {
foreach ($fach_abschluss_delete as $fach_id => $abschluesse) {
$row_count = UserStudyCourse::deleteBySQL(
'user_id = ? AND fach_id = ? AND abschluss_id IN (?)',
[$this->user->user_id, $fach_id, $abschluesse]);
$any_change = $row_count > 0;
// if we have no studies anymore we delete the visibilitysetting
if (!$this->hasStudiengang()) {
Visibility::removePrivacySetting('studying');
}
}
}
if (!$any_change) {
$change_fachsem = Request::getArray('change_fachsem');
foreach ($change_fachsem as $fach_id => $abschluesse) {
foreach ($abschluesse as $abschluss_id => $semester) {
$user_stc = UserStudyCourse::find([
$this->user->user_id,
$fach_id,
$abschluss_id
]);
if ($user_stc) {
$user_stc->semester = $semester;
$any_change = $user_stc->store() !== false;
}
}
}
$new_studiengang = Request::option('new_studiengang');
if ($new_studiengang && $new_studiengang != 'none') {
if (!$this->hasStudiengang()) {
Visibility::addPrivacySetting(_('Wo ich studiere'), 'studying', 'studdata');
}
$abschluss_id = Request::option('new_abschluss');
$duplicate = UserStudyCourse::exists([
$this->user->user_id,
$new_studiengang,
$abschluss_id,
]);
if ($duplicate) {
PageLayout::postInfo(_('Dieser Studiengang ist bereits eingetragen'));
} else {
$any_change = !is_null(UserStudyCourse::create([
'user_id' => $this->user->user_id,
'fach_id' => $new_studiengang,
'semester' => Request::int('fachsem'),
'abschluss_id' => Request::option('new_abschluss'),
]));
}
}
// store versions if module management is enabled
$change_versions = Request::getArray('change_version');
foreach ($change_versions as $fach_id => $abschluesse) {
foreach ($abschluesse as $abschluss_id => $version_id) {
$version = StgteilVersion::findByFachAbschluss(
$fach_id, $abschluss_id, $version_id
);
$version = reset($version);
if ($version && $version->hasPublicStatus('genehmigt')) {
$user_stc = UserStudyCourse::find([
$this->user->user_id,
$fach_id,
$abschluss_id
]);
if ($user_stc) {
$user_stc->version_id = $version->getId();
$any_change = $user_stc->store() !== false;
}
}
}
}
}
if ($any_change) {
PageLayout::postSuccess(_('Die Zuordnung zu Studiengängen wurde geändert.'));
setTempLanguage($this->user->user_id);
$this->postPrivateMessage(_('Die Zuordnung zu Studiengängen wurde geändert!') . "\n");
restoreLanguage();
}
$this->redirect('settings/studies');
}
/**
* Stores the study information of a user (institute-wise).
*/
public function store_in_action()
{
CSRFProtection::verifyUnsafeRequest();
$inst_delete = Request::optionArray('inst_delete');
if (count($inst_delete) > 0) {
$query = "DELETE FROM user_inst WHERE user_id = ? AND Institut_id = ?";
$statement = DBManager::get()->prepare($query);
foreach ($inst_delete as $institute_id) {
$statement->execute([
$this->user->user_id,
$institute_id,
]);
if ($statement->rowCount() > 0) {
StudipLog::log('INST_USER_DEL', $institute_id, $this->user->user_id);
NotificationCenter::postNotification('UserInstitutionDidDelete', $institute_id, $this->user->user_id);
$delete = true;
}
}
}
$new_inst = Request::option('new_inst');
if ($new_inst) {
$query
= "INSERT IGNORE INTO user_inst
(user_id, Institut_id, inst_perms)
VALUES (?, ?, 'user')";
$statement = DBManager::get()->prepare($query);
$statement->execute([
$this->user->user_id,
$new_inst,
]);
if ($statement->rowCount() > 0) {
StudipLog::log('INST_USER_ADD', $new_inst, $this->user->user_id, 'user');
NotificationCenter::postNotification('UserInstitutionDidCreate', $new_inst, $this->user->user_id);
$new = true;
}
}
if ($delete || $new) {
PageLayout::postSuccess(_('Die Zuordnung zu Einrichtungen wurde geändert.'));
setTempLanguage($this->user->user_id);
$this->postPrivateMessage(_('Die Zuordnung zu Einrichtungen wurde geändert.') . "\n");
restoreLanguage();
}
$this->redirect('settings/studies');
}
private function hasStudiengang()
{
$count = UserStudyCourse::countBySql('user_id = ?', [$this->user->user_id]);
return $count > 0;
}
}
|