proposed fix to straighten out the bootstrap alert classes
[openemr.git] / admin.php
blob3d553076b602a4310bd86612e870d7a09be0adcb
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 $response = OpenEMR\Checker::checkPhpVersion();
13 if ($response !== true) {
14 die($response);
17 require_once "version.php";
19 // Please note that the plain sql is used over the Doctrine ORM for
20 // `version` table interactions because it cannot connect due to a
21 // lack of context (this code is ran outside of the OpenEMR context).
23 $webserver_root = dirname(__FILE__);
24 if (stripos(PHP_OS, 'WIN') === 0) {
25 $webserver_root = str_replace("\\", "/", $webserver_root);
28 $OE_SITES_BASE = "$webserver_root/sites";
30 function sqlQuery($statement, $link)
32 $row = mysqli_fetch_array(mysqli_query($link, $statement), MYSQLI_ASSOC);
33 return $row;
36 <html>
37 <head>
38 <title>OpenEMR Site Administration</title>
39 <link rel='STYLESHEET' href='interface/themes/style_sky_blue.css'>
40 <style>
41 tr.head { font-size:10pt; background-color:#cccccc; text-align:center; font-weight:bold; }
42 tr.detail { font-size:10pt; }
43 a, a:visited, a:hover { color:#0000cc; text-decoration:none; }
44 </style>
45 </head>
46 <body>
47 <center>
48 <p><span class='title'>OpenEMR Site Administration</span></p>
49 <table width='100%' cellpadding='1' cellspacing='2'>
50 <tr class='head'>
51 <td>Site ID</td>
52 <td>DB Name</td>
53 <td>Site Name</td>
54 <td>Version</td>
55 <td>Action</td>
56 </tr>
57 <?php
58 $dh = opendir($OE_SITES_BASE);
59 if (!$dh) {
60 die("Cannot read directory '$OE_SITES_BASE'.");
63 $siteslist = array();
65 while (false !== ($sfname = readdir($dh))) {
66 if (substr($sfname, 0, 1) == '.') {
67 continue;
70 if ($sfname == 'CVS') {
71 continue;
74 $sitedir = "$OE_SITES_BASE/$sfname";
75 if (!is_dir($sitedir)) {
76 continue;
79 if (!is_file("$sitedir/sqlconf.php")) {
80 continue;
83 $siteslist[$sfname] = $sfname;
86 closedir($dh);
87 ksort($siteslist);
89 $encount = 0;
90 foreach ($siteslist as $sfname) {
91 $sitedir = "$OE_SITES_BASE/$sfname";
92 $errmsg = '';
93 ++$encount;
94 $bgcolor = "#" . (($encount & 1) ? "ddddff" : "ffdddd");
96 echo " <tr class='detail' bgcolor='$bgcolor'>\n";
98 // Access the site's database.
99 include "$sitedir/sqlconf.php";
101 if ($config) {
102 $dbh = mysqli_connect("$host", "$login", "$pass", $dbase, $port);
103 if (!$dbh) {
104 $errmsg = "MySQL connect failed";
108 echo " <td>$sfname</td>\n";
109 echo " <td>$dbase</td>\n";
111 if (!$config) {
112 echo " <td colspan='3'><a href='setup.php?site=$sfname'>Needs setup, click here to run it</a></td>\n";
113 } else if ($errmsg) {
114 echo " <td colspan='3' style='color:red'>$errmsg</td>\n";
115 } else {
116 // Get site name for display.
117 $row = sqlQuery("SELECT gl_value FROM globals WHERE gl_name = 'openemr_name' LIMIT 1", $dbh);
118 $openemr_name = $row ? $row['gl_value'] : '';
120 // Get version indicators from the database.
121 $row = sqlQuery("SHOW TABLES LIKE 'version'", $dbh);
122 if (empty($row)) {
123 $openemr_version = 'Unknown';
124 $database_version = 0;
125 } else {
126 $row = sqlQuery("SELECT * FROM version LIMIT 1", $dbh);
127 $database_patch_txt = "";
128 if (!(empty($row['v_realpatch'])) && $row['v_realpatch'] != 0) {
129 $database_patch_txt = " (" . $row['v_realpatch'] .")";
132 $openemr_version = $row['v_major'] . "." . $row['v_minor'] . "." .
133 $row['v_patch'] . $row['v_tag'] . $database_patch_txt;
134 $database_version = 0 + $row['v_database'];
135 $database_acl = 0 + $row['v_acl'];
136 $database_patch = 0 + $row['v_realpatch'];
139 // Display relevant columns.
140 echo " <td>$openemr_name</td>\n";
141 echo " <td>$openemr_version</td>\n";
142 if ($v_database != $database_version) {
143 echo " <td><a href='sql_upgrade.php?site=$sfname'>Upgrade Database</a></td>\n";
144 } else if (($v_acl > $database_acl)) {
145 echo " <td><a href='acl_upgrade.php?site=$sfname'>Upgrade Access Controls</a></td>\n";
146 } else if (($v_realpatch != $database_patch)) {
147 echo " <td><a href='sql_patch.php?site=$sfname'>Patch Database</a></td>\n";
148 } else {
149 echo " <td><a href='interface/login/login.php?site=$sfname'>Log In</a></td>\n";
153 echo " </tr>\n";
155 if ($config && $dbh !== false) {
156 mysqli_close($dbh);
160 </table>
161 <form method='post' action='setup.php'>
162 <p><input type='submit' name='form_submit' value='Add New Site' /></p>
163 </form>
164 </center>
165 </body>
166 </html>