Http (#3926)
[openemr.git] / admin.php
blob9f6e20ac51f1dcffd7ac057a4ab220e83ba21723
1 <?php
3 /**
5 * Multi Site Administration script.
7 * @package OpenEMR
8 * @link https://www.open-emr.org
9 * @author Rod Roark <rod@sunsetsystems.com>
10 * @author Ranganath Pathak <pathak@scrs1.org>
11 * @copyright Copyright (C) 2010 Rod Roark <rod@sunsetsystems.com>
12 * @copyright Copyright (c) 2019 Ranganath Pathak <pathak@scrs1.org>
13 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
16 // Checks if the server's PHP version is compatible with OpenEMR:
17 require_once(dirname(__FILE__) . "/src/Common/Compatibility/Checker.php");
18 $response = OpenEMR\Common\Compatibility\Checker::checkPhpVersion();
19 if ($response !== true) {
20 die(htmlspecialchars($response));
23 require_once "version.php";
25 // Please note that the plain sql is used over the Doctrine ORM for
26 // `version` table interactions because it cannot connect due to a
27 // lack of context (this code is ran outside of the OpenEMR context).
29 $webserver_root = dirname(__FILE__);
30 if (stripos(PHP_OS, 'WIN') === 0) {
31 $webserver_root = str_replace("\\", "/", $webserver_root);
34 $OE_SITES_BASE = "$webserver_root/sites";
36 function sqlQuery($statement, $link)
38 $row = mysqli_fetch_array(mysqli_query($link, $statement), MYSQLI_ASSOC);
39 return $row;
42 <html>
43 <head>
44 <title>OpenEMR Site Administration</title>
45 <link rel="stylesheet" href="public/assets/bootstrap/dist/css/bootstrap.min.css">
46 <script src="public/assets/jquery/dist/jquery.min.js"></script>
47 <script src="public/assets/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
48 <link rel="stylesheet" href="public/assets/@fortawesome/fontawesome-free/css/all.min.css">
49 <link rel="shortcut icon" href="public/images/favicon.ico" />
50 </head>
51 <body>
52 <div class='container mt-3'>
53 <div class="row">
54 <div class="col-12">
55 <div class="d-flex justify-content-between align-items-center">
56 <h2>OpenEMR Multi Site Administration</h2>
57 <a class="text-secondary" data-target="#myModal" data-toggle="modal" href="#" id="help-href" name="help-href">
58 <i class="fa fa-question-circle fa-lg" aria-hidden="true" data-toggle="tooltip" data-placement="top" title="Click to view Help"></i>
59 </a>
60 </div>
61 </div>
62 </div>
64 <div class="row">
65 <div class="col-sm-12">
66 <div class="table-responsive">
67 <table class='table table-striped text-center'>
68 <tr>
69 <th>Site ID</th>
70 <th>DB Name</th>
71 <th>Site Name</th>
72 <th>Version</th>
73 <th>Is Current</th>
74 <th>Log In</th>
75 </tr>
76 <?php
77 $dh = opendir($OE_SITES_BASE);
78 if (!$dh) {
79 die("Cannot read directory '$OE_SITES_BASE'.");
82 $siteslist = array();
84 while (false !== ($sfname = readdir($dh))) {
85 if (substr($sfname, 0, 1) == '.') {
86 continue;
89 if ($sfname == 'CVS') {
90 continue;
93 $sitedir = "$OE_SITES_BASE/$sfname";
94 if (!is_dir($sitedir)) {
95 continue;
98 if (!is_file("$sitedir/sqlconf.php")) {
99 continue;
102 $siteslist[$sfname] = $sfname;
105 closedir($dh);
106 ksort($siteslist);
108 $encount = 0;
109 foreach ($siteslist as $sfname) {
110 $sitedir = "$OE_SITES_BASE/$sfname";
111 $errmsg = '';
112 ++$encount;
114 echo " <tr>\n";
116 // Access the site's database.
117 include "$sitedir/sqlconf.php";
119 if ($config) {
120 $dbh = mysqli_connect("$host", "$login", "$pass", $dbase, $port);
121 if (!$dbh) {
122 $errmsg = "MySQL connect failed";
126 echo " <td>$sfname</td>\n";
127 echo " <td>$dbase</td>\n";
129 if (!$config) {
130 echo " <td colspan='3'><a href='setup.php?site=$sfname' class='text-decoration-none'>Needs setup, click here to run it</a></td>\n";
131 } elseif ($errmsg) {
132 echo " <td colspan='3' class='text-danger'>$errmsg</td>\n";
133 } else {
134 // Get site name for display.
135 $row = sqlQuery("SELECT gl_value FROM globals WHERE gl_name = 'openemr_name' LIMIT 1", $dbh);
136 $openemr_name = $row ? $row['gl_value'] : '';
138 // Get version indicators from the database.
139 $row = sqlQuery("SHOW TABLES LIKE 'version'", $dbh);
140 if (empty($row)) {
141 $openemr_version = 'Unknown';
142 $database_version = 0;
143 } else {
144 $row = sqlQuery("SELECT * FROM version LIMIT 1", $dbh);
145 $database_patch_txt = "";
146 if (!(empty($row['v_realpatch'])) && $row['v_realpatch'] != 0) {
147 $database_patch_txt = " (" . $row['v_realpatch'] . ")";
150 $openemr_version = $row['v_major'] . "." . $row['v_minor'] . "." .
151 $row['v_patch'] . $row['v_tag'] . $database_patch_txt;
152 $database_version = 0 + $row['v_database'];
153 $database_acl = 0 + $row['v_acl'];
154 $database_patch = 0 + $row['v_realpatch'];
157 // Display relevant columns.
158 echo " <td>$openemr_name</td>\n";
159 echo " <td>$openemr_version</td>\n";
160 if ($v_database != $database_version) {
161 echo " <td><a href='sql_upgrade.php?site=$sfname' class='text-decoration-none'>Upgrade Database</a></td>\n";
162 } elseif (($v_acl > $database_acl)) {
163 echo " <td><a href='acl_upgrade.php?site=$sfname' class='text-decoration-none'>Upgrade Access Controls</a></td>\n";
164 } elseif (($v_realpatch != $database_patch)) {
165 echo " <td><a href='sql_patch.php?site=$sfname' class='text-decoration-none'>Patch Database</a></td>\n";
166 } else {
167 echo " <td><i class='fa fa-check fa-lg text-success' aria-hidden='true' ></i></a></td>\n";
169 if (($v_database == $database_version) && ($v_acl <= $database_acl) && ($v_realpatch == $database_patch)) {
170 echo " <td><a href='interface/login/login.php?site=$sfname' class='text-decoration-none'><i class='fa fa-sign-in-alt fa-lg' aria-hidden='true' data-toggle='tooltip' data-placement='top' title ='Login to site $sfname'></i></a></td>\n";
171 } else {
172 echo " <td><i class='fa fa-ban fa-lg text-secondary' aria-hidden='true'></i></td>\n";
176 echo " </tr>\n";
178 if ($config && $dbh !== false) {
179 mysqli_close($dbh);
183 </table>
184 </div>
185 <form method='post' action='setup.php'>
186 <button type='submit' class='btn btn-primary font-weight-bold' name='form_submit' value='Add New Site'>Add New Site</button>
187 </form>
188 </div>
189 </div>
190 </div><!--end of container div-->
192 <div class="row">
193 <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
194 <div class="modal-dialog modal-lg">
195 <div class="modal-content" style="height:700px">
196 <div class="modal-header clearfix">
197 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
198 <span aria-hidden="true" style="color:var(--black); font-size:1.5em;">×</span>
199 </button>
200 </div>
201 <div class="modal-body" style="height:80%;">
202 <iframe src="" id="targetiframe" class="h-100 w-100" style="overflow-x: hidden; border:none"
203 allowtransparency="true"></iframe>
204 </div>
205 <div class="modal-footer mt-0">
206 <button class="btn btn-secondary" data-dismiss="modal" type="button">Close</button>
207 </div>
208 </div>
209 </div>
210 </div>
211 </div>
212 <script>
213 $(function () {
214 $('#help-href').click (function() {
215 document.getElementById('targetiframe').src = "Documentation/help_files/openemr_multisite_admin_help.php";
218 $(function () {
219 $('#print-help-href').click (function(){
220 $("#targetiframe").get(0).contentWindow.print();
223 $(function () {
224 $('[data-toggle="tooltip"]').tooltip();
226 // Jquery draggable
227 $(".modal-dialog").addClass('drag-action');
228 $(".modal-content").addClass('resize-action');
229 </script>
230 </body>
231 </html>