remove old readme
[atutor.git] / mods / _core / properties / access.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                                                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2010                                              */
6 /* Inclusive Design Institute                                           */
7 /* http://atutor.ca                                                     */
8 /* This program is free software. You can redistribute it and/or        */
9 /* modify it under the terms of the GNU General Public License          */
10 /* as published by the Free Software Foundation.                        */
11 /************************************************************************/
12 // $Id$
13
14 define('AT_INCLUDE_PATH', '../../../include/');
15 require(AT_INCLUDE_PATH.'vitals.inc.php');
16 authenticate(AT_PRIV_ADMIN);
17
18 if (isset($_POST['regenerate'])) {
19         $password = strtoupper(substr(md5(rand()), 3, 8));
20
21         $sql = "UPDATE ".TABLE_PREFIX."course_access SET `password`='$password' WHERE course_id=".$_SESSION['course_id'];
22         $result = mysql_query($sql, $db);
23         if (!mysql_affected_rows($db)) {
24                 // conflict. try again
25                 $password = strtoupper(substr(md5(rand()), 2, 7));
26                 $sql = "UPDATE ".TABLE_PREFIX."course_access SET `password`='$password' WHERE course_id=".$_SESSION['course_id'];
27                 $result = mysql_query($sql, $db);
28         }
29
30         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
31         header('Location: '.$_SERVER['PHP_SELF']);
32         exit;
33 } else if (isset($_POST['cancel'])) {
34         $msg->addFeedback('CANCELLED');
35         header('Location: '.$_SERVER['PHP_SELF']);
36         exit;
37 } else if (isset($_POST['submit'])) {
38         $auth = intval($_POST['auth']);
39
40         //expiry date
41         if (intval($_POST['expiry_date'])) {
42                 $day_expire             = intval($_POST['day_expire']);
43                 $month_expire   = intval($_POST['month_expire']);
44                 $year_expire    = intval($_POST['year_expire']);
45                 $hour_expire    = intval($_POST['hour_expire']);
46                 $min_expire             = intval($_POST['min_expire']);
47
48                 if (strlen($month_expire) == 1){
49                         $month_expire = "0$month_expire";
50                 }
51                 if (strlen($day_expire) == 1){
52                         $day_expire = "0$day_expire";
53                 }
54                 if (strlen($hour_expire) == 1){
55                         $hour_expire = "0$hour_expire";
56                 }
57                 if (strlen($min_expire) == 1){
58                         $min_expire = "0$min_expire";
59                 }
60                 $expiry_date = "$year_expire-$month_expire-$day_expire $hour_expire:$min_expire:00";
61         } else {
62                 $expiry_date = 0;
63         }
64
65         $sql = "UPDATE ".TABLE_PREFIX."course_access SET `expiry_date`='$expiry_date', enabled=$auth WHERE course_id=".$_SESSION['course_id'];
66         $result = mysql_query($sql, $db);
67         
68         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
69         header('Location: '.$_SERVER['PHP_SELF']);
70         exit;
71 }
72
73 require(AT_INCLUDE_PATH.'header.inc.php'); 
74
75 if ($system_courses[$_SESSION['course_id']]['access'] == 'public') { 
76         // if this course is public, then we can't use this feature
77         echo '<div class="toolcontainer">';
78         $msg->printInfos('ACCESS_PUBLIC');
79         echo '</div>';
80         require(AT_INCLUDE_PATH.'footer.inc.php'); 
81         exit;
82 }
83
84 $sql = "SELECT password, expiry_date+0 AS expiry_date, enabled FROM ".TABLE_PREFIX."course_access WHERE course_id=".$_SESSION['course_id'];
85 $result = mysql_query($sql, $db);
86
87 if ($row = mysql_fetch_assoc($result)) {                
88         $enabled = $row['enabled'];
89         $password = $row['password'];
90         $expiry = $row['expiry_date'];
91 } else {
92         $enabled = 0;
93         $password = strtoupper(substr(md5(rand()), 3, 8));
94         $expiry = 0;
95         $sql = "INSERT INTO ".TABLE_PREFIX."course_access VALUES ('$password', {$_SESSION['course_id']},'0000-00-00 00:00:00', 0)";
96         $result = mysql_query($sql, $db);
97 }
98 $url = AT_BASE_HREF.'acl.php?'.$password;
99
100 ?>
101         <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
102                 <div class="input-form">
103                 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('regenerate'); ?></legend>
104                         <div class="row">                               
105                                 <?php echo _AT('auth_access_text'); ?>
106                         </div>
107                         <div class="row">
108                                 <?php echo _AT('url'); ?><br />
109                                 <kbd><?php echo $url; ?></kbd>
110                         </div>
111                         <div class="row buttons">
112                                 <input type="submit" name="regenerate" value="<?php echo _AT('regenerate'); ?>"  />
113                         </div>
114                 </fieldset>
115                 </div>
116
117                 <div class="input-form">
118                 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('authenticated_access'); ?></legend>
119                         <div class="row">
120                                 <?php echo _AT('authenticated_access'); ?><br />
121                                 <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> 
122                         </div>
123
124                         <div class="row">
125                                 <?php echo _AT('expiry_date'); ?><br />
126                                 <?php
127                                         $exp_no = $exp_yes = '';
128
129                                         if (intval($expiry)) {
130                                                 $exp_yes = ' checked="checked"';
131
132                                                 $today_day   = substr($expiry, 6, 2);
133                                                 $today_mon   = substr($expiry, 4, 2);
134                                                 $today_year  = substr($expiry, 0, 4);
135                                                 $today_hour  = substr($expiry, 8, 2);
136                                                 $today_min   = substr($expiry, 10, 2);
137
138                                         } else {
139                                                 $exp_no = ' checked="checked"'; 
140                                                 $today_day       = date('d');
141                                                 $today_mon       = date('m');
142                                                 $today_year  = date('Y');
143                                         }
144                                 ?>
145
146                                 <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 />
147
148                                 <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> 
149                                 <?php
150                                         $name = '_expire';
151                                         require(AT_INCLUDE_PATH.'html/release_date.inc.php');
152                                 ?>
153                         </div>
154
155                         <div class="row buttons">
156                                 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" /> 
157                                 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
158                         </div>
159                         </fieldset>
160                 </div>
161         </form>
162 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>