added daily report for ippf and moved some items to a new Statistics section
[openemr.git] / setup.php
blob8a612d4df7cddc2c26bbefeea05780e7ba2b5492
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 $upgrade = 0;
10 $state = $_POST["state"];
12 //If having problems with file and directory permission
13 // checking, then can be manually disabled here.
14 $checkPermissions = "TRUE";
16 //Below section is only for variables that require a path.
17 // The $manualPath variable can be edited by 3rd party
18 // installation scripts to manually set path. (this will
19 // allow straightforward use of this script by 3rd party
20 // installers)
21 $manualPath = "";
22 $dumpfile = $manualPath."sql/database.sql";
23 $icd9 = $manualPath."sql/icd9.sql";
24 $conffile = $manualPath."library/sqlconf.php";
25 $conffile2 = $manualPath."interface/globals.php";
26 $gaclConfigFile1 = $manualPath."gacl/gacl.ini.php";
27 $gaclConfigFile2 = $manualPath."gacl/gacl.class.php";
28 $docsDirectory = $manualPath."documents";
29 $billingDirectory = $manualPath."edi";
30 $billingDirectory2 = $manualPath."era";
31 $lettersDirectory = $manualPath."custom/letter_templates";
32 $gaclWritableDirectory = $manualPath."gacl/admin/templates_c";
33 $requiredDirectory1 = $manualPath."interface/main/calendar/modules/PostCalendar/pntemplates/compiled";
34 $requiredDirectory2 = $manualPath."interface/main/calendar/modules/PostCalendar/pntemplates/cache";
35 $gaclSetupScript1 = $manualPath."gacl/setup.php";
36 $gaclSetupScript2 = $manualPath."acl_setup.php";
38 //These are files and dir checked before install for
39 // correct permissions.
40 $writableFileList = array($conffile, $conffile2, $gaclConfigFile1, $gaclConfigFile2);
41 $writableDirList = array($docsDirectory, $billingDirectory, $billingDirectory2, $lettersDirectory, $gaclWritableDirectory, $requiredDirectory1, $requiredDirectory2);
44 include_once($conffile);
46 <HTML>
47 <HEAD>
48 <TITLE>OpenEMR Setup Tool</TITLE>
49 <LINK REL=STYLESHEET HREF="interface/themes/style_blue.css">
50 </HEAD>
51 <BODY>
53 <span class="title">OpenEMR Setup</span>
54 <br><br>
55 <span class="text">
57 <?php
58 if (strtolower(ini_get('register_globals')) != 'off' && (bool) ini_get('register_globals')) {
59 echo "It appears that you have register_globals enabled in your php.ini\n" .
60 "configuration file. This causes unacceptable security risks. You must\n" .
61 "turn it off before continuing with installation.\n";
62 exit();
64 ?>
66 <?php
67 if ($state == 7) {
70 <p>Congratulations! OpenEMR is now installed.</p>
72 <ul>
73 <li>If applicable, please restore secure permissions on the four configuration files: /openemr/interface/globals.php,
74 /openemr/library/sqlconf.php, /openemr/gacl/gacl.ini.php, and /openemr/gacl/gacl.class.php files.
75 In linux, recommend changing file permissions with the 'chmod 644 filename' command.</li>
76 <li>Access controls (php-GACL) are installed for fine-grained security, and can be administered in
77 OpenEMR's admin->acl menu.</li>
78 <li>Reading openemr/includes/config.php and openemr/interface/globals.php is a good idea. These files
79 contain many options to choose from including themes.</li>
80 <li>There's much information and many extra tools bundled within the OpenEMR installation directory.
81 Please refer to openemr/Documentation. Many forms and other useful scripts can be found at openemr/contrib.</li>
82 <li>To ensure a consistent look and feel through out the application using
83 <a href='http://www.mozilla.org/products/firefox/'>Firefox</a> is recommended.</li>
84 <li>The OpenEMR project home page and wiki can be found at <a href = "http://www.oemr.org" target="_blank">http://www.oemr.org</a></li>
85 <li>The OpenEMR forums can be found at <a href = "http://sourceforge.net/projects/openemr" target="_blank">http://sourceforge.net/projects/openemr</a></li>
86 <li>We pursue grants to help fund the future development of OpenEMR. To apply for these grants, we need to estimate how many times this program is installed and how many practices are evaluating or using this software. It would be awesome if you would email us at <a href="mailto:drbowen@charter.net">drbowen@charter.net</a> if you have installed this software. The more details about your plans with this software, the better, but even just sending us an email stating you just installed it is very helpful.</li>
87 </ul>
88 <p>
89 We recommend you print these instructions for future reference.
90 </p>
91 <p>
92 <b>The initial OpenEMR user is "<?php echo $iuser; ?>" and the password is "pass".</b>
93 You should change this password!
94 </p>
95 <p>
96 <a href='./'>Click here to start using OpenEMR. </a>
97 </p>
100 exit();
104 <?php
106 $server = $_POST["server"];
107 $port = $_POST["port"];
108 $dbname = $_POST["dbname"];
109 $root = $_POST["root"];
110 $login = $_POST["login"];
111 $pass = $_POST["pass"];
112 $loginhost = $_POST["loginhost"];
113 $rootpass = $_POST["rootpass"];
114 $iuser = $_POST["iuser"];
115 $iuname = $_POST["iuname"];
116 $igroup = $_POST["igroup"];
117 $openemrBasePath = $_POST["openemrBasePath"];
118 $openemrWebPath = $_POST["openemrWebPath"];
119 //END POST VARIABLES
122 if (($config == 1) && ($state < 4)) {
123 echo "OpenEMR has already been installed. If you wish to force re-installation, then edit $conffile(change the 'config' variable to 0), and re-run this script.<br>\n";
125 else {
126 switch ($state) {
128 case 1:
129 echo "<b>Step $state</b><br><br>\n";
130 echo "Now I need to know whether you want me to create the database on my own or if you have already created the database for me to use. For me to create the database, you will need to supply the MySQL root password.\n
131 <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>
132 <br><br>\n
133 <FORM METHOD='POST'>\n
134 <INPUT TYPE='HIDDEN' NAME='state' VALUE='2'>\n
135 <INPUT TYPE='RADIO' NAME='inst' VALUE='1' checked>Have setup create the database<br>\n
136 <INPUT TYPE='RADIO' NAME='inst' VALUE='2'>I have already created the database<br>\n
137 <br>\n
138 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
139 break;
141 case 2:
142 echo "<b>Step $state</b><br><br>\n";
143 echo "Now you need to supply the MySQL server information and path information. Detailed instructions on each item can be found in the <a href='INSTALL' target='_blank'><span STYLE='text-decoration: underline;'>'INSTALL'</span></a> manual file.
144 <br><br>\n
145 <FORM METHOD='POST'>
146 <INPUT TYPE='HIDDEN' NAME='state' VALUE='3'>
147 <INPUT TYPE='HIDDEN' NAME='inst' VALUE='$inst'>
148 <TABLE>\n
149 <TR VALIGN='TOP'><TD COLSPAN=2><font color='red'>MYSQL SERVER:</font></TD></TR>
150 <TR VALIGN='TOP'><TD><span class='text'>Server Host: </span></TD><TD><INPUT TYPE='TEXT' VALUE='localhost' NAME='server' SIZE='30'></TD><TD><span class='text'>(If you run MySQL and Apache/PHP on the same computer, then leave this as 'localhost'. If they are on separate computers, then enter the IP address of the computer running MySQL.)</span><br></TD></TR>
151 <TR VALIGN='TOP'><TD><span class='text'>Server Port: </span></TD><TD><INPUT TYPE='TEXT' VALUE='3306' NAME='port' SIZE='30'></TD><TD><span class='text'>(This is the MySQL port. The default port for MySQL is 3306.)</span><br></TD></TR>
152 <TR VALIGN='TOP'><TD><span class='text'>Database Name: </span></TD><TD><INPUT TYPE='TEXT' VALUE='openemr' NAME='dbname' SIZE='30'></TD><TD><span class='text'>(This is the name of the OpenEMR database in MySQL - 'openemr' is the recommended)</span><br></TD></TR>
153 <TR VALIGN='TOP'><TD><span class='text'>Login Name: </span></TD><TD><INPUT TYPE='TEXT' VALUE='openemr' NAME='login' SIZE='30'></TD><TD><span class='text'>(This is the name of the OpenEMR login name in MySQL - 'openemr' is the recommended)</span><br></TD></TR>
154 <TR VALIGN='TOP'><TD><span class='text'>Password: </span></TD><TD><INPUT TYPE='PASSWORD' VALUE='' NAME='pass' SIZE='30'></TD><TD><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";
155 if ($inst != 2) {
156 echo "<TR VALIGN='TOP'><TD><span class='text'>Name for Root Account: </span></TD><TD><INPUT TYPE='TEXT' VALUE='root' NAME='root' SIZE='30'></TD><TD><span class='text'>(This is name for MySQL root account. For localhost, it is usually ok to leave it 'root'.)</span><br></TD></TR>
157 <TR VALIGN='TOP'><TD><span class='text'>Root Pass: </span></TD><TD><INPUT TYPE='PASSWORD' VALUE='' NAME='rootpass' SIZE='30'></TD><TD><span class='text'>(This is your MySQL root password. For localhost, it is usually ok to leave it blank.)</span><br></TD></TR>\n";
158 echo "<TR VALIGN='TOP'><TD><span class='text'>User Hostname: </span></TD><TD><INPUT TYPE='TEXT' VALUE='localhost' NAME='loginhost' SIZE='30'></TD><TD><span class='text'>(If you run Apache/PHP and MySQL on the same computer, then leave this as 'localhost'. If they are on separate computers, then enter the IP address of the computer running Apache/PHP.)</span><br></TD></TR>";
160 echo "<TR VALIGN='TOP'><TD>&nbsp;</TD></TR>";
161 echo "<TR VALIGN='TOP'><TD COLSPAN=2><font color='red'>OPENEMR USER:</font></TD></TR>";
162 echo "<TR VALIGN='TOP'><TD><span class='text'>Initial User:</span></TD><TD><INPUT SIZE='30' TYPE='TEXT' NAME='iuser' VALUE='admin'></TD><TD><span class='text'>(This is the login name of user that will be created for you. Limit this to one word.)</span></TD></TR>
163 <TR VALIGN='TOP'><TD><span class='text'>Initial User's Name:</span></TD><TD><INPUT SIZE='30' TYPE='TEXT' NAME='iuname' VALUE='Administrator'></TD><TD><span class='text'>(This is the real name of the 'initial user'.)</span></TD></TR>
164 <TR VALIGN='TOP'><TD><span class='text'>Initial Group:</span></TD><TD><INPUT SIZE='30' TYPE='TEXT' NAME='igroup' VALUE='Default'></TD><TD><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>
166 echo "<TR VALIGN='TOP'><TD>&nbsp;</TD></TR>";
167 echo "<TR VALIGN='TOP'><TD COLSPAN=2><font color='red'>OPENEMR PATHS:</font></TD></TR>";
168 echo "<TR VALIGN='TOP'><TD COLSPAN=3></TD></TR>
169 <TR VALIGN='TOP'><TD><span class='text'>Absolute Path:</span></TD><TD><INPUT SIZE='30' TYPE='TEXT' NAME='openemrBasePath' VALUE='".realpath('./')."'></TD><TD><span class='text'>(This is the full absolute directory path to openemr. The value here is automatically created, and should not need to be modified. Do not worry about direction of slashes; they will be automatically corrected.)</span></TD></TR>
170 <TR VALIGN='TOP'><TD><span class='text'>Relative HTML Path:</span></TD><TD><INPUT SIZE='30' TYPE='TEXT' NAME='openemrWebPath' VALUE='/openemr'></TD><TD><span class='text'>(Set this to the relative html path, ie. what you would type into the web browser after the server address to get to OpenEMR. For example, if you type 'http://127.0.0.1/clinic/openemr/ to load OpenEMR, set this to '/clinic/openemr' without the trailing slash. Do not worry about direction of slashes; they will be automatically corrected.)</span></TD></TR>
172 echo "</TABLE>
173 <br>
174 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>";
176 break;
179 case 3:
181 if ($login == "" || !isset($login)) {
182 echo "ERROR. Please pick a proper 'Login Name'.<br>\n";
183 echo "Click Back in browser to re-enter.<br>\n";
184 break;
186 if (strpos($iuser, " ")) {
187 echo "ERROR. The 'Initial User' field can only contain one word and no spaces.<br>\n";
188 echo "Click Back in browser to re-enter.<br>\n";
189 break;
191 if ($pass == "" || !isset($pass)) {
192 echo "ERROR. Please pick a proper 'Password'.<br>\n";
193 echo "Click Back in browser to re-enter.<br>\n";
194 break;
197 echo "<b>Step $state</b><br><br>\n";
198 echo "Configuring OpenEMR...<br><br>\n";
201 if ($inst != 2) {
202 echo "Connecting to MySQL Server...\n";
203 flush();
204 if ($server == "localhost")
205 $dbh = mysql_connect("$server","$root","$rootpass");
206 else
207 $dbh = mysql_connect("$server:$port","$root","$rootpass");
208 if ($dbh == FALSE) {
209 echo "ERROR. Check your login credentials.\n";
210 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
211 break;
213 else
214 echo "OK.<br>\n";
215 echo "Creating database...\n";
216 flush();
217 if (mysql_query("create database $dbname",$dbh) == FALSE) {
218 echo "ERROR. Check your login credentials.\n";
219 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
220 break;
222 else
223 echo "OK.<br>\n";
224 echo "Creating user with permissions for database...\n";
225 flush();
226 if (mysql_query("GRANT ALL PRIVILEGES ON $dbname.* TO '$login'@'$loginhost' IDENTIFIED BY '$pass'",$dbh) == FALSE) {
227 echo "ERROR when granting privileges to the specified user.\n";
228 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
229 echo "ERROR.\n";
230 break;
232 else
233 echo "OK.<br>\n";
234 echo "Reconnecting as new user...\n";
235 mysql_close($dbh);
237 else
238 echo "Connecting to MySQL Server...\n";
240 if ($server == "localhost")
241 $dbh = mysql_connect("$server","$login","$pass");
242 else
243 $dbh = mysql_connect("$server:$port","$login","$pass");
245 if ($dbh == FALSE) {
246 echo "ERROR. Check your login credentials.\n";
247 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
248 break;
250 else
251 echo "OK.<br>\n";
252 echo "Opening database...";
253 flush();
254 if (mysql_select_db("$dbname",$dbh) == FALSE) {
255 echo "ERROR. Check your login credentials.\n";
256 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
257 break;
259 else
260 echo "OK.<br>\n";
261 flush();
262 if ($upgrade != 1) {
263 echo "Creating initial tables...\n";
264 mysql_query("USE $dbname",$dbh);
265 flush();
266 $fd = fopen($dumpfile, 'r');
267 if ($fd == FALSE) {
268 echo "ERROR. Could not open dumpfile '$dumpfile'.\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<br>\n";
292 fclose($fd);
293 flush();
294 echo "Adding Initial User...\n";
295 flush();
296 //echo "INSERT INTO groups VALUES (1,'$igroup','$iuser')<br>\n";
297 if (mysql_query("INSERT INTO groups (id, name, user) VALUES (1,'$igroup','$iuser')") == FALSE) {
298 echo "ERROR. Could not run queries.\n";
299 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
300 flush();
301 break;
303 if (mysql_query("INSERT INTO users (id, username, password, authorized, lname,fname) VALUES (1,'$iuser','1a1dc91c907325c69271ddf0c944bc72',1,'$iuname','')") == FALSE) {
304 echo "ERROR. Could not run queries.\n";
305 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
306 flush();
307 break;
309 echo "OK<br>\n";
310 flush();
311 /* echo "Inserting ICD-9-CM Codes into Database...\n";
312 flush();
313 $fd = fopen($icd9, 'r');
314 if ($fd == FALSE) {
315 echo "ERROR. Could not open dumpfile.\n";
316 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
317 flush();
318 break;
320 $query = "";
321 $line = "";
322 while (!feof ($fd)){
323 $line = fgets($fd,1024);
324 $line = rtrim($line);
325 if (substr($line,0,2) == "--") // Kill comments
326 continue;
327 if (substr($line,0,1) == "#") // Kill comments
328 continue;
329 if ($line == "")
330 continue;
331 $query = $query.$line; // Check for full query
332 $chr = substr($query,strlen($query)-1,1);
333 if ($chr == ";") { // valid query, execute
334 $query = rtrim($query,";");
335 mysql_query("$query",$dbh);
336 $query = "";
339 echo "OK\n";
340 fclose($fd);*/
341 flush();
344 echo "<br>Writing SQL Configuration...<br>";
345 @touch($conffile); // php bug
346 $fd = @fopen($conffile, 'w');
347 $string = "<?
348 // OpenEMR
349 // MySQL Config
350 // Referenced from sql.inc
354 $it_died = 0; //fmg: variable keeps running track of any errors
356 fwrite($fd,$string) or $it_died++;
357 fwrite($fd,"\$host\t= '$server';\n") or $it_died++;
358 fwrite($fd,"\$port\t= '$port';\n") or $it_died++;
359 fwrite($fd,"\$login\t= '$login';\n") or $it_died++;
360 fwrite($fd,"\$pass\t= '$pass';\n") or $it_died++;
361 fwrite($fd,"\$dbase\t= '$dbname';\n") or $it_died++;
364 $string = '
366 $sqlconf = array();
367 $sqlconf["host"]= $host;
368 $sqlconf["port"] = $port;
369 $sqlconf["login"] = $login;
370 $sqlconf["pass"] = $pass;
371 $sqlconf["dbase"] = $dbase;
372 //////////////////////////
373 //////////////////////////
374 //////////////////////////
375 //////DO NOT TOUCH THIS///
376 $config = 1; /////////////
377 //////////////////////////
378 //////////////////////////
379 //////////////////////////
382 ?><? // done just for coloring
384 fwrite($fd,$string) or $it_died++;
386 //it's rather irresponsible to not report errors when writing this file.
387 if ($it_died != 0) {
388 echo "ERROR. Couldn't write $it_died lines to config file '$conffile'.\n";
389 flush();
390 break;
392 fclose($fd);
394 echo "Successfully wrote SQL configuration.<BR><br>";
396 echo "Writing OpenEMR webserver paths to config file...<br>";
397 //edit interface/globals.php
398 //first, ensure slashes are in correct direction (windows specific fix)
399 $openemrBasePath = str_replace('\\\\', '/', $openemrBasePath);
400 $openemrBasePath = str_replace('\\', '/', $openemrBasePath);
401 $openemrWebPath = str_replace('\\\\', '/', $openemrWebPath);
402 $openemrWebPath = str_replace('\\', '/', $openemrWebPath);
403 //second, edit file
404 $data = file($conffile2) or die("Could not read ".$conffile2." file.");
405 $finalData = "";
406 $isCount = 0;
407 foreach ($data as $line) {
408 $isHit = 0;
409 if ((strpos($line,"\$webserver_root = \"")) === false) {
411 else {
412 $isHit = 1;
413 $isCount += 1;
414 $finalData .= "\$webserver_root = \"$openemrBasePath\";\n";
416 if ((strpos($line,"\$web_root = \"")) === false) {
418 else {
419 $isHit = 1;
420 $isCount += 1;
421 $finalData .= "\$web_root = \"$openemrWebPath\";\n";
423 if (!$isHit) {
424 $finalData .= $line;
427 $fd = @fopen($conffile2, 'w') or die("Could not open ".$conffile2." file.");
428 fwrite($fd, $finalData);
429 fclose($fd);
430 if ($isCount == 2) {
431 echo "Successfully wrote OpenEMR webserver paths to config file<br><br>";
433 else {
434 echo "<FONT COLOR='red'>ERROR</FONT> writing openemr webserver root paths to config file ($conffile2). ($isCount)<br><br>\n";
437 echo "\n<br>Next step will install and configure access controls (php-GACL).<br>\n";
439 echo "
440 <FORM METHOD='POST'>\n
441 <INPUT TYPE='HIDDEN' NAME='state' VALUE='4'>
442 <INPUT TYPE='HIDDEN' NAME='server' VALUE='$server'>
443 <INPUT TYPE='HIDDEN' NAME='dbname' VALUE='$dbname'>
444 <INPUT TYPE='HIDDEN' NAME='port' VALUE='$port'>
445 <INPUT TYPE='HIDDEN' NAME='login' VALUE='$login'>
446 <INPUT TYPE='HIDDEN' NAME='pass' VALUE='$pass'>
447 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$iuser'>
448 <INPUT TYPE='HIDDEN' NAME='iuname' VALUE='$iuname'>
449 <br>\n
450 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
453 break;
455 case 4:
456 echo "<b>Step $state</b><br><br>\n";
457 echo "Installing and Configuring Access Controls (php-GACL)...<br><br>";
459 //first, edit two gacl config files
460 echo "Writing php-GACL configuration settings to config files...<br>";
461 // edit gacl.ini.php
462 $data = file($gaclConfigFile1) or die("Could not read ".$gaclConfigFile1." file.");
463 $finalData = "";
464 foreach ($data as $line) {
465 $isHit = 0;
466 if ((strpos($line,"db_host")) === false) {
468 else {
469 $isHit = 1;
470 if ($server == "localhost") {
471 $finalData .= "db_host = \"${server}\"\n";
473 else {
474 $finalData .= "db_host = \"${server}:${port}\"\n";
477 if ((strpos($line,"db_user")) === false) {
479 else {
480 $isHit = 1;
481 $finalData .= "db_user = \"${login}\"\n";
483 if ((strpos($line,"db_password")) === false) {
485 else {
486 $isHit = 1;
487 $finalData .= "db_password = \"${pass}\"\n";
489 if ((strpos($line,"db_name")) === false) {
491 else {
492 $isHit = 1;
493 $finalData .= "db_name = \"${dbname}\"\n";
495 if (!$isHit) {
496 $finalData .= $line;
499 $fd = @fopen($gaclConfigFile1, 'w') or die("Could not open ".$gaclConfigFile1." file.");
500 fwrite($fd, $finalData);
501 fclose($fd);
503 // edit gacl.class.php
504 $data = file($gaclConfigFile2) or die("Could not read ".$gaclConfigFile2." file.");
505 $finalData = "";
506 foreach ($data as $line) {
507 $isHit = 0;
508 if ((strpos($line,"var \$_db_host = ")) === false) {
510 else {
511 $isHit = 1;
512 if ($server == "localhost") {
513 $finalData .= "var \$_db_host = '$server';\n";
515 else {
516 $finalData .= "var \$_db_host = '$server:$port';\n";
519 if ((strpos($line,"var \$_db_user = ")) === false) {
521 else {
522 $isHit = 1;
523 $finalData .= "var \$_db_user = '$login';\n";
525 if ((strpos($line,"var \$_db_password = ")) === false) {
527 else {
528 $isHit = 1;
529 $finalData .= "var \$_db_password = '$pass';\n";
531 if ((strpos($line,"var \$_db_name = ")) === false) {
533 else {
534 $isHit = 1;
535 $finalData .= "var \$_db_name = '$dbname';\n";
537 if (!$isHit) {
538 $finalData .= $line;
541 $fd = @fopen($gaclConfigFile2, 'w') or die("Could not open ".$gaclConfigFile2." file.");
542 fwrite($fd, $finalData);
543 fclose($fd);
544 echo "Finished writing php-GACL configuration settings to config files.<br><br>";
546 //second, run gacl config scripts
547 require $gaclSetupScript1;
548 require $gaclSetupScript2;
549 echo "<br>";
551 //third, give the administrator user admin priviledges
552 $groupArray = array("Administrators");
553 set_user_aro($groupArray,$iuser,$iuname,"","");
554 echo "Gave the '$iuser' user (password is 'pass') administrator access.<br><br>";
556 echo "Done installing and configuring access controls (php-GACL).<br>";
557 echo "Next step will configure PHP.";
559 echo "<br><FORM METHOD='POST'>\n
560 <INPUT TYPE='HIDDEN' NAME='state' VALUE='5'>\n
561 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$iuser'>\n
562 <br>\n
563 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
565 break;
567 case 5:
568 echo "<b>Step $state</b><br><br>\n";
569 echo "Configuration of PHP...<br><br>\n";
570 echo "We recommend making the following changes to your PHP installation, which can normally be done by editing the php.ini configuration file:\n";
571 echo "<ul>";
572 $gotFileFlag = 0;
573 if (version_compare(PHP_VERSION, '5.2.4', '>=')) {
574 $phpINIfile = php_ini_loaded_file();
575 if ($phpINIfile) {
576 echo "<li><font color='green'>Your php.ini file can be found at ".$phpINIfile."</font></li>\n";
577 $gotFileFlag = 1;
580 echo "<li>To ensure proper functioning of OpenEMR you must make sure that settings in php.ini file include \"display_errors = Off\", \"register_globals = Off\", \"magic_quotes_gpc = Off\", and \"memory_limit\" set to at least \"128M\".</li>\n";
581 echo "<li>In order to take full advantage of the patient documents capability you must make sure that settings in php.ini file include \"file_uploads = On\", that \"upload_max_filesize\" is appropriate for your use and that \"upload_tmp_dir\" is set to a correct value that will work on your system.</li>\n";
582 if (!$gotFileFlag) {
583 echo "<li>If you are having difficulty finding your php.ini file, then refer to the <a href='INSTALL' target='_blank'><span STYLE='text-decoration: underline;'>'INSTALL'</span></a> manual for suggestions.</li>\n";
585 echo "</ul>";
587 echo "<br>We recommend you print these instructions for future reference.<br><br>";
588 echo "Next step will configure Apache web server.";
590 echo "<br><FORM METHOD='POST'>\n
591 <INPUT TYPE='HIDDEN' NAME='state' VALUE='6'>\n
592 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$iuser'>\n
593 <br>\n
594 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
596 break;
598 case 6:
599 echo "<b>Step $state</b><br><br>\n";
600 echo "Configuration of Apache web server...<br><br>\n";
601 echo "The \"".realpath($docsDirectory)."\", \"".realpath($billingDirectory)."\" and \"".realpath($billingDirectory2)."\" directories contain patient information, and
602 it is important to secure these directories. This can be done by placing pertinent .htaccess
603 files in these directories or by pasting the below to end of your apache configuration file:<br>
604 &nbsp;&nbsp;&lt;Directory ".realpath($docsDirectory)."&gt;<br>
605 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;order deny,allow<br>
606 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Deny from all<br>
607 &nbsp;&nbsp;&lt;/Directory&gt;<br>
608 &nbsp;&nbsp;&lt;Directory ".realpath($billingDirectory)."&gt;<br>
609 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;order deny,allow<br>
610 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Deny from all<br>
611 &nbsp;&nbsp;&lt;/Directory&gt;<br>
612 &nbsp;&nbsp;&lt;Directory ".realpath($billingDirectory2)."&gt;<br>
613 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;order deny,allow<br>
614 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Deny from all<br>
615 &nbsp;&nbsp;&lt;/Directory&gt;<br><br>";
617 echo "If you are having difficulty finding your apache configuration file, then refer to the <a href='INSTALL' target='_blank'><span STYLE='text-decoration: underline;'>'INSTALL'</span></a> manual for suggestions.<br><br>\n";
618 echo "<br>We recommend you print these instructions for future reference.<br><br>";
619 echo "Click 'continue' for further instructions.";
621 echo "<br><FORM METHOD='POST'>\n
622 <INPUT TYPE='HIDDEN' NAME='state' VALUE='7'>\n
623 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$iuser'>\n
624 <br>\n
625 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
627 break;
629 case 0:
630 default:
631 echo "<p>Welcome to OpenEMR. This utility will step you through the installation and configuration of OpenEMR for your practice.</p>\n";
632 echo "<ul><li>Before proceeding, be sure that you have a properly installed and configured MySQL server available, and a PHP configured webserver.</li>\n";
634 echo "<li>Detailed installation instructions can be found in the <a href='INSTALL' target='_blank'><span STYLE='text-decoration: underline;'>'INSTALL'</span></a> manual file.</li>\n";
636 Echo "<li>If you are upgrading from a previous version, do NOT use this script. Please read the 'Upgrading' section found in the <a href='INSTALL' target='_blank'><span STYLE='text-decoration: underline;'>'INSTALL'</span></a> manual file.</li></ul>";
638 if ($checkPermissions == "TRUE") {
639 echo "<p>We will now ensure correct file and directory permissions before starting installation:</p>\n";
640 echo "<FONT COLOR='green'>Ensuring following files are world-writable...</FONT><br>\n";
641 $errorWritable = 0;
642 foreach ($writableFileList as $tempFile) {
643 if (is_writable($tempFile)) {
644 echo "'".realpath($tempFile)."' file is <FONT COLOR='green'><b>ready</b></FONT>.<br>\n";
646 else {
647 echo "<p><FONT COLOR='red'>UNABLE</FONT> to open file '".realpath($tempFile)."' for writing.<br>\n";
648 echo "(configure file permissions; see below for further instructions)</p>\n";
649 $errorWritable = 1;
652 if ($errorWritable) {
653 echo "<p><FONT COLOR='red'>You can't proceed until all above files are ready (world-writable).</FONT><br>\n";
654 echo "In linux, recommend changing file permissions with the 'chmod 666 filename' command.<br>\n";
655 echo "Fix above file permissions and then click the 'Check Again' button to re-check files.<br>\n";
656 echo "<FORM METHOD='POST'><INPUT TYPE='SUBMIT' VALUE='Check Again'></p></FORM><br>\n";
657 break;
660 echo "<br><FONT COLOR='green'>Ensuring following directories have proper permissions...</FONT><br>\n";
661 $errorWritable = 0;
662 foreach ($writableDirList as $tempDir) {
663 if (is_writable($tempDir)) {
664 echo "'".realpath($tempDir)."' directory is <FONT COLOR='green'><b>ready</b></FONT>.<br>\n";
666 else {
667 echo "<p><FONT COLOR='red'>UNABLE</FONT> to open directory '".realpath($tempDir)."' for writing by web server.<br>\n";
668 echo "(configure directory permissions; see below for further instructions)</p>\n";
669 $errorWritable = 1;
672 if ($errorWritable) {
673 echo "<p><FONT COLOR='red'>You can't proceed until all directories are ready.</FONT><br>\n";
674 echo "In linux, recommend changing owners of these directories to the web server. For example, in many linux OS's the web server user is 'apache', 'nobody', or 'www-data'. So if 'apache' were the web server user name, could use the command 'chown -R apache:apache directory_name' command.<br>\n";
675 echo "Fix above directory permissions and then click the 'Check Again' button to re-check directories.<br>\n";
676 echo "<FORM METHOD='POST'><INPUT TYPE='SUBMIT' VALUE='Check Again'></p></FORM><br>\n";
677 break;
680 echo "<br>All required files and directories have been verified. Click to continue installation.<br>\n";
682 else {
683 echo "<br>Click to continue installation.<br>\n";
686 echo "<FORM METHOD='POST'><INPUT TYPE='HIDDEN' NAME='state' VALUE='1'><INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>";
693 </span>
695 </BODY>
696 </HTML>