removed call time *pass by reference* and made sure pass by reference specified in...
[openemr.git] / interface / code_systems / standard_tables_manage.php
blob7a1a2849071e38830734d965bc5cc8ce1318f734
1 <?php
2 /*******************************************************************/
3 // Copyright (C) 2011 Phyaura, LLC <info@phyaura.com>
4 //
5 // Authors:
6 // Rohit Kumar <pandit.rohit@netsity.com>
7 // Brady Miller <brady@sparmy.com>
8 //
9 // This program is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License
11 // as published by the Free Software Foundation; either version 2
12 // of the License, or (at your option) any later version.
13 /*******************************************************************/
15 //SANITIZE ALL ESCAPES
16 $sanitize_all_escapes=true;
19 //STOP FAKE REGISTER GLOBALS
20 $fake_register_globals=false;
23 require_once("../../interface/globals.php");
24 require_once("$srcdir/acl.inc");
25 require_once("$srcdir/standard_tables_capture.inc");
27 // Ensure script doesn't time out and has enough memory
28 set_time_limit(0);
29 ini_set('memory_limit', '150M');
31 // Control access
32 if (!acl_check('admin', 'super')) {
33 echo htmlspecialchars( xl('Not Authorized'), ENT_NOQUOTES);
34 exit;
37 // Collect parameters (ensure mode is either rxnorm or snomed)
38 $mode = isset($_GET['mode']) ? $_GET['mode'] : '';
39 if ($mode != 'rxnorm' && $mode != 'snomed') {
40 exit;
42 $process = isset($_GET['process']) ? $_GET['process'] : '0';
44 // Set path constant
45 if ($mode == 'rxnorm') {
46 $mainPATH = $GLOBALS['fileroot']."/contrib/rxnorm";
48 else { // $mode == 'snomed'
49 $mainPATH = $GLOBALS['fileroot']."/contrib/snomed";
52 // Get current revision (if installed)
53 $installed_flag = false;
54 $current_revision = '';
55 if ($mode == 'rxnorm') {
56 $sqlReturn = sqlQuery("SELECT DATE_FORMAT(`revision_date`,'%Y-%m-%d') as `revision` FROM `standardized_tables_track` WHERE `name` = 'RXNORM' ORDER BY `revision_date` DESC");
58 else { // $mode == 'snomed'
59 $sqlReturn = sqlQuery("SELECT DATE_FORMAT(`revision_date`,'%Y-%m-%d') as `revision` FROM `standardized_tables_track` WHERE `name` = 'SNOMED' ORDER BY `revision_date` DESC");
61 if (!empty($sqlReturn)) {
62 $installed_flag = true;
63 $current_revision = $sqlReturn['revision'];
66 // See if a database file exist (collect revision and see if upgrade is an option)
67 $pending_new = false;
68 $pending_upgrade = false;
69 $file_revision_path = ''; //Holds the database file
70 $file_revision_date = ''; //Holds the database file revision date
71 $revisions = array();
72 $files_array = array();
73 if (is_dir($mainPATH)) {
74 $files_array = scandir($mainPATH);
76 foreach ($files_array as $file) {
77 $file = $mainPATH."/".$file;
78 if (is_file($file)) {
79 if ($mode == 'rxnorm') {
80 if (preg_match("/RxNorm_full_([0-9]{8}).zip/",$file,$matches)) {
81 $temp_date = array(substr($matches[1],4)."-".substr($matches[1],0,2)."-".substr($matches[1],2,-4)=>$mainPATH."/".$matches[0]);
82 $revisions = array_merge($revisions,$temp_date);
85 else { // $mode == 'snomed'
86 if (preg_match("/SnomedCT_INT_([0-9]{8}).zip/",$file,$matches)) {
87 $temp_date = array(substr($matches[1],0,4)."-".substr($matches[1],4,-2)."-".substr($matches[1],6)=>$mainPATH."/".$matches[0]);
88 $revisions = array_merge($revisions,$temp_date);
90 else if (preg_match("/SnomedCT_Release_INT_([0-9]{8}).zip/",$file,$matches)) {
91 $temp_date = array(substr($matches[1],0,4)."-".substr($matches[1],4,-2)."-".substr($matches[1],6)=>$mainPATH."/".$matches[0]);
92 $revisions = array_merge($revisions,$temp_date);
94 else {
95 // nothing
100 if (!empty($revisions)) {
101 //sort dates and store the most recent dated file
102 krsort($revisions);
103 reset($revisions);
104 $file_revision_path = $revisions[key($revisions)];
105 reset($revisions);
106 $file_revision_date = key($revisions);
108 if ( !($installed_flag) && !empty($file_revision_date) ) {
109 $pending_new = true;
111 else if (strtotime($file_revision_date) > strtotime($current_revision)) {
112 $pending_upgrade = true;
114 else {
115 // do nothing
119 // Use the above booleans ($pending_new=>new,$pending_upgrade=>upgrade,$installed_flag=>installed vs. not installed)
120 // to figure out what to do in below script.
123 <html>
124 <head>
125 <?php html_header_show();?>
126 <?php if ($mode == 'rxnorm') { ?>
127 <title><?php echo htmlspecialchars( xl('RxNorm'), ENT_NOQUOTES); ?></title>
128 <?php } else { //$mode == 'snomed' ?>
129 <title><?php echo htmlspecialchars( xl('SNOMED'), ENT_NOQUOTES); ?></title>
130 <?php } ?>
131 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
133 <script type="text/javascript" src="../../library/js/jquery-1.4.3.min.js"></script>
134 <script type="text/javascript" src="../../../library/dialog.js"></script>
135 <script type="text/javascript" src="../../../library/textformat.js"></script>
136 <script type="text/javascript" src="../../../library/js/common.js"></script>
138 <script type="text/javascript">
139 function loading_show() {
140 $('#loading').show();
142 </script>
144 </head>
145 <body class="body_top">
147 <?php if ($mode == 'rxnorm') { ?>
148 <span class="title"><?php echo htmlspecialchars( xl('RxNorm Database'), ENT_NOQUOTES); ?></span><br><br>
149 <?php } else { //$mode == 'snomed' ?>
150 <span class="title"><?php echo htmlspecialchars( xl('SNOMED Database'), ENT_NOQUOTES); ?></span><br><br>
151 <?php } ?>
153 <?php if ($pending_new || $pending_upgrade) { ?>
154 <?php
155 if ($process != 1) {
156 if ($pending_new) {
157 echo htmlspecialchars( xl('Database is not installed.'), ENT_NOQUOTES)."<br>";
158 echo htmlspecialchars( xl('Click Install button to install database release from the following date').": ", ENT_NOQUOTES)."<b>".htmlspecialchars($file_revision_date, ENT_NOQUOTES)."</b><br>";
159 echo "(".htmlspecialchars( xl('Note it will take 5-10 minutes to fully process after you click Install'), ENT_NOQUOTES).")<br><br>";
160 echo "<div id='loading' style='margin:10px;display:none;'><img src='../pic/ajax-loader.gif'/></div>";
161 echo "<a href='standard_tables_manage.php?process=1&mode=".$mode."' class='css_button' onclick='loading_show();top.restoreSession();'><span>".htmlspecialchars( xl('Install'), ENT_NOQUOTES)."</span></a><br><br>";
163 else { //$pending_upgrade
164 echo htmlspecialchars( xl('The following database release is currently installed').": ",ENT_NOQUOTES)."<b>".htmlspecialchars($current_revision,ENT_NOQUOTES)."</b><br>";
165 echo htmlspecialchars( xl('Click Upgrade button to upgrade database release from the following date').": ", ENT_NOQUOTES)."<b>".htmlspecialchars($file_revision_date, ENT_NOQUOTES)."</b><br>";
166 echo "(".htmlspecialchars( xl('Note it will take 5-10 minutes to fully process after you click Upgrade'), ENT_NOQUOTES).")<br><br>";
167 echo "<div id='loading' style='margin:10px;display:none;'><img src='../pic/ajax-loader.gif'/></div>";
168 echo "<a href='standard_tables_manage.php?process=1&mode=".$mode."' class='css_button' onclick='loading_show();top.restoreSession();'><span>".htmlspecialchars( xl('Upgrade'), ENT_NOQUOTES)."</span></a><br><br>";
171 else {
172 // install/upgrade the rxnorm database
174 // Clean up temp dir before start
175 temp_dir_cleanup($mode);
177 // 1. copy the file to temp directory
178 echo htmlspecialchars( xl('Copying the database file. This will take some time...'), ENT_NOQUOTES)."<br>";
179 if (!temp_copy($file_revision_path,$mode)) {
180 echo htmlspecialchars( xl('ERROR: Unable to copy the file.'), ENT_NOQUOTES)."<br>";
181 temp_dir_cleanup($mode);
182 exit;
185 // 2. unarchive the file
186 echo htmlspecialchars( xl('Extracting the file. This will take some time...'), ENT_NOQUOTES)."<br>";
187 if (!temp_unarchive($file_revision_path,$mode)) {
188 echo htmlspecialchars( xl('ERROR: Unable to extract the file.'), ENT_NOQUOTES)."<br>";
189 temp_dir_cleanup($mode);
190 exit;
193 // 3. load the database
194 echo htmlspecialchars( xl('Loading the files into the database. This will take some time...'), ENT_NOQUOTES)."<br>";
195 if ($mode == 'rxnorm') {
196 if (!rxnorm_import(IS_WINDOWS)) {
197 echo htmlspecialchars( xl('ERROR: Unable to load the file into the database.'), ENT_NOQUOTES)."<br>";
198 temp_dir_cleanup($mode);
199 exit;
202 else { //$mode == 'snomed'
203 if (!snomed_import()) {
204 echo htmlspecialchars( xl('ERROR: Unable to load the file into the database.'), ENT_NOQUOTES)."<br>";
205 temp_dir_cleanup($mode);
206 exit;
210 // 4. set the revision version in the database
211 echo htmlspecialchars( xl('Setting the version number in the database...'), ENT_NOQUOTES)."<br>";
212 if (!update_tracker_table($mode,$file_revision_date)) {
213 echo htmlspecialchars( xl('ERROR: Unable to set the version number.'), ENT_NOQUOTES)."<br>";
214 temp_dir_cleanup($mode);
215 exit;
218 // done, so clean up the temp directory
219 if ($pending_new) {
220 echo "<b>".htmlspecialchars( xl('Successfully installed the database.'), ENT_NOQUOTES)."</b><br>";
222 else { //$pending_upgrade
223 echo "<b>".htmlspecialchars( xl('Successfully upgraded the database.'), ENT_NOQUOTES)."</b><br>";
225 temp_dir_cleanup($mode);
228 <?php } else if ($installed_flag) { ?>
229 <?php echo htmlspecialchars( xl('The following database release is currently installed').": ",ENT_NOQUOTES)."<b>".htmlspecialchars($current_revision,ENT_NOQUOTES)."</b><br>"; ?>
230 <?php echo htmlspecialchars( xl('If you want to upgrade the database, then place the database zip file in the following directory').": contrib/".$mode, ENT_NOQUOTES); ?><br><br>
231 <?php } else { // !$installed_flag ?>
232 <?php echo htmlspecialchars( xl('Database is not installed.'), ENT_NOQUOTES); ?><br>
233 <?php echo htmlspecialchars( xl('Place the database zip file in the following directory if want the option to install').": contrib/".$mode, ENT_NOQUOTES); ?><br><br>
234 <?php }?>
235 </body>
236 </html>