Missing $_REQUEST variable in messages check
[openemr.git] / contrib / util / de_identification_upgrade.php
blob5a95fdd42d19083db2b14e0db4c02c7d35bb5f17
1 <?php
2 /********************************************************************************\
3 * Copyright (C) ViCarePlus, Visolve (vicareplus_engg@visolve.com) *
4 * *
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. *
9 * *
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. *
14 * *
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;
35 return true;
38 function upgradeFromSqlFile_de($filename) {
39 global $webserver_root;
41 flush();
42 echo "<font color='green'>"; echo xl('Processing'); echo " ".$filename."...</font><br />\n";
44 $fullname = "$webserver_root/sql/$filename";
46 $fd = fopen($fullname, 'r');
47 if ($fd == FALSE) {
48 echo xl("Error, unable to open file"); echo " ".$fullname."\n";
49 flush();
50 break;
53 $query = "";
54 $line = "";
55 $skipping = false;
56 $proc = 0;
58 while (!feof ($fd)){
59 $line = fgets($fd, 2048);
60 $line = rtrim($line);
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)) {
70 $skipping = false;
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, '$');
81 if($proc == 0)
82 $proc = 1;
83 else
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";
91 $query = '';
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";
103 $query = '';
106 flush();
107 } // end function
110 $sqldir = "$webserver_root/sql";
111 $dh = opendir($sqldir);
112 if (! $dh) die( xl("Cannot read","e")." ".$sqldir);
113 closedir($dh);
115 <html>
116 <head>
117 <title><?php xl('OpenEMR Database Upgrade','e'); ?></title>
118 <link rel='STYLESHEET' href='../../interface/themes/style_sky_blue.css'>
119 </head>
120 <body> <br>
121 <center>
122 <span class='title'><?php xl('OpenEMR Database Upgrade for De-identification','e'); ?></span>
123 <br>
124 </center>
125 <?php
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());
132 else
133 $dbh = mysql_connect($sqlconf['host'].":".$sqlconf['port'],$_POST['root_user_name'],$_POST['root_user_pass']) or die(mysql_error());
134 if ($dbh == FALSE) {
135 echo "\n";
136 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
137 break;
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";
144 break;
146 else
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";
152 mysql_close($dbh);
153 exit();
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');?>");
163 return false;
165 /*if(document.forms[0].root_user_pass.value == "")
167 alert("<?php echo xl('Enter Database root Password');?>");
168 return false;
170 return true;
172 </script>
174 <center>
175 <form method='post' action='de_identification_upgrade.php' onsubmit="return form_validate();">
176 </br>
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)";
183 else
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>&nbsp;</td><td colspan=3 align=center>&nbsp;</td><td>&nbsp;</td></tr>
188 <tr valign="top">
189 <td>&nbsp;</td>
190 <td><?php xl('Enter Database root Username','e'); ?></td>
191 <td>:</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>
194 <td>&nbsp;</td>
195 </tr>
196 <tr valign="top">
197 <td>&nbsp;</td>
198 <td><?php xl('Enter Database root Password','e'); ?></td>
199 <td>:</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>
202 <td>&nbsp;</td>
203 </tr>
204 <tr><td>&nbsp;</td><td colspan=3 align=center>&nbsp;</td><td>&nbsp;</td></tr>
206 </table>
207 <p><input type='submit' name='form_submit' value="<?php xl('Upgrade Database','e');?>" /></p>
208 <?php } ?>
209 </form>
210 </center>
211 </body>
212 </html>