function addContent($course_id, $content_parent_id, $ordering, $title, $text, $keywords, $related, $formatting, $release_date, $head = '', $use_customized_head = 0, $test_message = '', $allow_test_export = 1, $content_type = CONTENT_TYPE_CONTENT)
 {
     if (!authenticate(AT_PRIV_CONTENT, AT_PRIV_RETURN) && $_SESSION['course_id'] != -1) {
         return false;
     }
     // shift the new neighbouring content down
     $sql = "UPDATE %scontent SET ordering=ordering+1 \n\t\t         WHERE ordering>=%d \n\t\t           AND content_parent_id=%d \n\t\t           AND course_id=%d";
     $result = queryDB($sql, array(TABLE_PREFIX, $ordering, $content_parent_id, $_SESSION['course_id']));
     /* main topics all have minor_num = 0 */
     $sql = "INSERT INTO %scontent\n\t\t               (course_id,\n\t\t                content_parent_id,\n\t\t                ordering,\n\t\t                last_modified,\n\t\t                revision,\n\t\t                formatting,\n\t\t                release_date,\n\t\t                head,\n\t\t                use_customized_head,\n\t\t                keywords,\n\t\t                content_path,\n\t\t                title,\n\t\t                text,\n\t\t\t\t\t\ttest_message,\n\t\t\t\t\t\tallow_test_export,\n\t\t\t\t\t\tcontent_type)\n\t\t        VALUES (\n\t\t                %d, \n\t\t                %d, \n\t\t                %d, \n\t\t                NOW(), \n\t\t                0, \n\t\t                %d, \n\t\t                '%s', \n\t\t                '%s',\n\t\t                %d,\n\t\t                '%s', \n\t\t                '', \n\t\t                '%s',\n\t\t                '%s',\n\t\t\t\t\t\t'%s',\n\t\t\t\t\t\t%d,\n\t\t\t\t\t\t%d)";
     $err = queryDB($sql, array(TABLE_PREFIX, $course_id, $content_parent_id, $ordering, $formatting, $release_date, $head, $use_customized_head, escapeSQLValue($keywords), escapeSQLValue($title), escapeSQLValue($text), escapeSQLValue($test_message), $allow_test_export, $content_type));
     /* insert the related content */
     $sql = "SELECT LAST_INSERT_ID() AS insert_id";
     $row = queryDB($sql, array(), TRUE);
     $cid = $row['insert_id'];
     $sql = '';
     if (is_array($related)) {
         foreach ($related as $x => $related_content_id) {
             $related_content_id = intval($related_content_id);
             if ($related_content_id != 0) {
                 if ($sql != '') {
                     $sql .= ', ';
                 }
                 $sql .= '(' . $cid . ', ' . $related_content_id . ')';
                 $sql .= ', (' . $related_content_id . ', ' . $cid . ')';
             }
         }
         if ($sql != '') {
             $sql = 'INSERT INTO %srelated_content VALUES ' . $sql;
             $result = queryDB($sql, array(TABLE_PREFIX));
         }
     }
     return $cid;
 }
示例#2
0
	          formatting, 
	          release_date,
	          head,
	          use_customized_head,
	          keywords, 
	          content_path, 
	          title, 
	          text,
			  test_message,
			  content_type) 
	       VALUES 
			     (' . $_SESSION['course_id'] . ',' . intval($content_parent_id) . ',' . ($content_info['ordering'] + $my_offset - $lti_offset[$content_info['parent_content_id']] + 1) . ',' . '"' . $last_modified . '",													
			      0,' . $content_formatting . ' ,
			      NOW(),"' . $head . '",
			     1,
			      "",' . '"' . $content_info['new_path'] . '",' . '"' . escapeSQLValue($content_info['title']) . '",' . '"' . escapeSQLValue($content) . '",' . '"' . escapeSQLValue($content_info['test_message']) . '",' . $content_folder_type . ')';
    $result = queryDB($sql, array(TABLE_PREFIX));
    /* get the content id and update $items */
    $items[$item_id]['real_content_id'] = at_insert_id();
    /* 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) {
            //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') {
 function importQTI($question)
 {
     global $msg;
     if ($question['question'] == '') {
         $msg->addError(array('EMPTY_FIELDS', _AT('question')));
     }
     //Multiple answer can have 0+ answers, in the QTIImport.class, if size(answer) < 2, answer will be came a scalar.
     //The following code will change $question[answer] back to a vector.
     $question['answer'] = $question['answers'];
     if (!$msg->containsErrors()) {
         $choice_new = array();
         // stores the non-blank choices
         $answer_new = array();
         // stores the associated "answer" for the choices
         foreach ($question['choice'] as $choiceNum => $choiceOpt) {
             $choiceOpt = validate_length($choiceOpt, 255);
             $choiceOpt = escapeSQLValue(trim($choiceOpt));
             $question['answer'][$choiceNum] = intval($question['answer'][$choiceNum]);
             if ($choiceOpt == '') {
                 /* an empty option can't be correct */
                 $question['answer'][$choiceNum] = 0;
             } else {
                 /* filter out empty choices/ remove gaps */
                 $choice_new[] = $choiceOpt;
                 if (in_array($choiceNum, $question['answer'])) {
                     $answer_new[] = 1;
                 } else {
                     $answer_new[] = 0;
                 }
                 if ($question['answer'][$choiceNum] != 0) {
                     $has_answer = TRUE;
                 }
             }
         }
         if ($has_answer != TRUE) {
             $hidden_vars['required'] = htmlspecialchars($question['required']);
             $hidden_vars['feedback'] = htmlspecialchars($question['feedback']);
             $hidden_vars['question'] = htmlspecialchars($question['question']);
             $hidden_vars['category_id'] = htmlspecialchars($question['category_id']);
             for ($i = 0; $i < count($choice_new); $i++) {
                 $hidden_vars['answer[' . $i . ']'] = htmlspecialchars($answer_new[$i]);
                 $hidden_vars['choice[' . $i . ']'] = htmlspecialchars($choice_new[$i]);
             }
             $msg->addConfirm('NO_ANSWER', $hidden_vars);
         } else {
             //add slahes throughout - does that fix it?
             $question['answer'] = $answer_new;
             $question['choice'] = $choice_new;
             $question['answer'] = array_pad($question['answer'], 10, 0);
             $question['choice'] = array_pad($question['choice'], 10, '');
             $question['feedback'] = str_replace("'", "\\'", escapeSQLValue($question['feedback']));
             $question['question'] = str_replace("'", "\\'", escapeSQLValue($question['question']));
             $sql_params = array($question['category_id'], $_SESSION['course_id'], $question['feedback'], $question['question'], $question['choice'][0], $question['choice'][1], $question['choice'][2], $question['choice'][3], $question['choice'][4], $question['choice'][5], $question['choice'][6], $question['choice'][7], $question['choice'][8], $question['choice'][9], $question['answer'][0], $question['answer'][1], $question['answer'][2], $question['answer'][3], $question['answer'][4], $question['answer'][5], $question['answer'][6], $question['answer'][7], $question['answer'][8], $question['answer'][9], 'DEFAULT');
             $sql = vsprintf(AT_SQL_QUESTION_MULTIANSWER, $sql_params);
             $result = queryDB($sql, array());
             if ($result > 0) {
                 return at_insert_id();
             }
         }
     }
 }