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
|
<?php
# Lifter002: TODO
# Lifter007: TODO
# Lifter003: TODO
# Lifter010: TODO
/**
* the evaluation participation page :)
*
* @author mcohrs <michael A7 cohrs D07 de>
* @author Michael Riehemann <michael.riehemann@uni-oldenburg.de>
* @copyright 2004 Stud.IP-Project
* @access public
* @package evaluation
* @modulegroup evaluation_modules
*
*/
// +---------------------------------------------------------------------------+
// 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.
// +---------------------------------------------------------------------------+
//TODO: auf TemplateFactory umstellen
# PHP-LIB: open session ===================================================== #
require '../lib/bootstrap.php';
page_open ( ["sess" => "Seminar_Session",
"auth" => "Seminar_Auth",
"perm" => "Seminar_Perm",
"user" => "Seminar_User"]);
$auth->login_if ($auth->auth["uid"] == "nobody");
$perm->check ("autor");
# ============================================================== end: PHP-LIB #
# Include all required files ================================================ #
require_once 'lib/evaluation/evaluation.config.php';
require_once 'lib/seminar_open.php';
require_once EVAL_FILE_EVAL;
require_once EVAL_FILE_EVALDB;
require_once EVAL_FILE_SHOW_TREEVIEW;
require_once EVAL_FILE_EVALTREE;
require_once EVAL_LIB_COMMON;
require_once EVAL_LIB_SHOW;
# ====================================================== end: including files #
/* Create objects ---------------------------------------------------------- */
$db = new EvaluationDB();
$lib = new EvalShow();
/* ------------------------------------------------------------ end: objects */
#error_reporting( E_ALL & ~E_NOTICE );
/* Set variables ----------------------------------------------------------- */
$rangeID = Request::option('rangeID',Context::getId());
if (empty ($rangeID)) {
$rangeID = $user->id; }
$evalID = Request::option('evalID');
$tree = new EvaluationTreeShowUser( $evalID );
$eval = $tree->tree->eval;
$evalDB = new EvaluationDB();
$isPreview = Request::option('isPreview') ? YES : NO;
$votedEarlier = $eval->hasVoted( $auth->auth["uid"] ) && $isPreview == NO;
$votedNow = Request::submitted('voteButton') && $votedEarlier == NO;
if ( $eval->isAnonymous() )
$userID = StudipObject::createNewID ();
else
$userID = $auth->auth["uid"];
/* ---------------------------------------------------------- end: variables */
$br = new HTMpty( "br" );
/* Surrounding Form -------------------------------------------------------- */
$form = new HTM( "form" );
$form->attr( "action", URLHelper::getLink(Request::url()) );
$form->attr( "method", "post" );
$form->html(CSRFProtection::tokenTag());
if (Request::isXHR()) {
PageLayout::setTitle(_("Stud.IP Online-Evaluation"));
} else {
// TODO: This should use Assets::img() but on the other hand it should also use templates
$titlebar = EvalCommon::createTitle( _("Stud.IP Online-Evaluation"), Icon::create('test', 'info_alt')->asImagePath() );
$form->cont( $titlebar );
}
/* Surrounding Table ------------------------------------------------------- */
$table = new HTM( "table" );
$table->attr( "border","0" );
$table->attr( "align", "center" );
$table->attr( "cellspacing", "0" );
$table->attr( "cellpadding", "3" );
$table->attr( "width", "100%" );
$table->attr( "class", "table_row_even" );
/* count mandatory items */
$mandatories = checkMandatoryItems( $eval );
$answers = Request::quotedArray('answers');
/* ------------------------------------------------------------------------- */
if( $votedNow ) {
$answers = Request::quotedArray('answers');
$freetexts = Request::quotedArray('freetexts');
if( ! ( is_array($answers) ||
/* clicked no answer */
(is_array($freetexts) && implode("", $freetexts) != "")
/* typed no freetext */
)
) {
$eval->throwError( 1, _("Sie haben keine Antworten gewählt.") );
$votedNow = NO;
}
/* check if mandatory answers are missing */
if( count($mandatories) > 0 ) {
$eval->throwError( 1, sprintf(_("Sie haben %s erforderliche Fragen nicht beantwortet. Diese wurden gesondert markiert."),
count($mandatories)) );
$votedNow = NO;
}
}
if( $votedNow ) {
/* the vote was OK */
/* process the user's selected answers --------------------------------- */
if( is_array($answers) ) {
foreach( $answers as $question_id => $answer ) {
if( is_array($answer) )
/* multiple choice question */
foreach( $answer as $nr => $answer_id )
voteFor( $answer_id );
else
/* answer = answer_id */
voteFor( $answer );
}
}
/* process the user's typed-in answers --------------------------------- */
$freetexts = Request::quotedArray('freetexts');
if( is_array($freetexts) ) {
foreach( $freetexts as $question_id => $text ) {
if( trim($text) != '' ) {
$question = new EvaluationQuestion( $question_id );
$answer = new EvaluationAnswer();
$answer->setText( $text );
$answer->setRows( 1 );
$answer->vote( $GLOBALS["userID"] );
$question->addChild( $answer );
$question->save();
$debug .= "added answer text <b>".$answer->getText().
"</b> for question <b>".$question->getText()."</b>\n";
}
}
}
/* connect user with eval */
$evalDB->connectWithUser( $evalID, $auth->auth["uid"] );
/* header ------ */
$table->cont( $lib->createEvaluationHeader( $eval, $votedNow, $votedEarlier ) );
} elseif( $votedEarlier ) {
/* header ------ */
$table->cont( $lib->createEvaluationHeader( $eval, $votedNow, $votedEarlier ) );
} else {
/* header ------ */
$table->cont( $lib->createEvaluationHeader( $eval, $votedNow, $votedEarlier ) );
/* the whole evaluation ------ */
$table->cont( $lib->createEvaluation( $tree ) );
}
/* footer ------ */
$table->cont( $lib->createEvaluationFooter( $eval, $votedNow || $votedEarlier, $isPreview ) );
$form->cont( $table );
/* Ausgabe erzeugen---------------------------------------------------------- */
//Content (TODO: besser mit TemplateFactory)
if (Request::isXHR()) {
echo $form->createContent();
} else {
$layout = $GLOBALS['template_factory']->open('layouts/base.php');
$layout->content_for_layout = $form->createContent();
echo $layout->render();
}
page_close();
/**
* checkMandatoryItems:
* put IDs of mandatory questions into global array $mandatories
* (or, if the user has voted, the IDs of the mandatory questions, which he did not answer to)
*
* @param object the Evaluation object (when called externally).
*/
function checkMandatoryItems( $item )
{
global $mandatories;
if( $children = $item->getChildren() )
{
foreach( $children as $child )
{
checkMandatoryItems( $child );
}
}
if( $item->x_instanceof() == INSTANCEOF_EVALQUESTION )
{
$group = $item->getParentObject();
$answers = Request::quotedArray('answers');
$freetexts = Request::quotedArray('freetexts');
if( $group->isMandatory() &&
( ! is_array($answers) ||
( is_array($answers) &&
! in_array($item->getObjectID(), array_keys($answers)) )
) &&
trim($freetexts[$item->getObjectID()]) == ''
)
{
$mandatories[] = $item->getObjectID();
}
}
return $mandatories ?: [];
}
/**
* vote for an answer of given ID
* @param string the ID.
*/
function voteFor( $answer_id )
{
global $debug;
global $userID;
$answer = new EvaluationAnswer( $answer_id );
$answer->vote($userID);
$answer->save();
$debug .= "voted for answer <b>".$answer->getText()."</b> (".
$answer->getObjectID().")\n";
}
?>
|