remove old readme
[atutor.git] / install / include / step5.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'])) {
16         $_POST['content_dir'] = $stripslashes($_POST['content_dir']);
17
18         unset($errors);
19
20         if (!file_exists($_POST['content_dir']) || !realpath($_POST['content_dir'])) {
21                 $errors[] = '<strong>Content Directory</strong> entered does not exist.';
22         } else if (!is_dir($_POST['content_dir'])) {
23                 $errors[] = '<strong>Content Directory</strong> is not a directory.';
24         } else if (!is_writable($_POST['content_dir'])){
25                 $errors[] = 'The Content Directory is not writable. To make it writable, at the command prompt from within the ATutor directory enter the command <strong>chmod 2777 content</strong>';
26         } else {
27
28                 $_POST['content_dir'] = realpath(urldecode($_POST['content_dir']));
29
30                 if (!is_dir($_POST['content_dir'].'/import')) {
31                         if (!@mkdir($_POST['content_dir'].'/import')) {
32                                 $errors[] = '<strong>'.$_POST['content_dir'].'/import</strong> directory does not exist and cannot be created.';  
33                         }
34                 } else if (!is_writable($_POST['content_dir'].'/import')){
35                         $errors[] = '<strong>'.$_POST['content_dir'].'/import</strong> directory is not writable.';
36                 } 
37
38                 if (!is_dir($_POST['content_dir'].'/chat')) {
39                         if (!@mkdir($_POST['content_dir'].'/chat')) {
40                                 $errors[] = '<strong>'.$_POST['content_dir'].'/chat</strong> directory does not exist and cannot be created.';  
41                         }
42                 } else if (!is_writable($_POST['content_dir'].'/chat')){
43                         $errors[] = '<strong>'.$_POST['content_dir'].'/chat</strong> directory is not writable.';
44                 }
45
46                 if (!is_dir($_POST['content_dir'].'/backups')) {
47                         if (!@mkdir($_POST['content_dir'].'/backups')) {
48                                 $errors[] = '<strong>'.$_POST['content_dir'].'/backups</strong> directory does not exist and cannot be created.';  
49                         }
50                 } else if (!is_writable($_POST['content_dir'].'/backups')){
51                         $errors[] = '<strong>'.$_POST['content_dir'].'/backups</strong> directory is not writable.';
52                 }
53                 if (!is_dir($_POST['content_dir'].'/feeds')) {
54                         if (!@mkdir($_POST['content_dir'].'/feeds')) {
55                                 $errors[] = '<strong>'.$_POST['content_dir'].'/feeds</strong> directory does not exist and cannot be created.';  
56                         }
57                 } else if (!is_writable($_POST['content_dir'].'/feeds')){
58                         $errors[] = '<strong>'.$_POST['content_dir'].'/feeds</strong> directory is not writable.';
59                 }
60
61                 if (!is_dir($_POST['content_dir'].'/file_storage')) {
62                         if (!@mkdir($_POST['content_dir'].'/file_storage')) {
63                                 $errors[] = '<strong>'.$_POST['content_dir'].'/file_storage</strong> directory does not exist and cannot be created.';  
64                         }
65                 } else if (!is_writable($_POST['content_dir'].'/file_storage')){
66                         $errors[] = '<strong>'.$_POST['content_dir'].'/file_storage</strong> directory is not writable.';
67                 }
68
69                 if (!is_dir($_POST['content_dir'].'/profile_pictures')) {
70                         if (!@mkdir($_POST['content_dir'].'/profile_pictures')) {
71                                 $errors[] = '<strong>'.$_POST['content_dir'].'/profile_pictures</strong> directory does not exist and cannot be created.';  
72                         } else {
73                                 mkdir($_POST['content_dir'].'/profile_pictures/originals');
74                                 mkdir($_POST['content_dir'].'/profile_pictures/thumbs');
75                                 mkdir($_POST['content_dir'].'/profile_pictures/profile');
76                         }
77                 } else if (!is_writable($_POST['content_dir'].'/profile_pictures')){
78                         $errors[] = '<strong>'.$_POST['content_dir'].'/profile_pictures</strong> directory is not writable.';
79                 }
80                 if (!is_dir($_POST['content_dir'].'/patcher')) {
81                         if (!@mkdir($_POST['content_dir'].'/patcher')) {
82                                 $errors[] = '<strong>'.$_POST['content_dir'].'/patcher</strong> directory does not exist and cannot be created.';  
83                         }
84                 } else if (!is_writable($_POST['content_dir'].'/patcher')){
85                         $errors[] = '<strong>'.$_POST['content_dir'].'/patcher</strong> directory is not writable.';
86                 }
87                 if (!is_dir($_POST['content_dir'].'/social')) {
88                         if (!@mkdir($_POST['content_dir'].'/social')) {
89                                 $errors[] = '<strong>'.$_POST['content_dir'].'/social</strong> directory does not exist and cannot be created.';  
90                         }
91                 } else if (!is_writable($_POST['content_dir'].'/social')){
92                         $errors[] = '<strong>'.$_POST['content_dir'].'/social</strong> directory is not writable.';
93                 }
94                 if (!is_dir($_POST['content_dir'].'/photos')) {
95                         if (!@mkdir($_POST['content_dir'].'/photos')) {
96                                 $errors[] = '<strong>'.$_POST['content_dir'].'/photos</strong> directory does not exist and cannot be created.';  
97                         }
98                 } else if (!is_writable($_POST['content_dir'].'/photos')){
99                         $errors[] = '<strong>'.$_POST['content_dir'].'/photos</strong> directory is not writable.';
100                 }
101                 if (!is_dir($_POST['content_dir'].'/module')) {
102                         if (!@mkdir($_POST['content_dir'].'/module')) {
103                                 $errors[] = '<strong>'.$_POST['content_dir'].'/module</strong> directory does not exist and cannot be created.';  
104                         }
105                 } else if (!is_writable($_POST['content_dir'].'/module')){
106                         $errors[] = '<strong>'.$_POST['content_dir'].'/module</strong> directory is not writable.';
107                 }
108                 if (!is_dir($_POST['content_dir'].'/theme')) {
109                         if (!@mkdir($_POST['content_dir'].'/theme')) {
110                                 $errors[] = '<strong>'.$_POST['content_dir'].'/theme</strong> directory does not exist and cannot be created.';  
111                         }
112                 } else if (!is_writable($_POST['content_dir'].'/theme')){
113                         $errors[] = '<strong>'.$_POST['content_dir'].'/theme</strong> directory is not writable.';
114                 }
115
116                 // save blank index.html pages to those directories
117                 @copy('../images/index.html', $_POST['content_dir'] . '/import/index.html');
118                 @copy('../images/index.html', $_POST['content_dir'] . '/chat/index.html');
119                 @copy('../images/index.html', $_POST['content_dir'] . '/backups/index.html');
120                 @copy('../images/index.html', $_POST['content_dir'] . '/feeds/index.html');
121                 @copy('../images/index.html', $_POST['content_dir'] . '/file_storage/index.html');
122                 @copy('../images/index.html', $_POST['content_dir'] . '/profile_pictures/index.html');
123                 @copy('../images/index.html', $_POST['content_dir'] . '/index.html');
124         }
125
126         if (!isset($errors)) {
127                 unset($errors);
128                 unset($_POST['submit']);
129                 unset($action);
130
131                 if (substr($_POST['content_dir'], -1) !='\\'){
132                         $_POST['content_dir'] .= DIRECTORY_SEPARATOR;
133                 }
134
135                 // kludge to fix the missing slashes when magic_quotes_gpc is On
136                 if ($addslashes != 'mysql_real_escape_string') {
137                         $_POST['content_dir'] = addslashes($_POST['content_dir']);
138                 }
139
140                 store_steps($step);
141                 $step++;
142                 return;
143         } else {
144                 // kludge to fix the missing slashes when magic_quotes_gpc is On
145                 if ($addslashes != 'mysql_real_escape_string') {
146                         $_POST['content_dir'] = addslashes($_POST['content_dir']);
147                 }
148         }
149 }       
150
151 print_progress($step);
152
153 if (isset($errors)) {
154         print_errors($errors);
155 }
156
157 if (isset($_POST['step1']['old_version'])) {
158         //get real path to old content
159
160         $old_install   = realpath('../../' . DIRECTORY_SEPARATOR . $_POST['step1']['old_path']);
161         $old_config_cd = urldecode($_POST['step1']['content_dir']); // this path may not exist
162         $new_install   = realpath('../');
163
164         $path_info = pathinfo($old_config_cd);
165         $content_dir_name = $path_info['basename'];
166
167         if ($new_install . DIRECTORY_SEPARATOR . $content_dir_name . DIRECTORY_SEPARATOR == $old_config_cd) {
168                 // case 2
169                 $copy_from     = $old_install . DIRECTORY_SEPARATOR . $content_dir_name;
170         } else {
171                 // case 3 + 4
172                 // it's outside
173                 $copy_from = '';
174         }
175
176         $_defaults['content_dir'] = $old_config_cd;
177
178 } else {
179         $defaults = $_defaults;
180         $blurb = '';
181
182         // the following code checks to see if get.php is being executed, then sets $_POST['get_file'] appropriately:
183         $headers = array();
184         $path  = substr($_SERVER['PHP_SELF'], 0, -strlen('install/install.php')) . 'get.php/?test';
185         $port = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : 80;
186
187         $host = parse_url($_SERVER['HTTP_HOST']);
188
189         if (isset($host['path'])) {
190                 $host = $host['path'];
191         } else if (isset($host['host'])) {
192                 $host = $host['host'];
193         } else {
194                 $_SERVER['HTTP_HOST'];
195         }
196         if ($port == 443) {
197                 // if we're using SSL, but don't know if support is compiled into PHP:
198                 $fd = @fopen('https://'.$host.$path, 'rb');
199                 if ($fd === false) {
200                         $content = false;
201                 } else {
202                         $content = @fread($fd, filesize($filename));
203                         @fclose($fd);
204                 }
205
206                 if (strlen($content) == 0) {
207                         $headers[] = 'ATutor-Get: OK';
208                 } else {
209                         $headers[] = '';
210                 }
211         } else {
212                 $fp   = @fsockopen($host, $port, $errno, $errstr, 15);
213
214                 if($fp) {
215                         $head = 'HEAD '.@$path. " HTTP/1.0\r\nHost: ".@$host."\r\n\r\n";
216                         fputs($fp, $head);
217                         while(!feof($fp)) {
218                                 if ($header = trim(fgets($fp, 1024))) {
219                                         $headers[] = $header;
220                                 }
221                         }
222                 }
223         }
224         if (in_array('ATutor-Get: OK', $headers)) {
225                 $get_file = 'TRUE';
226         } else {
227                 $get_file = 'FALSE';
228         }
229 }
230
231 ?>
232 <br />
233 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
234         <input type="hidden" name="step" value="<?php echo $step; ?>" />
235         <input type="hidden" name="copy_from" value="<?php echo $copy_from; ?>" />
236         <input type="hidden" name="get_file" value="<?php echo $get_file; ?>" />
237         <?php print_hidden($step); ?>
238
239 <?php if (isset($_POST['step1']['old_version'])) : ?>
240         <input type="hidden" name="content_dir" value="<?php echo $_defaults['content_dir']; ?>" />
241         <table width="80%" class="tableborder" cellspacing="0" cellpadding="1" align="center">  
242         <tr>
243                 <td class="row1">The content directory at <strong><?php echo $_defaults['content_dir']; ?> </strong> will be used for this installation's content. Please create it if it does not already exist.</td>
244         </tr>
245         </table>
246 <?php elseif ($get_file == 'FALSE') : ?>
247         <input type="hidden" name="content_dir" value="<?php if (!empty($_POST['content_dir'])) { echo $_POST['content_dir']; } else { echo $_defaults['content_dir']; } ?>" />
248
249         <table width="80%" class="tableborder" cellspacing="0" cellpadding="1" align="center">  
250         <tr>
251                 <td class="row1"><span class="required" title="Required Field">*</span><strong><label for="contentdir">Content Directory</label></strong>
252                 <p>It has been detected that your webserver does not support the protected content directory feature. The content directory stores all of the courses' files.</p>
253                 <p>Due to that restriction your content directory must exist within your ATutor installation directory and cannot be moved. Its path is specified below. Please create it if it does not already exist.</p>
254                 <br /><br />
255                 <input type="text" name="content_dir_disabled" id="contentdir" value="<?php if (!empty($_POST['content_dir'])) { echo $_POST['content_dir']; } else { echo $_defaults['content_dir']; } ?>" class="formfield" size="70" disabled="disabled" /></td>
256         </tr>
257         </table>
258 <?php else: ?>
259         <table width="80%" class="tableborder" cellspacing="0" cellpadding="1" align="center">  
260         <tr>
261                 <td class="row1"><span class="required" title="Required Field">*</span><strong><label for="contentdir">Content Directory</label></strong>
262                 <p>Please specify where the content directory should be. The content directory stores all of the courses' files. As a security measure, the content directory should be placed <em>outside</em> of your ATutor installation (for example, to a non-web-accessible location that is not publically available).</p>
263                 
264                 <p>On a Windows machine, the path should look like <kbd>C:\content</kbd>, while on Unix it should look like <kbd>/var/content</kbd>.</p>
265                 
266                 <p>The directory you specify must be created if it does not already exist and be writeable by the webserver. On Unix machines issue the command <kbd>chmod 2777 content</kbd>. Also be sure the path may not contain any symbolic links.</p>
267
268                 <input type="text" name="content_dir" id="contentdir" value="<?php if (!empty($_POST['content_dir'])) { echo $_POST['content_dir']; } else { echo $_defaults['content_dir']; } ?>" class="formfield" size="70" /></td>
269         </tr>
270         </table>
271 <?php endif; ?>
272         <br /><br /><p align="center"><input type="submit" class="button" value=" Next &raquo;" name="submit" /></p>
273 </form>