$qti_import = new QTIImport($import_path);
 if (isset($items[$item_id]['tests'])) {
     $loop_var = $items[$item_id]['tests'];
 } else {
     $loop_var = $items[$item_id]['file'];
 }
 foreach ($loop_var as $array_id => $test_xml_file) {
     //check if this item is the qti item object, or it is the content item obj
     //switch it to qti obj if it's content item obj
     if ($items[$item_id]['type'] == 'webcontent') {
         $item_qti = $items[$array_id];
     } else {
         $item_qti = $items[$item_id];
     }
     //call subrountine to add the questions.
     $qids = addQuestions($test_xml_file, $item_qti, $import_path);
     //import test
     if ($test_title == '') {
         $test_title = $content_info['title'];
     }
     $tid = $qti_import->importTest($test_title);
     //associate question and tests
     foreach ($qids as $order => $qid) {
         if (isset($qti_import->weights[$order])) {
             $weight = round($qti_import->weights[$order]);
         } else {
             $weight = 0;
         }
         $new_order = $order + 1;
         $sql = "INSERT INTO " . TABLE_PREFIX . "tests_questions_assoc" . "(test_id, question_id, weight, ordering, required) " . "VALUES ({$tid}, {$qid}, {$weight}, {$new_order}, 0)";
         $result = mysql_query($sql, $db);
Example #2
0
 /**
  * function actionEdit:
  * processes subaction and calls getQuizEditForm function which renders edit interface
  */
 public function actionEdit()
 {
     // dataSource: the $dataSource argument to get*Form() functions specifies where to persist data for the form from.
     // if a submit was in progress, and the submit was successful, we set dataSource to db.
     // else, we set dataSource to POST, because we need to present the user's entered values, rather than existing values
     // so that he/she may make changes and submit again, with least hassle.
     if (isset($_GET['subaction'])) {
         switch ($_GET['subaction']) {
             case 'addsections':
                 if (!$this->isValidId($_POST['txtSectionCount'])) {
                     displayerror('Error. No count specified.');
                 } else {
                     $count = escape($_POST['txtSectionCount']);
                     if (addSections($this->moduleComponentId, $count) !== false) {
                         displayinfo('Section(s) added successfully.');
                     }
                 }
                 break;
             case 'editsection':
                 $dataSource = 'db';
                 if (!$this->isValidId($_GET['sectionid'])) {
                     displayerror('Error. Invalid section id specified.');
                 } elseif (isset($_POST['btnSubmit'])) {
                     $dataSource = 'POST';
                     if (submitSectionEditForm($this->moduleComponentId, intval($_GET['sectionid']))) {
                         displayinfo('Section properties saved successfully.');
                         $dataSource = 'db';
                     }
                 }
                 return getSectionEditForm($this->moduleComponentId, intval($_GET['sectionid']), $dataSource);
                 break;
             case 'deletesection':
                 if (!$this->isValidId($_POST['hdnSectionId'])) {
                     displayerror('Error. Invalid section id specified.');
                 } elseif (deleteSection($this->moduleComponentId, intval($_POST['hdnSectionId']))) {
                     displayinfo('The specified section was successfully deleted.');
                 }
                 break;
             case 'movesection':
                 if (!$this->isValidId($_GET['sectionid'])) {
                     displayerror('Error. Invalid section id specified.');
                 } elseif (!isset($_GET['direction']) || $_GET['direction'] != 'up' && $_GET['direction'] != 'down') {
                     displayerror('Error. No or invalid direction specified. Could not move section.');
                 } elseif (moveSection($this->moduleComponentId, intval($_GET['sectionid']))) {
                     displayinfo('The specified section was successfully moved.');
                 }
                 break;
             case 'addquestions':
                 if (!$this->isValidId($_GET['sectionid'])) {
                     displayerror('Error. No or invalid section id specified. Could not add question.');
                 } elseif (!$this->isValidId($_POST['txtQuestionCount'])) {
                     displayerror('Error. No or invalid count specified. Could not add question.');
                 } else {
                     $count = intval($_POST['txtQuestionCount']);
                     $insertIds = addQuestions($this->moduleComponentId, intval($_GET['sectionid']), $count);
                     if ($insertIds !== false) {
                         displayinfo('New question(s) added successfully.');
                     }
                 }
                 break;
             case 'editquestion':
                 $dataSource = 'db';
                 if (!$this->isValidId($_GET['sectionid']) || !$this->isValidId($_GET['questionid'])) {
                     displayerror('Error. Invalid section or question specified.');
                 } elseif (isset($_POST['btnSubmit'])) {
                     $dataSource = 'POST';
                     if (submitQuestionEditForm($this->moduleComponentId, intval($_GET['sectionid']), intval($_GET['questionid']))) {
                         displayinfo('Question properties saved successfully.');
                         $dataSource = 'db';
                     }
                 }
                 return getQuestionEditForm($this->moduleComponentId, intval($_GET['sectionid']), intval($_GET['questionid']), $dataSource);
                 break;
             case 'deletequestion':
                 if (!$this->isValidId($_POST['hdnSectionId']) || !$this->isValidId($_POST['hdnQuestionId'])) {
                     displayerror('Error. Invalid section or question specified.');
                 } elseif (deleteQuestion($this->moduleComponentId, intval($_POST['hdnSectionId']), intval($_POST['hdnQuestionId']))) {
                     displayinfo('Question successfully deleted.');
                 }
                 break;
             case 'movequestion':
                 if (!$this->isValidId($_GET['sectionid'])) {
                     displayerror('Error. Invalid section id specified.');
                 } elseif (!$this->isValidId($_GET['questionid'])) {
                     displayerror('Error. Invalid question id specified.');
                 } elseif (!isset($_GET['direction']) || $_GET['direction'] != 'up' && $_GET['direction'] != 'down') {
                     displayerror('Error. No or invalid direction specified. Could not move section.');
                 } elseif (moveQuestion($this->moduleComponentId, intval($_GET['sectionid']), intval($_GET['questionid']), $_GET['direction'])) {
                     displayinfo('The specified question was successfully moved.');
                 }
                 break;
         }
     }
     if (isset($_POST['btnSetWeightMarks'])) {
         if (setWeightMark(intval($_POST['quizId']), intval($_POST['weight']), intval($_POST['pos']), intval($_POST['neg']))) {
             displayinfo('Weight - Marks saved.');
         } else {
             displayerror('Error in changing weight mark');
         }
     }
     $dataSource = 'db';
     if (isset($_POST['btnSubmit'])) {
         $dataSource = 'POST';
         if (submitQuizEditForm($this->moduleComponentId)) {
             $dataSource = 'db';
         }
     }
     return getQuizEditForm($this->moduleComponentId, $dataSource);
 }
Example #3
0
 //				 .$content_folder_type.')';
 //
 //	$result = mysql_query($sql, $db) or die(mysql_error());
 /* get the content id and update $items */
 //	$items[$item_id]['real_content_id'] = mysql_insert_id($db);
 /* get the tests associated with this content */
 if (!empty($items[$item_id]['tests']) || strpos($items[$item_id]['type'], 'imsqti_xmlv1p2/imscc_xmlv1p0') !== false) {
     $qti_import = new QTIImport($import_path);
     if (isset($items[$item_id]['tests'])) {
         $loop_var = $items[$item_id]['tests'];
     } else {
         $loop_var = $items[$item_id]['file'];
     }
     foreach ($loop_var as $array_id => $test_xml_file) {
         //call subrountine to add the questions.
         $qids = addQuestions($test_xml_file, $items[$item_id], $import_path);
         //import test
         $tid = $qti_import->importTest($content_info['title']);
         //associate question and tests
         foreach ($qids as $order => $qid) {
             if (isset($qti_import->weights[$order])) {
                 $weight = round($qti_import->weights[$order]);
             } else {
                 $weight = 0;
             }
             $new_order = $order + 1;
             $sql = "INSERT INTO " . TABLE_PREFIX . "tests_questions_assoc" . "(test_id, question_id, weight, ordering, required) " . "VALUES ({$tid}, {$qid}, {$weight}, {$new_order}, 0)";
             $result = mysql_query($sql, $db);
         }
         //associate content and test
         $sql = 'INSERT INTO ' . TABLE_PREFIX . 'content_tests_assoc' . '(content_id, test_id) ' . 'VALUES (' . $items[$item_id]['real_content_id'] . ", {$tid})";