patient-specific appointments report
[openemr.git] / setup.php
blob560bd052bfb3259dcbd45b1782e5869ed9398749
1 <?php
3 //required for normal operation because of recent changes in PHP:
4 extract($_GET);
5 extract($_POST);
6 //turn off PHP compatibility warnings
7 ini_set("session.bug_compat_warn","off");
9 $url = "";
10 $dumpfile = "sql/database.sql";
11 $icd9 = "sql/icd9.sql";
12 $conffile = "library/sqlconf.php";
13 $upgrade = 0;
14 $defhost = 'localhost';
15 $state = $_POST["state"];
17 include_once($conffile);
19 <HTML>
20 <HEAD>
21 <TITLE>OpenEMR Setup Tool</TITLE>
22 <LINK REL=STYLESHEET HREF="interface/themes/style_blue.css">
23 </HEAD>
24 <BODY>
26 <span class="title">OpenEMR Setup</span>
27 <br><br>
28 <span class="text">
30 <?php
31 if ($state == 5) {
34 <p>Congratulations! OpenEMR is now successfully installed.
36 <ul>
37 <li>Please Edit the 'interface/globals.php' file now to specify the correct
38 URL paths, and to select a theme.</li>
39 <li>Please make sure that the two folders underneath
40 'openemrwebroot/interface/main/calendar/modules/PostCalendar/pntemplates/'
41 exist and are writable by the web server. The two subdirectories are
42 'compiled' and 'cache'.<br>
43 Try "chown apache:apache -R openemrwebroot/interface/main/calendar/modules/PostCalendar/pntemplates/compiled"
44 and
45 "chown apache:apache -R openemrwebroot/interface/main/calendar/modules/PostCalendar/pntemplates/cache".
46 (If either subdirectory doesn't exist, create it first then do the chown above).<br>
47 The user name and group of apache may differ depending on your distro, i.e.
48 for Debian is www-data and www-data.</li>
49 </ul>
50 <p>
51 In order to take full advantage of the documents capability you
52 must give your web server permissions on the document storage
53 directory. Try "chown apache:apache -R openemrwebroot/documents"
54 and then "chmod g+w openemrwebroot/documents".
55 You must also make sure your PHP installation (normally set in
56 your php.ini file) has "file_uploads enabled", that
57 "upload_max_filesize" is appropriate for your use and that
58 "upload_tmp_dir" is set to a correct value if the default of
59 "/tmp" won't work on your system.
60 </p>
61 <p>
62 There's many information and extra tools bundled within OpenEMR Files.
63 <br>Please refer to openemr/Documentation
64 <br>Many forms and other useful scripts can be found at openemr/contrib
65 <br>OpenEMR now comes with optional GACL support, a fine grained access control system. Please refer to openemr/Documentation/README.phpgacl for -easy- installation.
66 </p>
67 <p>
68 Reading openemr/includes/config.php and openemr/interface/globals.php is a good idea.
69 </p>
70 <p>
71 To ensure a consistent look and feel through out the application
72 using <a href='http://www.mozilla.org/products/firefox/'> Firefox</a>
73 is recommended.
74 </p>
75 <p>
76 The default user is "admin" and the default password is "pass"
77 </P
78 <p>
79 <a href='./'>Click here to start using OpenEMR. </a>
80 </p>
83 exit();
87 <?php
89 $server = $_POST["server"];
90 $port = $_POST["port"];
91 $dbname = $_POST["dbname"];
92 $login = $_POST["login"];
93 $pass = $_POST["pass"];
94 $loginhost = $_POST["loginhost"];
95 $rootpass = $_POST["rootpass"];
98 if ($config == 1) {
99 echo "OpenEMR is already configured. If you wish to re-configure the SQL server, edit $conffile, or change the 'config' variable to 0, and re-run this script.<br>\n";
101 else {
102 switch ($state) {
104 case 1:
105 echo "<b>Step $state</b><br><br>\n";
106 echo "Now I need to know whether you want me to create the databases on my own or if you have already created the database for me to use. If you are upgrading, you will want to select the latter function. For me to create the databases, you will need to supply the MySQL root password.\n
107 <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>
108 <br><br>\n
109 <FORM METHOD='POST'>\n
110 <INPUT TYPE='HIDDEN' NAME='state' VALUE='2'>\n
111 <INPUT TYPE='RADIO' NAME='inst' VALUE='1' checked>Have setup create the databases<br>\n
112 <INPUT TYPE='RADIO' NAME='inst' VALUE='2'>I have already created the databases<br>\n
113 <br>\n
114 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
115 break;
117 case 2:
118 echo "<b>Step $state</b><br><br>\n";
119 echo "Now you need to supply the MySQL server information.
120 <br><br>
121 <FORM METHOD='POST'>
122 <INPUT TYPE='HIDDEN' NAME='state' VALUE='3'>
123 <INPUT TYPE='HIDDEN' NAME='inst' VALUE='$inst'>
124 <TABLE>\n
125 <TR><TD><font color='red'>SERVER:</font></TD></TR>
126 <TR><TD><span class='text'>Server Host: </span></TD><TD><INPUT TYPE='TEXT' VALUE='$defhost' NAME='server' SIZE='30'><span class='text'>(This is the IP address of the machine running MySQL)</span><br></TD></TR>
127 <TR><TD><span class='text'>Server Port: </span></TD><TD><INPUT TYPE='TEXT' VALUE='3306' NAME='port' SIZE='30'><span class='text'>(The default port for MySQL is 3306)</span><br></TD></TR>
128 <TR><TD><span class='text'>Database Name: </span></TD><TD><INPUT TYPE='TEXT' VALUE='openemr' NAME='dbname' SIZE='30'><span class='text'>(This is the name of the OpenEMR database - 'openemr' is the recommended)</span><br></TD></TR>
129 <TR><TD><span class='text'>Login Name: </span></TD><TD><INPUT TYPE='TEXT' VALUE='openemr' NAME='login' SIZE='30'><span class='text'>(This is the name of the OpenEMR login name - 'openemr' is the recommended)</span><br></TD></TR>
130 <TR><TD><span class='text'>Password: </span></TD><TD><INPUT TYPE='PASSWORD' VALUE='' NAME='pass' SIZE='30'><span class='text'>(This is the Login Password for when PHP accesses MySQL - it should be at least 8 characters long and composed of both numbers and letters)</span><br></TD></TR>\n";
131 if ($inst != 2) {
132 echo "<TR><TD><font color='red'>CLIENT:</font></TD></TR>";
133 echo "<TR><TD><span class='text'>User Hostname: </span></TD><TD><INPUT TYPE='TEXT' VALUE='$defhost' NAME='loginhost' SIZE='30'><span class='text'>(This is the IP address of the server machine running Apache and PHP - if you are setting up one computer, this is the same as the Server Host above)</span><br></TD></TR>
134 <TR><TD><span class='text'>Root Pass: </span></TD><TD><INPUT TYPE='PASSWORD' VALUE='' NAME='rootpass' SIZE='30'><span class='text'>(This is your MySQL root password. For localhost, it is usually ok to leave it blank.)</span><br></TD></TR>\n";
136 echo "<TR><TD><font color='red'>USER:</font></TD></TR>";
137 echo "<TR><TD COLSPAN=2></TD></TR>
138 <TR><TD><span class='text'>Initial User:</span></TD><TD><INPUT SIZE='30' TYPE='TEXT' NAME='iuser' VALUE='admin'><span class='text'>(This is the user that will be created for you. It will be an authorized user, so it should be for a Doctor or other Practitioner)</span></TD></TR>
139 <TR><TD><span class='text'>Initial User's Name:</span></TD><TD><INPUT SIZE='30' TYPE='TEXT' NAME='iuname' VALUE='Administrator'><span class='text'>(This is the real name of the initial user.)</span></TD></TR>
140 <TR><TD><span class='text'>Initial Group:</span></TD><TD><INPUT SIZE='30' TYPE='TEXT' NAME='igroup' VALUE='Default'><span class='text'>(This is the group that will be created for your users. This should be the name of your practice.)</span></TD></TR>
142 echo "</TABLE>
143 <br>
144 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>";
146 break;
149 case 3:
152 echo "<b>Step $state</b><br><br>\n";
153 if ($pass == "" || $login == "" || !isset($login) || !isset($pass)) {
154 echo "ERROR. Please pick a proper username and/or password.<br>\n";
155 break;
158 if ($inst != 2) {
159 echo "Connecting to MySQL Server...\n";
160 flush();
161 if ($server == "localhost")
162 $dbh = mysql_connect("$server","root","$rootpass");
163 else
164 $dbh = mysql_connect("$server:$port","root","$rootpass");
165 if ($dbh == FALSE) {
166 echo "ERROR. Check your login credentials.\n";
167 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
168 break;
170 else
171 echo "OK.<br>\n";
172 echo "Creating database...\n";
173 flush();
174 if (mysql_query("create database $dbname",$dbh) == FALSE) {
175 echo "ERROR. Check your login credentials.\n";
176 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
177 break;
179 else
180 echo "OK.<br>\n";
181 echo "Creating user with permissions for database...\n";
182 flush();
183 if (mysql_query("GRANT ALL PRIVILEGES ON $dbname.* TO '$login'@'$loginhost' IDENTIFIED BY '$pass'",$dbh) == FALSE) {
184 echo "ERROR when granting privileges to the specified user.\n";
185 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
186 echo "ERROR.\n";
187 break;
189 else
190 echo "OK.<br>\n";
191 echo "Reconnecting as new user...\n";
192 mysql_close($dbh);
194 else
195 echo "Connecting to MySQL Server...\n";
197 if ($server == "localhost")
198 $dbh = mysql_connect("$server","$login","$pass");
199 else
200 $dbh = mysql_connect("$server:$port","$login","$pass");
202 if ($dbh == FALSE) {
203 echo "ERROR. Check your login credentials.\n";
204 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
205 break;
207 else
208 echo "OK.<br>\n";
209 echo "Opening database...";
210 flush();
211 if (mysql_select_db("$dbname",$dbh) == FALSE) {
212 echo "ERROR. Check your login credentials.\n";
213 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
214 break;
216 else
217 echo "OK.<br>\n";
218 flush();
219 if ($upgrade != 1) {
220 echo "Creating initial tables...\n";
221 mysql_query("USE $dbname",$dbh);
222 flush();
223 $fd = fopen($dumpfile, 'r');
224 if ($fd == FALSE) {
225 echo "ERROR. Could not open dumpfile '$dumpfile'.\n";
226 flush();
227 break;
229 $query = "";
230 $line = "";
231 while (!feof ($fd)){
232 $line = fgets($fd,1024);
233 $line = rtrim($line);
234 if (substr($line,0,2) == "--") // Kill comments
235 continue;
236 if (substr($line,0,1) == "#") // Kill comments
237 continue;
238 if ($line == "")
239 continue;
240 $query = $query.$line; // Check for full query
241 $chr = substr($query,strlen($query)-1,1);
242 if ($chr == ";") { // valid query, execute
243 $query = rtrim($query,";");
244 mysql_query("$query",$dbh);
245 $query = "";
248 echo "OK<br>\n";
249 fclose($fd);
250 flush();
251 echo "Adding Initial User...\n";
252 flush();
253 $iuser = $_POST["iuser"];
254 $iuname = $_POST["iuname"];
255 $igroup = $_POST["igroup"];
256 //echo "INSERT INTO groups VALUES (1,'$igroup','$iuser')<br>\n";
257 if (mysql_query("INSERT INTO groups (id, name, user) VALUES (1,'$igroup','$iuser')") == FALSE) {
258 echo "ERROR. Could not run queries.\n";
259 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
260 flush();
261 break;
263 if (mysql_query("INSERT INTO users (id, username, password, authorized, lname,fname) VALUES (1,'$iuser','1a1dc91c907325c69271ddf0c944bc72',1,'$iuname','')") == FALSE) {
264 echo "ERROR. Could not run queries.\n";
265 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
266 flush();
267 break;
269 echo "OK<br>\n";
270 flush();
271 /* echo "Inserting ICD-9-CM Codes into Database...\n";
272 flush();
273 $fd = fopen($icd9, 'r');
274 if ($fd == FALSE) {
275 echo "ERROR. Could not open dumpfile.\n";
276 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
277 flush();
278 break;
280 $query = "";
281 $line = "";
282 while (!feof ($fd)){
283 $line = fgets($fd,1024);
284 $line = rtrim($line);
285 if (substr($line,0,2) == "--") // Kill comments
286 continue;
287 if (substr($line,0,1) == "#") // Kill comments
288 continue;
289 if ($line == "")
290 continue;
291 $query = $query.$line; // Check for full query
292 $chr = substr($query,strlen($query)-1,1);
293 if ($chr == ";") { // valid query, execute
294 $query = rtrim($query,";");
295 mysql_query("$query",$dbh);
296 $query = "";
299 echo "OK\n";
300 fclose($fd);*/
301 flush();
303 echo "\n<br>Please make sure 'library/sqlconf.php' is world-writeable for the next step.<br>\n";
306 echo "
307 <FORM METHOD='POST'>\n
308 <INPUT TYPE='HIDDEN' NAME='state' VALUE='4'>
309 <INPUT TYPE='HIDDEN' NAME='host' VALUE='$server'>
310 <INPUT TYPE='HIDDEN' NAME='dbname' VALUE='$dbname'>
311 <INPUT TYPE='HIDDEN' NAME='port' VALUE='$port'>
312 <INPUT TYPE='HIDDEN' NAME='login' VALUE='$login'>
313 <INPUT TYPE='HIDDEN' NAME='pass' VALUE='$pass'>
314 <br>\n
315 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
318 break;
320 case 4:
321 echo "<b>Step $state</b><br><br>\n";
322 echo "Writing SQL Configuration to disk...\n";
323 @touch($conffile); // php bug
324 $fd = @fopen($conffile, 'w');
325 if ($fd == FALSE) {
326 echo "ERROR. Could not open config file '$conffile' for writing.\n";
327 flush();
328 break;
330 $string = "<?
331 // OpenEMR
332 // MySQL Config
333 // Referenced from sql.inc
337 $it_died = 0; //fmg: variable keeps running track of any errors
339 fwrite($fd,$string) or $it_died++;
340 fwrite($fd,"\$host\t= '$host';\n") or $it_died++;
341 fwrite($fd,"\$port\t= '$port';\n") or $it_died++;
342 fwrite($fd,"\$login\t= '$login';\n") or $it_died++;
343 fwrite($fd,"\$pass\t= '$pass';\n") or $it_died++;
344 fwrite($fd,"\$dbase\t= '$dbname';\n") or $it_died++;
347 $string = '
349 $sqlconf = array();
350 $sqlconf["host"]= $host;
351 $sqlconf["port"] = $port;
352 $sqlconf["login"] = $login;
353 $sqlconf["pass"] = $pass;
354 $sqlconf["dbase"] = $dbase;
355 //////////////////////////
356 //////////////////////////
357 //////////////////////////
358 //////DO NOT TOUCH THIS///
359 $config = 1; /////////////
360 //////////////////////////
361 //////////////////////////
362 //////////////////////////
365 ?><? // done just for coloring
367 fwrite($fd,$string) or $it_died++;
369 //it's rather irresponsible to not report errors when writing this file.
370 if ($it_died != 0) {
371 echo "ERROR. Couldn't write $it_died lines to config file '$conffile'.\n";
372 flush();
373 break;
375 fclose($fd);
377 echo "OK<BR>\nPlease restore secure permissions on the 'library/sqlconf.php' file now.\n<br><FORM METHOD='POST'>\n
378 <INPUT TYPE='HIDDEN' NAME='state' VALUE='5'>\n
379 <br>\n
380 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
382 break;
384 case 0:
385 default:
386 echo "Welcome to OpenEMR. This utility will step you through the configuration of OpenEMR for your practice. Before proceeding, be sure that you have a properly installed and configured MySQL server available, and a PHP configured webserver.<br><br>\n";
388 Echo "<p>If you are upgrading from a previous version, please read the README file.<br><br>";
390 echo "<FORM METHOD='POST'><INPUT TYPE='HIDDEN' NAME='state' VALUE='1'><INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>";
397 </span>
399 </BODY>
400 </HTML>