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');
30 use OpenEMR\Common\Csrf\CsrfUtils
;
32 function tableExists_de($tblname)
34 $row = sqlQuery("SHOW TABLES LIKE '" . add_escape_custom($tblname) . "'");
42 function upgradeFromSqlFile_de($filename)
44 global $webserver_root;
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');
55 echo xlt("Error, unable to open file");
56 echo " " . text($fullname) . "\n";
67 $line = fgets($fd, 2048);
70 if (preg_match('/^\s*--/', $line)) {
78 if (preg_match('/^#IfNotTable\s+(\S+)/', $line, $matches)) {
79 $skipping = tableExists_de($matches[1]);
81 echo "<font color='green'>";
84 echo xlt('Skipping section');
85 echo " " . text($line) . "</font><br />\n";
86 } else if (preg_match('/^#EndIf/', $line)) {
90 if (preg_match('/^\s*#/', $line)) {
102 $query = $query . $line;
104 if (substr($query, -1) == '$') {
105 $query = rtrim($query, '$');
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";
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";
141 $sqldir = "$webserver_root/sql";
142 $dh = opendir($sqldir);
144 die(xlt("Cannot read") . " " . text($sqldir));
151 <title
><?php
echo xlt('OpenEMR Database Upgrade'); ?
></title
>
152 <link rel
='STYLESHEET' href
='../../interface/themes/style_sky_blue.css'>
156 <span
class='title'><?php
echo xlt('OpenEMR Database Upgrade for De-identification'); ?
></span
>
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'];
173 echo "<p>" . text(getSqlLastError()) . " (#" . text(getSqlLastErrorNo()) . ")\n";
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.");
181 echo "<p>" . text(getSqlLastError()) . " (#" . text(getSqlLastErrorNo()) . ")\n";
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";
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');?>");
215 /*if(document.forms[0].root_user_pass.value == "")
217 alert("<?php echo xls('Enter Database root Password');?>");
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()); ?>" />
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");
234 echo "([OPENEMR]/contrib/util/de_identification_upgrade.php)";
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
> 
;</td
><td colspan
=3 align
=center
> 
;</td
><td
> 
;</td
></tr
>
241 <td
><?php
echo xlt('Enter Database root Username'); ?
></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
>
249 <td
><?php
echo xlt('Enter Database root Password'); ?
></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
>
255 <tr
><td
> 
;</td
><td colspan
=3 align
=center
> 
;</td
><td
> 
;</td
></tr
>
258 <p
><input type
='submit' name
='form_submit' value
="<?php echo xla('Upgrade Database');?>" /></p
>