minor adjustments to questionnaire code (#5788)
[openemr.git] / admin.php
blobb299ffd0735294c433dc74bf2428381d69a755ad
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 $webserver_root = dirname(__FILE__);
26 if (stripos(PHP_OS, 'WIN') === 0) {
27 $webserver_root = str_replace("\\", "/", $webserver_root);
30 $OE_SITES_BASE = "$webserver_root/sites";
32 function sqlQuery($statement, $link)
34 $row = mysqli_fetch_array(mysqli_query($link, $statement), MYSQLI_ASSOC);
35 return $row;
38 <html>
39 <head>
40 <title>OpenEMR Site Administration</title>
41 <link rel="stylesheet" href="public/assets/bootstrap/dist/css/bootstrap.min.css">
42 <script src="public/assets/jquery/dist/jquery.min.js"></script>
43 <script src="public/assets/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
44 <link rel="stylesheet" href="public/assets/@fortawesome/fontawesome-free/css/all.min.css">
45 <link rel="shortcut icon" href="public/images/favicon.ico" />
46 </head>
47 <body>
48 <div class='container mt-3'>
49 <div class="row">
50 <div class="col-12">
51 <div class="d-flex justify-content-between align-items-center">
52 <h2>OpenEMR Multi Site Administration</h2>
53 <a class="text-secondary" data-target="#myModal" data-toggle="modal" href="#" id="help-href" name="help-href">
54 <i class="fa fa-question-circle fa-lg" aria-hidden="true" data-toggle="tooltip" data-placement="top" title="Click to view Help"></i>
55 </a>
56 </div>
57 </div>
58 </div>
60 <div class="row">
61 <div class="col-sm-12">
62 <div class="table-responsive">
63 <table class='table table-striped text-center'>
64 <tr>
65 <th>Site ID</th>
66 <th>DB Name</th>
67 <th>Site Name</th>
68 <th>Version</th>
69 <th>Is Current</th>
70 <th>Log In</th>
71 </tr>
72 <?php
73 $dh = opendir($OE_SITES_BASE);
74 if (!$dh) {
75 die("Cannot read directory '$OE_SITES_BASE'.");
78 $siteslist = array();
80 while (false !== ($sfname = readdir($dh))) {
81 if (substr($sfname, 0, 1) == '.') {
82 continue;
85 if ($sfname == 'CVS') {
86 continue;
89 $sitedir = "$OE_SITES_BASE/$sfname";
90 if (!is_dir($sitedir)) {
91 continue;
94 if (!is_file("$sitedir/sqlconf.php")) {
95 continue;
98 $siteslist[$sfname] = $sfname;
101 closedir($dh);
102 ksort($siteslist);
104 $encount = 0;
105 foreach ($siteslist as $sfname) {
106 $sitedir = "$OE_SITES_BASE/$sfname";
107 $errmsg = '';
108 ++$encount;
110 echo " <tr>\n";
112 // Access the site's database.
113 include "$sitedir/sqlconf.php";
115 if ($config) {
116 $dbh = mysqli_connect("$host", "$login", "$pass", $dbase, $port);
117 if (!$dbh) {
118 $errmsg = "MySQL connect failed";
122 echo " <td>$sfname</td>\n";
123 echo " <td>$dbase</td>\n";
125 if (!$config) {
126 echo " <td colspan='3'><a href='setup.php?site=$sfname' class='text-decoration-none'>Needs setup, click here to run it</a></td>\n";
127 } elseif ($errmsg) {
128 echo " <td colspan='3' class='text-danger'>$errmsg</td>\n";
129 } else {
130 // Get site name for display.
131 $row = sqlQuery("SELECT gl_value FROM globals WHERE gl_name = 'openemr_name' LIMIT 1", $dbh);
132 $openemr_name = $row ? $row['gl_value'] : '';
134 // Get version indicators from the database.
135 $row = sqlQuery("SHOW TABLES LIKE 'version'", $dbh);
136 if (empty($row)) {
137 $openemr_version = 'Unknown';
138 $database_version = 0;
139 } else {
140 $row = sqlQuery("SELECT * FROM version LIMIT 1", $dbh);
141 $database_patch_txt = "";
142 if (!(empty($row['v_realpatch'])) && $row['v_realpatch'] != 0) {
143 $database_patch_txt = " (" . $row['v_realpatch'] . ")";
146 $openemr_version = $row['v_major'] . "." . $row['v_minor'] . "." .
147 $row['v_patch'] . $row['v_tag'] . $database_patch_txt;
148 $database_version = 0 + $row['v_database'];
149 $database_acl = 0 + $row['v_acl'];
150 $database_patch = 0 + $row['v_realpatch'];
153 // Display relevant columns.
154 echo " <td>$openemr_name</td>\n";
155 echo " <td>$openemr_version</td>\n";
156 if ($v_database != $database_version) {
157 echo " <td><a href='sql_upgrade.php?site=$sfname' class='text-decoration-none'>Upgrade Database</a></td>\n";
158 } elseif (($v_acl > $database_acl)) {
159 echo " <td><a href='acl_upgrade.php?site=$sfname' class='text-decoration-none'>Upgrade Access Controls</a></td>\n";
160 } elseif (($v_realpatch != $database_patch)) {
161 echo " <td><a href='sql_patch.php?site=$sfname' class='text-decoration-none'>Patch Database</a></td>\n";
162 } else {
163 echo " <td><i class='fa fa-check fa-lg text-success' aria-hidden='true' ></i></a></td>\n";
165 if (($v_database == $database_version) && ($v_acl <= $database_acl) && ($v_realpatch == $database_patch)) {
166 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";
167 } else {
168 echo " <td><i class='fa fa-ban fa-lg text-secondary' aria-hidden='true'></i></td>\n";
172 echo " </tr>\n";
174 if ($config && $dbh !== false) {
175 mysqli_close($dbh);
179 </table>
180 </div>
181 <form method='post' action='setup.php'>
182 <button type='submit' class='btn btn-primary font-weight-bold' name='form_submit' value='Add New Site'>Add New Site</button>
183 </form>
184 </div>
185 </div>
186 </div><!--end of container div-->
188 <div class="row">
189 <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
190 <div class="modal-dialog modal-lg">
191 <div class="modal-content" style="height:700px">
192 <div class="modal-header clearfix">
193 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
194 <span aria-hidden="true" style="color:var(--black); font-size:1.5em;">×</span>
195 </button>
196 </div>
197 <div class="modal-body" style="height:80%;">
198 <iframe src="" id="targetiframe" class="h-100 w-100" style="overflow-x: hidden; border:none"
199 allowtransparency="true"></iframe>
200 </div>
201 <div class="modal-footer mt-0">
202 <button class="btn btn-secondary" data-dismiss="modal" type="button">Close</button>
203 </div>
204 </div>
205 </div>
206 </div>
207 </div>
208 <script>
209 $(function () {
210 $('#help-href').click (function() {
211 document.getElementById('targetiframe').src = "Documentation/help_files/openemr_multisite_admin_help.php";
214 $(function () {
215 $('#print-help-href').click (function(){
216 $("#targetiframe").get(0).contentWindow.print();
219 $(function () {
220 $('[data-toggle="tooltip"]').tooltip();
222 // Jquery draggable
223 $(".modal-dialog").addClass('drag-action');
224 $(".modal-content").addClass('resize-action');
225 </script>
226 </body>
227 </html>