function deleteContent($content_id)
 {
     global $_current_user, $_course_id;
     if (!isset($_current_user) || !$_current_user->isAuthor($this->course_id)) {
         return false;
     }
     /* check if exists */
     //		$sql	= "SELECT ordering, content_parent_id FROM ".TABLE_PREFIX."content WHERE content_id=$content_id AND course_id=$_SESSION[course_id]";
     //		$result	= mysql_query($sql, $this->db);
     //		if (!($row = @mysql_fetch_assoc($result)) ) {
     if (!($row = $this->getContentPage($content_id))) {
         return false;
     }
     $ordering = $row['ordering'];
     $content_parent_id = $row['content_parent_id'];
     /* check if this content has sub content	*/
     $children = $this->_menu[$content_id];
     if (is_array($children) && count($children) > 0) {
         /* delete its children recursively first*/
         foreach ($children as $x => $info) {
             if ($info['content_id'] > 0) {
                 $this->deleteContentRecursive($info['content_id']);
             }
         }
     }
     $this->contentDAO->Delete($content_id);
     /* re-order the rest of the content */
     $sql = "UPDATE " . TABLE_PREFIX . "content SET ordering=ordering-1 WHERE ordering>={$ordering} AND content_parent_id={$content_parent_id} AND course_id={$_course_id}";
     $this->contentDAO->execute($sql);
     // unset last-visited content id
     require_once TR_INCLUDE_PATH . 'classes/DAO/UserCoursesDAO.class.php';
     $userCoursesDAO = new UserCoursesDAO();
     $userCoursesDAO->UpdateLastCid($_SESSION['user_id'], $_course_id, 0);
     unset($_SESSION['s_cid']);
     unset($_SESSION['from_cid']);
     /* delete this content page					*/
     //		$sql	= "DELETE FROM ".TABLE_PREFIX."content WHERE content_id=$content_id AND course_id=$_SESSION[course_id]";
     //		$result = mysql_query($sql, $this->db);
     /* delete this content from member tracking page	*/
     //		$sql	= "DELETE FROM ".TABLE_PREFIX."member_track WHERE content_id=$content_id AND course_id=$_SESSION[course_id]";
     //		$result = mysql_query($sql, $this->db);
     //		$sql	= "DELETE FROM ".TABLE_PREFIX."related_content WHERE content_id=$content_id OR related_content_id=$content_id";
     //		$result = mysql_query($sql, $this->db);
     /* delete the content tests association */
     //		$sql	= "DELETE FROM ".TABLE_PREFIX."content_tests_assoc WHERE content_id=$content_id";
     //		$result = mysql_query($sql, $this->db);
     /* delete the content forum association */
     //		$sql	= "DELETE FROM ".TABLE_PREFIX."content_forums_assoc WHERE content_id=$content_id";
     //		$result = mysql_query($sql, $this->db);
     /* Delete all AccessForAll contents */
     //		require_once(TR_INCLUDE_PATH.'classes/A4a/A4a.class.php');
     //		$a4a = new A4a($content_id);
     //		$a4a->deleteA4a();
     /* remove the "resume" to this page, b/c it was deleted */
     //		$sql = "UPDATE ".TABLE_PREFIX."course_enrollment SET last_cid=0 WHERE course_id=$_SESSION[course_id] AND last_cid=$content_id";
     //		$result = mysql_query($sql, $this->db);
     return true;
 }
 /**
  * This function save the last content_id accessed by current user on a course into db and set $_SESSION['s_cid']
  * @access: public
  * @param: $content_id
  * @return: save $content_id, the last visited one of the current user, into db and session
  */
 public static function saveLastCid($content_id)
 {
     global $_course_id;
     if (!$content_id || !isset($_SESSION['user_id'])) {
         return;
     }
     include_once TR_INCLUDE_PATH . 'classes/DAO/UserCoursesDAO.class.php';
     $userCoursesDAO = new UserCoursesDAO();
     if ($userCoursesDAO->isExist($_SESSION['user_id'], $_course_id)) {
         $userCoursesDAO->UpdateLastCid($_SESSION['user_id'], $_course_id, $content_id);
         $_SESSION['s_cid'] = $content_id;
     }
 }
Example #3
0
/************************************************************************/
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);
}
?>


