Snomed support improvements and bug fixes (take 3):
[openemr.git] / sql_upgrade.php
blobae7799a075325d3a544532031075797df177a46b
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 flush();
64 echo "<font color='green'>Updating global configuration defaults...</font><br />\n";
65 require_once("library/globals.inc.php");
66 foreach ($GLOBALS_METADATA as $grpname => $grparr) {
67 foreach ($grparr as $fldid => $fldarr) {
68 list($fldname, $fldtype, $flddef, $flddesc) = $fldarr;
69 if (substr($fldtype, 0, 2) !== 'm_') {
70 $row = sqlQuery("SELECT count(*) AS count FROM globals WHERE gl_name = '$fldid'");
71 if (empty($row['count'])) {
72 sqlStatement("INSERT INTO globals ( gl_name, gl_index, gl_value ) " .
73 "VALUES ( '$fldid', '0', '$flddef' )");
79 echo "<font color='green'>Updating Access Controls...</font><br />\n";
80 require("acl_upgrade.php");
81 echo "<br />\n";
83 echo "<font color='green'>Updating version indicators...</font><br />\n";
84 sqlStatement("UPDATE version SET v_major = '$v_major', v_minor = '$v_minor', " .
85 "v_patch = '$v_patch', v_tag = '$v_tag', v_database = '$v_database'");
87 echo "<p><font color='green'>Database and Access Control upgrade finished.</font></p>\n";
88 echo "</body></html>\n";
89 exit();
93 <center>
94 <form method='post' action='sql_upgrade.php'>
95 <p>Please select the prior release you are converting from:
96 <select name='form_old_version'>
97 <?php
98 foreach ($versions as $version => $filename) {
99 echo " <option value='$version'";
100 // Defaulting to most recent version, which is now 4.1.1.
101 if ($version === '4.1.1') echo " selected";
102 echo ">$version</option>\n";
105 </select>
106 </p>
107 <p>If you are unsure or were using a development version between two
108 releases, then choose the older of possible releases.</p>
109 <p><input type='submit' name='form_submit' value='Upgrade Database' /></p>
110 </form>
111 </center>
112 </body>
113 </html>