tab layout bug fix
[openemr.git] / admin.php
blobd121ad44eb4622c791af56fe86eb52dc936d1b45
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, $link) {
17 $row = mysqli_fetch_array(mysqli_query($link, $statement), MYSQLI_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 = mysqli_connect("$host", "$login", "$pass", $dbase, $port);
72 if (!$dbh)
73 $errmsg = "MySQL connect failed";
76 echo " <td>$sfname</td>\n";
77 echo " <td>$dbase</td>\n";
79 if (!$config) {
80 echo " <td colspan='3'><a href='setup.php?site=$sfname'>Needs setup, click here to run it</a></td>\n";
82 else if ($errmsg) {
83 echo " <td colspan='3' style='color:red'>$errmsg</td>\n";
85 else {
86 // Get site name for display.
87 $row = sqlQuery("SELECT gl_value FROM globals WHERE gl_name = 'openemr_name' LIMIT 1", $dbh);
88 $openemr_name = $row ? $row['gl_value'] : '';
90 // Get version indicators from the database.
91 $row = sqlQuery("SHOW TABLES LIKE 'version'", $dbh);
92 if (empty($row)) {
93 $openemr_version = 'Unknown';
94 $database_version = 0;
96 else {
97 $row = sqlQuery("SELECT * FROM version LIMIT 1", $dbh);
98 $database_patch_txt = "";
99 if ( !(empty($row['v_realpatch'])) && $row['v_realpatch'] != 0 ) {
100 $database_patch_txt = " (" . $row['v_realpatch'] .")";
102 $openemr_version = $row['v_major'] . "." . $row['v_minor'] . "." .
103 $row['v_patch'] . $row['v_tag'] . $database_patch_txt;
104 $database_version = 0 + $row['v_database'];
105 $database_acl = 0 + $row['v_acl'];
106 $database_patch = 0 + $row['v_realpatch'];
109 // Display relevant columns.
110 echo " <td>$openemr_name</td>\n";
111 echo " <td>$openemr_version</td>\n";
112 if ($v_database != $database_version) {
113 echo " <td><a href='sql_upgrade.php?site=$sfname'>Upgrade Database</a></td>\n";
115 else if ( ($v_acl > $database_acl) ) {
116 echo " <td><a href='acl_upgrade.php?site=$sfname'>Upgrade Access Controls</a></td>\n";
118 else if ( ($v_realpatch != $database_patch) ) {
119 echo " <td><a href='sql_patch.php?site=$sfname'>Patch Database</a></td>\n";
121 else {
122 echo " <td><a href='interface/login/login.php?site=$sfname'>Log In</a></td>\n";
125 echo " </tr>\n";
127 if ($config && $dbh !== FALSE) mysqli_close($dbh);
130 </table>
131 <form method='post' action='setup.php'>
132 <p><input type='submit' name='form_submit' value='Add New Site' /></p>
133 </form>
134 </center>
135 </body>
136 </html>