fix to prior commit
[openemr.git] / admin.php
blob75c06f56b23006bdbe5e739e0c8043a6536c864a
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 require_once "version.php";
11 $webserver_root = dirname(__FILE__);
12 if (stripos(PHP_OS,'WIN') === 0)
13 $webserver_root = str_replace("\\","/",$webserver_root);
14 $OE_SITES_BASE = "$webserver_root/sites";
16 function sqlQuery($statement) {
17 $row = @mysql_fetch_array(mysql_query($statement), MYSQL_ASSOC);
18 return $row;
21 <html>
22 <head>
23 <title>OpenEMR Site Administration</title>
24 <link rel='STYLESHEET' href='interface/themes/style_sky_blue.css'>
25 <style>
26 tr.head { font-size:10pt; background-color:#cccccc; text-align:center; font-weight:bold; }
27 tr.detail { font-size:10pt; }
28 a, a:visited, a:hover { color:#0000cc; text-decoration:none; }
29 </style>
30 </head>
31 <body>
32 <center>
33 <p><span class='title'>OpenEMR Site Administration</span></p>
34 <table width='100%' cellpadding='1' cellspacing='2'>
35 <tr class='head'>
36 <td>Site ID</td>
37 <td>DB Name</td>
38 <td>Site Name</td>
39 <td>Version</td>
40 <td>Action</td>
41 </tr>
42 <?php
43 $dh = opendir($OE_SITES_BASE);
44 if (!$dh) die("Cannot read directory '$OE_SITES_BASE'.");
45 $siteslist = array();
47 while (false !== ($sfname = readdir($dh))) {
48 if (substr($sfname, 0, 1) == '.') continue;
49 if ($sfname == 'CVS' ) continue;
50 $sitedir = "$OE_SITES_BASE/$sfname";
51 if (!is_dir($sitedir) ) continue;
52 if (!is_file("$sitedir/sqlconf.php")) continue;
53 $siteslist[$sfname] = $sfname;
56 closedir($dh);
57 ksort($siteslist);
59 foreach ($siteslist as $sfname) {
60 $sitedir = "$OE_SITES_BASE/$sfname";
61 $errmsg = '';
62 ++$encount;
63 $bgcolor = "#" . (($encount & 1) ? "ddddff" : "ffdddd");
65 echo " <tr class='detail' bgcolor='$bgcolor'>\n";
67 // Access the site's database.
68 include "$sitedir/sqlconf.php";
70 if ($config) {
71 $dbh = mysql_connect("$host:$port", "$login", "$pass");
72 if ($dbh === FALSE)
73 $errmsg = "MySQL connect failed";
74 else if (!mysql_select_db($dbase, $dbh))
75 $errmsg = "Access to database failed";
78 echo " <td>$sfname</td>\n";
79 echo " <td>$dbase</td>\n";
81 if (!$config) {
82 echo " <td colspan='3'><a href='setup.php?site=$sfname'>Needs setup, click here to run it</a></td>\n";
84 else if ($errmsg) {
85 echo " <td colspan='3' style='color:red'>$errmsg</td>\n";
87 else {
88 // Get site name for display.
89 $row = sqlQuery("SELECT gl_value FROM globals WHERE gl_name = 'openemr_name' LIMIT 1");
90 $openemr_name = $row ? $row['gl_value'] : '';
92 // Get version indicators from the database.
93 $row = sqlQuery("SHOW TABLES LIKE 'version'");
94 if (empty($row)) {
95 $openemr_version = 'Unknown';
96 $database_version = 0;
98 else {
99 $row = sqlQuery("SELECT * FROM version LIMIT 1");
100 $database_patch_txt = "";
101 if ( !(empty($row['v_realpatch'])) && $row['v_realpatch'] != 0 ) {
102 $database_patch_txt = " (" . $row['v_realpatch'] .")";
104 $openemr_version = $row['v_major'] . "." . $row['v_minor'] . "." .
105 $row['v_patch'] . $row['v_tag'] . $database_patch_txt;
106 $database_version = 0 + $row['v_database'];
107 $database_acl = 0 + $row['v_acl'];
108 $database_patch = 0 + $row['v_realpatch'];
111 // Display relevant columns.
112 echo " <td>$openemr_name</td>\n";
113 echo " <td>$openemr_version</td>\n";
114 if ($v_database != $database_version) {
115 echo " <td><a href='sql_upgrade.php?site=$sfname'>Upgrade Database</a></td>\n";
117 else if ( ($v_acl > $database_acl) ) {
118 echo " <td><a href='acl_upgrade.php?site=$sfname'>Upgrade Access Controls</a></td>\n";
120 else if ( ($v_realpatch != $database_patch) ) {
121 echo " <td><a href='sql_patch.php?site=$sfname'>Patch Database</a></td>\n";
123 else {
124 echo " <td><a href='interface/login/login_frame.php?site=$sfname'>Log In</a></td>\n";
127 echo " </tr>\n";
129 if ($config && $dbh !== FALSE) mysql_close($dbh);
132 </table>
133 <form method='post' action='setup.php'>
134 <p><input type='submit' name='form_submit' value='Add New Site' /></p>
135 </form>
136 </center>
137 </body>
138 </html>