diff -Naur moodle/course/modedit.php moodle_omrquiz/course/modedit.php --- moodle/course/modedit.php 2008-07-22 05:48:50.000000000 +0530 +++ moodle_omrquiz/course/modedit.php 2010-03-10 17:42:04.000000000 +0530 @@ -254,6 +254,16 @@ error($returnfromfunc, "view.php?id=$course->id"); } +//---------------------------------------------For OMR Quiz,-------------------------------------- + if($fromform->quiztype=='omr'){ + $omrdata=new object(); + $omrdata->quizid=$fromform->instance; + if(!insert_record('omrquiz', $omrdata, $returnid=false, $primarykey='id')){ + error("could not insert omr data in table omr quiz"); + } + } +//-----------------------------------------author@ Harmeet Saini---------------------------------- + set_coursemodule_visible($fromform->coursemodule, $fromform->visible); set_coursemodule_groupmode($fromform->coursemodule, $fromform->groupmode); set_coursemodule_groupingid($fromform->coursemodule, $fromform->groupingid); @@ -290,6 +300,16 @@ } $fromform->instance = $returnfromfunc; + +//---------------------------------------------------For OMR Quiz,------------------------------------------------ + if($fromform->quiztype=='omr'){ + $omrdata=new object(); + $omrdata->quizid=$fromform->instance; + if(!insert_record('omrquiz', $omrdata, $returnid=false, $primarykey='id')){ + error("could not insert omr data in table omr quiz"); + } + } +//----------------------------------------------author@ Harmeet Saini--------------------------------------------- // course_modules and course_sections each contain a reference // to each other, so we have to update one of them twice. diff -Naur moodle/lang/en_utf8/help/quiz/omranswers.html moodle_omrquiz/lang/en_utf8/help/quiz/omranswers.html --- moodle/lang/en_utf8/help/quiz/omranswers.html 1970-01-01 05:30:00.000000000 +0530 +++ moodle_omrquiz/lang/en_utf8/help/quiz/omranswers.html 2010-03-10 17:43:13.000000000 +0530 @@ -0,0 +1,125 @@ +

Uploading and Correcting the Answer Sheet Data:

+ + +Content: + + +

Structure and Contents of scanned OMR answer sheet data file:

