fixed a couple of silly display errors
[openemr.git] / setup.php
blobca29d3a2b515b78f6bd6e4498abd371eb27598f6
1 <?php
3 //required for normal operation because of recent changes in PHP:
4 extract($_GET);
5 extract($_POST);
6 //turn off PHP compatibility warnings
7 ini_set("session.bug_compat_warn","off");
9 $url = "";
10 $dumpfile = "sql/database.sql";
11 $icd9 = "sql/icd9.sql";
12 $conffile = "library/sqlconf.php";
13 $upgrade = 0;
14 $defhost = 'localhost';
15 $state = $_POST["state"];
17 include_once($conffile);
19 <HTML>
20 <HEAD>
21 <TITLE>OpenEMR Setup Tool</TITLE>
22 <LINK REL=STYLESHEET HREF="interface/themes/style_blue.css">
23 </HEAD>
24 <BODY>
26 <span class="title">OpenEMR Setup</span>
27 <br><br>
28 <span class="text">
30 <?php
31 if ($state == 5) {
34 <p>Congratulations! OpenEMR is now successfully installed.
36 <ul>
37 <li>Please Edit the 'interface/globals.php' file now to specify the correct
38 URL paths, and to select a theme.</li>
39 <li>Please make sure that the two folders underneath
40 'openemrwebroot/interface/main/calendar/modules/PostCalendar/pntemplates/'
41 exist and are writable by the web server. The two subdirectories are
42 'compiled' and 'cache'.<br>
43 Try "chown apache:apache -R openemrwebroot/interface/main/calendar/modules/PostCalendar/pntemplates/compiled"
44 and
45 "chown apache:apache -R openemrwebroot/interface/main/calendar/modules/PostCalendar/pntemplates/cache".
46 (If either subdirectory doesn't exist, create it first then do the chown above).<br>
47 The user name and group of apache may differ depending on your distro, i.e.
48 for Debian is www-data and www-data.</li>
49 </ul>
50 <p>
51 In order to take full advantage of the documents capability you
52 must give your web server permissions on the document storage
53 directory. Try "chown apache:apache -R openemrwebroot/documents"
54 and then "chmod g+w openemrwebroot/documents".
55 You must also make sure your PHP installation (normally set in
56 your php.ini file) has "file_uploads enabled", that
57 "upload_max_filesize" is appropriate for your use and that
58 "upload_tmp_dir" is set to a correct value if the default of
59 "/tmp" won't work on your system.
60 </p>
61 <p>
62 To ensure a consistent look and feel through out the application
63 using <a href='http://www.mozilla.org/products/firefox/'> Firefox</a>
64 is recommended.
65 </p>
66 <p>
67 <a href='./'>Click here to start using OpenEMR. </a>
68 </p>
71 exit();
75 <?php
77 $server = $_POST["server"];
78 $port = $_POST["port"];
79 $dbname = $_POST["dbname"];
80 $login = $_POST["login"];
81 $pass = $_POST["pass"];
82 $loginhost = $_POST["loginhost"];
83 $rootpass = $_POST["rootpass"];
86 if ($config == 1) {
87 echo "OpenEMR is already configured. If you wish to re-configure the SQL server, edit $conffile, or change the 'config' variable to 0, and re-run this script.<br>\n";
89 else {
90 switch ($state) {
92 case 1:
93 echo "<b>Step $state</b><br><br>\n";
94 echo "Now I need to know whether you want me to create the databases on my own or if you have already created the database for me to use. If you are upgrading, you will want to select the latter function. For me to create the databases, you will need to supply the MySQL root password.\n
95 <span class='title'> <br />NOTE: clicking on \"Continue\" may delete or cause damage to data on your system. Before you continue please backup your data.</span>
96 <br><br>\n
97 <FORM METHOD='POST'>\n
98 <INPUT TYPE='HIDDEN' NAME='state' VALUE='2'>\n
99 <INPUT TYPE='RADIO' NAME='inst' VALUE='1' checked>Have setup create the databases<br>\n
100 <INPUT TYPE='RADIO' NAME='inst' VALUE='2'>I have already created the databases<br>\n
101 <br>\n
102 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
103 break;
105 case 2:
106 echo "<b>Step $state</b><br><br>\n";
107 echo "Now you need to supply the MySQL server information.
108 <br><br>
109 <FORM METHOD='POST'>
110 <INPUT TYPE='HIDDEN' NAME='state' VALUE='3'>
111 <INPUT TYPE='HIDDEN' NAME='inst' VALUE='$inst'>
112 <TABLE>\n
113 <TR><TD><font color='red'>SERVER:</font></TD></TR>
114 <TR><TD><span class='text'>Server Host: </span></TD><TD><INPUT TYPE='TEXT' VALUE='$defhost' NAME='server' SIZE='30'><span class='text'>(This is the IP address of the machine running MySQL)</span><br></TD></TR>
115 <TR><TD><span class='text'>Server Port: </span></TD><TD><INPUT TYPE='TEXT' VALUE='3306' NAME='port' SIZE='30'><span class='text'>(The default port for MySQL is 3306)</span><br></TD></TR>
116 <TR><TD><span class='text'>Database Name: </span></TD><TD><INPUT TYPE='TEXT' VALUE='openemr' NAME='dbname' SIZE='30'><span class='text'>(This is the name of the OpenEMR database - 'openemr' is the recommended)</span><br></TD></TR>
117 <TR><TD><span class='text'>Login Name: </span></TD><TD><INPUT TYPE='TEXT' VALUE='openemr' NAME='login' SIZE='30'><span class='text'>(This is the name of the OpenEMR login name - 'openemr' is the recommended)</span><br></TD></TR>
118 <TR><TD><span class='text'>Password: </span></TD><TD><INPUT TYPE='PASSWORD' VALUE='' NAME='pass' SIZE='30'><span class='text'>(This is the Login Password for when PHP accesses MySQL - it should be at least 8 characters long and composed of both numbers and letters)</span><br></TD></TR>\n";
119 if ($inst != 2) {
120 echo "<TR><TD><font color='red'>CLIENT:</font></TD></TR>";
121 echo "<TR><TD><span class='text'>User Hostname: </span></TD><TD><INPUT TYPE='TEXT' VALUE='$defhost' NAME='loginhost' SIZE='30'><span class='text'>(This is the IP address of the server machine running Apache and PHP - if you are setting up one computer, this is the same as the Server Host above)</span><br></TD></TR>
122 <TR><TD><span class='text'>Root Pass: </span></TD><TD><INPUT TYPE='PASSWORD' VALUE='' NAME='rootpass' SIZE='30'><span class='text'>(This is your MySQL root password. For localhost, it is usually ok to leave it blank.)</span><br></TD></TR>\n";
124 echo "<TR><TD><font color='red'>USER:</font></TD></TR>";
125 echo "<TR><TD COLSPAN=2></TD></TR>
126 <TR><TD><span class='text'>Initial User:</span></TD><TD><INPUT SIZE='30' TYPE='TEXT' NAME='iuser' VALUE='admin'><span class='text'>(This is the user that will be created for you. It will be an authorized user, so it should be for a Doctor or other Practitioner)</span></TD></TR>
127 <TR><TD><span class='text'>Initial User's Name:</span></TD><TD><INPUT SIZE='30' TYPE='TEXT' NAME='iuname' VALUE='Administrator'><span class='text'>(This is the real name of the initial user.)</span></TD></TR>
128 <TR><TD><span class='text'>Initial Group:</span></TD><TD><INPUT SIZE='30' TYPE='TEXT' NAME='igroup' VALUE='Default'><span class='text'>(This is the group that will be created for your users. This should be the name of your practice.)</span></TD></TR>
130 echo "</TABLE>
131 <br>
132 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>";
134 break;
137 case 3:
140 echo "<b>Step $state</b><br><br>\n";
141 if ($pass == "" || $login == "" || !isset($login) || !isset($pass)) {
142 echo "ERROR. Please pick a proper username and/or password.<br>\n";
143 break;
146 if ($inst != 2) {
147 echo "Connecting to MySQL Server...\n";
148 flush();
149 if ($server == "localhost")
150 $dbh = mysql_connect("$server","root","$rootpass");
151 else
152 $dbh = mysql_connect("$server:$port","root","$rootpass");
153 if ($dbh == FALSE) {
154 echo "ERROR. Check your login credentials.\n";
155 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
156 break;
158 else
159 echo "OK.<br>\n";
160 echo "Creating database...\n";
161 flush();
162 if (mysql_query("create database $dbname",$dbh) == FALSE) {
163 echo "ERROR. Check your login credentials.\n";
164 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
165 break;
167 else
168 echo "OK.<br>\n";
169 echo "Creating user with permissions for database...\n";
170 flush();
171 if (mysql_query("GRANT ALL PRIVILEGES ON $dbname.* TO '$login'@'$loginhost' IDENTIFIED BY '$pass'",$dbh) == FALSE) {
172 echo "ERROR when granting privileges to the specified user.\n";
173 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
174 echo "ERROR.\n";
175 break;
177 else
178 echo "OK.<br>\n";
179 echo "Reconnecting as new user...\n";
180 mysql_close($dbh);
182 else
183 echo "Connecting to MySQL Server...\n";
185 if ($server == "localhost")
186 $dbh = mysql_connect("$server","$login","$pass");
187 else
188 $dbh = mysql_connect("$server:$port","$login","$pass");
190 if ($dbh == FALSE) {
191 echo "ERROR. Check your login credentials.\n";
192 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
193 break;
195 else
196 echo "OK.<br>\n";
197 echo "Opening database...";
198 flush();
199 if (mysql_select_db("$dbname",$dbh) == FALSE) {
200 echo "ERROR. Check your login credentials.\n";
201 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
202 break;
204 else
205 echo "OK.<br>\n";
206 flush();
207 if ($upgrade != 1) {
208 echo "Creating initial tables...\n";
209 mysql_query("USE $dbname",$dbh);
210 flush();
211 $fd = fopen($dumpfile, 'r');
212 if ($fd == FALSE) {
213 echo "ERROR. Could not open dumpfile '$dumpfile'.\n";
214 flush();
215 break;
217 $query = "";
218 $line = "";
219 while (!feof ($fd)){
220 $line = fgets($fd,1024);
221 $line = rtrim($line);
222 if (substr($line,0,2) == "--") // Kill comments
223 continue;
224 if (substr($line,0,1) == "#") // Kill comments
225 continue;
226 if ($line == "")
227 continue;
228 $query = $query.$line; // Check for full query
229 $chr = substr($query,strlen($query)-1,1);
230 if ($chr == ";") { // valid query, execute
231 $query = rtrim($query,";");
232 mysql_query("$query",$dbh);
233 $query = "";
236 echo "OK<br>\n";
237 fclose($fd);
238 flush();
239 echo "Adding Initial User...\n";
240 flush();
241 $iuser = $_POST["iuser"];
242 $iuname = $_POST["iuname"];
243 $igroup = $_POST["igroup"];
244 //echo "INSERT INTO groups VALUES (1,'$igroup','$iuser')<br>\n";
245 if (mysql_query("INSERT INTO groups (id, name, user) VALUES (1,'$igroup','$iuser')") == FALSE) {
246 echo "ERROR. Could not run queries.\n";
247 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
248 flush();
249 break;
251 if (mysql_query("INSERT INTO users (id, username, password, authorized, lname,fname) VALUES (1,'$iuser','1a1dc91c907325c69271ddf0c944bc72',1,'$iuname','')") == FALSE) {
252 echo "ERROR. Could not run queries.\n";
253 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
254 flush();
255 break;
257 echo "OK<br>\n";
258 flush();
259 /* echo "Inserting ICD-9-CM Codes into Database...\n";
260 flush();
261 $fd = fopen($icd9, 'r');
262 if ($fd == FALSE) {
263 echo "ERROR. Could not open dumpfile.\n";
264 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
265 flush();
266 break;
268 $query = "";
269 $line = "";
270 while (!feof ($fd)){
271 $line = fgets($fd,1024);
272 $line = rtrim($line);
273 if (substr($line,0,2) == "--") // Kill comments
274 continue;
275 if (substr($line,0,1) == "#") // Kill comments
276 continue;
277 if ($line == "")
278 continue;
279 $query = $query.$line; // Check for full query
280 $chr = substr($query,strlen($query)-1,1);
281 if ($chr == ";") { // valid query, execute
282 $query = rtrim($query,";");
283 mysql_query("$query",$dbh);
284 $query = "";
287 echo "OK\n";
288 fclose($fd);*/
289 flush();
291 echo "\n<br>Please make sure 'library/sqlconf.php' is world-writeable for the next step.<br>\n";
294 echo "
295 <FORM METHOD='POST'>\n
296 <INPUT TYPE='HIDDEN' NAME='state' VALUE='4'>
297 <INPUT TYPE='HIDDEN' NAME='host' VALUE='$server'>
298 <INPUT TYPE='HIDDEN' NAME='dbname' VALUE='$dbname'>
299 <INPUT TYPE='HIDDEN' NAME='port' VALUE='$port'>
300 <INPUT TYPE='HIDDEN' NAME='login' VALUE='$login'>
301 <INPUT TYPE='HIDDEN' NAME='pass' VALUE='$pass'>
302 <br>\n
303 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
306 break;
308 case 4:
309 echo "<b>Step $state</b><br><br>\n";
310 echo "Writing SQL Configuration to disk...\n";
311 @touch($conffile); // php bug
312 $fd = @fopen($conffile, 'w');
313 if ($fd == FALSE) {
314 echo "ERROR. Could not open config file '$conffile' for writing.\n";
315 flush();
316 break;
318 $string = "<?
319 // OpenEMR
320 // MySQL Config
321 // Referenced from sql.inc
325 $it_died = 0; //fmg: variable keeps running track of any errors
327 fwrite($fd,$string) or $it_died++;
328 fwrite($fd,"\$host\t= '$host';\n") or $it_died++;
329 fwrite($fd,"\$port\t= '$port';\n") or $it_died++;
330 fwrite($fd,"\$login\t= '$login';\n") or $it_died++;
331 fwrite($fd,"\$pass\t= '$pass';\n") or $it_died++;
332 fwrite($fd,"\$dbase\t= '$dbname';\n") or $it_died++;
335 $string = '
337 $sqlconf = array();
338 $sqlconf["host"]= $host;
339 $sqlconf["port"] = $port;
340 $sqlconf["login"] = $login;
341 $sqlconf["pass"] = $pass;
342 $sqlconf["dbase"] = $dbase;
343 //////////////////////////
344 //////////////////////////
345 //////////////////////////
346 //////DO NOT TOUCH THIS///
347 $config = 1; /////////////
348 //////////////////////////
349 //////////////////////////
350 //////////////////////////
353 ?><? // done just for coloring
355 fwrite($fd,$string) or $it_died++;
357 //it's rather irresponsible to not report errors when writing this file.
358 if ($it_died != 0) {
359 echo "ERROR. Couldn't write $it_died lines to config file '$conffile'.\n";
360 flush();
361 break;
363 fclose($fd);
365 echo "OK<BR>\nPlease restore secure permissions on the 'library/sqlconf.php' file now.\n<br><FORM METHOD='POST'>\n
366 <INPUT TYPE='HIDDEN' NAME='state' VALUE='5'>\n
367 <br>\n
368 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
370 break;
372 case 0:
373 default:
374 echo "Welcome to OpenEMR. This utility will step you through the configuration of OpenEMR for your practice. Before proceeding, be sure that you have a properly installed and configured MySQL server available, and a PHP configured webserver.<br><br>\n";
376 Echo "<p>If you are upgrading from a previous version, please read the README file.<br><br>";
378 echo "<FORM METHOD='POST'><INPUT TYPE='HIDDEN' NAME='state' VALUE='1'><INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>";
385 </span>
387 </BODY>
388 </HTML>