path fix for public images
[openemr.git] / sql_upgrade.php
blob97a86f14aeaca70fc61cf54eac73eb4afd70ead3
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 <link rel="shortcut icon" href="public/images/favicon.ico" />
44 </head>
45 <body>
46 <center>
47 <span class='title'>OpenEMR Database Upgrade</span>
48 <br>
49 </center>
50 <?php
51 if (!empty($_POST['form_submit'])) {
52 $form_old_version = $_POST['form_old_version'];
54 foreach ($versions as $version => $filename) {
55 if (strcmp($version, $form_old_version) < 0) continue;
56 upgradeFromSqlFile($filename);
59 if (!empty($GLOBALS['ippf_specific'])) {
60 // Upgrade custom stuff for IPPF.
61 upgradeFromSqlFile('ippf_upgrade.sql');
64 if ( (!empty($v_realpatch)) && ($v_realpatch != "") && ($v_realpatch > 0) ) {
65 // This release contains a patch file, so process it.
66 upgradeFromSqlFile('patch.sql');
69 flush();
71 echo "<font color='green'>Updating global configuration defaults...</font><br />\n";
72 require_once("library/globals.inc.php");
73 foreach ($GLOBALS_METADATA as $grpname => $grparr) {
74 foreach ($grparr as $fldid => $fldarr) {
75 list($fldname, $fldtype, $flddef, $flddesc) = $fldarr;
76 if ( is_array($fldtype) || (substr($fldtype, 0, 2) !== 'm_') ) {
77 $row = sqlQuery("SELECT count(*) AS count FROM globals WHERE gl_name = '$fldid'");
78 if (empty($row['count'])) {
79 sqlStatement("INSERT INTO globals ( gl_name, gl_index, gl_value ) " .
80 "VALUES ( '$fldid', '0', '$flddef' )");
86 echo "<font color='green'>Updating Access Controls...</font><br />\n";
87 require("acl_upgrade.php");
88 echo "<br />\n";
90 echo "<font color='green'>Updating version indicators...</font><br />\n";
91 sqlStatement("UPDATE version SET v_major = '$v_major', v_minor = '$v_minor', " .
92 "v_patch = '$v_patch', v_tag = '$v_tag', v_database = '$v_database'");
94 if ( (!empty($v_realpatch)) && ($v_realpatch != "") && ($v_realpatch > 0) ) {
95 // This release contains a patch file, so update patch indicator.
96 echo "<font color='green'>Patch was also installed, so update version patch indicator...</font><br />\n";
97 sqlStatement("UPDATE version SET v_realpatch = '$v_realpatch'");
100 echo "<p><font color='green'>Database and Access Control upgrade finished.</font></p>\n";
101 echo "</body></html>\n";
102 exit();
106 <center>
107 <form method='post' action='sql_upgrade.php'>
108 <p>Please select the prior release you are converting from:
109 <select name='form_old_version'>
110 <?php
111 foreach ($versions as $version => $filename) {
112 echo " <option value='$version'";
113 // Defaulting to most recent version, which is now 4.2.2.
114 if ($version === '4.2.2') echo " selected";
115 echo ">$version</option>\n";
118 </select>
119 </p>
120 <p>If you are unsure or were using a development version between two
121 releases, then choose the older of possible releases.</p>
122 <p style="color:red">If you are upgrading from a version below 5.0.0 to version 5.0.0 or greater, do note that this upgrade can take anywhere from several minutes to several hours (you will only see a whitescreen until it is complete; do not stop the script before it is complete or you risk corrupting your data).</p>
123 <p><input type='submit' name='form_submit' value='Upgrade Database' /></p>
124 </form>
125 </center>
126 </body>
127 </html>