implemented customization of billing code types
[openemr.git] / setup.php
blobef5e62da30ace70d549871c0a6415614a856dfb8
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");
10 $url = "";
11 $dumpfile = "sql/database.sql";
12 $icd9 = "sql/icd9.sql";
13 $conffile = "library/sqlconf.php";
14 $upgrade = 0;
15 $defhost = 'localhost';
16 $state = $_POST["state"];
18 include_once($conffile);
21 <HTML>
22 <HEAD>
23 <TITLE>OpenEMR Setup Tool</TITLE>
24 <LINK REL=STYLESHEET HREF="interface/themes/style_blue.css">
25 </HEAD>
26 <BODY>
28 <span class="title">OpenEMR Setup</span>
29 <br><br>
30 <span class="text">
36 if ($state == 5) {
38 echo "
39 Congratulations! OpenEMR is now successfully installed.
40 <ul>
41 <li>Please Edit the 'interface/globals.php' file now to specify the correct URL paths, and to select a theme.<br>\n
42 <li>Please make sure that the two folders underneath 'openemrwebroot/interface/main/calendar/modules/PostCalendar/pntemplates/' exist and are writable by the web server. The two subdirectories are 'compiled' and 'cache'.<br>
43 Try \"chown apache:apache -R openemrwebroot/interface/main/calendar/modules/PostCalendar/pntemplates/compiled\".
44 \"chown apache:apache -R openemrwebroot/interface/main/calendar/modules/PostCalendar/pntemplates/cache\".
45 (If either subdirectory doesn't exist, create it first then do the chown above).<br>
46 The user name and group of apache may differ depending on your distro, i.e. for Debian is www-data and www-data.
47 <li>Please Edit the interface/globals.php file now to specify the correct URL paths, and to select a theme.<br>\n
48 <li>Please make sure that the folder underneath the OpenEMR webroot 'openemrwebroot/interface/main/calendar/modules/PostCalendar/pntemplates/compiled' is writable by the web server. <br>
49 Try \"chown apache:apache -R openemrwebroot/interface/main/calendar/modules/PostCalendar/pntemplates/compiled\".
50 </ul>
51 <p>
52 In order to take full advantage of the documents capability you must give your web server permissions on the document storage directory, try \"chown apache:apache -R openemrwebroot/documents\" and then \"chmod g+w openemrwebroot/documents\".
53 You must also make sure your PHP installation (normally set in your php.ini file) has \"file_uploads enabled\", that \"upload_max_filesize\" is appropriate for your use and that \"upload_tmp_dir\" is set to a correct value if the default of \"/tmp\" won't work on your system.
54 </p>
55 <p>
56 To ensure a consistent look and feel through out the application using <a href='http://www.mozilla.org/products/firefox/'> Firefox</a> is recommended.
57 </p>
58 <p>
59 <a href='./'>Click here to start using OpenEMR. </a>
60 </p>
62 exit();
76 <?php
80 $server = $_POST["server"];
81 $port = $_POST["port"];
82 $dbname = $_POST["dbname"];
83 $login = $_POST["login"];
84 $pass = $_POST["pass"];
85 $loginhost = $_POST["loginhost"];
86 $rootpass = $_POST["rootpass"];
89 if ($config == 1) {
90 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";
92 else {
93 switch ($state) {
95 case 1:
96 echo "<b>Step $state</b><br><br>\n";
97 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
98 <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>
99 <br><br>\n
100 <FORM METHOD='POST'>\n
101 <INPUT TYPE='HIDDEN' NAME='state' VALUE='2'>\n
102 <INPUT TYPE='RADIO' NAME='inst' VALUE='1' checked>Have setup create the databases<br>\n
103 <INPUT TYPE='RADIO' NAME='inst' VALUE='2'>I have already created the databases<br>\n
104 <br>\n
105 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
106 break;
108 case 2:
109 echo "<b>Step $state</b><br><br>\n";
110 echo "Now you need to supply the MySQL server information.
111 <br><br>
112 <FORM METHOD='POST'>
113 <INPUT TYPE='HIDDEN' NAME='state' VALUE='3'>
114 <INPUT TYPE='HIDDEN' NAME='inst' VALUE='$inst'>
115 <TABLE>\n
116 <TR><TD><font color='red'>SERVER:</font></TD></TR>
117 <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>
118 <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>
119 <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>
120 <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>
121 <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";
122 if ($inst != 2) {
123 echo "<TR><TD><font color='red'>CLIENT:</font></TD></TR>";
124 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>
125 <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";
127 echo "<TR><TD><font color='red'>USER:</font></TD></TR>";
128 echo "<TR><TD COLSPAN=2></TD></TR>
129 <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>
130 <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>
131 <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>
133 echo "</TABLE>
134 <br>
135 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>";
137 break;
140 case 3:
143 echo "<b>Step $state</b><br><br>\n";
144 if ($pass == "" || $login == "" || !isset($login) || !isset($pass)) {
145 echo "ERROR. Please pick a proper username and/or password.<br>\n";
146 break;
149 if ($inst != 2) {
150 echo "Connecting to MySQL Server...\n";
151 flush();
152 if ($server == "localhost")
153 $dbh = mysql_connect("$server","root","$rootpass");
154 else
155 $dbh = mysql_connect("$server:$port","root","$rootpass");
156 if ($dbh == FALSE) {
157 echo "ERROR. Check your login credentials.\n";
158 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
159 break;
161 else
162 echo "OK.<br>\n";
163 echo "Creating database...\n";
164 flush();
165 echo "ERROR.\n";
166 if (mysql_query("create database $dbname",$dbh) == FALSE) {
167 echo "ERROR. Check your login credentials.\n";
168 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
169 break;
171 else
172 echo "OK.<br>\n";
173 echo "Creating user with permissions for database...\n";
174 flush();
175 if (mysql_query("GRANT ALL PRIVILEGES ON $dbname.* TO '$login'@'$loginhost' IDENTIFIED BY '$pass'",$dbh) == FALSE) {
176 echo "ERROR when granting privileges to the specified user.\n";
177 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
178 echo "ERROR.\n";
179 break;
181 else
182 echo "OK.<br>\n";
183 echo "Reconnecting as new user...\n";
184 mysql_close($dbh);
186 else
187 echo "Connecting to MySQL Server...\n";
189 if ($server == "localhost")
190 $dbh = mysql_connect("$server","$login","$pass");
191 else
192 $dbh = mysql_connect("$server:$port","$login","$pass");
194 if ($dbh == FALSE) {
195 echo "ERROR. Check your login credentials.\n";
196 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
197 break;
199 else
200 echo "OK.<br>\n";
201 echo "Opening database...";
202 flush();
203 if (mysql_select_db("$dbname",$dbh) == FALSE) {
204 echo "ERROR. Check your login credentials.\n";
205 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
206 break;
208 else
209 echo "OK.<br>\n";
210 flush();
211 if ($upgrade != 1) {
212 echo "Creating initial tables...\n";
213 mysql_query("USE $dbname",$dbh);
214 flush();
215 $fd = fopen($dumpfile, 'r');
216 if ($fd == FALSE) {
217 echo "ERROR. Could not open dumpfile '$dumpfile'.\n";
218 flush();
219 break;
221 $query = "";
222 $line = "";
223 while (!feof ($fd)){
224 $line = fgets($fd,1024);
225 $line = rtrim($line);
226 if (substr($line,0,2) == "--") // Kill comments
227 continue;
228 if (substr($line,0,1) == "#") // Kill comments
229 continue;
230 if ($line == "")
231 continue;
232 $query = $query.$line; // Check for full query
233 $chr = substr($query,strlen($query)-1,1);
234 if ($chr == ";") { // valid query, execute
235 $query = rtrim($query,";");
236 mysql_query("$query",$dbh);
237 $query = "";
240 echo "OK<br>\n";
241 fclose($fd);
242 flush();
243 echo "Adding Initial User...\n";
244 flush();
245 $iuser = $_POST["iuser"];
246 $iuname = $_POST["iuname"];
247 $igroup = $_POST["igroup"];
248 //echo "INSERT INTO groups VALUES (1,'$igroup','$iuser')<br>\n";
249 if (mysql_query("INSERT INTO groups (id, name, user) VALUES (1,'$igroup','$iuser')") == FALSE) {
250 echo "ERROR. Could not run queries.\n";
251 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
252 flush();
253 break;
255 if (mysql_query("INSERT INTO users (id, username, password, authorized, lname,fname) VALUES (1,'$iuser','1a1dc91c907325c69271ddf0c944bc72',1,'$iuname','')") == FALSE) {
256 echo "ERROR. Could not run queries.\n";
257 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
258 flush();
259 break;
261 echo "OK<br>\n";
262 flush();
263 /* echo "Inserting ICD-9-CM Codes into Database...\n";
264 flush();
265 $fd = fopen($icd9, 'r');
266 if ($fd == FALSE) {
267 echo "ERROR. Could not open dumpfile.\n";
268 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
269 flush();
270 break;
272 $query = "";
273 $line = "";
274 while (!feof ($fd)){
275 $line = fgets($fd,1024);
276 $line = rtrim($line);
277 if (substr($line,0,2) == "--") // Kill comments
278 continue;
279 if (substr($line,0,1) == "#") // Kill comments
280 continue;
281 if ($line == "")
282 continue;
283 $query = $query.$line; // Check for full query
284 $chr = substr($query,strlen($query)-1,1);
285 if ($chr == ";") { // valid query, execute
286 $query = rtrim($query,";");
287 mysql_query("$query",$dbh);
288 $query = "";
291 echo "OK\n";
292 fclose($fd);*/
293 flush();
295 echo "\n<br>Please make sure 'library/sqlconf.php' is world-writeable for the next step.<br>\n";
298 echo "
299 <FORM METHOD='POST'>\n
300 <INPUT TYPE='HIDDEN' NAME='state' VALUE='4'>
301 <INPUT TYPE='HIDDEN' NAME='host' VALUE='$server'>
302 <INPUT TYPE='HIDDEN' NAME='dbname' VALUE='$dbname'>
303 <INPUT TYPE='HIDDEN' NAME='port' VALUE='$port'>
304 <INPUT TYPE='HIDDEN' NAME='login' VALUE='$login'>
305 <INPUT TYPE='HIDDEN' NAME='pass' VALUE='$pass'>
306 <br>\n
307 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
310 break;
312 case 4:
313 echo "<b>Step $state</b><br><br>\n";
314 echo "Writing SQL Configuration to disk...\n";
315 @touch($conffile); // php bug
316 $fd = @fopen($conffile, 'w');
317 if ($fd == FALSE) {
318 echo "ERROR. Could not open config file '$conffile' for writing.\n";
319 flush();
320 break;
322 $string = "<?
323 // OpenEMR
324 // MySQL Config
325 // Referenced from sql.inc
329 $it_died = 0; //fmg: variable keeps running track of any errors
331 fwrite($fd,$string) or $it_died++;
332 fwrite($fd,"\$host\t= '$host';\n") or $it_died++;
333 fwrite($fd,"\$port\t= '$port';\n") or $it_died++;
334 fwrite($fd,"\$login\t= '$login';\n") or $it_died++;
335 fwrite($fd,"\$pass\t= '$pass';\n") or $it_died++;
336 fwrite($fd,"\$dbase\t= '$dbname';\n") or $it_died++;
339 $string = '
341 $sqlconf = array();
342 $sqlconf["host"]= $host;
343 $sqlconf["port"] = $port;
344 $sqlconf["login"] = $login;
345 $sqlconf["pass"] = $pass;
346 $sqlconf["dbase"] = $dbase;
347 //////////////////////////
348 //////////////////////////
349 //////////////////////////
350 //////DO NOT TOUCH THIS///
351 $config = 1; /////////////
352 //////////////////////////
353 //////////////////////////
354 //////////////////////////
357 ?><? // done just for coloring
359 fwrite($fd,$string) or $it_died++;
361 //it's rather irresponsible to not report errors when writing this file.
362 if ($it_died != 0) {
363 echo "ERROR. Couldn't write $it_died lines to config file '$conffile'.\n";
364 flush();
365 break;
367 fclose($fd);
369 echo "OK<BR>\nPlease restore secure permissions on the 'library/sqlconf.php' file now.\n<br><FORM METHOD='POST'>\n
370 <INPUT TYPE='HIDDEN' NAME='state' VALUE='5'>\n
371 <br>\n
372 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
374 break;
376 case 0:
377 default:
378 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";
380 Echo "<p>If you are upgrading from a previous version, please read the README file.<br><br>";
382 echo "<FORM METHOD='POST'><INPUT TYPE='HIDDEN' NAME='state' VALUE='1'><INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>";
389 </span>
391 </BODY>
392 </HTML>