+
  1. Structure of the scanned OMR answers file
    + +OMR sheets can be scanned to obtain the student attempt data (consisting of student information & answers) in digital format. Currently OMR quiz requires the offline quiz attempt data in a standard format. +
    +

    Following are the details of the format:
    +     Each line should consist of a single student record only

    + + +

    +Note: + Scanned data format for OMR sheets differs from scanner to scanner and OMR sheet to OMR sheet. So, if scanned data is not available in above mentioned format, you can preprocess the scanned student quiz attempt data to obtain data in above mentioned format & smoothly do the result processing using OMR Quiz. In this way, you can potentially process student offline attempt data conducted on any OMR sheet irrespective of the scanner which was used for scanning the sheets or the structure of the OMR sheet. +

    + + + +
       rollno    name     variant no    answer string    
    +

    NOTE: Position of parameter can change.

    + +
  2. Sample contents of the scanned OMR answers file
    +
    1. Note that text in italics is just for information and should not be a part of the file.
      +
      +username   name                                   variant_no answerstring
      +
      +0957001 ABHAY KUMAR                               4321ACAAADACDAA
      +0957002 AGARWAL CHETNA                            4321ACAADDAAADD
      +0957003 SATISH BHIKAJI BELOSE                     4321ACAACAACBAA
      +0957004 FARHAN PATEL                              4321ACBBAAACDDB
      +0957005 AKSHAT GILL                               4321DCAABDADDCC
      +

      +Information for Configuration File +
      +variantcount:1
      +rollnoposition:1
      +variantposition:51
      +ansposition:55
      +rollnolength:7
      +variantlength:4
      +
      +

    2. +
    3. Note that text in italics is just for information and should not be a part of the file.
      +
      +name                           username      variant no     answer string
      +
      +ABHAY KUMAR                    d0957001        43215        ACAAADACDAA
      +AGARWAL CHETNA                 d0957002        43215        ACAADDAAADD
      +SATISH BHIKAJI BELOSE          d0957003        43215        ACAACAACBAA
      +FARHAN PATEL                   d0957004        43215        ACBBAAACDDB
      +AKSHAT GILL                    d0957005        43215        DCAABDADDCC
      +

      +Information for Configuration File +
      +variantcount:1
      +rollnoposition:32
      +variantposition:48
      +ansposition:61
      +rollnolength:8
      +variantlength:5
      +
      +
    4. +
    +[TOP] + + + + + + + + + +

    Uploading scanned OMR answer sheet data file:

    +
      +
    1. Click on the "OMR" tab then click on answers tab. Now an upload form will appear on the screen.
    2. +
    3. Click on "Browse" under "import from file upload" section and click "upload this file" to upload the scanned OMR answers file present on your file system
      OR

      +Click on "choose or upload a file" under "import from file already in course files.." section and click "import from this file" to import the scanned OMR answers file that is already present in files area of Moodle.
    4. +
    +Answer files uploaded earlier can also be uploaded again. +
    Refer to section Retrieving earlier uploaded answer data
    +

    Note: The uploaded answers are automatically saved in Moodle's files area in a directory named "answers" under another directory having name as the name of the quiz for which the answers are uploaded.

    +So do not use the characters as mentioned in the section "creating an OMR quiz" for naming the quiz. +
    +[TOP] + +

    Retrieving earlier uploaded answer data:

    +

    For retrieving the answer data file already uploaded to Moodle's files area:

    +
    1. go to the course under which this quiz is present.

    2. +
    3. click on "Files" present in the administration block.

    4. +
    5. click on folder with the name as the name of the quiz of which you want to access the uploaded answer data file.

    6. +
    7. click the "Answers" folder and select the file that you want to retrieve.
    8. +
    +

    Note: If a file is uploaded more than once using OMR system's answers upload then these uploaded files are renamed as given below.

    +
    +    File name answers
    +	1st upload:- answer
    +	2nd upload:- answers_1
    +	3rd upload:- answers_2 and so on
    +
    +    so detecting the latest uploaded file becomes easy.
    +
    +[TOP] + + + + + + diff -Naur moodle/lang/en_utf8/help/quiz/omrattempts.html moodle_omrquiz/lang/en_utf8/help/quiz/omrattempts.html --- moodle/lang/en_utf8/help/quiz/omrattempts.html 1970-01-01 05:30:00.000000000 +0530 +++ moodle_omrquiz/lang/en_utf8/help/quiz/omrattempts.html 2010-03-10 17:43:13.000000000 +0530 @@ -0,0 +1,19 @@ +

    Processing and Viewing Offline Attempts:

    + +

    Processing of offline attempt data:

    +

    When you are sure that all the uploaded records from scanned OMR data file are correct you can process and evaluate these records. These correct records are also called offline attempts.

    + +
    1. For processing the answers data
      +
      1. Click on the OMR tab then click on “process attempts” tab. A list of correct and incorrect records will be displayed.

      2. +
      3. Click on “process” button to process the correct records. System will process the correct records and will navigate to results page.

      4. +
      +

      Note: Avoid processing of uploaded records until all the uploaded records are correct.

      +
    + +

    Viewing the results of offline attempts:

    +

    To see the results of offline attempts click on the quiz then click on the results tab. You can see attempt of each student collectively or for a particular question by clicking on the total grade he/she got or the grade he /she got in a particular question.

    + + + + + diff -Naur moodle/lang/en_utf8/help/quiz/omrattendance.html moodle_omrquiz/lang/en_utf8/help/quiz/omrattendance.html --- moodle/lang/en_utf8/help/quiz/omrattendance.html 1970-01-01 05:30:00.000000000 +0530 +++ moodle_omrquiz/lang/en_utf8/help/quiz/omrattendance.html 2010-03-10 17:43:13.000000000 +0530 @@ -0,0 +1,36 @@ +

    Attendance for Offline Quiz

    +

    +
    +Attendance for OMR quiz is not compulsory. +
    But if you upload attendance for an OMR quiz then you have an option to test the validity of the students against this attendance also apart from regular validation against enrollment for the course. +

    +

    Structure of the Attendance File:

    +

    +   Attendance file have roll numbers(Username in Moodle) one at each line like +

    	username1
    +	username2
    +	username3
    +	...
    +	...
    +	...
    +

    + +

    Uploading Attendance:

    +
    1. Click on the "OMR" tab and then click on "Attendance" tab.

    2. +
    3. Click on "Browse" under "import from file upload" section and click "upload this file" to upload the attendance file present on your file system.
      +
      OR

      +Click on "choose or upload a file" under "import from file already in course files.." section and click "import from this file" to import the attendance file that is already present in files area of Moodle.
    4. +
      +
    + +

    Validating users against Attendance list

    +

    +

    + + + + diff -Naur moodle/lang/en_utf8/help/quiz/omrconfigupload.html moodle_omrquiz/lang/en_utf8/help/quiz/omrconfigupload.html --- moodle/lang/en_utf8/help/quiz/omrconfigupload.html 1970-01-01 05:30:00.000000000 +0530 +++ moodle_omrquiz/lang/en_utf8/help/quiz/omrconfigupload.html 2010-03-10 17:43:13.000000000 +0530 @@ -0,0 +1,89 @@ +

    Creating and Uploading the OMR Sheet Configuration File

    + +

    Creating OMR Sheet Configuration File

    +

    + The configuration file contains certain parameters that helps in flexible extraction of offline quiz attempt data from the scanned "OMR" answer sheet data file. + + For structure and contents of configuration file refer to "Structure of configuration file", "Contents of the configuration file" and "Example of OMR Configuration file". + + Configuration file can be created based on the structure of offline attempt (scanned OMR) data file. Based on that file various parameters of configuration file are decided. Currently OMR quiz requires the offline quiz attempt data in a Standard format +

    +
    +

    1. Structure of "OMR" Configuration File:
    +

      name_of_the_parameter:value_of_the_parameter
    +

    +

    2. Contents of the Configuration File:
    +  Following are the contents of the configuration file (order of the parameter must be same as shown in table and example): + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    ParameterValue required
    variantcountNumber of Variants required for the OMR Quiz
    rollnopositionPosition of roll number in scanned OMR File.
    variantpositionPosition of the Variant number in scanned OMR File
    anspositionPosition of the answer string in scanned OMR File
    rollnolengthLength of the Roll number
    variantlengthLength of the Variant number
    +

    +

    3. Example of OMR Configuration file:
    +

    +variantcount:4
    +rollnoposition:1
    +variantposition:40
    +ansposition:44
    +rollnolength:4
    +variantlength:4
    +
    +

    +

    +Note:
    +

    +

    +
    +

    Uploading OMR Configuration File:

    +

    +

    +
    +Note:
    +
    • "If you change the OMR configuration then all the existing +answer data and user attempts made on that +data for this OMR quiz will be erased."
    • Click "Yes" if you intend to do so. Click "No" otherwise.
    • After the file upload, contents of the file are displayed on the screen.
    • Click on the "Continue" button to decide the variants of quiz.
    +
    + + + + diff -Naur moodle/lang/en_utf8/help/quiz/omrdiagnostics.html moodle_omrquiz/lang/en_utf8/help/quiz/omrdiagnostics.html --- moodle/lang/en_utf8/help/quiz/omrdiagnostics.html 1970-01-01 05:30:00.000000000 +0530 +++ moodle_omrquiz/lang/en_utf8/help/quiz/omrdiagnostics.html 2010-03-10 17:43:13.000000000 +0530 @@ -0,0 +1,27 @@ +

    Analysis and Correcting the Answer Sheet Data:

    + + +Content: + + + + +

    Analysis of uploaded OMR answer sheet data:

    +

    Answer data analysis is done for detecting problems with the uploaded records. There are two types of analysis available for uploaded answer data.

    +
    1. Record wise analysis:
            When you upload the answer data then the system automatically performs the analysis and shows it record by record. If answers were already uploaded then just click the “upload answers” tab to see the record wise analysis of answer data.

    2. +
    3. Error category wise analysis:
           Under the “upload answers” tab click on the “diagnostics:” list and choose “category wise” and click on “show” button.
    +

    Diagnostics will be shown based on error category.

    +[TOP] + + + +

    Corrective actions on answer data:

    +

    After detecting the problems with the uploaded data you can go and manually change a copy of Scanned OMR data file.

    +

    After seeing the diagnostics the user should manually change the problematic records in the scanned answers file and re upload that file to system.

    +

    For re uploading an answer file go to “upload answers” tab and click on the “change” button present at the bottom of the page and follow the procedure as described in “Upload answers” section above.

    +

    NOTE: Do not change original scanned OMR data file. Always make a copy of it and do the changes on that file.

    +[TOP] + diff -Naur moodle/lang/en_utf8/help/quiz/omrvariant.html moodle_omrquiz/lang/en_utf8/help/quiz/omrvariant.html --- moodle/lang/en_utf8/help/quiz/omrvariant.html 1970-01-01 05:30:00.000000000 +0530 +++ moodle_omrquiz/lang/en_utf8/help/quiz/omrvariant.html 2010-03-10 17:43:13.000000000 +0530 @@ -0,0 +1,46 @@ +

    OMR Variant

    + +

    Creating Variants:

    + +
      +
    1. Generating Variant Numbers:

      +
        +
      1. Click on the "OMR" tab and then "Variants" tab.

      2. +
      3. If not created already, based on the "OMR" configuration parameter "variantcount" that many number of variants will be created automatically with empty "Variant No" field and a default question sequence in "Question Sequence" field. This is the sequence of the questions as present in the master quiz. +
        Note: in the question sequence field each question is represented by its unique id. +

      4. +
      5. Enter the desired variant number for each of the Variants, if not done already and click on "save changes" button.
        + Note: Variant numbers are unique for a quiz.

      6. +
      +

    2. + + +
    3. Deciding Question Sequence for each Variant :
      + There are three options for deciding question sequence for a variant :

      +
        +
      1. Change sequence directly from the text area by placing the question ids at desired place. The sequence should be comma separated with a 0 at the end of the sequence.
        Note: "0" denotes Page Break.

      2. +
      3. Automatic Shuffle: For shuffling the question sequence click on the “shuffle” button.
        + Click on the “save changes” button to save the changes made by shuffling the questions. +

      4. + +
      5. Manual Shuffle: For shuffling questions manually click on the “manual shuffle” button. Use up and down arrows to move a question up and down.

      6. +
      +

    4. + + +
    5. Adding page breaks:
           A page break after a question means the next question will appear on a new page. Page breaks can be added in the question sequence by two ways :

      +
        +
      1. Page break in "question sequence" text area: Add a "0" in the "Question Sequence" text area at the desired place and click on "save changes" button.

      2. +
      3. Page break using "Manual Shuffle" :
        click on "manual shuffle" button then click on "show page breaks" and use up arrow present against last page break to introduce a new page break. Then place it at the desired place using up and down arrows.

      4. +
      +
    6. +
    +

    Printing Variants:

    +
    1. If Variants are already created then the variants can be viewed and printed :
    2. + +
      1. Click on "preview" link present against the variant that you wish to preview. A printable version of the variant will be presented on the screen.

      2. +
      3. Now click on your browser's print preview option to see the layout of the questions along with page breaks. You can go back and adjust the question sequence or page break position if layout is not proper.

      4. +
      5. Click on your web browser's print button to get a hard copy of the quiz paper.

      6. +
      + +
    \ No newline at end of file diff -Naur moodle/lang/en_utf8/help/quiz/quiztype.html moodle_omrquiz/lang/en_utf8/help/quiz/quiztype.html --- moodle/lang/en_utf8/help/quiz/quiztype.html 1970-01-01 05:30:00.000000000 +0530 +++ moodle_omrquiz/lang/en_utf8/help/quiz/quiztype.html 2010-03-10 17:43:13.000000000 +0530 @@ -0,0 +1,34 @@ +

    Quiz Type

    +

    There are two type of quiz: +

    +
    +

    +
    +

    Open the OMR quiz

    +

    +

    +

    +

    Close the quiz

    +

    +

    +

    + +

    Time limit

    +

    +

    +

    + \ No newline at end of file diff -Naur moodle/mod/quiz/db/install.xml moodle_omrquiz/mod/quiz/db/install.xml --- moodle/mod/quiz/db/install.xml 2007-09-25 07:42:00.000000000 +0530 +++ moodle_omrquiz/mod/quiz/db/install.xml 2010-03-10 17:44:19.000000000 +0530 @@ -1,5 +1,5 @@ - @@ -87,7 +87,7 @@ - + @@ -129,7 +129,7 @@ - + @@ -204,7 +204,7 @@ - + @@ -280,7 +280,7 @@
    - +
    @@ -293,6 +293,64 @@
    + + + + + + + + + + + + + + + +
    + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + +
    diff -Naur moodle/mod/quiz/db/upgrade.php moodle_omrquiz/mod/quiz/db/upgrade.php --- moodle/mod/quiz/db/upgrade.php 2008-05-02 05:46:52.000000000 +0530 +++ moodle_omrquiz/mod/quiz/db/upgrade.php 2010-03-10 17:44:19.000000000 +0530 @@ -83,6 +83,93 @@ (($CFG->quiz_review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_CLOSED) << 12)); } + if ($result && $oldversion < 2007112200) { + + /// Define table omrquiz to be created + $table = new XMLDBTable('omrquiz'); + + /// Adding fields to table omrquiz + $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); + $table->addFieldInfo('quizid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); + $table->addFieldInfo('variantcount', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); + $table->addFieldInfo('rollnoposition', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, '0'); + $table->addFieldInfo('variantposition', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, '0'); + $table->addFieldInfo('ansposition', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, '0'); + $table->addFieldInfo('rollnolength', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, '0'); + $table->addFieldInfo('variantlength', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, '0'); + + /// Adding keys to table omrquiz + $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id')); + $table->addKeyInfo('quizid', XMLDB_KEY_FOREIGN, array('quizid'), 'quiz', array('id')); + + /// Launch create table for omrquiz + $result = $result && create_table($table); + } + + if ($result && $oldversion < 2007112200) { + + /// Define table omrquiz_variant to be created + $table = new XMLDBTable('omrquiz_variant'); + + /// Adding fields to table omrquiz_variant + $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); + $table->addFieldInfo('omrquizid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); + $table->addFieldInfo('variantno', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, null); + $table->addFieldInfo('questionsequence', XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null, null, null); + + /// Adding keys to table omrquiz_variant + $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id')); + $table->addKeyInfo('omrquizid', XMLDB_KEY_FOREIGN, array('omrquizid'), 'omrquiz', array('id')); + + /// Launch create table for omrquiz_variant + $result = $result && create_table($table); + } + + if ($result && $oldversion < 2007112200) { + + /// Define table omrquiz_answers to be created + $table = new XMLDBTable('omrquiz_answers'); + + /// Adding fields to table omrquiz_answers + $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); + $table->addFieldInfo('omrquizid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); + $table->addFieldInfo('variantno', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, null); + $table->addFieldInfo('rollno', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, null); + $table->addFieldInfo('name', XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null); + $table->addFieldInfo('answer', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null); + $table->addFieldInfo('valid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, '0'); + $table->addFieldInfo('problem', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null); + + /// Adding keys to table omrquiz_answers + $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id')); + $table->addKeyInfo('omrquizid', XMLDB_KEY_FOREIGN, array('omrquizid'), 'omrquiz', array('id')); + $table->addKeyInfo('rollno', XMLDB_KEY_FOREIGN, array('rollno'), 'user', array('username')); + + /// Launch create table for omrquiz_answers + $result = $result && create_table($table); + } + + if ($result && $oldversion < 2007112200) { + + /// Define table omrquiz_attendence to be created + $table = new XMLDBTable('omrquiz_attendence'); + + /// Adding fields to table omrquiz_attendence + $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); + $table->addFieldInfo('omrquizid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); + $table->addFieldInfo('rollno', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); + + /// Adding keys to table omrquiz_attendence + $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id')); + $table->addKeyInfo('rollno', XMLDB_KEY_FOREIGN, array('rollno'), 'user', array('username')); + $table->addKeyInfo('omrquizid', XMLDB_KEY_FOREIGN, array('omrquizid'), 'omrquiz', array('id')); + $table->addKeyInfo('unique', XMLDB_KEY_UNIQUE, array('omrquizid', 'rollno')); + + /// Launch create table for omrquiz_attendence + $result = $result && create_table($table); + } + + //===== 1.9.0 upgrade line ======// return $result; diff -Naur moodle/mod/quiz/edit.php moodle_omrquiz/mod/quiz/edit.php --- moodle/mod/quiz/edit.php 2009-06-06 05:37:04.000000000 +0530 +++ moodle_omrquiz/mod/quiz/edit.php 2010-03-10 17:44:04.000000000 +0530 @@ -168,6 +168,16 @@ $significantchangemade = true; } } + +//--------------------------------------------For OMR Quiz,------------------------------------------------ + $omrquiz = get_record("omrquiz", "quizid", $cm->instance); + $flag=false; + if(record_exists('omrquiz_variant', 'omrquizid', $omrquiz->id) && + !record_exists('omrquiz_answers', 'omrquizid', $omrquiz->id)){ + $flag=true; + $recordstoupdate=get_records('omrquiz_variant', 'omrquizid', $omrquiz->id,'' , 'id, questionsequence') ; + } +//----------------------------------------author@ Harmeet Saini--------------------------------------------- if (($addquestion = optional_param('addquestion', 0, PARAM_INT)) and confirm_sesskey()) { /// Add a single question to the current quiz quiz_add_quiz_question($addquestion, $quiz); diff -Naur moodle/mod/quiz/lang/en_utf8/quiz.php moodle_omrquiz/mod/quiz/lang/en_utf8/quiz.php --- moodle/mod/quiz/lang/en_utf8/quiz.php 1970-01-01 05:30:00.000000000 +0530 +++ moodle_omrquiz/mod/quiz/lang/en_utf8/quiz.php 2010-03-10 17:44:10.000000000 +0530 @@ -0,0 +1,82 @@ +'; +$string['rollnoposition'] = 'Position of rollNo : $a
    '; +$string['variantposition'] = 'Position of variants : $a
    '; +$string['answerstringposition'] = 'Position of answer string : $a
    '; +$string['rollnolength'] = 'Length of roll number : $a
    '; +$string['variantnolength'] = 'Length of variant number : $a
    '; + +$string['configinfo'] = 'Configuration information for this OMR Quiz is:'; +$string['deletewarning'] = 'All the attempts and answer data associated with all the variants of this omr quiz will be deleted..'; +$string['surechangeconfig'] = 'Are you sure you want to change the configuration?'; +$string['newconfiginfo_afterdelete'] = 'Previous attempts & answer data deleted, new configuration information for this OMR quiz is'; +$string['newconfiginfo'] = 'New configuration information for this OMR quiz is:'; +/* + * Language string for omr.php + * */ +$string['variantheading'] = 'Variants'; +$string['questionsequence'] = 'Question Sequence'; + +/* + * Language string for omrattendance.php + * */ +$string['attendencelist']= 'Attendance for this OMR quiz is:'; +$string['upload_quiz_attendence'] = 'Upload Quiz Attendance'; +//$string['attendanceheading'] = 'Upload Quiz Attendance'; +$string['validate_against_attendence'] = 'By default validity of a student is checked against the list of enrolled students for the course. Would you like to check the validity of students against the attendance list also?'; //edited by harmeet + +/* + * Language string for omr.php + * */ +$string['editing_omr_quiz'] = 'Editing OMR Quiz'; + +/* + * Language string for omranswers.php & omranswers_form.php + * */ +$string['upload_answers'] = 'Upload Answers'; +$string['answersheading'] = 'Upload Answers'; + +/* + * Language string for omrevaluate.php + */ +$string['evaluate_omr_attempts'] = 'Evaluate OMR Attempts'; +$string['attemptsheading'] = 'Evaluate OMR Attempts'; +$string['noofcorrectrecords'] = 'Following $a Records will be processed.'; +$string['noofwrongrecords'] = 'Following $a Records will not be processed.'; +$string['lineno'] = 'Line No'; +$string['name'] = 'Name'; +$string['variantno'] = 'Variant No'; +$string['rollno'] = 'Roll No'; +$string['answer_str'] = 'Answer String'; +$string['diagnostics'] = 'Diagnostics'; +?> diff -Naur moodle/mod/quiz/mod_form.php moodle_omrquiz/mod/quiz/mod_form.php --- moodle/mod/quiz/mod_form.php 2009-10-06 05:35:51.000000000 +0530 +++ moodle_omrquiz/mod/quiz/mod_form.php 2010-03-10 17:44:04.000000000 +0530 @@ -26,6 +26,14 @@ $mform->setType('intro', PARAM_RAW); $mform->setHelpButton('intro', array('richtext', get_string('helprichtext'))); +//---------------------------------------------------For OMR Quiz,------------------------------------------------ + // element of "select" type for "type of quiz". Possible values are "default" or "omr". + $mform->addElement('header', 'omr', get_string('omr_quiz_type','quiz')); + $quiztype=array('default'=>'default','omr'=>'omr'); + $mform->addElement('select', 'quiztype',get_string('omr_type_of_quiz', 'quiz'), $quiztype); //edited by Jalpa + $mform->setHelpButton('quiztype', array('quiztype', get_string('omr_quiz_type', 'quiz'), 'quiz')); ///edited by Jalpa +//----------------------------------------------author@ Harmeet Saini--------------------------------------------- + //------------------------------------------------------------------------------- $mform->addElement('header', 'timinghdr', get_string('timing', 'form')); $mform->addElement('date_time_selector', 'timeopen', get_string('quizopen', 'quiz'), array('optional'=>true)); diff -Naur moodle/mod/quiz/omranswers_form.php moodle_omrquiz/mod/quiz/omranswers_form.php --- moodle/mod/quiz/omranswers_form.php 1970-01-01 05:30:00.000000000 +0530 +++ moodle_omrquiz/mod/quiz/omranswers_form.php 2010-03-10 17:44:04.000000000 +0530 @@ -0,0 +1,58 @@ +libdir.'/formslib.php'); + +class answers_import_form extends moodleform { + + function definition() { + global $COURSE; + $mform =& $this->_form; + // $contexts = $this->_customdata['contexts']; + +//-------------------------------------------------------------------------------- + $mform->addElement('header', 'importfileupload', get_string('importfileupload','quiz')); + + $this->set_upload_manager(new upload_manager('newfile', true, false, $COURSE, false, 0, false, true, false)); + $mform->addElement('file', 'newfile', get_string('upload')); +//-------------------------------------------------------------------------------- + $mform->addElement('submit', 'submitbutton', get_string('uploadthisfile')); + +//-------------------------------------------------------------------------------- + if (has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $COURSE->id))){ + $mform->addElement('header', 'importfilearea', get_string('importfilearea','quiz')); + + $mform->addElement('choosecoursefile', 'choosefile', get_string('choosefile','quiz')); +//-------------------------------------------------------------------------------- + $mform->addElement('submit', 'submitbutton', get_string('importfromthisfile','quiz')); + } +//-------------------------------------------------------------------------------- + $mform->addElement('static', 'dummy', ''); + $mform->closeHeaderBefore('dummy'); + } + + +function get_importfile_name(){ + if ($this->is_submitted() and $this->is_validated()) { + // return the temporary filename to process + return $this->_upload_manager->files['newfile']['tmp_name']; + }else{ + return NULL; + } + } +function get_importfile_realname(){ + if ($this->is_submitted() and $this->is_validated()) { + // return the temporary filename to process + return $this->_upload_manager->files['newfile']['name']; + }else{ + return NULL; + } + } +} +?> \ No newline at end of file diff -Naur moodle/mod/quiz/omranswers.php moodle_omrquiz/mod/quiz/omranswers.php --- moodle/mod/quiz/omranswers.php 1970-01-01 05:30:00.000000000 +0530 +++ moodle_omrquiz/mod/quiz/omranswers.php 2010-03-10 17:44:04.000000000 +0530 @@ -0,0 +1,616 @@ +dirroot.'/mod/quiz/editlib.php'); +require_once("omranswers_form.php"); +require_once($CFG->libdir . '/uploadlib.php'); +require_once("locallib.php"); +require_once($CFG->dirroot.'/lib/questionlib.php'); + +$id = optional_param('cmid', 0, PARAM_INT); // course module id not quiz id +$thispageurl="$CFG->wwwroot/mod/quiz/omranswers.php?cmid=$id"; + +if (! $cm = get_coursemodule_from_id('quiz', $id)) { + error("There is no coursemodule with id $id"); +} + +if (! $course = get_record("course", "id", $cm->course)) { + error("Course is misconfigured"); +} + +if (! $quiz = get_record("quiz", "id", $cm->instance)) { + error("The quiz with id $cm->instance corresponding to this coursemodule $id is missing"); +} + +if (! $omrquiz = get_record("omrquiz", "quizid", $cm->instance)) { + error("The specified omrquiz does not exist"); +} + +if(($omrquiz->variantcount==0)){ + redirect("$CFG->wwwroot/mod/quiz/omruploadconfig.php?cmid=$id", "Upload configuration file first..",1); +} +else if(!record_exists('omrquiz_variant', 'omrquizid', $omrquiz->id)){ + redirect("$CFG->wwwroot/mod/quiz/omr.php?cmid=$id", "Enter variant information first..",1); +} + +require_login($course->id, false, $cm); + +// remove if its not really required +make_upload_directory("$COURSE->id"); // it creates a directory in files area with its name as the value of the course id +//make_upload_directory("./$quiz->name"); + +$navigation = build_navigation(get_string('upload_answers','quiz'), $cm); //edited by Jalpa +print_header_simple(get_string('upload_answers','quiz'), '', $navigation, "", "", true, ""); //edited by Jalpa +$currenttab = 'omr'; +$mode = 'answers'; +include('tabs.php'); + +$displayform=true; +$import_form = new answers_import_form($thispageurl); + +$viewtype=optional_param('diagnostics',"record", PARAM_CLEAN); +$response=optional_param('response',NULL,PARAM_CLEAN); + +if(!$form = $import_form->get_data() ){ + if(!optional_param('change',0,PARAM_CLEAN) and !optional_param('continue',0,PARAM_CLEAN) and !optional_param('yes',0,PARAM_CLEAN)){ + if($omrquiz_response=get_records('omrquiz_answers', 'omrquizid', $omrquiz->id, $sort='id')){ + $displayform=false; + $tempincorrectrecords=array(); + diagnosticsWrapper($omrquiz_response,$viewtype, $thispageurl, $id); + } + } +} + +if(optional_param("yes", NULL, PARAM_CLEAN) && $response){ + //$response=stripslashes($response); //this is to get the data as it is as it was sent coz while sending the data php itself added backslashes in front of double quotes.. + //print_r($response); + //echo"unserialised:
    "; + $response=unserialize(urldecode(stripslashes($response))); + if(!$response){ + error("problem in unserializing serialized string array"); + } + $displayform=false; + set_answers($quiz,$response,$omrquiz,$cm->id,$course->id,true); + + //redirect($thispageurl); +} + +if($displayform){ + if ($import_form->is_cancelled()){ + redirect($thispageurl); + } + if($form){ + // file checks out ok + $fileisgood = false; + if (!empty($form->choosefile)) { + $importfile = "{$CFG->dataroot}/{$COURSE->id}/{$form->choosefile}"; + $realfilename = $form->choosefile; + if (file_exists($importfile)) { + $fileisgood = true; + } + else { + print_error('uploadproblem', 'moodle', $form->choosefile); + } + } + else { + $realfilename = $import_form->get_importfile_realname(); + if (!$importfile = $import_form->get_importfile_name()) { + print_error('uploadproblem', 'moodle'); + } + else { + $fileisgood = true; + } + } + if ($fileisgood){ + if (ansimportprocess($quiz,$importfile,$omrquiz,$cm->id,$course->id)){ + print_error('importerror', 'quiz', $thispageurl->out()); + } + } + // to store the attempts file in files area. + $import_form->_upload_manager->config->deleteothers=false; //this is to avoid deleting other files in the file area + $import_form->_upload_manager->config->handlecollisions=true; //this is to rename the file if a file with this name already exists + $import_form->_upload_manager->process_file_uploads("{$CFG->dataroot}/{$COURSE->id}/{$quiz->name}/answers/"); + + if(!$omrquiz_response=get_records('omrquiz_answers', 'omrquizid', $omrquiz->id, $sort='id')){ + error("Could not get the answers information from db"); + } + } + else{ + print_heading_with_help(get_string('answersheading','quiz'),'omranswers','quiz',NULL,false); //edited by Jalpa + $import_form->display(); + } +} + +print_footer($course); + +// Functions......... +function ansimportprocess($quiz,$importfile,$omrquiz,$cmid,$courseid) { + if (! $lines = readomrdata($importfile)) { + notify( get_string('cannotread','quiz')); + return false; + } + foreach($lines as $line) { + $response[]=$line; + } + set_answers($quiz,$response,$omrquiz,$cmid,$courseid); +} + +function readomrdata($filename) { //similar function is also present in question/format.php + if (is_readable($filename)) { + $filearray = file($filename); + /// Check for Macintosh OS line returns (ie file on one line), and fix + if (ereg("\r", $filearray[0]) AND !ereg("\n", $filearray[0])) { + return explode("\r", $filearray[0]); + } + else { + return $filearray; + } + } + return false; +} + +// in future this function can be specific to the each omr sheet format.i.e for each format there will be a function like this. +function set_answers($quiz,$response,$omrquiz,$cmid,$courseid, $reupload=false){ + //$omrquiz_response= new object(); + $omrquizid=$omrquiz->id; + $rollnoposition=$omrquiz->rollnoposition; + $rollnolength=$omrquiz->rollnolength; + $variantposition=$omrquiz->variantposition; + $ansposition=$omrquiz->ansposition; + $variantlength=$omrquiz->variantlength; + + $rollnumbers=array(); // array for all the roll numbers, it will be indexed by line number of the record being processed. + $duplicaterollnos=array(); // it will be indexed by line number of the record being processed. + $errormessages=array(); // it will be indexed by line number of the record being processed. + $omrquiz_response=new object(); + $omrquizresponsearray=array(); // Array of all the responses that will be fed in database.it will be indexed by line number of the record being processed. + + $questionscount=count(explode(',',$quiz->questions))-1; //note no. of questions are calculated from original quiz. + if(!$omrquiz_response=get_records('omrquiz_answers', 'omrquizid', $omrquizid, $sort='id')){ + foreach($response as $key=>$value){ + $linenumber=$key+1; + $roll=trim(substr($value,$rollnoposition-1,$rollnolength)); + $variantno=trim(substr($value,$variantposition-1,$variantlength)); + $name=trim(substr($value,$rollnolength,($variantposition)-($rollnolength+1))); + $answer=substr($value,$ansposition-1,$questionscount); + $omrquiz_response->omrquizid= $omrquizid; + $omrquiz_response->variantno=$variantno; + $omrquiz_response->rollno=$roll; + $omrquiz_response->name=$name; + $omrquiz_response->answer=$answer; + + if(!($errormessages[$linenumber]=validateomrinput($omrquiz_response,$key, $omrquizid,$courseid))){ + unset($errormessages[$linenumber]); + + } + if(!in_array($omrquiz_response->rollno,$duplicaterollnos) && $omrquiz_response->rollno!=""){ + if(in_array($omrquiz_response->rollno,$rollnumbers)){ + $error="duplicate roll number"; + $duplicaterollnos[$linenumber]=$omrquiz_response->rollno; + } + } + $rollnumbers[$linenumber]=$omrquiz_response->rollno; + + if(isset($error)){ + $errormessages[$linenumber][]=$error; + $omrquiz_response->valid=0; + unset($error); + }else{ + $omrquiz_response->valid=1; + } + + if(!($errormessages[$linenumber])){ + $omrquiz_response->valid=1; + } + else{ + $omrquiz_response->valid=0; + } + $omrquizresponsearray[$linenumber]=$omrquiz_response; + unset($omrquiz_response); + } + + foreach($rollnumbers as $key=>$value){ + foreach($duplicaterollnos as $dupkey=>$dupvalue){ + if($dupvalue==$value and !isset($duplicaterollnos[$key])){ + $duplicaterollnos[$key]=$dupvalue; + $error="duplicate roll number"; + $errormessages[$key][]=$error; + $omrquizresponsearray[$key]->valid=0; + //set_field('omrquiz_answers', 'valid', 0, 'omrquizid', $omrquiz->id, 'rollno', $dupvalue); + } + } + } + + $keystosort=array(); + foreach($omrquizresponsearray as $key=>$value){ + $keystosort[]=$key; + } + sort($keystosort); + foreach($keystosort as $key=>$value){ + $temp[$value]=$omrquizresponsearray[$value]; + } + $omrquizresponsearray=$temp; + unset($keystosort); + unset($temp); + //sorting errormessages by line numbers + $keystosort=array(); + foreach($errormessages as $key=>$value){ + $keystosort[]=$key; + } + sort($keystosort); + + foreach($keystosort as $key=>$value){ + $temp[$value]=$errormessages[$value]; + } + $errormessages=$temp; + unset($key); + + // now merge error messages with omr responses... + foreach($omrquizresponsearray as $lineno => $resp){ + if(!$errormessages[$lineno]){ + continue; + }else{ + $lineerrors=$errormessages[$lineno]; + foreach($lineerrors as $key => $error ){ + $finalerror[]=$error; + } + if(count($finalerror)>1){ + $finalerror=array_unique($finalerror); + $finalerror= implode(',', $finalerror); + }else{ + $finalerror=$finalerror[0]; + } + $omrquizresponsearray[$lineno]->problem=$finalerror; + unset($finalerror); + } + } + // now storing all the records in database... + foreach($omrquizresponsearray as $key => $value){ + if(!insert_record('omrquiz_answers', $value, $returnid=false, $primarykey='id')){ + error("could not insert omrvariant data in table omrquiz_variant"); + } + } + diagnosticsWrapper($omrquizresponsearray,'record','',$cmid); + } + else{ + //Multiple Uploads + if(!optional_param('yes',NULL, PARAM_CLEAN) && !$reupload){ + $pass=urlencode(serialize($response)); + + print_simple_box_start('center', '60%', '#FFAAAA', 20, 'noticebox'); + notify("All the attempts for this omr quiz will be deleted.."); + print_heading("Are you sure you want to reupload the answers?"); + echo'
    '; // action=\"omranswers.php?cmid=$cmid\"> + echo''; + echo''; + echo''; + print_simple_box_end(); + print_footer(); + exit; + } + // deleting attempts.. + $context = get_context_instance(CONTEXT_MODULE, $cmid); + require_capability('mod/quiz:deleteattempts', $context); + $attemptids= get_records('quiz_attempts', 'quiz', $quiz->id, 'id', 'id'); + //if(isset($attemptids) && $attemptids!=''){ + if($attemptids){ + foreach($attemptids as $attemptid=>$value) { + add_to_log($courseid, 'quiz', 'delete attempt', 'report.php?id=' . $cmid, + $attemptid, $cmid); + quiz_delete_attempt($attemptid, $quiz); + } + } + // deleting offline answer data + delete_records('omrquiz_answers', 'omrquizid', $omrquizid); + // reuploading... + set_answers($quiz,$response,$omrquiz,$cmid,$courseid); + } +} + +function validateomrinput($omrquiz_response, $key, $omrquizid, $courseid){ + $linenumber=$key+1; + $error=array(); + if(!isset($omrquiz_response->variantno)){ + $error[]="variant number not present"; + } + if(!isset($omrquiz_response->rollno)){ + $error[]="roll number not present"; + } + if(!isset($omrquiz_response->answer)){ + $error[]="answer string not present"; + } + if(empty($omrquiz_response->variantno)){ + $error[]="variant number is empty"; + } + if($omrquiz_response->variantno!=""){ + if(!is_numeric($omrquiz_response->variantno)){ + $error[]="variant number not numeric"; + } + } + if(empty($omrquiz_response->rollno)){ + $error[]="roll number is empty"; + } + if($omrquiz_response->rollno!=""){ + //check if student exists + if(!record_exists('user', 'username', $omrquiz_response->rollno)){ + $error[]="invalid user"; + } + //check if student is enrolled for this course + if (!$context = get_context_instance(CONTEXT_COURSE, $courseid)) { + print_error('nocontext'); + } + $userid= get_field('user', 'id' ,'username',$omrquiz_response->rollno ); + if(!record_exists('role_assignments', 'contextid', $context->id, 'userid', $userid)){ + $error[]="invalid user"; + } + } + + if(empty($omrquiz_response->answer)){ + $error[]="answer string is empty"; + } + $omrquiz_variants=get_records('omrquiz_variant', 'omrquizid', $omrquizid, $sort='id'); + //this function is here for the time being..shud not remain here as it will be executed for each line in input file...which is not necessary + foreach($omrquiz_variants as $value){ + $variant[]=$value->variantno; + } + if($omrquiz_response->variantno != ""){ + if(!in_array($omrquiz_response->variantno,$variant)){ + $error[]="invalid variant"; + } + } + if($error){ + return $error; + }else{ + return false; + } +} + +function showdiagnostics($omrquiz_response, $viewtype="record"){ + if($viewtype == "record"){ + $count=1; + echo""; + echo''; //edited by Jalpa (All echo '; + echo''; + echo''; + echo''; + echo''; + echo''; + + foreach($omrquiz_response as $key=>$value){ + if(!$value->valid){ + if(is_null($value->problem)){ + $value->problem="invalid user"; + } + echo""; + echo' '; + echo' '; + echo' '; + echo' '; + echo' '; + echo''; + } + $count++; + } + echo"
    statement) + echo'
    '.get_string('lineno','quiz').'
    '.get_string('name','quiz').'
    '.get_string('rollno','quiz').'
    '.get_string('variantno','quiz').'
    '.get_string('diagnostics','quiz').'
    '.$count.'
    '.$value->name.'
    '.$value->rollno.'
    '.$value->variantno.'
    '.$value->problem.'
    "; + }else if($viewtype == "category"){ + $invalidrollno=array(); + $count=1; + foreach($omrquiz_response as $key => $value){ + $allrecords[$count-1]=$value; + if(!$value->valid){ + if(is_null($value->problem)){ + $errormessages[$count]=array("invalid user"); + }else{ + $errormessages[$count]=array_unique(explode(',', $value->problem)); + } + } + $count++; + } + // now we have to categorize errors + // there will be three categories + //1. invalid variant + //2. invalid roll no + //3. duplicate roll numbers + $invalidvariant=array(); + $duplicates=array(); + foreach($errormessages as $key=>$value){ + $temperror=$value;//explode(',',$value); + foreach($temperror as $tempkey=>$tempvalue){ + if(($tempvalue == "variant number not present") || ($tempvalue == "variant number is empty") || ($tempvalue == "variant number not numeric") || ($tempvalue == "invalid variant")){ + $invalidvariant[]=$key; + } + if(($tempvalue=="roll number not present") || ($tempvalue=="roll number is empty") ||($tempvalue=="invalid user") ){ + $invalidrollno[]=$key; + } + if($tempvalue=="duplicate roll number"){ + $duplicates[]=$key; + } + } + } + if($invalidvariant){ + notify("Invalid variant number"); + echo""; + echo''; //edited by Jalpa (All echo '; + echo''; + echo''; + echo''; + echo''; + echo''; + + $invalidvariant=array_unique($invalidvariant); + foreach($invalidvariant as $key=>$invalid){ + $z=$invalid-1; + $k=$key+1; + echo""; + echo' '; + echo' '; + echo' '; + echo' '; + echo' '; + echo''; + } + echo"
    statement) + echo'
    '.get_string('lineno','quiz').'
    '.get_string('name','quiz').'
    '.get_string('rollno','quiz').'
    '.get_string('variantno','quiz').'
    '.get_string('answer_str','quiz').'
    '.$invalid.'
    '.$allrecords[$z]->name.'
    '.$allrecords[$z]->rollno.'
    '.$allrecords[$z]->variantno.'
    '.$allrecords[$z]->answer.'
    "; + echo"
    "; + } + + if($invalidrollno){ + notify("Invalid roll number"); + echo""; + echo''; //edited by Jalpa (All echo '; + echo''; + echo''; + echo''; + echo''; + echo''; + array_unique($invalidrollno); + foreach($invalidrollno as $key=>$invalid){ + $z=$invalid-1; + $k=$key+1; + echo""; + echo' '; + echo' '; + echo' '; + echo' '; + echo' '; + echo''; + } + echo"
    statement) + echo'
    '.get_string('lineno','quiz').'
    '.get_string('name','quiz').'
    '.get_string('rollno','quiz').'
    '.get_string('variantno','quiz').'
    '.get_string('answer_str','quiz').'
    '.$invalid.'
    '.$allrecords[$z]->name.'
    '.$allrecords[$z]->rollno.'
    '.$allrecords[$z]->variantno.'
    '.$allrecords[$z]->answer.'
    "; + echo"
    "; + } + + if($duplicates){ + notify("Duplicate roll number"); + echo""; + echo''; //edited by Jalpa (All echo '; + echo''; + echo''; + echo''; + echo''; + echo''; + array_unique($duplicates); + foreach($duplicates as $key=>$invalid){ + $z=$invalid-1; + $k=$key+1; + echo""; + echo' '; + echo' '; + echo' '; + echo' '; + echo' '; + echo''; + } + echo"
    statement) + echo'
    '.get_string('lineno','quiz').'
    '.get_string('name','quiz').'
    '.get_string('rollno','quiz').'
    '.get_string('variantno','quiz').'
    '.get_string('answer_str','quiz').'
    '.$invalid.'
    '.$allrecords[$z]->name.'
    '.$allrecords[$z]->rollno.'
    '.$allrecords[$z]->variantno.'
    '.$allrecords[$z]->answer.'
    "; + echo"

    "; + } + }else { + error("invalid select field. this should not happen"); + } +} + +function diagnosticsWrapper($omrquiz_response, $viewtype, $thispageurl='', $cmid){ + + Global $CFG; + print_box_start(); + $errorexists=false; + foreach($omrquiz_response as $key=>$value){ + if(!$value->valid){ + $errorexists=true; + break; + } + } + if($errorexists) { + //code to show diagnostics // create a select element to have two options 1. record wise and 2. category wise + echo ""; + echo''; + echo''; + echo''; + echo''; + echo''; + echo''; + echo'
    '; + + echo''.get_string('diagnostics','quiz').''; //edited by Jalpa + echo"wwwroot."/help.php?module=quiz&file=omrdiagnostics.html&forcelang=\" title=\"Help with Diagnosis (new window)\">wwwroot."/pix/help.gif\" alt=\"Help with Daignosis (new window)\" class=\"iconhelp\"/>"; + + echo''; + echo''; + echo'
    '; + echo'
    '; + echo"
    "; + + showdiagnostics($omrquiz_response,$viewtype); + } + + else{//No problem found with uploaded records, these records are shown below. + notify('No problem found with uploaded records, these records are shown below'); + //going to show all the records(records must be correct) + $count=1; + echo""; + echo''; //edited by Jalpa (All echo '; + echo''; + echo''; + echo''; + echo''; + echo''; + + foreach($omrquiz_response as $key=>$value){ + if($value->valid){ + echo""; + echo' '; + echo' '; + echo' '; + echo' '; + echo' '; + echo''; + } + $count++; + } + echo'
    statement) + echo'
    '.get_string('lineno','quiz').'
    '.get_string('name','quiz').'
       '.get_string('rollno','quiz').'
    '.get_string('variantno','quiz').'
                  '.get_string('answer_str','quiz').'
    '.$count.'
    '.$value->name.'
    '.$value->rollno.'
    '.$value->variantno.'
    '.$value->answer.'
    '; + } + echo '
    '; + echo''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo '
    '; + //for displaying change button + echo "
    "; + echo''; + echo'
    '; + echo '
    '; + //for displaying "process attempts" button + echo "
    "; + echo'
    '; + echo'
    '; + echo '
    '; + echo'
    '; + print_box_end(); +} +?> diff -Naur moodle/mod/quiz/omrattendence.php moodle_omrquiz/mod/quiz/omrattendence.php --- moodle/mod/quiz/omrattendence.php 1970-01-01 05:30:00.000000000 +0530 +++ moodle_omrquiz/mod/quiz/omrattendence.php 2010-03-10 17:44:04.000000000 +0530 @@ -0,0 +1,374 @@ + + + + + +libdir . '/uploadlib.php'); +require_once("locallib.php"); + +define('INVALID', 0); +define('VALIDBY_ENROLMENT', 1); +define('VALIDBY_ATTENDENCE', 2); + + +$id = optional_param('cmid', 0, PARAM_INT); // course module id not quiz id +$thispageurl="$CFG->wwwroot/mod/quiz/omrattendence.php?cmid=$id"; + +if (! $cm = get_coursemodule_from_id('quiz', $id)) { + error("There is no coursemodule with id $id"); +} + +if (! $course = get_record("course", "id", $cm->course)) { + error("Course is misconfigured"); +} + +if (! $quiz = get_record("quiz", "id", $cm->instance)) { + error("The quiz with id $cm->instance corresponding to this coursemodule $id is missing"); +} + +if (! $omrquiz = get_record("omrquiz", "quizid", $cm->instance)) { + error("The specified omrquiz does not exist"); +} + +require_login($course->id, false, $cm); + +$navigation = build_navigation(get_string('upload_quiz_attendence','quiz'), $cm); //edited by Jalpa +print_header_simple(get_string('upload_quiz_attendence','quiz'), '', $navigation, "", "", true, ""); //edited by Jalpa +$currenttab = 'omr'; +$mode = 'attendence'; +include('tabs.php'); + +$displayform=true; +$displayattendence=true; +$import_form = new omrattendence_import_form($thispageurl); + +if(optional_param('continue',NULL, PARAM_CLEAN)){ + $displayform=false; + if(record_exists('omrquiz_answers','omrquizid',$omrquiz->id)){ + $displayattendence=false; + print_simple_box_start('center', '60%', '', 20,'noticebox'); + notify(get_string('validate_against_attendence', 'quiz')); //edited by hameet + echo'
    '; + echo''; + echo''; + //echo''; + print_simple_box_end(); + }else{ + //redirect("$CFG->wwwroot/mod/quiz/omranswers.php?cmid=$id","Redirecting for answers upload...",-1); + } + +} + + +if(optional_param('No',NULL, PARAM_CLEAN)){ + $displayform=false; + //redirect($thispageurl); +} + +if(optional_param('Yes',NULL, PARAM_CLEAN)){ + check_user_against_attendence($omrquiz->id); + $displayform=false; + //redirect($thispageurl); +} +if(optional_param('checkattendence',-1,PARAM_CLEAN) == 1){ + check_user_against_attendence($omrquiz->id); +} +if(optional_param('checkattendence',-1,PARAM_CLEAN) == 0){ + check_user_against_enrollments($omrquiz->id); +} + +if(! $form = $import_form->get_data()) { + if($omrattendence=get_records('omrquiz_attendence', 'omrquizid',$omrquiz->id)){ + // && !optional_param('Yes',NULL,PARAM_CLEAN) && !optional_param('No',NULL,PARAM_CLEAN) + //&& !optional_param('continue',NULL,PARAM_CLEAN) + if(!optional_param('change',0,PARAM_CLEAN) && $displayattendence){ + $displayform=false; + print_box_start(); + notify(get_string('attendencelist', quiz)); + $count=1; + foreach($omrattendence as $value){ + if($count < 10){ + echo(' '.$count .'       '.$value->rollno.'
    '); + $count++; + } + else{ + echo(' '.$count .'     '.$value->rollno.'
    '); + $count++; + } + } + echo"
    "; + if(record_exists('omrquiz_answers','omrquizid',$omrquiz->id)){ + $valids=get_records('omrquiz_answers', 'omrquizid', $omrquiz->id); // all the records of an omrquiz + $validatedByAttendence=false; + foreach($valids as $value){ + if($value->valid==2){ + $validatedByAttendence=true; + break; + } + } + echo''; + echo ''; + echo ''; + echo"Check student validity against attendence list"; + } + + //for displaying change button after displaying already present data. + echo ""; + echo'
    '; + echo'
    '; + print_box_end(); + } + } + +} + +if($displayform){ + if ($import_form->is_cancelled()){ + redirect($thispageurl); + } + if($form) { + // file checks out ok + $fileisgood = false; + if (! empty($form->choosefile)) { + $importfile = "{$CFG->dataroot}/{$COURSE->id}/{$form->choosefile}"; + $realfilename = $form->choosefile; + if (file_exists($importfile)) { + $fileisgood = true; + } + else { + print_error('uploadproblem', 'moodle', $form->choosefile); + } + } + else { + $realfilename = $import_form->get_importfile_realname(); + if (! $importfile = $import_form->get_importfile_name()) { + print_error('uploadproblem', 'moodle'); + } + else { + $fileisgood = true; + } + } + if ($fileisgood){ + if (attendenceimportprocess($quiz,$importfile,$omrquiz->id,$cm->id, $course->id , $thispageurl)){ + print_error('importerror', 'quiz', $thispageurl->out()); + } + } + //for printing continue button after displaying attendence data after first upload of file or when there is data already present + echo "
    "; + echo'
    '; + echo'
    '; + print_box_end(); + } + else{ + print_heading_with_help(get_string('upload_quiz_attendence','quiz'),'omrattendance','quiz',NULL,false); //edited by Jalpa + $import_form->display(); + } +} + +print_footer($course); + +//------------------------------------------Functions------------------------------------------- + +/** + * Reads the uploaded attendence file and processes it. + * It calls {@link readattendencedata()} for getting the file contents as an array. + * calls {@link set_omrquiz()} for setting up the configuration for OMR quiz + * + * @param Object $quiz + * @param String $importfile + * @param String $omrquizid + * @param String $cmid + * @param String $courseid + * @param String $thispageurl + */ + +function attendenceimportprocess($quiz,$importfile,$omrquizid,$cmid, $courseid, $thispageurl) { + if (! $lines = readattendencedata($importfile)) { + notify( get_string('cannotread','quiz') ); + return false; + } + if (! $response = trimresponse($lines)) { + notify( "some problem occured, no data present" ); + return false; + } + set_attendence($quiz,$response,$omrquizid,$cmid,$courseid); + +} + +/** + * reads the contents of a file in an array + * @param array $filename + * @return array $filearray the array with contents as the whole file, false on failure. + */ +function readattendencedata($filename) { + if (is_readable($filename)) { + $filearray = file($filename); + /// Check for Macintosh OS line returns (ie file on one line), and fix + if (ereg("\r", $filearray[0]) AND !ereg("\n", $filearray[0])) { + return explode("\r", $filearray[0]); + } + else { + return $filearray; + } + } + return false; +} + +/* + * Just trims every line in array + * @param array $lines file contents as array + * @return array $response trimmed response + */ +function trimresponse($lines) { + foreach($lines as $line) { + $line = trim($line); + $response[]=$line; + } + return $response; +} + +/** + * Extracts attendence from uploaded file. Stores the information in database and then displays the + * attendece information on screen. + * Reuploads the OMR attendence if attendence already present + * + * @param Object $quiz + * @param array $response The array having the contents of uploaded attendence file + * @param String $omrquizid + * @param String $cmid + * @param String $courseid + */ +function set_attendence($quiz, $response, $omrquizid, $cmid, $courseid){ + $rollnumbers; + foreach($response as $value){ + $rollnumbers[]=$value; + } + sort($rollnumbers); + $omrattendence=new object(); + $omrattendence->omrquizid=$omrquizid; + print_box_start(); + + if( !record_exists('omrquiz_attendence', 'omrquizid', $omrquizid) ){ + //first time attendece upload + foreach($rollnumbers as $value){ + $omrattendence->rollno=$value; + if(!insert_record('omrquiz_attendence', $omrattendence)){ + error("could not insert record in omr_attendence"); + } + } + notify("Attendence uploaded successfully"); + }else{ + // reupload omr attendence + delete_records('omrquiz_attendence', 'omrquizid', $omrquizid); + foreach($rollnumbers as $value){ + $omrattendence->rollno=$value; + if(!insert_record('omrquiz_attendence', $omrattendence)){ + error("could not insert record in omr_attendence"); + } + } + notify("Attendence re uploaded successfully"); + if(record_exists('omrquiz_answers','omrquizid',$omrquizid)){ + check_user_against_enrollments($omrquizid); + } + + } + + foreach($rollnumbers as $value){ + echo"$value
    "; + } +} + +/** + * Validates the user against uploaded attendence also. + * By default the validity of user is checked against the enrollment only. That is + * if the user is enrolled in the course then he/she is valid user for a quiz in that course. + * + * @param String $omrquizid + */ +function check_user_against_attendence($omrquizid){ + $attendence=get_records('omrquiz_attendence', 'omrquizid', $omrquizid); + foreach($attendence as $value){ + $attendencelist[]=$value->rollno; + } + $partialValids=get_records('omrquiz_answers','omrquizid', $omrquizid); + foreach($partialValids as $value){ + if($value->valid ==1 || $value->valid ==2){ + if(in_array($value->rollno, $attendencelist)){ + $value->valid=2; + update_record('omrquiz_answers', $value); + }else{ + $value->valid=0; + update_record('omrquiz_answers', $value); + } + } + } + +} + +/** + * If the user validity is already done against attendence in addition to validity against enrollments + * then this function nullifies the validity against attendence and + * validates the user against enrollment only. + * + * @param String $omrquizid + */ +function check_user_against_enrollments($omrquizid){ + $attendence=get_records('omrquiz_attendence', 'omrquizid', $omrquizid); + $invalids=get_records('omrquiz_answers','omrquizid', $omrquizid); + foreach($invalids as $value){ + if($value->valid == 0 && is_null($value->problem)){ + $value->valid=1; + update_record('omrquiz_answers', $value); + }else if($value->valid == 2){ + $value->valid=1; + update_record('omrquiz_answers', $value); + } + } +} + +?> + + + diff -Naur moodle/mod/quiz/omrevaluate.php moodle_omrquiz/mod/quiz/omrevaluate.php --- moodle/mod/quiz/omrevaluate.php 1970-01-01 05:30:00.000000000 +0530 +++ moodle_omrquiz/mod/quiz/omrevaluate.php 2010-03-10 17:44:04.000000000 +0530 @@ -0,0 +1,335 @@ +dirroot.'/mod/quiz/editlib.php'); +require_once("omranswers_form.php"); +require_once($CFG->libdir . '/uploadlib.php'); +require_once("locallib.php"); +require_once($CFG->dirroot.'/lib/questionlib.php'); + +$id = optional_param('cmid', 0, PARAM_INT); // course module id not quiz id +$thispageurl="$CFG->wwwroot/mod/quiz/omrevaluate.php?cmid=$id"; + +if (! $cm = get_coursemodule_from_id('quiz', $id)) { + error("There is no coursemodule with id $id"); +} +if (! $course = get_record("course", "id", $cm->course)) { + error("Course is misconfigured"); +} +if (! $quiz = get_record("quiz", "id", $cm->instance)) { + error("The quiz with id $cm->instance corresponding to this coursemodule $id is missing"); +} +if (! $omrquiz = get_record("omrquiz", "quizid", $cm->instance)) { + error("The specified omrquiz does not exist"); +} +if(($omrquiz->variantcount==0)){ + redirect("$CFG->wwwroot/mod/quiz/omruploadconfig.php?cmid=$id", "Upload configuration file first..",1); +} +else if(!record_exists('omrquiz_variant', 'omrquizid', $omrquiz->id)){ + redirect("$CFG->wwwroot/mod/quiz/omr.php?cmid=$id", "Enter variant information first..",1); +} +else if(!record_exists('omrquiz_answers', 'omrquizid', $omrquiz->id)){ + redirect("$CFG->wwwroot/mod/quiz/omranswers.php?cmid=$id", "upload answers first.",1); +} + +require_login($course->id, false, $cm); + +$navigation = build_navigation(get_string('evaluate_omr_attempts','quiz'), $cm); //edited by Jalpa +print_header_simple(get_string('evaluate_omr_attempts','quiz'), '', $navigation, "", "", true, ""); //edited by Jalpa +$currenttab = 'omr'; +$mode = 'process'; +include('tabs.php'); + +if(optional_param('process',null,PARAM_CLEAN)){ + if($omrquiz_answers=get_records('omrquiz_answers', 'omrquizid', $omrquiz->id, $sort='rollno')){ + ini_set('max_execution_time', 300); // this is to set the execution time of this script to 5 minutes othervise all records will not be processed + foreach($omrquiz_answers as $key=>$value){ + //$variantnoarray[$l]=$value->variantno; + if($value->valid){ + omrevaluate($quiz,$omrquiz->id,$value->variantno,$value->rollno,$value->answer, $course->id, $cm->id); + } + } + redirect("$CFG->wwwroot/mod/quiz/report.php?q=$quiz->id",'' , 0); + } +} +if($omrquiz_response=get_records('omrquiz_answers', 'omrquizid', $omrquiz->id, $sort='id')){ + $displayform=false; + $tempincorrectrecords=array(); + + print_heading_with_help(get_string('attemptsheading','quiz'),'omrattempts','quiz',NULL,false); //edited by Jalpa + print_box_start(); + $correctrecordexist=false; + foreach($omrquiz_response as $key=>$value){ + if($value->valid){ + $correctrecordexist=true; + break; + } + } + if($correctrecordexist){ + $noofcorrectrecords=count_records('omrquiz_answers', 'omrquizid', $omrquiz->id, 'valid', 1); + if(!$noofcorrectrecords){ + $noofcorrectrecords=count_records('omrquiz_answers', 'omrquizid', $omrquiz->id, 'valid', 2); + } + notify(get_string('noofcorrectrecords','quiz',$noofcorrectrecords)); //edited by Jalpa + + echo""; + echo''; //edited by Jalpa (All echo '; + echo''; + echo''; + echo''; + echo''; + echo''; + } + $count=1; + foreach($omrquiz_response as $key=>$value){ + if($value->valid){ + echo""; + echo' '; + echo' '; + echo' '; + echo' '; + echo' '; + echo''; + }else{ + $tempincorrectrecords[$count]= $value; + } + $count++; + } + echo'
    statement) + echo'
    '.get_string('lineno','quiz').'
    '.get_string('name','quiz').'
        '.get_string('rollno','quiz').'
    '.get_string('variantno','quiz').'
                  '.get_string('answer_str','quiz').'
    '.$count.'
    '.$value->name.'
    '.$value->rollno.'
    '.$value->variantno.'
    '.$value->answer.'
    '; + echo'
    '; + if($tempincorrectrecords){ + $noofwrongrecords=count_records('omrquiz_answers', 'omrquizid', $omrquiz->id, 'valid', 0); + notify(get_string('noofwrongrecords','quiz',$noofwrongrecords)); //edited by Jalpa + echo''; + foreach($tempincorrectrecords as $key => $value){ + echo""; + echo' '; + echo' '; + echo' '; + echo' '; + echo' '; + echo''; + } + echo'
    '.$key.'
    '.$value->name.'
    '.$value->rollno.'
    '.$value->variantno.'
    '.$value->answer.'
    '; + } +} +echo "
    "; +echo '
    '; +echo "sesskey\" />"; +echo '
    '; +// echo '
    '; //for savechanges button to work. +echo '
    '; +echo "
    \n"; +print_box_end(); +print_footer($course); + +function omrevaluate($quiz,$omrquizid, $variantno, $userloginid, $answer,$courseid, $cmid){ + //initialisation part ....think of it as before submiting the form..... + global $CFG; + if(!$userid=get_field('user', 'id', 'username', $userloginid)){ + error('Could not get user information'); + } + //it can be an argument with default value 1. so tht in future if multiple offline attempts are allowed, its value can be taken from omrconfig + $attemptnumber=1; //its not used at present. it can be deleted. + $questionlist=get_field('omrquiz_variant', 'questionsequence', 'omrquizid', $omrquizid, 'variantno', $variantno); + $attempt = omrquiz_create_attempt($quiz, $userid, $questionlist); + if (!$attempt->id = insert_record('quiz_attempts', $attempt)) { + error('Could not create new attempt'); + } + add_to_log($courseid, 'quiz', 'attempt', + "review.php?attempt=$attempt->id", + "$quiz->id", $cmid); + + $questionlist=str_replace(',0', '', $questionlist); + $sql = "SELECT q.*, i.grade AS maxgrade, i.id AS instance". + " FROM {$CFG->prefix}question q,". + " {$CFG->prefix}quiz_question_instances i". + " WHERE i.quiz = '$quiz->id' AND q.id = i.question". + " AND q.id IN ($questionlist)"; + + if (!$questions = get_records_sql($sql)) { + print_error('noquestionsfound', 'quiz', 'view.php?q='.$quiz->id); + } + // Load the question type specific information + if (!get_question_options($questions)) { + error('Could not load question options'); + } + if (!$states = get_question_states($questions, $quiz, $attempt, $lastattemptid)) { + error('Could not restore question sessions'); + } + foreach ($questions as $i => $question) { + save_question_session($questions[$i], $states[$i]); + } + + // post initialisation....think as after form submission.... + $finishattempt = 1; + $timelimitseconds=get_field('quiz', 'timelimit', 'id', $quiz->id)*60; + $attempt->timefinish=$attempt->timestart + $timelimitseconds; + $attempt->timemodified=$attempt->timefinish; + $answer="$answer"; // quotes are important... + $answer=str_split($answer); + + foreach($answer as $key=>$value){ + switch("$value"){ + case "A": + $answer[$key]=0; + break; + case "a": + $answer[$key]=0; + break; + case "B": + $answer[$key]=1; + break; + case "b": + $answer[$key]=1; + break; + case "C": + $answer[$key]=2; + break; + case "c": + $answer[$key]=2; + break; + case "D": + $answer[$key]=3; + break; + case "d": + $answer[$key]=3; + break; + case " ": + $answer[$key]=""; + break; + default : + $answer[$key]=""; + } + } + $attemptnumber=1; // or if it is passed as parameter to this fuction then its value can b taken from there + $questionids=$questionlist; // coz in original function name questionid is used...v can change it later + $questionidarray = explode(',', $questionids); + + foreach($questionidarray as $index=>$question){ + if(!$availableoptions=get_records('question_answers', 'question', $question, $sort='', 'id, question')){ + error('unable to fetch records from question_answers'); + } + foreach($availableoptions as $key => $value){ + if($question==$value->question){ + $optionid[$question][]=$key; + } + } + $responses[$question]=$optionid[$question][$answer[$index]]; + } + $responses['timeup']=0; + $event=8; // QUESTION_EVENTCLOSE + $actions = question_extract_omrresponses($questions, $responses, $event); + + // Process each question in turn + foreach($questionidarray as $i) { + if (!isset($actions[$i])) { + $actions[$i]->responses = array('' => ''); + $actions[$i]->event = QUESTION_EVENTOPEN; + } + $actions[$i]->timestamp = $attempt->timefinish; + if (question_process_responses($questions[$i], $states[$i], $actions[$i], $quiz, $attempt)) { + save_question_session($questions[$i], $states[$i]); + }else { + error('could not process the responses'); + } + } + + //now simulate finish the attempt + $closequestionlist="$questionlist"; + $sql = "SELECT q.*, i.grade AS maxgrade, i.id AS instance". + " FROM {$CFG->prefix}question q,". + " {$CFG->prefix}quiz_question_instances i". + " WHERE i.quiz = '$quiz->id' AND q.id = i.question". + " AND q.id IN ($closequestionlist)"; + if (!$closequestions = get_records_sql($sql)) { + error('Questions missing'); + } + if (!get_question_options($closequestions)) { + error('Could not load question options'); + } + // Restore the question sessions + if (!$closestates = get_question_states($closequestions, $quiz, $attempt)) { + error('Could not restore question sessions'); + } + foreach($closequestions as $key => $question) { + $action->event = QUESTION_EVENTCLOSE; + $action->responses = $closestates[$key]->responses; + $action->timestamp = $closestates[$key]->timestamp; + + if (question_process_responses($question, $closestates[$key], $action, $quiz, $attempt)) { + save_question_session($question, $closestates[$key]); + } else { + error('could not process responses while closing attempts'); + } + } + add_to_log($courseid, 'quiz', 'close attempt', + "review.php?attempt=$attempt->id", + "$quiz->id", $cmid); + + if ($responses || $finishattempt) { + if (!update_record('quiz_attempts', $attempt)) { + error('Failed to save the current quiz attempt!'); + } + if (($attempt->attempt > 1 || $attempt->timefinish > 0) and !$attempt->preview) { + quiz_save_best_grade($quiz,$userid); + } + } + return true; +} + +function omrquiz_create_attempt($quiz, $userid, $questionlist) { + global $CFG; + // we are not building on last attempt so create a new attempt + $attempt->quiz = $quiz->id; + $attempt->userid = $userid; + $attempt->preview = 0; + $attempt->layout = "$questionlist"; + $timenow = time(); + $attempt->attempt =1; //this is hardcoded...attempt number + $attempt->sumgrades = 0.0; + $attempt->timestart = get_field('quiz', 'timeopen', 'id', $quiz->id); + $attempt->timefinish = 0; + $attempt->timemodified = $attempt->timestart; + $attempt->uniqueid = question_new_attempt_uniqueid(); + return $attempt; +} + +function question_extract_omrresponses($questions, $formdata, $defaultevent=QUESTION_EVENTSAVE) { + + $time = get_field('quiz', 'timeclose', 'id', $quiz->id); + $actions = array(); + foreach ($formdata as $key => $response) { + if($key!="timeup"){ //because last key of the array is "timeup" which we do not need here. + $quid=$key; + // check if this is a valid id + if (!isset($questions[$quid])) { + error("this is not a valid question id $quid"); + } + $actions[$quid]->event = $defaultevent; + + // Update the state with the new response + $actions[$quid]->responses[] = $response; + + // Set the timestamp + $actions[$quid]->timestamp = $time; + } + } + foreach ($actions as $quid => $notused) { + ksort($actions[$quid]->responses); + } + return $actions; +} +?> diff -Naur moodle/mod/quiz/omr.php moodle_omrquiz/mod/quiz/omr.php --- moodle/mod/quiz/omr.php 1970-01-01 05:30:00.000000000 +0530 +++ moodle_omrquiz/mod/quiz/omr.php 2010-03-10 17:44:04.000000000 +0530 @@ -0,0 +1,767 @@ +dirroot.'/mod/quiz/editlib.php'); + +Global $USER; +$id = optional_param('cmid', 0, PARAM_INT); // course module id not quiz id +$q = optional_param('q', 0, PARAM_INT); // quiz ID +$tempseq=array(); //for shuffling purpose. It will hold temporary sequence of shuffled questions for each variant untill "save" button pressed. + +if (! $cm = get_coursemodule_from_id('quiz', $id)) { + error("There is no coursemodule with id $id"); +} + +if (! $course = get_record("course", "id", $cm->course)) { + error("Course is misconfigured"); +} + +if (! $quiz = get_record("quiz", "id", $cm->instance)) { + error("The quiz with id $cm->instance corresponding to this coursemodule $id is missing"); +} + +// $cm->id gives course module id as in mdl_course_module. +// $cm->instance gives corresponding coursemodule instance id(or quiz id as in mdl_quiz table if module=12). +if (! $omrquiz = get_record("omrquiz", "quizid", $cm->instance)) { + error("The specified omrquiz does not exist"); +} + +if($omrquiz->variantcount==0){ + redirect("$CFG->wwwroot/mod/quiz/omruploadconfig.php?cmid=$id", "Upload configuration file first..",1); +} + +$countvariants=$omrquiz->variantcount; + +//this loop will run on every execution of this page no matter required or not...fix it by introducing some check. +for($k=1;$k<=$countvariants;$k++){ + + //$index refers to id(in mdl_omrquiz_variant) of the variant which is needed to be shuffled. + if($index=optional_param('shuffleid'.$k,NULL,PARAM_CLEAN)){ + + if($tempsequence=optional_param('tempseq'.$k,NULL,PARAM_CLEAN)){ + + $tempseq[$index]=$tempsequence; // maintaining the temporary sequence of questions before user clikced the save button + + } + } +} + +$shufflemanually=false; +$indexformanualshuffle=null; // id of the variant that is set for manual shuffle (id in mdl_omrquiz_variant). +$currentshuffleid=null; // id of the variant that is requested to shuffle currently. + +for($k=1;$k<=$countvariants;$k++){ + + if(optional_param('manualshuffle'.$k,NULL,PARAM_CLEAN)){ + $shufflemanually=true; + + $indexformanualshuffle=$k; + } + + if(optional_param('shufflebutton'.$k,NULL,PARAM_CLEAN)){ + if($currentshuffleid=optional_param('shuffleid'.$k,NULL,PARAM_CLEAN)){ + if(!$tempseq[$currentshuffleid]){ + error("there must be something wrong "); //delete this if cond. if its not reached here even after some significant testing. + } + + $questions=explode(',',$tempseq[$currentshuffleid]); + $countsequence=count($questions); + + foreach($questions as $key=> $value){ + if($value==0){ + $pagebreakposition[]=$key; + unset($questions[$key]); + } + } + $questions=implode(',',$questions); + $questions=explode(',',$questions); + $tempquestions=swapshuffle($questions); + $pagebreakcounter=count($pagebreakposition); + $count=0; + for($i=0;$i<$countsequence;$i++){ + $set=false; + for($z=0;$z<$pagebreakcounter;$z++){ + if($i==$pagebreakposition[$z]){ + $questions[$i]=0; + $count+=1; + $set=true; + break; + } + if(!$set){ + $questions[$i]=$tempquestions[$i-$count]; + } + + } + + } + + $tempseq[$currentshuffleid]= implode(',',$questions); + $tempseq[$currentshuffleid]=trim($tempseq[$currentshuffleid]); + } + } +} + + +//for getting existing variants information +if($omrquiz_variants=get_records('omrquiz_variant', 'omrquizid', $omrquiz->id, $sort='id')){ + $l=1; + foreach($omrquiz_variants as $key=>$value){ + $variantnoarray[$l]=$value->variantno; + $variantidarray[$l]=$key; + $l+=1; + + } + $firstvariantid=$variantidarray[1]; //remains zero after first "save changes" is made +} + + +//------------------- code for right column i.e. for manual shuffling.----------------- +$thispageurl=new moodle_url; +$thispageurl->param('cmid', $cm->id); // have a close check on this +$variantid=optional_param('variantid',NULL,PARAM_CLEAN); + +$quiz_showbreaks = optional_param('showbreaks', -1, PARAM_BOOL); +$quiz_reordertool = optional_param('reordertool', 0, PARAM_BOOL); + +if ($quiz_showbreaks > -1) { + $thispageurl->param('showbreaks', $quiz_showbreaks); +} else { + $quiz_showbreaks = ($CFG->quiz_questionsperpage < 2) ? 0 : 1; +} +if ($quiz_reordertool != 0) { + $thispageurl->param('reordertool', $quiz_reordertool); +} + + +/// Now, check for commands on this page and modify variables as necessary +// If any edit action makes a significant change to the structure of the quiz, then we +// will need to delete all preview attempts. +$significantchangemade = false; + +if (($up = optional_param('up', false, PARAM_INT)) !== false and confirm_sesskey()) { /// Move the given question up a slot + + $questions = explode(",", $omrquiz_variants[$variantid]->questionsequence); + if ($up > 0 and isset($questions[$up])) { + $prevkey = ($questions[$up-1] == 0) ? $up-2 : $up-1; + $swap = $questions[$prevkey]; + $questions[$prevkey] = $questions[$up]; + $questions[$up] = $swap; + $omrquiz_variants[$variantid]->questionsequence = implode(",", $questions); + + // Always have a page break at the end + $omrquiz_variants[$variantid]->questionsequence = $omrquiz_variants[$variantid]->questionsequence . ',0'; + // Avoid duplicate page breaks + $omrquiz_variants[$variantid]->questionsequence = str_replace(',0,0', ',0', $omrquiz_variants[$variantid]->questionsequence); + if (!set_field('omrquiz_variant', 'questionsequence', $omrquiz_variants[$variantid]->questionsequence, 'id', $variantid)) { + error('Could not save question list'); + } + $significantchangemade = true; + } +} +if (($delete = optional_param('delete', false, PARAM_INT)) !== false and confirm_sesskey()) { /// Remove a pagebreak from the variant + $sequence=$omrquiz_variants[$variantid]->questionsequence; + $questions = explode(",", $sequence); + if (!isset($questions[$delete])) { + error("Page break position to delete is incorrect"); + } + + //$question = $questions[$id]; + unset($questions[$delete]); + + $sequence = implode(",", $questions); + // Avoid duplicate page breaks + $sequence = str_replace(',0,0', ',0', $sequence); + $omrquiz_variants[$variantid]->questionsequence=$sequence; + if (!set_field('omrquiz_variant', 'questionsequence', $sequence, 'omrquizid', $omrquiz->id, 'id', $variantid)) { + error('Could not save question list'); + } + $shufflemanually=true; + + $significantchangemade = true; +} + + +if (($down = optional_param('down', false, PARAM_INT)) !== false and confirm_sesskey()) { /// Move the given question down a slot + $questions = explode(",", $omrquiz_variants[$variantid]->questionsequence); + if ($down < count($questions)) { + $nextkey = ($questions[$down+1] == 0) ? $down+2 : $down+1; + $swap = $questions[$nextkey]; + $questions[$nextkey] = $questions[$down]; + $questions[$down] = $swap; + $omrquiz_variants[$variantid]->questionsequence = implode(",", $questions); + + // Avoid duplicate page breaks + + $omrquiz_variants[$variantid]->questionsequence = str_replace(',0,0', ',0', $omrquiz_variants[$variantid]->questionsequence); + if (!set_field('omrquiz_variant', 'questionsequence', $omrquiz_variants[$variantid]->questionsequence, 'id', $variantid)) { + error('Could not save question list'); + } + $significantchangemade = true; + } +} + +if (optional_param('repaginate', false, PARAM_BOOL) and confirm_sesskey()) { /// Re-paginate the quiz + $shufflemanually=true; + + $oldquestions = explode(",", $omrquiz_variants[$variantid]->questionsequence); // the questions in the old order + $questionss = array(); // for questions in the new order + $reorderdata = (array) data_submitted(); + + foreach ($reorderdata as $key => $value) { + if (preg_match('!^o([0-9]+)$!', $key, $matches)) { + $key = $matches[1]; + + // Make sure two questions don't overwrite each other. If we get a second + // question with the same position, shift the second one along to the next gap. + while (array_key_exists($value, $questionss)) { + + $value++; + } + $questionss[$value] = $oldquestions[$key]; + + } + } + + // If ordering info was given, reorder the questions + if ($questionss) { + ksort($questionss); + // Make sure that the quiz does not start with a page break. + while (reset($questionss) == '0') { + array_shift($questionss); + } + + $omrquiz_variants[$variantid]->questionsequence = implode(",", $questionss); + // Always have a page break at the end + $omrquiz_variants[$variantid]->questionsequence = $omrquiz_variants[$variantid]->questionsequence . ',0'; + // Avoid duplicate page breaks + while (strpos($omrquiz_variants[$variantid]->questionsequence, ',0,0')) { + $omrquiz_variants[$variantid]->questionsequence = str_replace(',0,0', ',0', $omrquiz_variants[$variantid]->questionsequence); + } + if (!set_field('omrquiz_variant', 'questionsequence', $omrquiz_variants[$variantid]->questionsequence, 'id', $variantid)) { + error('Could not save question list'); + } + } + $significantchangemade = true; +} + +if( $up or $down or $down===0 or $quiz_reordertool or $quiz_showbreaks or optional_param("shufflemanually",false,PARAM_CLEAN)){ + $shufflemanually=true; +} + +/// Delete any teacher preview attempts if the quiz has been modified +if ($significantchangemade) { + $previewattempts = get_records_select('quiz_attempts', + 'quiz = ' . $quiz->id . ' AND preview = 1'); + if ($previewattempts) { + foreach ($previewattempts as $attempt) { + quiz_delete_attempt($attempt, $quiz); + } + } +} + + +require_login($course->id, false, $cm); +$context = get_context_instance(CONTEXT_MODULE, $cm->id); +// if no questions have been set up yet redirect to edit.php +if (!$quiz->questions and has_capability('mod/quiz:manage', $context)){ + //no questions added, redirect to edit page + redirect($CFG->wwwroot . '/mod/quiz/edit.php?cmid=' . $cm->id); +} + +add_to_log($course->id, "omr-quiz", "edit", "omr.php?id=$cm->id", $quiz->id, $cm->id); + +$navigation = build_navigation(get_string('editing_omr_quiz','quiz'), $cm); //edited by Jalpa +print_header_simple(get_string('editing_omr_quiz','quiz'), '', $navigation, "", "", true, ""); //edited by Jalpa +$currenttab = 'omr'; +$mode = 'variants'; // mode is the subtab that is first activated on cliking the main tab. +include('tabs.php'); + + +if (optional_param('savechanges', false, PARAM_BOOL) and confirm_sesskey()){ + //when no variant already exists for this quiz + if (! $omrquiz_variants) { + $issetallvariants=true; //boolean flag to check wheather info is added for all the variants? + for($i=1;$i<=$omrquiz->variantcount;$i++){ + $temp=trim(optional_param('variantno'.$i, 0, PARAM_CLEAN)); + if($temp==""){ + $issetallvariants=false; + }else{ + $isduplicatevariantno[]=$temp; + } + + } + $a=count($isduplicate=array_unique($isduplicatevariantno)); + + if(!$issetallvariants){ + notify("Enter information for all the variants, changes are not saved.."); + } + else if( $a != $omrquiz->variantcount and $issetallvariants){ + notify("Variant numbers should be unique for a quiz, changes are not saved.."); + } + else{ + for($i=1;$i<=$omrquiz->variantcount;$i++){ + $omrquiz_variant=new object(); // place this before the loop....ensure that functioning doesnt get affected by doing so + $omrquiz_variant->omrquizid=$omrquiz->id; + $omrquiz_variant->variantno=optional_param('variantno'.$i, 0, PARAM_CLEAN); + $omrquiz_variant->questionsequence=optional_param('qseq'.$i, '', PARAM_SEQUENCE); + + if(!insert_record('omrquiz_variant', $omrquiz_variant, $returnid=false, $primarykey='id')){ + error("could not insert omrvariant data in table omrquiz_variant"); + } + } + if($omrquiz_variants=get_records('omrquiz_variant', 'omrquizid', $omrquiz->id, $sort='id')){ + $l=1; + + foreach($omrquiz_variants as $key=>$value){ + $variantnoarray[$l]=$value->variantno; + $variantidarray[$l]=$key; + $l+=1; + } + } + } + } + + //variants already exist for this quiz + else{ + + $issetallvariants=true; //boolean flag to check wheather info is added for all the variants? + for($i=1;$i<=$omrquiz->variantcount;$i++){ + $temp=trim(optional_param('variantno'.$i, 0, PARAM_CLEAN)); + if($temp==""){ + $issetallvariants=false; + }else{ + $isduplicatevariantno[]=$temp; + } + + } + $a=count($isduplicate=array_unique($isduplicatevariantno)); + + if(!$issetallvariants){ + notify("Enter information for all the variants, changes are not saved.."); + } + else if( $a != $omrquiz->variantcount and $issetallvariants){ + notify("Variant numbers should be unique for a quiz, changes are not saved.."); + } + else{ + $j=$firstvariantid+$omrquiz->variantcount; + for($i=$firstvariantid, $count=1;$i<$j;$i++,$count++){ + $omrquiz_variant_update=new object();// place this before the loop....ensure that functioning doesnt get affected by doing so + $omrquiz_variant_update->id=$i; + $omrquiz_variant_update->omrquizid=$omrquiz->id; + $omrquiz_variant_update->variantno=optional_param('variantno'.$count, 0, PARAM_CLEAN); + $omrquiz_variant_update->questionsequence=optional_param('qseq'.$count, '', PARAM_SEQUENCE); + if(!update_record('omrquiz_variant', $omrquiz_variant_update)){ + error("could not update omrvariant data in table omrquiz_variant"); + } + } + + if($omrquiz_variants=get_records('omrquiz_variant', 'omrquizid', $omrquiz->id, $sort='id')){ + $l=1; + foreach($omrquiz_variants as $key=>$value){ + $variantnoarray[$l]=$value->variantno; + $variantidarray[$l]=$key; + $l+=1; + + } + $firstvariantid=$variantidarray[1]; + } + } + unset($tempseq); + } +} + +echo ''; +if(!$shufflemanually){ + echo ''; + + + +if($indexformanualshuffle){ + $variantno=$variantnoarray[$indexformanualshuffle]; + $variantid=$variantidarray[$indexformanualshuffle]; +} + + + +if($shufflemanually){ + if($variantid=optional_param('variantid',NULL,PARAM_CLEAN)){ + //echo"variant id is taken from page post variable"; + }else{ + $variantid=$variantidarray[$indexformanualshuffle]; + } + $variantno=$omrquiz_variants[$variantid]->variantno; + $questionseq=$omrquiz_variants[$variantid]->questionsequence; + + echo ''; +} +echo ''; +echo '
    '; +} +else{ + echo '
    '; +} +print_box_start(); + +//print_heading(get_string('variantheading','quiz'),"", 3); //edited by Jalpa +print_heading_with_help(get_string('variantheading','quiz'),'omrvariant','quiz',NULL,false); //edited by Jalpa + +echo "
    id\">"; +echo '
    '; +echo "sesskey\" />"; +//echo $pageurl->hidden_params_out(); +echo "\n"; +echo ""; +echo ""; //edited by Jalpa +echo ""; //edited by Jalpa +if($omrquiz_variants){ + echo ""; +} + +echo "\n"; +if(isset($firstvariantid)){ + $variant=$firstvariantid; +} +if(!$omrquiz_variants){ + for($i=1;$i <= $omrquiz->variantcount;$i++){ + echo ""; + echo ""; + echo ""; + echo '"; + } +} + +elseif($variant){ + //processing when buklets are already present and save changes are made more thn once + // if possible use foreach loop because here an assumption is made that starting from a particular id for a variant(e.g. 48) the next variant must have consecutive id. + for($i=1;$i <= $omrquiz->variantcount;$i++,$variant++){ + echo ""; + echo ""; + echo ""; + + + //shuffleid gives id in omrquiz_variant table. + echo ""; + + echo '"; + } +} +//after clicking save changes for the first time... coz $key is not set yet +else{ + //echo"
    processing when variants are already present and "save changes" is made for the first time
    "; + + $i=1; + foreach($omrquiz_variants as $key=>$value){ + echo ""; + echo ""; + echo ""; + echo ""; + echo '"; + $i+=1; + } +} +echo "
    #".get_string('variantno','quiz')."".get_string('questionsequence','quiz')."Action
    $i"; + echo ''; + echo""; + echo ''; + echo "'; + echo "
    $i"; + + if(record_exists('omrquiz_answers', 'omrquizid', $omrquiz->id)){ + echo ''; + }else{ + echo ''; + } + + echo""; + //if($currentshuffleid){ + if($tempseq[$currentshuffleid] and $variant==$currentshuffleid){ + if(record_exists('omrquiz_answers', 'omrquizid', $omrquiz->id)){ + echo ''; + }else{ + echo ''; + } + + echo ''; + // } + }elseif(!isset($tempseq[$variant])){ + if(record_exists('omrquiz_answers', 'omrquizid', $omrquiz->id)){ + echo ''; + }else{ + echo ''; + } + echo ''; + } + else{ + if(record_exists('omrquiz_answers', 'omrquizid', $omrquiz->id)){ + echo ''; + }else{ + echo ''; + } + echo ''; + } + echo ""; + if(record_exists('omrquiz_answers', 'omrquizid', $omrquiz->id)){ + // do not show the button + }else{ + echo ''; + echo" "; + } + + if(record_exists('omrquiz_answers', 'omrquizid', $omrquiz->id)){ + // do not show the button + }else{ + echo ''; + echo" "; + } + + echo 'preview'; + echo ''; + + echo "'; + echo "
    $i"; + echo ''; + echo""; + echo ''; + echo ""; + //onClick="'.shuffle($omrquiz_variant[$key]->questionsequence).'" + echo ''; + echo ''; + echo ''; + echo ''; + echo ' preview'; + echo "'; + echo "
    "; +echo"
    "; +echo"
    "; +if(record_exists('omrquiz_answers', 'omrquizid', $omrquiz->id)){ + //do not show the save button +}else{ + echo '
    '; +} +echo '
    '; +echo "
    \n"; +print_box_end(); +echo '
    '; + print_box_start(); + print_heading("Questions in variant $variantno","", 4); + //echo"questions in this variant are $questionseq"; + print_omrquestion_list($questionseq, $quiz,$variantid, $thispageurl, $quiz_showbreaks, $quiz_reordertool); + //echo ''; + print_box_end(); + + echo '
    '; + +print_footer($course); + + +//-------------------------------------functions---------------------------------------- + +/** + * Prints the questions present in the currently selected variant for manual shuffle. + * questions can be shuffled manually by using up and down arrows. + * Also page break can be added between the questions. Reordering tool is also provided. + * + * @param string $questionseq comma separated values of question ids + * @param object $quiz + * @param string $variantid + * @param object $pageurl + * @param boolean $showbreaks + * @param boolean $reordertool + * @return boolean + */ +function print_omrquestion_list($questionseq,$quiz,$variantid, $pageurl, $showbreaks=true, $reordertool=false) { + global $USER, $CFG, $QTYPES; + $strorder = get_string("order"); + $strquestionname = get_string("questionname", "quiz"); + $strview = get_string("view"); + $straction = get_string("action"); + $strmoveup = get_string("moveup"); + $strmovedown = get_string("movedown"); + $strremove = get_string('remove', 'quiz'); + $strtype = get_string("type", "quiz"); + $strpreview = get_string("preview", "quiz"); + + if (!$questionseq) {// modify the internal contents + echo "

    "; + print_string("noquestions", "quiz"); + echo "

    "; + return 0; + } + + if (!$questions = get_records_sql("SELECT q.*,c.contextid + FROM {$CFG->prefix}question q, + {$CFG->prefix}question_categories c + WHERE q.id in ($questionseq) + AND q.category = c.id")) { + echo "

    "; + print_string("noquestions", "quiz"); + echo "

    "; + return 0; + } + + $count = 0; + $qno = 1; + $order = explode(',', $questionseq); + $lastindex = count($order)-1; + // If the list does not end with a pagebreak then add it on. + if ($order[$lastindex] != 0) { + $order[] = 0; + $lastindex++; + } + + //form for manual shuffling + echo "
    "; // this needs to be looked at + echo '
    '; + echo "sesskey\" />"; + + echo ''; + echo $pageurl->hidden_params_out(); + + echo "\n"; + echo ""; + echo ""; + echo ""; + echo ""; + echo "\n"; + + + foreach ($order as $i => $qnum) { //here $qnum gives id of the question as in mdl_questions. + + + if ($qnum and empty($questions[$qnum])) { + continue; + } + + + + // If the questiontype is missing change the question type + if ($qnum and !array_key_exists($questions[$qnum]->qtype, $QTYPES)) { + $questions[$qnum]->qtype = 'missingtype'; + } + + // Show the re-ordering field if the tool is turned on. + // But don't show it in front of pagebreaks if they are hidden. + if ($reordertool) { + + + if ($qnum or $showbreaks) { + + echo ' '; + + + } else { + + echo ' '; + } + } else { + echo ''; + } + if ($qnum == 0) { // This is a page break + if ($showbreaks) { + echo ''; + echo ''; + echo ''; + } + $count++; + // missing here, if loop is broken, need to close the + echo ""; + continue; + } + $question = $questions[$qnum]; + + echo ""; + echo ""; + + // Print and increment question number + echo ''; + $qno += $question->length; + + + echo ''; + echo'"; + $count++; + + } + + + echo"
    $strorder#$strquestionname$straction
     '; + echo ''; + echo ''; + echo ''; + echo '

    Page break
    '; + if ($count > 1) { + + + echo "out_action(array('up'=>$count, 'variantid'=>$variantid))."\">pixpath/t/up.gif\" class=\"iconsmall\" alt=\"$strmoveup\" />"; + } + echo ' '; + if ($count < $lastindex) { + echo "out_action(array('down'=>$count, 'variantid'=>$variantid))."\">pixpath/t/down.gif\" class=\"iconsmall\" alt=\"$strmovedown\" />"; + + echo "out_action(array('delete'=>$count, 'variantid'=>$variantid))."\"> + pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strremove\" />"; + } + echo '
     
    "; + if ($count != 0) { + echo "out_action(array('up'=>$count, 'variantid'=>$variantid))."\">pixpath/t/up.gif\" class=\"iconsmall\" alt=\"$strmoveup\" />"; + } + echo ""; + if ($count < $lastindex-1) { + echo "out_action(array('down'=>$count, 'variantid'=>$variantid))."\">pixpath/t/down.gif\" class=\"iconsmall\" alt=\"$strmovedown\" />"; + } + echo "'.($question->length ? $qno : ' ').'' . format_string($question->name) . ''; + + if (($question->qtype != 'random')){ + echo quiz_question_preview_button($quiz, $question); + } + + echo "
    \n"; + + echo '
    '; + echo '
    '; + echo '
    '; + echo "
    \n"; + + /// Form to choose to show pagebreaks and to repaginate quiz + echo '
    '; + echo '
    '; + echo ''; + echo $pageurl->hidden_params_out(array('showbreaks', 'reordertool')); + echo ''; + echo ''; + echo ''; + echo ''; + print_string('showbreaks', 'quiz'); + echo '
    '; + echo ''; + print_string('reordertool', 'quiz'); + echo ' '; + helpbutton('reorderingtool', get_string('reordertool', 'quiz'), 'quiz'); + + + echo '
    '; + echo '
    '; + + return true; +} +?> diff -Naur moodle/mod/quiz/omrpreview.php moodle_omrquiz/mod/quiz/omrpreview.php --- moodle/mod/quiz/omrpreview.php 1970-01-01 05:30:00.000000000 +0530 +++ moodle_omrquiz/mod/quiz/omrpreview.php 2010-03-10 17:44:04.000000000 +0530 @@ -0,0 +1,103 @@ + +Preview Quiz + +dirroot.'/mod/quiz/editlib.php'); + +$cmid=optional_param('cmid',NULL,PARAM_INT); +$omrquizid=optional_param('omrquizid',NULL,PARAM_INT); +$variantid=optional_param('variantid',NULL,PARAM_INT); +$variantno=get_field('omrquiz_variant', 'variantno', 'id', $variantid); + +if (! $cm = get_coursemodule_from_id('quiz', $cmid)) { + error("There is no coursemodule with id $id"); +} +if (! $course = get_record("course", "id", $cm->course)) { + error("Course is misconfigured"); +} +if (! $quiz = get_record("quiz", "id", $cm->instance)) { + error("The quiz with id $cm->instance corresponding to this coursemodule $id is missing"); +} + +require_login($course->id, false, $cm); +$quizname=$quiz->name; +$coursename=$course->fullname; +$coursecategoryname=get_field('course_categories', 'name', 'id', $course->category); + +print_omrheader($variantno,$quiz,$coursename,$coursecategoryname); + +$questionseq=get_field('omrquiz_variant', 'questionsequence', 'omrquizid', $omrquizid, 'id', $variantid); +$pagebreakposition=array(); +$questionsequence=explode(',',$questionseq); + +foreach($questionsequence as $key=> $value){ + if($value==0){ + $pagebreakposition[]=$key; + unset($questionsequence[$key]); + } +} +$subtractfrompagebreak=0; +$newpagebreakposition=array(); + +foreach($pagebreakposition as $value){ + $value=$value-$subtractfrompagebreak; + $newpagebreakposition[]=$value; + $subtractfrompagebreak++; +} +$questionsequence=implode(',',$questionsequence); +$questionsequence=explode(',',$questionsequence); +$questionseq=$questionsequence; +$questioncount=count($questionsequence); + +echo''; +echo'
      '; +for($i=0;$i<$questioncount;$i++){ + foreach($newpagebreakposition as $value){ + if($i==$value){ + echo'
      '; + } + } + $j=$i+1; + //echo'Q. '.$j.' '; + $questiontext[$i]=get_field('question', 'questiontext', 'id', $questionseq[$i]); + $options[$i]=get_records('question_answers', 'question',$questionseq[$i],'id'); + //echo" "; + echo '
    1. '.$questiontext[$i].'
    2. '; + + echo'
        '; + foreach($options[$i] as $key=>$value){ + echo'
      1. '; + echo''.$value->answer.''; + } + echo'
      '; + echo'
      '; +} +echo'
    '; +echo'
    '; + +function print_omrheader($variantno,$quiz,$coursename,$coursecategoryname){ + echo'

    variant No: '.$variantno.'

    '; + echo'

    '.$coursecategoryname.'

    '; + echo'

    '.$coursename.'

    '; + echo'

    '.$quiz->name.'


    '; + echo''; + echo''; + echo''; + echo''; + echo''; + echo'
    Date: '.date("D, M jS Y",$quiz->timeopen).'
    Max Marks: '.$quiz->grade.'
    Student ID:Duration: '.$quiz->timelimit.' minutes

    '; + echo"$quiz->intro
    "; + echo'
    '; +} +?> + + diff -Naur moodle/mod/quiz/omruploadattendence_form.php moodle_omrquiz/mod/quiz/omruploadattendence_form.php --- moodle/mod/quiz/omruploadattendence_form.php 1970-01-01 05:30:00.000000000 +0530 +++ moodle_omrquiz/mod/quiz/omruploadattendence_form.php 2010-03-10 17:44:04.000000000 +0530 @@ -0,0 +1,51 @@ +libdir.'/formslib.php'); + +//class for creating upload form for OMR quiz attendence upload. It is called from omrattendence.php +class omrattendence_import_form extends moodleform { + + function definition() { + global $COURSE; + $mform =& $this->_form; + // $contexts = $this->_customdata['contexts']; + +//-------------------------------------------------------------------------------- + $mform->addElement('header', 'importfileupload', get_string('importfileupload','quiz')); + + $this->set_upload_manager(new upload_manager('newfile', true, false, $COURSE, false, 0, false, true, false)); + $mform->addElement('file', 'newfile', get_string('upload')); +//-------------------------------------------------------------------------------- + $mform->addElement('submit', 'submitbutton', get_string('uploadthisfile')); + +//-------------------------------------------------------------------------------- + if (has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $COURSE->id))){ + $mform->addElement('header', 'importfilearea', get_string('importfilearea','quiz')); + + $mform->addElement('choosecoursefile', 'choosefile', get_string('choosefile','quiz')); +//-------------------------------------------------------------------------------- + $mform->addElement('submit', 'submitbutton', get_string('importfromthisfile','quiz')); + } +//-------------------------------------------------------------------------------- + $mform->addElement('static', 'dummy', ''); + $mform->closeHeaderBefore('dummy'); + } + + +function get_importfile_name(){ + if ($this->is_submitted() and $this->is_validated()) { + // return the temporary filename to process + return $this->_upload_manager->files['newfile']['tmp_name']; + }else{ + return NULL; + } + } +function get_importfile_realname(){ + if ($this->is_submitted() and $this->is_validated()) { + // return the temporary filename to process + return $this->_upload_manager->files['newfile']['name']; + }else{ + return NULL; + } + } +} +?> \ No newline at end of file diff -Naur moodle/mod/quiz/omruploadconfig_form.php moodle_omrquiz/mod/quiz/omruploadconfig_form.php --- moodle/mod/quiz/omruploadconfig_form.php 1970-01-01 05:30:00.000000000 +0530 +++ moodle_omrquiz/mod/quiz/omruploadconfig_form.php 2010-03-10 17:44:04.000000000 +0530 @@ -0,0 +1,51 @@ +libdir.'/formslib.php'); + +//class for creating upload form for OMR configuration upload. It is called from omruploadconfig.php +class omrconfig_import_form extends moodleform { + + function definition() { + global $COURSE; + $mform =& $this->_form; + // $contexts = $this->_customdata['contexts']; + +//-------------------------------------------------------------------------------- + $mform->addElement('header', 'importfileupload', get_string('importfileupload','quiz')); + + $this->set_upload_manager(new upload_manager('newfile', true, false, $COURSE, false, 0, false, true, false)); + $mform->addElement('file', 'newfile', get_string('upload')); +//-------------------------------------------------------------------------------- + $mform->addElement('submit', 'submitbutton', get_string('uploadthisfile')); + +//-------------------------------------------------------------------------------- + if (has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $COURSE->id))){ + $mform->addElement('header', 'importfilearea', get_string('importfilearea','quiz')); + + $mform->addElement('choosecoursefile', 'choosefile', get_string('choosefile','quiz')); +//-------------------------------------------------------------------------------- + $mform->addElement('submit', 'submitbutton', get_string('importfromthisfile','quiz')); + } +//-------------------------------------------------------------------------------- + $mform->addElement('static', 'dummy', ''); + $mform->closeHeaderBefore('dummy'); + } + + +function get_importfile_name(){ + if ($this->is_submitted() and $this->is_validated()) { + // return the temporary filename to process + return $this->_upload_manager->files['newfile']['tmp_name']; + }else{ + return NULL; + } + } +function get_importfile_realname(){ + if ($this->is_submitted() and $this->is_validated()) { + // return the temporary filename to process + return $this->_upload_manager->files['newfile']['name']; + }else{ + return NULL; + } + } +} +?> \ No newline at end of file diff -Naur moodle/mod/quiz/omruploadconfig.php moodle_omrquiz/mod/quiz/omruploadconfig.php --- moodle/mod/quiz/omruploadconfig.php 1970-01-01 05:30:00.000000000 +0530 +++ moodle_omrquiz/mod/quiz/omruploadconfig.php 2010-03-10 17:44:04.000000000 +0530 @@ -0,0 +1,356 @@ +dirroot.'/mod/quiz/editlib.php'); //needed for tabs.php +require_once("omruploadconfig_form.php"); +require_once($CFG->libdir . '/uploadlib.php'); +require_once("locallib.php"); +//require_once($CFG->dirroot.'/lib/questionlib.php'); + +$id = optional_param('cmid', 0, PARAM_INT); // course module id not quiz id +$thispageurl="$CFG->wwwroot/mod/quiz/omruploadconfig.php?cmid=$id"; + +if (! $cm = get_coursemodule_from_id('quiz', $id)) { + error("There is no coursemodule with id $id"); +} + +if (! $course = get_record("course", "id", $cm->course)) { + error("Course is misconfigured"); +} + +if (! $quiz = get_record("quiz", "id", $cm->instance)) { + error("The quiz with id $cm->instance corresponding to this coursemodule $id is missing"); +} + +if (! $omrquiz = get_record("omrquiz", "quizid", $cm->instance)) { + error("The specified omrquiz does not exist"); +} + +require_login($course->id, false, $cm); +$navigation = build_navigation(get_string('upload_omr_configuration','quiz'), $cm); //edited by Jalpa +print_header_simple(get_string('upload_omr_configuration','quiz'), '', $navigation, "", "", true, ""); //edited by Jalpa +$currenttab = 'omr'; +$mode = 'omrconfig'; +include('tabs.php'); + +//for deleting attempts and answer data when user selected reupload configuration where number of variants in this configuration differ from previous omr configuration +if(optional_param('yes',NULL,PARAM_CLEAN)){ + $response=optional_param('response',NULL, PARAM_RAW); + $response=stripslashes($response); + $response=unserialize($response); + + set_omrconfig($quiz,$response,$omrquiz->id,$cm->id,$course->id, true , $thispageurl); + + echo "
    "; + echo'
    '; + echo'
    '; + + print_footer($course); + exit; +} + + +$displayform=true; +$import_form = new omrconfig_import_form($thispageurl); + +if(! $form = $import_form->get_data() and !optional_param('yes',0,PARAM_CLEAN)) { + if(!optional_param('change',0,PARAM_CLEAN) and !optional_param('continue',0,PARAM_CLEAN)){ + if($omrquizconfig=get_record('omrquiz', 'quizid',$quiz->id)){ + if($omrquizconfig->variantcount > 0){ + $displayform=false; + print_box_start(); + notify(get_string('configinfo', 'quiz')); + echo(get_string('noofvariants','quiz',$omrquizconfig->variantcount)); + echo(get_string('rollnoposition','quiz',$omrquizconfig->rollnoposition)); + echo(get_string('variantposition','quiz',$omrquizconfig->variantposition)); + echo(get_string('answerstringposition','quiz',$omrquizconfig->ansposition)); + echo(get_string('rollnolength','quiz',$omrquizconfig->rollnolength)); + echo(get_string('variantnolength','quiz',$omrquizconfig->variantlength)); + + + //for displaying change button after displaying already present data. + echo "
    "; + echo'
    '; + echo'
    '; + print_box_end(); + } + } + } +} + +if($displayform){ + if ($import_form->is_cancelled()){ + redirect($thispageurl); + } + if($form) { + // file checks out ok + $fileisgood = false; + if (! empty($form->choosefile)) { + $importfile = "{$CFG->dataroot}/{$COURSE->id}/{$form->choosefile}"; + $realfilename = $form->choosefile; + if (file_exists($importfile)) { + $fileisgood = true; + } + else { + print_error('uploadproblem', 'moodle', $form->choosefile); + } + } + else { + $realfilename = $import_form->get_importfile_realname(); + if (! $importfile = $import_form->get_importfile_name()) { + print_error('uploadproblem', 'moodle'); + } + else { + $fileisgood = true; + } + } + if ($fileisgood){ + if (configimportprocess($quiz,$importfile,$omrquiz->id,$cm->id, $course->id , $thispageurl)){ + print_error('importerror', 'quiz', $thispageurl->out()); + } + } + //for printing continue button after displaying config data. + echo "
    "; + echo'
    '; + echo'
    '; + //print_box_end(); + } + else{ + print_heading_with_help('Upload a Configuration File','omrconfigupload','quiz',NULL,false); //edited by Jalpa + $import_form->display(); + } +} +print_footer($course); + +//-------------------------------------Functions--------------------------------------------- + +/** + * Reads the uploaded configuration file and processes it. + * It calls {@link readomrdata()} for getting the file contents as an array. + * calls {@link set_omrquiz()} for setting up the configuration for OMR quiz + * + * @param Object $quiz + * @param String $importfile + * @param String $omrquizid + * @param String $cmid + * @param String $courseid + * @param String $thispageurl + */ +function configimportprocess($quiz,$importfile,$omrquizid,$cmid, $courseid, $thispageurl) { + if (! $lines = readomrdata($importfile)) { + notify( get_string('cannotread','quiz') ); + return false; + } + if (! $response = trimresponse($lines)) { + notify( "some problem occured, no data present" ); + return false; + } + set_omrconfig($quiz,$response,$omrquizid,$cmid,$courseid,false,$thispageurl); +} + +/** + * reads the contents of a file in an array + * @param array $filename + * @return array $filearray the array with contents as the whole file, false on failure. + */ +function readomrdata($filename) { + if (is_readable($filename)) { + $filearray = file($filename); + /// Check for Macintosh OS line returns (ie file on one line), and fix + if (ereg("\r", $filearray[0]) AND !ereg("\n", $filearray[0])) { + return explode("\r", $filearray[0]); + } + else { + return $filearray; + } + } + return false; +} + +/* + * Just trims every line in array + * @param array $lines file contents as array + * @return array $response trimmed response + */ +function trimresponse($lines) { + foreach($lines as $line) { + $line = trim($line); + $response[]=$line; + } + return $response; +} + +/** + * Extracts OMR configuration parameters from uploaded file. Stores the information in database and then displays the + * configuration information on screen. + * Reuploads the OMR configuration if configuration already present + * + * @param Object $quiz + * @param array $response The array having the contents of uploaded configuration file + * @param String $omrquizid + * @param String $cmid + * @param String $courseid + * @param boolean $deleteattempts whether to delete attempts on configuration reupload. False by default. + * @param String $thispageurl + */ +function set_omrconfig($quiz,$response,$omrquizid,$cmid,$courseid,$deleteattempts=false, $thispageurl){ + + if($deleteattempts){ + $omrquiz_config=new object(); + foreach($response as $key => $value){ + $omrquiz_config->$key=$value; + } + }else{ + $omrquiz_config=new object(); + + // extract config params from uploaded file + $conf_param=array(1=>"variantcount","rollnoposition","variantposition","ansposition","rollnolength","variantlength"); + $a=1; + + // search for every configuration parameter in the uploaded configuration file. + foreach($response as $value){ + $pos=stripos($value,$conf_param[$a]); + if($pos!==false){ + $pos1=stripos($value,':'); + $parameter=substr($value,$pos1+1); + trim($parameter); + $temp=$conf_param[$a]; + $$temp=$parameter; + $a=$a+1; + } + } + $omrquiz_config->id=$omrquizid; + $omrquiz_config->variantcount=$variantcount; + $omrquiz_config->rollnoposition=$rollnoposition; + $omrquiz_config->variantposition=$variantposition; + $omrquiz_config->ansposition=$ansposition; + $omrquiz_config->rollnolength=$rollnolength; + $omrquiz_config->variantlength=$variantlength; + + //TODO check for input validation + } + + + //print_box_start(); + if($previousomrconfig = get_records('omrquiz', 'quizid', $quiz->id, $sort='id') ){ + foreach($previousomrconfig as $key => $value){ + $issetvariantcount= $value->variantcount; + break; + } + } + + if(!$issetvariantcount){ // because if variantcount is set that means config is already uploaded + // insert information in mdl_omrquiz table + if(!update_record('omrquiz', $omrquiz_config)){ + //it shud b an error statement.. + error("could not update omrquiz table with omr config"); + } + + // now code for displaying some information after configuration upload to database... + print_box_start(); + notify(get_string('configinfo', 'quiz')); + echo(get_string('noofvariants','quiz',$omrquiz_config->variantcount)); + echo(get_string('rollnoposition','quiz',$omrquiz_config->rollnoposition)); + echo(get_string('variantposition','quiz',$omrquiz_config->variantposition)); + echo(get_string('answerstringposition','quiz',$omrquiz_config->ansposition)); + echo(get_string('rollnolength','quiz',$omrquiz_config->rollnolength)); + echo(get_string('variantnolength','quiz',$omrquiz_config->variantlength)); + print_box_end(); + }else{ + //reupload omr configuraion + //reuploading configuration when variant count is not same as earlier + if(!($issetvariantcount == $omrquiz_config->variantcount)){ + // first notify user that attempts will be deleted and ask whether to continue or not + if(!$deleteattempts){ + foreach($omrquiz_config as $key => $value){ + $pass[$key]=$value; + } + + $pass=serialize($pass); + + //$navigation = build_navigation("change configuration?", $cm); + //print_header_simple("change configuration?", '', $navigation, "", "", true, ""); + print_simple_box_start('center', '60%', '#FFAAAA', 20, 'noticebox'); + notify(get_string('deletewarning','quiz')); + print_heading(get_string('surechangeconfig','quiz')); + echo'
    '; + echo''; + echo''; + echo''; + echo''; + print_simple_box_end(); + print_footer(); + exit; + + }else{ + //delete user attempts and answer data for all the variants if there is a change in variantcount + + // first delete attempts related to all the variants for this omrquiz + $context = get_context_instance(CONTEXT_MODULE, $cmid); + require_capability('mod/quiz:deleteattempts', $context); + $attemptids= get_records('quiz_attempts', 'quiz', $quiz->id, 'id', 'id'); + if($attemptids != ''){ + foreach($attemptids as $attemptid=>$value) { + add_to_log($courseid, 'quiz', 'delete attempt', 'report.php?id=' . $cmid, + $attemptid, $cmid); + quiz_delete_attempt($attemptid, $quiz); + } + } + + // check if answers and variants exist already then only delete + if(record_exists('omrquiz_variant', 'omrquizid', $omrquizid)){ + + //delete all the answer data associated with this omrquiz. + if(record_exists('omrquiz_answers', 'omrquizid', $omrquizid)){ + delete_records('omrquiz_answers', 'omrquizid', $omrquizid); + } + + + // then delete all the variants + if(!delete_records('omrquiz_variant', 'omrquizid', $omrquizid)){ + echo"could not delete omrquiz variants "; + } + } + + + // now update the record for new configuration + if(!update_record('omrquiz', $omrquiz_config)){ + echo"could not update omrquiz table with omr config"; + } + print_box_start(); + notify(get_string('newconfiginfo_afterdelete', 'quiz')); + echo(get_string('noofvariants','quiz',$omrquiz_config->variantcount)); + echo(get_string('rollnoposition','quiz',$omrquiz_config->rollnoposition)); + echo(get_string('variantposition','quiz',$omrquiz_config->variantposition)); + echo(get_string('answerstringposition','quiz',$omrquiz_config->ansposition)); + echo(get_string('rollnolength','quiz',$omrquiz_config->rollnolength)); + echo(get_string('variantnolength','quiz',$omrquiz_config->variantlength)); + print_box_end(); + } + + + }else{ + //reuploading configuration when variant count is same as earlier + if(!update_record('omrquiz', $omrquiz_config)){ + error("could not update omrquiz table with omr configuration"); + } + print_box_start(); + notify(get_string('newconfiginfo', 'quiz')); + echo(get_string('noofvariants','quiz',$omrquiz_config->variantcount)); + echo(get_string('rollnoposition','quiz',$omrquiz_config->rollnoposition)); + echo(get_string('variantposition','quiz',$omrquiz_config->variantposition)); + echo(get_string('answerstringposition','quiz',$omrquiz_config->ansposition)); + echo(get_string('rollnolength','quiz',$omrquiz_config->rollnolength)); + echo(get_string('variantnolength','quiz',$omrquiz_config->variantlength)); + print_box_end(); + } + } +} +?> diff -Naur moodle/mod/quiz/tabs.php moodle_omrquiz/mod/quiz/tabs.php --- moodle/mod/quiz/tabs.php 2008-04-23 05:48:00.000000000 +0530 +++ moodle_omrquiz/mod/quiz/tabs.php 2010-03-10 17:44:04.000000000 +0530 @@ -41,6 +41,14 @@ $row[] = new tabobject('edit', "$CFG->wwwroot/mod/quiz/edit.php?cmid=$cm->id", get_string('edit')); } +//---------------------------------------------------For OMR Quiz,------------------------------------------------ +if(record_exists('omrquiz', 'quizid', $quiz->id)){ + if (has_capability('mod/quiz:manage', $context)) { + $row[] = new tabobject('omr', "$CFG->wwwroot/mod/quiz/omr.php?cmid=$cm->id", get_string('omr_tab','quiz')); + } +} +//----------------------------------------------author@ Harmeet Saini--------------------------------------------- + if ($currenttab == 'info' && count($row) == 1) { // Don't show only an info tab (e.g. to students). } else { @@ -96,8 +104,24 @@ } +//---------------------------------------------------For OMR Quiz,------------------------------------------------ +if ($currenttab == 'omr' and isset($mode)) { + $activated[]= 'omr'; + $row=array(); + $currenttab=$mode; + if (has_capability('mod/quiz:manage', $context)) { + $row[] = new tabobject('omrconfig', "$CFG->wwwroot/mod/quiz/omruploadconfig.php?cmid=$cm->id",get_string('omr_configuration_tab','quiz')); + $row[] = new tabobject('variants', "$CFG->wwwroot/mod/quiz/omr.php?cmid=$cm->id",get_string('omr_variants_tab','quiz')); + $row[] = new tabobject('attendence', "$CFG->wwwroot/mod/quiz/omrattendence.php?cmid=$cm->id",get_string('omr_attendance_tab','quiz')); + $row[] = new tabobject('answers', "$CFG->wwwroot/mod/quiz/omranswers.php?cmid=$cm->id",get_string('omr_answers_tab','quiz')); + $row[] = new tabobject('process', "$CFG->wwwroot/mod/quiz/omrevaluate.php?cmid=$cm->id",get_string('omr_attempts_tab','quiz')); + } + $tabs[]=$row; +} +//----------------------------------------------author@ Harmeet Saini--------------------------------------------- + if (!$quiz->questions) { - $inactive += array('info', 'reports', 'preview'); + $inactive += array('info', 'reports', 'preview', 'omr'); //edited For OMR Quiz (added 'omr' in $inactive) } print_tabs($tabs, $currenttab, $inactive, $activated); diff -Naur moodle/mod/quiz/version.php moodle_omrquiz/mod/quiz/version.php --- moodle/mod/quiz/version.php 2009-01-15 04:37:01.000000000 +0530 +++ moodle_omrquiz/mod/quiz/version.php 2010-03-10 17:44:04.000000000 +0530 @@ -5,7 +5,7 @@ // This fragment is called by moodle_needs_upgrading() and /admin/index.php //////////////////////////////////////////////////////////////////////////////// -$module->version = 2007101511; // The (date) version of this module +$module->version = 2007101611; // The (date) version of this module $module->requires = 2007101509; // Requires this Moodle version $module->cron = 0; // How often should cron check this module (seconds)?