added CSS for the demographics screen and upcoming appts
[openemr.git] / setup.php
blobdc0d21e4e971ba4b3b94a77969c4663f36c41ae4
1 <?php
2 //required for normal operation because of recent changes in PHP:
3 extract($_GET);
4 extract($_POST);
5 //turn off PHP compatibility warnings
6 ini_set("session.bug_compat_warn","off");
8 $url = "";
9 $dumpfile = "sql/database.sql";
10 $icd9 = "sql/icd9.sql";
11 $conffile = "library/sqlconf.php";
12 $upgrade = 0;
13 $defhost = 'localhost';
14 $state = $_POST["state"];
16 include_once($conffile);
18 <HTML>
19 <HEAD>
20 <TITLE>OpenEMR Setup Tool</TITLE>
21 <LINK REL=STYLESHEET HREF="interface/themes/style_blue.css">
22 </HEAD>
23 <BODY>
25 <span class="title">OpenEMR Setup</span>
26 <br><br>
27 <span class="text">
29 <?php
30 if (strtolower(ini_get('register_globals')) != 'off' && (bool) ini_get('register_globals')) {
31 echo "It appears that you have register_globals enabled in your php.ini\n" .
32 "configuration file. This causes unacceptable security risks. You must\n" .
33 "turn it off before continuing with installation.\n";
34 exit();
38 <?php
39 if ($state == 5) {
42 <p>Congratulations! OpenEMR is now successfully installed.
44 <ul>
45 <li>Please Edit the 'interface/globals.php' file now to specify the correct
46 URL paths, and to select a theme.</li>
47 <li>Please make sure that the two folders underneath
48 'openemrwebroot/interface/main/calendar/modules/PostCalendar/pntemplates/'
49 exist and are writable by the web server. The two subdirectories are
50 'compiled' and 'cache'.<br>
51 Try "chown apache:apache -R openemrwebroot/interface/main/calendar/modules/PostCalendar/pntemplates/compiled"
52 and
53 "chown apache:apache -R openemrwebroot/interface/main/calendar/modules/PostCalendar/pntemplates/cache".
54 (If either subdirectory doesn't exist, create it first then do the chown above).<br>
55 The user name and group of apache may differ depending on your OS, i.e.
56 for Debian they are www-data and www-data.</li>
57 </ul>
58 <p>
59 In order to take full advantage of the documents capability you
60 must give your web server permissions on the document storage
61 directory. Try "chown apache:apache -R openemrwebroot/documents"
62 and then "chmod g+w openemrwebroot/documents".
63 You must also make sure your PHP installation (normally set in
64 your php.ini file) has "file_uploads enabled", that
65 "upload_max_filesize" is appropriate for your use and that
66 "upload_tmp_dir" is set to a correct value if the default of
67 "/tmp" won't work on your system.
68 </p>
69 <p>
70 There's much information and many extra tools bundled within the OpenEMR
71 installation directory. Please refer to openemr/Documentation.
72 <br>Many forms and other useful scripts can be found at openemr/contrib.
73 <br>OpenEMR now comes with optional GACL support, a fine grained access control
74 system. Please refer to openemr/Documentation/README.phpgacl for -easy-
75 installation.
76 </p>
77 <p>
78 Reading openemr/includes/config.php and openemr/interface/globals.php is a good
79 idea.
80 </p>
81 <p>
82 To ensure a consistent look and feel through out the application
83 using <a href='http://www.mozilla.org/products/firefox/'>Firefox</a>
84 is recommended.
85 </p>
86 <p>
87 <b>The initial OpenEMR user is "admin" and the password is "pass".</b>
88 You should change this password!
89 </p>
90 <p>
91 <a href='./'>Click here to start using OpenEMR. </a>
92 </p>
95 exit();
99 <?php
101 $server = $_POST["server"];
102 $port = $_POST["port"];
103 $dbname = $_POST["dbname"];
104 $root = $_POST["root"];
105 $login = $_POST["login"];
106 $pass = $_POST["pass"];
107 $loginhost = $_POST["loginhost"];
108 $rootpass = $_POST["rootpass"];
111 if ($config == 1) {
112 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";
114 else {
115 switch ($state) {
117 case 1:
118 echo "<b>Step $state</b><br><br>\n";
119 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
120 <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>
121 <br><br>\n
122 <FORM METHOD='POST'>\n
123 <INPUT TYPE='HIDDEN' NAME='state' VALUE='2'>\n
124 <INPUT TYPE='RADIO' NAME='inst' VALUE='1' checked>Have setup create the databases<br>\n
125 <INPUT TYPE='RADIO' NAME='inst' VALUE='2'>I have already created the databases<br>\n
126 <br>\n
127 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
128 break;
130 case 2:
131 echo "<b>Step $state</b><br><br>\n";
132 echo "Now you need to supply the MySQL server information.
133 <br><br>
134 <FORM METHOD='POST'>
135 <INPUT TYPE='HIDDEN' NAME='state' VALUE='3'>
136 <INPUT TYPE='HIDDEN' NAME='inst' VALUE='$inst'>
137 <TABLE>\n
138 <TR><TD><font color='red'>SERVER:</font></TD></TR>
139 <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>
140 <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>
141 <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>
142 <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>
143 <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";
144 if ($inst != 2) {
145 echo "<TR><TD><font color='red'>CLIENT:</font></TD></TR>";
146 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>
147 <TR><TD><span class='text'>Name for Root Account: </span></TD><TD><INPUT TYPE='TEXT' VALUE='root' NAME='root' SIZE='30'><span class='text'>(This is name for MySQL root account. For localhost, it is usually ok to leave it 'root'.)</span><br></TD></TR>
148 <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";
150 echo "<TR><TD><font color='red'>USER:</font></TD></TR>";
151 echo "<TR><TD COLSPAN=2></TD></TR>
152 <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>
153 <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>
154 <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>
156 echo "</TABLE>
157 <br>
158 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>";
160 break;
163 case 3:
166 echo "<b>Step $state</b><br><br>\n";
167 if ($pass == "" || $login == "" || !isset($login) || !isset($pass)) {
168 echo "ERROR. Please pick a proper username and/or password.<br>\n";
169 break;
172 if ($inst != 2) {
173 echo "Connecting to MySQL Server...\n";
174 flush();
175 if ($server == "localhost")
176 $dbh = mysql_connect("$server","$root","$rootpass");
177 else
178 $dbh = mysql_connect("$server:$port","$root","$rootpass");
179 if ($dbh == FALSE) {
180 echo "ERROR. Check your login credentials.\n";
181 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
182 break;
184 else
185 echo "OK.<br>\n";
186 echo "Creating database...\n";
187 flush();
188 if (mysql_query("create database $dbname",$dbh) == FALSE) {
189 echo "ERROR. Check your login credentials.\n";
190 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
191 break;
193 else
194 echo "OK.<br>\n";
195 echo "Creating user with permissions for database...\n";
196 flush();
197 if (mysql_query("GRANT ALL PRIVILEGES ON $dbname.* TO '$login'@'$loginhost' IDENTIFIED BY '$pass'",$dbh) == FALSE) {
198 echo "ERROR when granting privileges to the specified user.\n";
199 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
200 echo "ERROR.\n";
201 break;
203 else
204 echo "OK.<br>\n";
205 echo "Reconnecting as new user...\n";
206 mysql_close($dbh);
208 else
209 echo "Connecting to MySQL Server...\n";
211 if ($server == "localhost")
212 $dbh = mysql_connect("$server","$login","$pass");
213 else
214 $dbh = mysql_connect("$server:$port","$login","$pass");
216 if ($dbh == FALSE) {
217 echo "ERROR. Check your login credentials.\n";
218 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
219 break;
221 else
222 echo "OK.<br>\n";
223 echo "Opening database...";
224 flush();
225 if (mysql_select_db("$dbname",$dbh) == FALSE) {
226 echo "ERROR. Check your login credentials.\n";
227 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
228 break;
230 else
231 echo "OK.<br>\n";
232 flush();
233 if ($upgrade != 1) {
234 echo "Creating initial tables...\n";
235 mysql_query("USE $dbname",$dbh);
236 flush();
237 $fd = fopen($dumpfile, 'r');
238 if ($fd == FALSE) {
239 echo "ERROR. Could not open dumpfile '$dumpfile'.\n";
240 flush();
241 break;
243 $query = "";
244 $line = "";
245 while (!feof ($fd)){
246 $line = fgets($fd,1024);
247 $line = rtrim($line);
248 if (substr($line,0,2) == "--") // Kill comments
249 continue;
250 if (substr($line,0,1) == "#") // Kill comments
251 continue;
252 if ($line == "")
253 continue;
254 $query = $query.$line; // Check for full query
255 $chr = substr($query,strlen($query)-1,1);
256 if ($chr == ";") { // valid query, execute
257 $query = rtrim($query,";");
258 mysql_query("$query",$dbh);
259 $query = "";
262 echo "OK<br>\n";
263 fclose($fd);
264 flush();
265 echo "Adding Initial User...\n";
266 flush();
267 $iuser = $_POST["iuser"];
268 $iuname = $_POST["iuname"];
269 $igroup = $_POST["igroup"];
270 //echo "INSERT INTO groups VALUES (1,'$igroup','$iuser')<br>\n";
271 if (mysql_query("INSERT INTO groups (id, name, user) VALUES (1,'$igroup','$iuser')") == FALSE) {
272 echo "ERROR. Could not run queries.\n";
273 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
274 flush();
275 break;
277 if (mysql_query("INSERT INTO users (id, username, password, authorized, lname,fname) VALUES (1,'$iuser','1a1dc91c907325c69271ddf0c944bc72',1,'$iuname','')") == FALSE) {
278 echo "ERROR. Could not run queries.\n";
279 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
280 flush();
281 break;
283 echo "OK<br>\n";
284 flush();
285 /* echo "Inserting ICD-9-CM Codes into Database...\n";
286 flush();
287 $fd = fopen($icd9, 'r');
288 if ($fd == FALSE) {
289 echo "ERROR. Could not open dumpfile.\n";
290 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
291 flush();
292 break;
294 $query = "";
295 $line = "";
296 while (!feof ($fd)){
297 $line = fgets($fd,1024);
298 $line = rtrim($line);
299 if (substr($line,0,2) == "--") // Kill comments
300 continue;
301 if (substr($line,0,1) == "#") // Kill comments
302 continue;
303 if ($line == "")
304 continue;
305 $query = $query.$line; // Check for full query
306 $chr = substr($query,strlen($query)-1,1);
307 if ($chr == ";") { // valid query, execute
308 $query = rtrim($query,";");
309 mysql_query("$query",$dbh);
310 $query = "";
313 echo "OK\n";
314 fclose($fd);*/
315 flush();
317 echo "\n<br>Please make sure 'library/sqlconf.php' is world-writeable for the next step.<br>\n";
320 echo "
321 <FORM METHOD='POST'>\n
322 <INPUT TYPE='HIDDEN' NAME='state' VALUE='4'>
323 <INPUT TYPE='HIDDEN' NAME='host' VALUE='$server'>
324 <INPUT TYPE='HIDDEN' NAME='dbname' VALUE='$dbname'>
325 <INPUT TYPE='HIDDEN' NAME='port' VALUE='$port'>
326 <INPUT TYPE='HIDDEN' NAME='login' VALUE='$login'>
327 <INPUT TYPE='HIDDEN' NAME='pass' VALUE='$pass'>
328 <br>\n
329 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
332 break;
334 case 4:
335 echo "<b>Step $state</b><br><br>\n";
336 echo "Writing SQL Configuration to disk...\n";
337 @touch($conffile); // php bug
338 $fd = @fopen($conffile, 'w');
339 if ($fd == FALSE) {
340 echo "ERROR. Could not open config file '$conffile' for writing.\n";
341 flush();
342 break;
344 $string = "<?
345 // OpenEMR
346 // MySQL Config
347 // Referenced from sql.inc
351 $it_died = 0; //fmg: variable keeps running track of any errors
353 fwrite($fd,$string) or $it_died++;
354 fwrite($fd,"\$host\t= '$host';\n") or $it_died++;
355 fwrite($fd,"\$port\t= '$port';\n") or $it_died++;
356 fwrite($fd,"\$login\t= '$login';\n") or $it_died++;
357 fwrite($fd,"\$pass\t= '$pass';\n") or $it_died++;
358 fwrite($fd,"\$dbase\t= '$dbname';\n") or $it_died++;
361 $string = '
363 $sqlconf = array();
364 $sqlconf["host"]= $host;
365 $sqlconf["port"] = $port;
366 $sqlconf["login"] = $login;
367 $sqlconf["pass"] = $pass;
368 $sqlconf["dbase"] = $dbase;
369 //////////////////////////
370 //////////////////////////
371 //////////////////////////
372 //////DO NOT TOUCH THIS///
373 $config = 1; /////////////
374 //////////////////////////
375 //////////////////////////
376 //////////////////////////
379 ?><? // done just for coloring
381 fwrite($fd,$string) or $it_died++;
383 //it's rather irresponsible to not report errors when writing this file.
384 if ($it_died != 0) {
385 echo "ERROR. Couldn't write $it_died lines to config file '$conffile'.\n";
386 flush();
387 break;
389 fclose($fd);
391 echo "OK<BR>\nPlease restore secure permissions on the 'library/sqlconf.php' file now.\n<br><FORM METHOD='POST'>\n
392 <INPUT TYPE='HIDDEN' NAME='state' VALUE='5'>\n
393 <br>\n
394 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
396 break;
398 case 0:
399 default:
400 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";
402 Echo "<p>If you are upgrading from a previous version, please read the README file.<br><br>";
404 echo "<FORM METHOD='POST'><INPUT TYPE='HIDDEN' NAME='state' VALUE='1'><INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>";
411 </span>
413 </BODY>
414 </HTML>