<div class="input-form">
<fieldset class="group_form"><legend class="group_form"><?php 
echo $this->title;
?>
</legend>
<?php 
if (is_array($this->courses)) {
    ?>
  <div class="results">
    <ol class="remove-margin-left">
<?php 
    if (isset($_SESSION['user_id'])) {
        $userCoursesDAO = new UserCoursesDAO();
    }
    $num_results = count($this->courses);
    // if the requested page number exceeds the max number of pages, set the current page to the last page
    $num_pages = ceil($num_results / RESULTS_PER_PAGE);
    if ($this->curr_page_num > $num_pages) {
        $this->curr_page_num = $num_pages;
    }
    $start_num = ($this->curr_page_num - 1) * RESULTS_PER_PAGE;
    $end_num = min($this->curr_page_num * RESULTS_PER_PAGE, $num_results);
    ?>
      <li class="course" style="font-weight:bold">
        <div><?php 
    echo (strstr($caller_script, 'search.php') ? _AT('results') : _AT('lessons')) . ' ' . ($start_num + 1) . '-' . $end_num . ' ' . _AT('of') . ' ' . $num_results . ' ' . ($this->search_text != '' ? _AT('for') . ' "<em>' . $this->search_text . '</em>"' : '');
    ?>
        <?php 
Example #5
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.                        */
/************************************************************************/
if (!defined('TR_INCLUDE_PATH')) {
    exit;
}
require_once TR_INCLUDE_PATH . 'vitals.inc.php';
require_once TR_INCLUDE_PATH . 'classes/DAO/UserCoursesDAO.class.php';
// can only be used by login user
if (!isset($_SESSION['user_id']) || $_SESSION['user_id'] == 0) {
    return;
}
global $savant, $_course_id;
$userCoursesDAO = new UserCoursesDAO();
$output = '';
// The main page can be home/index.php or home/search.php
// Find out the caller URL and direct the page back to the caller
// after adding/removing the course from "My Courses"
list($caller_url, $url_param) = Utility::getRefererURLAndParams();
// retrieve data to display
if ($_SESSION['user_id'] > 0) {
    $my_courses = $userCoursesDAO->getByUserID($_SESSION['user_id']);
}
if (!is_array($my_courses)) {
    $num_of_courses = 0;
    $output = _AT('none_found');
} else {
    $num_of_courses = count($my_courses);
    $output .= '<ol class="remove-margin-left">' . "\n";
Example #6
0
    if (isset($_POST['hide_course'])) {
        $access = 'private';
    } else {
        $access = 'public';
    }
    if (isset($course_primary_lang) && $course_primary_lang != '') {
        $langcode_and_charset = explode('-', $course_primary_lang);
        //		$course_primary_lang = Utility::get3LetterLangCode($langcode_and_charset[0]);
        $course_primary_lang = $langcode_and_charset[0];
    } else {
        $course_primary_lang = DEFAULT_LANGUAGE_CODE;
    }
    $_course_id = $coursesDAO->Create($_SESSION['user_id'], 'top', $access, $course_title, $course_description, '', '', '', '', $course_primary_lang, '', '');
    check_available_size($_course_id);
    // insert author role into table "user_courses"
    $userCoursesDAO = new UserCoursesDAO();
    $userCoursesDAO->Create($_SESSION['user_id'], $_course_id, TR_USERROLE_AUTHOR, 0);
} else {
    $_course_id = $_POST['_course_id'];
}
// end of added by Cindy Li on Jan 10, 2010
/* 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, -6);
} else {
    if (!$package_base_name) {
        $package_base_name = substr($_FILES['file']['name'], 0, -4);
    }
Example #7
0
if ($_content_id > 0) {
    include_once TR_INCLUDE_PATH . 'classes/DAO/ContentDAO.class.php';
    $contentDAO = new ContentDAO();
    $content_row = $contentDAO->get($_content_id);
    $_course_id = $content_row['course_id'];
}
// Generate $_SESSION['s_cid']: record the last visited content_id
// for authors and the users who have the current course in "my courses" list,
//     save the last visited content_id into user_courses and set the session var.
//     @see ContentUtility::saveLastCid()
// for the users who don't have the current course in "my courses" list,
//     set the session var as $_GET['cid']
if ($_course_id > 0) {
    if ($_SESSION['user_id'] > 0) {
        include_once TR_INCLUDE_PATH . 'classes/DAO/UserCoursesDAO.class.php';
        $userCoursesDAO = new UserCoursesDAO();
        $user_courses_row = $userCoursesDAO->get($_SESSION['user_id'], $_course_id);
        if ($user_courses_row && $user_courses_row['last_cid'] > 0) {
            $_SESSION['s_cid'] = $user_courses_row['last_cid'];
        } else {
            if ($_content_id > 0) {
                $_SESSION['s_cid'] = $_content_id;
            } else {
                // first time accessing this course, no last cid yet
                unset($_SESSION['s_cid']);
            }
        }
    } else {
        $_SESSION['s_cid'] = $_content_id;
    }
}