/**
  * Delete row by test ID
  * @access  public
  * @param   testID
  * @return  true or false
  * @author  Cindy Qi Li
  */
 function DeleteByTestID($testID)
 {
     $sql = "DELETE FROM " . TABLE_PREFIX . "content_tests_assoc \n\t             WHERE test_id = " . $testID . "";
     if ($this->execute($sql)) {
         // update the courses.modified_date to the current timestamp
         include_once TR_INCLUDE_PATH . 'classes/DAO/TestsDAO.class.php';
         include_once TR_INCLUDE_PATH . 'classes/DAO/CoursesDAO.class.php';
         $testsDAO = new TestsDAO();
         $test_rows = $testsDAO->get($testID);
         if ($test_rows['course_id'] > 0) {
             $coursesDAO = new CoursesDAO();
             $coursesDAO->updateModifiedDate($test_rows['course_id']);
         }
         return true;
     } else {
         $msg->addError('DB_NOT_UPDATED');
         return false;
     }
 }
示例#2
0
/* Inclusive Design Institute                                           */
/*                                                                      */
/* This program is free software. You can redistribute it and/or        */
/* modify it under the terms of the GNU General Public License          */
/* as published by the Free Software Foundation.                        */
/************************************************************************/
$page = 'tests';
define('TR_INCLUDE_PATH', '../include/');
require_once TR_INCLUDE_PATH . 'vitals.inc.php';
require_once TR_INCLUDE_PATH . 'classes/Utility.class.php';
require_once TR_INCLUDE_PATH . 'classes/DAO/TestsDAO.class.php';
require_once TR_INCLUDE_PATH . 'classes/DAO/TestsQuestionsAssocDAO.class.php';
require_once TR_INCLUDE_PATH . 'classes/DAO/ContentTestsAssocDAO.class.php';
global $_course_id;
Utility::authenticate(TR_PRIV_ISAUTHOR_OF_CURRENT_COURSE);
$testsDAO = new TestsDAO();
if (isset($_POST['submit_no'])) {
    $msg->addFeedback('CANCELLED');
    header('Location: index.php?_course_id=' . $_course_id);
    exit;
} else {
    if (isset($_POST['submit_yes'])) {
        $tid = intval($_POST['tid']);
        if ($testsDAO->Delete($tid)) {
            $testsQuestionsAssocDAO = new TestsQuestionsAssocDAO();
            $testsQuestionsAssocDAO->DeleteByTestID($tid);
            //delete test content association as well
            $contentTestsAssocDAO = new ContentTestsAssocDAO();
            $contentTestsAssocDAO->DeleteByTestID($tid);
        }
        $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
示例#3
0
    if (isset($_GET['preview'], $_GET['id'])) {
        header('Location: preview.php?tid=' . $_GET['id'] . '&_course_id=' . $_course_id);
        exit;
    } else {
        if (isset($_GET['questions'], $_GET['id'])) {
            header('Location: questions.php?tid=' . $_GET['id'] . '&_course_id=' . $_course_id);
            exit;
        } else {
            if (isset($_GET['delete'], $_GET['id'])) {
                header('Location: delete_test.php?tid=' . $_GET['id'] . '&_course_id=' . $_course_id);
                exit;
            } else {
                if (isset($_GET['export'], $_GET['id'])) {
                    header('Location: export_test.php?tid=' . $_GET['id'] . '&_course_id=' . $_course_id);
                } else {
                    if (isset($_GET['edit']) || isset($_GET['preview']) || isset($_GET['questions']) || isset($_GET['delete']) || isset($_GET['export'])) {
                        $msg->addError('NO_ITEM_SELECTED');
                    }
                }
            }
        }
    }
}
$testsDAO = new TestsDAO();
/* get a list of all the tests we have, and links to create, edit, delete, preview */
$rows = $testsDAO->getByCourseID($_course_id);
require_once TR_INCLUDE_PATH . 'header.inc.php';
$savant->assign('course_id', $_course_id);
$savant->assign('rows', $rows);
$savant->display('tests/index.tmpl.php');
require_once TR_INCLUDE_PATH . 'footer.inc.php';
示例#4
0
/* Inclusive Design Institute                                           */
/*                                                                      */
/* This program is free software. You can redistribute it and/or        */
/* modify it under the terms of the GNU General Public License          */
/* as published by the Free Software Foundation.                        */
/************************************************************************/
if (!defined('TR_INCLUDE_PATH')) {
    exit;
}
global $_course_id, $_content_id;
include_once TR_INCLUDE_PATH . 'classes/DAO/ContentTestsAssocDAO.class.php';
include_once TR_INCLUDE_PATH . 'classes/DAO/TestsDAO.class.php';
/* Get the list of associated tests with this content on page load */
$cid = $_REQUEST['cid'] = $_content_id;
//uses request 'cause after 'saved', the cid will become $_GET.
$testsDAO = new TestsDAO();
$num_tests = 0;
$all_tests = $testsDAO->getByCourseID($_course_id);
/* get a list of all the tests we have, and links to create, edit, delete, preview */
//$sql	= "SELECT *, UNIX_TIMESTAMP(start_date) AS us, UNIX_TIMESTAMP(end_date) AS ue
//             FROM ".TABLE_PREFIX."tests
//            WHERE course_id=$_SESSION[course_id]
//            ORDER BY start_date DESC";
//$result	= mysql_query($sql, $db);
if (is_array($all_tests)) {
    $num_tests = count($all_tests);
}
//If there are no tests, don't display anything except a message
if ($num_tests == 0) {
    $msg->addInfo(array('NO_TESTS', TR_BASE_HREF . 'tests/create_test.php?_course_id=' . $_course_id));
    $msg->printInfos();
/** 
 * Export test 
 * @param	int		test id
 * @param	string	the test title
 * @param	ref		[OPTIONAL] zip object reference
 * @param	array	[OPTIONAL] list of already added files.
 */
function test_qti_export($tid, $test_title = '', $zipfile = null)
{
    global $_course_id;
    require_once TR_INCLUDE_PATH . 'classes/DAO/CoursesDAO.class.php';
    require_once TR_INCLUDE_PATH . 'classes/DAO/TestsDAO.class.php';
    require_once TR_INCLUDE_PATH . 'classes/DAO/TestsQuestionsAssocDAO.class.php';
    require_once TR_INCLUDE_PATH . 'classes/zipfile.class.php';
    // for zipfile
    require_once TR_INCLUDE_PATH . 'classes/XML/XML_HTMLSax/XML_HTMLSax.php';
    // for XML_HTMLSax
    require_once TR_INCLUDE_PATH . 'lib/html_resource_parser.inc.php';
    // for get_html_resources()
    global $savant, $db, $languageManager, $test_zipped_files, $test_files, $use_cc;
    global $course_id;
    $coursesDAO = new CoursesDAO();
    $course_row = $coursesDAO->get($_course_id);
    $course_language = $course_row['primary_language'];
    $courseLanguage =& $languageManager->getLanguage($course_language);
    $course_language_charset = $courseLanguage->getCharacterSet();
    $imported_files;
    $zipflag = false;
    if ($zipfile == null) {
        $zipflag = true;
    }
    if ($test_zipped_files == null) {
        $test_zipped_files = array();
    }
    if ($zipflag) {
        $zipfile = new zipfile();
        $zipfile->create_dir('resources/');
        // for all the dependency files
    }
    $resources = array();
    $dependencies = array();
    //	don't want to sort it, i want the same order out.
    //	asort($question_ids);
    //TODO: Merge the following 2 sqls together.
    //Randomized or not, export all the questions that are associated with it.
    //	$sql	= "SELECT TQ.question_id, TQA.weight FROM ".TABLE_PREFIX."tests_questions TQ INNER JOIN ".TABLE_PREFIX."tests_questions_assoc TQA USING (question_id) WHERE TQ.course_id=$_SESSION[course_id] AND TQA.test_id=$tid ORDER BY TQA.ordering, TQA.question_id";
    //	$result	= mysql_query($sql, $db);
    //	$question_ids = array();
    //
    //	if (is_array($question_rows)){
    //		foreach ($question_rows as $question_row) $question_ids[] = $question_row['question_id'];
    //	}
    //
    //	//No questions in the test
    //	if (sizeof($question_ids)==0){
    //		return;
    //	}
    //
    //	$question_ids_delim = implode(',',$question_ids);
    //
    //	//$sql = "SELECT * FROM ".TABLE_PREFIX."tests_questions WHERE course_id=$_SESSION[course_id] AND question_id IN($question_ids_delim)";
    //	$sql = "SELECT TQ.*, TQA.weight, TQA.test_id FROM ".TABLE_PREFIX."tests_questions TQ INNER JOIN ".TABLE_PREFIX."tests_questions_assoc TQA USING (question_id) WHERE TQA.test_id=$tid AND TQ.question_id IN($question_ids_delim) ORDER BY TQA.ordering, TQA.question_id";
    //
    //	$result = mysql_query($sql, $db);
    //	while ($row = mysql_fetch_assoc($result)) {
    $testsQuestionsAssocDAO = new TestsQuestionsAssocDAO();
    $question_rows = $testsQuestionsAssocDAO->getByTestID($tid);
    if (!is_array($question_rows)) {
        return false;
    } else {
        foreach ($question_rows as $row) {
            $obj = TestQuestions::getQuestion($row['type']);
            $local_xml = '';
            $local_xml = $obj->exportQTI($row, $course_language_charset, '1.2.1');
            $local_dependencies = array();
            $text_blob = implode(' ', $row);
            $local_dependencies = get_html_resources($text_blob);
            $dependencies = array_merge($dependencies, $local_dependencies);
            $xml = $xml . "\n\n" . $local_xml;
        }
    }
    //files that are found inside the test; used by print_organization(), to add all test files into QTI/ folder.
    $test_files = $dependencies;
    $resources[] = array('href' => 'tests_' . $tid . '.xml', 'dependencies' => array_keys($dependencies));
    $xml = trim($xml);
    //get test title
    //	$sql = "SELECT title FROM ".TABLE_PREFIX."tests WHERE test_id = $tid";
    //	$result = mysql_query($sql, $db);
    //	$row = mysql_fetch_array($result);
    $testsDAO = new TestsDAO();
    $row = $testsDAO->get($tid);
    //TODO: wrap around xml now
    $savant->assign('xml_content', $xml);
    $savant->assign('title', htmlspecialchars($row['title'], ENT_QUOTES, 'UTF-8'));
    $savant->assign('num_takes', $row['num_takes']);
    $savant->assign('use_cc', $use_cc);
    $xml = $savant->fetch('tests/test_questions/wrapper.tmpl.php');
    $xml_filename = 'tests_' . $tid . '.xml';
    if (!$use_cc) {
        $zipfile->add_file($xml, $xml_filename);
    } else {
        $zipfile->add_file($xml, 'QTI/' . $xml_filename);
    }
    // add any dependency files:
    if (!$use_cc) {
        foreach ($dependencies as $resource => $resource_server_path) {
            //add this file in if it's not already in the zip package
            if (!in_array($resource_server_path, $test_zipped_files)) {
                $zipfile->add_file(@file_get_contents($resource_server_path), 'resources/' . $resource, filemtime($resource_server_path));
                $test_zipped_files[] = $resource_server_path;
            }
        }
    }
    if ($zipflag) {
        // construct the manifest xml
        $savant->assign('resources', $resources);
        $savant->assign('dependencies', array_keys($dependencies));
        $savant->assign('encoding', $course_language_charset);
        $savant->assign('title', $test_title);
        $savant->assign('xml_filename', $xml_filename);
        $manifest_xml = $savant->fetch('tests/test_questions/manifest_qti_1p2.tmpl.php');
        $zipfile->add_file($manifest_xml, 'imsmanifest.xml');
        $zipfile->close();
        $filename = str_replace(array(' ', ':'), '_', $course_row['title'] . '-' . $test_title . '-' . date('Ymd'));
        $zipfile->send_file($filename);
        exit;
    }
    $return_array[$xml_filename] = array_keys($dependencies);
    return $return_array;
    //done
}
示例#6
0
/* Copyright (c) 2010                                                   */
/* Inclusive Design Institute                                           */
/*                                                                      */
/* This program is free software. You can redistribute it and/or        */
/* modify it under the terms of the GNU General Public License          */
/* as published by the Free Software Foundation.                        */
/************************************************************************/
$page = 'tests';
define('TR_INCLUDE_PATH', '../include/');
require_once TR_INCLUDE_PATH . 'vitals.inc.php';
require_once TR_INCLUDE_PATH . 'classes/DAO/TestsDAO.class.php';
require_once TR_INCLUDE_PATH . 'classes/Utility.class.php';
global $_course_id;
Utility::authenticate(TR_PRIV_ISAUTHOR_OF_CURRENT_COURSE);
$tid = intval($_REQUEST['tid']);
$testsDAO = new TestsDAO();
$row = $testsDAO->get($tid);
if (isset($_POST['cancel'])) {
    $msg->addFeedback('CANCELLED');
    header('Location: index.php?_course_id=' . $_course_id);
    exit;
} else {
    if (isset($_POST['submit'])) {
        if ($testsDAO->Update($_POST['tid'], $_POST['title'], $_POST['description'])) {
            $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
            header('Location: index.php?_course_id=' . $_course_id);
            exit;
        }
    }
}
$onload = 'document.form.title.focus();';
示例#7
0
/************************************************************************/
/* AContent                                                             */
/************************************************************************/
/* Copyright (c) 2010                                                   */
/* Inclusive Design Institute                                           */
/*                                                                      */
/* This program is free software. You can redistribute it and/or        */
/* modify it under the terms of the GNU General Public License          */
/* as published by the Free Software Foundation.                        */
/************************************************************************/
define('TR_INCLUDE_PATH', '../include/');
require_once TR_INCLUDE_PATH . 'vitals.inc.php';
require_once TR_INCLUDE_PATH . 'classes/testQuestions.class.php';
require_once TR_INCLUDE_PATH . 'classes/DAO/TestsDAO.class.php';
require_once TR_INCLUDE_PATH . 'classes/Utility.class.php';
global $_course_id;
Utility::authenticate(TR_PRIV_ISAUTHOR_OF_CURRENT_COURSE);
$testsDAO = new TestsDAO();
$tid = intval($_GET['tid']);
/* Retrieve the content_id of this test */
if (!($test_row = $testsDAO->get($tid))) {
    $msg->addError('ITEM_NOT_FOUND');
    header('Location: index.php?_course_id=' . $_course_id);
    exit;
}
//export
if (!test_qti_export($tid, $test_row['title'])) {
    $msg->addInfo('TEST_NO_QUESTION');
    header('Location: index.php?_course_id=' . $_course_id);
    exit;
}
示例#8
0
/* modify it under the terms of the GNU General Public License          */
/* as published by the Free Software Foundation.                        */
/************************************************************************/
//$page = 'tests';
define('TR_INCLUDE_PATH', '../include/');
require_once TR_INCLUDE_PATH . 'vitals.inc.php';
require_once TR_INCLUDE_PATH . 'classes/DAO/TestsDAO.class.php';
require_once TR_INCLUDE_PATH . 'classes/Utility.class.php';
global $_course_id;
Utility::authenticate(TR_PRIV_ISAUTHOR_OF_CURRENT_COURSE);
$test_type = 'normal';
if (isset($_POST['cancel'])) {
    $msg->addFeedback('CANCELLED');
    header('Location: index.php?_course_id=' . $_course_id);
    exit;
} else {
    if (isset($_POST['submit'])) {
        $testsDAO = new TestsDAO();
        if ($testsDAO->Create($_course_id, $_POST['title'], $_POST['description'])) {
            $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
            header('Location: index.php?_course_id=' . $_course_id);
            exit;
        }
    }
}
$onload = 'document.form.title.focus();';
$savant->assign('course_id', $_course_id);
require_once TR_INCLUDE_PATH . 'header.inc.php';
$msg->printErrors();
$savant->display('tests/create_edit_test.tmpl.php');
require TR_INCLUDE_PATH . 'footer.inc.php';
示例#9
0
/*                                                                      */
/* This program is free software. You can redistribute it and/or        */
/* modify it under the terms of the GNU General Public License          */
/* as published by the Free Software Foundation.                        */
/************************************************************************/
$page = 'tests';
define('TR_INCLUDE_PATH', '../include/');
require_once TR_INCLUDE_PATH . 'vitals.inc.php';
require_once TR_INCLUDE_PATH . 'classes/testQuestions.class.php';
require_once TR_INCLUDE_PATH . 'classes/Utility.class.php';
require_once TR_INCLUDE_PATH . 'classes/DAO/TestsDAO.class.php';
require_once TR_INCLUDE_PATH . 'classes/DAO/TestsQuestionsCategoriesDAO.class.php';
require_once TR_INCLUDE_PATH . 'classes/DAO/TestsQuestionsAssocDAO.class.php';
global $_course_id;
Utility::authenticate(TR_PRIV_ISAUTHOR_OF_CURRENT_COURSE);
$testsDAO = new TestsDAO();
$testsQuestionsCategoriesDAO = new TestsQuestionsCategoriesDAO();
$testsQuestionsAssocDAO = new TestsQuestionsAssocDAO();
$_pages['tests/questions.php']['title_var'] = 'questions';
$_pages['tests/questions.php']['parent'] = 'tests/index.php';
$_pages['tests/questions.php']['children'] = array('tests/add_test_questions.php?tid=' . $_GET['tid'] . '&_course_id=' . $_course_id);
$_pages['tests/add_test_questions.php?tid=' . $_GET['tid'] . '&_course_id=' . $_course_id]['title_var'] = 'add_questions';
$_pages['tests/add_test_questions.php?tid=' . $_GET['tid'] . '&_course_id=' . $_course_id]['parent'] = 'tests/questions.php?tid=' . $_GET['tid'] . '&_course_id=' . $_course_id;
$_pages['tests/questions.php']['guide'] = 'instructor/?p=add_questions.php';
$tid = intval($_REQUEST['tid']);
if (isset($_POST['submit'])) {
    $count = 1;
    foreach ($_POST['weight'] as $qid => $weight) {
        $qid = intval($qid);
        $weight = intval($weight);
        $orders = $_POST['ordering'];
示例#10
0
 /**
  * This function is to import a test and returns the test id.
  * @param	string	custmom test title
  *
  * @return	int		test id
  */
 function importTest($title = '')
 {
     global $_course_id;
     $title = $title == '' ? $this->title : $title;
     $testsDAO = new TestsDAO();
     $tid = $testsDAO->Create($_course_id, $title, $test_obj['description']);
     //			$sql_params = array (	$_SESSION['course_id'],
     //									$test_obj['title'],
     //									$test_obj['description'],
     //									$test_obj['format'],
     //									$start_date,
     //									$end_date,
     //									$test_obj['order'],
     //									$test_obj['num_questions'],
     //									$test_obj['instructions'],
     //									$test_obj['content_id'],
     //									$test_obj['passscore'],
     //									$test_obj['passpercent'],
     //									$test_obj['passfeedback'],
     //									$test_obj['failfeedback'],
     //									$test_obj['result_release'],
     //									$test_obj['random'],
     //									$test_obj['difficulty'],
     //									$test_obj['num_takes'],
     //									$test_obj['anonymous'],
     //									'',
     //									$test_obj['allow_guests'],
     //									$test_obj['display']);
     //
     //			$sql = vsprintf(AT_SQL_TEST, $sql_params);
     //			$result = mysql_query($sql, $db);
     //			$tid = mysql_insert_id($db);
     //debug($qti_import->weights, 'weights');
     return $tid;
 }