Merge branch 'master' of git://github.com/openemr/openemr
[openemr.git] / setup.php
blobf98ca65c9d7ed273a23c8025ed5e8ce84b60867f
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 $COMMAND_LINE = php_sapi_name() == 'cli';
9 // Dummy xl function so things needing it will work.
10 function xl($s) {
11 return $s;
14 // Directory copy logic borrowed from a user comment at
15 // http://www.php.net/manual/en/function.copy.php
16 function recurse_copy($src, $dst) {
17 $dir = opendir($src);
18 @mkdir($dst);
19 while(false !== ($file = readdir($dir))) {
20 if ($file != '.' && $file != '..') {
21 if (is_dir($src . '/' . $file)) {
22 recurse_copy($src . '/' . $file, $dst . '/' . $file);
24 else {
25 copy($src . '/' . $file, $dst . '/' . $file);
29 closedir($dir);
32 function write_sqlconf($conffile, $server, $port, $login, $pass, $dbname, $config='1') {
33 @touch($conffile); // php bug
34 $fd = @fopen($conffile, 'w');
35 $string = "<?php
36 // OpenEMR
37 // MySQL Config
38 // Referenced from sql.inc
42 $it_died = 0; //fmg: variable keeps running track of any errors
44 fwrite($fd, $string ) or $it_died++;
45 fwrite($fd, "\$host\t= '$server';\n" ) or $it_died++;
46 fwrite($fd, "\$port\t= '$port';\n" ) or $it_died++;
47 fwrite($fd, "\$login\t= '$login';\n" ) or $it_died++;
48 fwrite($fd, "\$pass\t= '$pass';\n" ) or $it_died++;
49 fwrite($fd, "\$dbase\t= '$dbname';\n\n" ) or $it_died++;
50 fwrite($fd, "//Added ability to disable\n" ) or $it_died++;
51 fwrite($fd, "//utf8 encoding - bm 05-2009\n") or $it_died++;
52 fwrite($fd, "\$disable_utf8_flag = false;\n") or $it_died++;
54 $string = '
55 $sqlconf = array();
56 $sqlconf["host"]= $host;
57 $sqlconf["port"] = $port;
58 $sqlconf["login"] = $login;
59 $sqlconf["pass"] = $pass;
60 $sqlconf["dbase"] = $dbase;
61 //////////////////////////
62 //////////////////////////
63 //////////////////////////
64 //////DO NOT TOUCH THIS///
65 $config = ' . $config . '; /////////////
66 //////////////////////////
67 //////////////////////////
68 //////////////////////////
72 fwrite($fd, $string) or $it_died++;
74 fclose($fd);
75 return $it_died;
78 //turn off PHP compatibility warnings
79 ini_set("session.bug_compat_warn","off");
81 $url = "";
82 $upgrade = 0;
83 $state = $_POST["state"];
85 // Make this true for IPPF.
86 $ippf_specific = false;
88 // If this script was invoked with no site ID, then ask for one.
89 if (!$COMMAND_LINE && empty($_REQUEST['site'])) {
90 echo "<html>\n";
91 echo "<head>\n";
92 echo "<title>OpenEMR Setup Tool</title>\n";
93 echo "<link rel='stylesheet' href='interface/themes/style_blue.css'>\n";
94 echo "</head>\n";
95 echo "<body>\n";
96 echo "<p><b>Optional Site ID Selection</b></p>\n";
97 echo "<p>Most OpenEMR installations support only one site. If that is " .
98 "true for you then ignore the rest of this text and just click Continue.</p>\n";
99 echo "<p>Otherwise please enter a unique Site ID here.</p>\n";
100 echo "<p>A Site ID is a short identifier with no spaces or special " .
101 "characters other than periods or dashes. It is case-sensitive and we " .
102 "suggest sticking to lower case letters for ease of use.</p>\n";
103 echo "<p>If each site will have its own host/domain name, then use that " .
104 "name as the Site ID (e.g. www.example.com).</p>\n";
105 echo "<p>The site ID is used to identify which site you will log in to. " .
106 "If it is a hostname then it is taken from the hostname in the URL. " .
107 "Otherwise you must append \"?site=<i>siteid</i>\" to the URL used for " .
108 "logging in.</p>\n";
109 echo "<p>It is OK for one of the sites to have \"default\" as its ID. This " .
110 "is the ID that will be used if it cannot otherwise be determined.</p>\n";
111 echo "<form method='post'><input type='hidden' name='state' value='0'>" .
112 "Site ID: <input type='text' name='site' value='default'>&nbsp;" .
113 "<input type='submit' value='Continue'><br></form><br>\n";
114 echo "</body></html>\n";
115 exit();
118 // Support "?site=siteid" in the URL, otherwise assume "default".
119 $site_id = 'default';
120 if (!$COMMAND_LINE && !empty($_REQUEST['site'])) {
121 $site_id = trim($_REQUEST['site']);
124 // Die if site ID is empty or has invalid characters.
125 if (empty($site_id) || preg_match('/[^A-Za-z0-9\\-.]/', $site_id))
126 die("Site ID '$site_id' contains invalid characters.");
128 //If having problems with file and directory permission
129 // checking, then can be manually disabled here.
130 $checkPermissions = "TRUE";
132 //Below section is only for variables that require a path.
133 // The $manualPath variable can be edited by 3rd party
134 // installation scripts to manually set path. (this will
135 // allow straightforward use of this script by 3rd party
136 // installers)
137 $manualPath = "";
139 $GLOBALS['OE_SITE_DIR'] = $manualPath . "sites/$site_id";
141 $dumpfile = $manualPath."sql/database.sql";
142 $translations_dumpfile_utf8 = $manualPath."contrib/util/language_translations/currentLanguage_utf8.sql";
143 $translations_dumpfile_latin1 = $manualPath."contrib/util/language_translations/currentLanguage_utf8.sql";
144 $icd9 = $manualPath."sql/icd9.sql";
145 $conffile = "$OE_SITE_DIR/sqlconf.php";
146 $conffile2 = $manualPath."interface/globals.php";
147 $docsDirectory = "$OE_SITE_DIR/documents";
148 $billingDirectory = "$OE_SITE_DIR/edi";
149 $billingDirectory2 = "$OE_SITE_DIR/era";
150 $billingLogDirectory = $manualPath."library/freeb";
151 $lettersDirectory = "$OE_SITE_DIR/letter_templates";
152 $gaclWritableDirectory = $manualPath."gacl/admin/templates_c";
153 $requiredDirectory1 = $manualPath."interface/main/calendar/modules/PostCalendar/pntemplates/compiled";
154 $requiredDirectory2 = $manualPath."interface/main/calendar/modules/PostCalendar/pntemplates/cache";
155 $gaclSetupScript1 = $manualPath."gacl/setup.php";
156 $gaclSetupScript2 = $manualPath."acl_setup.php";
158 //These are files and dir checked before install for
159 // correct permissions.
160 // $writableFileList = array($conffile, $conffile2);
161 $writableFileList = array($conffile);
162 $writableDirList = array($docsDirectory, $billingDirectory, $billingDirectory2, $billingLogDirectory, $lettersDirectory, $gaclWritableDirectory, $requiredDirectory1, $requiredDirectory2);
164 //These are the dumpfiles that are loaded into database
165 // The subsequent array holds the title of dumpfiles
166 $dumpfiles = array($dumpfile);
167 $dumpfilesTitles = array("Main");
169 // Create site directory if it is missing.
170 if (empty($state) && !file_exists($OE_SITE_DIR)) {
171 recurse_copy($manualpath . "sites/default", $OE_SITE_DIR);
172 write_sqlconf($conffile, 'localhost', '3306', 'openemr', 'openemr', 'openemr', '0');
175 include_once($conffile);
177 <HTML>
178 <HEAD>
179 <TITLE>OpenEMR Setup Tool</TITLE>
180 <LINK REL=STYLESHEET HREF="interface/themes/style_blue.css">
181 </HEAD>
182 <BODY>
184 <span class="title">OpenEMR Setup</span>
185 <br><br>
186 <span class="text">
188 <?php
189 if (strtolower(ini_get('register_globals')) != 'off' && (bool) ini_get('register_globals')) {
190 echo "It appears that you have register_globals enabled in your php.ini\n" .
191 "configuration file. This causes unacceptable security risks. You must\n" .
192 "turn it off before continuing with installation.\n";
193 exit();
197 <?php
198 if ($state == 7) {
199 $iuser = $_POST["iuser"];
202 <p>Congratulations! OpenEMR is now installed.</p>
204 <ul>
205 <li>Access controls (php-GACL) are installed for fine-grained security, and can be administered in
206 OpenEMR's admin->acl menu.</li>
207 <li>Reading <?php echo $OE_SITE_DIR; ?>/config.php and openemr/interface/globals.php is a good idea. These files
208 contain many options to choose from including themes.</li>
209 <li>There's much information and many extra tools bundled within the OpenEMR installation directory.
210 Please refer to openemr/Documentation. Many forms and other useful scripts can be found at openemr/contrib.</li>
211 <li>To ensure a consistent look and feel through out the application using
212 <a href='http://www.mozilla.org/products/firefox/'>Firefox</a> is recommended.</li>
213 <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>
214 <li>The OpenEMR forums can be found at <a href = "http://sourceforge.net/projects/openemr" target="_blank">http://sourceforge.net/projects/openemr</a></li>
215 <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>
216 </ul>
218 We recommend you print these instructions for future reference.
219 </p>
221 <b>The initial OpenEMR user is "<?php echo $iuser; ?>" and the password is "pass".</b>
222 You should change this password!
223 </p>
225 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.
226 </p>
228 <a href='./?site=<?php echo $site_id; ?>'>Click here to start using OpenEMR. </a>
229 </p>
231 <?php
232 exit();
236 <?php
238 $server = $_POST["server"];
239 $port = $_POST["port"];
240 $dbname = $_POST["dbname"];
241 $root = $_POST["root"];
242 $login = $_POST["login"];
243 $pass = $_POST["pass"];
244 $loginhost = $_POST["loginhost"];
245 $collate = $_POST["collate"];
246 $rootpass = $_POST["rootpass"];
247 $iuser = $_POST["iuser"];
248 $iuname = $_POST["iuname"];
249 $igroup = $_POST["igroup"];
250 $inst = $_POST["inst"];
252 /*******************************************************************
253 $openemrBasePath = $_POST["openemrBasePath"];
254 $openemrWebPath = $_POST["openemrWebPath"];
255 *******************************************************************/
257 //END POST VARIABLES
260 if (($config == 1) && ($state < 4)) {
261 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";
263 else {
264 switch ($state) {
266 case 1:
267 echo "<b>Step $state</b><br><br>\n";
268 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
269 <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>
270 <br><br>\n
271 <FORM METHOD='POST'>\n
272 <INPUT TYPE='HIDDEN' NAME='state' VALUE='2'>\n
273 <INPUT TYPE='HIDDEN' NAME='site' VALUE='$site_id'>\n
274 <INPUT TYPE='RADIO' NAME='inst' VALUE='1' checked>Have setup create the database<br>\n
275 <INPUT TYPE='RADIO' NAME='inst' VALUE='2'>I have already created the database<br>\n
276 <br>\n
277 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
278 break;
280 case 2:
281 echo "<b>Step $state</b><br><br>\n";
282 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.
283 <br><br>\n
284 <FORM METHOD='POST'>
285 <INPUT TYPE='HIDDEN' NAME='state' VALUE='3'>
286 <INPUT TYPE='HIDDEN' NAME='site' VALUE='$site_id'>\n
287 <INPUT TYPE='HIDDEN' NAME='inst' VALUE='$inst'>
288 <TABLE>\n
289 <TR VALIGN='TOP'><TD COLSPAN=2><font color='red'>MYSQL SERVER:</font></TD></TR>
290 <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>
291 <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>
292 <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>
293 <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>
294 <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";
295 if ($inst != 2) {
296 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>
297 <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";
298 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>";
299 echo "<TR VALIGN='TOP'><TD><span class='text'>UTF-8 Collation: </span></TD><TD colspan='2'>" .
300 "<select name='collate'>" .
301 "<option value='utf8_bin' >Bin</option>" .
302 "<option value='utf8_czech_ci' >Czech</option>" .
303 "<option value='utf8_danish_ci' >Danish</option>" .
304 "<option value='utf8_esperanto_ci' >Esperanto</option>" .
305 "<option value='utf8_estonian_ci' >Estonian</option>" .
306 "<option value='utf8_general_ci' selected>General</option>" .
307 "<option value='utf8_hungarian_ci' >Hungarian</option>" .
308 "<option value='utf8_icelandic_ci' >Icelandic</option>" .
309 "<option value='utf8_latvian_ci' >Latvian</option>" .
310 "<option value='utf8_lithuanian_ci'>Lithuanian</option>" .
311 "<option value='utf8_persian_ci' >Persian</option>" .
312 "<option value='utf8_polish_ci' >Polish</option>" .
313 "<option value='utf8_roman_ci' >Roman</option>" .
314 "<option value='utf8_romanian_ci' >Romanian</option>" .
315 "<option value='utf8_slovak_ci' >Slovak</option>" .
316 "<option value='utf8_slovenian_ci' >Slovenian</option>" .
317 "<option value='utf8_spanish2_ci' >Spanish2 (Traditional)</option>" .
318 "<option value='utf8_spanish_ci' >Spanish (Modern)</option>" .
319 "<option value='utf8_swedish_ci' >Swedish</option>" .
320 "<option value='utf8_turkish_ci' >Turkish</option>" .
321 "<option value='utf8_unicode_ci' >Unicode (German, French, Russian, Armenian, Greek)</option>" .
322 "<option value='' >None (Do not force UTF-8)</option>" .
323 "</select>" .
324 "</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>";
326 echo "<TR VALIGN='TOP'><TD>&nbsp;</TD></TR>";
327 echo "<TR VALIGN='TOP'><TD COLSPAN=2><font color='red'>OPENEMR USER:</font></TD></TR>";
328 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>
329 <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>
330 <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>
332 echo "<TR VALIGN='TOP'><TD>&nbsp;</TD></TR>";
334 /*********************************************************************
335 echo "<TR VALIGN='TOP'><TD COLSPAN=2><font color='red'>OPENEMR PATHS:</font></TD></TR>";
336 echo "<TR VALIGN='TOP'><TD COLSPAN=3></TD></TR>
337 <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>
338 <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>
340 *********************************************************************/
342 echo "</TABLE>
343 <br>
344 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>";
346 break;
349 case 3:
351 if ($login == "" || !isset($login)) {
352 echo "ERROR. Please pick a proper 'Login Name'.<br>\n";
353 echo "Click Back in browser to re-enter.<br>\n";
354 break;
356 if (strpos($iuser, " ")) {
357 echo "ERROR. The 'Initial User' field can only contain one word and no spaces.<br>\n";
358 echo "Click Back in browser to re-enter.<br>\n";
359 break;
361 if ($pass == "" || !isset($pass)) {
362 echo "ERROR. Please pick a proper 'Password'.<br>\n";
363 echo "Click Back in browser to re-enter.<br>\n";
364 break;
367 echo "<b>Step $state</b><br><br>\n";
368 echo "Configuring OpenEMR...<br><br>\n";
371 if ($inst != 2) {
372 echo "Connecting to MySQL Server...\n";
373 flush();
374 if ($server == "localhost")
375 $dbh = mysql_connect("$server","$root","$rootpass");
376 else
377 $dbh = mysql_connect("$server:$port","$root","$rootpass");
378 if ($dbh == FALSE) {
379 echo "ERROR. Check your login credentials.\n";
380 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
381 break;
383 else
384 echo "OK.<br>\n";
385 echo "Creating database...\n";
386 flush();
387 $sql = "create database $dbname";
388 if ($collate) {
389 $sql .= " character set utf8 collate $collate";
390 mysql_query("SET NAMES 'utf8'", $dbh);
392 if (mysql_query($sql, $dbh) == FALSE) {
393 echo "ERROR. Check your login credentials.\n";
394 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
395 break;
397 else
398 echo "OK.<br>\n";
399 echo "Creating user with permissions for database...\n";
400 flush();
401 if (mysql_query("GRANT ALL PRIVILEGES ON $dbname.* TO '$login'@'$loginhost' IDENTIFIED BY '$pass'",$dbh) == FALSE) {
402 echo "ERROR when granting privileges to the specified user.\n";
403 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
404 echo "ERROR.\n";
405 break;
407 else
408 echo "OK.<br>\n";
409 echo "Reconnecting as new user...\n";
410 mysql_close($dbh);
412 else
413 echo "Connecting to MySQL Server...\n";
415 if ($server == "localhost")
416 $dbh = mysql_connect("$server","$login","$pass");
417 else
418 $dbh = mysql_connect("$server:$port","$login","$pass");
420 if ($dbh == FALSE) {
421 echo "ERROR. Check your login credentials.\n";
422 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
423 break;
425 else {
426 if ($collate) {
427 mysql_query("SET NAMES 'utf8'", $dbh);
429 echo "OK.<br>\n";
431 echo "Opening database...";
432 flush();
433 if (mysql_select_db("$dbname",$dbh) == FALSE) {
434 echo "ERROR. Check your login credentials.\n";
435 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
436 break;
438 else
439 echo "OK.<br>\n";
440 flush();
441 if ($upgrade != 1) {
443 //select the correct translation dumpfile
444 if ($collate) {
445 array_push($dumpfiles,$translations_dumpfile_utf8);
446 array_push($dumpfilesTitles,"Language Translation (utf8)");
448 else {
449 array_push($dumpfiles,$translations_dumpfile_latin1);
450 array_push($dumpfilesTitles,"Language Translation (latin1)");
453 // Deal with IPPF-specific SQL.
454 if ($ippf_specific) {
455 array_push($dumpfiles, $manualPath . "sql/ippf_layout.sql");
456 array_push($dumpfilesTitles, "IPPF Layout");
459 // Load ICD-9 codes if present.
460 if (file_exists("sql/icd9.sql")) {
461 array_push($dumpfiles, $manualPath . "sql/icd9.sql");
462 array_push($dumpfilesTitles, "ICD-9");
465 $dumpfileCounter = 0;
466 foreach ($dumpfiles as $var) {
467 echo "Creating ".$dumpfilesTitles[$dumpfileCounter]." tables...\n";
468 mysql_query("USE $dbname",$dbh);
469 flush();
470 $fd = fopen($var, 'r');
471 if ($fd == FALSE) {
472 echo "ERROR. Could not open dumpfile '$dumpfile'.\n";
473 flush();
474 break;
476 $query = "";
477 $line = "";
478 while (!feof ($fd)){
479 $line = fgets($fd,1024);
480 $line = rtrim($line);
481 if (substr($line,0,2) == "--") // Kill comments
482 continue;
483 if (substr($line,0,1) == "#") // Kill comments
484 continue;
485 if ($line == "")
486 continue;
487 $query = $query.$line; // Check for full query
488 $chr = substr($query,strlen($query)-1,1);
489 if ($chr == ";") { // valid query, execute
490 $query = rtrim($query,";");
491 if (!mysql_query($query, $dbh)) {
492 echo "<p>ERROR. Query failed: \"$query\"\n";
493 echo "<br />" . mysql_error() . " (#" . mysql_errno() . ")</p>\n";
495 $query = "";
498 echo "OK<br>\n";
499 fclose($fd);
500 flush();
501 $dumpfileCounter++;
503 echo "Adding Initial User...\n";
504 flush();
505 //echo "INSERT INTO groups VALUES (1,'$igroup','$iuser')<br>\n";
506 if (mysql_query("INSERT INTO groups (id, name, user) VALUES (1,'$igroup','$iuser')") == FALSE) {
507 echo "ERROR. Could not run queries.\n";
508 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
509 flush();
510 break;
512 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) {
513 echo "ERROR. Could not run queries.\n";
514 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
515 flush();
516 break;
518 echo "OK<br>\n";
519 flush();
521 // Set our version numbers into the version table.
522 echo "Setting version indicators...\n";
523 include "version.php";
524 if (mysql_query("UPDATE version SET v_major = '$v_major', v_minor = '$v_minor', " .
525 "v_patch = '$v_patch', v_tag = '$v_tag', v_database = '$v_database'") == FALSE) {
526 echo "ERROR.\n";
527 echo "<p>" . mysql_error() . " (#" . mysql_errno() . ")\n";
529 else {
530 echo "OK<br>\n";
532 flush();
535 echo "<br>Writing SQL Configuration...<br>";
536 @touch($conffile); // php bug
537 $fd = @fopen($conffile, 'w');
538 $string = "<?php
539 // OpenEMR
540 // MySQL Config
541 // Referenced from sql.inc
545 $it_died = //fmg: variable keeps running track of any errors
546 write_sqlconf($conffile, $server, $port, $login, $pass, $dbname);
548 //it's rather irresponsible to not report errors when writing this file.
549 if ($it_died != 0) {
550 echo "ERROR. Couldn't write $it_died lines to config file '$conffile'.\n";
551 flush();
552 break;
555 echo "Successfully wrote SQL configuration.<BR><br>";
557 /*********************************************************************
558 echo "Writing OpenEMR webserver paths to config file...<br>";
559 //edit interface/globals.php
560 //first, ensure slashes are in correct direction (windows specific fix)
561 $openemrBasePath = str_replace('\\\\', '/', $openemrBasePath);
562 $openemrBasePath = str_replace('\\', '/', $openemrBasePath);
563 $openemrWebPath = str_replace('\\\\', '/', $openemrWebPath);
564 $openemrWebPath = str_replace('\\', '/', $openemrWebPath);
565 //second, edit file (web paths and set UTF8 if pertinent)
566 $data = file($conffile2) or die("Could not read ".$conffile2." file.");
567 $finalData = "";
568 $isCount = 0;
569 foreach ($data as $line) {
570 $isHit = 0;
571 if ((strpos($line,"\$webserver_root = \"")) === false) {
573 else {
574 $isHit = 1;
575 $isCount += 1;
576 $finalData .= "\$webserver_root = \"$openemrBasePath\";\n";
578 if ((strpos($line,"\$web_root = \"")) === false) {
580 else {
581 $isHit = 1;
582 $isCount += 1;
583 $finalData .= "\$web_root = \"$openemrWebPath\";\n";
585 if (!$isHit) {
586 $finalData .= $line;
589 $fd = @fopen($conffile2, 'w') or die("Could not open ".$conffile2." file.");
590 fwrite($fd, $finalData);
591 fclose($fd);
592 if ($isCount == 2) {
593 echo "Successfully wrote OpenEMR webserver paths to config file<br><br>";
595 else {
596 echo "<FONT COLOR='red'>ERROR</FONT> writing openemr webserver root paths to config file ($conffile2). ($isCount)<br><br>\n";
598 *********************************************************************/
600 echo "Writing global configuration defaults...<br>";
601 require_once("library/globals.inc.php");
602 foreach ($GLOBALS_METADATA as $grpname => $grparr) {
603 foreach ($grparr as $fldid => $fldarr) {
604 list($fldname, $fldtype, $flddef, $flddesc) = $fldarr;
605 if (substr($fldtype, 0, 2) !== 'm_') {
606 $res = mysql_query("SELECT count(*) AS count FROM globals WHERE gl_name = '$fldid'");
607 $row = @mysql_fetch_array($res, MYSQL_ASSOC);
608 if (empty($row['count'])) {
609 mysql_query("INSERT INTO globals ( gl_name, gl_index, gl_value ) " .
610 "VALUES ( '$fldid', '0', '$flddef' )");
615 echo "Successfully wrote global configuration defaults.<br><br>";
617 echo "\n<br>Next step will install and configure access controls (php-GACL).<br>\n";
619 echo "
620 <FORM METHOD='POST'>\n
621 <INPUT TYPE='HIDDEN' NAME='state' VALUE='4'>
622 <INPUT TYPE='HIDDEN' NAME='site' VALUE='$site_id'>\n
623 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$iuser'>
624 <INPUT TYPE='HIDDEN' NAME='iuname' VALUE='$iuname'>
625 <br>\n
626 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
629 break;
631 case 4:
632 echo "<b>Step $state</b><br><br>\n";
633 echo "Installing and Configuring Access Controls (php-GACL)...<br><br>";
635 //run gacl config scripts, all sql config data now in sqlconf.php file
636 require $gaclSetupScript1;
637 require $gaclSetupScript2;
638 echo "<br>";
640 //give the administrator user admin priviledges
641 $groupArray = array("Administrators");
642 set_user_aro($groupArray,$iuser,$iuname,"","");
643 echo "Gave the '$iuser' user (password is 'pass') administrator access.<br><br>";
645 echo "Done installing and configuring access controls (php-GACL).<br>";
646 echo "Next step will configure PHP.";
648 echo "<br><FORM METHOD='POST'>\n
649 <INPUT TYPE='HIDDEN' NAME='state' VALUE='5'>\n
650 <INPUT TYPE='HIDDEN' NAME='site' VALUE='$site_id'>\n
651 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$iuser'>\n
652 <br>\n
653 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
655 break;
657 case 5:
658 echo "<b>Step $state</b><br><br>\n";
659 echo "Configuration of PHP...<br><br>\n";
660 echo "We recommend making the following changes to your PHP installation, which can normally be done by editing the php.ini configuration file:\n";
661 echo "<ul>";
662 $gotFileFlag = 0;
663 if (version_compare(PHP_VERSION, '5.2.4', '>=')) {
664 $phpINIfile = php_ini_loaded_file();
665 if ($phpINIfile) {
666 echo "<li><font color='green'>Your php.ini file can be found at ".$phpINIfile."</font></li>\n";
667 $gotFileFlag = 1;
670 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";
671 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";
672 if (!$gotFileFlag) {
673 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";
675 echo "</ul>";
677 echo "<br>We recommend you print these instructions for future reference.<br><br>";
678 echo "Next step will configure Apache web server.";
680 echo "<br><FORM METHOD='POST'>\n
681 <INPUT TYPE='HIDDEN' NAME='state' VALUE='6'>\n
682 <INPUT TYPE='HIDDEN' NAME='site' VALUE='$site_id'>\n
683 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$iuser'>\n
684 <br>\n
685 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
687 break;
689 case 6:
690 echo "<b>Step $state</b><br><br>\n";
691 echo "Configuration of Apache web server...<br><br>\n";
692 echo "The \"".realpath($docsDirectory)."\", \"".realpath($billingDirectory)."\" and \"".realpath($billingDirectory2)."\" directories contain patient information, and
693 it is important to secure these directories. This can be done by placing pertinent .htaccess
694 files in these directories or by pasting the below to end of your apache configuration file:<br>
695 &nbsp;&nbsp;&lt;Directory ".realpath($docsDirectory)."&gt;<br>
696 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;order deny,allow<br>
697 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Deny from all<br>
698 &nbsp;&nbsp;&lt;/Directory&gt;<br>
699 &nbsp;&nbsp;&lt;Directory ".realpath($billingDirectory)."&gt;<br>
700 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;order deny,allow<br>
701 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Deny from all<br>
702 &nbsp;&nbsp;&lt;/Directory&gt;<br>
703 &nbsp;&nbsp;&lt;Directory ".realpath($billingDirectory2)."&gt;<br>
704 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;order deny,allow<br>
705 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Deny from all<br>
706 &nbsp;&nbsp;&lt;/Directory&gt;<br><br>";
708 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";
709 echo "<br>We recommend you print these instructions for future reference.<br><br>";
710 echo "Click 'continue' for further instructions.";
712 echo "<br><FORM METHOD='POST'>\n
713 <INPUT TYPE='HIDDEN' NAME='state' VALUE='7'>\n
714 <INPUT TYPE='HIDDEN' NAME='site' VALUE='$site_id'>\n
715 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$iuser'>\n
716 <br>\n
717 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
719 break;
721 case 0:
722 default:
723 echo "<p>Welcome to OpenEMR. This utility will step you through the installation and configuration of OpenEMR for your practice.</p>\n";
724 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";
726 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";
728 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>";
730 if ($checkPermissions == "TRUE") {
731 echo "<p>We will now ensure correct file and directory permissions before starting installation:</p>\n";
732 echo "<FONT COLOR='green'>Ensuring following files are world-writable...</FONT><br>\n";
733 $errorWritable = 0;
734 foreach ($writableFileList as $tempFile) {
735 if (is_writable($tempFile)) {
736 echo "'".realpath($tempFile)."' file is <FONT COLOR='green'><b>ready</b></FONT>.<br>\n";
738 else {
739 echo "<p><FONT COLOR='red'>UNABLE</FONT> to open file '".realpath($tempFile)."' for writing.<br>\n";
740 echo "(configure file permissions; see below for further instructions)</p>\n";
741 $errorWritable = 1;
744 if ($errorWritable) {
745 echo "<p><FONT COLOR='red'>You can't proceed until all above files are ready (world-writable).</FONT><br>\n";
746 echo "In linux, recommend changing file permissions with the 'chmod 666 filename' command.<br>\n";
747 echo "Fix above file permissions and then click the 'Check Again' button to re-check files.<br>\n";
748 echo "<FORM METHOD='POST'><INPUT TYPE='SUBMIT' VALUE='Check Again'></p>" .
749 "<INPUT TYPE='HIDDEN' NAME='site' VALUE='$site_id'></FORM><br>\n";
750 break;
753 echo "<br><FONT COLOR='green'>Ensuring following directories have proper permissions...</FONT><br>\n";
754 $errorWritable = 0;
755 foreach ($writableDirList as $tempDir) {
756 if (is_writable($tempDir)) {
757 echo "'".realpath($tempDir)."' directory is <FONT COLOR='green'><b>ready</b></FONT>.<br>\n";
759 else {
760 echo "<p><FONT COLOR='red'>UNABLE</FONT> to open directory '".realpath($tempDir)."' for writing by web server.<br>\n";
761 echo "(configure directory permissions; see below for further instructions)</p>\n";
762 $errorWritable = 1;
765 if ($errorWritable) {
766 echo "<p><FONT COLOR='red'>You can't proceed until all directories are ready.</FONT><br>\n";
767 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";
768 echo "Fix above directory permissions and then click the 'Check Again' button to re-check directories.<br>\n";
769 echo "<FORM METHOD='POST'><INPUT TYPE='SUBMIT' VALUE='Check Again'></p>" .
770 "<INPUT TYPE='HIDDEN' NAME='site' VALUE='$site_id'></FORM><br>\n";
771 break;
774 echo "<br>All required files and directories have been verified. Click to continue installation.<br>\n";
776 else {
777 echo "<br>Click to continue installation.<br>\n";
780 echo "<FORM METHOD='POST'><INPUT TYPE='HIDDEN' NAME='state' VALUE='1'>" .
781 "<INPUT TYPE='HIDDEN' NAME='site' VALUE='$site_id'>" .
782 "<INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>";
788 </span>
790 </BODY>
791 </HTML>