Merge pull request #940 for adding access controls for encounter categories
[openemr.git] / admin.php
blob791b63ed71c9b1ea368f0fbe3b32832eb9a0f1ed
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);
26 $OE_SITES_BASE = "$webserver_root/sites";
28 function sqlQuery($statement, $link)
30 $row = mysqli_fetch_array(mysqli_query($link, $statement), MYSQLI_ASSOC);
31 return $row;
34 <html>
35 <head>
36 <title>OpenEMR Site Administration</title>
37 <link rel='STYLESHEET' href='interface/themes/style_sky_blue.css'>
38 <style>
39 tr.head { font-size:10pt; background-color:#cccccc; text-align:center; font-weight:bold; }
40 tr.detail { font-size:10pt; }
41 a, a:visited, a:hover { color:#0000cc; text-decoration:none; }
42 </style>
43 </head>
44 <body>
45 <center>
46 <p><span class='title'>OpenEMR Site Administration</span></p>
47 <table width='100%' cellpadding='1' cellspacing='2'>
48 <tr class='head'>
49 <td>Site ID</td>
50 <td>DB Name</td>
51 <td>Site Name</td>
52 <td>Version</td>
53 <td>Action</td>
54 </tr>
55 <?php
56 $dh = opendir($OE_SITES_BASE);
57 if (!$dh) die("Cannot read directory '$OE_SITES_BASE'.");
58 $siteslist = array();
60 while (false !== ($sfname = readdir($dh))) {
61 if (substr($sfname, 0, 1) == '.') continue;
62 if ($sfname == 'CVS' ) continue;
63 $sitedir = "$OE_SITES_BASE/$sfname";
64 if (!is_dir($sitedir) ) continue;
65 if (!is_file("$sitedir/sqlconf.php")) continue;
66 $siteslist[$sfname] = $sfname;
69 closedir($dh);
70 ksort($siteslist);
72 $encount = 0;
73 foreach ($siteslist as $sfname) {
74 $sitedir = "$OE_SITES_BASE/$sfname";
75 $errmsg = '';
76 ++$encount;
77 $bgcolor = "#" . (($encount & 1) ? "ddddff" : "ffdddd");
79 echo " <tr class='detail' bgcolor='$bgcolor'>\n";
81 // Access the site's database.
82 include "$sitedir/sqlconf.php";
84 if ($config) {
85 $dbh = mysqli_connect("$host", "$login", "$pass", $dbase, $port);
86 if (!$dbh)
87 $errmsg = "MySQL connect failed";
90 echo " <td>$sfname</td>\n";
91 echo " <td>$dbase</td>\n";
93 if (!$config) {
94 echo " <td colspan='3'><a href='setup.php?site=$sfname'>Needs setup, click here to run it</a></td>\n";
96 else if ($errmsg) {
97 echo " <td colspan='3' style='color:red'>$errmsg</td>\n";
99 else {
100 // Get site name for display.
101 $row = sqlQuery("SELECT gl_value FROM globals WHERE gl_name = 'openemr_name' LIMIT 1", $dbh);
102 $openemr_name = $row ? $row['gl_value'] : '';
104 // Get version indicators from the database.
105 $row = sqlQuery("SHOW TABLES LIKE 'version'", $dbh);
106 if (empty($row)) {
107 $openemr_version = 'Unknown';
108 $database_version = 0;
110 else {
111 $row = sqlQuery("SELECT * FROM version LIMIT 1", $dbh);
112 $database_patch_txt = "";
113 if ( !(empty($row['v_realpatch'])) && $row['v_realpatch'] != 0 ) {
114 $database_patch_txt = " (" . $row['v_realpatch'] .")";
116 $openemr_version = $row['v_major'] . "." . $row['v_minor'] . "." .
117 $row['v_patch'] . $row['v_tag'] . $database_patch_txt;
118 $database_version = 0 + $row['v_database'];
119 $database_acl = 0 + $row['v_acl'];
120 $database_patch = 0 + $row['v_realpatch'];
123 // Display relevant columns.
124 echo " <td>$openemr_name</td>\n";
125 echo " <td>$openemr_version</td>\n";
126 if ($v_database != $database_version) {
127 echo " <td><a href='sql_upgrade.php?site=$sfname'>Upgrade Database</a></td>\n";
129 else if ( ($v_acl > $database_acl) ) {
130 echo " <td><a href='acl_upgrade.php?site=$sfname'>Upgrade Access Controls</a></td>\n";
132 else if ( ($v_realpatch != $database_patch) ) {
133 echo " <td><a href='sql_patch.php?site=$sfname'>Patch Database</a></td>\n";
135 else {
136 echo " <td><a href='interface/login/login.php?site=$sfname'>Log In</a></td>\n";
139 echo " </tr>\n";
141 if ($config && $dbh !== false) mysqli_close($dbh);
144 </table>
145 <form method='post' action='setup.php'>
146 <p><input type='submit' name='form_submit' value='Add New Site' /></p>
147 </form>
148 </center>
149 </body>
150 </html>