move code up one directory
[atutor.git] / admin / config_edit.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 admin_authenticate(AT_ADMIN_PRIV_ADMIN);
17
18 global $stripslashes;
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['allow_registration']   = intval($_POST['allow_registration']);
38         $_POST['allow_browse']   = intval($_POST['allow_browse']);
39         $_POST['allow_instructor_registration']   = intval($_POST['allow_instructor_registration']);
40         $_POST['allow_unenroll']   = intval($_POST['allow_unenroll']);
41         $_POST['master_list']        = intval($_POST['master_list']);
42         $_POST['email_confirmation'] = intval($_POST['email_confirmation']);
43         $_POST['email_notification'] = intval($_POST['email_notification']);
44         $_POST['sent_msgs_ttl']      = intval($_POST['sent_msgs_ttl']);
45         $_POST['allow_instructor_requests'] = intval($_POST['allow_instructor_requests']);
46         $_POST['auto_approve_instructors']  = intval($_POST['auto_approve_instructors']);
47         $_POST['theme_categories']          = intval($_POST['theme_categories']);
48         $_POST['user_notes']                = intval($_POST['user_notes']);
49         $_POST['illegal_extentions']        = str_replace(array('  ', ' '), array(' ','|'), $_POST['illegal_extentions']);
50         $_POST['cache_dir']                 = trim($_POST['cache_dir']);
51         $_POST['latex_server']                          = (trim($_POST['latex_server'])==''?$_config['latex_server']:trim($_POST['latex_server']));
52         $_POST['course_backups']            = intval($_POST['course_backups']);
53         $_POST['course_backups']            = max(0, $_POST['course_backups']);
54         $_POST['check_version']             = $_POST['check_version'] ? 1 : 0;
55         $_POST['fs_versioning']             = $_POST['fs_versioning'] ? 1 : 0;
56         $_POST['enable_mail_queue']         = $_POST['enable_mail_queue'] ? 1 : 0;
57         $_POST['display_name_format']       = intval($_POST['display_name_format']);
58         $_POST['pretty_url']                            = intval($_POST['pretty_url']);
59         $_POST['course_dir_name']                       = intval($_POST['course_dir_name']);
60         $_POST['max_login']                                     = intval($_POST['max_login']);          //max login attempt
61         $_POST['use_captcha']                           = $_POST['use_captcha'] ? 1 : 0;
62
63         //apache_mod_rewrite can only be enabled if pretty_url is.
64         if ($_POST['pretty_url']==1){
65                 $_POST['apache_mod_rewrite']            = intval($_POST['apache_mod_rewrite']);
66         } else {
67                 $_POST['apache_mod_rewrite'] = 0;
68         }
69
70         if (!isset($display_name_formats[$_POST['display_name_format']])) {
71                 $_POST['display_name_format'] = $_config_defaults['display_name_format'];
72         }
73
74         //check that all values have been set   
75         if (!$_POST['site_name']) {
76                 $missing_fields[] = _AT('site_name');
77         }
78
79         /* email check */
80         if (!$_POST['contact_email']) {
81                 $missing_fields[] = _AT('contact_email');
82         } else if (!preg_match("/^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,6}$/i", $_POST['contact_email'])) {
83                 $msg->addError('EMAIL_INVALID');        
84         }
85
86         if ($_POST['cache_dir']) {
87                 if (!is_dir($_POST['cache_dir'])) {
88                         $msg->addError('CACHE_DIR_NOT_EXIST');
89                 } else if (!is_writable($_POST['cache_dir'])){
90                         $msg->addError('CACHE_DIR_NOT_WRITEABLE');
91                 }
92         }
93
94         if ($missing_fields) {
95                 $missing_fields = implode(', ', $missing_fields);
96                 $msg->addError(array('EMPTY_FIELDS', $missing_fields));
97         }
98
99         if (!$msg->containsErrors()) {
100                 $_POST['site_name']     = $addslashes($_POST['site_name']);
101                 $_POST['home_url']      = $addslashes($_POST['home_url']);
102                 $_POST['default_language']      = $addslashes($_POST['default_language']);
103                 $_POST['contact_email'] = $addslashes($_POST['contact_email']);
104                 $_POST['time_zone']     = floatval($_POST['time_zone']);
105
106                 foreach ($_config as $name => $value) {
107                         // the isset() is needed to avoid overridding settings that don't get set here (ie. modules)
108                         if (isset($_POST[$name]) && ($stripslashes($_POST[$name]) != $value) && ($stripslashes($_POST[$name]) != $_config_defaults[$name])) {
109                                 $sql = "REPLACE INTO ".TABLE_PREFIX."config VALUES ('$name', '$_POST[$name]')";
110                                 mysql_query($sql, $db);
111                                 write_to_log(AT_ADMIN_LOG_REPLACE, 'config', mysql_affected_rows($db), $sql);
112                         } else if (isset($_POST[$name]) && ($stripslashes($_POST[$name]) == $_config_defaults[$name])) {
113                                 $sql = "DELETE FROM ".TABLE_PREFIX."config WHERE name='$name'";
114                                 mysql_query($sql, $db);
115                                 write_to_log(AT_ADMIN_LOG_DELETE, 'config', mysql_affected_rows($db), $sql);
116                         }
117                 }
118
119                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
120
121                 // special case: disabling the mail queue should flush all queued mail:
122                 if (!$_POST['enable_mail_queue'] && $_POST['old_enable_mail_queue']) {
123                         require_once(AT_INCLUDE_PATH . 'classes/phpmailer/atutormailer.class.php');
124                         $mail = new ATutorMailer;
125                         $mail->SendQueue();
126                 }
127
128                 header('Location: '.$_SERVER['PHP_SELF']);
129                 exit;
130         }
131 }
132
133 $onload = 'document.form.sitename.focus();';
134
135 require(AT_INCLUDE_PATH.'header.inc.php');
136
137 if (!isset($_POST['submit'])) {
138
139 } else {
140         $defaults = $_POST;
141 }
142 ?>
143
144 <script type="text/javascript">
145         function apache_mod_rewrite_toggler(enabled){
146                 var obj_y = document.getElementById('mr_y');
147                 var obj_n = document.getElementById('mr_n');
148                 if(enabled==true) {
149                         obj_y.disabled = "";    
150                 } else if (enabled==false){
151                         obj_y.disabled = "disabled";
152                         obj_n.checked = "checked";
153                 }
154         }
155
156         //Validate apache_mod data
157         var pu_n = document.getElementById('pu_n');
158         var obj_y = document.getElementById('mr_y');
159         var obj_n = document.getElementById('mr_n');
160         if (pu_n.checked == true){
161                 obj_y.disabled = "disabled";
162                 obj_n.checked = "checked";
163         }
164 </script>
165
166
167 <?php 
168 $savant->assign('display_name_formats', $display_name_formats);
169 $savant->display('admin/system_preferences/config_edit.tmpl.php');
170 require(AT_INCLUDE_PATH.'footer.inc.php'); 
171 ?>