Redesign of new group encounter form like patient's form (#1892)
[openemr.git] / contrib / util / de_identification_upgrade.php
blob50067e401c011a0c06ab00c5ee8b9bfc08383b43
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 function tableExists_de($tblname)
32 $row = sqlQuery("SHOW TABLES LIKE '" . add_escape_custom($tblname) . "'");
33 if (empty($row)) {
34 return false;
37 return true;
40 function upgradeFromSqlFile_de($filename)
42 global $webserver_root;
44 flush();
45 echo "<font color='green'>";
46 echo xlt('Processing');
47 echo " " . text($filename) . "...</font><br />\n";
49 $fullname = "$webserver_root/sql/" . convert_safe_file_dir_name($filename);
51 $fd = fopen($fullname, 'r');
52 if ($fd == false) {
53 echo xlt("Error, unable to open file");
54 echo " " . text($fullname) . "\n";
55 flush();
56 exit();
59 $query = "";
60 $line = "";
61 $skipping = false;
62 $proc = 0;
64 while (!feof($fd)) {
65 $line = fgets($fd, 2048);
66 $line = rtrim($line);
68 if (preg_match('/^\s*--/', $line)) {
69 continue;
72 if ($line == "") {
73 continue;
76 if (preg_match('/^#IfNotTable\s+(\S+)/', $line, $matches)) {
77 $skipping = tableExists_de($matches[1]);
78 if ($skipping) {
79 echo "<font color='green'>";
82 echo xlt('Skipping section');
83 echo " " . text($line) . "</font><br />\n";
84 } else if (preg_match('/^#EndIf/', $line)) {
85 $skipping = false;
88 if (preg_match('/^\s*#/', $line)) {
89 continue;
92 if ($skipping) {
93 continue;
96 if ($proc == 1) {
97 $query .= "\n";
100 $query = $query . $line;
102 if (substr($query, -1) == '$') {
103 $query = rtrim($query, '$');
104 if ($proc == 0) {
105 $proc = 1;
106 } else {
107 $proc = 0; //executes procedures and functions
108 if (!sqlStatement($query)) {
109 echo "<font color='red'>";
110 echo xlt("The above statement failed"); echo ": " .
111 text(getSqlLastError()) . "<br />";
112 echo xlt("Upgrading will continue");
113 echo ".<br /></font>\n";
116 $query = '';
120 if (substr($query, -1) == ';'and $proc == 0) {
121 $query = rtrim($query, ';');
122 echo text($query) . "<br />\n"; //executes sql statements
123 if (!sqlStatement($query)) {
124 echo "<font color='red'>";
125 echo xlt("The above statement failed"); echo ": " .
126 text(getSqlLastError()) . "<br />";
127 echo xlt("Upgrading will continue");
128 echo ".<br /></font>\n";
131 $query = '';
135 flush();
136 } // end function
139 $sqldir = "$webserver_root/sql";
140 $dh = opendir($sqldir);
141 if (! $dh) {
142 die(xlt("Cannot read") . " " . text($sqldir));
145 closedir($dh);
147 <html>
148 <head>
149 <title><?php echo xlt('OpenEMR Database Upgrade'); ?></title>
150 <link rel='STYLESHEET' href='../../interface/themes/style_sky_blue.css'>
151 </head>
152 <body> <br>
153 <center>
154 <span class='title'><?php echo xlt('OpenEMR Database Upgrade for De-identification'); ?></span>
155 <br>
156 </center>
157 <?php
158 if (!empty($_POST['form_submit'])) {
159 if (!verifyCsrfToken($_POST["csrf_token_form"])) {
160 die(xlt('Authentication Error'));
163 upgradeFromSqlFile_de("database_de_identification.sql");
165 // grant file privilege to user
167 $dbh = $GLOBALS['dbh'];
169 if ($dbh == false) {
170 echo "\n";
171 echo "<p>" . text(getSqlLastError()) . " (#" . text(getSqlLastErrorNo()) . ")\n";
172 exit();
173 } $login=$sqlconf["login"];
174 $loginhost=$sqlconf["host"];
175 generic_sql_select_db($sqlconf['dbase']) or die(text(getSqlLastError()));
176 if (sqlStatement("GRANT FILE ON *.* TO '$login'@'$loginhost'") == false) {
177 echo xlt("Error when granting file privilege to the OpenEMR user.");
178 echo "\n";
179 echo "<p>" . text(getSqlLastError()) . " (#" . text(getSqlLastErrorNo()) . ")\n";
180 echo xlt("Error");
181 echo "\n";
182 exit();
183 } else {
184 echo "<font color='green'>";
187 echo xlt("File privilege granted to OpenEMR user.");
188 echo "<br></font>\n";
190 echo "<p><font color='green'>";
191 echo xlt("Database upgrade finished.");
192 echo "</font></p>\n";
193 echo "<p><font color='red'>";
194 echo xlt("Please restart the apache server before playing with de-identification");
195 echo "</font></p>\n";
196 echo "<p><font color='red'>";
197 echo xlt("Please set de_identification_config variable back to zero");
198 echo "</font></p>\n";
199 echo "</body></html>\n";
200 sqlClose($dbh);
201 exit();
205 <script language="JavaScript">
206 function form_validate()
208 if(document.forms[0].root_user_name.value == "")
210 alert("<?php echo xls('Enter Database root Username');?>");
211 return false;
213 /*if(document.forms[0].root_user_pass.value == "")
215 alert("<?php echo xls('Enter Database root Password');?>");
216 return false;
218 return true;
220 </script>
222 <center>
223 <form method='post' action='de_identification_upgrade.php' onsubmit="return form_validate();">
224 <input type="hidden" name="csrf_token_form" value="<?php echo attr(collectCsrfToken()); ?>" />
225 </br>
226 <p><?php if ($de_identification_config != 1) {
227 echo "<p><font color='red'>";
228 echo xlt("Please set");
229 echo " 'de_identification_config' ";
230 echo xlt("variable to one to run de-identification upgrade script");
231 echo "</br></br>";
232 echo "([OPENEMR]/contrib/util/de_identification_upgrade.php)";
233 } else {
234 echo xlt('Upgrades the OpenEMR database to include Procedures, Functions and tables needed for De-identification process');?></p></br>
235 <table class="de_id_upgrade_login" align="center">
236 <tr><td>&nbsp;</td><td colspan=3 align=center>&nbsp;</td><td>&nbsp;</td></tr>
237 <tr valign="top">
238 <td>&nbsp;</td>
239 <td><?php echo xlt('Enter Database root Username'); ?></td>
240 <td>:</td>
241 <td> <input type='text' size='20' name='root_user_name' id='root_user_name'
242 value= "" title="<?php echo xla('Enter Database root Username'); ?>" /> </td>
243 <td>&nbsp;</td>
244 </tr>
245 <tr valign="top">
246 <td>&nbsp;</td>
247 <td><?php echo xlt('Enter Database root Password'); ?></td>
248 <td>:</td>
249 <td><input type='password' size='20' name='root_user_pass' id='root_user_pass'
250 value= "" title="<?php echo xlt('Enter Database root Password'); ?>" /> </td>
251 <td>&nbsp;</td>
252 </tr>
253 <tr><td>&nbsp;</td><td colspan=3 align=center>&nbsp;</td><td>&nbsp;</td></tr>
255 </table>
256 <p><input type='submit' name='form_submit' value="<?php echo xla('Upgrade Database');?>" /></p>
257 <?php } ?>
258 </form>
259 </center>
260 </body>
261 </html>