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
|
<?php
# Lifter002: TODO
# Lifter005: 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.
// +--------------------------------------------------------------------------+
# Define constants ========================================================== #
# ===================================================== end: define constants #
# Include all required files ================================================ #
require_once 'lib/evaluation/evaluation.config.php';
require_once HTML;
# ====================================================== end: including files #
/**
* Library with common static functions for the evaluation module
*
* @author Alexander Willner <mail@AlexanderWillner.de>
*
* @copyright 2004 Stud.IP-Project
* @access public
* @package evaluation
*
*/
class EvalCommon
{
/**
* Creates this funny blue title bar
* @param string $title The title
* @param string $iconURL The URL for the icon
*/
public static function createTitle($title, $iconURL = "", $padding = 0)
{
$table = new HTML("table");
$table->addAttr("border", "0");
$table->addAttr("class", "blank");
$table->addAttr("align", "center");
$table->addAttr("cellspacing", "0");
$table->addAttr("cellpadding", $padding);
$table->addAttr("width", "100%");
$trTitle = new HTML("tr");
$trTitle->AddAttr("valign", "top");
$trTitle->AddAttr("align", "center");
$tdTitle = new HTML("td");
if ($iconURL) {
$tdTitle->addAttr("class", "table_header_bold");
} else {
$tdTitle->addAttr("class", "content_body");
}
$tdTitle->addAttr("colspan", "2");
$tdTitle->addAttr("align", "left");
$tdTitle->addAttr("valign", "middle");
if ($iconURL) {
$imgTitle = new HTMLempty ("img");
$imgTitle->addAttr("src", $iconURL);
$imgTitle->addAttr("alt", $title);
$imgTitle->addAttr("align", "bottom");
$tdTitle->addContent($imgTitle);
}
$bTitle = new HTML ("b");
$bTitle->addContent($title);
$tdTitle->addContent($bTitle);
$trTitle->addContent($tdTitle);
$table->addContent($trTitle);
return $table;
}
/**
* Creates a simple image for the normal top of an modulepage
* @param string $imgURL The URL for the icon
* @param string $imgALT The description for the icon
*/
public static function createImage($imgURL, $imgALT, $extra = "")
{
$img = new HTMLempty ("img");
$img->addAttr("border", "0");
$img->addAttr("valign", "middle");
$img->addAttr("src", $imgURL);
if (empty($extra)) {
$img->addAttr("alt", $imgALT);
$img->addAttr("title", $imgALT);
} else {
$img->addString($extra);
}
return $img;
}
/**
* Creates the Javascript static function, which will open an evaluation popup
*/
static function createEvalShowJS($isPreview = NO, $as_object = YES)
{
$html = "";
$html .=
"<script type=\"text/javascript\" language=\"JavaScript\">" .
" function openEval( evalID ) {" .
" evalwin = window.open(STUDIP.URLHelper.getURL('show_evaluation.php?evalID=' + evalID + '&isPreview=" . $isPreview . "'), " .
" evalID, 'width=790,height=500,scrollbars=yes,resizable=yes');" .
" evalwin.focus();" .
" }\n" .
"</script>\n";
$div = new HTML ("div");
$div->addHTMLContent($html);
if ($as_object) {
return $div;
}
return $html;
}
/**
* Creates a link, which will open an evaluation popup
*/
static function createEvalShowLink($evalID, $content, $isPreview = NO, $as_object = YES)
{
$html = "";
$html .=
"<a " .
"href=\"" . URLHelper::getLink('show_evaluation.php?evalID=' . $evalID . '&isPreview=' . $isPreview) . "\" " .
"target=\"" . $evalID . "\" " .
"onClick=\"openEval('" . $evalID . "'); return false;\">" .
(is_object($content) ? str_replace("\n", "", $content->createContent()) : $content) .
"</a>";
$div = new HTML ("div");
$div->addHTMLContent($html);
if ($as_object) {
return $div;
}
return $html;
}
/**
* @param $object
* @param string $errortitle
* @return MessageBox
* @deprecated
*/
public static function createErrorReport(AuthorObject $object, string $errortitle = ''): MessageBox
{
$errors = $object->getErrors();
if (!$errortitle) {
if (count($errors) > 1) {
$errortitle = _('Es sind Fehler aufgetreten.');
} else {
$errortitle = _('Es ist ein Fehler aufgetreten.');
}
}
$details = array_map(
function ($error) {
return "#{$error['code']}: {$error['string']}";
},
$errors
);
return MessageBox::error($errortitle, $details);
}
/**
* Returns the rangeID
*/
public static function getRangeID()
{
$rangeID = Request::option('range_id') ?: Context::getId();
if (empty ($rangeID) || ($rangeID == get_username($GLOBALS['user']->id)))
$rangeID = $GLOBALS['user']->id;
return $rangeID;
}
/**
* Checks and transforms a date into a UNIX (r)(tm) timestamp
* @access public
* @static
* @param integer $day The day
* @param integer $month The month
* @param integer $year The year
* @param integer $hour The hour (optional)
* @param integer $minute The minute (optional)
* @param integer $second The second (optional)
* @return integer If an error occurs -> -1. Otherwise the UNIX-timestamp
*/
public static function date2timestamp(
$day,
$month,
$year,
$hour = 0,
$minute = 0,
$second = 0
)
{
if (!checkdate((int)$month, (int)$day, (int)$year) ||
$hour < 0 || $hour > 24 ||
$minute < 0 || $minute > 59 ||
$second < 0 || $second > 59) {
return -1;
}
// windows cant count that mutch
if ($year < 1971) {
$year = 1971;
} elseif ($year > 2037) {
$year = 2037;
}
return mktime($hour, $minute, $second, $month, $day, $year);
}
}
?>
|