http://atutor.ca/atutor/mantis/view.php?id=3089
authorjoel kronenberg <joel.kronenberg@utoronto.ca>
Mon, 16 Jul 2007 19:30:01 +0000 (19:30 -0000)
committerjoel kronenberg <joel.kronenberg@utoronto.ca>
Mon, 16 Jul 2007 19:30:01 +0000 (19:30 -0000)
docs/bounce.php
docs/include/html/course_properties.inc.php
docs/include/lib/course.inc.php
docs/include/vitals.inc.php
docs/install/db/atutor_schema.sql
docs/install/db/atutor_upgrade_1.5.4_to_1.5.5.sql
docs/users/create_course.php

index b425855..5adfb6c 100644 (file)
@@ -179,14 +179,14 @@ if (($course === 0) && $_SESSION['valid_user']) {
        exit; 
 }
 
-$sql   = "SELECT member_id, content_packaging, cat_id, access, title, UNIX_TIMESTAMP(release_date) AS u_release_date FROM ".TABLE_PREFIX."courses WHERE course_id=$course";
+$sql   = "SELECT member_id, content_packaging, cat_id, access, title, UNIX_TIMESTAMP(release_date) AS u_release_date, UNIX_TIMESTAMP(end_date) AS u_end_date FROM ".TABLE_PREFIX."courses WHERE course_id=$course";
 $result = mysql_query($sql,$db);
 if (!$row = mysql_fetch_assoc($result)) {
        $msg->addError('ITEM_NOT_FOUND');
        if ($_SESSION['member_id']) {
                header('Location: '.AT_BASE_HREF.'users/index.php');
        } else {
-               header('Location: login.php');
+               header('Location: '.AT_BASE_HREF.'login.php');
        }
        exit;
 }
@@ -208,11 +208,12 @@ if ($set_to_public) {
        $row['access'] = "public";
 }
 
