move code up one directory
[atutor.git] / install / include / step3.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                                                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2010                                              */
6 /* http://atutor.ca                                                     */
7 /* This program is free software. You can redistribute it and/or        */
8 /* modify it under the terms of the GNU General Public License          */
9 /* as published by the Free Software Foundation.                        */
10 /************************************************************************/
11 // $Id$
12
13 if (!defined('AT_INCLUDE_PATH')) { exit; }
14
15 if(isset($_POST['submit']) && ($_POST['action'] == 'process')) {
16         unset($errors);
17
18         $_POST['admin_username'] = trim($_POST['admin_username']);
19         $_POST['admin_email']    = trim($_POST['admin_email']);
20         $_POST['site_name']      = trim($_POST['site_name']);
21         $_POST['home_url']           = trim($_POST['home_url']);
22         $_POST['email']          = trim($_POST['email']);
23         $_POST['account_email']  = trim($_POST['account_email']);
24         $_POST['account_fname']  = trim($_POST['account_fname']);
25         $_POST['account_lname']  = trim($_POST['account_lname']);
26
27         /* Super Administrator Account checking: */
28         if ($_POST['admin_username'] == ''){
29                 $errors[] = 'Administrator username cannot be empty.';
30         } else {
31                 /* check for special characters */
32                 if (!(preg_match("/^[a-zA-Z0-9_]([a-zA-Z0-9_])*$/i", $_POST['admin_username']))){
33                         $errors[] = 'Administrator username is not valid.';
34                 }
35         }
36         if ($_POST['form_admin_password_hidden'] == '') {
37                 $errors[] = 'Administrator password cannot be empty.';
38         }
39         if ($_POST['admin_email'] == '') {
40                 $errors[] = 'Administrator email cannot be empty.';
41         } else if (!preg_match("/^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,6}$/i", $_POST['admin_email'])) {
42                 $errors[] = 'Administrator email is not valid.';
43         }
44
45         /* System Preferences checking: */
46         if ($_POST['site_name'] == '') {
47                 $errors[] = 'Site name cannot be empty.';
48         }
49         if ($_POST['email'] == '') {
50                 $errors[] = 'Contact email cannot be empty.';
51         } else if (!preg_match("/^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,6}$/i", $_POST['email'])) {
52                 $errors[] = 'Contact email is not valid.';
53         }
54
55         /* Personal Account checking: */
56         if ($_POST['account_username'] == ''){
57                 $errors[] = 'Personal Account Username cannot be empty.';
58         } else {
59                 /* check for special characters */
60                 if (!(preg_match("/^[a-zA-Z0-9_]([a-zA-Z0-9_])*$/i", $_POST['account_username']))){
61                         $errors[] = 'Personal Account Username is not valid.';
62                 } else {
63                         if ($_POST['account_username'] == $_POST['admin_username']) {
64                                 $errors[] = 'That Personal Account Username is already being used for the Administrator account, choose another.';
65                         }
66                 }
67         }
68         if ($_POST['form_account_password_hidden'] == '') {
69                 $errors[] = 'Personal Account Password cannot be empty.';
70         }
71         if ($_POST['account_email'] == '') {
72                 $errors[] = 'Personal Account email cannot be empty.';
73         } else if (!preg_match("/^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,6}$/i", $_POST['account_email'])) {
74                 $errors[] = 'Invalid Personal Account email is not valid.';
75         }
76
77         if ($_POST['account_fname'] == '') {
78                 $errors[] = 'Personal Account First Name cannot be empty.';
79         }
80         if ($_POST['account_lname'] == '') {
81                 $errors[] = 'Personal Account Last Name cannot be empty.';
82         }
83         if (!isset($errors)) {
84                 $db = @mysql_connect($_POST['step2']['db_host'] . ':' . $_POST['step2']['db_port'], $_POST['step2']['db_login'], urldecode($_POST['step2']['db_password']));
85                 @mysql_select_db($_POST['step2']['db_name'], $db);
86
87                 $_POST['account_email'] = $addslashes($_POST['account_email']);
88                 $_POST['account_fname'] = $addslashes($_POST['account_fname']);
89                 $_POST['account_lname'] = $addslashes($_POST['account_lname']);
90
91                 $status = 3; // for instructor account
92
93                 $sql = "INSERT INTO ".$_POST['step2']['tb_prefix']."admins VALUES ('$_POST[admin_username]', '$_POST[form_admin_password_hidden]', '', '$_POST[admin_email]', 'en', 1, NOW())";
94                 $result= mysql_query($sql, $db);
95
96                 $sql = "INSERT INTO ".$_POST['step2']['tb_prefix']."members VALUES (NULL,'$_POST[account_username]','$_POST[form_account_password_hidden]','$_POST[account_email]','','$_POST[account_fname]','','$_POST[account_lname]','0000-00-00','n', '','','','','', '',$status,'', NOW(),'en', 0, 1, '0000-00-00 00:00:00')";
97                 $result = mysql_query($sql ,$db);
98
99                 $_POST['site_name'] = $addslashes($_POST['site_name']);
100                 $sql = "INSERT INTO ".$_POST['step2']['tb_prefix']."config VALUES ('site_name', '$_POST[site_name]')";
101                 $result = mysql_query($sql ,$db);
102
103                 $_POST['email'] = $addslashes($_POST['email']);
104                 $sql = "INSERT INTO ".$_POST['step2']['tb_prefix']."config VALUES ('contact_email', '$_POST[email]')";
105                 $result = mysql_query($sql ,$db);
106
107                 $_POST['home_url'] = $addslashes($_POST['home_url']);
108                 if ($_POST['home_url'] != '') {
109                         $sql = "INSERT INTO ".$_POST['step2']['tb_prefix']."config VALUES ('home_url', '$_POST[home_url]')";
110                         $result = mysql_query($sql ,$db);
111                 }
112
113                 $_POST['just_social'] = intval($_POST['just_social']);
114                 if ($_POST['just_social'] > 0){
115                         $sql = "INSERT INTO ".$_POST['step2']['tb_prefix']."config VALUES ('just_social', '1')";
116                         $result = mysql_query($sql ,$db);
117                 }
118
119                 //if fresh install, use SET NAME to set the mysql connection to UTF8
120                 $sql = "INSERT INTO ".$_POST['step2']['tb_prefix']."config VALUES ('set_utf8', '1')";
121                 mysql_query($sql ,$db);
122
123                 // Calculate the ATutor installation path and save into database for the usage of
124                 // session associated path @ include/vitals.inc.php
125                 $sql = "INSERT INTO ".$_POST['step2']['tb_prefix']."config VALUES ('session_path', '".get_atutor_installation_path(AT_INCLUDE_PATH)."')";
126                 mysql_query($sql ,$db);
127                 
128                 unset($_POST['admin_username']);
129                 unset($_POST['form_admin_password_hidden']);
130                 unset($_POST['admin_email']);
131                 unset($_POST['account_username']);
132                 unset($_POST['form_account_password_hidden']);
133                 unset($_POST['account_email']);
134                 unset($_POST['home_url']);
135                 unset($_POST['email']);
136                 unset($_POST['site_name']);
137                 unset($_POST['just_social']);
138
139                 unset($errors);
140                 unset($_POST['submit']);
141                 unset($action);
142                 store_steps($step);
143                 $step++;
144                 return;
145         }
146 }       
147
148 print_progress($step);
149
150 if (isset($errors)) {
151         print_errors($errors);
152 }
153
154 if (isset($_POST['step1']['old_version']) && $_POST['upgrade_action']) {
155         $defaults['admin_username'] = urldecode($_POST['step1']['admin_username']);
156         $defaults['admin_email']    = urldecode($_POST['step1']['admin_email']);
157
158         $defaults['site_name']   = urldecode($_POST['step1']['site_name']);
159         $defaults['header_img']  = urldecode($_POST['step1']['header_img']);
160         $defaults['header_logo'] = urldecode($_POST['step1']['header_logo']);
161         $defaults['home_url']    = urldecode($_POST['step1']['home_url']);
162 } else {
163         $defaults = $_defaults;
164 }
165
166 ?>
167 <script language="JavaScript" src="<?php echo AT_INCLUDE_PATH; ?>../../sha-1factory.js" type="text/javascript"></script>
168
169 <script type="text/javascript">
170 function encrypt_password()
171 {
172         document.form.form_admin_password_hidden.value = hex_sha1(document.form.admin_password.value);
173         document.form.form_account_password_hidden.value = hex_sha1(document.form.account_password.value);
174         document.form.admin_password.value = "";
175         document.form.account_password.value = "";
176 }
177 </script>
178
179 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
180         <input type="hidden" name="action" value="process" />
181         <input type="hidden" name="form_admin_password_hidden" value="" />
182         <input type="hidden" name="form_account_password_hidden" value="" />
183         <input type="hidden" name="step" value="<?php echo $step; ?>" />
184         <?php print_hidden($step); ?>
185
186         <?php
187                 /* detect mail settings. if sendmail_path is empty then use SMTP. */
188                 if (@ini_get('sendmail_path') == '') { 
189                         echo '<input type="hidden" name="smtp" value="true" />';
190                 } else {
191                         echo '<input type="hidden" name="smtp" value="false" />';
192                 }
193         ?>
194         <br />
195                 <table width="70%" class="tableborder" cellspacing="0" cellpadding="1" align="center">
196                 <tr>
197                         <th colspan="2">Super Administrator Account</th>
198                 </tr>
199                 <tr>
200                         <td colspan="2" class="row1">The Super Administrator account is used for managing ATutor. The Super Administrator can also create additional Administrators each with their own privileges and roles. Administrator accounts cannot enroll in courses.</td>
201                 </tr>
202                 <tr>
203                         <td class="row1"><span class="required" title="Required Field">*</span><b><label for="username">Administrator Username:</label></b><br />
204                         May contain only letters, numbers, or underscores.</td>
205                         <td class="row1"><input type="text" name="admin_username" id="username" maxlength="20" size="20" value="<?php if (!empty($_POST['admin_username'])) { echo stripslashes(htmlspecialchars($_POST['admin_username'])); } else { echo $defaults['admin_username']; } ?>" class="formfield" /></td>
206                 </tr>
207                 <tr>
208                         <td class="row1"><span class="required" title="Required Field">*</span><b><label for="password">Administrator Password:</label></b></td>
209                         <td class="row1"><input type="text" name="admin_password" id="password" maxlength="15" size="15" class="formfield" /></td>
210                 </tr>
211                 <tr>
212                         <td class="row1"><span class="required" title="Required Field">*</span><b><label for="email">Administrator Email:</label></b></td>
213                         <td class="row1"><input type="text" name="admin_email" id="email" size="40" value="<?php if (!empty($_POST['admin_email'])) { echo stripslashes(htmlspecialchars($_POST['admin_email'])); } else { echo $defaults['admin_email']; } ?>" class="formfield" /></td>
214                 </tr>
215                 </table>
216
217         <br />
218
219                 <table width="70%" class="tableborder" cellspacing="0" cellpadding="1" align="center">
220                 <tr>
221                         <th colspan="2">System Preferences</th>
222                 </tr>
223                 <tr>
224                         <td class="row1"><span class="required" title="Required Field">*</span><b><label for="sitename">Site Name:</label></b><br />
225                         The name of your course server website.<br />Default: <kbd><?php echo $defaults['site_name']; ?></kbd></td>
226                         <td class="row1"><input type="text" name="site_name" size="28" maxlength="60" id="sitename" value="<?php if (!empty($_POST['site_name'])) { echo stripslashes(htmlspecialchars($_POST['site_name'])); } else { echo $defaults['site_name']; } ?>" class="formfield" /></td>
227                 </tr>
228                 <tr>
229                         <td class="row1"><span class="required" title="Required Field">*</span><b><label for="cemail">Contact Email:</label></b><br />
230                         The email that will be used as the return email when needed.</td>
231                         <td class="row1"><input type="text" name="email" id="cemail" size="40" value="<?php if (!empty($_POST['email'])) { echo stripslashes(htmlspecialchars($_POST['email'])); } else { echo $defaults['email']; } ?>" class="formfield" /></td>
232                 </tr>
233                 <tr>                    
234                         <td class="row1"><span class="required" title="Required Field">*</span><b><label for="just_social">Just Social:</label></b><br />
235                         Deploy ATutor as just a Social Networking platform? (without LMS)</td>
236                         <td class="row1">
237                                 <label for="social_y">Just Social</label><input type="radio" name="just_social" id="social_y" value="1" class="formfield" <?php echo ($_POST['just_social']==1)?' checked="checked"':''; ?>/>
238                                 <label for="social_n">Social and LMS</label><input type="radio" name="just_social" id="social_n" value="0" class="formfield" <?php echo ($_POST['just_social']==0 || !isset($_POST['just_social']))?' checked="checked"':''; ?>/>
239                         </td>
240                 </tr>
241                 <tr>
242                         <td class="row1"><div class="optional" title="Optional Field">?</div><b><label for="home_url">Optional 'Home' URL:</label></b><br />
243                         This will be the URL for the 'Home' link in the Public Area. Leave empty to have this link not appear. <br /></td>
244                         <td class="row1"><input type="text" name="home_url" size="28" maxlength="60" id="home_url" value="<?php if (!empty($_POST['home_url'])) { echo stripslashes(htmlspecialchars($_POST['home_url'])); } else { echo $defaults['home_url']; } ?>" class="formfield" /></td>
245                 </tr>
246                 </table>
247
248         <br />
249
250                 <table width="70%" class="tableborder" cellspacing="0" cellpadding="1" align="center">
251                 <tr>
252                         <th colspan="2">Personal Account</th>
253                 </tr>
254                 <tr>
255                         <td colspan="2" class="row1">You will need a personal account to view and create courses.</td>
256                 </tr>
257                 <tr>
258                         <td class="row1"><span class="required" title="Required Field">*</span><b><label for="account_username">Username:</label></b><br />
259                         May contain only letters, numbers, and underscores.</td>
260                         <td class="row1"><input type="text" name="account_username" id="account_username" maxlength="20" size="20" value="<?php if (!empty($_POST['account_username'])) { echo stripslashes(htmlspecialchars($_POST['account_username'])); } ?>" class="formfield" /></td>
261                 </tr>
262                 <tr>
263                         <td class="row1"><span class="required" title="Required Field">*</span><b><label for="account_password">Password:</label></b></td>
264                         <td class="row1"><input type="text" name="account_password" id="account_password" maxlength="15" size="15" class="formfield" /></td>
265                 </tr>
266                 <tr>
267                         <td class="row1"><span class="required" title="Required Field">*</span><b><label for="account_email">Email:</label></b></td>
268                         <td class="row1"><input type="text" name="account_email" id="account_email" size="40" maxlength="60" value="<?php if (!empty($_POST['account_email'])) { echo stripslashes(htmlspecialchars($_POST['account_email'])); } ?>" class="formfield" /></td>
269                 </tr>
270                 <tr>
271                         <td class="row1"><span class="required" title="Required Field">*</span><b><label for="account_fname">First Name:</label></b></td>
272                         <td class="row1"><input type="text" name="account_fname" id="account_fname" size="40" maxlength="60" value="<?php if (!empty($_POST['account_fname'])) { echo stripslashes(htmlspecialchars($_POST['account_fname'])); } ?>" class="formfield" /></td>
273                 </tr>
274                 <tr>
275                         <td class="row1"><span class="required" title="Required Field">*</span><b><label for="account_lname">Last Name:</label></b></td>
276                         <td class="row1"><input type="text" name="account_lname" id="account_lname" size="40" maxlength="60" value="<?php if (!empty($_POST['account_lname'])) { echo stripslashes(htmlspecialchars($_POST['account_lname'])); } ?>" class="formfield" /></td>
277                 </tr>
278                 </table>
279         <br />
280         <br />
281         <div align="center"><input type="submit" class="button" value=" Next &raquo;" name="submit" onclick="return encrypt_password();" /></div>
282 </form>