~ubuntu-branches/ubuntu/jaunty/moodle/jaunty

« back to all changes in this revision

Viewing changes to mod/lesson/action/continue.php

  • Committer: Bazaar Package Importer
  • Author(s): Jordan Mantha, Matt Oquist
  • Date: 2009-02-25 15:16:22 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20090225151622-0ekt1liwhv2obfza
Tags: 1.9.4.dfsg-0ubuntu1
* Merge with Debian git (Closes LP: #322961, #239481, #334611):
  - use Ubuntu's smarty lib directory for linking
  - use internal yui library 
  - add update-notifier support back in

[Matt Oquist]
  * renamed prerm script
  * significantly rewrote postinst and other maintainer scripts to improve
    user experience and package maintainability
    (Closes LP: #225662, #325450, #327843, #303078, #234609)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php // $Id: continue.php,v 1.37.2.1 2007/02/23 18:54:27 mark-nielsen Exp $
 
1
<?php // $Id: continue.php,v 1.39.2.8 2008/11/26 15:13:51 thepurpleblob Exp $
2
2
/**
3
3
 * Action for processing page answers by users
4
4
 *
5
 
 * @version $Id: continue.php,v 1.37.2.1 2007/02/23 18:54:27 mark-nielsen Exp $
 
5
 * @version $Id: continue.php,v 1.39.2.8 2008/11/26 15:13:51 thepurpleblob Exp $
6
6
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
7
7
 * @package lesson
8
8
 **/
9
9
    confirm_sesskey();
10
10
 
 
11
    require_once($CFG->dirroot.'/mod/lesson/pagelib.php');
 
12
    require_once($CFG->libdir.'/blocklib.php');
 
13
 
11
14
    // left menu code
12
15
    // check to see if the user can see the left menu
13
16
    if (!has_capability('mod/lesson:manage', $context)) {
16
19
 
17
20
    // This is the code updates the lesson time for a timed test
18
21
    // get time information for this user
19
 
    $outoftime = false;
20
22
    $timer = new stdClass;
21
23
    if (!has_capability('mod/lesson:manage', $context)) {
22
24
        if (!$timer = get_records_select('lesson_timer', "lessonid = $lesson->id AND userid = $USER->id", 'starttime')) {
26
28
        }
27
29
        
28
30
        if ($lesson->timed) {
29
 
            if ((($timer->starttime + $lesson->maxtime * 60) - time()) < 60 && !((($timer->starttime + $lesson->maxtime * 60) - time()) < 0)) {
30
 
                lesson_set_message(get_string("studentoneminwarning", "lesson"));
31
 
            } else if (($timer->starttime + $lesson->maxtime * 60) < time()) {
32
 
                lesson_set_message(get_string("studentoutoftime", "lesson"));
33
 
                $outoftime = true;
34
 
            }
35
 
            if ((($timer->starttime + $lesson->maxtime * 60) - time()) <= 0) {
 
31
            $timeleft = ($timer->starttime + $lesson->maxtime * 60) - time();
 
32
 
 
33
            if ($timeleft <= 0) {
36
34
                // Out of time
37
35
                lesson_set_message(get_string('eolstudentoutoftime', 'lesson'));
38
 
                redirect("$CFG->wwwroot/mod/lesson/view.php?id=$cm->id&amp;pageid=".LESSON_EOL."&outoftime=normal", get_string("outoftime", "lesson"));
 
36
                redirect("$CFG->wwwroot/mod/lesson/view.php?id=$cm->id&amp;pageid=".LESSON_EOL."&outoftime=normal");
 
37
                die; // Shouldn't be reached, but make sure
 
38
            } else if ($timeleft < 60) {
 
39
                // One minute warning
 
40
                lesson_set_message(get_string("studentoneminwarning", "lesson"));
39
41
            }
40
42
        }
41
43
        
85
87
            $studentanswer = s(stripslashes_safe($useranswer));
86
88
            break;
87
89
         case LESSON_SHORTANSWER :
88
 
            if (!$useranswer = $_POST['answer']) {
 
90
            if (isset($_POST['answer'])) {
 
91
                $useranswer = $_POST['answer'];
 
92
            } else {
89
93
                $noanswer = true;
90
94
                break;
91
95
            }            
92
 
            $useranswer = stripslashes(clean_param($useranswer, PARAM_RAW));
 
96
            $useranswer = s(stripslashes(clean_param($useranswer, PARAM_RAW)));
93
97
            $userresponse = addslashes($useranswer);
94
98
            if (!$answers = get_records("lesson_answers", "pageid", $pageid, "id")) {
95
99
                error("Continue: No answers found");
118
122
                    $expectedanswer = str_replace('#####', '.*', $expectedanswer);
119
123
                }
120
124
                // see if user typed in any of the correct answers
121
 
                if (lesson_iscorrect($pageid, $answer->jumpto) or ($lesson->custom && $answer->score > 0) ) {
 
125
                if (lesson_iscorrect($pageid, $answer->jumpto) and ($lesson->custom && $answer->score > 0) ) {
122
126
                    if (!$useregexp) { // we are using 'normal analysis', which ignores case
123
127
                        if (preg_match('/^'.$expectedanswer.'$/i',$useranswer)) {
124
128
                            $ismatch = true;
185
189
                    break; // quit answer analysis immediately after a match has been found
186
190
                }
187
191
            }
188
 
            $studentanswer = s($useranswer);
 
192
            $studentanswer = $useranswer;
189
193
            break;
190
194
        
191
195
        case LESSON_TRUEFALSE :
234
238
                $nhits = 0;
235
239
                $correctresponse = '';
236
240
                $wrongresponse = '';
 
241
                $correctanswerid = 0;
 
242
                $wronganswerid = 0;
237
243
                // store student's answers for displaying on feedback page
238
244
                foreach ($answers as $answer) {
239
245
                    foreach ($useranswers as $key => $answerid) {
260
266
                                // leave in its "raw" state - will converted into a proper page id later
261
267
                                $correctpageid = $answer->jumpto;
262
268
                            }
 
269
                            // save the answer id for scoring
 
270
                            if ($correctanswerid == 0) {
 
271
                                $correctanswerid = $answer->id;
 
272
                            }
263
273
                            // ...also save any response from the correct answers...
264
274
                            if (trim(strip_tags($answer->response))) {
265
275
                                $correctresponse = $answer->response;
270
280
                                // leave in its "raw" state - will converted into a proper page id later
271
281
                                $wrongpageid = $answer->jumpto;
272
282
                            }
 
283
                            // save the answer id for scoring
 
284
                            if ($wronganswerid == 0) {
 
285
                                $wronganswerid = $answer->id;
 
286
                            }
273
287
                            // ...and from the incorrect ones, don't know which to use at this stage
274
288
                            if (trim(strip_tags($answer->response))) {
275
289
                                $wrongresponse = $answer->response;
290
304
                                // leave in its "raw" state - will converted into a proper page id later
291
305
                                $correctpageid = $answer->jumpto;
292
306
                            }
 
307
                            // save the answer id for scoring
 
308
                            if ($correctanswerid == 0) {
 
309
                                $correctanswerid = $answer->id;
 
310
                            }
293
311
                            // ...also save any response from the correct answers...
294
312
                            if (trim(strip_tags($answer->response))) {
295
313
                                $correctresponse = $answer->response;
300
318
                                // leave in its "raw" state - will converted into a proper page id later
301
319
                                $wrongpageid = $answer->jumpto;
302
320
                            }
 
321
                            // save the answer id for scoring
 
322
                            if ($wronganswerid == 0) {
 
323
                                $wronganswerid = $answer->id;
 
324
                            }
303
325
                            // ...and from the incorrect ones, don't know which to use at this stage
304
326
                            if (trim(strip_tags($answer->response))) {
305
327
                                $wrongresponse = $answer->response;
311
333
                    $correctanswer = true;
312
334
                    $response  = $correctresponse;
313
335
                    $newpageid = $correctpageid;
 
336
                    $answerid  = $correctanswerid;
314
337
                } else {
315
338
                    $response  = $wrongresponse;
316
339
                    $newpageid = $wrongpageid;
 
340
                    $answerid  = $wronganswerid;
317
341
                }
318
342
            } else {
319
343
                // only one answer allowed
389
413
            }
390
414
            $userresponse = implode(",", $userresponse);
391
415
 
 
416
            $response = '';
392
417
            if ($ncorrect == count($answers)-2) {  // dont count correct/wrong responses in the total.
393
418
                foreach ($answers as $answer) {
394
419
                    if ($answer->response == NULL && $answer->answer != NULL) {
520
545
        
521
546
    }
522
547
 
523
 
    $attemptsremaining = 0;
 
548
    $attemptsremaining  = 0;
524
549
    $maxattemptsreached = 0;
 
550
    $nodefaultresponse  = false; // Flag for redirecting when default feedback is turned off
525
551
 
526
552
    if ($noanswer) {
527
553
        $newpageid = $pageid; // display same page again
 
554
        $feedback  = get_string('noanswer', 'lesson');
528
555
    } else {
529
556
        $nretakes = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id); 
530
557
        if (!has_capability('mod/lesson:manage', $context)) {
541
568
            }
542
569
            
543
570
            $attempt->timeseen = time();
544
 
            // dont want to insert the attempt if they ran out of time
545
 
            if (!$outoftime) {
546
 
                // if allow modattempts, then update the old attempt record, otherwise, insert new answer record
547
 
                if (isset($USER->modattempts[$lesson->id])) {
548
 
                    $attempt->retry = $nretakes - 1; // they are going through on review, $nretakes will be too high
549
 
                }
550
 
                if (!$newattemptid = insert_record("lesson_attempts", $attempt)) {
551
 
                    error("Continue: attempt not inserted");
552
 
                }
 
571
            // if allow modattempts, then update the old attempt record, otherwise, insert new answer record
 
572
            if (isset($USER->modattempts[$lesson->id])) {
 
573
                $attempt->retry = $nretakes - 1; // they are going through on review, $nretakes will be too high
 
574
            }
 
575
            if (!$newattemptid = insert_record("lesson_attempts", $attempt)) {
 
576
                error("Continue: attempt not inserted");
553
577
            }
554
578
            // "number of attempts remaining" message if $lesson->maxattempts > 1
555
579
            // displaying of message(s) is at the end of page for more ergonomic display
624
648
        }
625
649
 
626
650
        // Determine default feedback if necessary
627
 
        $nodefaultresponse = false;  // Flag for redirecting when default feedback is turned off
628
651
        if (empty($response)) {
629
652
            if (!$lesson->feedback and !$noanswer and !($lesson->review and !$correctanswer and !$isessayquestion)) {
630
653
                // These conditions have been met:
646
669
        // display response (if there is one - there should be!)
647
670
        // display: lesson title, page title, question text, student's answer(s) before feedback message
648
671
        
649
 
        if ($noanswer) {
650
 
            $feedback = get_string('noanswer', 'lesson');
651
 
        } else if ($response) {
 
672
        if ($response) {
652
673
            //optionally display question page title
653
674
            //if ($title = get_field("lesson_pages", "title", "id", $pageid)) {
654
675
            //    print_heading($title);
680
701
    }
681
702
 
682
703
    // TODO: merge with the jump code above.  This is where some jump numbers are interpreted
683
 
    if($outoftime) {
684
 
        $newpageid = LESSON_EOL;  // ran out of time for the test, so go to eol
685
 
    } elseif (isset($USER->modattempts[$lesson->id])) {
 
704
    if (isset($USER->modattempts[$lesson->id])) {
686
705
        // make sure if the student is reviewing, that he/she sees the same pages/page path that he/she saw the first time
687
706
        if ($USER->modattempts[$lesson->id] == $pageid) {  // remember, this session variable holds the pageid of the last page that the user saw
688
707
            $newpageid = LESSON_EOL;
771
790
    if ($maxattemptsreached != 0) { 
772
791
        lesson_set_message('('.get_string("maximumnumberofattemptsreached", "lesson").')');
773
792
    }
774
 
    
775
 
    lesson_print_header($cm, $course, $lesson, 'view');
 
793
 
 
794
    $PAGE = page_create_object('mod-lesson-view', $lesson->id);
 
795
    $PAGE->set_lessonpageid($page->id);
 
796
    $pageblocks = blocks_setup($PAGE);
 
797
 
 
798
    $leftcolumnwidth  = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), 210);
 
799
    $rightcolumnwidth = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), 210);
 
800
 
 
801
/// Print the header, heading and tabs
 
802
    $PAGE->print_header();
776
803
 
777
804
    include(dirname(__FILE__).'/continue.html');
778
805
?>