tagging as ATutor 1.5.4-release
[atutor.git] / admin / config_edit.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                                                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2006 by Greg Gay, Joel Kronenberg & Heidi Hazelton*/
6 /* Adaptive Technology Resource Centre / University of Toronto                  */
7 /* http://atutor.ca                                                                                                             */
8 /*                                                                                                                                              */
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 /************************************************************************/
13 // $Id$
14
15 define('AT_INCLUDE_PATH', '../include/');
16 require(AT_INCLUDE_PATH.'vitals.inc.php');
17 admin_authenticate(AT_ADMIN_PRIV_ADMIN);
18
19
20 if (isset($_POST['cancel'])) {
21         $msg->addFeedback('CANCELLED');
22         header('Location: index.php');
23         exit;
24 } else if (isset($_POST['submit'])) {
25         $missing_fields = array();
26
27         $_POST['site_name']          = trim($_POST['site_name']);
28         $_POST['home_url']           = trim($_POST['home_url']);
29         $_POST['default_language']   = trim($_POST['default_language']);
30         $_POST['contact_email']      = trim($_POST['contact_email']);
31         $_POST['max_file_size']      = intval($_POST['max_file_size']);
32         $_POST['max_file_size']      = max(0, $_POST['max_file_size']);
33         $_POST['max_course_size']    = intval($_POST['max_course_size']);
34         $_POST['max_course_size']    = max(0, $_POST['max_course_size']);
35         $_POST['max_course_float']   = intval($_POST['max_course_float']);
36         $_POST['max_course_float']   = max(0, $_POST['max_course_float']);
37         $_POST['master_list']        = intval($_POST['master_list']);
38         $_POST['email_confirmation'] = intval($_POST['email_confirmation']);
39         $_POST['email_notification'] = intval($_POST['email_notification']);
40         $_POST['sent_msgs_ttl']      = intval($_POST['sent_msgs_ttl']);
41         $_POST['allow_instructor_requests'] = intval($_POST['allow_instructor_requests']);
42         $_POST['auto_approve_instructors']  = intval($_POST['auto_approve_instructors']);
43         $_POST['theme_categories']          = intval($_POST['theme_categories']);
44         $_POST['user_notes']                = intval($_POST['user_notes']);
45         $_POST['illegal_extentions']        = str_replace(array('  ', ' '), array(' ','|'), $_POST['illegal_extentions']);
46         $_POST['cache_dir']                 = trim($_POST['cache_dir']);
47         $_POST['course_backups']            = intval($_POST['course_backups']);
48         $_POST['course_backups']            = max(0, $_POST['course_backups']);
49         $_POST['check_version']             = $_POST['check_version'] ? 1 : 0;
50         $_POST['fs_versioning']             = $_POST['fs_versioning'] ? 1 : 0;
51         $_POST['enable_mail_queue']         = $_POST['enable_mail_queue'] ? 1 : 0;
52         $_POST['display_name_format']       = intval($_POST['display_name_format']);
53
54         if (!isset($display_name_formats[$_POST['display_name_format']])) {
55                 $_POST['display_name_format'] = $_config_defaults['display_name_format'];
56         }
57
58         //check that all values have been set   
59         if (!$_POST['site_name']) {
60                 $missing_fields[] = _AT('site_name');
61         }
62
63         /* email check */
64         if (!$_POST['contact_email']) {
65                 $missing_fields[] = _AT('contact_email');
66         } else if (!eregi("^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,6}$", $_POST['contact_email'])) {
67                 $msg->addError('EMAIL_INVALID');        
68         }
69
70         if ($_POST['cache_dir']) {
71                 if (!is_dir($_POST['cache_dir'])) {
72                         $msg->addError('CACHE_DIR_NOT_EXIST');
73                 } else if (!is_writable($_POST['cache_dir'])){
74                         $msg->addError('CACHE_DIR_NOT_WRITEABLE');
75                 }
76         }
77
78         if ($missing_fields) {
79                 $missing_fields = implode(', ', $missing_fields);
80                 $msg->addError(array('EMPTY_FIELDS', $missing_fields));
81         }
82
83         if (!$msg->containsErrors()) {
84                 $_POST['site_name']     = $addslashes($_POST['site_name']);
85                 $_POST['home_url']      = $addslashes($_POST['home_url']);
86                 $_POST['default_language']      = $addslashes($_POST['default_language']);
87                 $_POST['contact_email'] = $addslashes($_POST['contact_email']);
88                 $_POST['time_zone']     = $addslashes($_POST['time_zone']);
89
90                 foreach ($_config as $name => $value) {
91                         // the isset() is needed to avoid overridding settings that don't get set here (ie. modules)
92                         if (isset($_POST[$name]) && (stripslashes($_POST[$name]) != $value) && (stripslashes($_POST[$name]) != $_config_defaults[$name])) {
93                                 $sql = "REPLACE INTO ".TABLE_PREFIX."config VALUES ('$name', '$_POST[$name]')";
94                                 mysql_query($sql, $db);
95                                 write_to_log(AT_ADMIN_LOG_REPLACE, 'config', mysql_affected_rows($db), $sql);
96                         } else if (isset($_POST[$name]) && (stripslashes($_POST[$name]) == $_config_defaults[$name])) {
97                                 $sql = "DELETE FROM ".TABLE_PREFIX."config WHERE name='$name'";
98                                 mysql_query($sql, $db);
99                                 write_to_log(AT_ADMIN_LOG_DELETE, 'config', mysql_affected_rows($db), $sql);
100                         }
101                 }
102
103                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
104
105                 // special case: disabling the mail queue should flush all queued mail:
106                 if (!$_POST['enable_mail_queue'] && $_POST['old_enable_mail_queue']) {
107                         require_once(AT_INCLUDE_PATH . 'classes/phpmailer/atutormailer.class.php');
108                         $mail = new ATutorMailer;
109                         $mail->SendQueue();
110                 }
111
112                 header('Location: '.$_SERVER['PHP_SELF']);
113                 exit;
114         }
115 }
116
117 $onload = 'document.form.sitename.focus();';
118
119 require(AT_INCLUDE_PATH.'header.inc.php');
120
121 if (!isset($_POST['submit'])) {
122
123 } else {
124         $defaults = $_POST;
125 }
126 ?>
127
128 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="form">
129 <div class="input-form">
130         <div class="row">
131                 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="sitename"><?php echo _AT('site_name'); ?></label><br />
132                 <input type="text" name="site_name" size="40" maxlength="60" id="sitename" value="<?php if (!empty($_POST['site_name'])) { echo $stripslashes(htmlspecialchars($_POST['site_name'])); } else { echo $_config['site_name']; } ?>" />
133         </div>
134
135         <div class="row">
136                 <label for="home_url"><?php echo _AT('home_url'); ?></label><br />
137
138                 <input type="text" name="home_url" size="50" maxlength="60" id="home_url" value="<?php if (!empty($_POST['home_url'])) { echo $stripslashes(htmlspecialchars($_POST['home_url'])); } else { echo $_config['home_url']; } ?>"  />
139         </div>
140
141         <div class="row">
142                 <label for="default_lang"><?php echo _AT('default_language'); ?></label><br />
143
144                 <?php if (!empty($_POST['default_language'])) { 
145                                 $select_lang = $_POST['default_language']; 
146                         } else { 
147                                 $select_lang = $_config['default_language'];
148                         } ?>
149                 <?php if ($disabled): ?>
150                         <select name="default_language" id="default_lang" disabled="disabled"><option><?php echo $select_lang; ?></option></select>
151                 <?php else: ?>
152                         <?php $languageManager->printDropdown($select_lang, 'default_language', 'default_lang'); ?>
153                 <?php endif; ?>
154         </div>
155
156         <div class="row">
157                 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="cemail"><?php echo _AT('contact_email'); ?></label><br />
158                 <input type="text" name="contact_email" id="cemail" size="40" value="<?php if (!empty($_POST['email'])) { echo $stripslashes(htmlspecialchars($_POST['email'])); } else { echo $_config['contact_email']; } ?>"  />
159         </div>
160
161         <div class="row">
162                 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="time_zone"><?php echo _AT('time_zone'); ?></label><br />
163                         <?php
164                                 $sql = "SELECT Name FROM mysql.time_zone_name ORDER BY Name";
165                                 $result = @mysql_query($sql, $db);
166                         ?>
167                         <?php if ($result && mysql_num_rows($result)): ?>
168                                 <select name="time_zone" id="time_zone">
169                                         <option value="" <?php if (!$_config['time_zone']) { echo 'selected="selected"'; } ?>><?php echo _AT('use_system_time'); ?></option>
170                                         <option value=""></option>
171                                         <?php while ($row = mysql_fetch_assoc($result)): ?>
172                                                 <option <?php if ($_config['time_zone'] == $row['Name']) { echo 'selected="selected"'; } ?>><?php echo $row['Name']; ?></option>
173                                         <?php endwhile; ?>
174                                 </select>
175                         <?php else: ?>
176                                 <?php echo _AT('time_zones_not_supported'); ?>
177                         <?php endif; ?>
178         </div>
179
180         <div class="row">
181                 <label for="maxfile"><?php echo _AT('maximum_file_size'); ?></label> (<?php echo _AT('default'); ?>: <?php echo $_config_defaults['max_file_size']; ?>)<br />
182                 <input type="text" size="10" name="max_file_size" id="maxfile" value="<?php if (!empty($_POST['max_file_size'])) { echo $stripslashes(htmlspecialchars($_POST['max_file_size'])); } else { echo $_config['max_file_size']; } ?>"  /> <?php echo _AT('bytes'); ?>
183         </div>
184
185         <div class="row">
186                 <label for="maxcourse"><?php echo _AT('maximum_course_size'); ?></label> (<?php echo _AT('default'); ?>: <?php echo $_config_defaults['max_course_size']; ?>)<br />
187                 <input type="text" size="10" name="max_course_size" id="maxcourse" value="<?php if (!empty($_POST['max_course_size'])) { echo $stripslashes(htmlspecialchars($_POST['max_course_size'])); } else { echo $_config['max_course_size']; } ?>"  /> <?php echo _AT('bytes'); ?>
188         </div>
189
190         <div class="row">
191                 <label for="float"><?php echo _AT('maximum_course_float'); ?></label> (<?php echo _AT('default'); ?>: <?php echo $_config_defaults['max_course_float']; ?>)<br />
192                 <input type="text" size="10" name="max_course_float" id="float" value="<?php if (!empty($_POST['max_course_float'])) { echo $stripslashes(htmlspecialchars($_POST['max_course_float'])); } else { echo $_config['max_course_float']; } ?>"  /> <?php echo _AT('bytes'); ?>
193         </div>
194
195         <div class="row">
196                 <?php echo _AT('display_name_format'); ?> (<?php echo _AT('default'); ?>: <em><?php echo _AT($display_name_formats[$_config_defaults['display_name_format']], _AT('login_name'), _AT('first_name'), _AT('second_name'), _AT('last_name')); ?></em>)<br />
197                 <?php foreach ($display_name_formats as $key => $value): ?>
198                         <input type="radio" name="display_name_format" value="<?php echo $key; ?>" id="dnf<?php echo $key; ?>" <?php if ($_config['display_name_format'] == $key) { echo 'checked="checked"'; }?> /><label for="dnf<?php echo $key; ?>"><em><?php echo _AT($value, _AT('login_name'), _AT('first_name'), _AT('second_name'), _AT('last_name')); ?></em></label><br />
199                 <?php endforeach; ?>
200         </div>
201
202         <div class="row">
203                 <?php echo _AT('master_list_authentication'); ?> (<?php echo _AT('default'); ?>: <?php echo ($_config_defaults['master_list'] ? _AT('enable') : _AT('disable')); ?>)<br />
204                 <input type="radio" name="master_list" value="1" id="ml_y" <?php if ($_config['master_list']) { echo 'checked="checked"'; }?>  /><label for="ml_y"><?php echo _AT('enable'); ?></label> 
205
206                 <input type="radio" name="master_list" value="0" id="ml_n" <?php if(!$_config['master_list']) { echo 'checked="checked"'; }?>  /><label for="ml_n"><?php echo $disable_on . _AT('disable') . $disable_off; ?></label>
207         </div>
208
209         <div class="row">
210                 <?php echo _AT('require_email_confirmation'); ?> (<?php echo _AT('default'); ?>: <?php echo ($_config_defaults['require_email_confirmation'] ? _AT('enable') : _AT('disable')); ?>)<br />
211                 <input type="radio" name="email_confirmation" value="1" id="ec_y" <?php if ($_config['email_confirmation']) { echo 'checked="checked"'; }?>  /><label for="ec_y"><?php echo _AT('enable'); ?></label> <input type="radio" name="email_confirmation" value="0" id="ec_n" <?php if(!$_config['email_confirmation']) { echo 'checked="checked"'; }?>  /><label for="ec_n"><?php echo _AT('disable'); ?></label>
212         </div>
213                 
214         <div class="row">
215                 <?php echo _AT('allow_instructor_requests'); ?> (<?php echo _AT('default'); ?>: <?php echo ($_config_defaults['allow_instructor_requests'] ? _AT('enable') : _AT('disable')); ?>)<br />
216                 <input type="radio" name="allow_instructor_requests" value="1" id="air_y" <?php if($_config['allow_instructor_requests']) { echo 'checked="checked"'; }?>  /><label for="air_y"><?php echo _AT('enable'); ?></label> <input type="radio" name="allow_instructor_requests" value="0" id="air_n" <?php if(!$_config['allow_instructor_requests']) { echo 'checked="checked"'; }?>  /><label for="air_n"><?php echo _AT('disable'); ?></label>
217         </div>
218
219         <div class="row">
220                 <?php echo _AT('instructor_request_email_notification'); ?> (<?php echo _AT('default'); ?>: <?php echo ($_config_defaults['email_notification'] ? _AT('enable') : _AT('disable')); ?>)<br />
221                 <input type="radio" name="email_notification" value="1" id="en_y" <?php if ($_config['email_notification']) { echo 'checked="checked"'; }?>  /><label for="en_y"><?php echo _AT('enable'); ?></label> <input type="radio" name="email_notification" value="0" id="en_n" <?php if(!$_config['email_notification']) { echo 'checked="checked"'; }?>  /><label for="en_n"><?php echo _AT('disable'); ?></label>
222         </div>
223
224         <div class="row">
225                 <?php echo _AT('auto_approve_instructors'); ?> (<?php echo _AT('default'); ?>: <?php echo ($_config_defaults['auto_approve_instructors'] ? _AT('enable') : _AT('disable')); ?>)<br />
226                 <input type="radio" name="auto_approve_instructors" value="1" id="aai_y" <?php if($_config['auto_approve_instructors']) { echo 'checked="checked"'; }?>  /><label for="aai_y"><?php echo _AT('enable'); ?></label> <input type="radio" name="auto_approve_instructors" value="0" id="aai_n" <?php if(!$_config['auto_approve_instructors']) { echo 'checked="checked"'; }?>  /><label for="aai_n"><?php echo _AT('disable'); ?></label>
227         </div>
228
229         <div class="row">
230                 <?php echo _AT('theme_specific_categories'); ?> (<?php echo _AT('default'); ?>: <?php echo ($_config_defaults['theme_categories'] ? _AT('enable') : _AT('disable')); ?>)<br />
231                 <input type="radio" name="theme_categories" value="1" id="tc_y" <?php if($_config['theme_categories']) { echo 'checked="checked"'; }?>  /><label for="tc_y"><?php echo _AT('enable'); ?></label> <input type="radio" name="theme_categories" value="0" id="tc_n" <?php if(!$_config['theme_categories']) { echo 'checked="checked"'; }?>  /><label for="tc_n"><?php echo _AT('disable'); ?></label>
232         </div>
233
234         <div class="row">
235                 <?php echo _AT('user_contributed_notes'); ?> (<?php echo _AT('default'); ?>: <?php echo ($_config_defaults['user_notes'] ? _AT('enable') : _AT('disable')); ?>)<br />
236                 <input type="radio" name="user_notes" value="1" id="un_y" <?php if($_config['user_notes']) { echo 'checked="checked"'; }?>  /><label for="un_y"><?php echo _AT('enable'); ?></label> <input type="radio" name="user_notes" value="0" id="un_n" <?php if(!$_config['user_notes']) { echo 'checked="checked"'; }?>  /><label for="un_n"><?php echo _AT('disable'); ?></label>
237         </div>
238
239         <div class="row">
240                 <label for="ext"><?php echo _AT('illegal_file_extensions'); ?></label><br />
241                 <textarea name="illegal_extentions" cols="24" id="ext" rows="2" class="formfield" ><?php if ($_config['illegal_extentions']) { echo str_replace('|',' ',$_config['illegal_extentions']); }?></textarea>
242         </div>
243
244         <div class="row">
245                 <label for="cache"><?php echo _AT('cache_directory'); ?></label><br />
246                 <input type="text" name="cache_dir" id="cache" size="40" value="<?php if (!empty($_POST['cache_dir'])) { echo $stripslashes(htmlspecialchars($_POST['cache_dir'])); } else { echo $_config['cache_dir']; } ?>"  />
247         </div>
248
249         <div class="row">
250                 <label for="course_backups"><?php echo _AT('course_backups'); ?></label> (<?php echo _AT('default'); ?>: <?php echo $_config_defaults['course_backups']; ?>)<br />
251                 <input type="text" size="2" name="course_backups" id="course_backups" value="<?php if (!empty($_POST['course_backups'])) { echo $stripslashes(htmlspecialchars($_POST['course_backups'])); } else { echo $_config['course_backups']; } ?>"  />
252         </div>
253
254         <div class="row">
255                 <label for="sent_msgs_ttl"><?php echo _AT('sent_msgs_ttl_text'); ?></label> (<?php echo _AT('default'); ?>: <?php echo $_config_defaults['sent_msgs_ttl']; ?>)<br />
256                 <input type="text" size="3" name="sent_msgs_ttl" id="sent_msgs_ttl" value="<?php if (!empty($_POST['sent_msgs_ttl'])) { echo intval($_POST['sent_msgs_ttl']); } else { echo $_config['sent_msgs_ttl']; } ?>"  />
257         </div>
258
259         <div class="row">
260                 <?php echo _AT('auto_check_new_version'); ?> (<?php echo _AT('default'); ?>: <?php echo ($_config_defaults['check_version'] ? _AT('enable') : _AT('disable')); ?>)<br />
261                 <input type="radio" name="check_version" value="1" id="cv_y" <?php if($_config['check_version']) { echo 'checked="checked"'; }?>  /><label for="cv_y"><?php echo _AT('enable'); ?></label> <input type="radio" name="check_version" value="0" id="cv_n" <?php if(!$_config['check_version']) { echo 'checked="checked"'; }?>  /><label for="cv_n"><?php echo _AT('disable'); ?></label>
262         </div>
263
264         <div class="row">
265                 <?php echo _AT('file_storage_version_control'); ?> (<?php echo _AT('default'); ?>: <?php echo ($_config_defaults['fs_versioning'] ? _AT('enable') : _AT('disable')); ?>)<br />
266                 <input type="radio" name="fs_versioning" value="1" id="cf_y" <?php if($_config['fs_versioning']) { echo 'checked="checked"'; }?>  /><label for="cf_y"><?php echo _AT('enable'); ?></label> <input type="radio" name="fs_versioning" value="0" id="cf_n" <?php if(!$_config['fs_versioning']) { echo 'checked="checked"'; }?>  /><label for="cf_n"><?php echo _AT('disable'); ?></label>
267         </div>
268
269         <div class="row">
270                 <input type="hidden" name="old_enable_mail_queue" value="<?php echo $_config['enable_mail_queue']; ?>" />
271                 <?php echo _AT('enable_mail_queue'); ?> (<?php echo _AT('default'); ?>: <?php echo ($_config_defaults['enable_mail_queue'] ? _AT('enable') : _AT('disable')); ?>)<br />
272                 <?php echo _AT('mail_queue_cron'); ?><br />
273                 <?php if (!$_config['last_cron'] || (time() - (int) $_config['last_cron'] > 2 * 60 * 60)): ?>
274                         <input type="radio" name="enable_mail_queue" value="1" disabled="disabled" /><?php echo _AT('enable'); ?> <input type="radio" name="enable_mail_queue" value="0" id="mq_n" checked="checked" /><label for="mq_n"><?php echo _AT('disable'); ?></label>
275                 <?php else: ?>
276                         <input type="radio" name="enable_mail_queue" value="1" id="mq_y" <?php if($_config['enable_mail_queue']) { echo 'checked="checked"'; }?>  /><label for="mq_y"><?php echo _AT('enable'); ?></label> <input type="radio" name="enable_mail_queue" value="0" id="mq_n" <?php if(!$_config['enable_mail_queue']) { echo 'checked="checked"'; }?>  /><label for="mq_n"><?php echo _AT('disable'); ?></label>
277                 <?php endif; ?>
278         </div>
279
280         <div class="row">
281                 <?php echo _AT('auto_install_languages'); ?> (<?php echo _AT('default'); ?>: <?php echo ($_config_defaults['auto_install_languages'] ? _AT('enable') : _AT('disable')); ?>)<br />
282                 <?php echo _AT('auto_install_languages_cron'); ?><br />
283                 <?php if (!$_config['last_cron'] || (time() - (int) $_config['last_cron'] > 2 * 60 * 60)): ?>
284                         <input type="radio" name="auto_install_languages" value="1" disabled="disabled" /><?php echo _AT('enable'); ?> <input type="radio" name="auto_install_languages" value="0" id="ai_n" checked="checked" /><label for="ai_n"><?php echo _AT('disable'); ?></label>
285                 <?php else: ?>
286                         <input type="radio" name="auto_install_languages" value="1" id="ai_y" <?php if($_config['auto_install_languages']) { echo 'checked="checked"'; }?>  /><label for="ai_y"><?php echo _AT('enable'); ?></label> <input type="radio" name="auto_install_languages" value="0" id="ai_n" <?php if(!$_config['auto_install_languages']) { echo 'checked="checked"'; }?>  /><label for="ai_n"><?php echo _AT('disable'); ?></label>
287                 <?php endif; ?>
288         </div>
289
290         <div class="row buttons">
291                         <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s"  />
292                 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>"  />
293         </div>
294 </div>
295 </form>
296
297 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>