Example #1
0
 /**
  * Check if user is an author 
  * @access  public
  * @param   $course_id: optional. 
  *          if > 0, check whether the user is the author of the course with $course_id
  *          else if = 0 or is not given, check whether the user has author privilege 
  * @return  true : if is an author
  *          false : if not an author
  * @author  Cindy Qi Li
  */
 public function isAuthor($course_id = 0)
 {
     if ($course_id == 0) {
         $row = $this->userDAO->getUserByID($this->userID);
         return $row['is_author'];
     } else {
         include_once TR_INCLUDE_PATH . 'classes/DAO/CoursesDAO.class.php';
         $coursesDAO = new CoursesDAO();
         $course_row = $coursesDAO->get($course_id);
         return $course_row['user_id'] == $this->userID;
     }
 }
 /**
  * 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;
     }
 }
 /**
  * Delete row by forum ID
  * @access  public
  * @param   forumID
  * @return  true or false
  * @author  Cindy Qi Li
  */
 function DeleteByForumID($forumID)
 {
     $sql = "DELETE FROM " . TABLE_PREFIX . "content_forums_assoc \n\t             WHERE forum_id = " . $forumID . "";
     if ($this->execute($sql)) {
         // update the courses.modified_date to the current timestamp
         include_once TR_INCLUDE_PATH . 'classes/DAO/ForumsCoursesDAO.class.php';
         include_once TR_INCLUDE_PATH . 'classes/DAO/CoursesDAO.class.php';
         $forumsCoursesDAO = new ForumsCoursesDAO();
         $course_rows = $forumsCoursesDAO->getByForum($forumID);
         if (is_array($course_rows)) {
             foreach ($course_rows as $row) {
                 $coursesDAO = new CoursesDAO();
                 $coursesDAO->updateModifiedDate($row['course_id']);
             }
         }
         return true;
     } else {
         $msg->addError('DB_NOT_UPDATED');
         return false;
     }
 }
