Mangled path fax send (#7515)
[openemr.git] / interface / usergroup / facilities.php
blob14753da647decdb97e19a259f31775309573aa8e
1 <?php
3 /**
4 * Facilities.
6 * @package OpenEMR
7 * @link https://www.open-emr.org
8 * @author Ranganath Pathak <pathak01@hotmail.com>
9 * @author Brady Miller <brady.g.miller@gmail.com>
10 * @author Stephen Waite <stephen.waite@cmsvt.com>
11 * @copyright Copyright (c) 2017 Ranganath Pathak <pathak01@hotmail.com>
12 * @copyright Copyright (c) 2017-2018 Brady Miller <brady.g.miller@gmail.com>
13 * @copyright Copyright (c) 2021 Stephen Waite <stephen.waite@cmsvt.com>
14 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
17 require_once("../globals.php");
19 use OpenEMR\Common\Acl\AclMain;
20 use OpenEMR\Common\Csrf\CsrfUtils;
21 use OpenEMR\Common\Twig\TwigContainer;
22 use OpenEMR\Core\Header;
23 use OpenEMR\Services\FacilityService;
25 if (!AclMain::aclCheckCore('admin', 'users')) {
26 echo (new TwigContainer(null, $GLOBALS['kernel']))->getTwig()->render('core/unauthorized.html.twig', ['pageTitle' => xl("Facilities")]);
27 exit;
30 if (!empty($_POST)) {
31 if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
32 CsrfUtils::csrfNotVerified();
36 $facilityService = new FacilityService();
38 $alertmsg = '';
40 $columns = [
41 "name" => "facility",
42 "phone" => true,
43 "fax" => true,
44 "street" => true,
45 "city" => true,
46 "state" => true,
47 "postal_code" => true,
48 "country_code" => true,
49 "federal_ein" => true,
50 "website" => true,
51 "email" => true,
52 "color" => "ncolor",
53 "service_location" => true,
54 "billing_location" => true,
55 "accepts_assignment" => true,
56 "pos_code" => true,
57 "domain_identifier" => true,
58 "attn" => true,
59 "tax_id_type" => true,
60 "primary_business_entity" => true,
61 "facility_npi" => true,
62 "facility_taxonomy" => true,
63 "facility_code" => "facility_id",
64 "mail_street" => true,
65 "mail_street2" => true,
66 "mail_city" => true,
67 "mail_state" => true,
68 "mail_zip" => true,
69 "oid" => true,
70 "iban" => true,
71 "info" => true,
72 "inactive" => true
75 $values = [];
76 // Populate the $values array with a associative array of column names => $_POST value
77 foreach ($columns as $c => $v) {
78 // Ensure form fields that have a different name from the column gets corrected
79 $k = ($columns[$c] !== true) ? $v : $c;
80 $values[$c] = trim($_POST[$k] ?? '');
83 /* Inserting New facility */
84 if (($_POST["mode"] ?? "") == "facility" && (empty($_POST["newmode"]) || ($_POST["newmode"] != "admin_facility"))) {
85 $insert_id = $facilityService->insertFacility($values);
86 exit(); // sjp 12/20/17 for ajax save
89 /* Editing existing facility */
90 if (($_POST["mode"] ?? "") == "facility" && $_POST["newmode"] == "admin_facility") {
91 // Since it's an edit, add in the facility ID
92 $values["id"] = trim($_POST['fid'] ?? '');
93 $facilityService->updateFacility($values);
95 // Update facility name for all users with this facility.
96 // This is necessary because some provider based code uses facility name for lookups instead of facility id.
98 $facilityService->updateUsersFacility($values['name'], $values['id']);
99 exit(); // sjp 12/20/17 for ajax save
103 <!DOCTYPE html >
104 <html>
105 <head>
106 <title><?php echo xlt("Facilities") ; ?></title>
107 <?php Header::setupHeader(['common']); ?>
108 <script>
109 function refreshme() {
110 top.restoreSession();
111 document.location.reload();
113 $(function () {
114 $(".medium_modal").on('click', function(e) {
115 e.preventDefault();
116 e.stopPropagation();
117 dlgopen('', '', 1020, 900, '', '', {
118 allowResize: true,
119 allowDrag: true, // note these default to true if not defined here. left as example.
120 type: 'iframe',
121 url: $(this).attr('href')
125 $(".addfac_modal").on('click', function(e) {
126 e.preventDefault();e.stopPropagation();
127 dlgopen('', '', 1020, 620, '', '', {
128 allowResize: false,
129 allowDrag: true,
130 type: 'iframe',
131 url: $(this).attr('href')
135 $("#form_inactive").on('click', function(e) {
136 $(".inactive").toggleClass('d-none');
137 $("#form_inactive i").toggleClass("fa-square-check");
138 $("#form_inactive i").toggleClass("fa-square");
142 </script>
143 </head>
145 <body class="">
146 <div class="container">
147 <div class="row">
148 <div class="col-12 my-2 justify-content-between d-flex align-items-center">
149 <a href="facilities_add.php" class="addfac_modal btn btn-text btn-add"><?php echo xlt('Add Facility');?></a>
150 <div class="form-check d-flex align-items-center">
151 <input class="form-check-input" type="checkbox" value="" id="form_inactive">
152 <label class="form-check-label" for="form_inactive">
153 <?php echo xlt('Include Inactive Facilities'); ?>
154 </label>
155 </div>
156 </div>
157 </div>
158 <div class="row">
159 <div class="col-12">
160 <div class="table-responsive">
161 <table class="table table-striped">
162 <thead>
163 <tr>
164 <th scope="col"><?php echo xlt('Name'); ?></th>
165 <th scope="col"><?php echo xlt('Tax ID'); ?></th>
166 <th scope="col"><?php echo xlt('NPI'); ?></th>
167 <th scope="col"><?php echo xlt('Billing Address'); ?></th>
168 <th scope="col"><?php echo xlt('Mailing Address'); ?></th>
169 <th scope="col"><?php echo xlt('Phone'); ?></th>
170 </tr>
171 </thead>
172 <tbody>
173 <?php
174 $fres = 0;
175 $fres = $facilityService->getAllFacility();
176 if ($fres) {
177 $result2 = array();
178 for ($iter3 = 0; $iter3 < sizeof($fres); $iter3++) {
179 $result2[$iter3] = $fres[$iter3];
182 foreach ($result2 as $iter3) {
183 $varstreet = "";//these are assigned conditionally below,blank assignment is done so that old values doesn't get propagated to next level.
184 $varcity = "";
185 $varstate = "";
186 $varmstreet = "";
187 $varmcity = "";
188 $varmstate = "";
189 $varstreet = $iter3["street"];
190 if ($iter3["street"] != "") {
191 $varstreet = $iter3["street"] . " ";
194 if ($iter3["city"] != "") {
195 $varcity = $iter3["city"] . ", ";
198 if ($iter3["state"] != "") {
199 $varstate = $iter3["state"] . " ";
202 $varmstreet = $iter3["mail_street"];
203 if ($iter3["mail_street"] != "") {
204 $varmstreet = $iter3["mail_street"] . " ";
207 if ($iter3["mail_city"] != "") {
208 $varmcity = $iter3["mail_city"] . ", ";
211 if ($iter3["mail_state"] != "") {
212 $varmstate = $iter3["mail_state"] . " ";
215 <tr class="<?php echo ($iter3['inactive']) ? 'inactive text-muted d-none' : '';?>">
216 <td valign="top" class="text">
217 <a class="font-weight-bold medium_modal" href="facility_admin.php?fid=<?php echo attr_url($iter3["id"]); ?>"><?php echo xlt($iter3["name"]);?></a>
218 <?php echo ($iter3['inactive']) ? "<br>(" . xlt("Inactive") . ")" : ''; ?>
219 </td>
220 <td valign="top" class="text"><?php echo text($iter3["federal_ein"]); ?>&nbsp;</td>
221 <td valign="top" class="text"><?php echo text($iter3["facility_npi"]); ?>&nbsp;</td>
222 <td valign="top" class="text"><?php echo text($varstreet) . "<br>" . text($varcity) . text($varstate) . text($iter3["country_code"]) . " " . text($iter3["postal_code"]); ?></td>
223 <td valign="top" class="text"><?php echo text($varmstreet) . "<br>" . text($varmcity) . text($varmstate) . " " . text($iter3['mail_zip']); ?></td>
224 <td><?php echo text($iter3["phone"]);?>&nbsp;</td>
225 </tr>
226 <?php
230 if (count($result2) <= 0) {?>
231 <tr height="25">
232 <td colspan="3" class="text-center font-weight-bold"> <?php echo xlt("Currently there are no facilities."); ?></td>
233 </tr>
234 <?php
235 } ?>
236 </tbody>
237 </table>
238 </div>
239 </div>
240 </div>
241 </div><!-- end of div container -->
242 <script>
243 <?php
244 if ($alertmsg = trim($alertmsg)) {
245 echo "alert(" . js_escape($alertmsg) . ");\n";
248 </script>
249 </body>
250 </html>