Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-9883 Use new fields in question table - created, modified, create…

…dby and modifiedby
  • Loading branch information...
commit ea7a09095596b592fe0808b406cd7b8c673de9c4 1 parent 788376b
authored May 22, 2007

Showing 1 changed file with 303 additions and 281 deletions. Show diff stats Hide diff stats

  1. 584  question/format/coursetestmanager/format.php
584  question/format/coursetestmanager/format.php
@@ -6,12 +6,17 @@
6 6
 ////////////////////////////////////////////////////////////////////
7 7
 
8 8
 // Based on format.php, included by ../../import.php
  9
+/**
  10
+ * @package questionbank
  11
+ * @subpackage importexport
  12
+ */
  13
+
9 14
 require_once($CFG->dirroot.'/lib/uploadlib.php');
10 15
 
11 16
 class qformat_coursetestmanager extends qformat_default {
12 17
 
13 18
     function provide_import() {
14  
-      return true;
  19
+        return true;
15 20
     }
16 21
 
17 22
     function importpreprocess($category) {
@@ -20,108 +25,113 @@ function importpreprocess($category) {
20 25
     }
21 26
 
22 27
     function importprocess($filename) {
23  
-      global $CFG,$strimportquestions,$form,$question_category,$category,$course,
24  
-      $hostname, $mdapath, $mdbpath;
25  
-            if ((PHP_OS == "Linux") and isset($hostname)) {
26  
-                $hostname = trim($hostname);
27  
-                // test the ODBC socket server connection
28  
-                // if failure, unset hostname and set hostname_access_error
29  
-        $question_categories = $this->getquestioncategories($mdbpath, $mdapath, $hostname);
30  
-        if (!$question_categories) {
31  
-            $hostname_access_error = $hostname . " ";
32  
-            unset($hostname);
33  
-        } else  {
34  
-            $hostname_access_error = 0;
35  
-        }
  28
+        global $CFG, $USER, $strimportquestions,$form,$question_category,$category,$course,
  29
+            $hostname, $mdapath, $mdbpath;
  30
+        if ((PHP_OS == "Linux") and isset($hostname)) {
  31
+            $hostname = trim($hostname);
  32
+            // test the ODBC socket server connection
  33
+            // if failure, unset hostname and set hostname_access_error
  34
+            $question_categories = $this->getquestioncategories($mdbpath, $mdapath, $hostname);
  35
+            if (!$question_categories) {
  36
+                $hostname_access_error = $hostname . " ";
  37
+                unset($hostname);
  38
+            } else  {
  39
+                $hostname_access_error = 0;
36 40
             }
  41
+        }
37 42
 
38  
-            if ((PHP_OS == "Linux") and !isset($hostname)) {
39  
-                                // copy the file to a semi-permanent location
  43
+        if ((PHP_OS == "Linux") and !isset($hostname)) {
  44
+            // copy the file to a semi-permanent location
40 45
             if (! $basedir = make_upload_directory("$course->id")) {
41 46
                 error("The site administrator needs to fix the file permissions for the data directory");
42 47
             }
43  
-                if (!isset($hostname_access_error)) {
44  
-              $bname=basename($filename);
45  
-            $cleanfilename = clean_filename($bname);
46  
-            if ($cleanfilename) {
47  
-                $newfile = "$basedir/$cleanfilename";
48  
-                if (move_uploaded_file($filename, $newfile)) {
49  
-                    chmod($newfile, 0666);
50  
-                    clam_log_upload($newfile,$course);
51  
-                } else {
52  
-                    notify(get_string("uploadproblem", "", $filename));
  48
+            if (!isset($hostname_access_error)) {
  49
+                $bname=basename($filename);
  50
+                $cleanfilename = clean_filename($bname);
  51
+                if ($cleanfilename) {
  52
+                    $newfile = "$basedir/$cleanfilename";
  53
+                    if (move_uploaded_file($filename, $newfile)) {
  54
+                        chmod($newfile, 0666);
  55
+                        clam_log_upload($newfile,$course);
  56
+                    } else {
  57
+                        notify(get_string("uploadproblem", "", $filename));
  58
+                    }
53 59
                 }
  60
+                $filename = $newfile;
54 61
             }
55  
-            $filename = $newfile;
56  
-                }
57 62
             print_heading_with_help($strimportquestions, "import", "quiz");
58 63
             print_simple_box_start("center");
59  
-                if ($hostname_access_error) { notify("couldn't connect to ODBC Socket Server on " . $hostname_access_error); }
  64
+            if ($hostname_access_error) { notify("couldn't connect to ODBC Socket Server on " . $hostname_access_error); }
60 65
             echo "<form method=\"post\" action=\"import.php\">";
  66
+            echo '<fieldset class="invisiblefieldset">';
61 67
             echo "<table cellpadding=\"5\">";
62 68
 
63  
-        echo "<tr><td align=\"right\">";
  69
+            echo "<tr><td align=\"right\">";
64 70
             echo "What is the hostname or IP address of the ODBC Socket Server:</td><td>";
65 71
             echo " <input name=\"hostname\" type=\"text\" size=\"50\" value=\"".stripslashes($hostname_access_error)."\" />";
66 72
             echo " <input name=\"filename\" type=\"hidden\" value=\"".$filename."\" />";
67 73
             echo " <input name=\"category\" type=\"hidden\" value=\"".$category->id."\" />";
68 74
             echo " <input name=\"format\" type=\"hidden\" value=\"".$form->format."\" />";
69 75
             echo "</td><td>&nbsp;</td></tr>";
70  
-        echo "<tr><td align=\"right\">";
  76
+            echo "<tr><td align=\"right\">";
71 77
             echo "What is the location of the database (.mdb file) on the Socket Server:</td><td>";
72 78
             echo " <input name=\"mdbpath\" type=\"text\" size=\"50\" value=\"".stripslashes($mdbpath)."\" />";
73  
-                echo "</td><td>&nbsp;</td></tr>";
74  
-        echo "<tr><td align=\"right\">";
  79
+            echo "</td><td>&nbsp;</td></tr>";
  80
+            echo "<tr><td align=\"right\">";
75 81
             echo "What is the location of the system database (System.mda file) on the Socket Server:</td><td>";
76 82
             echo " <input name=\"mdapath\" type=\"text\" size=\"50\" value=\"".stripslashes($mdapath)."\" />";
77  
-                echo "</td><td>&nbsp;</td></tr>";
  83
+            echo "</td><td>&nbsp;</td></tr>";
78 84
             echo "<tr><td>&nbsp;</td><td>";
79 85
             echo " <input type=\"submit\" name=\"save\" value=\"Connect to Server\" />";
80 86
             echo "</td></tr>";
81 87
             echo "</table>";
  88
+            echo '</fieldset>';
82 89
             echo "</form>";
83 90
             print_simple_box_end();
84 91
             print_footer($course);
85  
-          exit;
86  
-            }
  92
+            exit;
  93
+        }
87 94
 
88  
-            // we get here if running windows or after connect to ODBC socket server on linux
  95
+        // we get here if running windows or after connect to ODBC socket server on linux
89 96
 //
90 97
 // this generates the page to choose categories of questions to import
91 98
 //
92 99
         if (!isset($question_category)) {
93 100
 
94  
-                if (PHP_OS == "WINNT") {
95  
-                    // copy the file to a semi-permanent location
  101
+            if (PHP_OS == "WINNT") {
  102
+            // copy the file to a semi-permanent location
96 103
                 if (! $basedir = make_upload_directory("$course->id")) {
97 104
                     error("The site administrator needs to fix the file permissions for the data directory");
98 105
                 }
99  
-              $bname=basename($filename);
100  
-            $cleanfilename = clean_filename($bname);
101  
-            if ($cleanfilename) {
102  
-                $newfile = "$basedir/$cleanfilename";
103  
-                if (move_uploaded_file($filename, $newfile)) {
104  
-                    chmod($newfile, 0666);
105  
-                    clam_log_upload($newfile,$course);
106  
-                } else {
107  
-                    notify(get_string("uploadproblem", "", $filename));
  106
+                $bname=basename($filename);
  107
+                $cleanfilename = clean_filename($bname);
  108
+                if ($cleanfilename) {
  109
+                    $newfile = "$basedir/$cleanfilename";
  110
+                    if (move_uploaded_file($filename, $newfile)) {
  111
+                        chmod($newfile, 0666);
  112
+                        clam_log_upload($newfile,$course);
  113
+                    } else {
  114
+                        notify(get_string("uploadproblem", "", $filename));
  115
+                    }
108 116
                 }
  117
+                $filename = $newfile;
109 118
             }
110  
-            $filename = $newfile;
111  
-                }
112  
-        // end of file copy
  119
+            // end of file copy
113 120
 
114  
-                // don't have to do this on linux, since it's alreay been done in the test above
115  
-        if (PHP_OS == "WINNT") { $question_categories = $this->getquestioncategories($filename); }
116  
-        // print the intermediary form
117  
-            if (!$categories = question_category_menu($course->id, true)) {
  121
+            // don't have to do this on linux, since it's alreay been done in the test above
  122
+            if (PHP_OS == "WINNT") {
  123
+                $question_categories = $this->getquestioncategories($filename);
  124
+            }
  125
+            // print the intermediary form
  126
+            if (!$categories = question_category_options($course->id, true)) {
118 127
                 error("No categories!");
119 128
             }
120 129
             print_heading_with_help($strimportquestions, "import", "quiz");
121 130
             print_simple_box_start("center");
122 131
             echo "<form method=\"post\" action=\"import.php\">";
  132
+            echo '<fieldset class="invisiblefieldset">';
123 133
             echo "<table cellpadding=\"5\">";
124  
-        echo "<tr><td align=\"right\">";
  134
+            echo "<tr><td align=\"right\">";
125 135
             echo "Choose a category of questions to import:</td><td>";
126 136
             asort($question_categories);
127 137
             choose_from_menu($question_categories, "question_category","All Categories","All Categories", "", "allcategories");
@@ -138,27 +148,27 @@ function importprocess($filename) {
138 148
             echo " <input type=\"submit\" name=\"save\" value=\"Import Questions\" />";
139 149
             echo "</td></tr>";
140 150
             echo "</table>";
  151
+            echo '</fieldset>';
141 152
             echo "</form>";
142 153
             print_simple_box_end();
143 154
             print_footer($course);
144  
-          exit;
  155
+            exit;
145 156
         }
146 157
 //
147 158
 // this is the main import section
148 159
 //
149  
-    notify("Importing questions");
150  
-    if (PHP_OS == "Linux") {
151  
-        $hostname = trim($hostname);
152  
-        $records = $this->getquestions($mdbpath,$question_category,$mdapath, $hostname);
153  
-    } else {
154  
-        $records = $this->getquestions($filename,$question_category);
155  
-    }
156  
-                foreach ($records as $qrec)
157  
-                {
158  
-                    $question = $this->defaultquestion();
159  
-                    if ($qrec[9] != "") {
160  
-                        $question->image = $qrec[9];
161  
-                    }
  160
+        notify("Importing questions");
  161
+        if (PHP_OS == "Linux") {
  162
+            $hostname = trim($hostname);
  163
+            $records = $this->getquestions($mdbpath,$question_category,$mdapath, $hostname);
  164
+        } else {
  165
+            $records = $this->getquestions($filename,$question_category);
  166
+        }
  167
+        foreach ($records as $qrec) {
  168
+            $question = $this->defaultquestion();
  169
+            if ($qrec[9] != "") {
  170
+                $question->image = $qrec[9];
  171
+            }
162 172
 //  0   Selected
163 173
 //  1   PracticeTestOK?
164 174
 //  2   QuestionText
@@ -172,93 +182,103 @@ function importprocess($filename) {
172 182
 //  10  Module
173 183
 //  11  ChapterNumber
174 184
 //  12  PageNumber
175  
-          $ref = "Answer can be found in chapter ". $qrec[11] . ", page " . $qrec[12] . ".";
176  
-                    switch ($qrec[3]) {
177  
-                  case 1:
  185
+            $ref = "Answer can be found in chapter ". $qrec[11] . ", page " . $qrec[12] . ".";
  186
+            switch ($qrec[3]) {
  187
+                case 1:
178 188
                     $question->qtype = MULTICHOICE; // MULTICHOICE, SHORTANSWER, TRUEFALSE
179 189
         //          echo "<pre>";echo htmlspecialchars($qrec[2]); echo "</pre>";
180 190
                     $question->questiontext = addslashes(trim($qrec[2]));
181 191
         //          echo "<pre>";echo $question->questiontext; echo "</pre>";
182 192
                     $question->name = preg_replace("/<br />/", "", $question->questiontext);
183 193
                     $question->single = 1;  // Only one answer is allowed -- used for multiple choicers
184  
-                            $fractionset = 0;
185  
-                            for ($i=4;$i<=7;$i++) {
186  
-                                if ($qrec[$i] != "") {
187  
-                                    $question->answer[$i-3]=addslashes($qrec[$i]);
188  
-                                    if ($qrec[8] == $i-3) {  // if this is the index of CorrectAnswer
189  
-                                      $question->fraction[$i-3] = 1;
190  
-                                      $fractionset = 1;
191  
-                                    } else {
192  
-                                      $question->fraction[$i-3] = 0;
193  
-                                    }
194  
-                                    $question->feedback[$i-3] = (($qrec[8] == $i-3)?"Correct. ":"Incorrect. ") . $ref;
195  
-                                }
  194
+                    $fractionset = 0;
  195
+                    for ($i=4;$i<=7;$i++) {
  196
+                        if ($qrec[$i] != "") {
  197
+                            $question->answer[$i-3]=addslashes($qrec[$i]);
  198
+                            if ($qrec[8] == $i-3) {  // if this is the index of CorrectAnswer
  199
+                                $question->fraction[$i-3] = 1;
  200
+                                $fractionset = 1;
  201
+                            } else {
  202
+                                $question->fraction[$i-3] = 0;
196 203
                             }
197  
-                            if ($fractionset == 0) { $question->fraction[1] = 1; }
198  
-                        break;
199  
-                        case 2:  // TRUE FALSE
  204
+                            $question->feedback[$i-3] = (($qrec[8] == $i-3)?"Correct. ":"Incorrect. ") . $ref;
  205
+                        }
  206
+                    }
  207
+                    if ($fractionset == 0) { 
  208
+                        $question->fraction[1] = 1; 
  209
+                    }
  210
+                break;
  211
+                case 2:  // TRUE FALSE
200 212
                     $question->qtype = TRUEFALSE;
201 213
                     $question->questiontext = addslashes(trim($qrec[2]));
202 214
                     $question->name = preg_replace("/<br />/", "", $question->questiontext);
203  
-                            // for TF, $question->answer should be 1 for true, 0 for false
204  
-                    if ($qrec[8] == "T") { $question->answer =1;} else { $question->answer = 0; }
  215
+                    // for TF, $question->answer should be 1 for true, 0 for false
  216
+                    if ($qrec[8] == "T") { 
  217
+                        $question->answer =1;
  218
+                    } else { 
  219
+                        $question->answer = 0; 
  220
+                    }
205 221
                       // for TF, use $question->feedbacktrue and feedbackfalse
206 222
                     $question->feedbacktrue = (($qrec[8] =="T")?"Correct. ":"Incorrect. ") . $ref;
207 223
                     $question->feedbackfalse = (($qrec[8] =="F")?"Correct. ":"Incorrect. ") . $ref;
208  
-                        break;
209  
-                        case 3:
  224
+                break;
  225
+                case 3:
210 226
                     $question->qtype = SHORTANSWER;
211 227
                     $question->questiontext = addslashes(trim($qrec[2]));
212 228
         //          echo "<pre>";echo $question->questiontext; echo "</pre>";
213 229
                     $question->name = preg_replace("/<br />/", "", $question->questiontext);
214 230
                     $question->usecase=0;  // Ignore case -- for SHORT ANSWER questions
215  
-                            $answers = explode("~", $qrec[8]);
216  
-                            $question->answer[0]=" ";
217  
-                            $question->fraction[0]=1;
218  
-                            for ($i=0;$i<count($answers);$i++) {
219  
-                                $question->answer[$i] = addslashes(trim($answers[$i]));
220  
-                                $question->feedback[$i] = $ref;
221  
-                                $question->fraction[$i] = 1; // 1 for 100%, 0 for none or somewhere in between
222  
-                            }
223  
-                        break;
224  
-                        case 4:
225  
-                          $question = 0;
226  
-                            notify("Cannot use essay questions - skipping question ". $qrec[2] . " " . $ref);
227  
-                        break;
228  
-                        default:
229  
-                            $question = 0;
230  
-                            notify("Misformatted Record.  Question Skipped.");
231  
-                        break;
  231
+                    $answers = explode("~", $qrec[8]);
  232
+                    $question->answer[0]=" ";
  233
+                    $question->fraction[0]=1;
  234
+                    for ($i=0;$i<count($answers);$i++) {
  235
+                        $question->answer[$i] = addslashes(trim($answers[$i]));
  236
+                        $question->feedback[$i] = $ref;
  237
+                        $question->fraction[$i] = 1; // 1 for 100%, 0 for none or somewhere in between
232 238
                     }
233  
-          if ($question) { $questions[] = $question; }
234  
-                }
235  
-                $count = 0;
236  
-                // process all the questions
237  
-                if (PHP_OS == "WINNT") {
238  
-                    $filename = str_replace("\\\\","\\",$filename);
239  
-                    $filename = str_replace("/","\\",$filename);
240  
-                }
241  
-                foreach ($questions as $question) {   // Process and store each question
242  
-          $count++;
243  
-          echo "<hr /><p><b>$count</b>. ".stripslashes($question->questiontext)."</p>";
244  
-          $question->category = $this->category->id;
245  
-          $question->stamp = make_unique_id_code();  // Set the unique code (not to be changed)
246  
-          if (!$question->id = insert_record("question", $question)) {
247  
-              error("Could not insert new question!");
248  
-          }
249  
-          $this->questionids[] = $question->id;
250  
-          // Now to save all the answers and type-specific options
251  
-          $result = save_question_options($question);
252  
-          if (!empty($result->error)) {
253  
-              notify($result->error);
254  
-              $this->deletedatabase($filename);
255  
-              return false;
256  
-          }
257  
-          if (!empty($result->notice)) {
258  
-              notify($result->notice);
259  
-              $this->deletedatabase($filename);
260  
-              return true;
261  
-          }
  239
+                break;
  240
+                case 4:
  241
+                    $question = 0;
  242
+                    notify("Cannot use essay questions - skipping question ". $qrec[2] . " " . $ref);
  243
+                break;
  244
+                default:
  245
+                    $question = 0;
  246
+                    notify("Misformatted Record.  Question Skipped.");
  247
+                break;
  248
+            }
  249
+            if ($question) { 
  250
+                $questions[] = $question; 
  251
+            }
  252
+        }
  253
+        $count = 0;
  254
+        // process all the questions
  255
+        if (PHP_OS == "WINNT") {
  256
+            $filename = str_replace("\\\\","\\",$filename);
  257
+            $filename = str_replace("/","\\",$filename);
  258
+        }
  259
+        foreach ($questions as $question) {   // Process and store each question
  260
+            $count++;
  261
+            echo "<hr /><p><b>$count</b>. ".stripslashes($question->questiontext)."</p>";
  262
+            $question->category = $this->category->id;
  263
+            $question->stamp = make_unique_id_code();  // Set the unique code (not to be changed)
  264
+            $question->createdby = $USER->id;
  265
+            $question->timecreated = time();
  266
+            if (!$question->id = insert_record("question", $question)) {
  267
+                error("Could not insert new question!");
  268
+            }
  269
+            $this->questionids[] = $question->id;
  270
+            // Now to save all the answers and type-specific options
  271
+            $result = save_question_options($question);
  272
+            if (!empty($result->error)) {
  273
+                notify($result->error);
  274
+                $this->deletedatabase($filename);
  275
+                return false;
  276
+            }
  277
+            if (!empty($result->notice)) {
  278
+                notify($result->notice);
  279
+                $this->deletedatabase($filename);
  280
+                return true;
  281
+            }
262 282
             // Give the question a unique version stamp determined by question_hash()
263 283
             set_field('question', 'version', question_hash($question), 'id', $question->id);
264 284
         }
@@ -270,100 +290,100 @@ function importpostprocess() {
270 290
         return true;
271 291
     }
272 292
 
273  
-      function deletedatabase($filename) {
  293
+    function deletedatabase($filename) {
274 294
         if (! $this->fulldelete($filename)) {
275  
-        echo "<br />Error: Could not delete: $filename";
276  
-        return false;
277  
-      }
278  
-            return true;
279  
-      }
  295
+            echo "<br />Error: Could not delete: $filename";
  296
+            return false;
  297
+        }
  298
+        return true;
  299
+    }
280 300
 
281  
-        function getquestions($filename, $category, $mdapath="", $hostname="") {
282  
-            if (($category == "allcategories") or ($category == "")) {
  301
+    function getquestions($filename, $category, $mdapath="", $hostname="") {
  302
+        if (($category == "allcategories") or ($category == "")) {
283 303
             $sql = "SELECT * FROM TBQuestions";
284  
-            } else {
  304
+        } else {
285 305
             $sql = "SELECT * FROM TBQuestions where module = '".$category."'";
286  
-            }
287  
-            if (PHP_OS == "WINNT") {
  306
+        }
  307
+        if (PHP_OS == "WINNT") {
288 308
             $ldb =& $this->connect_win($filename);
289  
-              $qset = $ldb->Execute("$sql");
290  
-          if ( $qset->RecordCount() > 0 ) {
291  
-            $records = $qset->GetAssoc(true);
292  
-              } else {
293  
-            $this->err("There were no records in the database.",$dsn);
294  
-              $ldb->Close();
295  
-              return false;
296  
-              }
  309
+            $qset = $ldb->Execute("$sql");
  310
+            if ( $qset->RecordCount() > 0 ) {
  311
+                $records = $qset->GetAssoc(true);
  312
+            } else {
  313
+                $this->err("There were no records in the database.",$dsn);
  314
+                $ldb->Close();
  315
+                return false;
  316
+            }
297 317
             $ldb->Close();
298  
-            } else  { // if PHP_OS == WINNT
299  
-              // we have a linux installation
300  
-                $result = $this->query_linux($sql,$filename, $mdapath,$hostname);
301  
-          if ( count($result) > 0 ) {
302  
-                    // get rid of the ID field in the first column.
303  
-                    for($i=0;$i<count($result);$i++) {
304  
-                        foreach (array_keys($result[$i]) as $j) {
305  
-                            $records[$i][$j-1] = $result[$i][$j];
306  
-                        }
  318
+        } else  { // if PHP_OS == WINNT
  319
+            // we have a linux installation
  320
+            $result = $this->query_linux($sql,$filename, $mdapath,$hostname);
  321
+            if ( count($result) > 0 ) {
  322
+                // get rid of the ID field in the first column.
  323
+                for($i=0;$i<count($result);$i++) {
  324
+                    foreach (array_keys($result[$i]) as $j) {
  325
+                        $records[$i][$j-1] = $result[$i][$j];
307 326
                     }
308  
-              } else {
309  
-            $this->err("There were no records in the database.",$dsn);
310  
-                    $ldb->Close();
311  
-              return false;
312  
-              }
  327
+                }
  328
+            } else {
  329
+                $this->err("There were no records in the database.",$dsn);
  330
+                $ldb->Close();
  331
+                return false;
  332
+            }
313 333
                 // xml test and connect
314  
-            }  // PHP_OS TEST
  334
+        }  // PHP_OS TEST
315 335
             return $records;
316  
-        }
  336
+    }
317 337
 
318 338
     function getquestioncategories($filename, $mdapath="", $hostname="") {
319  
-      global $CFG, $result;
320  
-            $sql = "SELECT Distinct module FROM TBQuestions";
321  
-            if (PHP_OS == "WINNT") {
322  
-                $ldb =& $this->connect_win($filename);
323  
-                $qset = $ldb->Execute("$sql");
324  
-        if ( $qset->RecordCount() > 0 ) {
325  
-          $records = $qset->GetArray(true);
326  
-                  foreach ($records as $record) {
  339
+        global $CFG, $result;
  340
+        $sql = "SELECT Distinct module FROM TBQuestions";
  341
+        if (PHP_OS == "WINNT") {
  342
+            $ldb =& $this->connect_win($filename);
  343
+            $qset = $ldb->Execute("$sql");
  344
+            if ( $qset->RecordCount() > 0 ) {
  345
+                $records = $qset->GetArray(true);
  346
+                foreach ($records as $record) {
327 347
                     $categories[$record[0]] = $record[0];
328  
-                  }
329  
-          } else { // if recordcount
330  
-          $this->err("There were no records in the database.",$dsn);
  348
+                }
  349
+            } else { // if recordcount
  350
+                $this->err("There were no records in the database.",$dsn);
331 351
                 $ldb->Close();
332  
-            return false;
333  
-          }
334  
-        $ldb->Close();
335  
-            } else  { // if PHP_OS == WINNT
336  
-              // we have a linux installation
337  
-                    $result = $this->query_linux($sql, $filename, $mdapath, $hostname);
338  
-                    for($i=0;$i<count($result);$i++) {
339  
-                        $categories[$result[$i][0]] = $result[$i][0];
340  
-                    }
341  
-            }  // PHP_OS TEST
342  
-            return $categories;
  352
+                return false;
  353
+            }
  354
+            $ldb->Close();
  355
+        } else  { // if PHP_OS == WINNT
  356
+            // we have a linux installation
  357
+            $result = $this->query_linux($sql, $filename, $mdapath, $hostname);
  358
+            for($i=0;$i<count($result);$i++) {
  359
+                $categories[$result[$i][0]] = $result[$i][0];
  360
+            }
  361
+        }  // PHP_OS TEST
  362
+        return $categories;
343 363
     }
344 364
 
345  
-        function query_linux($sql, $mdbpath, $mdapath, $hostname) {
346  
-                global $result;
347  
-                include_once("odbcsocketserver.class.php");
348  
-                // set up socket server object to connect to remote host
349  
-                $oTest = new ODBCSocketServer;
350  
-                //Set the Hostname, port, and connection string
351  
-              $oTest->sHostName = $hostname;
352  
-                $oTest->nPort = 9628;
353  
-//            $oTest->sConnectionString="DRIVER=Microsoft Access Driver (*.mdb);SystemDB=C:\CTM\System.mda;DBQ=C:\CTM\of2K3\ctm.mdb;UID=Assess;PWD=VBMango;";
354  
-              $oTest->sConnectionString="DRIVER=Microsoft Access Driver (*.mdb);SystemDB=".
355  
-                $mdapath.";DBQ=".$mdbpath.";UID=Assess;PWD=VBMango;";
356  
-                // send and receive XML communication
357  
-                $qResult = $oTest->ExecSQL($sql);
358  
-                // set up XML parser to read the results
359  
-                $xml_parser = xml_parser_create("US-ASCII");
360  
-                xml_set_element_handler($xml_parser, "quiz_xmlstart", "quiz_xmlend");
  365
+    function query_linux($sql, $mdbpath, $mdapath, $hostname) {
  366
+        global $result;
  367
+        include_once("odbcsocketserver.class.php");
  368
+        // set up socket server object to connect to remote host
  369
+        $oTest = new ODBCSocketServer;
  370
+        //Set the Hostname, port, and connection string
  371
+        $oTest->sHostName = $hostname;
  372
+        $oTest->nPort = 9628;
  373
+//      $oTest->sConnectionString="DRIVER=Microsoft Access Driver (*.mdb);SystemDB=C:\CTM\System.mda;DBQ=C:\CTM\of2K3\ctm.mdb;UID=Assess;PWD=VBMango;";
  374
+        $oTest->sConnectionString="DRIVER=Microsoft Access Driver (*.mdb);SystemDB=".
  375
+        $mdapath.";DBQ=".$mdbpath.";UID=Assess;PWD=VBMango;";
  376
+        // send and receive XML communication
  377
+        $qResult = $oTest->ExecSQL($sql);
  378
+        // set up XML parser to read the results
  379
+        $xml_parser = xml_parser_create("US-ASCII");
  380
+        xml_set_element_handler($xml_parser, "quiz_xmlstart", "quiz_xmlend");
361 381
         xml_set_character_data_handler($xml_parser, "quiz_xmldata");
362 382
         // parse the XML and get back the result set array
363 383
         if (!xml_parse($xml_parser, $qResult)) {
364 384
             $this->err("XML error: ".xml_error_string(xml_get_error_code($xml_parser))
365 385
               ." at line ".xml_get_current_line_number($xml_parser),$oTest->sConnectionString);
366  
-                    return false;
  386
+            return false;
367 387
         } else  {
368 388
 //          echo("Successful XML parse.  ");
369 389
             // prepare the array for use in the pull-down
@@ -373,101 +393,102 @@ function query_linux($sql, $mdbpath, $mdapath, $hostname) {
373 393
                     echo $qResult;
374 394
                     echo "\n</pre>";
375 395
 */
376  
-                xml_parser_free($xml_parser);
  396
+            xml_parser_free($xml_parser);
377 397
 //  $sResult = HtmlSpecialChars($qResult);
378 398
     //echo("<pre>");
379 399
 //  echo($sResult);
380 400
 //  echo("</pre>");
381 401
 
382  
-                    return $result;
383  
-        }
  402
+            return $result;
384 403
         }
  404
+    }
385 405
 
386  
-        function connect_win($filename) {
387  
-            global $CFG, $systemdb;
388  
-            // first, verify the location of System.mda
389  
-            if (!isset($systemdb)) {
  406
+    function connect_win($filename) {
  407
+        global $CFG, $systemdb;
  408
+        // first, verify the location of System.mda
  409
+        if (!isset($systemdb)) {
390 410
             $systemdb=$this->findfile("System.mda");
391  
-            }
  411
+        }
392 412
         if (! $systemdb) {
393  
-        $this->err("The system database System.mda cannot be found.  Check that you've uploaded it to the course.",$dsn);
394  
-        die;
  413
+            $this->err("The system database System.mda cannot be found.  Check that you've uploaded it to the course.",$dsn);
  414
+            die;
395 415
         }
396 416
 
397  
-            $ldb = &ADONewConnection('access');
398  
-          $dsn="DRIVER=Microsoft Access Driver (*.mdb);SystemDB=".$systemdb.";DBQ=".$filename.";UID=Assess;PWD=VBMango;";
399  
-          $dbconnected = $ldb->Connect($dsn);
  417
+        $ldb = &ADONewConnection('access');
  418
+        $dsn="DRIVER=Microsoft Access Driver (*.mdb);SystemDB=".$systemdb.";DBQ=".$filename.";UID=Assess;PWD=VBMango;";
  419
+        $dbconnected = $ldb->Connect($dsn);
400 420
         if (! $dbconnected) {
401  
-        $this->err("Moodle could not connect to the database.",$dsn);
402  
-        die;
403  
-        }
404  
-            return $ldb;
  421
+            $this->err("Moodle could not connect to the database.",$dsn);
  422
+            die;
405 423
         }
  424
+        return $ldb;
  425
+    }
406 426
 
407 427
     function err($message, $dsn) {
408  
-            echo "<font color=\"#990000\">";
409  
-          echo "<p>Error: $message</p>";
410  
-          echo "<p>ODBC File DSN: $dsn<br />";
411  
-          echo "</font>";
  428
+        echo "<font color=\"#990000\">";
  429
+        echo "<p>Error: $message</p>";
  430
+        echo "<p>ODBC File DSN: $dsn<br />";
  431
+        echo "</font>";
412 432
     }
413 433
 
414  
-        function fulldelete($location) {
415  
-            if (is_dir($location)) {
416  
-                $currdir = opendir($location);
417  
-                while ($file = readdir($currdir)) {
418  
-                    if ($file <> ".." && $file <> ".") {
419  
-                        $fullfile = $location."/".$file;
420  
-                        if (is_dir($fullfile)) {
421  
-                            if (!fulldelete($fullfile)) {
422  
-                                return false;
423  
-                            }
424  
-                        } else {
425  
-                            if (!unlink($fullfile)) {
426  
-                                return false;
427  
-                            }
  434
+    function fulldelete($location) {
  435
+        if (is_dir($location)) {
  436
+            $currdir = opendir($location);
  437
+            while ($file = readdir($currdir)) {
  438
+                if ($file <> ".." && $file <> ".") {
  439
+                    $fullfile = $location."/".$file;
  440
+                    if (is_dir($fullfile)) {
  441
+                        if (!fulldelete($fullfile)) {
  442
+                            return false;
  443
+                        }
  444
+                    } else {
  445
+                        if (!unlink($fullfile)) {
  446
+                            return false;
428 447
                         }
429 448
                     }
430 449
                 }
431  
-                closedir($currdir);
432  
-                if (! rmdir($location)) {
433  
-                    return false;
434  
-                }
  450
+            }
  451
+            closedir($currdir);
  452
+            if (! rmdir($location)) {
  453
+                return false;
  454
+            }
435 455
 
436  
-            } else {
437  
-                if (!unlink($location)) {
438  
-                    return false;
439  
-                }
  456
+        } else {
  457
+            if (!unlink($location)) {
  458
+                return false;
440 459
             }
441  
-            return true;
442 460
         }
  461
+        return true;
  462
+    }
443 463
 
444 464
 
445 465
     function findfile($filename) {
446 466
         global $CFG;
447  
-            $dirs = $this->getcoursedirs();
448  
-            $dirs[] = $CFG->dirroot."\mod\quiz\format";
449  
-            foreach ($dirs as $dir) {
450  
-                $file = $dir . "\System.mda";
451  
-                // look for System.mda
452  
-                if (is_file($file)) return $file;
453  
-            }
454  
-            return false;
  467
+        $dirs = $this->getcoursedirs();
  468
+        $dirs[] = $CFG->dirroot."\mod\quiz\format";
  469
+        foreach ($dirs as $dir) {
  470
+            $file = $dir . "\System.mda";
  471
+            // look for System.mda
  472
+            if (is_file($file)) return $file;
  473
+        }
  474
+        return false;
455 475
     }
456 476
 
457 477
     function getcoursedirs() {
458 478
         global $CFG;
459 479
         // for every course in the system, find the root of the data directory
460  
-                $courses = get_records_sql("select distinct id,fullname from ".$CFG->prefix."course");
461  
-                $dirs = array();
462  
-                if ($courses) {
463  
-                    foreach ($courses as $course) {
464  
-                        $dir = $CFG->dataroot . "/" . $course->id;
465  
-                        if (is_dir($dir)) { $dirs[] = $dir; }
466  
-                    }
  480
+        $courses = get_records_sql("select distinct id,fullname from ".$CFG->prefix."course");
  481
+        $dirs = array();
  482
+        if ($courses) {
  483
+            foreach ($courses as $course) {
  484
+                $dir = $CFG->dataroot . "/" . $course->id;
  485
+                if (is_dir($dir)) { 
  486
+                    $dirs[] = $dir; 
467 487
                 }
468  
-                return $dirs;
  488
+            }
  489
+        }
  490
+        return $dirs;
469 491
     }
470  
-
471 492
 } // END OF CLASS
472 493
 
473 494
     //Handler for starting elements
@@ -476,11 +497,11 @@ function quiz_xmlstart($parser, $name, $attribs) {
476 497
         $name = strtolower($name);
477 498
         switch ($name) {
478 499
             case "row":
479  
-        $col=0;break;
  500
+                $col=0;break;
480 501
             case "column":
481 502
                 $incolumn = 1;break;
482 503
             case "error":
483  
-        break;
  504
+            break;
484 505
             case "result":
485 506
                 $row = 0; break;
486 507
         } // switch
@@ -492,22 +513,23 @@ function quiz_xmlend($parser, $name) {
492 513
         $name = strtolower($name);
493 514
         switch ($name) {
494 515
             case "row":
495  
-        $row++;break;
  516
+                $row++;break;
496 517
             case "column":
497 518
                 $incolumn = 0;
498  
-        $col++;
499  
-        break;
  519
+                $col++;
  520
+            break;
500 521
             case "error":
501  
-        break;
  522
+            break;
502 523
             case "result":
503  
-        break;
  524
+            break;
504 525
         } // switch
505 526
     }  // function
506 527
 
507 528
     //handler for character data
508 529
     function quiz_xmldata($parser, $data) {
509 530
         global $result, $row, $col, $incolumn;
510  
-        if ($incolumn) { $result[$row][$col] = $result[$row][$col] . $data;
  531
+        if ($incolumn) { 
  532
+            $result[$row][$col] = $result[$row][$col] . $data;
511 533
         }
512 534
     }
513 535
 

0 notes on commit ea7a090

Please sign in to comment.
Something went wrong with that request. Please try again.