Merge pull request #1421 from priya-anand/patch-6
[openemr.git] / admin.php
blobce741b159bf2d168c1c745ee207af563b31c2647
1 <?php
2 // Copyright (C) 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.
9 // Checks if the server's PHP version is compatible with OpenEMR:
10 require_once(dirname(__FILE__) . "/common/compatibility/Checker.php");
12 use OpenEMR\Common\Checker;
14 $response = Checker::checkPhpVersion();
15 if ($response !== true) {
16 die($response);
19 require_once "version.php";
21 // Please note that the plain sql is used over the Doctrine ORM for
22 // `version` table interactions because it cannot connect due to a
23 // lack of context (this code is ran outside of the OpenEMR context).
25 $webserver_root = dirname(__FILE__);
26 if (stripos(PHP_OS, 'WIN') === 0) {
27 $webserver_root = str_replace("\\", "/", $webserver_root);
30 $OE_SITES_BASE = "$webserver_root/sites";
32 function sqlQuery($statement, $link)
34 $row = mysqli_fetch_array(mysqli_query($link, $statement), MYSQLI_ASSOC);
35 return $row;
38 <html>
39 <head>
40 <title>OpenEMR Site Administration</title>
41 <link rel='STYLESHEET' href='interface/themes/style_sky_blue.css'>
42 <style>
43 tr.head { font-size:10pt; background-color:#cccccc; text-align:center; font-weight:bold; }
44 tr.detail { font-size:10pt; }
45 a, a:visited, a:hover { color:#0000cc; text-decoration:none; }
46 </style>
47 </head>
48 <body>
49 <center>
50 <p><span class='title'>OpenEMR Site Administration</span></p>
51 <table width='100%' cellpadding='1' cellspacing='2'>
52 <tr class='head'>
53 <td>Site ID</td>
54 <td>DB Name</td>
55 <td>Site Name</td>
56 <td>Version</td>
57 <td>Action</td>
58 </tr>
59 <?php
60 $dh = opendir($OE_SITES_BASE);
61 if (!$dh) {
62 die("Cannot read directory '$OE_SITES_BASE'.");
65 $siteslist = array();
67 while (false !== ($sfname = readdir($dh))) {
68 if (substr($sfname, 0, 1) == '.') {
69 continue;
72 if ($sfname == 'CVS') {
73 continue;
76 $sitedir = "$OE_SITES_BASE/$sfname";
77 if (!is_dir($sitedir)) {
78 continue;
81 if (!is_file("$sitedir/sqlconf.php")) {
82 continue;
85 $siteslist[$sfname] = $sfname;
88 closedir($dh);
89 ksort($siteslist);
91 $encount = 0;
92 foreach ($siteslist as $sfname) {
93 $sitedir = "$OE_SITES_BASE/$sfname";
94 $errmsg = '';
95 ++$encount;
96 $bgcolor = "#" . (($encount & 1) ? "ddddff" : "ffdddd");
98 echo " <tr class='detail' bgcolor='$bgcolor'>\n";
100 // Access the site's database.
101 include "$sitedir/sqlconf.php";
103 if ($config) {
104 $dbh = mysqli_connect("$host", "$login", "$pass", $dbase, $port);
105 if (!$dbh) {
106 $errmsg = "MySQL connect failed";
110 echo " <td>$sfname</td>\n";
111 echo " <td>$dbase</td>\n";
113 if (!$config) {
114 echo " <td colspan='3'><a href='setup.php?site=$sfname'>Needs setup, click here to run it</a></td>\n";
115 } else if ($errmsg) {
116 echo " <td colspan='3' style='color:red'>$errmsg</td>\n";
117 } else {
118 // Get site name for display.
119 $row = sqlQuery("SELECT gl_value FROM globals WHERE gl_name = 'openemr_name' LIMIT 1", $dbh);
120 $openemr_name = $row ? $row['gl_value'] : '';
122 // Get version indicators from the database.
123 $row = sqlQuery("SHOW TABLES LIKE 'version'", $dbh);
124 if (empty($row)) {
125 $openemr_version = 'Unknown';
126 $database_version = 0;
127 } else {
128 $row = sqlQuery("SELECT * FROM version LIMIT 1", $dbh);
129 $database_patch_txt = "";
130 if (!(empty($row['v_realpatch'])) && $row['v_realpatch'] != 0) {
131 $database_patch_txt = " (" . $row['v_realpatch'] .")";
134 $openemr_version = $row['v_major'] . "." . $row['v_minor'] . "." .
135 $row['v_patch'] . $row['v_tag'] . $database_patch_txt;
136 $database_version = 0 + $row['v_database'];
137 $database_acl = 0 + $row['v_acl'];
138 $database_patch = 0 + $row['v_realpatch'];
141 // Display relevant columns.
142 echo " <td>$openemr_name</td>\n";
143 echo " <td>$openemr_version</td>\n";
144 if ($v_database != $database_version) {
145 echo " <td><a href='sql_upgrade.php?site=$sfname'>Upgrade Database</a></td>\n";
146 } else if (($v_acl > $database_acl)) {
147 echo " <td><a href='acl_upgrade.php?site=$sfname'>Upgrade Access Controls</a></td>\n";
148 } else if (($v_realpatch != $database_patch)) {
149 echo " <td><a href='sql_patch.php?site=$sfname'>Patch Database</a></td>\n";
150 } else {
151 echo " <td><a href='interface/login/login.php?site=$sfname'>Log In</a></td>\n";
155 echo " </tr>\n";
157 if ($config && $dbh !== false) {
158 mysqli_close($dbh);
162 </table>
163 <form method='post' action='setup.php'>
164 <p><input type='submit' name='form_submit' value='Add New Site' /></p>
165 </form>
166 </center>
167 </body>
168 </html>