bug fixins (#1951)
[openemr.git] / interface / super / edit_layout_props.php
blob9f9d1f3cac563539c50d3e2c0e14c3574c7e057d
1 <?php
2 /**
3 * Edit Layout Properties.
5 * Copyright (C) 2016-2017 Rod Roark <rod@sunsetsystems.com>
7 * LICENSE: This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
18 * @package OpenEMR
19 * @author Rod Roark <rod@sunsetsystems.com>
20 * @link http://www.open-emr.org
23 require_once("../globals.php");
24 require_once("$srcdir/acl.inc");
25 require_once("$phpgacl_location/gacl_api.class.php");
27 $alertmsg = "";
29 // Check authorization.
30 $thisauth = acl_check('admin', 'super');
31 if (!$thisauth) {
32 die(xlt('Not authorized'));
35 $layout_id = empty($_GET['layout_id']) ? '' : $_GET['layout_id'];
36 $group_id = empty($_GET['group_id' ]) ? '' : $_GET['group_id' ];
38 <html>
39 <head>
40 <?php html_header_show();?>
41 <title><?php echo xlt("Edit Layout Properties"); ?></title>
42 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
44 <style>
45 td { font-size:10pt; }
46 </style>
48 <script type="text/javascript" src="<?php echo $webroot ?>/interface/main/tabs/js/include_opener.js?v=<?php echo $v_js_includes; ?>"></script>
49 <script type="text/javascript" src="../../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script>
50 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery/dist/jquery.min.js"></script>
51 <script type="text/javascript" src="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
53 <script language="JavaScript">
55 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
57 // The name of the input element to receive a found code.
58 var current_sel_name = '';
60 // This invokes the "dynamic" find-code popup.
61 function sel_related(elem, codetype) {
62 current_sel_name = elem ? elem.name : '';
63 var url = '<?php echo $rootdir ?>/patient_file/encounter/find_code_dynamic.php';
64 if (codetype) url += '?codetype=' + codetype;
65 dlgopen(url, '_blank', 800, 500);
68 // This is for callback by the find-code popup.
69 // Appends to or erases the current list of related codes.
70 function set_related(codetype, code, selector, codedesc) {
71 var f = document.forms[0];
72 // frc will be the input element containing the codes.
73 var frc = f[current_sel_name];
74 var s = frc.value;
75 if (code) {
76 if (s.length > 0) {
77 s += ';';
79 s += codetype + ':' + code;
80 } else {
81 s = '';
83 frc.value = s;
84 return '';
87 // This is for callback by the find-code popup.
88 // Deletes the specified codetype:code from the active input element.
89 function del_related(s) {
90 var f = document.forms[0];
91 my_del_related(s, f[current_sel_name], false);
94 // This is for callback by the find-code popup.
95 // Returns the array of currently selected codes with each element in codetype:code format.
96 function get_related() {
97 var f = document.forms[0];
98 if (current_sel_name) {
99 return f[current_sel_name].value.split(';');
101 return new Array();
104 </script>
106 </head>
108 <body class="body_top">
110 <?php
111 if ($_POST['form_submit'] && !$alertmsg) {
112 if (!verifyCsrfToken($_POST["csrf_token_form"])) {
113 csrfNotVerified();
116 if ($group_id) {
117 $sets =
118 "grp_subtitle = ?, " .
119 "grp_columns = ?";
120 $sqlvars = array(
121 $_POST['form_subtitle'],
122 intval($_POST['form_columns']),
124 } else {
125 $sets =
126 "grp_title = ?, " .
127 "grp_subtitle = ?, " .
128 "grp_mapping = ?, " .
129 "grp_seq = ?, " .
130 "grp_activity = ?, " .
131 "grp_repeats = ?, " .
132 "grp_columns = ?, " .
133 "grp_size = ?, " .
134 "grp_issue_type = ?, " .
135 "grp_aco_spec = ?, " .
136 "grp_services = ?, " .
137 "grp_products = ?, " .
138 "grp_diags = ?";
139 $sqlvars = array(
140 $_POST['form_title'],
141 $_POST['form_subtitle'],
142 $_POST['form_mapping'],
143 intval($_POST['form_seq']),
144 empty($_POST['form_activity']) ? 0 : 1,
145 intval($_POST['form_repeats']),
146 intval($_POST['form_columns']),
147 intval($_POST['form_size']),
148 $_POST['form_issue'],
149 $_POST['form_aco'],
150 empty($_POST['form_services']) ? '' : (empty($_POST['form_services_codes']) ? '*' : $_POST['form_services_codes']),
151 empty($_POST['form_products']) ? '' : (empty($_POST['form_products_codes']) ? '*' : $_POST['form_products_codes']),
152 empty($_POST['form_diags' ]) ? '' : (empty($_POST['form_diags_codes' ]) ? '*' : $_POST['form_diags_codes' ]),
156 if ($layout_id) {
157 // They have edited an existing layout.
158 $sqlvars[] = $layout_id;
159 $sqlvars[] = $group_id;
160 sqlStatement(
161 "UPDATE layout_group_properties SET $sets " .
162 "WHERE grp_form_id = ? AND grp_group_id = ?",
163 $sqlvars
165 } else if (!$group_id) {
166 // They want to add a new layout. New groups not supported here.
167 $form_form_id = $_POST['form_form_id'];
168 if (preg_match('/(LBF|LBT)[0-9A-Za-z_]+/', $form_form_id)) {
169 $tmp = sqlQuery(
170 "SELECT grp_form_id FROM layout_group_properties WHERE " .
171 "grp_form_id = ? AND grp_group_id = ''",
172 array($form_form_id)
174 if (empty($row)) {
175 $sqlvars[] = $form_form_id;
176 sqlStatement(
177 "INSERT INTO layout_group_properties " .
178 "SET $sets, grp_form_id = ?, grp_group_id = ''",
179 $sqlvars
181 $layout_id = $form_form_id;
182 } else {
183 $alertmsg = xl('This layout ID already exists');
185 } else {
186 $alertmsg = xl('Invalid layout ID');
190 // Close this window and redisplay the layout editor.
192 echo "<script language='JavaScript'>\n";
193 if ($alertmsg) {
194 echo " alert('" . addslashes($alertmsg) . "');\n";
196 echo " if (opener.refreshme) opener.refreshme('" . attr($layout_id) . "');\n";
197 echo " window.close();\n";
198 echo "</script></body></html>\n";
199 exit();
202 $row = array(
203 'grp_form_id' => '',
204 'grp_title' => '',
205 'grp_subtitle' => '',
206 'grp_mapping' => 'Clinical',
207 'grp_seq' => '0',
208 'grp_activity' => '1',
209 'grp_repeats' => '0',
210 'grp_columns' => '4',
211 'grp_size' => '9',
212 'grp_issue_type' => '',
213 'grp_aco_spec' => '',
214 'grp_services' => '',
215 'grp_products' => '',
216 'grp_diags' => '',
219 if ($layout_id) {
220 $row = sqlQuery(
221 "SELECT * FROM layout_group_properties WHERE " .
222 "grp_form_id = ? AND grp_group_id = ?",
223 array($layout_id, $group_id)
225 if (empty($row)) {
226 die(xlt('This layout does not exist.'));
231 <form method='post' action='edit_layout_props.php?<?php echo "layout_id=" . attr($layout_id) . "&group_id=" . attr($group_id); ?>'>
232 <input type="hidden" name="csrf_token_form" value="<?php echo attr(collectCsrfToken()); ?>" />
233 <center>
235 <table border='0' width='100%'>
236 <?php if (empty($layout_id)) { ?>
237 <tr>
238 <td valign='top' width='1%' nowrap>
239 <?php echo xlt('Layout ID'); ?>
240 </td>
241 <td>
242 <input type='text' size='31' maxlength='31' name='form_form_id'
243 value='' /><br />
244 <?php echo xlt('Visit form ID must start with LBF. Transaction form ID must start with LBT.') ?>
245 </td>
246 </tr>
247 <?php } ?>
249 <?php if (empty($group_id)) { ?>
250 <tr>
251 <td valign='top' width='1%' nowrap>
252 <?php echo xlt('Title'); ?>
253 </td>
254 <td>
255 <input type='text' size='40' name='form_title' style='width:100%'
256 value='<?php echo attr($row['grp_title']); ?>' />
257 </td>
258 </tr>
259 <?php } ?>
261 <tr>
262 <td valign='top' width='1%' nowrap>
263 <?php echo xlt('Subtitle'); ?>
264 </td>
265 <td>
266 <input type='text' size='40' name='form_subtitle' style='width:100%'
267 value='<?php echo attr($row['grp_subtitle']); ?>' />
268 </td>
269 </tr>
271 <?php if (empty($group_id)) { ?>
273 <tr>
274 <td valign='top' width='1%' nowrap>
275 <?php echo xlt('Category'); ?>
276 </td>
277 <td>
278 <input type='text' size='40' name='form_mapping' style='width:100%'
279 value='<?php echo attr($row['grp_mapping']); ?>' />
280 </td>
281 </tr>
283 <tr>
284 <td valign='top' width='1%' nowrap>
285 <?php echo xlt('Active'); ?>
286 </td>
287 <td>
288 <input type='checkbox' name='form_activity' <?php if ($row['grp_activity']) {
289 echo "checked";} ?> />
290 </td>
291 </tr>
293 <tr>
294 <td valign='top' width='1%' nowrap>
295 <?php echo xlt('Sequence'); ?>
296 </td>
297 <td>
298 <input type='text' size='4' name='form_seq'
299 value='<?php echo attr($row['grp_seq']); ?>' />
300 </td>
301 </tr>
303 <tr>
304 <td valign='top' width='1%' nowrap>
305 <?php echo xlt('Repeats'); ?>
306 </td>
307 <td>
308 <input type='text' size='4' name='form_repeats'
309 value='<?php echo attr($row['grp_repeats']); ?>' />
310 </td>
311 </tr>
313 <?php } ?>
315 <tr>
316 <td valign='top' nowrap>
317 <?php echo xlt('Layout Columns'); ?>
318 </td>
319 <td>
320 <select name='form_columns'>
321 <?php
322 echo "<option value='0'>" . xlt('Default') . "</option>\n";
323 for ($cols = 2; $cols <= 10; ++$cols) {
324 echo "<option value='" . attr($cols) . "'";
325 if ($cols == $row['grp_columns']) {
326 echo " selected";
328 echo ">" . text($cols) . "</option>\n";
331 </select>
332 </td>
333 </tr>
335 <?php if (empty($group_id)) { ?>
337 <tr>
338 <td valign='top' nowrap>
339 <?php echo xlt('Font Size'); ?>
340 </td>
341 <td>
342 <select name='form_size'>
343 <?php
344 echo "<option value='0'>" . xlt('Default') . "</option>\n";
345 for ($size = 5; $size <= 15; ++$size) {
346 echo "<option value='" . attr($size) . "'";
347 if ($size == $row['grp_size']) {
348 echo " selected";
350 echo ">" . text($size) . "</option>\n";
353 </select>
354 </td>
355 </tr>
357 <tr>
358 <td valign='top' nowrap>
359 <?php echo xlt('Issue Type'); ?>
360 </td>
361 <td>
362 <select name='form_issue'>
363 <option value=''></option>
364 <?php
365 $itres = sqlStatement(
366 "SELECT type, singular FROM issue_types " .
367 "WHERE category = ? AND active = 1 ORDER BY singular",
368 array($GLOBALS['ippf_specific'] ? 'ippf_specific' : 'default')
370 while ($itrow = sqlFetchArray($itres)) {
371 echo "<option value='" . attr($itrow['type']) . "'";
372 if ($itrow['type'] == $row['grp_issue_type']) {
373 echo " selected";
375 echo ">" . xlt($itrow['singular']) . "</option>\n";
378 </select>
379 </td>
380 </tr>
382 <tr>
383 <td valign='top' nowrap>
384 <?php echo xlt('Access Control'); ?>
385 </td>
386 <td>
387 <select name='form_aco' style='width:100%'>
388 <option value=''></option>
389 <?php
390 $gacl = new gacl_api();
391 // collect and sort all aco objects
392 $list_aco_objects = $gacl->get_objects(null, 0, 'ACO');
393 ksort($list_aco_objects);
394 foreach ($list_aco_objects as $seckey => $dummy) {
395 if (empty($dummy)) {
396 continue;
398 asort($list_aco_objects[$seckey]);
399 $aco_section_data = $gacl->get_section_data($seckey, 'ACO');
400 $aco_section_title = $aco_section_data[3];
401 echo " <optgroup label='" . xla($aco_section_title) . "'>\n";
402 foreach ($list_aco_objects[$seckey] as $acokey) {
403 $aco_id = $gacl->get_object_id($seckey, $acokey, 'ACO');
404 $aco_data = $gacl->get_object_data($aco_id, 'ACO');
405 $aco_title = $aco_data[0][3];
406 echo " <option value='" . attr("$seckey|$acokey") . "'";
407 if ("$seckey|$acokey" == $row['grp_aco_spec']) {
408 echo " selected";
410 echo ">" . xla($aco_title) . "</option>\n";
412 echo " </optgroup>\n";
415 </select>
416 </td>
417 </tr>
419 <tr>
420 <td valign='top' width='1%' nowrap>
421 <input type='checkbox' name='form_services' <?php if ($row['grp_services']) {
422 echo "checked";} ?> />
423 <?php echo xlt('Show Services Section'); ?>
424 </td>
425 <td>
426 <input type='text' size='40' name='form_services_codes' onclick='sel_related(this, "MA")' style='width:100%'
427 value='<?php if ($row['grp_services'] != '*') {
428 echo attr($row['grp_services']);} ?>' />
429 </td>
430 </tr>
432 <tr>
433 <td valign='top' width='1%' nowrap>
434 <input type='checkbox' name='form_products' <?php if ($row['grp_products']) {
435 echo "checked";} ?> />
436 <?php echo xlt('Show Products Section'); ?>
437 </td>
438 <td>
439 <input type='text' size='40' name='form_products_codes' onclick='sel_related(this, "PROD")' style='width:100%'
440 value='<?php if ($row['grp_products'] != '*') {
441 echo attr($row['grp_products']);} ?>' />
442 </td>
443 </tr>
445 <tr>
446 <td valign='top' width='1%' nowrap>
447 <input type='checkbox' name='form_diags' <?php if ($row['grp_diags']) {
448 echo "checked";} ?> />
449 <?php echo xlt('Show Diagnoses Section'); ?>
450 </td>
451 <td>
452 <input type='text' size='40' name='form_diags_codes' onclick='sel_related(this, "ICD10")' style='width:100%'
453 value='<?php if ($row['grp_diags'] != '*') {
454 echo attr($row['grp_diags']);} ?>' />
455 </td>
456 </tr>
458 <?php } ?>
460 </table>
463 <input type='submit' name='form_submit' value='<?php echo xla('Submit'); ?>' />
465 &nbsp;
466 <input type='button' value='<?php echo xla('Cancel'); ?>' onclick='window.close()' />
467 </p>
469 </center>
470 </form>
471 <script language='JavaScript'>
472 <?php
473 if ($alertmsg) {
474 echo " alert('" . addslashes($alertmsg) . "');\n";
475 echo " window.close();\n";
478 </script>
479 </body>
480 </html>