diff options
Diffstat (limited to 'series/trunk/install.php')
-rw-r--r-- | series/trunk/install.php | 260 |
1 files changed, 0 insertions, 260 deletions
diff --git a/series/trunk/install.php b/series/trunk/install.php deleted file mode 100644 index 905344b..0000000 --- a/series/trunk/install.php +++ /dev/null | |||
@@ -1,260 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /* InstaDisc Series - A Four Island Project */ | ||
4 | |||
5 | if (!isset($_GET['submit'])) | ||
6 | { | ||
7 | showHeader('1'); | ||
8 | showStepOne('localhost', 'root', '', 'instadisc', array()); | ||
9 | } else { | ||
10 | $numOfErrors = 0; | ||
11 | $errors = array(); | ||
12 | |||
13 | switch ($_GET['submit']) | ||
14 | { | ||
15 | case 1: | ||
16 | if ($_POST['host'] == '') | ||
17 | { | ||
18 | addError($numOfErrors, $errors, 'host', 'Hostname is a required field'); | ||
19 | } | ||
20 | |||
21 | if ($_POST['username'] == '') | ||
22 | { | ||
23 | addError($numOfErrors, $errors, 'username', 'Username is a required field'); | ||
24 | } | ||
25 | |||
26 | if ($_POST['password'] == '') | ||
27 | { | ||
28 | addError($numOfErrors, $errors, 'password', 'Password is a required field'); | ||
29 | } | ||
30 | |||
31 | if ($_POST['dbname'] == '') | ||
32 | { | ||
33 | addError($numOfErrors, $errors, 'dbname', 'Name is a required field'); | ||
34 | } | ||
35 | |||
36 | if ($numOfErrors > 0) | ||
37 | { | ||
38 | showHeader('1'); | ||
39 | showStepOne($_POST['host'], $_POST['username'], $_POST['password'], $_POST['dbname'], $errors); | ||
40 | } else { | ||
41 | if (!@mysql_connect($_POST['host'], $_POST['username'], $_POST['password'])) | ||
42 | { | ||
43 | addError($numOfErrors, $errors, '', 'Cannot connect to database server'); | ||
44 | showHeader('1'); | ||
45 | showStepOne($_POST['host'], $_POST['username'], $_POST['password'], $_POST['dbname'], $errors); | ||
46 | } else { | ||
47 | if (!@mysql_select_db($_POST['dbname'])) | ||
48 | { | ||
49 | addError($numOfErrors, $errors, 'dbname', 'Database does not exist'); | ||
50 | showHeader('1'); | ||
51 | showStepOne($_POST['host'], $_POST['username'], $_POST['password'], $_POST['dbname'], $errors); | ||
52 | } else { | ||
53 | $sql = file_get_contents('instadisc.sql'); | ||
54 | $makedb = split(';', $sql); | ||
55 | foreach ($makedb as $name => $value) | ||
56 | { | ||
57 | if (!trim($value) == '') | ||
58 | { | ||
59 | $makedb2 = @mysql_query($value); | ||
60 | if (!$makedb2) | ||
61 | { | ||
62 | addError($numOfErrors, $errors, '', "MySQL error \"" . mysql_error() . "\" while creating database"); | ||
63 | } | ||
64 | } | ||
65 | } | ||
66 | |||
67 | @file_put_contents('includes/config.php', "<?php\n\n/* InstaDisc Server - A Four Island Project */\n\n\$dbhost = \"" . $_POST['host'] . "\";\n\$dbuser = \"" . $_POST['username'] . "\";\n\$dbpass = \"" . $_POST['password'] . "\";\n\$dbname = \"" . $_POST['dbname'] . "\";\n\n?>"); | ||
68 | |||
69 | if (!file_exists('includes/config.php')) | ||
70 | { | ||
71 | addError($numOfErrors, $errors, '', 'Could not write config.php file, please check directory permissions'); | ||
72 | } | ||
73 | |||
74 | if ($numOfErrors > 0) | ||
75 | { | ||
76 | showHeader('1'); | ||
77 | showStepOne($_POST['host'], $_POST['username'], $_POST['password'], $_POST['dbname'], $errors); | ||
78 | } else { | ||
79 | showHeader('2'); | ||
80 | showStepTwo('', '', '', array()); | ||
81 | } | ||
82 | } | ||
83 | } | ||
84 | } | ||
85 | |||
86 | break; | ||
87 | |||
88 | case 2: | ||
89 | if ($_POST['siteName'] == '') | ||
90 | { | ||
91 | addError($numOfErrors, $errors, 'siteName', 'Site Name is a required field'); | ||
92 | } | ||
93 | |||
94 | if ($_POST['adminUser'] == '') | ||
95 | { | ||
96 | addError($numOfErrors, $errors, 'adminUser', 'Administrator Username is a required field'); | ||
97 | } | ||
98 | |||
99 | if ($_POST['adminPass'] == '') | ||
100 | { | ||
101 | addError($numOfErrors, $errors, 'adminPass', 'Administrator Password is a required field'); | ||
102 | } | ||
103 | |||
104 | if ($numOfErrors > 0) | ||
105 | { | ||
106 | showHeader('2'); | ||
107 | showStepTwo($_POST['siteName'], $_POST['adminUser'], $_POST['adminPass'], $errors); | ||
108 | } else { | ||
109 | include_once('includes/config.php'); | ||
110 | |||
111 | mysql_connect($dbhost, $dbuser, $dbpass); | ||
112 | mysql_select_db($dbname); | ||
113 | |||
114 | $sql[0] = "INSERT INTO config (name,value) VALUES (\"siteName\",\"" . mysql_real_escape_string($_POST['siteName']) . "\")"; | ||
115 | $sql[1] = "INSERT INTO config (name,value) VALUES (\"adminUser\",\"" . mysql_real_escape_string($_POST['adminUser']) . "\")"; | ||
116 | $sql[2] = "INSERT INTO users (username,password) VALUES (\"" . mysql_real_escape_string($_POST['adminUser']) . "\",\"" . mysql_real_escape_string(md5($_POST['adminPass'])) . "\")"; | ||
117 | |||
118 | foreach ($sql as $name => $value) | ||
119 | { | ||
120 | if (!trim($value) == '') | ||
121 | { | ||
122 | $sql2 = @mysql_query($value); | ||
123 | if (!$sql2) | ||
124 | { | ||
125 | addError($numOfErrors, $errors, '', "MySQL error \"" . mysql_error() . "\" while filling database"); | ||
126 | } | ||
127 | } | ||
128 | } | ||
129 | |||
130 | if ($numOfErrors > 0) | ||
131 | { | ||
132 | showHeader('2'); | ||
133 | showStepTwo($_POST['siteName'], $_POST['adminUser'], $_POST['adminPass'], $errors); | ||
134 | } else { | ||
135 | showHeader('3'); | ||
136 | showStepThree(); | ||
137 | } | ||
138 | } | ||
139 | |||
140 | break; | ||
141 | } | ||
142 | } | ||
143 | |||
144 | ?><P><CENTER><SMALL><SMALL>InstaDisc (C) Starla Insigna 2008. InstaDisc Setup uses the UniForm form theme</SMALL></SMALL></CENTER></BODY></HTML><?php | ||
145 | |||
146 | function showHeader($number) | ||
147 | { | ||
148 | ?><HTML><HEAD><TITLE>InstaDisc Series Setup Step <?php echo($number); ?></TITLE><LINK REL="stylesheet" TYPE="text/css" HREF="theme/uniform.css"></HEAD><BODY><CENTER><H1>InstaDisc Installation</H1></CENTER><P><?php | ||
149 | } | ||
150 | |||
151 | function showStepOne($host, $username, $password, $dbname, $errors) | ||
152 | { | ||
153 | ?>Welcome to the InstaDisc Series Control installation! Please input your database details below.<P> | ||
154 | <FORM CLASS="uniform" ACTION="./install.php?submit=1" METHOD="POST"> | ||
155 | <?php | ||
156 | if (isset($errors[1])) | ||
157 | { | ||
158 | ?><DIV ID="errorMsg">Uh oh! Validation errors!<P> | ||
159 | <OL><?php | ||
160 | foreach ($errors as $name => $value) | ||
161 | { | ||
162 | ?><LI><A HREF="#error<?php echo($name); ?>"><?php echo($value['msg']); ?></A></LI><?php | ||
163 | } | ||
164 | ?></OL></DIV><?php | ||
165 | } | ||
166 | ?> | ||
167 | <FIELDSET CLASS="inlineLabels"><LEGEND>Database Details</LEGEND> | ||
168 | <DIV CLASS="ctrlHolder<?php ifErrors($errors, 'host'); ?>"> | ||
169 | <?php doErrors($errors, 'host'); ?> <LABEL FOR="host"><EM>*</EM> Host: </LABEL> | ||
170 | <INPUT TYPE="text" ID="host" NAME="host" CLASS="textInput" VALUE="<?php echo($host); ?>"> | ||
171 | </DIV> | ||
172 | <DIV CLASS="ctrlHolder<?php ifErrors($errors, 'username'); ?>"> | ||
173 | <?php doErrors($errors, 'username'); ?> <LABEL FOR="username"><EM>*</EM> Username: </LABEL> | ||
174 | <INPUT TYPE="text" ID="username" NAME="username" CLASS="textInput" VALUE="<?php echo($username); ?>"> | ||
175 | </DIV> | ||
176 | <DIV CLASS="ctrlHolder<?php ifErrors($errors, 'password'); ?>"> | ||
177 | <?php doErrors($errors, 'password'); ?> <LABEL FOR="password"><EM>*</EM> Password: </LABEL> | ||
178 | <INPUT TYPE="password" ID="password" NAME="password" CLASS="textInput" VALUE="<?php echo($password); ?>"> | ||
179 | </DIV> | ||
180 | <DIV CLASS="ctrlHolder<?php ifErrors($errors, 'dbname'); ?>"> | ||
181 | <?php doErrors($errors, 'dbname'); ?> <LABEL FOR="dbname"><EM>*</EM> Name: </LABEL> | ||
182 | <INPUT TYPE="text" ID="dbname" NAME="dbname" CLASS="textInput" VALUE="<?php echo($dbname); ?>"> | ||
183 | <P CLASS="formHint">You need to create this database before running this script.</P> | ||
184 | </DIV> | ||
185 | </FIELDSET> | ||
186 | <DIV CLASS="buttonHolder"> | ||
187 | <INPUT TYPE="submit" VALUE="Next"> | ||
188 | </DIV></FORM><?php | ||
189 | } | ||
190 | |||
191 | function showStepTwo($siteName, $adminUser, $adminPass, $errors) | ||
192 | { | ||
193 | ?>Your database has been set up. All we need to do now is fill it up a little. Please answer the below questions to set up your configuration: | ||
194 | <FORM CLASS="uniform" ACTION="./install.php?submit=2" METHOD="POST"> | ||
195 | <?php | ||
196 | if (isset($errors[1])) | ||
197 | { | ||
198 | ?><DIV ID="errorMsg">Uh oh! Validation errors!<P> | ||
199 | <OL><?php | ||
200 | foreach ($errors as $name => $value) | ||
201 | { | ||
202 | ?><LI><A HREF="#error<?php echo($name); ?>"><?php echo($value['msg']); ?></A></LI><?php | ||
203 | } | ||
204 | ?></OL></DIV><?php | ||
205 | } | ||
206 | ?> | ||
207 | <FIELDSET CLASS="inlineLabels"><LEGEND>Website</LEGEND> | ||
208 | <DIV CLASS="ctrlHolder<?php ifErrors($errors, 'siteName'); ?>"> | ||
209 | <?php doErrors($errors, 'siteName'); ?> <LABEL FOR="siteName"><EM>*</EM> Site Name: </LABEL> | ||
210 | <INPUT TYPE="text" ID="siteName" NAME="siteName" CLASS="textInput" VALUE="<?php echo($siteName); ?>"> | ||
211 | </DIV> | ||
212 | </FIELDSET><FIELDSET CLASS="inlineLabels"><LEGEND>Administrator User Details</LEGEND> | ||
213 | <DIV CLASS="ctrlHolder<?php ifErrors($errors, 'adminUser'); ?>"> | ||
214 | <?php doErrors($errors, 'adminUser'); ?> <LABEL FOR="adminUser"><EM>*</EM> Administrator Username: </LABEL> | ||
215 | <INPUT TYPE="text" ID="adminUser" NAME="adminUser" CLASS="textInput" VALUE="<?php echo($adminUser); ?>"> | ||
216 | </DIV> | ||
217 | <DIV CLASS="ctrlHolder<?php ifErrors($errors, 'adminPass'); ?>"> | ||
218 | <?php doErrors($errors, 'adminPass'); ?> <LABEL FOR="adminPass"><EM>*</EM> Administrator Password: </LABEL> | ||
219 | <INPUT TYPE="password" ID="adminPass" NAME="adminPass" CLASS="textInput" VALUE="<?php echo($adminPass); ?>"> | ||
220 | </DIV> | ||
221 | </FIELDSET> | ||
222 | <DIV CLASS="buttonHolder"> | ||
223 | <INPUT TYPE="submit" VALUE="Next"> | ||
224 | </DIV></FORM><?php | ||
225 | } | ||
226 | |||
227 | function showStepThree() | ||
228 | { | ||
229 | ?>Congradulations! You've successfully set up your InstaDisc Series Control!<?php | ||
230 | } | ||
231 | |||
232 | function ifErrors($errors, $id) | ||
233 | { | ||
234 | foreach ($errors as $name => $value) | ||
235 | { | ||
236 | if ($value['field'] == $id) | ||
237 | { | ||
238 | echo(' error'); | ||
239 | return; | ||
240 | } | ||
241 | } | ||
242 | } | ||
243 | |||
244 | |||
245 | function doErrors($errors, $id) | ||
246 | { | ||
247 | foreach ($errors as $name => $value) | ||
248 | { | ||
249 | if ($value['field'] == $id) | ||
250 | { | ||
251 | ?> <P ID="error<?php echo($name); ?>" CLASS="errorField"><EM>*</EM> <?php echo($value['msg']); ?></P><?php echo("\n"); | ||
252 | } | ||
253 | } | ||
254 | } | ||
255 | |||
256 | function addError(&$numOfErrors, &$errors, $field, $msg) | ||
257 | { | ||
258 | $numOfErrors++; | ||
259 | $errors[$numOfErrors] = array('field' => $field, 'msg' => $msg); | ||
260 | } | ||