fix typo in an 837 claim function call (#2669)
[openemr.git] / contrib / util / de_identification_upgrade.php
blob5d6b69199cd381e40ddc789f77c00dd8da81dccc
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');
30 use OpenEMR\Common\Csrf\CsrfUtils;
32 function tableExists_de($tblname)
34 $row = sqlQuery("SHOW TABLES LIKE '" . add_escape_custom($tblname) . "'");
35 if (empty($row)) {
36 return false;
39 return true;
42 function upgradeFromSqlFile_de($filename)
44 global $webserver_root;
46 flush();
47 echo "<font color='green'>";
48 echo xlt('Processing');
49 echo " " . text($filename) . "...</font><br />\n";
51 $fullname = "$webserver_root/sql/" . convert_safe_file_dir_name($filename);
53 $fd = fopen($fullname, 'r');
54 if ($fd == false) {
55 echo xlt("Error, unable to open file");
56 echo " " . text($fullname) . "\n";
57 flush();
58 exit();
61 $query = "";
62 $line = "";
63 $skipping = false;
64 $proc = 0;
66 while (!feof($fd)) {
67 $line = fgets($fd, 2048);
68 $line = rtrim($line);
70 if (preg_match('/^\s*--/', $line)) {
71 continue;
74 if ($line == "") {
75 continue;
78 if (preg_match('/^#IfNotTable\s+(\S+)/', $line, $matches)) {
79 $skipping = tableExists_de($matches[1]);
80 if ($skipping) {
81 echo "<font color='green'>";
84 echo xlt('Skipping section');
85 echo " " . text($line) . "</font><br />\n";
86 } else if (preg_match('/^#EndIf/', $line)) {
87 $skipping = false;
90 if (preg_match('/^\s*#/', $line)) {
91 continue;
94 if ($skipping) {
95 continue;
98 if ($proc == 1) {
99 $query .= "\n";
102 $query = $query . $line;
104 if (substr($query, -1) == '$') {
105 $query = rtrim($query, '$');
106 if ($proc == 0) {
107 $proc = 1;
108 } else {
109 $proc = 0; //executes procedures and functions
110 if (!sqlStatement($query)) {
111 echo "<font color='red'>";
112 echo xlt("The above statement failed"); echo ": " .
113 text(getSqlLastError()) . "<br />";
114 echo xlt("Upgrading will continue");
115 echo ".<br /></font>\n";
118 $query = '';
122 if (substr($query, -1) == ';'and $proc == 0) {
123 $query = rtrim($query, ';');
124 echo text($query) . "<br />\n"; //executes sql statements
125 if (!sqlStatement($query)) {
126 echo "<font color='red'>";
127 echo xlt("The above statement failed"); echo ": " .
128 text(getSqlLastError()) . "<br />";
129 echo xlt("Upgrading will continue");
130 echo ".<br /></font>\n";
133 $query = '';
137 flush();
138 } // end function
141 $sqldir = "$webserver_root/sql";
142 $dh = opendir($sqldir);
143 if (! $dh) {
144 die(xlt("Cannot read") . " " . text($sqldir));
147 closedir($dh);
149 <html>
150 <head>
151 <title><?php echo xlt('OpenEMR Database Upgrade'); ?></title>
152 <link rel='STYLESHEET' href='../../interface/themes/style_sky_blue.css'>
153 </head>
154 <body> <br>
155 <center>
156 <span class='title'><?php echo xlt('OpenEMR Database Upgrade for De-identification'); ?></span>
157 <br>
158 </center>
159 <?php
160 if (!empty($_POST['form_submit'])) {
161 if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
162 CsrfUtils::csrfNotVerified();
165 upgradeFromSqlFile_de("database_de_identification.sql");
167 // grant file privilege to user
169 $dbh = $GLOBALS['dbh'];
171 if ($dbh == false) {
172 echo "\n";
173 echo "<p>" . text(getSqlLastError()) . " (#" . text(getSqlLastErrorNo()) . ")\n";
174 exit();
175 } $login=$sqlconf["login"];
176 $loginhost=$sqlconf["host"];
177 generic_sql_select_db($sqlconf['dbase']) or die(text(getSqlLastError()));
178 if (sqlStatement("GRANT FILE ON *.* TO '$login'@'$loginhost'") == false) {
179 echo xlt("Error when granting file privilege to the OpenEMR user.");
180 echo "\n";
181 echo "<p>" . text(getSqlLastError()) . " (#" . text(getSqlLastErrorNo()) . ")\n";
182 echo xlt("Error");
183 echo "\n";
184 exit();
185 } else {
186 echo "<font color='green'>";
189 echo xlt("File privilege granted to OpenEMR user.");
190 echo "<br></font>\n";
192 echo "<p><font color='green'>";
193 echo xlt("Database upgrade finished.");
194 echo "</font></p>\n";
195 echo "<p><font color='red'>";
196 echo xlt("Please restart the apache server before playing with de-identification");
197 echo "</font></p>\n";
198 echo "<p><font color='red'>";
199 echo xlt("Please set de_identification_config variable back to zero");
200 echo "</font></p>\n";
201 echo "</body></html>\n";
202 sqlClose($dbh);
203 exit();
207 <script language="JavaScript">
208 function form_validate()
210 if(document.forms[0].root_user_name.value == "")
212 alert("<?php echo xls('Enter Database root Username');?>");
213 return false;
215 /*if(document.forms[0].root_user_pass.value == "")
217 alert("<?php echo xls('Enter Database root Password');?>");
218 return false;
220 return true;
222 </script>
224 <center>
225 <form method='post' action='de_identification_upgrade.php' onsubmit="return form_validate();">
226 <input type="hidden" name="csrf_token_form" value="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
227 </br>
228 <p><?php if ($de_identification_config != 1) {
229 echo "<p><font color='red'>";
230 echo xlt("Please set");
231 echo " 'de_identification_config' ";
232 echo xlt("variable to one to run de-identification upgrade script");
233 echo "</br></br>";
234 echo "([OPENEMR]/contrib/util/de_identification_upgrade.php)";
235 } else {
236 echo xlt('Upgrades the OpenEMR database to include Procedures, Functions and tables needed for De-identification process');?></p></br>
237 <table class="de_id_upgrade_login" align="center">
238 <tr><td>&nbsp;</td><td colspan=3 align=center>&nbsp;</td><td>&nbsp;</td></tr>
239 <tr valign="top">
240 <td>&nbsp;</td>
241 <td><?php echo xlt('Enter Database root Username'); ?></td>
242 <td>:</td>
243 <td> <input type='text' size='20' name='root_user_name' id='root_user_name'
244 value= "" title="<?php echo xla('Enter Database root Username'); ?>" /> </td>
245 <td>&nbsp;</td>
246 </tr>
247 <tr valign="top">
248 <td>&nbsp;</td>
249 <td><?php echo xlt('Enter Database root Password'); ?></td>
250 <td>:</td>
251 <td><input type='password' size='20' name='root_user_pass' id='root_user_pass'
252 value= "" title="<?php echo xlt('Enter Database root Password'); ?>" /> </td>
253 <td>&nbsp;</td>
254 </tr>
255 <tr><td>&nbsp;</td><td colspan=3 align=center>&nbsp;</td><td>&nbsp;</td></tr>
257 </table>
258 <p><input type='submit' name='form_submit' value="<?php echo xla('Upgrade Database');?>" /></p>
259 <?php } ?>
260 </form>
261 </center>
262 </body>
263 </html>