about summary refs log tree commit diff stats
path: root/series/trunk/install.php
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2008-09-10 21:06:49 +0000
committerKelly Rauchenberger <fefferburbia@gmail.com>2008-09-10 21:06:49 +0000
commit44c3bc48b5db7b3dc6517d2b073a55af5d4b52db (patch)
treea48f63061f3cfe5427ce1bc313147cf6be0e739a /series/trunk/install.php
parenta9a796498285358e7a2f1fde5043e4015de5db70 (diff)
downloadinstadisc-44c3bc48b5db7b3dc6517d2b073a55af5d4b52db.tar.gz
instadisc-44c3bc48b5db7b3dc6517d2b073a55af5d4b52db.tar.bz2
instadisc-44c3bc48b5db7b3dc6517d2b073a55af5d4b52db.zip
Series: Moved around directory structure
Refs #55
Diffstat (limited to 'series/trunk/install.php')
-rw-r--r--series/trunk/install.php261
1 files changed, 261 insertions, 0 deletions
diff --git a/series/trunk/install.php b/series/trunk/install.php new file mode 100644 index 0000000..cf0d592 --- /dev/null +++ b/series/trunk/install.php
@@ -0,0 +1,261 @@
1<?php
2
3/* InstaDisc Series - A Four Island Project */
4
5if (!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 config (name,value) VALUES (\"adminPass\",\"" . 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
146function showHeader($number)
147{
148?><HTML><HEAD><TITLE>InstaDisc Series Setup Step <?php echo($number); ?></TITLE><LINK REL="stylesheet" TYPE="text/css" HREF="uniform.css"></HEAD><BODY><CENTER><H1>InstaDisc Installation</H1></CENTER><P><?php
149}
150
151function 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
191function 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 <P CLASS="formHint">Your website's name is required for a little personalization of emails.</P>
212</DIV>
213</FIELDSET><FIELDSET CLASS="inlineLabels"><LEGEND>Administrator User Details</LEGEND>
214<DIV CLASS="ctrlHolder<?php ifErrors($errors, 'adminUser'); ?>">
215<?php doErrors($errors, 'adminUser'); ?> <LABEL FOR="adminUser"><EM>*</EM> Administrator Username: </LABEL>
216 <INPUT TYPE="text" ID="adminUser" NAME="adminUser" CLASS="textInput" VALUE="<?php echo($adminUser); ?>">
217</DIV>
218<DIV CLASS="ctrlHolder<?php ifErrors($errors, 'adminPass'); ?>">
219<?php doErrors($errors, 'adminPass'); ?> <LABEL FOR="adminPass"><EM>*</EM> Administrator Password: </LABEL>
220 <INPUT TYPE="password" ID="adminPass" NAME="adminPass" CLASS="textInput" VALUE="<?php echo($adminPass); ?>">
221</DIV>
222</FIELDSET>
223<DIV CLASS="buttonHolder">
224 <INPUT TYPE="submit" VALUE="Next">
225</DIV></FORM><?php
226}
227
228function showStepThree()
229{
230?>Congradulations! You've successfully set up your InstaDisc Series Control!<?php
231}
232
233function ifErrors($errors, $id)
234{
235 foreach ($errors as $name => $value)
236 {
237 if ($value['field'] == $id)
238 {
239 echo(' error');
240 return;
241 }
242 }
243}
244
245
246function doErrors($errors, $id)
247{
248 foreach ($errors as $name => $value)
249 {
250 if ($value['field'] == $id)
251 {
252?> <P ID="error<?php echo($name); ?>" CLASS="errorField"><EM>*</EM> <?php echo($value['msg']); ?></P><?php echo("\n");
253 }
254 }
255}
256
257function addError(&$numOfErrors, &$errors, $field, $msg)
258{
259 $numOfErrors++;
260 $errors[$numOfErrors] = array('field' => $field, 'msg' => $msg);
261}