2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2002-2010 */
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 /************************************************************************/
13 if (!defined('AT_INCLUDE_PATH')) { exit; }
15 if (isset($_POST['submit'])) {
16 $_POST['content_dir'] = $stripslashes($_POST['content_dir']);
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>';
28 $_POST['content_dir'] = realpath(urldecode($_POST['content_dir']));
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.';
34 } else if (!is_writable($_POST['content_dir'].'/import')){
35 $errors[] = '<strong>'.$_POST['content_dir'].'/import</strong> directory is not writable.';
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.';
42 } else if (!is_writable($_POST['content_dir'].'/chat')){
43 $errors[] = '<strong>'.$_POST['content_dir'].'/chat</strong> directory is not writable.';
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.';
50 } else if (!is_writable($_POST['content_dir'].'/backups')){
51 $errors[] = '<strong>'.$_POST['content_dir'].'/backups</strong> directory is not writable.';
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.';
57 } else if (!is_writable($_POST['content_dir'].'/feeds')){
58 $errors[] = '<strong>'.$_POST['content_dir'].'/feeds</strong> directory is not writable.';
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.';
65 } else if (!is_writable($_POST['content_dir'].'/file_storage')){
66 $errors[] = '<strong>'.$_POST['content_dir'].'/file_storage</strong> directory is not writable.';
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.';
73 mkdir($_POST['content_dir'].'/profile_pictures/originals');
74 mkdir($_POST['content_dir'].'/profile_pictures/thumbs');
75 mkdir($_POST['content_dir'].'/profile_pictures/profile');
77 } else if (!is_writable($_POST['content_dir'].'/profile_pictures')){
78 $errors[] = '<strong>'.$_POST['content_dir'].'/profile_pictures</strong> directory is not writable.';
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.';
84 } else if (!is_writable($_POST['content_dir'].'/patcher')){
85 $errors[] = '<strong>'.$_POST['content_dir'].'/patcher</strong> directory is not writable.';
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.';
91 } else if (!is_writable($_POST['content_dir'].'/social')){
92 $errors[] = '<strong>'.$_POST['content_dir'].'/social</strong> directory is not writable.';
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.';
98 } else if (!is_writable($_POST['content_dir'].'/photos')){
99 $errors[] = '<strong>'.$_POST['content_dir'].'/photos</strong> directory is not writable.';
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.';
105 } else if (!is_writable($_POST['content_dir'].'/module')){
106 $errors[] = '<strong>'.$_POST['content_dir'].'/module</strong> directory is not writable.';
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.';
112 } else if (!is_writable($_POST['content_dir'].'/theme')){
113 $errors[] = '<strong>'.$_POST['content_dir'].'/theme</strong> directory is not writable.';
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');
126 if (!isset($errors)) {
128 unset($_POST['submit']);
131 if (substr($_POST['content_dir'], -1) !='\\'){
132 $_POST['content_dir'] .= DIRECTORY_SEPARATOR;
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']);
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']);
151 print_progress($step);
153 if (isset($errors)) {
154 print_errors($errors);
157 if (isset($_POST['step1']['old_version'])) {
158 //get real path to old content
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('../');
164 $path_info = pathinfo($old_config_cd);
165 $content_dir_name = $path_info['basename'];
167 if ($new_install . DIRECTORY_SEPARATOR . $content_dir_name . DIRECTORY_SEPARATOR == $old_config_cd) {
169 $copy_from = $old_install . DIRECTORY_SEPARATOR . $content_dir_name;
176 $_defaults['content_dir'] = $old_config_cd;
179 $defaults = $_defaults;
182 // the following code checks to see if get.php is being executed, then sets $_POST['get_file'] appropriately:
184 $path = substr($_SERVER['PHP_SELF'], 0, -strlen('install/install.php')) . 'get.php/?test';
185 $port = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : 80;
187 $host = parse_url($_SERVER['HTTP_HOST']);
189 if (isset($host['path'])) {
190 $host = $host['path'];
191 } else if (isset($host['host'])) {
192 $host = $host['host'];
194 $_SERVER['HTTP_HOST'];
197 // if we're using SSL, but don't know if support is compiled into PHP:
198 $fd = @fopen('https://'.$host.$path, 'rb');
202 $content = @fread($fd, filesize($filename));
206 if (strlen($content) == 0) {
207 $headers[] = 'ATutor-Get: OK';
212 $fp = @fsockopen($host, $port, $errno, $errstr, 15);
215 $head = 'HEAD '.@$path. " HTTP/1.0\r\nHost: ".@$host."\r\n\r\n";
218 if ($header = trim(fgets($fp, 1024))) {
219 $headers[] = $header;
224 if (in_array('ATutor-Get: OK', $headers)) {
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); ?>
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">
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>
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']; } ?>" />
249 <table width="80%" class="tableborder" cellspacing="0" cellpadding="1" align="center">
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>
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>
259 <table width="80%" class="tableborder" cellspacing="0" cellpadding="1" align="center">
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>
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>
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>
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>
272 <br /><br /><p align="center"><input type="submit" class="button" value=" Next »" name="submit" /></p>