fixed updating of displayed payment total
[openemr.git] / setup.php
blob7a024324293344d7291de7373ab91dece4f69f9b
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>Pennington Firm OpenEMR Setup Tool</TITLE>
24 <LINK REL=STYLESHEET HREF="interface/themes/style_blue.css">
25 </HEAD>
26 <BODY>
28 <span class="title">Pennington Firm 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)
46 <li>Please Edit the interface/globals.php file now to specify the correct URL paths, and to select a theme.<br>\n
47 <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>
48 Try \"chown apache:apache -R openemrwebroot/interface/main/calendar/modules/PostCalendar/pntemplates/compiled\".
49 </ul>
50 <p>
51 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\".
52 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.
53 </p>
54 <p>
55 To ensure a consistent look and feel through out the application Pennington Firm, LLC recommends using <a href='http://www.mozilla.org/products/firefox/'> Firefox</a>.
56 </p>
57 <p>
58 <a href='./'>Click here to start using OpenEMR. </a>
59 </p>
61 exit();
75 <?php
79 $server = $_POST["server"];
80 $port = $_POST["port"];
81 $dbname = $_POST["dbname"];
82 $login = $_POST["login"];
83 $pass = $_POST["pass"];
84 $loginhost = $_POST["loginhost"];
85 $rootpass = $_POST["rootpass"];
88 if ($config == 1) {
89 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";
91 else {
92 switch ($state) {
94 case 1:
95 echo "<b>Step $state</b><br><br>\n";
96 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
97 <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>
98 <br><br>\n
99 <FORM METHOD='POST'>\n
100 <INPUT TYPE='HIDDEN' NAME='state' VALUE='2'>\n
101 <INPUT TYPE='RADIO' NAME='inst' VALUE='1' checked>Have setup create the databases<br>\n
102 <INPUT TYPE='RADIO' NAME='inst' VALUE='2'>I have already created the databases<br>\n
103 <br>\n
104 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
105 break;
107 case 2:
108 echo "<b>Step $state</b><br><br>\n";
109 echo "Now you need to supply the MySQL server information.
110 <br><br>
111 <FORM METHOD='POST'>
112 <INPUT TYPE='HIDDEN' NAME='state' VALUE='3'>
113 <INPUT TYPE='HIDDEN' NAME='inst' VALUE='$inst'>
114 <TABLE>\n
115 <TR><TD><font color='red'>SERVER:</font></TD></TR>
116 <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>
117 <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>
118 <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>
119 <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>
120 <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";
121 if ($inst != 2) {
122 echo "<TR><TD><font color='red'>CLIENT:</font></TD></TR>";
123 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>
124 <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";
126 echo "<TR><TD><font color='red'>USER:</font></TD></TR>";
127 echo "<TR><TD COLSPAN=2></TD></TR>
128 <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>
129 <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>
130 <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>
132 echo "</TABLE>
133 <br>
134 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>";
136 break;
139 case 3:
142 echo "<b>Step $state</b><br><br>\n";
143 if ($pass == "" || $login == "" || !isset($login) || !isset($pass)) {
144 echo "ERROR. Please pick a proper username and/or password.<br>\n";
145 break;
148 if ($inst != 2) {
149 echo "Connecting to MySQL Server...\n";
150 flush();
151 if ($server == "localhost")
152 $dbh = mysql_connect("$server","root","$rootpass");
153 else
154 $dbh = mysql_connect("$server:$port","root","$rootpass");
155 if ($dbh == FALSE) {
156 echo "ERROR. Check your login credentials.\n";
157 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
158 break;
160 else
161 echo "OK.<br>\n";
162 echo "Creating database...\n";
163 flush();
164 echo "ERROR.\n";
165 if (mysql_query("create database $dbname",$dbh) == FALSE) {
166 echo "ERROR. Check your login credentials.\n";
167 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
168 break;
170 else
171 echo "OK.<br>\n";
172 echo "Creating user with permissions for database...\n";
173 flush();
174 if (mysql_query("GRANT ALL PRIVILEGES ON $dbname.* TO '$login'@'$loginhost' IDENTIFIED BY '$pass'",$dbh) == FALSE) {
175 echo "ERROR when granting privileges to the specified user.\n";
176 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
177 echo "ERROR.\n";
178 break;
180 else
181 echo "OK.<br>\n";
182 echo "Reconnecting as new user...\n";
183 mysql_close($dbh);
185 else
186 echo "Connecting to MySQL Server...\n";
188 if ($server == "localhost")
189 $dbh = mysql_connect("$server","$login","$pass");
190 else
191 $dbh = mysql_connect("$server:$port","$login","$pass");
193 if ($dbh == FALSE) {
194 echo "ERROR. Check your login credentials.\n";
195 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
196 break;
198 else
199 echo "OK.<br>\n";
200 echo "Opening database...";
201 flush();
202 if (mysql_select_db("$dbname",$dbh) == FALSE) {
203 echo "ERROR. Check your login credentials.\n";
204 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
205 break;
207 else
208 echo "OK.<br>\n";
209 flush();
210 if ($upgrade != 1) {
211 echo "Creating initial tables...\n";
212 mysql_query("USE $dbname",$dbh);
213 flush();
214 $fd = fopen($dumpfile, 'r');
215 if ($fd == FALSE) {
216 echo "ERROR. Could not open dumpfile '$dumpfile'.\n";
217 flush();
218 break;
220 $query = "";
221 $line = "";
222 while (!feof ($fd)){
223 $line = fgets($fd,1024);
224 $line = rtrim($line);
225 if (substr($line,0,2) == "--") // Kill comments
226 continue;
227 if (substr($line,0,1) == "#") // Kill comments
228 continue;
229 if ($line == "")
230 continue;
231 $query = $query.$line; // Check for full query
232 $chr = substr($query,strlen($query)-1,1);
233 if ($chr == ";") { // valid query, execute
234 $query = rtrim($query,";");
235 mysql_query("$query",$dbh);
236 $query = "";
239 echo "OK<br>\n";
240 fclose($fd);
241 flush();
242 echo "Adding Initial User...\n";
243 flush();
244 $iuser = $_POST["iuser"];
245 $iuname = $_POST["iuname"];
246 $igroup = $_POST["igroup"];
247 //echo "INSERT INTO groups VALUES (1,'$igroup','$iuser')<br>\n";
248 if (mysql_query("INSERT INTO groups (id, name, user) VALUES (1,'$igroup','$iuser')") == FALSE) {
249 echo "ERROR. Could not run queries.\n";
250 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
251 flush();
252 break;
254 if (mysql_query("INSERT INTO users (id, username, password, authorized, lname,fname) VALUES (1,'$iuser','1a1dc91c907325c69271ddf0c944bc72',1,'$iuname','')") == FALSE) {
255 echo "ERROR. Could not run queries.\n";
256 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
257 flush();
258 break;
260 echo "OK<br>\n";
261 flush();
262 /* echo "Inserting ICD-9-CM Codes into Database...\n";
263 flush();
264 $fd = fopen($icd9, 'r');
265 if ($fd == FALSE) {
266 echo "ERROR. Could not open dumpfile.\n";
267 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
268 flush();
269 break;
271 $query = "";
272 $line = "";
273 while (!feof ($fd)){
274 $line = fgets($fd,1024);
275 $line = rtrim($line);
276 if (substr($line,0,2) == "--") // Kill comments
277 continue;
278 if (substr($line,0,1) == "#") // Kill comments
279 continue;
280 if ($line == "")
281 continue;
282 $query = $query.$line; // Check for full query
283 $chr = substr($query,strlen($query)-1,1);
284 if ($chr == ";") { // valid query, execute
285 $query = rtrim($query,";");
286 mysql_query("$query",$dbh);
287 $query = "";
290 echo "OK\n";
291 fclose($fd);*/
292 flush();
294 echo "\n<br>Please make sure 'library/sqlconf.php' is world-writeable for the next step.<br>\n";
297 echo "
298 <FORM METHOD='POST'>\n
299 <INPUT TYPE='HIDDEN' NAME='state' VALUE='4'>
300 <INPUT TYPE='HIDDEN' NAME='host' VALUE='$server'>
301 <INPUT TYPE='HIDDEN' NAME='dbname' VALUE='$dbname'>
302 <INPUT TYPE='HIDDEN' NAME='port' VALUE='$port'>
303 <INPUT TYPE='HIDDEN' NAME='login' VALUE='$login'>
304 <INPUT TYPE='HIDDEN' NAME='pass' VALUE='$pass'>
305 <br>\n
306 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
309 break;
311 case 4:
312 echo "<b>Step $state</b><br><br>\n";
313 echo "Writing SQL Configuration to disk...\n";
314 @touch($conffile); // php bug
315 $fd = @fopen($conffile, 'w');
316 if ($fd == FALSE) {
317 echo "ERROR. Could not open config file '$conffile' for writing.\n";
318 flush();
319 break;
321 $string = "<?
322 // OpenEMR
323 // MySQL Config
324 // Referenced from sql.inc
328 $it_died = 0; //fmg: variable keeps running track of any errors
330 fwrite($fd,$string) or $it_died++;
331 fwrite($fd,"\$host\t= '$host';\n") or $it_died++;
332 fwrite($fd,"\$port\t= '$port';\n") or $it_died++;
333 fwrite($fd,"\$login\t= '$login';\n") or $it_died++;
334 fwrite($fd,"\$pass\t= '$pass';\n") or $it_died++;
335 fwrite($fd,"\$dbase\t= '$dbname';\n") or $it_died++;
338 $string = '
340 $sqlconf = array();
341 $sqlconf["host"]= $host;
342 $sqlconf["port"] = $port;
343 $sqlconf["login"] = $login;
344 $sqlconf["pass"] = $pass;
345 $sqlconf["dbase"] = $dbase;
346 //////////////////////////
347 //////////////////////////
348 //////////////////////////
349 //////DO NOT TOUCH THIS///
350 $config = 1; /////////////
351 //////////////////////////
352 //////////////////////////
353 //////////////////////////
356 ?><? // done just for coloring
358 fwrite($fd,$string) or $it_died++;
360 //it's rather irresponsible to not report errors when writing this file.
361 if ($it_died != 0) {
362 echo "ERROR. Couldn't write $it_died lines to config file '$conffile'.\n";
363 flush();
364 break;
366 fclose($fd);
368 echo "OK<BR>\nPlease restore secure permissions on the 'library/sqlconf.php' file now.\n<br><FORM METHOD='POST'>\n
369 <INPUT TYPE='HIDDEN' NAME='state' VALUE='5'>\n
370 <br>\n
371 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
373 break;
375 case 0:
376 default:
377 echo "Welcome to Pennington Firm 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";
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>