2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2002-2007 by Greg Gay, Joel Kronenberg & Heidi Hazelton*/
6 /* Adaptive Technology Resource Centre / University of Toronto */
9 /* This program is free software. You can redistribute it and/or */
10 /* modify it under the terms of the GNU General Public License */
11 /* as published by the Free Software Foundation. */
12 /************************************************************************/
15 define('AT_INCLUDE_PATH', '../include/');
16 require(AT_INCLUDE_PATH.'vitals.inc.php');
17 authenticate(AT_PRIV_ADMIN);
19 if (isset($_POST['regenerate'])) {
20 $password = strtoupper(substr(md5(rand()), 3, 8));
22 $sql = "UPDATE ".TABLE_PREFIX."course_access SET `password`='$password' WHERE course_id=".$_SESSION['course_id'];
23 $result = mysql_query($sql, $db);
24 if (!mysql_affected_rows($db)) {
25 // conflict. try again
26 $password = strtoupper(substr(md5(rand()), 2, 7));
27 $sql = "UPDATE ".TABLE_PREFIX."course_access SET `password`='$password' WHERE course_id=".$_SESSION['course_id'];
28 $result = mysql_query($sql, $db);
31 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
32 header('Location: '.$_SERVER['PHP_SELF']);
34 } else if (isset($_POST['cancel'])) {
35 $msg->addFeedback('CANCELLED');
36 header('Location: '.$_SERVER['PHP_SELF']);
38 } else if (isset($_POST['submit'])) {
39 $auth = intval($_POST['auth']);
42 if (intval($_POST['expiry_date'])) {
43 $day_expire = intval($_POST['day_expire']);
44 $month_expire = intval($_POST['month_expire']);
45 $year_expire = intval($_POST['year_expire']);
46 $hour_expire = intval($_POST['hour_expire']);
47 $min_expire = intval($_POST['min_expire']);
49 if (strlen($month_expire) == 1){
50 $month_expire = "0$month_expire";
52 if (strlen($day_expire) == 1){
53 $day_expire = "0$day_expire";
55 if (strlen($hour_expire) == 1){
56 $hour_expire = "0$hour_expire";
58 if (strlen($min_expire) == 1){
59 $min_expire = "0$min_expire";
61 $expiry_date = "$year_expire-$month_expire-$day_expire $hour_expire:$min_expire:00";
66 $sql = "UPDATE ".TABLE_PREFIX."course_access SET `expiry_date`='$expiry_date', enabled=$auth WHERE course_id=".$_SESSION['course_id'];
67 $result = mysql_query($sql, $db);
69 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
70 header('Location: '.$_SERVER['PHP_SELF']);
74 require(AT_INCLUDE_PATH.'header.inc.php');
76 if ($system_courses[$_SESSION['course_id']]['access'] == 'public') {
77 // if this course is public, then we can't use this feature
78 $msg->printInfos('ACCESS_PUBLIC');
79 require(AT_INCLUDE_PATH.'footer.inc.php');
83 $sql = "SELECT password, expiry_date+0 AS expiry_date, enabled FROM ".TABLE_PREFIX."course_access WHERE course_id=".$_SESSION['course_id'];
84 $result = mysql_query($sql, $db);
86 if ($row = mysql_fetch_assoc($result)) {
87 $enabled = $row['enabled'];
88 $password = $row['password'];
89 $expiry = $row['expiry_date'];
92 $password = strtoupper(substr(md5(rand()), 3, 8));
94 $sql = "INSERT INTO ".TABLE_PREFIX."course_access VALUES ('$password', {$_SESSION['course_id']},'0000-00-00 00:00:00', 0)";
95 $result = mysql_query($sql, $db);
97 $url = AT_BASE_HREF.'acl.php?'.$password;
100 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
101 <div class="input-form">
103 <?php echo _AT('auth_access_text'); ?>
106 <?php echo _AT('url'); ?><br />
107 <kbd><?php echo $url; ?></kbd>
109 <div class="row buttons">
110 <input type="submit" name="regenerate" value="<?php echo _AT('regenerate'); ?>" />
114 <div class="input-form">
116 <?php echo _AT('authenticated_access'); ?><br />
117 <input type="radio" name="auth" id="enable" value="1" <?php if($enabled) { echo 'checked="checked"'; } ?> /> <label for="enable"><?php echo _AT('enable'); ?></label> <input type="radio" name="auth" id="disable" value="0" <?php if(!$enabled) { echo 'checked="checked"'; } ?> /> <label for="disable"><?php echo _AT('disable'); ?></label>
121 <?php echo _AT('expiry_date'); ?><br />
123 $exp_no = $exp_yes = '';
125 if (intval($expiry)) {
126 $exp_yes = ' checked="checked"';
128 $today_day = substr($expiry, 6, 2);
129 $today_mon = substr($expiry, 4, 2);
130 $today_year = substr($expiry, 0, 4);
131 $today_hour = substr($expiry, 8, 2);
132 $today_min = substr($expiry, 10, 2);
135 $exp_no = ' checked="checked"';
136 $today_day = date('d');
137 $today_mon = date('m');
138 $today_year = date('Y');
142 <input type="radio" name="expiry_date" value="0" id="expire_never" <?php echo $exp_no; ?> /> <label for="expire_never"><?php echo _AT('expire_never'); ?></label><br />
144 <input type="radio" name="expiry_date" value="1" id="expire_on" <?php echo $exp_yes; ?> /> <label for="expire_on"><?php echo _AT('expire_on'); ?></label>
147 require(AT_INCLUDE_PATH.'html/release_date.inc.php');
151 <div class="row buttons">
152 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" />
153 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
157 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>