8 if (!$_POST['submit']) {
12 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
.
15 Make sure that you close Text Editors
, Windows Explorer
, etc
... as these things may stop directory rename that occurs in this script
.
18 Enter the name you wish to
use for this OpenEMR installation
.
20 <input type
=text name
=newname
>
21 <input type
=submit name
=submit value
=submit
>
26 if ($_POST['submit']) {
27 $newname = $_POST['newname'];
28 //handle the database stuff
29 $dumpfile = "sql/database.sql";
30 $icd9 = "sql/icd9.sql";
31 $conffile = "library/sqlconf.php";
32 $server = "localhost";
39 $loginhost = "localhost";
43 echo "Connecting to MySQL Server...\n";
45 if ($server == "localhost")
46 $dbh = mysql_connect("$server","$root","$rootpass");
48 $dbh = mysql_connect("$server:$port","$root","$rootpass");
50 echo "ERROR. Check your login credentials.\n";
51 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
56 echo "Creating database...\n";
58 if (mysql_query("create database $dbname",$dbh) == FALSE) {
59 echo "ERROR. Check your login credentials.\n";
60 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
65 echo "Creating user with permissions for database...\n";
67 if (mysql_query("GRANT ALL PRIVILEGES ON $dbname.* TO '$login'@'$loginhost' IDENTIFIED BY '$pass'",$dbh) == FALSE) {
68 echo "ERROR when granting privileges to the specified user.\n";
69 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
75 echo "Reconnecting as new user...\n";
79 echo "Connecting to MySQL Server...\n";
81 if ($server == "localhost")
82 $dbh = mysql_connect("$server","$login","$pass");
84 $dbh = mysql_connect("$server:$port","$login","$pass");
87 echo "ERROR. Check your login credentials.\n";
88 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
93 echo "Opening database...";
95 if (mysql_select_db("$dbname",$dbh) == FALSE) {
96 echo "ERROR. Check your login credentials.\n";
97 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
104 echo "Creating initial tables...\n";
105 mysql_query("USE $dbname",$dbh);
107 $fd = fopen($dumpfile, 'r');
109 echo "ERROR. Could not open dumpfile '$dumpfile'.\n";
116 $line = fgets($fd,1024);
117 $line = rtrim($line);
118 if (substr($line,0,2) == "--") // Kill comments
120 if (substr($line,0,1) == "#") // Kill comments
124 $query = $query.$line; // Check for full query
125 $chr = substr($query,strlen($query)-1,1);
126 if ($chr == ";") { // valid query, execute
127 $query = rtrim($query,";");
128 mysql_query("$query",$dbh);
135 echo "Adding Initial User...\n";
140 //echo "INSERT INTO groups VALUES (1,'$igroup','$iuser')<br>\n";
141 if (mysql_query("INSERT INTO groups (id, name, user) VALUES (1,'$igroup','$iuser')") == FALSE) {
142 echo "ERROR. Could not run queries.\n";
143 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
147 if (mysql_query("INSERT INTO users (id, username, password, authorized, lname,fname) VALUES (1,'$iuser','1a1dc91c907325c69271ddf0c944bc72',1,'$iuname','')") == FALSE) {
148 echo "ERROR. Could not run queries.\n";
149 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
156 //Now write sqlconf file
157 echo "Writing SQL Configuration to disk...\n";
158 @touch
($conffile); // php bug
159 $fd = @fopen
($conffile, 'w');
161 echo "ERROR. Could not open config file '$conffile' for writing.\n";
168 // Referenced from sql.inc
172 $it_died = 0; //fmg: variable keeps running track of any errors
174 fwrite($fd,$string) or $it_died++
;
175 fwrite($fd,"\$host\t= '$host';\n") or $it_died++
;
176 fwrite($fd,"\$port\t= '$port';\n") or $it_died++
;
177 fwrite($fd,"\$login\t= '$login';\n") or $it_died++
;
178 fwrite($fd,"\$pass\t= '$pass';\n") or $it_died++
;
179 fwrite($fd,"\$dbase\t= '$dbname';\n") or $it_died++
;
185 $sqlconf["host"]= $host;
186 $sqlconf["port"] = $port;
187 $sqlconf["login"] = $login;
188 $sqlconf["pass"] = $pass;
189 $sqlconf["dbase"] = $dbase;
190 //////////////////////////
191 //////////////////////////
192 //////////////////////////
193 //////DO NOT TOUCH THIS///
194 $config = 1; /////////////
195 //////////////////////////
196 //////////////////////////
197 //////////////////////////
200 ?
><?
// done just for coloring
202 fwrite($fd,$string) or $it_died++
;
204 //it's rather irresponsible to not report errors when writing this file.
206 echo "ERROR. Couldn't write $it_died lines to config file '$conffile'.\n";
212 //Now, use new name and fix globals.php and rename directory!!!
215 $contents = file_get_contents($d.'/interface/globals.php');
216 $contents = preg_replace('/\$webserver_root\s+=\s+[\"\'].*?[\"\'];/',
217 "\$webserver_root = '".$dn."/".$newname."';",$contents);
218 $contents = preg_replace('/\$web_root\s+=\s+[\"\'].*?[\"\'];/',
219 "\$web_root = '/".$newname."';",$contents);
220 file_put_contents($d.'/interface/globals.php',$contents);
221 if (rename($d,$dn.'/'.$newname)) {
222 echo "<br/><a href='http://localhost/".$newname."'>click here</a>";