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