Add Modal view of ID CARD image and drop modal use from Patient Reports
[openemr.git] / setup.php
blob0e8a4318d07c0fa35a7c432a7c28c9f6acef5c23
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 $dumpfileCounter = 0;
460 foreach ($dumpfiles as $var) {
461 echo "Creating ".$dumpfilesTitles[$dumpfileCounter]." tables...\n";
462 mysql_query("USE $dbname",$dbh);
463 flush();
464 $fd = fopen($var, 'r');
465 if ($fd == FALSE) {
466 echo "ERROR. Could not open dumpfile '$dumpfile'.\n";
467 flush();
468 break;
470 $query = "";
471 $line = "";
472 while (!feof ($fd)){
473 $line = fgets($fd,1024);
474 $line = rtrim($line);
475 if (substr($line,0,2) == "--") // Kill comments
476 continue;
477 if (substr($line,0,1) == "#") // Kill comments
478 continue;
479 if ($line == "")
480 continue;
481 $query = $query.$line; // Check for full query
482 $chr = substr($query,strlen($query)-1,1);
483 if ($chr == ";") { // valid query, execute
484 $query = rtrim($query,";");
485 if (!mysql_query($query, $dbh)) {
486 echo "<p>ERROR. Query failed: \"$query\"\n";
487 echo "<br />" . mysql_error() . " (#" . mysql_errno() . ")</p>\n";
489 $query = "";
492 echo "OK<br>\n";
493 fclose($fd);
494 flush();
495 $dumpfileCounter++;
497 echo "Adding Initial User...\n";
498 flush();
499 //echo "INSERT INTO groups VALUES (1,'$igroup','$iuser')<br>\n";
500 if (mysql_query("INSERT INTO groups (id, name, user) VALUES (1,'$igroup','$iuser')") == FALSE) {
501 echo "ERROR. Could not run queries.\n";
502 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
503 flush();
504 break;
506 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) {
507 echo "ERROR. Could not run queries.\n";
508 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
509 flush();
510 break;
512 echo "OK<br>\n";
513 flush();
515 // Set our version numbers into the version table.
516 echo "Setting version indicators...\n";
517 include "version.php";
518 if (mysql_query("UPDATE version SET v_major = '$v_major', v_minor = '$v_minor', " .
519 "v_patch = '$v_patch', v_tag = '$v_tag', v_database = '$v_database'") == FALSE) {
520 echo "ERROR.\n";
521 echo "<p>" . mysql_error() . " (#" . mysql_errno() . ")\n";
523 else {
524 echo "OK<br>\n";
526 flush();
529 echo "<br>Writing SQL Configuration...<br>";
530 @touch($conffile); // php bug
531 $fd = @fopen($conffile, 'w');
532 $string = "<?php
533 // OpenEMR
534 // MySQL Config
535 // Referenced from sql.inc
539 $it_died = //fmg: variable keeps running track of any errors
540 write_sqlconf($conffile, $server, $port, $login, $pass, $dbname);
542 //it's rather irresponsible to not report errors when writing this file.
543 if ($it_died != 0) {
544 echo "ERROR. Couldn't write $it_died lines to config file '$conffile'.\n";
545 flush();
546 break;
549 echo "Successfully wrote SQL configuration.<BR><br>";
551 /*********************************************************************
552 echo "Writing OpenEMR webserver paths to config file...<br>";
553 //edit interface/globals.php
554 //first, ensure slashes are in correct direction (windows specific fix)
555 $openemrBasePath = str_replace('\\\\', '/', $openemrBasePath);
556 $openemrBasePath = str_replace('\\', '/', $openemrBasePath);
557 $openemrWebPath = str_replace('\\\\', '/', $openemrWebPath);
558 $openemrWebPath = str_replace('\\', '/', $openemrWebPath);
559 //second, edit file (web paths and set UTF8 if pertinent)
560 $data = file($conffile2) or die("Could not read ".$conffile2." file.");
561 $finalData = "";
562 $isCount = 0;
563 foreach ($data as $line) {
564 $isHit = 0;
565 if ((strpos($line,"\$webserver_root = \"")) === false) {
567 else {
568 $isHit = 1;
569 $isCount += 1;
570 $finalData .= "\$webserver_root = \"$openemrBasePath\";\n";
572 if ((strpos($line,"\$web_root = \"")) === false) {
574 else {
575 $isHit = 1;
576 $isCount += 1;
577 $finalData .= "\$web_root = \"$openemrWebPath\";\n";
579 if (!$isHit) {
580 $finalData .= $line;
583 $fd = @fopen($conffile2, 'w') or die("Could not open ".$conffile2." file.");
584 fwrite($fd, $finalData);
585 fclose($fd);
586 if ($isCount == 2) {
587 echo "Successfully wrote OpenEMR webserver paths to config file<br><br>";
589 else {
590 echo "<FONT COLOR='red'>ERROR</FONT> writing openemr webserver root paths to config file ($conffile2). ($isCount)<br><br>\n";
592 *********************************************************************/
594 echo "Writing global configuration defaults...<br>";
595 require_once("library/globals.inc.php");
596 foreach ($GLOBALS_METADATA as $grpname => $grparr) {
597 foreach ($grparr as $fldid => $fldarr) {
598 list($fldname, $fldtype, $flddef, $flddesc) = $fldarr;
599 if (substr($fldtype, 0, 2) !== 'm_') {
600 $res = mysql_query("SELECT count(*) AS count FROM globals WHERE gl_name = '$fldid'");
601 $row = @mysql_fetch_array($res, MYSQL_ASSOC);
602 if (empty($row['count'])) {
603 mysql_query("INSERT INTO globals ( gl_name, gl_index, gl_value ) " .
604 "VALUES ( '$fldid', '0', '$flddef' )");
609 echo "Successfully wrote global configuration defaults.<br><br>";
611 echo "\n<br>Next step will install and configure access controls (php-GACL).<br>\n";
613 echo "
614 <FORM METHOD='POST'>\n
615 <INPUT TYPE='HIDDEN' NAME='state' VALUE='4'>
616 <INPUT TYPE='HIDDEN' NAME='site' VALUE='$site_id'>\n
617 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$iuser'>
618 <INPUT TYPE='HIDDEN' NAME='iuname' VALUE='$iuname'>
619 <br>\n
620 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
623 break;
625 case 4:
626 echo "<b>Step $state</b><br><br>\n";
627 echo "Installing and Configuring Access Controls (php-GACL)...<br><br>";
629 //run gacl config scripts, all sql config data now in sqlconf.php file
630 require $gaclSetupScript1;
631 require $gaclSetupScript2;
632 echo "<br>";
634 //give the administrator user admin priviledges
635 $groupArray = array("Administrators");
636 set_user_aro($groupArray,$iuser,$iuname,"","");
637 echo "Gave the '$iuser' user (password is 'pass') administrator access.<br><br>";
639 echo "Done installing and configuring access controls (php-GACL).<br>";
640 echo "Next step will configure PHP.";
642 echo "<br><FORM METHOD='POST'>\n
643 <INPUT TYPE='HIDDEN' NAME='state' VALUE='5'>\n
644 <INPUT TYPE='HIDDEN' NAME='site' VALUE='$site_id'>\n
645 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$iuser'>\n
646 <br>\n
647 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
649 break;
651 case 5:
652 echo "<b>Step $state</b><br><br>\n";
653 echo "Configuration of PHP...<br><br>\n";
654 echo "We recommend making the following changes to your PHP installation, which can normally be done by editing the php.ini configuration file:\n";
655 echo "<ul>";
656 $gotFileFlag = 0;
657 if (version_compare(PHP_VERSION, '5.2.4', '>=')) {
658 $phpINIfile = php_ini_loaded_file();
659 if ($phpINIfile) {
660 echo "<li><font color='green'>Your php.ini file can be found at ".$phpINIfile."</font></li>\n";
661 $gotFileFlag = 1;
664 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";
665 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";
666 if (!$gotFileFlag) {
667 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";
669 echo "</ul>";
671 echo "<br>We recommend you print these instructions for future reference.<br><br>";
672 echo "Next step will configure Apache web server.";
674 echo "<br><FORM METHOD='POST'>\n
675 <INPUT TYPE='HIDDEN' NAME='state' VALUE='6'>\n
676 <INPUT TYPE='HIDDEN' NAME='site' VALUE='$site_id'>\n
677 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$iuser'>\n
678 <br>\n
679 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
681 break;
683 case 6:
684 echo "<b>Step $state</b><br><br>\n";
685 echo "Configuration of Apache web server...<br><br>\n";
686 echo "The \"".realpath($docsDirectory)."\", \"".realpath($billingDirectory)."\" and \"".realpath($billingDirectory2)."\" directories contain patient information, and
687 it is important to secure these directories. This can be done by placing pertinent .htaccess
688 files in these directories or by pasting the below to end of your apache configuration file:<br>
689 &nbsp;&nbsp;&lt;Directory ".realpath($docsDirectory)."&gt;<br>
690 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;order deny,allow<br>
691 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Deny from all<br>
692 &nbsp;&nbsp;&lt;/Directory&gt;<br>
693 &nbsp;&nbsp;&lt;Directory ".realpath($billingDirectory)."&gt;<br>
694 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;order deny,allow<br>
695 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Deny from all<br>
696 &nbsp;&nbsp;&lt;/Directory&gt;<br>
697 &nbsp;&nbsp;&lt;Directory ".realpath($billingDirectory2)."&gt;<br>
698 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;order deny,allow<br>
699 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Deny from all<br>
700 &nbsp;&nbsp;&lt;/Directory&gt;<br><br>";
702 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";
703 echo "<br>We recommend you print these instructions for future reference.<br><br>";
704 echo "Click 'continue' for further instructions.";
706 echo "<br><FORM METHOD='POST'>\n
707 <INPUT TYPE='HIDDEN' NAME='state' VALUE='7'>\n
708 <INPUT TYPE='HIDDEN' NAME='site' VALUE='$site_id'>\n
709 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$iuser'>\n
710 <br>\n
711 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
713 break;
715 case 0:
716 default:
717 echo "<p>Welcome to OpenEMR. This utility will step you through the installation and configuration of OpenEMR for your practice.</p>\n";
718 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";
720 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";
722 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>";
724 if ($checkPermissions == "TRUE") {
725 echo "<p>We will now ensure correct file and directory permissions before starting installation:</p>\n";
726 echo "<FONT COLOR='green'>Ensuring following files are world-writable...</FONT><br>\n";
727 $errorWritable = 0;
728 foreach ($writableFileList as $tempFile) {
729 if (is_writable($tempFile)) {
730 echo "'".realpath($tempFile)."' file is <FONT COLOR='green'><b>ready</b></FONT>.<br>\n";
732 else {
733 echo "<p><FONT COLOR='red'>UNABLE</FONT> to open file '".realpath($tempFile)."' for writing.<br>\n";
734 echo "(configure file permissions; see below for further instructions)</p>\n";
735 $errorWritable = 1;
738 if ($errorWritable) {
739 echo "<p><FONT COLOR='red'>You can't proceed until all above files are ready (world-writable).</FONT><br>\n";
740 echo "In linux, recommend changing file permissions with the 'chmod 666 filename' command.<br>\n";
741 echo "Fix above file permissions and then click the 'Check Again' button to re-check files.<br>\n";
742 echo "<FORM METHOD='POST'><INPUT TYPE='SUBMIT' VALUE='Check Again'></p>" .
743 "<INPUT TYPE='HIDDEN' NAME='site' VALUE='$site_id'></FORM><br>\n";
744 break;
747 echo "<br><FONT COLOR='green'>Ensuring following directories have proper permissions...</FONT><br>\n";
748 $errorWritable = 0;
749 foreach ($writableDirList as $tempDir) {
750 if (is_writable($tempDir)) {
751 echo "'".realpath($tempDir)."' directory is <FONT COLOR='green'><b>ready</b></FONT>.<br>\n";
753 else {
754 echo "<p><FONT COLOR='red'>UNABLE</FONT> to open directory '".realpath($tempDir)."' for writing by web server.<br>\n";
755 echo "(configure directory permissions; see below for further instructions)</p>\n";
756 $errorWritable = 1;
759 if ($errorWritable) {
760 echo "<p><FONT COLOR='red'>You can't proceed until all directories are ready.</FONT><br>\n";
761 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";
762 echo "Fix above directory permissions and then click the 'Check Again' button to re-check directories.<br>\n";
763 echo "<FORM METHOD='POST'><INPUT TYPE='SUBMIT' VALUE='Check Again'></p>" .
764 "<INPUT TYPE='HIDDEN' NAME='site' VALUE='$site_id'></FORM><br>\n";
765 break;
768 echo "<br>All required files and directories have been verified. Click to continue installation.<br>\n";
770 else {
771 echo "<br>Click to continue installation.<br>\n";
774 echo "<FORM METHOD='POST'><INPUT TYPE='HIDDEN' NAME='state' VALUE='1'>" .
775 "<INPUT TYPE='HIDDEN' NAME='site' VALUE='$site_id'>" .
776 "<INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>";
782 </span>
784 </BODY>
785 </HTML>