9 // This exit is to avoid malicious use of this script.
10 // (before running this script, comment out the exit command)
11 // (when you are done running the script, remember to uncomment the exit command)
14 if (!$_POST['submit']) {
18 This script will take the name that you give
and create an OpenEMR database with this
as the database name
, username
, password
, group name
. It will also rename the directory this OpenEMR installation is under to the
new name
. THIS ONLY WORKS WITH XAMPP
AND HAS VERY LIMITED TESTING
.
21 Make sure that you close Text Editors
, Windows Explorer
, etc
... as these things may stop directory rename that occurs in this script
.
24 Enter the name you wish to
use for this OpenEMR installation
.
26 <input type
=text name
=newname
>
27 <input type
=submit name
=submit value
=submit
>
32 if ($_POST['submit']) {
33 $newname = $_POST['newname'];
34 //handle the database stuff
35 $dumpfile = "sql/database.sql";
36 $icd9 = "sql/icd9.sql";
37 $conffile = "library/sqlconf.php";
38 $server = "localhost";
45 $loginhost = "localhost";
49 echo "Connecting to MySQL Server...\n";
51 if ($server == "localhost")
52 $dbh = mysql_connect("$server","$root","$rootpass");
54 $dbh = mysql_connect("$server:$port","$root","$rootpass");
56 echo "ERROR. Check your login credentials.\n";
57 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
62 echo "Creating database...\n";
64 if (mysql_query("create database $dbname",$dbh) == FALSE) {
65 echo "ERROR. Check your login credentials.\n";
66 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
71 echo "Creating user with permissions for database...\n";
73 if (mysql_query("GRANT ALL PRIVILEGES ON $dbname.* TO '$login'@'$loginhost' IDENTIFIED BY '$pass'",$dbh) == FALSE) {
74 echo "ERROR when granting privileges to the specified user.\n";
75 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
81 echo "Reconnecting as new user...\n";
85 echo "Connecting to MySQL Server...\n";
87 if ($server == "localhost")
88 $dbh = mysql_connect("$server","$login","$pass");
90 $dbh = mysql_connect("$server:$port","$login","$pass");
93 echo "ERROR. Check your login credentials.\n";
94 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
99 echo "Opening database...";
101 if (mysql_select_db("$dbname",$dbh) == FALSE) {
102 echo "ERROR. Check your login credentials.\n";
103 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
110 echo "Creating initial tables...\n";
111 mysql_query("USE $dbname",$dbh);
113 $fd = fopen($dumpfile, 'r');
115 echo "ERROR. Could not open dumpfile '$dumpfile'.\n";
122 $line = fgets($fd,1024);
123 $line = rtrim($line);
124 if (substr($line,0,2) == "--") // Kill comments
126 if (substr($line,0,1) == "#") // Kill comments
130 $query = $query.$line; // Check for full query
131 $chr = substr($query,strlen($query)-1,1);
132 if ($chr == ";") { // valid query, execute
133 $query = rtrim($query,";");
134 mysql_query("$query",$dbh);
141 echo "Adding Initial User...\n";
146 //echo "INSERT INTO groups VALUES (1,'$igroup','$iuser')<br>\n";
147 if (mysql_query("INSERT INTO groups (id, name, user) VALUES (1,'$igroup','$iuser')") == FALSE) {
148 echo "ERROR. Could not run queries.\n";
149 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
153 //// ViCareplus : As per NIST standard, SHA1 hash/digest of 'pass' is used
154 if (mysql_query("INSERT INTO users (id, username, password, authorized, lname,fname) VALUES (1,'$iuser','9d4e1e23bd5b727046a9e3b4b7db57bd8d6ee684',1,'$iuname','')") == FALSE) {
155 echo "ERROR. Could not run queries.\n";
156 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
163 //Now write sqlconf file
164 echo "Writing SQL Configuration to disk...\n";
165 @touch
($conffile); // php bug
166 $fd = @fopen
($conffile, 'w');
168 echo "ERROR. Could not open config file '$conffile' for writing.\n";
176 // Referenced from sql.inc
180 $it_died = 0; //fmg: variable keeps running track of any errors
182 fwrite($fd,$string) or $it_died++
;
183 fwrite($fd,"\$host\t= '$host';\n") or $it_died++
;
184 fwrite($fd,"\$port\t= '$port';\n") or $it_died++
;
185 fwrite($fd,"\$login\t= '$login';\n") or $it_died++
;
186 fwrite($fd,"\$pass\t= '$pass';\n") or $it_died++
;
187 fwrite($fd,"\$dbase\t= '$dbname';\n") or $it_died++
;
193 $sqlconf["host"]= $host;
194 $sqlconf["port"] = $port;
195 $sqlconf["login"] = $login;
196 $sqlconf["pass"] = $pass;
197 $sqlconf["dbase"] = $dbase;
198 //////////////////////////
199 //////////////////////////
200 //////////////////////////
201 //////DO NOT TOUCH THIS///
202 $config = 1; /////////////
203 //////////////////////////
204 //////////////////////////
205 //////////////////////////
208 ?
><?php
// done just for coloring
210 fwrite($fd,$string) or $it_died++
;
212 //it's rather irresponsible to not report errors when writing this file.
214 echo "ERROR. Couldn't write $it_died lines to config file '$conffile'.\n";
220 //Now, use new name and fix globals.php and rename directory!!!
223 $contents = file_get_contents($d.'/interface/globals.php');
224 $contents = preg_replace('/\$webserver_root\s+=\s+[\"\'].*?[\"\'];/',
225 "\$webserver_root = '".$dn."/".$newname."';",$contents);
226 $contents = preg_replace('/\$web_root\s+=\s+[\"\'].*?[\"\'];/',
227 "\$web_root = '/".$newname."';",$contents);
228 file_put_contents($d.'/interface/globals.php',$contents);
229 if (rename($d,$dn.'/'.$newname)) {
230 echo "<br/><a href='http://localhost/".$newname."'>click here</a>";