Example #4
0
    } else {
        $use_a4a = false;
        if (isset($_REQUEST['to_a4a'])) {
            $use_a4a = true;
        }
        //	require_once(TR_INCLUDE_PATH.'vitals.inc.php');
        //	$course_id = $_SESSION['course_id'];
    }
}
//load the following after vitals is included
require_once TR_INCLUDE_PATH . 'classes/testQuestions.class.php';
require_once TR_INCLUDE_PATH . 'classes/A4a/A4aExport.class.php';
require_once TR_INCLUDE_PATH . 'classes/Weblinks/Weblinks.class.php';
require_once TR_INCLUDE_PATH . 'classes/Weblinks/WeblinksExport.class.php';
$use_cc = true;
$coursesDAO = new CoursesDAO();
$course_row = $coursesDAO->get($course_id);
$contentManager = new ContentManager($course_id);
$instructor_id = $course_row['user_id'];
$course_desc = htmlspecialchars($course_row['description'], ENT_QUOTES, 'UTF-8');
$course_title = htmlspecialchars($course_row['title'], ENT_QUOTES, 'UTF-8');
$course_language = $course_row['primary_language'];
$courseLanguage =& $languageManager->getLanguage($course_language);
//If course language cannot be found, use UTF-8 English
//@author harris, Oct 30,2008
if (!isset($courseLanguage) || $courseLanguage == null) {
    $courseLanguage =& $languageManager->getLanguage(DEFAULT_LANGUAGE_CODE);
}
$course_language_charset = $courseLanguage->getCharacterSet();
$course_language_code = $courseLanguage->getCode();
require_once TR_INCLUDE_PATH . 'classes/zipfile.class.php';
Example #5
0
        $msg->addError('IMPORTDIR_FAILED');
    }
    /* extract the entire archive into TR_COURSE_CONTENT . import/$course using the call back function to filter out php files */
    error_reporting(0);
    $archive = new PclZip($_FILES['file']['tmp_name']);
    if ($archive->extract(PCLZIP_OPT_PATH, $import_path, PCLZIP_CB_PRE_EXTRACT, 'preImportCallBack') == 0) {
        $msg->addError('IMPORT_FAILED');
        echo 'Error : ' . $archive->errorInfo(true);
        FileUtility::clr_dir($import_path);
        header('Location: question_db.php?_course_id=' . $_course_id);
        exit;
    }
    error_reporting(TR_ERROR_REPORTING);
}
/* get the course's max_quota */
$coursesDAO = new CoursesDAO();
$q_row = $coursesDAO->get($_course_id);
if ($q_row['max_quota'] != TR_COURSESIZE_UNLIMITED) {
    $zip_size_limit = $MaxCourseSize;
    $totalBytes = FileUtility::dirsize($import_path);
    $total_after = $zip_size_limit - $totalBytes;
    if (is_dir(TR_CONTENT_DIR . $_course_id . '/')) {
        $course_total = FileUtility::dirsize(TR_CONTENT_DIR . $_course_id . '/');
        $total_after -= $course_total;
    }
    if ($total_after < 0) {
        /* remove the content dir, since there's no space for it */
        $errors = array('NO_CONTENT_SPACE', number_format(-1 * ($total_after / TR_KBYTE_SIZE), 2));
        $msg->addError($errors);
        // Clean up import path and inserted course row
        FileUtility::clr_dir($import_path);
Example #6
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 TR_INCLUDE_PATH . 'vitals.inc.php';
require_once TR_INCLUDE_PATH . 'classes/Utility.class.php';
require_once TR_INCLUDE_PATH . 'classes/DAO/CoursesDAO.class.php';
global $_course_id;
$coursesDAO = new CoursesDAO();
if ($_course_id > 0) {
    Utility::authenticate(TR_PRIV_ISAUTHOR_OF_CURRENT_COURSE);
} else {
    Utility::authenticate(TR_PRIV_ISAUTHOR);
}
if (isset($_POST['cancel'])) {
    $msg->addFeedback('CANCELLED');
    header('Location: ' . TR_BASE_HREF . 'home/course/index.php?_course_id=' . $_course_id);
    exit;
} else {
    if ($_POST['submit']) {
        if (isset($_POST['hide_course'])) {
            $access = 'private';
        } else {
            $access = 'public';
Example #7
0
//}
// Check if all the files exists in the manifest, iff it's a IMS CC package.
if ($content_type == 'IMS Common Cartridge') {
    checkResources($import_path);
}
// Check if there are any errors during parsing.
if ($msg->containsErrors()) {
    if (isset($_GET['tile'])) {
        header('Location: ' . $_base_path . 'tools/tile/index.php');
    } else {
        header('Location: ../index.php');
    }
    exit;
}
/* initialize DAO objects */
$coursesDAO = new CoursesDAO();
$contentDAO = new ContentDAO();
/* generate a unique new package base path based on the package file name and date as needed. */
/* the package name will be the dir where the content for this package will be put, as a result */
/* the 'content_path' field in the content table will be set to this path. */
/* $package_base_name_url comes from the URL file name (NOT the file name of the actual file we open)*/
if (!$package_base_name && $package_base_name_url) {
    $package_base_name = substr($package_base_name_url, 0, -4);
} else {
    if (!$package_base_name) {
        $package_base_name = substr($_FILES['file']['name'], 0, -4);
    }
}
// create course
if (isset($_POST['hide_course'])) {
    $access = 'private';
Example #8
0
 /**
  * Delete content
  * @access  public
  * @param   content ID
  * @return  true, if successful
  *          false and add error into global var $msg, if unsuccessful
  * @author  Cindy Qi Li
  */
 public function Delete($contentID)
 {
     global $msg;
     require_once TR_INCLUDE_PATH . 'classes/A4a/A4a.class.php';
     $a4a = new A4a($contentID);
     $a4a->deleteA4a();
     // delete the content tests association
     include_once TR_INCLUDE_PATH . 'classes/DAO/ContentTestsAssocDAO.class.php';
     $contentTestsAssocDAO = new ContentTestsAssocDAO();
     $contentTestsAssocDAO->DeleteByContentID($contentID);
     // delete the content forums association
     include_once TR_INCLUDE_PATH . 'classes/DAO/ContentForumsAssocDAO.class.php';
     $contentForumsAssocDAO = new ContentForumsAssocDAO();
     $contentForumsAssocDAO->DeleteByContentID($contentID);
     $sql = "DELETE FROM " . TABLE_PREFIX . "content WHERE content_id = " . $contentID;
     if ($this->execute($sql)) {
         // update the courses.modified_date to the current timestamp
         include_once TR_INCLUDE_PATH . 'classes/DAO/CoursesDAO.class.php';
         $coursesDAO = new CoursesDAO();
         $coursesDAO->updateModifiedDate($contentID, "content_id");
         return true;
     } else {
         $msg->addError('DB_NOT_UPDATED');
         return false;
     }
 }
Example #9
0
/* as published by the Free Software Foundation.                        */
/************************************************************************/
define('TR_INCLUDE_PATH', '../include/');
require TR_INCLUDE_PATH . 'vitals.inc.php';
require_once TR_INCLUDE_PATH . 'classes/DAO/CoursesDAO.class.php';
require_once TR_INCLUDE_PATH . 'classes/DAO/UserCoursesDAO.class.php';
require_once TR_INCLUDE_PATH . 'classes/DAO/CourseCategoriesDAO.class.php';
global $_current_user;
//if (trim($_GET['search_text'] == ''))
//{
//	global $msg;
//	$msg->addError('NO_SEARCH_TEXT');
//
//	header('Location: index.php?id='.$ids);
//}
$coursesDAO = new CoursesDAO();
$userCoursesDAO = new UserCoursesDAO();
$courseCategoriesDAO = new CourseCategoriesDAO();
//$my_courses = array();
$search_text = trim($_GET['search_text']);
$courses = $coursesDAO->getSearchResult($addslashes($search_text), $_GET['catid']);
// handle submits
if (isset($_GET['action'], $_GET['cid']) && $_SESSION['user_id'] > 0) {
    $cid = intval($_GET['cid']);
    if ($_GET['action'] == 'remove') {
        $userCoursesDAO->Delete($_SESSION['user_id'], $cid);
    }
    if ($_GET['action'] == 'add') {
        $userCoursesDAO->Create($_SESSION['user_id'], $cid, TR_USERROLE_VIEWER, 0);
    }
    $msg->addFeedback(ACTION_COMPLETED_SUCCESSFULLY);
/** 
 * 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
}
Example #11
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.                        */
/************************************************************************/
define('TR_INCLUDE_PATH', '../include/');
require TR_INCLUDE_PATH . 'vitals.inc.php';
require_once TR_INCLUDE_PATH . 'classes/DAO/UserCoursesDAO.class.php';
require_once TR_INCLUDE_PATH . 'classes/DAO/CoursesDAO.class.php';
require_once TR_INCLUDE_PATH . 'classes/DAO/CourseCategoriesDAO.class.php';
global $_current_user;
// clean up the session vars from the previous course
unset($_SESSION['course_id']);
$userCoursesDAO = new UserCoursesDAO();
$coursesDAO = new CoursesDAO();
$courseCategoriesDAO = new CourseCategoriesDAO();
if (isset($_GET['catid']) && trim($_GET['catid']) != '') {
    $catid = intval($_GET['catid']);
}
if (isset($_GET['action'], $_GET['cid']) && $_SESSION['user_id'] > 0) {
    $cid = intval($_GET['cid']);
    if ($_GET['action'] == 'remove') {
        $userCoursesDAO->Delete($_SESSION['user_id'], $cid);
    }
    if ($_GET['action'] == 'add') {
        $userCoursesDAO->Create($_SESSION['user_id'], $cid, TR_USERROLE_VIEWER, 0);
    }
    $msg->addFeedback(ACTION_COMPLETED_SUCCESSFULLY);
}
// retrieve data to display
Example #12
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.                        */
/************************************************************************/
if (!defined('TR_INCLUDE_PATH')) {
    exit;
}
require_once TR_INCLUDE_PATH . 'vitals.inc.php';
require_once TR_INCLUDE_PATH . 'classes/DAO/CourseCategoriesDAO.class.php';
require_once TR_INCLUDE_PATH . 'classes/DAO/CoursesDAO.class.php';
global $savant;
$courseCategoriesDAO = new CourseCategoriesDAO();
$coursesDAO = new CoursesDAO();
$output = '';
// get the number of courses in each category
$courses_in_category = $coursesDAO->getCategoriesAndNumOfCourses();
if (is_array($courses_in_category)) {
    foreach ($courses_in_category as $row) {
        $course_num_summary[$row['category_id']] = $row['num_of_courses'];
    }
}
// get all categories
$categories = $courseCategoriesDAO->getAll();
if (is_array($categories)) {
    foreach ($categories as $category) {
        $output .= '<a href="' . TR_BASE_HREF . 'home/index.php?catid=' . $category['category_id'] . '">';
        if ($_GET['catid'] != '' && $_GET['catid'] == $category['category_id']) {
            $output .= '<span class="selected-sidemenu">';
Example #13
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 TR_INCLUDE_PATH . 'vitals.inc.php';
require_once TR_INCLUDE_PATH . 'classes/DAO/CoursesDAO.class.php';
require_once TR_INCLUDE_PATH . 'classes/Utility.class.php';
global $_course_id;
Utility::authenticate(TR_PRIV_ISAUTHOR_OF_CURRENT_COURSE);
$coursesDAO = new CoursesDAO();
$course_info = $coursesDAO->get($_course_id);
if (isset($_POST['submit_no'])) {
    $msg->addFeedback('CANCELLED');
    header('Location: ' . TR_BASE_HREF . 'home/course/index.php?_course_id=' . $_course_id);
    exit;
} else {
    if (isset($_POST['step']) && $_POST['step'] == 2 && isset($_POST['submit_yes'])) {
        $coursesDAO->Delete($_course_id);
        $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
        header('Location: ' . TR_BASE_HREF . 'home/index.php');
        exit;
    }
}
require TR_INCLUDE_PATH . 'header.inc.php';
if (!isset($_POST['step'])) {
Example #14
0
    $errors[] = 'TR_ERROR_EMPTY_WEB_SERVICE_ID';
} else {
    // validate web service id
    $usersDAO = new UsersDAO();
    $user_row = $usersDAO->getUserByWebServiceID($web_service_id);
    if (!$user_row) {
        $errors[] = 'TR_ERROR_INVALID_WEB_SERVICE_ID';
    }
    $user_id = $user_row['user_id'];
}
// return errors
if (is_array($errors)) {
    echo RESTWebServiceOutput::generateErrorRpt($errors);
    exit;
}
$coursesDAO = new CoursesDAO();
$results = $coursesDAO->getSearchResult($addslashes($keywords), '', $start, $maxResults);
// get total number of search results regardless of $maxResults
$all_results = $coursesDAO->getSearchResult($addslashes($keywords));
if (is_array($all_results)) {
    $total_num = count($all_results);
} else {
    $total_num = 0;
}
// calculate the last record number
if (is_array($results)) {
    $num_of_results = count($results);
    if ($maxResults > $num_of_results) {
        $last_rec_number = $start + $num_of_results;
    } else {
        $last_rec_number = $start + $maxResults;
Example #15
0
if ($archive->extract(PCLZIP_OPT_PATH, $import_path, PCLZIP_CB_PRE_EXTRACT, 'preImportCallBack') == 0) {
    if ($oauth_import) {
        echo "error=" . urlencode('Cannot unzip the package');
    } else {
        $msg->addError('IMPORT_FAILED');
        echo 'Error : ' . $archive->errorInfo(true);
    }
    FileUtility::clr_dir($import_path);
    header('Location: ' . $_SERVER['HTTP_REFERER']);
    if (file_exists($full_filename)) {
        @unlink($full_filename);
    }
    exit;
}
/* initialize DAO objects */
$coursesDAO = new CoursesDAO();
$contentDAO = new ContentDAO();
$testsQuestionsAssocDAO = new TestsQuestionsAssocDAO();
$contentTestsAssocDAO = new ContentTestsAssocDAO();
// get the course's max_quota
if (isset($_POST['_course_id'])) {
    check_available_size($_POST['_course_id']);
}
$items = array();
/* all the content pages */
$order = array();
/* keeps track of the ordering for each content page */
$path = array();
/* the hierarchy path taken in the menu to get to the current item in the manifest */
$dependency_files = array();
/* the file path for the dependency files */