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
|
<?php
# Lifter002: TODO
# Lifter007: TODO
# Lifter003: TODO
# Lifter010: TODO
// +--------------------------------------------------------------------------+
// This file is part of Stud.IP
// Copyright (C) 2001-2004 Stud.IP
// +--------------------------------------------------------------------------+
// 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/evaluation/evaluation.config.php';
/**
* Databaseclass for all evaluationobjects
*
* @author Alexander Willner <mail@AlexanderWillner.de>
*
* @copyright 2004 Stud.IP-Project
* @access public
* @package evaluation
*
*/
class EvaluationObjectDB extends DatabaseObject
{
/**
* Constructor
* @access public
*/
public function __construct()
{
parent::__construct();
$this->instanceof = 'EvalDBObject';
}
/**
* Gets the name of the range. Copied somewhere from Stud.IP...
* @access public
* @param string $rangeID the rangeID
* @param boolean $html_decode (optional)
* @return string The name of the range
*/
public function getRangename($rangeID, $html_decode = true)
{
if ($rangeID == "studip") {
return _('Systemweite Evaluationen');
}
$o_type = get_object_type($rangeID, ['sem', 'user', 'inst']);
if (in_array($o_type, ['sem','inst','fak'])) {
$range = get_object_by_range_id($rangeID);
if ($range) {
$rangename = $range->getFullname('number-name-semester');
} else {
$rangename = _('Kein Titel gefunden.');
}
return $rangename;
}
if ($o_type != 'user') {
$user_id = get_userid($rangeID);
} else {
$user_id = $rangeID;
}
if ($user_id != $GLOBALS['user']->id) {
$rangename = _('Profil') . ': '
. get_fullname($user_id, 'full', true)
. ' (' . get_username($user_id) . ')';
} else {
$rangename = _('Profil');
}
return $rangename;
}
/**
* Gets the global Studi.IP perm
* @access public
* @param boolean $as_value If YES return as value
* @return string the perm or NULL
*/
public static function getGlobalPerm($as_value = false)
{
if ($GLOBALS['perm']->have_perm("root")) {
return $as_value ? 63 : "root";
} elseif ($GLOBALS['perm']->have_perm("admin")) {
return $as_value ? 31 : "admin";
} elseif ($GLOBALS['perm']->have_perm("dozent")) {
return $as_value ? 15 : "dozent";
} elseif ($GLOBALS['perm']->have_perm("tutor")) {
return $as_value ? 7 : "dozent";
} elseif ($GLOBALS['perm']->have_perm("autor")) {
return $as_value ? 3 : "autor";
} elseif ($GLOBALS['perm']->have_perm("user")) {
return $as_value ? 1 : "user";
} else {
return $as_value ? 0 : NULL;
}
}
/**
* Get the Stud.IP-Perm for a range
* @param string $rangeID The range id
* @param string $userID The user id
* @param boolean $as_value If YES return as value
* @access public
* @return string
*/
public static function getRangePerm($rangeID, $userID = NULL, $as_value = false)
{
if (!$rangeID) {
print "no rangeID!<br>";
return NULL;
}
$userID = ($userID) ? $userID : $GLOBALS['user']->id;
$range_perm = $GLOBALS['perm']->get_studip_perm($rangeID, $userID);
if ($rangeID == $userID) {
return ($as_value) ? 63 : "root";
}
if (($rangeID == "studip") && ($GLOBALS['perm']->have_perm("root"))) {
return ($as_value) ? 63 : "root";
}
switch ($range_perm) {
case "root":
return ($as_value) ? 63 : "root";
case "admin":
return ($as_value) ? 31 : "admin";
case "dozent":
return ($as_value) ? 15 : "dozent";
case "tutor":
return ($as_value) ? 7 : "dozent";
case "autor":
return ($as_value) ? 3 : "autor";
case "user":
return ($as_value) ? 1 : "user";
default:
return 0;
}
}
/**
* Look for all rangeIDs for my permissions
* @param object Perm &$permObj PHP-LIB-Perm-Object
* @param object User &$userObj PHP-LIB-User-Object
* @param string $rangeID RangeID of actual page
*/
public function getValidRangeIDs(&$permObj, &$userObj, $rangeID)
{
$range_ids = [];
$username = $userObj->username;
$range_ids += [
$username => ["name" => _("Profil")]
];
if ($permObj->have_perm("root")) {
$range_ids += ["studip" => ["name" => _("Stud.IP-System")]];
if (($adminRange = $this->getRangename($rangeID)) &&
$rangeID != $userObj->id)
$range_ids += [$rangeID => ["name" =>
$adminRange]];
} else if ($permObj->have_perm("admin")) {
if (($adminRange = $this->getRangename($rangeID)) &&
$rangeID != $userObj->id) {
$range_ids += [$rangeID => ["name" =>
$adminRange]];
}
} else if ($permObj->have_perm("dozent") || $permObj->have_perm("tutor")) {
if ($ranges = search_range("")) {
$range_ids += $ranges;
}
}
return $range_ids;
}
/**
* Returns the number of ranges with no permission
* @access public
* @param EvaluationObject &$eval The evaluation
* @param boolean $return_ids If YES return the ids
* @return array|integer Number of ranges with no permission or array of ids
*/
public static function getEvalUserRangesWithNoPermission(&$eval, $return_ids = false)
{
$no_permisson = 0;
$rangeIDs = $eval->getRangeIDs();
$no_permisson_ranges = [];
if (!is_array($rangeIDs)) {
$rangeIDs = [$rangeIDs];
}
foreach ($eval->getRangeIDs() as $rangeID) {
$user_perm = EvaluationObjectDB::getRangePerm($rangeID, $GLOBALS['user']->id, YES);
// every range with a lower perm than Tutor
if ($user_perm < 7) {
$no_permisson++;
$no_permisson_ranges[] = $rangeID;
}
}
if ($return_ids == YES) {
return $no_permisson_ranges;
}
return ($no_permisson > 0) ? $no_permisson : NO;
}
/**
* Gets the public template ids
* @access public
* @param string $searchString The name of the template
* @return array The public template ids
*/
public function getPublicTemplateIDs($searchString)
{
$sql = "
SELECT eval_id FROM eval
LEFT JOIN auth_user_md5 ON user_id = author_id
WHERE shared = 1
AND author_id <> :current_user
AND (title LIKE :search_string
OR text LIKE :search_string
OR Vorname LIKE :search_string
OR Nachname LIKE :search_string
OR username LIKE :search_string
)
ORDER BY title";
return DBManager::get()->fetchFirst(
$sql, [':current_user' => $GLOBALS['user']->id, ':search_string' => '%' . $searchString . '%']
);
}
/**
* Return all evaluationIDs in a specific range
*
* @access public
* @param string $rangeID Specific rangeID or it is a template
* @param string $state Specific state
* @return array All evaluations in this range and this state
*/
public function getEvaluationIDs($rangeID = "", $state = "")
{
if (!empty ($rangeID) && !is_scalar($rangeID)) {
return $this->throwError(1, _("Übergebene RangeID ist ungültig."));
}
if ($state != "" &&
$state != EVAL_STATE_NEW &&
$state != EVAL_STATE_ACTIVE &&
$state != EVAL_STATE_STOPPED) {
return $this->throwError(2, _("Übergebener Status ist ungültig."));
}
if (get_userid($rangeID) != NULL && $rangeID != NULL) {
$rangeID = get_userid($rangeID);
}
if (!empty ($rangeID)) {
$sql =
"SELECT" .
" a.eval_id " .
"FROM" .
" eval_range a, eval b " .
"WHERE" .
" a.eval_id = b.eval_id" .
" AND " .
" a.range_id = ?";
$param = $rangeID;
} else {
$sql =
"SELECT" .
" b.eval_id " .
"FROM" .
" eval b " .
"LEFT JOIN" .
" eval_range " .
"ON" .
" b.eval_id = eval_range.eval_id " .
"WHERE" .
" eval_range.eval_id IS NULL" .
" AND" .
" b.author_id = ?";
$param = $GLOBALS['user']->id;
}
if ($state == EVAL_STATE_NEW)
$sql .= " AND (b.startdate IS NULL OR b.startdate > " . time() . ")";
elseif ($state == EVAL_STATE_ACTIVE)
$sql .=
" AND b.startdate < " . time() . "" .
" AND (" .
" (b.timespan IS NULL AND b.stopdate > " . time() . ")" .
" OR" .
" (b.stopdate IS NULL AND (b.startdate+b.timespan) > " . time() . ")" .
" OR" .
" (b.timespan IS NULL AND b.stopdate IS NULL)" .
" )";
elseif ($state == EVAL_STATE_STOPPED)
$sql .=
" AND b.startdate < " . time() . "" .
" AND (" .
" (b.timespan IS NULL AND b.stopdate <= " . time() . ")" .
" OR" .
" (b.stopdate IS NULL AND (b.startdate+b.timespan) <= " . time() . ")" .
" )";
$sql .= " ORDER BY chdate DESC";
return DBManager::get()->fetchFirst($sql, [$param]);
}
/**
* Gets the evaluation id for a object id
* @access public
* @param string $objectID The object id
* @return string The evaluation id or nothing
*/
public function getEvalID($objectID)
{
if (empty ($objectID)) {
throw new Exception("FATAL ERROR in getEvalID ;)");
}
$type = EvaluationObjectDB::getType($objectID);
switch ($type) {
case INSTANCEOF_EVALANSWER:
$parentID = EvaluationAnswerDB::getParentID($objectID);
break;
case INSTANCEOF_EVALQUESTION:
$parentID = EvaluationQuestionDB::getParentID($objectID);
break;
case INSTANCEOF_EVALGROUP:
$parentID = EvaluationGroupDB::getParentID($objectID);
break;
default:
return $objectID;
}
return EvaluationObjectDB::getEvalID($parentID);
}
/**
* Returns the type of an objectID
* @access public
* @param string $objectID The objectID
* @return string INSTANCEOF_x, else NO
*/
public function getType($objectID)
{
return (new EvaluationDB ())->getType($objectID);
}
}
|