Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / mod / workshop / view.php
blobfa31516b6fdc93255a7b44468bbc0be201cae1aa
1 <?php // $Id$
3 /*************************************************
4 ACTIONS handled are:
6 displayfinalgrade (for students)
7 notavailable (for students)
8 studentsview
9 submitexample
10 teachersview
11 showdescription
12 showallsubmissions
14 ************************************************/
16 require("../../config.php");
17 require("lib.php");
18 require("locallib.php");
20 $id = required_param('id', PARAM_INT); // Course Module ID
21 $action = optional_param('action', '', PARAM_ALPHA);
22 $sort = optional_param('sort', 'lastname', PARAM_ALPHA);
23 $dir = optional_param('dir', 'ASC', PARAM_ALPHA);
25 $timenow = time();
27 // get some useful stuff...
28 if (! $cm = get_coursemodule_from_id('workshop', $id)) {
29 error("Course Module ID was incorrect");
31 if (! $course = get_record("course", "id", $cm->course)) {
32 error("Course is misconfigured");
34 if (! $workshop = get_record("workshop", "id", $cm->instance)) {
35 error("Course module is incorrect");
38 require_login($course->id, false, $cm);
39 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
41 $strworkshops = get_string("modulenameplural", "workshop");
42 $strworkshop = get_string("modulename", "workshop");
43 $straction = ($action) ? '-> '.get_string($action, 'workshop') : '';
45 // ...and if necessary set default action
46 if (workshop_is_teacher($workshop)) {
47 if (empty($action)) { // no action specified, either go straight to elements page else the admin page
48 // has the assignment any elements
49 if (count_records("workshop_elements", "workshopid", $workshop->id) >= $workshop->nelements) {
50 $action = "teachersview";
52 else {
53 redirect("assessments.php?action=editelements&id=$cm->id");
56 } else { // it's a student then
57 if (!$cm->visible) {
58 notice(get_string("activityiscurrentlyhidden"));
60 if ($timenow < $workshop->submissionstart) {
61 $action = 'notavailable';
62 } else if (!$action) {
63 if ($timenow < $workshop->assessmentend) {
64 $action = 'studentsview';
65 } else {
66 $action = 'displayfinalgrade';
71 // ...display header...
72 $navlinks = array();
73 $navlinks[] = array('name' => $strworkshops, 'link' => "index.php?id=$course->id", 'type' => 'activity');
74 $navlinks[] = array('name' => format_string($workshop->name,true), 'link' => "view.php?id=$cm->id", 'type' => 'activityinstance');
75 if ($straction) {
76 $navlinks[] = array('name' => $straction, 'link' => '', 'type' => 'title');
78 $navigation = build_navigation($navlinks);
80 print_header_simple(format_string($workshop->name), "", $navigation,
81 "", "", true, update_module_button($cm->id, $course->id, $strworkshop), navmenu($course, $cm));
84 // ...log activity...
85 add_to_log($course->id, "workshop", "view", "view.php?id=$cm->id", $workshop->id, $cm->id);
87 if ($action == 'studentsview' and !workshop_is_student($workshop)) {
88 $action = 'showdescription';
91 /****************** display final grade (for students) ************************************/
92 if ($action == 'displayfinalgrade' ) {
93 require_capability('mod/workshop:participate', $context);
95 print_heading("<b><a href=\"view.php?id=$cm->id&amp;action=showdescription\">".
96 get_string("showdescription", 'workshop')."</a></b>");
97 // show the final grades as stored in the tables...
98 if ($submissions = workshop_get_user_submissions($workshop, $USER)) { // any submissions from user?
99 print_heading(get_string("displayoffinalgrades", "workshop"));
100 echo "<div class=\"boxaligncenter\"><table border=\"1\" width=\"90%\"><tr>";
101 echo "<td><b>".get_string("submissions", "workshop")."</b></td>";
102 if ($workshop->wtype) {
103 echo "<td align=\"center\"><b>".get_string("assessmentsdone", "workshop")."</b></td>";
104 echo "<td align=\"center\"><b>".get_string("gradeforassessments", "workshop")."</b></td>";
106 echo "<td align=\"center\"><b>".get_string("teacherassessments", "workshop",
107 $course->teacher)."</b></td>";
108 if ($workshop->wtype) {
109 echo "<td align=\"center\"><b>".get_string("studentassessments", "workshop",
110 $course->student)."</b></td>";
112 echo "<td align=\"center\"><b>".get_string("gradeforsubmission", "workshop")."</b></td>";
113 echo "<td align=\"center\"><b>".get_string("overallgrade", "workshop")."</b></td></tr>\n";
114 foreach ($submissions as $submission) {
115 $grade = workshop_submission_grade($workshop, $submission);
116 echo "<tr><td>".workshop_print_submission_title($workshop, $submission)."</td>\n";
117 if ($workshop->wtype) {
118 echo "<td align=\"center\">".workshop_print_user_assessments($workshop, $USER, $gradinggrade)."</td>";
119 echo "<td align=\"center\">$gradinggrade</td>";
121 echo "<td align=\"center\">".workshop_print_submission_assessments($workshop,
122 $submission, "teacher")."</td>";
123 if ($workshop->wtype) {
124 echo "<td align=\"center\">".workshop_print_submission_assessments($workshop,
125 $submission, "student")."</td>";
127 echo "<td align=\"center\">$grade</td>";
128 echo "<td align=\"center\">".number_format($gradinggrade + $grade, 1)."</td></tr>\n";
130 echo "</table></div><br clear=\"all\" />\n";
131 workshop_print_key($workshop);
132 } else {
133 print_heading(get_string('nowork', 'workshop'));
135 if ($workshop->showleaguetable) {
136 workshop_print_league_table($workshop);
141 /****************** assignment not available (for students)***********************/
142 elseif ($action == 'notavailable') {
143 print_heading(get_string("notavailable", "workshop"));
146 /****************** student's view could be in 1 of 4 stages ***********************/
147 elseif ($action == 'studentsview') {
148 require_capability('mod/workshop:participate', $context);
150 // is a password needed?
151 if ($workshop->usepassword) {
152 $correctpass = false;
153 if (isset($_POST['userpassword'])) {
154 if ($workshop->password == md5(trim($_POST['userpassword']))) {
155 $USER->workshoploggedin[$workshop->id] = true;
156 $correctpass = true;
158 } elseif (isset($USER->workshoploggedin[$workshop->id])) {
159 $correctpass = true;
162 if (!$correctpass) {
163 print_simple_box_start("center");
164 echo "<form id=\"password\" method=\"post\" action=\"view.php\">\n";
165 echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\" />\n";
166 echo "<table cellpadding=\"7px\">";
167 if (isset($_POST['userpassword'])) {
168 echo "<tr align=\"center\" style='color:#DF041E;'><td>".get_string("wrongpassword", "workshop").
169 "</td></tr>";
171 echo "<tr align=\"center\"><td>".get_string("passwordprotectedworkshop", "workshop", format_string($workshop->name)).
172 "</td></tr>";
173 echo "<tr align=\"center\"><td>".get_string("enterpassword", "workshop").
174 " <input type=\"password\" name=\"userpassword\" /></td></tr>";
176 echo "<tr align=\"center\"><td>";
177 echo "<input type=\"button\" value=\"".get_string("cancel").
178 "\" onclick=\"parent.location='../../course/view.php?id=$course->id';\"> ";
179 echo "<input type=\"button\" value=\"".get_string("continue").
180 "\" onclick=\"document.password.submit();\" />";
181 echo "</td></tr></table>";
182 print_simple_box_end();
183 exit();
186 workshop_print_assignment_info($workshop);
188 // if the student has not yet submitted show the full description
189 if (!record_exists('workshop_submissions', 'workshopid', $workshop->id, 'userid', $USER->id)) {
190 print_box(format_text($workshop->description, $workshop->format), 'generalbox', 'intro');
191 } else {
192 print_heading("<b><a href=\"view.php?id=$cm->id&amp;action=showdescription\">".
193 get_string("showdescription", 'workshop')."</a></b>");
196 // in Stage 1? - are there any teacher's submissions? and...
197 // ...has student assessed the required number of the teacher's submissions
198 if ($workshop->ntassessments and (!workshop_test_user_assessments($workshop, $USER))) {
199 print_heading(get_string("pleaseassesstheseexamplesfromtheteacher", "workshop",
200 $course->teacher));
201 workshop_list_teacher_submissions($workshop, $USER);
203 // in stage 2? - submit own first attempt
204 else {
205 if ($workshop->ntassessments) {
206 // show assessment of the teacher's examples, there may be feedback from teacher
207 print_heading(get_string("yourassessmentsofexamplesfromtheteacher", "workshop",
208 $course->teacher));
209 workshop_list_teacher_submissions($workshop, $USER);
211 // has user submitted anything yet?
212 if (!workshop_get_user_submissions($workshop, $USER)) {
213 if ($timenow < $workshop->submissionend) {
214 // print upload form
215 print_heading(get_string("submitassignmentusingform", "workshop").":");
216 workshop_print_upload_form($workshop);
217 } else {
218 print_heading(get_string("submissionsnolongerallowed", "workshop"));
221 // in stage 3? - grade other student's submissions, resubmit and list all submissions
222 else {
223 // is self assessment used in this workshop?
224 if ($workshop->includeself) {
225 // prints a table if there are any submissions which have not been self assessed yet
226 workshop_list_self_assessments($workshop, $USER);
228 // if peer assessments are being done then show some to assess...
229 if ($workshop->nsassessments and ($workshop->assessmentstart < $timenow and $workshop->assessmentend > $timenow)) {
230 workshop_list_student_submissions($workshop, $USER);
232 // ..and any they have already done (and have gone cold)...
233 if (workshop_count_user_assessments($workshop, $USER, "student")) {
234 print_heading(get_string("yourassessments", "workshop"));
235 workshop_list_assessed_submissions($workshop, $USER);
237 // list any assessments by teachers
238 if (workshop_count_teacher_assessments_by_user($workshop, $USER) and ($timenow > $workshop->releasegrades)) {
239 print_heading(get_string("assessmentsby", "workshop", $course->teachers));
240 workshop_list_teacher_assessments_by_user($workshop, $USER);
242 // ... and show peer assessments
243 if (workshop_count_peer_assessments($workshop, $USER)) {
244 print_heading(get_string("assessmentsby", "workshop", $course->students));
245 workshop_list_peer_assessments($workshop, $USER);
247 // list previous submissions
248 print_heading(get_string("yoursubmissions", "workshop"));
249 workshop_list_user_submissions($workshop, $USER);
251 // are resubmissions allowed and the workshop is in submission/assessment phase?
252 if ($workshop->resubmit and ($timenow > $workshop->assessmentstart and $timenow < $workshop->submissionend)) {
253 // see if there are any cold assessments of the last submission
254 // if there are then print upload form
255 if ($submissions = workshop_get_user_submissions($workshop, $USER)) {
256 foreach ($submissions as $submission) {
257 $lastsubmission = $submission;
258 break;
260 $n = 0; // number of cold assessments (not include self assessments)
261 if ($assessments = workshop_get_assessments($lastsubmission)) {
262 foreach ($assessments as $assessment) {
263 if ($assessment->userid <> $USER->id) {
264 $n++;
268 if ($n) {
269 echo "<hr size=\"1\" noshade=\"noshade\" />";
270 print_heading(get_string("submitrevisedassignment", "workshop").":");
271 workshop_print_upload_form($workshop);
272 echo "<hr size=\"1\" noshade=\"noshade\" />";
281 /****************** submission of example by teacher only***********************/
282 elseif ($action == 'submitexample') {
284 require_capability('mod/workshop:manage', $context);
286 // list previous submissions from teacher
287 workshop_list_user_submissions($workshop, $USER);
289 echo "<hr size=\"1\" noshade=\"noshade\" />";
291 // print upload form
292 print_heading(get_string("submitexampleassignment", "workshop").":");
293 workshop_print_upload_form($workshop);
295 print_heading("<a $CFG->frametarget href=\"view.php?id=$cm->id\">".get_string("cancel")."</a>");
299 /****************** teacher's view - display admin page ************/
300 elseif ($action == 'teachersview') {
302 require_capability('mod/workshop:manage', $context);
304 // automatically grade assessments if workshop has examples and/or peer assessments
305 if ($workshop->gradingstrategy and ($workshop->ntassessments or $workshop->nsassessments)) {
306 workshop_grade_assessments($workshop);
309 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
311 /// find out current groups mode
312 $groupmode = groupmode($course, $cm);
313 $currentgroup = setup_and_print_groups($course, $groupmode, "view.php?id=$cm->id");
315 /// Print admin links
316 echo "<table width=\"100%\"><tr><td>";
317 echo "<a href=\"submissions.php?id=$cm->id&amp;action=adminlist\">".
318 get_string("administration")."</a>\n";
320 echo '</td></tr>';
322 echo '<tr><td>';
323 workshop_print_assignment_info($workshop);
324 print_heading("<a href=\"view.php?id=$cm->id&amp;action=showdescription\">".
325 get_string("showdescription", 'workshop')."</a>");
326 echo '</td></tr>';
328 /// Print grade tables /////////////////////////////////////////////////
330 // display the teacher's submissions
331 if ($workshop->ntassessments) {
332 $table->head = array(get_string("examplesubmissions", "workshop"),
333 get_string("assessmentsby", "workshop", $course->teachers),
334 get_string("assessmentsby", "workshop", $course->students));
335 $table->data = array();
336 if ($submissions = workshop_get_teacher_submissions($workshop)) {
337 foreach ($submissions as $submission) {
338 $teacherassessments = workshop_print_submission_assessments($workshop, $submission, "teacher");
339 // If not yet assessed, show assess link
340 if ($teacherassessments == '&nbsp;') {
341 $teacherassessments = '<a href="assess.php?id='.
342 $cm->id.'&amp;sid='.$submission->id.'">'.get_string('assess', 'workshop').'</a>';
344 $title = workshop_print_submission_title($workshop, $submission).
345 " <a href=\"submissions.php?action=editsubmission&amp;id=$cm->id&amp;sid=$submission->id\">".
346 "<img src=\"$CFG->pixpath/t/edit.gif\" ".
347 'class="iconsmall" alt="'.get_string('edit').'" /></a>'.
348 " <a href=\"submissions.php?action=confirmdelete&amp;id=$cm->id&amp;sid=$submission->id\">".
349 "<img src=\"$CFG->pixpath/t/delete.gif\" ".
350 'class="iconsmall" alt="'.get_string('delete', 'workshop').'" /></a>';
351 $table->data[] = array($title, $teacherassessments,
352 workshop_print_submission_assessments($workshop, $submission, "student"));
355 // Put in a submission link
356 $table->data[] = array("<b><a href=\"view.php?id=$cm->id&amp;action=submitexample\">".
357 get_string("submitexampleassignment", "workshop")."</a></b>".
358 helpbutton("submissionofexamples", get_string("submitexampleassignment", "workshop"), "workshop", true, false, '', true),
359 '&nbsp;', '&nbsp;');
360 print_table($table);
361 workshop_print_key($workshop);
364 // Get all the students
365 if (!$users = workshop_get_students($workshop)) {
366 echo ('</table>');
367 print_heading(get_string("nostudentsyet"));
368 print_footer($course);
369 exit;
372 /// Now prepare table with student assessments and submissions
373 $tablesort->data = array();
374 $tablesort->sortdata = array();
375 foreach ($users as $user) {
376 // skip if student not in group
377 if ($currentgroup) {
378 if (!ismember($currentgroup, $user->id)) {
379 continue;
382 if ($submissions = workshop_get_user_submissions($workshop, $user)) {
383 foreach ($submissions as $submission) {
384 $data = array();
385 $sortdata = array();
387 $data[] = "<a name=\"userid$user->id\" href=\"{$CFG->wwwroot}/user/view.php?id=$user->id&amp;course=$course->id\">".
388 fullname($user).'</a>';
389 $sortdata['firstname'] = $user->firstname;
390 $sortdata['lastname'] = $user->lastname;
392 if ($workshop->wtype) {
393 $data[] = workshop_print_user_assessments($workshop, $user, $gradinggrade);
395 $data[] = $gradinggrade;
396 $sortdata['agrade'] = $gradinggrade;
399 $data[] = workshop_print_submission_title($workshop, $submission).
400 " <a href=\"submissions.php?action=adminamendtitle&amp;id=$cm->id&amp;sid=$submission->id\">".
401 "<img src=\"$CFG->pixpath/t/edit.gif\" ".
402 'class="iconsmall" alt="'.get_string('amendtitle', 'workshop').'" /></a>'.
403 " <a href=\"submissions.php?action=confirmdelete&amp;id=$cm->id&amp;sid=$submission->id\">".
404 "<img src=\"$CFG->pixpath/t/delete.gif\" ".
405 'class="iconsmall" alt="'.get_string('delete', 'workshop').'" /></a>';
406 $sortdata['title'] = $submission->title;
408 $data[] = userdate($submission->timecreated, get_string('datestr', 'workshop'));
409 $sortdata['date'] = $submission->timecreated;
411 if (($tmp = workshop_print_submission_assessments($workshop, $submission, "teacher")) == '&nbsp;') {
412 $data[] = '<a href="assess.php?id='.
413 $cm->id.'&amp;sid='.$submission->id.'">'.get_string('assess', 'workshop').'</a>';
414 $sortdata['tassmnt'] = -1;
415 } else {
416 $data[] = $tmp;
417 $sortdata['tassmnt'] = 1; // GWD still have to fix this
420 if ($workshop->wtype) {
421 $data[] = workshop_print_submission_assessments($workshop, $submission, "student");
424 $grade = workshop_submission_grade($workshop, $submission);
425 $data[] = $grade;
426 $sortdata['sgrade'] = $grade;
428 if ($workshop->wtype) {
429 $data[] = number_format($gradinggrade + $grade, 1);
430 $sortdata['ograde'] = $gradinggrade + $grade;
433 $tablesort->data[] = $data;
434 $tablesort->sortdata[] = $sortdata;
439 function workshop_sortfunction($a, $b) {
440 global $sort, $dir;
441 if ($dir == 'ASC') {
442 return ($a[$sort] > $b[$sort]);
443 } else {
444 return ($a[$sort] < $b[$sort]);
447 uasort($tablesort->sortdata, 'workshop_sortfunction');
448 $table->data = array();
449 foreach($tablesort->sortdata as $key => $row) {
450 $table->data[] = $tablesort->data[$key];
453 if ($workshop->wtype) {
454 $table->align = array ('left', 'center', 'center', 'left', 'center', 'center', 'center', 'center', 'center', 'center');
455 $columns = array('firstname', 'lastname', 'agrade', 'title', 'date', 'tassmnt', 'sgrade', 'ograde');
456 } else {
457 $table->align = array ('left', 'left', 'center', 'center', 'center', 'center');
458 $columns = array('firstname', 'lastname', 'title', 'date', 'tassmnt', 'ograde');
460 $table->width = "95%";
462 foreach ($columns as $column) {
463 $string[$column] = get_string("$column", 'workshop');
464 if ($sort != $column) {
465 $columnicon = '';
466 $columndir = 'ASC';
467 } else {
468 $columndir = $dir == 'ASC' ? 'DESC':'ASC';
469 if ($column == 'lastaccess') {
470 $columnicon = $dir == 'ASC' ? 'up':'down';
471 } else {
472 $columnicon = $dir == 'ASC' ? 'down':'up';
474 $columnicon = " <img src=\"$CFG->pixpath/t/$columnicon.gif\" alt=\"$columnicon\" />";
477 $$column = "<a href=\"view.php?id=$id&amp;sort=$column&amp;dir=$columndir\">".$string[$column]."</a>$columnicon";
480 if ($workshop->wtype) {
481 $table->head = array ("$firstname / $lastname", get_string("assmnts", "workshop"), $agrade,
482 $title, $date, $tassmnt, get_string('passmnts', 'workshop'), $sgrade, $ograde);
483 } else {
484 $table->head = array ("$firstname / $lastname", $title, $date, $tassmnt, $ograde);
487 echo '<tr><td>';
488 print_table($table);
489 echo '</td></tr>';
490 echo '<tr><td>';
491 workshop_print_key($workshop);
492 echo '</td></tr>';
494 // grading grade analysis
495 unset($table);
496 $table->head = array (get_string("count", "workshop"), get_string("mean", "workshop"),
497 get_string("standarddeviation", "workshop"), get_string("maximum", "workshop"),
498 get_string("minimum", "workshop"));
499 $table->align = array ("center", "center", "center", "center", "center");
500 $table->size = array ("*", "*", "*", "*", "*");
501 $table->cellpadding = 2;
502 $table->cellspacing = 0;
503 if ($currentgroup) {
504 $stats = get_record_sql("SELECT COUNT(*) as count, AVG(gradinggrade) AS mean,
505 STDDEV(gradinggrade) AS stddev, MIN(gradinggrade) AS min, MAX(gradinggrade) AS max
506 FROM {$CFG->prefix}groups_members g, {$CFG->prefix}workshop_assessments a
507 WHERE g.groupid = $currentgroup AND a.userid = g.userid AND a.timegraded > 0
508 AND a.workshopid = $workshop->id");
509 } else { // no group/all participants
510 $stats = get_record_sql("SELECT COUNT(*) as count, AVG(gradinggrade) AS mean,
511 STDDEV(gradinggrade) AS stddev, MIN(gradinggrade) AS min, MAX(gradinggrade) AS max
512 FROM {$CFG->prefix}workshop_assessments a
513 WHERE a.timegraded > 0 AND a.workshopid = $workshop->id");
515 $table->data[] = array($stats->count, number_format($stats->mean * $workshop->gradinggrade / 100, 1),
516 number_format($stats->stddev * $workshop->gradinggrade /100, 1),
517 number_format($stats->max * $workshop->gradinggrade / 100, 1),
518 number_format($stats->min* $workshop->gradinggrade / 100, 1));
519 echo '<tr><td>';
520 print_heading(get_string("gradinggrade", "workshop")." ".get_string("analysis", "workshop"));
521 print_table($table);
522 echo '</td></tr>';
524 if ($workshop->showleaguetable and time() > $workshop->assessmentend) {
525 workshop_print_league_table($workshop);
526 if ($workshop->anonymous) {
527 echo "<p>".get_string("namesnotshowntostudents", "workshop", $course->students)."</p>\n";
530 echo '</table>';
534 /****************** show description ************/
535 elseif ($action == 'showdescription') {
536 workshop_print_assignment_info($workshop);
537 print_box(format_text($workshop->description, $workshop->format), 'generalbox', 'intro');
538 if (isset($_SERVER["HTTP_REFERER"])) {
539 print_continue(htmlentities($_SERVER["HTTP_REFERER"]));
540 } else {
541 print_continue("$CFG->wwwroot/course/view.php?id=$cm->id");
546 /****************** teacher's view - list all submissions ************/
547 elseif ($action == 'allsubmissions') {
548 require_capability('mod/workshop:manage', $context);
550 if ($submissions = get_records('workshop_submissions', 'workshopid', $workshop->id)) {
551 foreach($submissions as $submission) {
552 $user = get_record('user', 'id', $submission->userid);
553 print_heading('"'.$submission->title.'" '.get_string('by', 'workshop').' '.fullname($user));
554 workshop_print_submission($workshop, $submission);
560 /*************** no man's land **************************************/
561 else {
562 error("Fatal Error: Unknown Action: ".$action."\n");
566 print_footer($course);