6 * @link http://www.open-emr.org
7 * @author bradymiller <bradymiller>
8 * @author bradymiller <bradymiller@users.sourceforge.net>
9 * @author bradymiller <bradymiller@users.sourceforge.net>
10 * @author Robert Down <robertdown@live.com>
11 * @author cornfeed <jdough823@gmail.com>
12 * @copyright Copyright (c) 2010 bradymiller <bradymiller>
13 * @copyright Copyright (c) 2011 bradymiller <bradymiller@users.sourceforge.net>
14 * @copyright Copyright (c) 2011 bradymiller <bradymiller@users.sourceforge.net>
15 * @copyright Copyright (c) 2017 Robert Down <robertdown@live.com>
16 * @copyright Copyright (c) 2011 cornfeed <jdough823@gmail.com>
17 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
28 // This exit is to avoid malicious use of this script.
29 // (before running this script, comment out the exit command)
30 // (when you are done running the script, remember to uncomment the exit command)
33 if (!$_POST['submit']) {
37 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
.
40 Make sure that you close Text Editors
, Windows Explorer
, etc
... as these things may stop directory rename that occurs in this script
.
43 Enter the name you wish to
use for this OpenEMR installation
.
45 <input type
=text name
=newname
>
46 <input type
=submit name
=submit value
=submit
>
52 if ($_POST['submit']) {
53 $newname = $_POST['newname'];
54 //handle the database stuff
55 $dumpfile = "sql/database.sql";
56 $icd9 = "sql/icd9.sql";
57 $conffile = "library/sqlconf.php";
58 $server = "localhost";
65 $loginhost = "localhost";
69 echo "Connecting to MySQL Server...\n";
71 if ($server == "localhost") {
72 $dbh = mysql_connect("$server", "$root", "$rootpass");
74 $dbh = mysql_connect("$server:$port", "$root", "$rootpass");
78 echo "ERROR. Check your login credentials.\n";
79 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
85 echo "Creating database...\n";
87 if (mysql_query("create database $dbname", $dbh) == false) {
88 echo "ERROR. Check your login credentials.\n";
89 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
95 echo "Creating user with permissions for database...\n";
97 if (mysql_query("GRANT ALL PRIVILEGES ON $dbname.* TO '$login'@'$loginhost' IDENTIFIED BY '$pass'", $dbh) == false) {
98 echo "ERROR when granting privileges to the specified user.\n";
99 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
106 echo "Reconnecting as new user...\n";
109 echo "Connecting to MySQL Server...\n";
112 if ($server == "localhost") {
113 $dbh = mysql_connect("$server", "$login", "$pass");
115 $dbh = mysql_connect("$server:$port", "$login", "$pass");
119 echo "ERROR. Check your login credentials.\n";
120 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
126 echo "Opening database...";
128 if (mysql_select_db("$dbname", $dbh) == false) {
129 echo "ERROR. Check your login credentials.\n";
130 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
138 echo "Creating initial tables...\n";
139 mysql_query("USE $dbname", $dbh);
141 $fd = fopen($dumpfile, 'r');
143 echo "ERROR. Could not open dumpfile '$dumpfile'.\n";
151 $line = fgets($fd, 1024);
152 $line = rtrim($line);
153 if (substr($line, 0, 2) == "--") { // Kill comments
157 if (substr($line, 0, 1) == "#") { // Kill comments
165 $query = $query.$line; // Check for full query
166 $chr = substr($query, strlen($query)-1, 1);
167 if ($chr == ";") { // valid query, execute
168 $query = rtrim($query, ";");
169 mysql_query("$query", $dbh);
177 echo "Adding Initial User...\n";
182 //echo "INSERT INTO groups VALUES (1,'$igroup','$iuser')<br>\n";
183 if (mysql_query("INSERT INTO groups (id, name, user) VALUES (1,'$igroup','$iuser')") == false) {
184 echo "ERROR. Could not run queries.\n";
185 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
190 //// ViCareplus : As per NIST standard, SHA1 hash/digest of 'pass' is used
191 if (mysql_query("INSERT INTO users (id, username, password, authorized, lname,fname) VALUES (1,'$iuser','9d4e1e23bd5b727046a9e3b4b7db57bd8d6ee684',1,'$iuname','')") == false) {
192 echo "ERROR. Could not run queries.\n";
193 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
201 //Now write sqlconf file
202 echo "Writing SQL Configuration to disk...\n";
203 @touch
($conffile); // php bug
204 $fd = @fopen
($conffile, 'w');
206 echo "ERROR. Could not open config file '$conffile' for writing.\n";
211 $string = "<?php\n\n// OpenEMR\n// MySQL Config\n// Referenced from sql.inc\n\n";
213 $it_died = 0; //fmg: variable keeps running track of any errors
215 fwrite($fd, $string) or $it_died++
;
216 fwrite($fd, "\$host\t= '$host';\n") or $it_died++
;
217 fwrite($fd, "\$port\t= '$port';\n") or $it_died++
;
218 fwrite($fd, "\$login\t= '$login';\n") or $it_died++
;
219 fwrite($fd, "\$pass\t= '$pass';\n") or $it_died++
;
220 fwrite($fd, "\$dbase\t= '$dbname';\n") or $it_died++
;
224 '$sqlconf = array();\n' .
225 '$sqlconf["host"]= $host;\n' .
226 '$sqlconf["port"] = $port;\n' .
227 '$sqlconf["login"] = $login;\n' .
228 '$sqlconf["pass"] = $pass;\n' .
229 '$sqlconf["dbase"] = $dbase;\n' .
230 '//////////////////////////\n' .
231 '//////////////////////////\n' .
232 '//////////////////////////\n' .
233 '//////DO NOT TOUCH THIS///\n' .
234 '$config = 1; /////////////\n' .
235 '//////////////////////////\n' .
236 '//////////////////////////\n' .
237 '//////////////////////////\n' .
240 <?php
// done just for coloring
242 fwrite($fd, $string) or $it_died++
;
244 //it's rather irresponsible to not report errors when writing this file.
246 echo "ERROR. Couldn't write $it_died lines to config file '$conffile'.\n";
253 //Now, use new name and fix globals.php and rename directory!!!
256 $contents = file_get_contents($d.'/interface/globals.php');
257 $contents = preg_replace(
258 '/\$webserver_root\s+=\s+[\"\'].*?[\"\'];/',
259 "\$webserver_root = '".$dn."/".$newname."';",
262 $contents = preg_replace(
263 '/\$web_root\s+=\s+[\"\'].*?[\"\'];/',
264 "\$web_root = '/".$newname."';",
267 file_put_contents($d.'/interface/globals.php', $contents);
268 if (rename($d, $dn.'/'.$newname)) {
269 echo "<br/><a href='http://localhost/".$newname."'>click here</a>";