2 /********************************************************************************\
3 * Copyright (C) ViCarePlus, Visolve (vicareplus_engg@visolve.com) *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License *
7 * as published by the Free Software Foundation; either version 2 *
8 * of the License, or (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18 /********************************************************************************/
20 // Disable PHP timeout. This will not work in safe mode.
21 ini_set('max_execution_time', '0');
23 $ignoreAuth = true; // no login required
25 //set de_identification_config to 1 to run the de_identification_upgrade script
26 $de_identification_config = 0;
28 require_once('../../interface/globals.php');
29 require_once('../../library/sql.inc');
30 require_once('../../library/sqlconf.php');
32 function tableExists_de($tblname) {
33 $row = sqlQuery("SHOW TABLES LIKE '$tblname'");
34 if (empty($row)) return false;
38 function upgradeFromSqlFile_de($filename) {
39 global $webserver_root;
42 echo "<font color='green'>"; echo xl('Processing'); echo " ".$filename."...</font><br />\n";
44 $fullname = "$webserver_root/sql/$filename";
46 $fd = fopen($fullname, 'r');
48 echo xl("Error, unable to open file"); echo " ".$fullname."\n";
59 $line = fgets($fd, 2048);
62 if (preg_match('/^\s*--/', $line)) continue;
63 if ($line == "") continue;
65 if (preg_match('/^#IfNotTable\s+(\S+)/', $line, $matches)) {
66 $skipping = tableExists_de($matches[1]);
67 if ($skipping) echo "<font color='green'>"; echo xl('Skipping section'); echo " ".$line."</font><br />\n";
69 else if (preg_match('/^#EndIf/', $line)) {
72 if (preg_match('/^\s*#/', $line)) continue;
73 if ($skipping) continue;
75 if($proc == 1) $query .= "\n";
76 $query = $query . $line;
78 if (substr($query, -1) == '$')
80 $query = rtrim($query, '$');
85 $proc = 0; //executes procedures and functions
86 if (!sqlStatement($query))
88 echo "<font color='red'>"; echo xl("The above statement failed"); echo ": " .
89 mysql_error() . "<br />"; echo xl("Upgrading will continue"); echo ".<br /></font>\n";
96 if (substr($query, -1) == ';'and $proc == 0) {
97 $query = rtrim($query, ';');
98 echo "$query<br />\n"; //executes sql statements
99 if (!sqlStatement($query)) {
100 echo "<font color='red'>"; echo xl("The above statement failed"); echo ": " .
101 mysql_error() . "<br />"; echo xl("Upgrading will continue"); echo ".<br /></font>\n";
110 $sqldir = "$webserver_root/sql";
111 $dh = opendir($sqldir);
112 if (! $dh) die( xl("Cannot read","e")." ".$sqldir);
117 <title
><?php
xl('OpenEMR Database Upgrade','e'); ?
></title
>
118 <link rel
='STYLESHEET' href
='../../interface/themes/style_sky_blue.css'>
122 <span
class='title'><?php
xl('OpenEMR Database Upgrade for De-identification','e'); ?
></span
>
126 if (!empty($_POST['form_submit'])) {
127 upgradeFromSqlFile_de("database_de_identification.sql");
129 // grant file privilege to user
130 if ($sqlconf["host"] == "localhost")
131 $dbh = mysql_connect($sqlconf['host'],$_POST['root_user_name'],$_POST['root_user_pass'],$sqlconf['host']) or die(mysql_error());
133 $dbh = mysql_connect($sqlconf['host'].":".$sqlconf['port'],$_POST['root_user_name'],$_POST['root_user_pass']) or die(mysql_error());
136 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
138 } $login=$sqlconf["login"]; $loginhost=$sqlconf["host"];
139 mysql_select_db($sqlconf['dbase']) or die(mysql_error());
140 if (mysql_query("GRANT FILE ON *.* TO '$login'@'$loginhost'",$dbh) == FALSE) {
141 echo xl("Error when granting file privilege to the OpenEMR user."); echo "\n";
142 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
143 echo xl("Error"); echo "\n";
147 echo "<font color='green'>"; echo xl("File privilege granted to OpenEMR user."); echo "<br></font>\n";
149 echo "<p><font color='green'>"; echo xl("Database upgrade finished."); echo "</font></p>\n";
150 echo "<p><font color='red'>"; echo xl("Please restart the apache server before playing with de-identification"); echo "</font></p>\n";
151 echo "<p><font color='red'>"; echo xl("Please set de_identification_config variable back to zero"); echo "</font></p>\n"; echo "</body></html>\n";
157 <script language
="JavaScript">
158 function form_validate()
160 if(document
.forms
[0].root_user_name
.value
== "")
162 alert("<?php echo xl('Enter Database root Username');?>");
165 /*if(document.forms[0].root_user_pass.value == "")
167 alert("<?php echo xl('Enter Database root Password');?>");
175 <form method
='post' action
='de_identification_upgrade.php' onsubmit
="return form_validate();">
177 <p
><?php
if($de_identification_config != 1)
179 echo "<p><font color='red'>";
180 echo xl("Please set"); echo " 'de_identification_config' "; echo xl("variable to one to run de-identification upgrade script"); echo "</br></br>";
181 echo "([OPENEMR]/contrib/util/de_identification_upgrade.php)";
185 xl('Upgrades the OpenEMR database to include Procedures, Functions and tables needed for De-identification process','e');?
></p
></br
>
186 <table
class="de_id_upgrade_login" align
="center">
187 <tr
><td
> 
;</td
><td colspan
=3 align
=center
> 
;</td
><td
> 
;</td
></tr
>
190 <td
><?php
xl('Enter Database root Username','e'); ?
></td
>
192 <td
> <input type
='text' size
='20' name
='root_user_name' id
='root_user_name'
193 value
= "" title
="<?php xl('Enter Database root Username','e'); ?>" /> </td
>
198 <td
><?php
xl('Enter Database root Password','e'); ?
></td
>
200 <td
><input type
='password' size
='20' name
='root_user_pass' id
='root_user_pass'
201 value
= "" title
="<?php xl('Enter Database root Password','e'); ?>" /> </td
>
204 <tr
><td
> 
;</td
><td colspan
=3 align
=center
> 
;</td
><td
> 
;</td
></tr
>
207 <p
><input type
='submit' name
='form_submit' value
="<?php xl('Upgrade Database','e');?>" /></p
>