bug fix for Windows to allow moving of documents between patients
[openemr.git] / setup.php
blob9180ec19d3a56dd51f87ce673113b02dc8b3d57d
1 <?php
2 // This program is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU General Public License
4 // as published by the Free Software Foundation; either version 2
5 // of the License, or (at your option) any later version.
7 // Dummy xl function so things needing it will work.
8 function xl($s) {
9 return $s;
12 //required for normal operation because of recent changes in PHP:
13 extract($_GET);
14 extract($_POST);
15 //turn off PHP compatibility warnings
16 ini_set("session.bug_compat_warn","off");
18 $url = "";
19 $upgrade = 0;
20 $state = $_POST["state"];
22 // Make this true for IPPF.
23 $ippf_specific = false;
25 //If having problems with file and directory permission
26 // checking, then can be manually disabled here.
27 $checkPermissions = "TRUE";
29 //Below section is only for variables that require a path.
30 // The $manualPath variable can be edited by 3rd party
31 // installation scripts to manually set path. (this will
32 // allow straightforward use of this script by 3rd party
33 // installers)
34 $manualPath = "";
35 $dumpfile = $manualPath."sql/database.sql";
36 $translations_dumpfile_utf8 = $manualPath."contrib/util/language_translations/currentLanguage_utf8.sql";
37 $translations_dumpfile_latin1 = $manualPath."contrib/util/language_translations/currentLanguage_latin1.sql";
38 $icd9 = $manualPath."sql/icd9.sql";
39 $conffile = $manualPath."library/sqlconf.php";
40 $conffile2 = $manualPath."interface/globals.php";
41 $docsDirectory = $manualPath."documents";
42 $billingDirectory = $manualPath."edi";
43 $billingDirectory2 = $manualPath."era";
44 $billingLogDirectory = $manualPath."library/freeb";
45 $lettersDirectory = $manualPath."custom/letter_templates";
46 $gaclWritableDirectory = $manualPath."gacl/admin/templates_c";
47 $requiredDirectory1 = $manualPath."interface/main/calendar/modules/PostCalendar/pntemplates/compiled";
48 $requiredDirectory2 = $manualPath."interface/main/calendar/modules/PostCalendar/pntemplates/cache";
49 $gaclSetupScript1 = $manualPath."gacl/setup.php";
50 $gaclSetupScript2 = $manualPath."acl_setup.php";
52 //These are files and dir checked before install for
53 // correct permissions.
54 // $writableFileList = array($conffile, $conffile2);
55 $writableFileList = array($conffile);
56 $writableDirList = array($docsDirectory, $billingDirectory, $billingDirectory2, $billingLogDirectory, $lettersDirectory, $gaclWritableDirectory, $requiredDirectory1, $requiredDirectory2);
58 //These are the dumpfiles that are loaded into database
59 // The subsequent array holds the title of dumpfiles
60 $dumpfiles = array($dumpfile);
61 $dumpfilesTitles = array("Main");
63 include_once($conffile);
65 <HTML>
66 <HEAD>
67 <TITLE>OpenEMR Setup Tool</TITLE>
68 <LINK REL=STYLESHEET HREF="interface/themes/style_blue.css">
69 </HEAD>
70 <BODY>
72 <span class="title">OpenEMR Setup</span>
73 <br><br>
74 <span class="text">
76 <?php
77 if (strtolower(ini_get('register_globals')) != 'off' && (bool) ini_get('register_globals')) {
78 echo "It appears that you have register_globals enabled in your php.ini\n" .
79 "configuration file. This causes unacceptable security risks. You must\n" .
80 "turn it off before continuing with installation.\n";
81 exit();
83 ?>
85 <?php
86 if ($state == 7) {
89 <p>Congratulations! OpenEMR is now installed.</p>
91 <ul>
92 <li>Access controls (php-GACL) are installed for fine-grained security, and can be administered in
93 OpenEMR's admin->acl menu.</li>
94 <li>Reading openemr/includes/config.php and openemr/interface/globals.php is a good idea. These files
95 contain many options to choose from including themes.</li>
96 <li>There's much information and many extra tools bundled within the OpenEMR installation directory.
97 Please refer to openemr/Documentation. Many forms and other useful scripts can be found at openemr/contrib.</li>
98 <li>To ensure a consistent look and feel through out the application using
99 <a href='http://www.mozilla.org/products/firefox/'>Firefox</a> is recommended.</li>
100 <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>
101 <li>The OpenEMR forums can be found at <a href = "http://sourceforge.net/projects/openemr" target="_blank">http://sourceforge.net/projects/openemr</a></li>
102 <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@openmedsoftware.org">drbowen@openmedsoftware.org</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>
103 </ul>
105 We recommend you print these instructions for future reference.
106 </p>
108 <b>The initial OpenEMR user is "<?php echo $iuser; ?>" and the password is "pass".</b>
109 You should change this password!
110 </p>
112 If you edited the PHP or Apache configuration files during this installation process, then we recommend you restart your Apache server before following below OpenEMR link.
113 </p>
115 <a href='./'>Click here to start using OpenEMR. </a>
116 </p>
118 <?php
119 exit();
123 <?php
125 $server = $_POST["server"];
126 $port = $_POST["port"];
127 $dbname = $_POST["dbname"];
128 $root = $_POST["root"];
129 $login = $_POST["login"];
130 $pass = $_POST["pass"];
131 $loginhost = $_POST["loginhost"];
132 $collate = $_POST["collate"];
133 $rootpass = $_POST["rootpass"];
134 $iuser = $_POST["iuser"];
135 $iuname = $_POST["iuname"];
136 $igroup = $_POST["igroup"];
138 /*******************************************************************
139 $openemrBasePath = $_POST["openemrBasePath"];
140 $openemrWebPath = $_POST["openemrWebPath"];
141 *******************************************************************/
143 //END POST VARIABLES
146 if (($config == 1) && ($state < 4)) {
147 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";
149 else {
150 switch ($state) {
152 case 1:
153 echo "<b>Step $state</b><br><br>\n";
154 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
155 <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>
156 <br><br>\n
157 <FORM METHOD='POST'>\n
158 <INPUT TYPE='HIDDEN' NAME='state' VALUE='2'>\n
159 <INPUT TYPE='RADIO' NAME='inst' VALUE='1' checked>Have setup create the database<br>\n
160 <INPUT TYPE='RADIO' NAME='inst' VALUE='2'>I have already created the database<br>\n
161 <br>\n
162 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
163 break;
165 case 2:
166 echo "<b>Step $state</b><br><br>\n";
167 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.
168 <br><br>\n
169 <FORM METHOD='POST'>
170 <INPUT TYPE='HIDDEN' NAME='state' VALUE='3'>
171 <INPUT TYPE='HIDDEN' NAME='inst' VALUE='$inst'>
172 <TABLE>\n
173 <TR VALIGN='TOP'><TD COLSPAN=2><font color='red'>MYSQL SERVER:</font></TD></TR>
174 <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>
175 <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>
176 <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>
177 <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>
178 <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";
179 if ($inst != 2) {
180 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>
181 <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";
182 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>";
183 echo "<TR VALIGN='TOP'><TD><span class='text'>UTF-8 Collation: </span></TD><TD colspan='2'>" .
184 "<select name='collate'>" .
185 "<option value='utf8_bin' >Bin</option>" .
186 "<option value='utf8_czech_ci' >Czech</option>" .
187 "<option value='utf8_danish_ci' >Danish</option>" .
188 "<option value='utf8_esperanto_ci' >Esperanto</option>" .
189 "<option value='utf8_estonian_ci' >Estonian</option>" .
190 "<option value='utf8_general_ci' selected>General</option>" .
191 "<option value='utf8_hungarian_ci' >Hungarian</option>" .
192 "<option value='utf8_icelandic_ci' >Icelandic</option>" .
193 "<option value='utf8_latvian_ci' >Latvian</option>" .
194 "<option value='utf8_lithuanian_ci'>Lithuanian</option>" .
195 "<option value='utf8_persian_ci' >Persian</option>" .
196 "<option value='utf8_polish_ci' >Polish</option>" .
197 "<option value='utf8_roman_ci' >Roman</option>" .
198 "<option value='utf8_romanian_ci' >Romanian</option>" .
199 "<option value='utf8_slovak_ci' >Slovak</option>" .
200 "<option value='utf8_slovenian_ci' >Slovenian</option>" .
201 "<option value='utf8_spanish2_ci' >Spanish2 (Traditional)</option>" .
202 "<option value='utf8_spanish_ci' >Spanish (Modern)</option>" .
203 "<option value='utf8_swedish_ci' >Swedish</option>" .
204 "<option value='utf8_turkish_ci' >Turkish</option>" .
205 "<option value='utf8_unicode_ci' >Unicode (German, French, Russian, Armenian, Greek)</option>" .
206 "<option value='' >None (Do not force UTF-8)</option>" .
207 "</select>" .
208 "</TD></TR><TR VALIGN='TOP'><TD>&nbsp;</TD><TD colspan='2'><span class='text'>(This is the collation setting for mysql. Leave as 'General' if you are not sure. If the language you are planning to use in OpenEMR is in the menu, then you can select it. Otherwise, just select 'General'.)</span><br></TD></TR>";
210 echo "<TR VALIGN='TOP'><TD>&nbsp;</TD></TR>";
211 echo "<TR VALIGN='TOP'><TD COLSPAN=2><font color='red'>OPENEMR USER:</font></TD></TR>";
212 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>
213 <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>
214 <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>
216 echo "<TR VALIGN='TOP'><TD>&nbsp;</TD></TR>";
218 /*********************************************************************
219 echo "<TR VALIGN='TOP'><TD COLSPAN=2><font color='red'>OPENEMR PATHS:</font></TD></TR>";
220 echo "<TR VALIGN='TOP'><TD COLSPAN=3></TD></TR>
221 <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>
222 <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>
224 *********************************************************************/
226 echo "</TABLE>
227 <br>
228 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>";
230 break;
233 case 3:
235 if ($login == "" || !isset($login)) {
236 echo "ERROR. Please pick a proper 'Login Name'.<br>\n";
237 echo "Click Back in browser to re-enter.<br>\n";
238 break;
240 if (strpos($iuser, " ")) {
241 echo "ERROR. The 'Initial User' field can only contain one word and no spaces.<br>\n";
242 echo "Click Back in browser to re-enter.<br>\n";
243 break;
245 if ($pass == "" || !isset($pass)) {
246 echo "ERROR. Please pick a proper 'Password'.<br>\n";
247 echo "Click Back in browser to re-enter.<br>\n";
248 break;
251 echo "<b>Step $state</b><br><br>\n";
252 echo "Configuring OpenEMR...<br><br>\n";
255 if ($inst != 2) {
256 echo "Connecting to MySQL Server...\n";
257 flush();
258 if ($server == "localhost")
259 $dbh = mysql_connect("$server","$root","$rootpass");
260 else
261 $dbh = mysql_connect("$server:$port","$root","$rootpass");
262 if ($dbh == FALSE) {
263 echo "ERROR. Check your login credentials.\n";
264 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
265 break;
267 else
268 echo "OK.<br>\n";
269 echo "Creating database...\n";
270 flush();
271 $sql = "create database $dbname";
272 if ($collate) {
273 $sql .= " character set utf8 collate $collate";
274 mysql_query("SET NAMES 'utf8'", $dbh);
276 if (mysql_query($sql, $dbh) == FALSE) {
277 echo "ERROR. Check your login credentials.\n";
278 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
279 break;
281 else
282 echo "OK.<br>\n";
283 echo "Creating user with permissions for database...\n";
284 flush();
285 if (mysql_query("GRANT ALL PRIVILEGES ON $dbname.* TO '$login'@'$loginhost' IDENTIFIED BY '$pass'",$dbh) == FALSE) {
286 echo "ERROR when granting privileges to the specified user.\n";
287 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
288 echo "ERROR.\n";
289 break;
291 else
292 echo "OK.<br>\n";
293 echo "Reconnecting as new user...\n";
294 mysql_close($dbh);
296 else
297 echo "Connecting to MySQL Server...\n";
299 if ($server == "localhost")
300 $dbh = mysql_connect("$server","$login","$pass");
301 else
302 $dbh = mysql_connect("$server:$port","$login","$pass");
304 if ($dbh == FALSE) {
305 echo "ERROR. Check your login credentials.\n";
306 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
307 break;
309 else {
310 if ($collate) {
311 mysql_query("SET NAMES 'utf8'", $dbh);
313 echo "OK.<br>\n";
315 echo "Opening database...";
316 flush();
317 if (mysql_select_db("$dbname",$dbh) == FALSE) {
318 echo "ERROR. Check your login credentials.\n";
319 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
320 break;
322 else
323 echo "OK.<br>\n";
324 flush();
325 if ($upgrade != 1) {
327 //select the correct translation dumpfile
328 if ($collate) {
329 array_push($dumpfiles,$translations_dumpfile_utf8);
330 array_push($dumpfilesTitles,"Language Translation (utf8)");
332 else {
333 array_push($dumpfiles,$translations_dumpfile_latin1);
334 array_push($dumpfilesTitles,"Language Translation (latin1)");
337 // Deal with IPPF-specific SQL.
338 if ($ippf_specific) {
339 array_push($dumpfiles, $manualPath . "sql/ippf_layout.sql");
340 array_push($dumpfilesTitles, "IPPF Layout");
343 $dumpfileCounter = 0;
344 foreach ($dumpfiles as $var) {
345 echo "Creating ".$dumpfilesTitles[$dumpfileCounter]." tables...\n";
346 mysql_query("USE $dbname",$dbh);
347 flush();
348 $fd = fopen($var, 'r');
349 if ($fd == FALSE) {
350 echo "ERROR. Could not open dumpfile '$dumpfile'.\n";
351 flush();
352 break;
354 $query = "";
355 $line = "";
356 while (!feof ($fd)){
357 $line = fgets($fd,1024);
358 $line = rtrim($line);
359 if (substr($line,0,2) == "--") // Kill comments
360 continue;
361 if (substr($line,0,1) == "#") // Kill comments
362 continue;
363 if ($line == "")
364 continue;
365 $query = $query.$line; // Check for full query
366 $chr = substr($query,strlen($query)-1,1);
367 if ($chr == ";") { // valid query, execute
368 $query = rtrim($query,";");
369 if (!mysql_query($query, $dbh)) {
370 echo "<p>ERROR. Query failed: \"$query\"\n";
371 echo "<br />" . mysql_error() . " (#" . mysql_errno() . ")</p>\n";
373 $query = "";
376 echo "OK<br>\n";
377 fclose($fd);
378 flush();
379 $dumpfileCounter++;
381 echo "Adding Initial User...\n";
382 flush();
383 //echo "INSERT INTO groups VALUES (1,'$igroup','$iuser')<br>\n";
384 if (mysql_query("INSERT INTO groups (id, name, user) VALUES (1,'$igroup','$iuser')") == FALSE) {
385 echo "ERROR. Could not run queries.\n";
386 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
387 flush();
388 break;
390 if (mysql_query("INSERT INTO users (id, username, password, authorized, lname, fname, facility_id, calendar, cal_ui) VALUES (1,'$iuser','1a1dc91c907325c69271ddf0c944bc72',1,'$iuname','',3,1,3)") == FALSE) {
391 echo "ERROR. Could not run queries.\n";
392 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
393 flush();
394 break;
396 echo "OK<br>\n";
397 flush();
399 /* echo "Inserting ICD-9-CM Codes into Database...\n";
400 flush();
401 $fd = fopen($icd9, 'r');
402 if ($fd == FALSE) {
403 echo "ERROR. Could not open dumpfile.\n";
404 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
405 flush();
406 break;
408 $query = "";
409 $line = "";
410 while (!feof ($fd)){
411 $line = fgets($fd,1024);
412 $line = rtrim($line);
413 if (substr($line,0,2) == "--") // Kill comments
414 continue;
415 if (substr($line,0,1) == "#") // Kill comments
416 continue;
417 if ($line == "")
418 continue;
419 $query = $query.$line; // Check for full query
420 $chr = substr($query,strlen($query)-1,1);
421 if ($chr == ";") { // valid query, execute
422 $query = rtrim($query,";");
423 mysql_query("$query",$dbh);
424 $query = "";
427 echo "OK\n";
428 fclose($fd);*/
430 flush();
433 echo "<br>Writing SQL Configuration...<br>";
434 @touch($conffile); // php bug
435 $fd = @fopen($conffile, 'w');
436 $string = "<?php
437 // OpenEMR
438 // MySQL Config
439 // Referenced from sql.inc
443 $it_died = 0; //fmg: variable keeps running track of any errors
445 fwrite($fd,$string) or $it_died++;
446 fwrite($fd,"\$host\t= '$server';\n") or $it_died++;
447 fwrite($fd,"\$port\t= '$port';\n") or $it_died++;
448 fwrite($fd,"\$login\t= '$login';\n") or $it_died++;
449 fwrite($fd,"\$pass\t= '$pass';\n") or $it_died++;
450 fwrite($fd,"\$dbase\t= '$dbname';\n\n") or $it_died++;
451 fwrite($fd,"//Added ability to disable\n") or $it_died++;
452 fwrite($fd,"//utf8 encoding - bm 05-2009\n") or $it_died++;
453 fwrite($fd,"\$disable_utf8_flag = false;\n") or $it_died++;
455 $string = '
456 $sqlconf = array();
457 $sqlconf["host"]= $host;
458 $sqlconf["port"] = $port;
459 $sqlconf["login"] = $login;
460 $sqlconf["pass"] = $pass;
461 $sqlconf["dbase"] = $dbase;
462 //////////////////////////
463 //////////////////////////
464 //////////////////////////
465 //////DO NOT TOUCH THIS///
466 $config = 1; /////////////
467 //////////////////////////
468 //////////////////////////
469 //////////////////////////
472 ?><?php // done just for coloring
474 fwrite($fd,$string) or $it_died++;
476 //it's rather irresponsible to not report errors when writing this file.
477 if ($it_died != 0) {
478 echo "ERROR. Couldn't write $it_died lines to config file '$conffile'.\n";
479 flush();
480 break;
482 fclose($fd);
484 echo "Successfully wrote SQL configuration.<BR><br>";
486 /*********************************************************************
487 echo "Writing OpenEMR webserver paths to config file...<br>";
488 //edit interface/globals.php
489 //first, ensure slashes are in correct direction (windows specific fix)
490 $openemrBasePath = str_replace('\\\\', '/', $openemrBasePath);
491 $openemrBasePath = str_replace('\\', '/', $openemrBasePath);
492 $openemrWebPath = str_replace('\\\\', '/', $openemrWebPath);
493 $openemrWebPath = str_replace('\\', '/', $openemrWebPath);
494 //second, edit file (web paths and set UTF8 if pertinent)
495 $data = file($conffile2) or die("Could not read ".$conffile2." file.");
496 $finalData = "";
497 $isCount = 0;
498 foreach ($data as $line) {
499 $isHit = 0;
500 if ((strpos($line,"\$webserver_root = \"")) === false) {
502 else {
503 $isHit = 1;
504 $isCount += 1;
505 $finalData .= "\$webserver_root = \"$openemrBasePath\";\n";
507 if ((strpos($line,"\$web_root = \"")) === false) {
509 else {
510 $isHit = 1;
511 $isCount += 1;
512 $finalData .= "\$web_root = \"$openemrWebPath\";\n";
514 if (!$isHit) {
515 $finalData .= $line;
518 $fd = @fopen($conffile2, 'w') or die("Could not open ".$conffile2." file.");
519 fwrite($fd, $finalData);
520 fclose($fd);
521 if ($isCount == 2) {
522 echo "Successfully wrote OpenEMR webserver paths to config file<br><br>";
524 else {
525 echo "<FONT COLOR='red'>ERROR</FONT> writing openemr webserver root paths to config file ($conffile2). ($isCount)<br><br>\n";
527 *********************************************************************/
529 echo "Writing global configuration defaults...<br>";
530 require_once("library/globals.inc.php");
531 foreach ($GLOBALS_METADATA as $grpname => $grparr) {
532 foreach ($grparr as $fldid => $fldarr) {
533 list($fldname, $fldtype, $flddef, $flddesc) = $fldarr;
534 if (substr($fldtype, 0, 2) !== 'm_') {
535 $res = mysql_query("SELECT count(*) AS count FROM globals WHERE gl_name = '$fldid'");
536 $row = @mysql_fetch_array($res, MYSQL_ASSOC);
537 if (empty($row['count'])) {
538 mysql_query("INSERT INTO globals ( gl_name, gl_index, gl_value ) " .
539 "VALUES ( '$fldid', '0', '$flddef' )");
544 echo "Successfully wrote global configuration defaults.<br><br>";
546 echo "\n<br>Next step will install and configure access controls (php-GACL).<br>\n";
548 echo "
549 <FORM METHOD='POST'>\n
550 <INPUT TYPE='HIDDEN' NAME='state' VALUE='4'>
551 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$iuser'>
552 <INPUT TYPE='HIDDEN' NAME='iuname' VALUE='$iuname'>
553 <br>\n
554 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
557 break;
559 case 4:
560 echo "<b>Step $state</b><br><br>\n";
561 echo "Installing and Configuring Access Controls (php-GACL)...<br><br>";
563 //run gacl config scripts, all sql config data now in sqlconf.php file
564 require $gaclSetupScript1;
565 require $gaclSetupScript2;
566 echo "<br>";
568 //give the administrator user admin priviledges
569 $groupArray = array("Administrators");
570 set_user_aro($groupArray,$iuser,$iuname,"","");
571 echo "Gave the '$iuser' user (password is 'pass') administrator access.<br><br>";
573 echo "Done installing and configuring access controls (php-GACL).<br>";
574 echo "Next step will configure PHP.";
576 echo "<br><FORM METHOD='POST'>\n
577 <INPUT TYPE='HIDDEN' NAME='state' VALUE='5'>\n
578 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$iuser'>\n
579 <br>\n
580 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
582 break;
584 case 5:
585 echo "<b>Step $state</b><br><br>\n";
586 echo "Configuration of PHP...<br><br>\n";
587 echo "We recommend making the following changes to your PHP installation, which can normally be done by editing the php.ini configuration file:\n";
588 echo "<ul>";
589 $gotFileFlag = 0;
590 if (version_compare(PHP_VERSION, '5.2.4', '>=')) {
591 $phpINIfile = php_ini_loaded_file();
592 if ($phpINIfile) {
593 echo "<li><font color='green'>Your php.ini file can be found at ".$phpINIfile."</font></li>\n";
594 $gotFileFlag = 1;
597 echo "<li>To ensure proper functioning of OpenEMR you must make sure that settings in php.ini file include \"short_open_tag = On\", \"display_errors = Off\", \"register_globals = Off\", \"magic_quotes_gpc = On\", \"max_execution_time\" set to at least 60, \"max_input_time\" set to at least 90, and \"memory_limit\" set to at least \"128M\".</li>\n";
598 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";
599 if (!$gotFileFlag) {
600 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";
602 echo "</ul>";
604 echo "<br>We recommend you print these instructions for future reference.<br><br>";
605 echo "Next step will configure Apache web server.";
607 echo "<br><FORM METHOD='POST'>\n
608 <INPUT TYPE='HIDDEN' NAME='state' VALUE='6'>\n
609 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$iuser'>\n
610 <br>\n
611 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
613 break;
615 case 6:
616 echo "<b>Step $state</b><br><br>\n";
617 echo "Configuration of Apache web server...<br><br>\n";
618 echo "The \"".realpath($docsDirectory)."\", \"".realpath($billingDirectory)."\" and \"".realpath($billingDirectory2)."\" directories contain patient information, and
619 it is important to secure these directories. This can be done by placing pertinent .htaccess
620 files in these directories or by pasting the below to end of your apache configuration file:<br>
621 &nbsp;&nbsp;&lt;Directory ".realpath($docsDirectory)."&gt;<br>
622 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;order deny,allow<br>
623 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Deny from all<br>
624 &nbsp;&nbsp;&lt;/Directory&gt;<br>
625 &nbsp;&nbsp;&lt;Directory ".realpath($billingDirectory)."&gt;<br>
626 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;order deny,allow<br>
627 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Deny from all<br>
628 &nbsp;&nbsp;&lt;/Directory&gt;<br>
629 &nbsp;&nbsp;&lt;Directory ".realpath($billingDirectory2)."&gt;<br>
630 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;order deny,allow<br>
631 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Deny from all<br>
632 &nbsp;&nbsp;&lt;/Directory&gt;<br><br>";
634 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";
635 echo "<br>We recommend you print these instructions for future reference.<br><br>";
636 echo "Click 'continue' for further instructions.";
638 echo "<br><FORM METHOD='POST'>\n
639 <INPUT TYPE='HIDDEN' NAME='state' VALUE='7'>\n
640 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$iuser'>\n
641 <br>\n
642 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
644 break;
646 case 0:
647 default:
648 echo "<p>Welcome to OpenEMR. This utility will step you through the installation and configuration of OpenEMR for your practice.</p>\n";
649 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";
651 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";
653 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>";
655 if ($checkPermissions == "TRUE") {
656 echo "<p>We will now ensure correct file and directory permissions before starting installation:</p>\n";
657 echo "<FONT COLOR='green'>Ensuring following files are world-writable...</FONT><br>\n";
658 $errorWritable = 0;
659 foreach ($writableFileList as $tempFile) {
660 if (is_writable($tempFile)) {
661 echo "'".realpath($tempFile)."' file is <FONT COLOR='green'><b>ready</b></FONT>.<br>\n";
663 else {
664 echo "<p><FONT COLOR='red'>UNABLE</FONT> to open file '".realpath($tempFile)."' for writing.<br>\n";
665 echo "(configure file permissions; see below for further instructions)</p>\n";
666 $errorWritable = 1;
669 if ($errorWritable) {
670 echo "<p><FONT COLOR='red'>You can't proceed until all above files are ready (world-writable).</FONT><br>\n";
671 echo "In linux, recommend changing file permissions with the 'chmod 666 filename' command.<br>\n";
672 echo "Fix above file permissions and then click the 'Check Again' button to re-check files.<br>\n";
673 echo "<FORM METHOD='POST'><INPUT TYPE='SUBMIT' VALUE='Check Again'></p></FORM><br>\n";
674 break;
677 echo "<br><FONT COLOR='green'>Ensuring following directories have proper permissions...</FONT><br>\n";
678 $errorWritable = 0;
679 foreach ($writableDirList as $tempDir) {
680 if (is_writable($tempDir)) {
681 echo "'".realpath($tempDir)."' directory is <FONT COLOR='green'><b>ready</b></FONT>.<br>\n";
683 else {
684 echo "<p><FONT COLOR='red'>UNABLE</FONT> to open directory '".realpath($tempDir)."' for writing by web server.<br>\n";
685 echo "(configure directory permissions; see below for further instructions)</p>\n";
686 $errorWritable = 1;
689 if ($errorWritable) {
690 echo "<p><FONT COLOR='red'>You can't proceed until all directories are ready.</FONT><br>\n";
691 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";
692 echo "Fix above directory permissions and then click the 'Check Again' button to re-check directories.<br>\n";
693 echo "<FORM METHOD='POST'><INPUT TYPE='SUBMIT' VALUE='Check Again'></p></FORM><br>\n";
694 break;
697 echo "<br>All required files and directories have been verified. Click to continue installation.<br>\n";
699 else {
700 echo "<br>Click to continue installation.<br>\n";
703 echo "<FORM METHOD='POST'><INPUT TYPE='HIDDEN' NAME='state' VALUE='1'><INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>";
710 </span>
712 </BODY>
713 </HTML>