Added Spain and Latin American locales of Spanish
[openemr.git] / sql_upgrade.php
blobba84cfcc4267b8a702b341659f57b8868211a755
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 version indicators...</font><br />\n";
80 sqlStatement("UPDATE version SET v_major = '$v_major', v_minor = '$v_minor', " .
81 "v_patch = '$v_patch', v_tag = '$v_tag', v_database = '$v_database'");
83 echo "<p><font color='green'>Database upgrade finished.</font></p>\n";
84 echo "</body></html>\n";
85 exit();
89 <center>
90 <form method='post' action='sql_upgrade.php'>
91 <p>Please select the prior release you are converting from:
92 <select name='form_old_version'>
93 <?php
94 foreach ($versions as $version => $filename) {
95 echo " <option value='$version'";
96 // Defaulting to most recent version, which is now 4.1.0.
97 if ($version === '4.1.0') echo " selected";
98 echo ">$version</option>\n";
101 </select>
102 </p>
103 <p>If you are unsure or were using a development version between two
104 releases, then choose the older of possible releases.</p>
105 <p><input type='submit' name='form_submit' value='Upgrade Database' /></p>
106 </form>
107 </center>
108 </body>
109 </html>