+//debug($row); exit;
 switch ($row['access']){
        case 'public':
                apply_category_theme($row['cat_id']);
 
-               if (!$_SESSION['valid_user'] && ($row['u_release_date'] < time())) {
+               if (!$_SESSION['valid_user'] && ($row['u_release_date'] < time()) && (!$row['u_end_date'] || $row['u_end_date'] > time())) {
                        $_SESSION['course_id']    = $course;
                        /* guest login */
                        $_SESSION['login']              = 'guest';
@@ -224,7 +225,11 @@ switch ($row['access']){
                        /* add guest login to counter: */
                        count_login();
                } else if (!$_SESSION['valid_user']) {
-                       $msg->addError(array('COURSE_NOT_RELEASED', AT_Date(_AT('announcement_date_format'), $row['u_release_date'], AT_DATE_UNIX_TIMESTAMP)));
+                       if ($row['u_release_date'] > time()) {
+                               $msg->addError(array('COURSE_NOT_RELEASED', AT_Date(_AT('announcement_date_format'), $row['u_release_date'], AT_DATE_UNIX_TIMESTAMP)));
+                       } else {
+                               $msg->addError(array('COURSE_ENDED', AT_Date(_AT('announcement_date_format'), $row['u_end_date'], AT_DATE_UNIX_TIMESTAMP)));
+                       }
                        header('Location: '.AT_BASE_HREF.'browse.php');
                        exit;
 
@@ -257,6 +262,13 @@ switch ($row['access']){
                        exit;
                } else if ($row['u_release_date'] > time()) {
                        $msg->addInfo(array('COURSE_RELEASE', AT_Date(_AT('announcement_date_format'), $row['u_release_date'], AT_DATE_UNIX_TIMESTAMP)));
+
+               } else if ($row['u_end_date'] && ($row['u_end_date'] < time()) && !($_SESSION['is_admin'] || $_SESSION['privileges'])) {
+                       $msg->addError(array('COURSE_ENDED', AT_Date(_AT('announcement_date_format'), $row['u_end_date'], AT_DATE_UNIX_TIMESTAMP)));
+                       header('Location: '.AT_BASE_HREF.'bounce.php?course=0');
+                       exit;
+               } else if ($row['u_end_date'] && $row['u_end_date'] < time()) {
+                       $msg->addInfo(array('COURSE_ENDED', AT_Date(_AT('announcement_date_format'), $row['u_end_date'], AT_DATE_UNIX_TIMESTAMP)));
                }
 
                /* add member login to counter: */
@@ -313,7 +325,16 @@ switch ($row['access']){
                        exit;
                } else if ($row['u_release_date'] > time()) {
                        $msg->addInfo(array('COURSE_RELEASE', AT_Date(_AT('announcement_date_format'), $row['u_release_date'], AT_DATE_UNIX_TIMESTAMP)));
+
+               } else if ($row['u_end_date'] && ($row['u_end_date'] < time()) && !($_SESSION['is_admin'] || $_SESSION['privileges'])) {
+                       $msg->addError(array('COURSE_ENDED', AT_Date(_AT('announcement_date_format'), $row['u_end_date'], AT_DATE_UNIX_TIMESTAMP)));
+                       header('Location: '.AT_BASE_HREF.'bounce.php?course=0');
+                       exit;
+               } else if ($row['u_end_date'] && $row['u_end_date'] < time()) {
+                       $msg->addInfo(array('COURSE_ENDED', AT_Date(_AT('announcement_date_format'), $row['u_end_date'], AT_DATE_UNIX_TIMESTAMP)));
                }
+
+
                $_SESSION['course_title'] = $row['title'];
 
                /* update users_online  */
@@ -364,6 +385,8 @@ switch ($row['access']){
                        } /* else */
                        if ($row['u_release_date'] > time()) {
                                $msg->addInfo(array('COURSE_RELEASE', AT_Date(_AT('announcement_date_format'), $row['u_release_date'], AT_DATE_UNIX_TIMESTAMP)));
+                       } else if ($row['u_end_date'] && $row['u_end_date'] < time()) {
+                               $msg->addInfo(array('COURSE_ENDED', AT_Date(_AT('announcement_date_format'), $row['u_end_date'], AT_DATE_UNIX_TIMESTAMP)));
                        }
                        header('Location: ./'.$addslashes($page));
                        exit;
@@ -380,13 +403,19 @@ switch ($row['access']){
                        exit;
                } /* else */
 
-               if (($row['u_release_date'] > time()) && !$row2['privileges']) {
+               if (($row['u_release_date'] > time()) && !($_SESSION['is_admin'] || $_SESSION['privileges'])) {
                        $msg->addError(array('COURSE_NOT_RELEASED', AT_Date(_AT('announcement_date_format'), $row['u_release_date'], AT_DATE_UNIX_TIMESTAMP)));
-                       header('Location: '.$_AT_BASE_HREF.'bounce.php?course=0');
+                       header('Location: '.AT_BASE_HREF.'bounce.php?course=0');
                        exit;
                } else if ($row['u_release_date'] > time()) {
-                       // only instructor and TAs may view  a course before it is released.
                        $msg->addInfo(array('COURSE_RELEASE', AT_Date(_AT('announcement_date_format'), $row['u_release_date'], AT_DATE_UNIX_TIMESTAMP)));
+
+               } else if ($row['u_end_date'] && ($row['u_end_date'] < time()) && !($_SESSION['is_admin'] || $_SESSION['privileges'])) {
+                       $msg->addError(array('COURSE_ENDED', AT_Date(_AT('announcement_date_format'), $row['u_end_date'], AT_DATE_UNIX_TIMESTAMP)));
+                       header('Location: '.AT_BASE_HREF.'bounce.php?course=0');
+                       exit;
+               } else if ($row['u_end_date'] && $row['u_end_date'] < time()) {
+                       $msg->addInfo(array('COURSE_ENDED', AT_Date(_AT('announcement_date_format'), $row['u_end_date'], AT_DATE_UNIX_TIMESTAMP)));
                }
                /* we have requested or are enrolled in this course */
 
index cb40c82..6bd3b7a 100644 (file)
@@ -94,8 +94,32 @@ if (isset($_POST['form_course'])) {
                $row['release_date'] = 0;
        }
 
+       if (intval($_POST['end_date'])) {
+               $day_end        = intval($_POST['day_end']);
+               $month_end      = intval($_POST['month_end']);
+               $year_end       = intval($_POST['year_end']);
+               $hour_end       = intval($_POST['hour_end']);
+               $min_end        = intval($_POST['min_end']);
+
+               if (strlen($month_end) == 1){
+                       $month_end = "0$month_end";
+               }
+               if (strlen($day_end) == 1){
+                       $day_end = "0$day_end";
+               }
+               if (strlen($hour_end) == 1){
+                       $hour_end = "0$hour_end";
+               }
+               if (strlen($min_end) == 1){
+                       $min_end = "0$min_end";
+               }
+               $row['end_date'] = "$year_end-$month_end-$day_end $hour_end:$min_end:00";
+       } else {
+               $row['end_date'] = 0;
+       }
+
 } else if ($course) {
-       $sql    = "SELECT *, DATE_FORMAT(release_date, '%Y-%m-%d %H:%i:00') AS release_date FROM ".TABLE_PREFIX."courses WHERE course_id=$course";
+       $sql    = "SELECT *, DATE_FORMAT(release_date, '%Y-%m-%d %H:%i:00') AS release_date, DATE_FORMAT(end_date, '%Y-%m-%d %H:%i:00') AS end_date  FROM ".TABLE_PREFIX."courses WHERE course_id=$course";
        $result = mysql_query($sql, $db);
        if (!($row      = mysql_fetch_assoc($result))) {
                echo _AT('no_course_found');
@@ -116,6 +140,7 @@ if (isset($_POST['form_course'])) {
        $row['created_date']            = date('Y-m-d');
        $row['rss']                 = 0; // default to off
        $row['release_date']            = '0';
+       $row['end_date']            = '0';
 }
 /*
 if (($_POST['setvisual'] || $_POST['settext']) && !$_POST['submit']){
@@ -155,7 +180,6 @@ if (($_POST['setvisual'] || $_POST['settext']) && !$_POST['submit']){
                                echo '<span id="inst">'._AT('none_found').'</span>';
                        }
                        ?>
-               
        </div>
 <?php endif; ?>
 
@@ -295,6 +319,36 @@ if (($_POST['setvisual'] || $_POST['settext']) && !$_POST['submit']){
                ?>
        </div>
 
+       <div class="row">
+               <?php echo _AT('end_date'); ?><br />
+               <?php
+                       $end_no = $end_yes = '';
+
+                       if (intval($row['end_date'])) {
+                               $end_yes = ' checked="checked"';
+
+                               $today_day   = substr($row['end_date'], 8, 2);
+                               $today_mon   = substr($row['end_date'], 5, 2);
+                               $today_year  = substr($row['end_date'], 0, 4);
+
+                               $today_hour  = substr($row['end_date'], 11, 2);
+                               $today_min   = substr($row['end_date'], 14, 2);
+                       } else {
+                               $end_no = ' checked="checked"'; 
+                               $today_year  = date('Y')+1;
+                       }
+
+               ?>
+
+               <input type="radio" name="end_date" value="0" id="end_now" <?php echo $end_no; ?> /> <label for="end_now"><?php echo _AT('no_end_date'); ?></label><br />
+
+               <input type="radio" name="end_date" value="1" id="end_later" <?php echo $end_yes; ?> /> <label for="end_later"><?php echo _AT('end_on'); ?></label> 
+               <?php
+                       $name = '_end';
+                       require(AT_INCLUDE_PATH.'html/release_date.inc.php');
+               ?>
+       </div>
+
        <div class="row">
                <?php
                        if (($_POST['setvisual'] && !$_POST['settext']) || $_GET['setvisual']){
index 08444d9..1475d67 100644 (file)
@@ -84,6 +84,34 @@ function add_update_course($_POST, $isadmin = FALSE) {
                $release_date = "0000-00-00 00:00:00";
        }
 
+       if ($_POST['end_date']) {
+               $day_end        = intval($_POST['day_end']);
+               $month_end      = intval($_POST['month_end']);
+               $year_end       = intval($_POST['year_end']);
+               $hour_end       = intval($_POST['hour_end']);
+               $min_end        = intval($_POST['min_end']);
+
+               if (!checkdate($month_end, $day_end, $year_end)) { //or date is in the past
+                       $msg->addError('END_DATE_INVALID');
+               }
+
+               if (strlen($month_end) == 1){
+                       $month_end = "0$month_end";
+               }
+               if (strlen($day_end) == 1){
+                       $day_end = "0$day_end";
+               }
+               if (strlen($hour_end) == 1){
+                       $hour_end = "0$hour_end";
+               }
+               if (strlen($min_end) == 1){
+                       $min_end = "0$min_end";
+               }
+               $end_date = "$year_end-$month_end-$day_end $hour_end:$min_end:00";
+       } else {
+               $end_date = "0000-00-00 00:00:00";
+       }
+
        $initial_content_info = explode('_', $_POST['initial_content'], 2);
        //admin
        $course_quotas = '';
@@ -150,7 +178,7 @@ function add_update_course($_POST, $isadmin = FALSE) {
                $menu_defaults = ',home_links=\''.$system_courses[$_POST['course']]['home_links'].'\', main_links=\''.$system_courses[$_POST['course']]['main_links'].'\', side_menu=\''.$system_courses[$_POST['course']]['side_menu'].'\'';
        }
 
-       $sql    = "REPLACE INTO ".TABLE_PREFIX."courses SET course_id=$_POST[course], member_id='$_POST[instructor]', access='$_POST[access]', title='$_POST[title]', description='$_POST[description]', cat_id='$_POST[category_parent]', content_packaging='$_POST[content_packaging]', notify=$_POST[notify], hide=$_POST[hide], $course_quotas primary_language='$_POST[pri_lang]', created_date='$_POST[created_date]', rss=$_POST[rss], copyright='$_POST[copyright]', icon='$_POST[icon]', banner='$_POST[banner]', release_date='$release_date' $menu_defaults";
+       $sql    = "REPLACE INTO ".TABLE_PREFIX."courses SET course_id=$_POST[course], member_id='$_POST[instructor]', access='$_POST[access]', title='$_POST[title]', description='$_POST[description]', cat_id='$_POST[category_parent]', content_packaging='$_POST[content_packaging]', notify=$_POST[notify], hide=$_POST[hide], $course_quotas primary_language='$_POST[pri_lang]', created_date='$_POST[created_date]', rss=$_POST[rss], copyright='$_POST[copyright]', icon='$_POST[icon]', banner='$_POST[banner]', release_date='$release_date', end_date='$end_date' $menu_defaults";
 
        $result = mysql_query($sql, $db);
        if (!$result) {
index e69270c..11ca5bc 100644 (file)
@@ -13,7 +13,7 @@
 // $Id$
 if (!defined('AT_INCLUDE_PATH')) { exit; }
 
-define('AT_DEVEL', 0);
+define('AT_DEVEL', 1);
 define('AT_ERROR_REPORTING', E_ALL ^ E_NOTICE); // default is E_ALL ^ E_NOTICE, use E_ALL or E_ALL + E_STRICT for developing
 define('AT_DEVEL_TRANSLATE', 0);
 
@@ -903,6 +903,25 @@ function get_group_concat($table, $field, $where_clause = 1, $separator = ',') {
        return 0;
 }
 
+function get_human_time($seconds) {
+       if ($seconds < 0) { 
+               $out = '0'._AT('second_short'); 
+       } else if ($seconds > 60 * 60) { // more than 60 minutes.
+               $hours = floor($seconds / 60 / 60);
+               $minutes = floor(($seconds - $hours * 60 * 60) / 60);
+               $out = $hours ._AT('hour_short').' '.$minutes._AT('minute_short');
+
+               //$out = ($seconds
+       } else if ($seconds > 60) { // more than a minute
+               $minutes = floor($seconds / 60);
+               $out = $minutes ._AT('minute_short').' '.($seconds - $minutes * 60)._AT('second_short');
+       } else { // less than a minute
+               $out = $seconds . _AT('second_short');
+       }
+
+       return $out;
+}
+
 require(AT_INCLUDE_PATH . 'classes/Module/Module.class.php');
 
 $moduleFactory =& new ModuleFactory(TRUE); // TRUE is for auto_loading the module.php files
index 97e76b2..e04910c 100644 (file)
@@ -204,6 +204,7 @@ CREATE TABLE `courses` (
   `main_links` text NOT NULL ,
   `side_menu` VARCHAR( 255 ) NOT NULL default '',
   `release_date` datetime NOT NULL default '0000-00-00 00:00:00',
+  `end_date` datetime NOT NULL default '0000-00-00 00:00:00',
    `banner` TEXT NOT NULL ,
   PRIMARY KEY  (`course_id`)
 ) TYPE=MyISAM;
index ed16f3e..285977b 100644 (file)
@@ -14,3 +14,6 @@ UPDATE TABLE `tests_results` SET status=1, date_taken=date_taken;
 ## times tests - #3084
 ALTER TABLE `tests_results` ADD `end_time` TIMESTAMP NOT NULL ;
 UPDATE TABLE `tests_results` SET date_taken=date_taken, end_time=date_taken;
+
+## end date - #3089
+ALTER TABLE `courses` ADD `end_date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `release_date`;
index c80a28c..1b80453 100644 (file)
@@ -11,8 +11,6 @@
 /* as published by the Free Software Foundation.                               */
 /****************************************************************/
 // $Id$
-
-$page = 'my_courses';
 $_user_location        = 'users';
 define('AT_INCLUDE_PATH', '../include/');
 require(AT_INCLUDE_PATH.'vitals.inc.php');