Fixing critical issues with Fees > Batch Payments (#2656)
[openemr.git] / sql_patch.php
blobb5a2b0ff32bc9d1ad942897a3d9d96657ed6e33c
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 // Checks if the server's PHP version is compatible with OpenEMR:
14 require_once(dirname(__FILE__) . "/src/Common/Compatibility/Checker.php");
15 $response = OpenEMR\Common\Compatibility\Checker::checkPhpVersion();
16 if ($response !== true) {
17 die(htmlspecialchars($response));
20 // Disable PHP timeout. This will not work in safe mode.
21 ini_set('max_execution_time', '0');
23 $ignoreAuth = true; // no login required
25 require_once('interface/globals.php');
26 require_once('library/sql_upgrade_fx.php');
28 use OpenEMR\Services\VersionService;
30 $versionService = new VersionService();
32 // Fetching current version because it was updated by the sql_upgrade_fx
33 // script and this script will further modify it.
34 $currentVersion = $versionService->fetch();
36 $desiredVersion = $currentVersion;
37 $desiredVersion->setDatabase($v_database);
38 $desiredVersion->setTag($v_tag);
39 $desiredVersion->setRealPatch($v_realpatch);
40 $desiredVersion->setPatch($v_patch);
41 $desiredVersion->setMinor($v_minor);
42 $desiredVersion->setMajor($v_major);
44 // Force logging off
45 $GLOBALS["enable_auditlog"]=0;
47 $EMRversion = trim(preg_replace('/\s*\([^)]*\)/', '', $GLOBALS['openemr_version']));
51 <html>
52 <head>
53 <title>OpenEMR <?php echo attr($EMRversion) ?> <?php echo xlt('Database Patch'); ?></title>
54 <link rel='STYLESHEET' href='interface/themes/style_blue.css'>
55 <link rel="shortcut icon" href="public/images/favicon.ico" />
56 </head>
57 <body style="color:green;">
59 <div style="box-shadow: 3px 3px 5px 6px #ccc; border-radius: 20px; padding: 10px 40px;background-color:#EFEFEF; width:500px; margin:40px auto">
61 <p style="font-weight:bold; font-size:1.8em; text-align:center">OpenEMR <?php echo text($EMRversion),' ',xlt('Database Patch'),' ',text($desiredVersion->getRealPatch()) ?></p>
62 <p style="font-weight:bold; text-align:center;"><?php echo xlt('Applying Patch to site'),' : ',text($_SESSION['site_id']) ?></p>
65 <?php
66 upgradeFromSqlFile('patch.sql');
67 flush();
69 echo '<p style="font-weight:bold; text-align:left; color:green">',xlt('Updating global configuration defaults'),'...</p>';
70 $skipGlobalEvent = true; //use in globals.inc.php script to skip event stuff
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 (is_array($fldtype) || (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 $canRealPatchBeApplied = $versionService->canRealPatchBeApplied($desiredVersion);
86 if ($canRealPatchBeApplied) {
87 echo '<p style="font-weight:bold; text-align:left;">',xlt('Updating version indicators'),'...</p>';
88 $result = $versionService->update($desiredVersion);
90 if (!$result) {
91 echo '<p style="font-weight:bold; text-align:left; color:red">',xlt('Unable insert version information into database'),'...</p>';
95 echo '<p style="text-align:center; font-size:1.8em;">',xlt('Database Patch'),' ',text($desiredVersion->getRealPatch()),' ',xlt('finished'),'.</p>';
97 echo '<p style="text-align:center; font-size:1.8em;">OpenEMR ',xlt('Version'),' = ',text($EMRversion.'('.$desiredVersion->getRealPatch().')'),'.</p>';
99 echo '<p><a style="border-radius: 10px; padding:5px; width:200px; margin:0 auto; background-color:green; color:white; font-weight:bold; display:block; text-align:center;" href="index.php?site=',attr($_SESSION['site_id']).'">',xlt('Log in'),'</a></p>';
101 if (isset($_SERVER['HTTP_REFERER'])) {
102 $split = preg_split('/\//', $_SERVER['HTTP_REFERER']);
103 if ($split[count($split) - 1] == 'admin.php') {
104 echo '<p><a style="border-radius: 10px; padding:5px; width:200px; margin:0 auto; background-color:green; color:white; font-weight:bold; display:block; text-align:center;" href="admin.php">',xlt('Back to Admin Page'),'</a></p>';
109 </div>
110 </body>
111 </html>