Option for showing description instead of codes in LBF Billing Code fields, and some...
[openemr.git] / sql_upgrade.php
blob021403c94c0b906beebf8fe3cd0060b659a5d4bf
1 <?php
2 // Copyright (C) 2008-2010 Rod Roark <rod@sunsetsystems.com>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This may be run after an upgraded OpenEMR has been installed.
10 // Its purpose is to upgrade the MySQL OpenEMR database as needed
11 // for the new release.
13 // Disable PHP timeout. This will not work in safe mode.
14 ini_set('max_execution_time', '0');
16 $ignoreAuth = true; // no login required
18 require_once('interface/globals.php');
19 require_once('library/sql.inc');
20 require_once('library/sql_upgrade_fx.php');
22 // Force logging off
23 $GLOBALS["enable_auditlog"]=0;
25 $versions = array();
26 $sqldir = "$webserver_root/sql";
27 $dh = opendir($sqldir);
28 if (! $dh) die("Cannot read $sqldir");
29 while (false !== ($sfname = readdir($dh))) {
30 if (substr($sfname, 0, 1) == '.') continue;
31 if (preg_match('/^(\d+)_(\d+)_(\d+)-to-\d+_\d+_\d+_upgrade.sql$/', $sfname, $matches)) {
32 $version = $matches[1] . '.' . $matches[2] . '.' . $matches[3];
33 $versions[$version] = $sfname;
36 closedir($dh);
37 ksort($versions);
39 <html>
40 <head>
41 <title>OpenEMR Database Upgrade</title>
42 <link rel='STYLESHEET' href='interface/themes/style_blue.css'>
43 </head>
44 <body>
45 <center>
46 <span class='title'>OpenEMR Database Upgrade</span>
47 <br>
48 </center>
49 <?php
50 if (!empty($_POST['form_submit'])) {
51 $form_old_version = $_POST['form_old_version'];
53 foreach ($versions as $version => $filename) {
54 if (strcmp($version, $form_old_version) < 0) continue;
55 upgradeFromSqlFile($filename);
58 if (!empty($GLOBALS['ippf_specific'])) {
59 // Upgrade custom stuff for IPPF.
60 upgradeFromSqlFile('ippf_upgrade.sql');
63 if ( (!empty($v_realpatch)) && ($v_realpatch != "") && ($v_realpatch > 0) ) {
64 // This release contains a patch file, so process it.
65 upgradeFromSqlFile('patch.sql');
68 flush();
70 echo "<font color='green'>Updating global configuration defaults...</font><br />\n";
71 require_once("library/globals.inc.php");
72 foreach ($GLOBALS_METADATA as $grpname => $grparr) {
73 foreach ($grparr as $fldid => $fldarr) {
74 list($fldname, $fldtype, $flddef, $flddesc) = $fldarr;
75 if (substr($fldtype, 0, 2) !== 'm_') {
76 $row = sqlQuery("SELECT count(*) AS count FROM globals WHERE gl_name = '$fldid'");
77 if (empty($row['count'])) {
78 sqlStatement("INSERT INTO globals ( gl_name, gl_index, gl_value ) " .
79 "VALUES ( '$fldid', '0', '$flddef' )");
85 echo "<font color='green'>Updating Access Controls...</font><br />\n";
86 require("acl_upgrade.php");
87 echo "<br />\n";
89 echo "<font color='green'>Updating version indicators...</font><br />\n";
90 sqlStatement("UPDATE version SET v_major = '$v_major', v_minor = '$v_minor', " .
91 "v_patch = '$v_patch', v_tag = '$v_tag', v_database = '$v_database'");
93 if ( (!empty($v_realpatch)) && ($v_realpatch != "") && ($v_realpatch > 0) ) {
94 // This release contains a patch file, so update patch indicator.
95 echo "<font color='green'>Patch was also installed, so update version patch indicator...</font><br />\n";
96 sqlStatement("UPDATE version SET v_realpatch = '$v_realpatch'");
99 echo "<p><font color='green'>Database and Access Control upgrade finished.</font></p>\n";
100 echo "</body></html>\n";
101 exit();
105 <center>
106 <form method='post' action='sql_upgrade.php'>
107 <p>Please select the prior release you are converting from:
108 <select name='form_old_version'>
109 <?php
110 foreach ($versions as $version => $filename) {
111 echo " <option value='$version'";
112 // Defaulting to most recent version, which is now 4.1.2.
113 if ($version === '4.1.2') echo " selected";
114 echo ">$version</option>\n";
117 </select>
118 </p>
119 <p>If you are unsure or were using a development version between two
120 releases, then choose the older of possible releases.</p>
121 <p><input type='submit' name='form_submit' value='Upgrade Database' /></p>
122 </form>
123 </center>
124 </body>
125 </html>