Bug fix for "Deleted data is displaying in the Recent vital section"
[openemr.git] / admin.php
blob933aab283e396d6418c39d5947350acb74cd51bc
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 $openemr_version = $row['v_major'] . "." . $row['v_minor'] . "." .
101 $row['v_patch'] . $row['v_tag'];
102 $database_version = 0 + $row['v_database'];
105 // Display relevant columns.
106 echo " <td>$openemr_name</td>\n";
107 echo " <td>$openemr_version</td>\n";
108 if ($v_database == $database_version) {
109 echo " <td><a href='interface/login/login_frame.php?site=$sfname'>Log In</a></td>\n";
111 else {
112 echo " <td><a href='sql_upgrade.php?site=$sfname'>Upgrade Database</a></td>\n";
115 echo " </tr>\n";
117 if ($config && $dbh !== FALSE) mysql_close($dbh);
120 </table>
121 <form method='post' action='setup.php'>
122 <p><input type='submit' name='form_submit' value='Add New Site' /></p>
123 </form>
124 </center>
125 </body>
126 </html>