about summary refs log tree commit diff stats
path: root/series/core/trunk/install.php
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2008-09-07 13:08:25 +0000
committerKelly Rauchenberger <fefferburbia@gmail.com>2008-09-07 13:08:25 +0000
commit0c61e34109d7c69b1093463ece88e5545c6f1c16 (patch)
treedbceacc8ba609c8a1518bed91f63916b3244f242 /series/core/trunk/install.php
parent055a0711293a186e2c0bfa189c74eea7b8b320c6 (diff)
downloadinstadisc-0c61e34109d7c69b1093463ece88e5545c6f1c16.tar.gz
instadisc-0c61e34109d7c69b1093463ece88e5545c6f1c16.tar.bz2
instadisc-0c61e34109d7c69b1093463ece88e5545c6f1c16.zip
Series: Wrote installation script
Refs #28
Diffstat (limited to 'series/core/trunk/install.php')
-rw-r--r--series/core/trunk/install.php235
1 files changed, 235 insertions, 0 deletions
diff --git a/series/core/trunk/install.php b/series/core/trunk/install.php index 3b3f202..0f7549d 100644 --- a/series/core/trunk/install.php +++ b/series/core/trunk/install.php
@@ -2,4 +2,239 @@
2 2
3/* InstaDisc Series - A Four Island Project */ 3/* InstaDisc Series - A Four Island Project */
4 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 ($numOfErrors > 0)
95 {
96 showHeader('2');
97 showStepTwo($_POST['mailDomain'], $_POST['smtpHost'], ($_POST['smtpAuth'] == 'on' ? ' CHECKED' : ''), $_POST['smtpUser'], $_POST['smtpPass'], $_POST['siteName'], $_POST['xmlrpcURL'], $_POST['adminUser'], $_POST['adminPass'], $_POST['adminEmail'], $errors);
98 } else {
99 include_once('includes/config.php');
100
101 mysql_connect($dbhost, $dbuser, $dbpass);
102 mysql_select_db($dbname);
103
104 $sql[0] = "INSERT INTO config (name,value) VALUES (\"siteName\",\"" . mysql_real_escape_string($_POST['siteName']) . "\")";
105
106 foreach ($sql as $name => $value)
107 {
108 if (!trim($value) == '')
109 {
110 $sql2 = @mysql_query($value);
111 if (!$sql2)
112 {
113 addError($numOfErrors, $errors, '', "MySQL error \"" . mysql_error() . "\" while filling database");
114 }
115 }
116 }
117
118 if ($numOfErrors > 0)
119 {
120 showHeader('2');
121 showStepTwo($_POST['siteName'], $errors);
122 } else {
123 showHeader('3');
124 showStepThree();
125 }
126 }
127
128 break;
129 }
130}
131
132?><P><CENTER><SMALL><SMALL>InstaDisc (C) Starla Insigna 2008. InstaDisc Setup uses the UniForm form theme</SMALL></SMALL></CENTER></BODY></HTML><?php
133
134function showHeader($number)
135{
136?><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
137}
138
139function showStepOne($host, $username, $password, $dbname, $errors)
140{
141?>Welcome to the InstaDisc Series Control installation! Please input your database details below.<P>
142<FORM CLASS="uniform" ACTION="./install.php?submit=1" METHOD="POST">
143<?php
144 if (isset($errors[1]))
145 {
146?><DIV ID="errorMsg">Uh oh! Validation errors!<P>
147<OL><?php
148 foreach ($errors as $name => $value)
149 {
150?><LI><A HREF="#error<?php echo($name); ?>"><?php echo($value['msg']); ?></A></LI><?php
151 }
152?></OL></DIV><?php
153 }
154?>
155<FIELDSET CLASS="inlineLabels"><LEGEND>Database Details</LEGEND>
156<DIV CLASS="ctrlHolder<?php ifErrors($errors, 'host'); ?>">
157<?php doErrors($errors, 'host'); ?> <LABEL FOR="host"><EM>*</EM> Host: </LABEL>
158 <INPUT TYPE="text" ID="host" NAME="host" CLASS="textInput" VALUE="<?php echo($host); ?>">
159</DIV>
160<DIV CLASS="ctrlHolder<?php ifErrors($errors, 'username'); ?>">
161<?php doErrors($errors, 'username'); ?> <LABEL FOR="username"><EM>*</EM> Username: </LABEL>
162 <INPUT TYPE="text" ID="username" NAME="username" CLASS="textInput" VALUE="<?php echo($username); ?>">
163</DIV>
164<DIV CLASS="ctrlHolder<?php ifErrors($errors, 'password'); ?>">
165<?php doErrors($errors, 'password'); ?> <LABEL FOR="password"><EM>*</EM> Password: </LABEL>
166 <INPUT TYPE="password" ID="password" NAME="password" CLASS="textInput" VALUE="<?php echo($password); ?>">
167</DIV>
168<DIV CLASS="ctrlHolder<?php ifErrors($errors, 'dbname'); ?>">
169<?php doErrors($errors, 'dbname'); ?> <LABEL FOR="dbname"><EM>*</EM> Name: </LABEL>
170 <INPUT TYPE="text" ID="dbname" NAME="dbname" CLASS="textInput" VALUE="<?php echo($dbname); ?>">
171 <P CLASS="formHint">You need to create this database before running this script.</P>
172</DIV>
173</FIELDSET>
174<DIV CLASS="buttonHolder">
175 <INPUT TYPE="submit" VALUE="Next">
176</DIV></FORM><?php
177}
178
179function showStepTwo($siteName, $errors)
180{
181?>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:
182<FORM CLASS="uniform" ACTION="./install.php?submit=2" METHOD="POST">
183<?php
184 if (isset($errors[1]))
185 {
186?><DIV ID="errorMsg">Uh oh! Validation errors!<P>
187<OL><?php
188 foreach ($errors as $name => $value)
189 {
190?><LI><A HREF="#error<?php echo($name); ?>"><?php echo($value['msg']); ?></A></LI><?php
191 }
192?></OL></DIV><?php
193 }
5?> 194?>
195<FIELDSET CLASS="inlineLabels"><LEGEND>Website</LEGEND>
196<DIV CLASS="ctrlHolder<?php ifErrors($errors, 'siteName'); ?>">
197<?php doErrors($errors, 'siteName'); ?> <LABEL FOR="siteName"><EM>*</EM> Site Name: </LABEL>
198 <INPUT TYPE="text" ID="siteName" NAME="siteName" CLASS="textInput" VALUE="<?php echo($siteName); ?>">
199 <P CLASS="formHint">Your website's name is required for a little personalization of emails.</P>
200</DIV>
201</FIELDSET>
202<DIV CLASS="buttonHolder">
203 <INPUT TYPE="submit" VALUE="Next">
204</DIV></FORM><?php
205}
206
207function showStepThree()
208{
209?>Congradulations! You've successfully set up your InstaDisc Series Control!<?php
210}
211
212function ifErrors($errors, $id)
213{
214 foreach ($errors as $name => $value)
215 {
216 if ($value['field'] == $id)
217 {
218 echo(' error');
219 return;
220 }
221 }
222}
223
224
225function doErrors($errors, $id)
226{
227 foreach ($errors as $name => $value)
228 {
229 if ($value['field'] == $id)
230 {
231?> <P ID="error<?php echo($name); ?>" CLASS="errorField"><EM>*</EM> <?php echo($value['msg']); ?></P><?php echo("\n");
232 }
233 }
234}
235
236function addError(&$numOfErrors, &$errors, $field, $msg)
237{
238 $numOfErrors++;
239 $errors[$numOfErrors] = array('field' => $field, 'msg' => $msg);
240}