3 * Copyright (C) 2014-2015 Rod Roark <rod@sunsetsystems.com>
5 * LICENSE: This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>.
17 * @author Rod Roark <rod@sunsetsystems.com>
18 * @link http://www.open-emr.org
21 require_once("../globals.php");
22 require_once("$srcdir/acl.inc");
23 require_once("$srcdir/log.inc");
24 require_once("$srcdir/formdata.inc.php");
27 'DEM' => xl('Demographics'),
28 'HIS' => xl('History'),
29 'FACUSR' => xl('Facility Specific User Information')
31 if ($GLOBALS['ippf_specific']) {
32 $layouts['GCA'] = xl('Abortion Issues');
33 $layouts['CON'] = xl('Contraception Issues');
36 // Include Layout Based Transaction Forms.
37 $lres = sqlStatement("SELECT * FROM list_options " .
38 "WHERE list_id = 'transactions' ORDER BY seq, title");
39 while ($lrow = sqlFetchArray($lres)) {
40 $layouts[$lrow['option_id']] = xl_list_label($lrow['title']);
43 // Include Layout Based Encounter Forms.
44 $lres = sqlStatement("SELECT * FROM list_options " .
45 "WHERE list_id = 'lbfnames' ORDER BY seq, title");
46 while ($lrow = sqlFetchArray($lres)) {
47 $layouts[$lrow['option_id']] = xl_list_label($lrow['title']);
50 // array of the data_types of the fields
52 "1" => xl("List box"),
54 "3" => xl("Textarea"),
55 "4" => xl("Text-date"),
56 "10" => xl("Providers"),
57 "11" => xl("Providers NPI"),
58 "12" => xl("Pharmacies"),
60 "14" => xl("Organizations"),
61 "15" => xl("Billing codes"),
62 "16" => xl("Insurances"),
63 "18" => xl("Visit Categories"),
64 "21" => xl("Checkbox list"),
65 "22" => xl("Textbox list"),
66 "23" => xl("Exam results"),
67 "24" => xl("Patient allergies"),
68 "25" => xl("Checkbox w/text"),
69 "26" => xl("List box w/add"),
70 "27" => xl("Radio buttons"),
71 "28" => xl("Lifestyle status"),
72 "31" => xl("Static Text"),
73 "32" => xl("Smoking Status"),
74 "33" => xl("Race and Ethnicity"),
75 "34" => xl("NationNotes"),
76 "35" => xl("Facilities"),
77 "36" => xl("Multiple Select List")
88 function nextGroupOrder($order) {
89 if ($order == '9') $order = 'A';
90 else if ($order == 'Z') $order = 'a';
91 else $order = chr(ord($order) +
1);
95 // Call this when adding or removing a layout field. This will create or drop
96 // the corresponding table column when appropriate. Table columns are not
97 // dropped if they contain any non-empty values.
98 function addOrDeleteColumn($layout_id, $field_id, $add=TRUE) {
99 if (substr($layout_id,0,3) == 'LBF' ||
substr($layout_id,0,3) == 'LBT' ||
$layout_id == "FACUSR") return;
101 if ($layout_id == "DEM") $tablename = "patient_data";
102 else if ($layout_id == "HIS") $tablename = "history_data";
103 else if ($layout_id == "SRH") $tablename = "lists_ippf_srh";
104 else if ($layout_id == "CON") $tablename = "lists_ippf_con";
105 else if ($layout_id == "GCA") $tablename = "lists_ippf_gcac";
106 else die('Internal error in addOrDeleteColumn()');
108 // Check if the column currently exists.
109 $tmp = sqlQuery("SHOW COLUMNS FROM `$tablename` LIKE '$field_id'");
110 $column_exists = !empty($tmp);
112 if ($add && !$column_exists) {
113 sqlStatement("ALTER TABLE `$tablename` ADD `$field_id` TEXT NOT NULL");
114 newEvent("alter_table", $_SESSION['authUser'], $_SESSION['authProvider'], 1,
115 "$tablename ADD $field_id");
117 else if (!$add && $column_exists) {
118 // Do not drop a column that has any data.
119 $tmp = sqlQuery("SELECT `$field_id` FROM `$tablename` WHERE " .
120 "`$field_id` IS NOT NULL AND `$field_id` != '' LIMIT 1");
121 if (!isset($tmp['field_id'])) {
122 sqlStatement("ALTER TABLE `$tablename` DROP `$field_id`");
123 newEvent("alter_table", $_SESSION['authUser'], $_SESSION['authProvider'], 1,
124 "$tablename DROP $field_id ");
129 // Check authorization.
130 $thisauth = acl_check('admin', 'super');
131 if (!$thisauth) die(xl('Not authorized'));
133 // The layout ID identifies the layout to be edited.
134 $layout_id = empty($_REQUEST['layout_id']) ?
'' : $_REQUEST['layout_id'];
136 // Tag style for stuff to hide if not an LBF layout. Currently just for the Source column.
137 $lbfonly = substr($layout_id,0,3) == 'LBF' ?
"" : "style='display:none;'";
139 // Handle the Form actions
141 if ($_POST['formaction'] == "save" && $layout_id) {
142 // If we are saving, then save.
143 $fld = $_POST['fld'];
144 for ($lino = 1; isset($fld[$lino]['id']); ++
$lino) {
146 $field_id = formTrim($iter['id']);
147 $data_type = formTrim($iter['data_type']);
148 $listval = $data_type == 34 ?
formTrim($iter['contextName']) : formTrim($iter['list_id']);
150 // Skip conditions for the line are stored as a serialized array.
152 for ($cix = 0; !empty($iter['condition_id'][$cix]); ++
$cix) {
153 $andor = empty($iter['condition_andor'][$cix]) ?
'' : $iter['condition_andor'][$cix];
154 $condarr[$cix] = array(
155 'id' => strip_escape_custom($iter['condition_id' ][$cix]),
156 'itemid' => strip_escape_custom($iter['condition_itemid' ][$cix]),
157 'operator' => strip_escape_custom($iter['condition_operator'][$cix]),
158 'value' => strip_escape_custom($iter['condition_value' ][$cix]),
159 'andor' => strip_escape_custom($andor),
162 $conditions = empty($condarr) ?
'' : serialize($condarr);
165 sqlStatement("UPDATE layout_options SET " .
166 "source = '" . formTrim($iter['source']) . "', " .
167 "title = '" . formTrim($iter['title']) . "', " .
168 "group_name = '" . formTrim($iter['group']) . "', " .
169 "seq = '" . formTrim($iter['seq']) . "', " .
170 "uor = '" . formTrim($iter['uor']) . "', " .
171 "fld_length = '" . formTrim($iter['lengthWidth']) . "', " .
172 "fld_rows = '" . formTrim($iter['lengthHeight']) . "', " .
173 "max_length = '" . formTrim($iter['maxSize']) . "', " .
174 "titlecols = '" . formTrim($iter['titlecols']) . "', " .
175 "datacols = '" . formTrim($iter['datacols']) . "', " .
176 "data_type= '$data_type', " .
177 "list_id= '" . $listval . "', " .
178 "list_backup_id= '" . formTrim($iter['list_backup_id']) . "', " .
179 "edit_options = '" . formTrim($iter['edit_options']) . "', " .
180 "default_value = '" . formTrim($iter['default']) . "', " .
181 "description = '" . formTrim($iter['desc']) . "', " .
182 "conditions = '" . add_escape_custom($conditions) . "' " .
183 "WHERE form_id = '$layout_id' AND field_id = '$field_id'");
188 else if ($_POST['formaction'] == "addfield" && $layout_id) {
189 // Add a new field to a specific group
190 $data_type = formTrim($_POST['newdatatype']);
191 $max_length = $data_type == 3 ?
3 : 255;
192 $listval = $data_type == 34 ?
formTrim($_POST['contextName']) : formTrim($_POST['newlistid']);
193 sqlStatement("INSERT INTO layout_options (" .
194 " form_id, source, field_id, title, group_name, seq, uor, fld_length, fld_rows" .
195 ", titlecols, datacols, data_type, edit_options, default_value, description" .
196 ", max_length, list_id, list_backup_id " .
198 "'" . formTrim($_POST['layout_id'] ) . "'" .
199 ",'" . formTrim($_POST['newsource'] ) . "'" .
200 ",'" . formTrim($_POST['newid'] ) . "'" .
201 ",'" . formTrim($_POST['newtitle'] ) . "'" .
202 ",'" . formTrim($_POST['newfieldgroupid']) . "'" .
203 ",'" . formTrim($_POST['newseq'] ) . "'" .
204 ",'" . formTrim($_POST['newuor'] ) . "'" .
205 ",'" . formTrim($_POST['newlengthWidth'] ) . "'" .
206 ",'" . formTrim($_POST['newlengthHeight'] ) . "'" .
207 ",'" . formTrim($_POST['newtitlecols'] ) . "'" .
208 ",'" . formTrim($_POST['newdatacols'] ) . "'" .
210 ",'" . formTrim($_POST['newedit_options']) . "'" .
211 ",'" . formTrim($_POST['newdefault'] ) . "'" .
212 ",'" . formTrim($_POST['newdesc'] ) . "'" .
213 ",'" . formTrim($_POST['newmaxSize']) . "'" .
214 ",'" . $listval . "'" .
215 ",'" . formTrim($_POST['newbackuplistid']) . "'" .
217 addOrDeleteColumn($layout_id, formTrim($_POST['newid']), TRUE);
220 else if ($_POST['formaction'] == "movefields" && $layout_id) {
221 // Move field(s) to a new group in the layout
222 $sqlstmt = "UPDATE layout_options SET ".
223 " group_name='". $_POST['targetgroup']."' ".
225 " form_id = '".$_POST['layout_id']."' ".
226 " AND field_id IN (";
228 foreach (explode(" ", $_POST['selectedfields']) as $onefield) {
229 $sqlstmt .= $comma."'".$onefield."'";
234 sqlStatement($sqlstmt);
237 else if ($_POST['formaction'] == "deletefields" && $layout_id) {
238 // Delete a field from a specific group
239 $sqlstmt = "DELETE FROM layout_options WHERE ".
240 " form_id = '".$_POST['layout_id']."' ".
241 " AND field_id IN (";
243 foreach (explode(" ", $_POST['selectedfields']) as $onefield) {
244 $sqlstmt .= $comma."'".$onefield."'";
248 sqlStatement($sqlstmt);
249 foreach (explode(" ", $_POST['selectedfields']) as $onefield) {
250 addOrDeleteColumn($layout_id, $onefield, FALSE);
254 else if ($_POST['formaction'] == "addgroup" && $layout_id) {
255 // all group names are prefixed with a number indicating their display order
256 // this new group is prefixed with the net highest number given the
258 $results = sqlStatement("select distinct(group_name) as gname ".
259 " from layout_options where ".
260 " form_id = '".$_POST['layout_id']."'"
263 while ($result = sqlFetchArray($results)) {
264 $tmp = substr($result['gname'], 0, 1);
265 if ($tmp >= $maxnum) $maxnum = nextGroupOrder($tmp);
268 $data_type = formTrim($_POST['gnewdatatype']);
269 $max_length = $data_type == 3 ?
3 : 255;
270 $listval = $data_type == 34 ?
formTrim($_POST['gcontextName']) : formTrim($_POST['gnewlistid']);
271 // add a new group to the layout, with the defined field
272 sqlStatement("INSERT INTO layout_options (" .
273 " form_id, source, field_id, title, group_name, seq, uor, fld_length, fld_rows" .
274 ", titlecols, datacols, data_type, edit_options, default_value, description" .
275 ", max_length, list_id, list_backup_id " .
277 "'" . formTrim($_POST['layout_id'] ) . "'" .
278 ",'" . formTrim($_POST['gnewsource'] ) . "'" .
279 ",'" . formTrim($_POST['gnewid'] ) . "'" .
280 ",'" . formTrim($_POST['gnewtitle'] ) . "'" .
281 ",'" . formTrim($maxnum . $_POST['newgroupname']) . "'" .
282 ",'" . formTrim($_POST['gnewseq'] ) . "'" .
283 ",'" . formTrim($_POST['gnewuor'] ) . "'" .
284 ",'" . formTrim($_POST['gnewlengthWidth'] ) . "'" .
285 ",'" . formTrim($_POST['gnewlengthHeight'] ) . "'" .
286 ",'" . formTrim($_POST['gnewtitlecols'] ) . "'" .
287 ",'" . formTrim($_POST['gnewdatacols'] ) . "'" .
289 ",'" . formTrim($_POST['gnewedit_options']) . "'" .
290 ",'" . formTrim($_POST['gnewdefault'] ) . "'" .
291 ",'" . formTrim($_POST['gnewdesc'] ) . "'" .
292 ",'" . formTrim($_POST['gnewmaxSize']) . "'" .
293 ",'" . $listval . "'" .
294 ",'" . formTrim($_POST['gnewbackuplistid'] ) . "'" .
296 addOrDeleteColumn($layout_id, formTrim($_POST['gnewid']), TRUE);
299 else if ($_POST['formaction'] == "deletegroup" && $layout_id) {
300 // drop the fields from the related table (this is critical)
301 $res = sqlStatement("SELECT field_id FROM layout_options WHERE " .
302 "form_id = '" . $_POST['layout_id'] . "' ".
303 "AND group_name = '" . $_POST['deletegroupname'] . "'");
304 while ($row = sqlFetchArray($res)) {
305 addOrDeleteColumn($layout_id, $row['field_id'], FALSE);
307 // Delete an entire group from the form
308 sqlStatement("DELETE FROM layout_options WHERE ".
309 " form_id = '".$_POST['layout_id']."' ".
310 " AND group_name = '".$_POST['deletegroupname']."'"
314 else if ($_POST['formaction'] == "movegroup" && $layout_id) {
315 $results = sqlStatement("SELECT DISTINCT(group_name) AS gname " .
316 "FROM layout_options WHERE form_id = '$layout_id' " .
320 while ($result = sqlFetchArray($results)) {
321 if ($result['gname'] == $_POST['movegroupname']) {
322 if ($_POST['movedirection'] == 'up') { // moving up
324 $garray[$i] = $garray[$i - 1];
325 $garray[$i - 1] = $result['gname'];
329 $garray[$i++
] = $result['gname'];
332 else { // moving down
334 $garray[$i++
] = $result['gname'];
337 else if ($i > 1 && $garray[$i - 2] == '') {
338 $garray[$i - 2] = $result['gname'];
341 $garray[$i++
] = $result['gname'];
345 foreach ($garray as $value) {
346 if ($value === '') continue;
347 $newname = $nextord . substr($value, 1);
348 sqlStatement("UPDATE layout_options SET " .
349 "group_name = '$newname' WHERE " .
350 "form_id = '$layout_id' AND " .
351 "group_name = '$value'");
352 $nextord = nextGroupOrder($nextord);
356 else if ($_POST['formaction'] == "renamegroup" && $layout_id) {
357 $currpos = substr($_POST['renameoldgroupname'], 0, 1);
358 // update the database rows
359 sqlStatement("UPDATE layout_options SET " .
360 "group_name = '" . $currpos . $_POST['renamegroupname'] . "' ".
361 "WHERE form_id = '$layout_id' AND ".
362 "group_name = '" . $_POST['renameoldgroupname'] . "'");
365 // Get the selected form's elements.
367 $res = sqlStatement("SELECT * FROM layout_options WHERE " .
368 "form_id = '$layout_id' ORDER BY group_name, seq");
371 // global counter for field numbers
376 // This is called to generate a select option list for fields within this form.
377 // Used for selecting a field for testing in a skip condition.
379 function genFieldOptionList($current='') {
381 $option_list = "<option value=''>-- " . xlt('Please Select') . " --</option>";
383 $query = "SELECT field_id FROM layout_options WHERE form_id = ? ORDER BY group_name, seq";
384 $res = sqlStatement($query, array($layout_id));
385 while ($row = sqlFetchArray($res)) {
386 $field_id = $row['field_id'];
387 $option_list .= "<option value='" . attr($field_id) . "'";
388 if ($field_id == $current) $option_list .= " selected";
389 $option_list .= ">" . text($field_id) . "</option>";
395 // Write one option line to the form.
397 function writeFieldLine($linedata) {
398 global $fld_line_no, $sources, $lbfonly, $extra_html;
400 $checked = $linedata['default_value'] ?
" checked" : "";
402 //echo " <tr bgcolor='$bgcolor'>\n";
403 echo " <tr id='fld[$fld_line_no]' class='".($fld_line_no %
2 ?
'even' : 'odd')."'>\n";
405 echo " <td class='optcell' style='width:4%' nowrap>";
406 // tuck the group_name INPUT in here
407 echo "<input type='hidden' name='fld[$fld_line_no][group]' value='" .
408 htmlspecialchars($linedata['group_name'], ENT_QUOTES
) . "' class='optin' />";
410 echo "<input type='checkbox' class='selectfield' ".
411 "name='".$linedata['group_name']."~".$linedata['field_id']."' ".
412 "id='".$linedata['group_name']."~".$linedata['field_id']."' ".
413 "title='".htmlspecialchars(xl('Select field', ENT_QUOTES
))."'>";
415 echo "<input type='text' name='fld[$fld_line_no][seq]' id='fld[$fld_line_no][seq]' value='" .
416 htmlspecialchars($linedata['seq'], ENT_QUOTES
) . "' size='2' maxlength='3' " .
417 "class='optin' style='width:36pt' />";
420 echo " <td align='center' class='optcell' $lbfonly style='width:3%'>";
421 echo "<select name='fld[$fld_line_no][source]' class='optin noselect' $lbfonly>";
422 foreach ($sources as $key => $value) {
423 echo "<option value='" . attr($key) . "'";
424 if ($key == $linedata['source']) echo " selected";
425 echo ">" . text($value) . "</option>\n";
430 echo " <td align='left' class='optcell' style='width:10%'>";
431 echo "<input type='text' name='fld[$fld_line_no][id]' value='" .
432 htmlspecialchars($linedata['field_id'], ENT_QUOTES
) . "' size='15' maxlength='63'
433 class='optin noselect' style='width:100%' />";
434 // class='optin noselect' onclick='FieldIDClicked(this)' />";
436 echo "<input type='hidden' name='fld[$fld_line_no][id]' value='" .
437 htmlspecialchars($linedata['field_id'], ENT_QUOTES) . "' />";
438 echo htmlspecialchars($linedata['field_id'], ENT_QUOTES);
442 echo " <td align='center' class='optcell' style='width:12%'>";
443 echo "<input type='text' id='fld[$fld_line_no][title]' name='fld[$fld_line_no][title]' value='" .
444 htmlspecialchars($linedata['title'], ENT_QUOTES
) . "' size='15' maxlength='63' class='optin' style='width:100%' />";
447 // if not english and set to translate layout labels, then show the translation
448 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
449 echo "<td align='center' class='translation' style='width:10%'>" . htmlspecialchars(xl($linedata['title']), ENT_QUOTES
) . "</td>\n";
452 echo " <td align='center' class='optcell' style='width:4%'>";
453 echo "<select name='fld[$fld_line_no][uor]' class='optin'>";
454 foreach (array(0 =>xl('Unused'), 1 =>xl('Optional'), 2 =>xl('Required')) as $key => $value) {
455 echo "<option value='$key'";
456 if ($key == $linedata['uor']) echo " selected";
457 echo ">$value</option>\n";
462 echo " <td align='center' class='optcell' style='width:8%'>";
463 echo "<select name='fld[$fld_line_no][data_type]' id='fld[$fld_line_no][data_type]' onchange=NationNotesContext('".$fld_line_no."',this.value)>";
464 echo "<option value=''></option>";
466 foreach ($datatypes as $key=>$value) {
467 if ($linedata['data_type'] == $key)
468 echo "<option value='$key' selected>$value</option>";
470 echo "<option value='$key'>$value</option>";
475 echo " <td align='center' class='optcell' style='width:4%'>";
476 if ($linedata['data_type'] == 2 ||
$linedata['data_type'] == 3 ||
477 $linedata['data_type'] == 21 ||
$linedata['data_type'] == 22 ||
478 $linedata['data_type'] == 23 ||
$linedata['data_type'] == 25 ||
479 $linedata['data_type'] == 27 ||
$linedata['data_type'] == 28 ||
480 $linedata['data_type'] == 32)
482 // Show the width field
483 echo "<input type='text' name='fld[$fld_line_no][lengthWidth]' value='" .
484 htmlspecialchars($linedata['fld_length'], ENT_QUOTES
) .
485 "' size='1' maxlength='10' class='optin' title='" . xla('Width') . "' />";
486 if ($linedata['data_type'] == 3) {
487 // Show the height field
488 echo "<input type='text' name='fld[$fld_line_no][lengthHeight]' value='" .
489 htmlspecialchars($linedata['fld_rows'], ENT_QUOTES
) .
490 "' size='1' maxlength='10' class='optin' title='" . xla('Height') . "' />";
493 // Hide the height field
494 echo "<input type='hidden' name='fld[$fld_line_no][lengthHeight]' value=''>";
498 // all other data_types (hide both the width and height fields
499 echo "<input type='hidden' name='fld[$fld_line_no][lengthWidth]' value=''>";
500 echo "<input type='hidden' name='fld[$fld_line_no][lengthHeight]' value=''>";
504 echo " <td align='center' class='optcell' style='width:4%'>";
505 echo "<input type='text' name='fld[$fld_line_no][maxSize]' value='" .
506 htmlspecialchars($linedata['max_length'], ENT_QUOTES
) .
507 "' size='1' maxlength='10' class='optin' style='width:100%' " .
508 "title='" . xla('Maximum Size (entering 0 will allow any size)') . "' />";
511 echo " <td align='center' class='optcell' style='width:8%'>";
512 if ($linedata['data_type'] == 1 ||
$linedata['data_type'] == 21 ||
513 $linedata['data_type'] == 22 ||
$linedata['data_type'] == 23 ||
514 $linedata['data_type'] == 25 ||
$linedata['data_type'] == 26 ||
515 $linedata['data_type'] == 27 ||
$linedata['data_type'] == 32 ||
516 $linedata['data_type'] == 33 ||
$linedata['data_type'] == 34 ||
517 $linedata['data_type'] == 36)
520 $disp = "style='display:none'";
521 if($linedata['data_type'] == 34){
522 $type = "style='display:none'";
525 echo "<input type='text' name='fld[$fld_line_no][list_id]' id='fld[$fld_line_no][list_id]' value='" .
526 htmlspecialchars($linedata['list_id'], ENT_QUOTES
) . "'".$type.
527 " size='6' maxlength='30' class='optin listid' style='width:100%;cursor:pointer'".
528 "title='". xl('Choose list') . "' />";
530 echo "<select name='fld[$fld_line_no][contextName]' id='fld[$fld_line_no][contextName]' ".$disp.">";
531 $res = sqlStatement("SELECT * FROM customlists WHERE cl_list_type=2 AND cl_deleted=0");
532 while($row = sqlFetchArray($res)){
534 if ($linedata['list_id'] == $row['cl_list_item_long'])
536 echo "<option value='".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES
)."' ".$sel.">".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES
)."</option>";
541 // all other data_types
542 echo "<input type='hidden' name='fld[$fld_line_no][list_id]' value=''>";
547 echo " <td align='center' class='optcell' style='width:4%'>";
548 if ($linedata['data_type'] == 1 ||
$linedata['data_type'] == 26 ||
549 $linedata['data_type'] == 33 ||
$linedata['data_type'] == 36)
551 echo "<input type='text' name='fld[$fld_line_no][list_backup_id]' value='" .
552 htmlspecialchars($linedata['list_backup_id'], ENT_QUOTES
) .
553 "' size='3' maxlength='10' class='optin listid' style='cursor:pointer; width:100%' />";
556 echo "<input type='hidden' name='fld[$fld_line_no][list_backup_id]' value=''>";
561 echo " <td align='center' class='optcell' style='width:4%'>";
562 echo "<input type='text' name='fld[$fld_line_no][titlecols]' value='" .
563 htmlspecialchars($linedata['titlecols'], ENT_QUOTES
) . "' size='3' maxlength='10' class='optin' style='width:100%' />";
566 echo " <td align='center' class='optcell' style='width:4%'>";
567 echo "<input type='text' name='fld[$fld_line_no][datacols]' value='" .
568 htmlspecialchars($linedata['datacols'], ENT_QUOTES
) . "' size='3' maxlength='10' class='optin' style='width:100%' />";
571 echo " <td align='center' class='optcell' style='width:5%' title='" .
572 "A = " . xla('Age') .
573 ", B = " . xla('Gestational Age') .
574 ", C = " . xla('Capitalize') .
575 ", D = " . xla('Dup Check') .
576 ", G = " . xla('Graphable') .
577 ", L = " . xla('Lab Order') .
578 ", N = " . xla('New Patient Form') .
579 ", O = " . xla('Order Processor') .
580 ", P = " . xla('Default to previous value') .
581 ", R = " . xla('Distributor') .
582 ", T = " . xla('Description is default text') .
583 ", U = " . xla('Capitalize all') .
584 ", V = " . xla('Vendor') .
585 ", 0 = " . xla('Read Only') .
586 ", 1 = " . xla('Write Once') .
587 ", 2 = " . xla('Billing Code Descriptions') .
589 echo "<input type='text' name='fld[$fld_line_no][edit_options]' value='" .
590 htmlspecialchars($linedata['edit_options'], ENT_QUOTES
) . "' size='3' " .
591 "maxlength='36' class='optin' style='width:100%' />";
594 /*****************************************************************
595 echo " <td align='center' class='optcell'>";
596 if ($linedata['data_type'] == 2) {
597 echo "<input type='text' name='fld[$fld_line_no][default]' value='" .
598 htmlspecialchars($linedata['default_value'], ENT_QUOTES) . "' size='10' maxlength='63' class='optin' />";
604 echo " <td align='center' class='optcell'>";
605 echo "<input type='text' name='fld[$fld_line_no][desc]' value='" .
606 htmlspecialchars($linedata['description'], ENT_QUOTES) . "' size='20' maxlength='63' class='optin' />";
609 // if not english and showing layout labels, then show the translation of Description
610 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
611 echo "<td align='center' class='translation'>" . htmlspecialchars(xl($linedata['description']), ENT_QUOTES) . "</td>\n";
613 *****************************************************************/
615 if ($linedata['data_type'] == 31) {
616 echo " <td align='center' class='optcell' style='width:24%'>";
617 echo "<textarea name='fld[$fld_line_no][desc]' rows='3' cols='35' class='optin' style='width:100%'>" .
618 $linedata['description'] . "</textarea>";
619 echo "<input type='hidden' name='fld[$fld_line_no][default]' value='" .
620 htmlspecialchars($linedata['default_value'], ENT_QUOTES
) . "' />";
624 echo " <td align='center' class='optcell' style='width:24%'>";
625 echo "<input type='text' name='fld[$fld_line_no][desc]' value='" .
626 htmlspecialchars($linedata['description'], ENT_QUOTES
) .
627 "' size='30' class='optin' style='width:100%' />";
628 echo "<input type='hidden' name='fld[$fld_line_no][default]' value='" .
629 htmlspecialchars($linedata['default_value'], ENT_QUOTES
) . "' />";
631 // if not english and showing layout labels, then show the translation of Description
632 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
633 echo "<td align='center' class='translation' style='width:10%'>" .
634 htmlspecialchars(xl($linedata['description']), ENT_QUOTES
) . "</td>\n";
638 // The "?" to click on for yet more field attributes.
639 echo " <td class='bold' id='querytd_$fld_line_no' style='cursor:pointer;";
640 if (!empty($linedata['conditions'])) echo "background-color:#77ff77;";
641 echo "' onclick='extShow($fld_line_no, this)' align='center' ";
642 echo "title='" . xla('Click here to view/edit more details') . "'>";
643 echo " ? ";
648 // Create a floating div for the additional attributes of this field.
649 $conditions = empty($linedata['conditions']) ?
650 array(0 => array('id' => '', 'itemid' => '', 'operator' => '', 'value' => '')) :
651 unserialize($linedata['conditions']);
653 $extra_html .= "<div id='ext_$fld_line_no' " .
654 "style='position:absolute;width:750px;border:1px solid black;" .
655 "padding:2px;background-color:#cccccc;visibility:hidden;" .
656 "z-index:1000;left:-1000px;top:0px;font-size:9pt;'>\n" .
657 "<table width='100%'>\n" .
659 " <th colspan='3' align='left' class='bold'>\"" . text($linedata['field_id']) . "\" " .
660 xlt('will be hidden if') . ":</th>\n" .
661 " <th colspan='2' align='right' class='text'><input type='button' " .
662 "value='" . xla('Close') . "' onclick='extShow($fld_line_no, false)' /> </th>\n" .
665 " <th align='left' class='bold'>" . xlt('Field ID') . "</th>\n" .
666 " <th align='left' class='bold'>" . xlt('List item ID') . "</th>\n" .
667 " <th align='left' class='bold'>" . xlt('Operator') . "</th>\n" .
668 " <th align='left' class='bold'>" . xlt('Value if comparing') . "</th>\n" .
669 " <th align='left' class='bold'> </th>\n" .
671 // There may be multiple condition lines for each field.
672 foreach ($conditions as $i => $condition) {
675 " <td align='left'>\n" .
676 " <select name='fld[$fld_line_no][condition_id][$i]' onchange='cidChanged($fld_line_no, $i)'>" .
677 genFieldOptionList($condition['id']) . " </select>\n" .
679 " <td align='left'>\n" .
680 // List item choices are populated on the client side but will need the current value,
681 // so we insert a temporary option here to hold that value.
682 " <select name='fld[$fld_line_no][condition_itemid][$i]'><option value='" .
683 attr($condition['itemid']) . "'>...</option></select>\n" .
685 " <td align='left'>\n" .
686 " <select name='fld[$fld_line_no][condition_operator][$i]'>\n";
688 'eq' => xl('Equals' ),
689 'ne' => xl('Does not equal' ),
690 'se' => xl('Is selected' ),
691 'ns' => xl('Is not selected'),
692 ) as $key => $value) {
693 $extra_html .= " <option value='$key'";
694 if ($key == $condition['operator']) $extra_html .= " selected";
695 $extra_html .= ">" . text($value) . "</option>\n";
700 " <td align='left' title='" . xla('Only for comparisons') . "'>\n" .
701 " <input type='text' name='fld[$fld_line_no][condition_value][$i]' value='" .
702 attr($condition['value']) . "' size='15' maxlength='63' />\n" .
704 if (count($conditions) == $i +
1) {
706 " <td align='right' title='" . xla('Add a condition') . "'>\n" .
707 " <input type='button' value='+' onclick='extAddCondition($fld_line_no,this)' />\n" .
712 " <td align='right'>\n" .
713 " <select name='fld[$fld_line_no][condition_andor][$i]'>\n";
717 ) as $key => $value) {
718 $extra_html .= " <option value='$key'";
719 if ($key == $condition['andor']) $extra_html .= " selected";
720 $extra_html .= ">" . text($value) . "</option>\n";
737 <?php
html_header_show();?
>
739 <!-- supporting javascript code
-->
740 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script
>
742 <link rel
="stylesheet" href
='<?php echo $css_header ?>' type
='text/css'>
744 <title
><?php
xl('Layout Editor','e'); ?
></title
>
747 tr
.head
{ font
-size
:10pt
; background
-color
:#cccccc; }
748 tr
.detail
{ font
-size
:10pt
; }
749 td
{ font
-size
:10pt
; }
750 input
{ font
-size
:10pt
; }
751 a
, a
:visited
, a
:hover
{ color
:#0000cc; }
753 .optin
{ background
: transparent
; }
755 margin
: 0pt
0pt
8pt
0pt
;
760 border
-collapse
: collapse
;
764 background
-color
: #ddddff;
765 padding
: 3px
0px
3px
0px
;
768 background
-color
: #ffdddd;
769 padding
: 3px
0px
3px
0px
;
771 .help
{ cursor
: help
; }
772 .layouts_title
{ font
-size
: 110%
; }
778 border
: 2px solid blue
;
779 background
-color
: yellow
;
784 <script language
="JavaScript">
786 // Helper functions for positioning the floating divs.
787 function extGetX(elem
) {
789 while(elem
!= null) {
790 x +
= elem
.offsetLeft
;
791 elem
= elem
.offsetParent
;
795 function extGetY(elem
) {
797 while(elem
!= null) {
799 elem
= elem
.offsetParent
;
804 // Show or hide the "extras" div for a row.
806 function extShow(lino
, show
) {
807 var thisdiv
= document
.getElementById("ext_" + lino
);
809 extdiv
.style
.visibility
= 'hidden';
810 extdiv
.style
.left
= '-1000px';
811 extdiv
.style
.top
= '0px';
813 if (show
&& thisdiv
!= extdiv
) {
815 var dw
= window
.innerWidth ? window
.innerWidth
- 20 : document
.body
.clientWidth
;
816 x
= dw
- extdiv
.offsetWidth
;
818 var y
= extGetY(show
) + show
.offsetHeight
;
819 extdiv
.style
.left
= x
;
820 extdiv
.style
.top
= y
;
821 extdiv
.style
.visibility
= 'visible';
828 // Add an extra condition line for the given row.
829 function extAddCondition(lino
, btnelem
) {
830 var f
= document
.forms
[0];
833 // Get index of next condition line.
834 while (f
['fld[' + lino +
'][condition_id][' + i +
']']) ++i
;
835 if (i
== 0) alert('f["fld[' + lino +
'][condition_id][' + i +
']"] <?php echo xls('not found
') ?>');
837 // Get containing <td>, <tr> and <table> nodes of the "+" button.
838 var tdplus
= btnelem
.parentNode
;
839 var trelem
= tdplus
.parentNode
;
840 var telem
= trelem
.parentNode
;
842 // Replace contents of the tdplus cell.
844 "<select name='fld[" + lino +
"][condition_andor][" + i +
"]'>" +
845 "<option value='and'><?php echo xls('And') ?></option>" +
846 "<option value='or' ><?php echo xls('Or' ) ?></option>" +
850 var newtrelem
= telem
.insertRow(i+
2);
851 newtrelem
.innerHTML
=
852 "<td align='left'>" +
853 "<select name='fld[" + lino +
"][condition_id][" + i +
"]' onchange='cidChanged(" + lino +
"," + i +
")'>" +
854 "<?php echo addslashes(genFieldOptionList()) ?>" +
857 "<td align='left'>" +
858 "<select name='fld[" + lino +
"][condition_itemid][" + i +
"]' style='display:none' />" +
860 "<td align='left'>" +
861 "<select name='fld[" + lino +
"][condition_operator][" + i +
"]'>" +
862 "<option value='eq'><?php echo xls('Equals' ) ?></option>" +
863 "<option value='ne'><?php echo xls('Does not equal' ) ?></option>" +
864 "<option value='se'><?php echo xls('Is selected' ) ?></option>" +
865 "<option value='ns'><?php echo xls('Is not selected') ?></option>" +
868 "<td align='left'>" +
869 "<input type='text' name='fld[" + lino +
"][condition_value][" + i +
"]' value='' size='15' maxlength='63' />" +
871 "<td align='right'>" +
872 "<input type='button' value='+' onclick='extAddCondition(" + lino +
",this)' />" +
876 // This is called when a field ID is chosen for testing within a skip condition.
877 // It checks to see if a corresponding list item must also be chosen for the test, and
878 // if so then inserts the dropdown for selecting an item from the appropriate list.
879 function setListItemOptions(lino
, seq
, init
) {
880 var f
= document
.forms
[0];
881 var target
= 'fld[' + lino +
'][condition_itemid][' + seq +
']';
882 // field_id is the ID of the field that the condition will test.
883 var field_id
= f
['fld[' + lino +
'][condition_id][' + seq +
']'].value
;
885 f
[target
].options
.length
= 0;
886 f
[target
].style
.display
= 'none';
889 // Find the occurrence of that field in the layout.
892 var idname
= 'fld[' + i +
'][id]';
894 alert('<?php echo xls('Condition field not found
') ?>: ' + field_id
);
897 if (f
[idname
].value
== field_id
) break;
900 // If this is startup initialization then preserve the current value.
901 var current
= init ? f
[target
].value
: '';
902 f
[target
].options
.length
= 0;
903 // Get the corresponding data type and list ID.
904 var data_type
= f
['fld[' + i +
'][data_type]'].value
;
905 var list_id
= f
['fld[' + i +
'][list_id]'].value
;
906 // WARNING: If new data types are defined the following test may need enhancing.
907 // We're getting out if the type does not generate multiple fields with different names.
908 if (data_type
!= '21' && data_type
!= '22' && data_type
!= '23' && data_type
!= '25') {
909 f
[target
].style
.display
= 'none';
912 // OK, list item IDs do apply so go get 'em.
913 // This happens asynchronously so the generated code needs to stand alone.
914 f
[target
].style
.display
= '';
915 $
.getScript('layout_listitems_ajax.php' +
916 '?listid=' +
encodeURIComponent(list_id
) +
917 '&target=' +
encodeURIComponent(target
) +
918 '¤t=' +
encodeURIComponent(current
));
921 // This is called whenever a condition's field ID selection is changed.
922 function cidChanged(lino
, seq
) {
923 var thisid
= document
.forms
[0]['fld[' + lino +
'][condition_id][0]'].value
;
924 var thistd
= document
.getElementById("querytd_" + lino
);
925 thistd
.style
.backgroundColor
= thisid ?
'#77ff77' : '';
926 setListItemOptions(lino
, seq
, false);
933 <body
class="body_top">
935 <form method
='post' name
='theform' id
='theform' action
='edit_layout.php'>
936 <input type
="hidden" name
="formaction" id
="formaction" value
="">
937 <!-- elements used to identify a field to delete
-->
938 <input type
="hidden" name
="deletefieldid" id
="deletefieldid" value
="">
939 <input type
="hidden" name
="deletefieldgroup" id
="deletefieldgroup" value
="">
940 <!-- elements used to identify a group to delete
-->
941 <input type
="hidden" name
="deletegroupname" id
="deletegroupname" value
="">
942 <!-- elements used to change the group order
-->
943 <input type
="hidden" name
="movegroupname" id
="movegroupname" value
="">
944 <input type
="hidden" name
="movedirection" id
="movedirection" value
="">
945 <!-- elements used to select more than one field
-->
946 <input type
="hidden" name
="selectedfields" id
="selectedfields" value
="">
947 <input type
="hidden" id
="targetgroup" name
="targetgroup" value
="">
949 <p
><b
><?php
xl('Edit layout','e'); ?
>:</b
> 
;
950 <select name
='layout_id' id
='layout_id'>
951 <option value
=''>-- <?php
echo xl('Select') ?
> --</option
>
953 foreach ($layouts as $key => $value) {
954 echo " <option value='$key'";
955 if ($key == $layout_id) echo " selected";
956 echo ">$value</option>\n";
961 <?php
if ($layout_id) { ?
>
962 <div style
='margin: 0 0 8pt 0;'>
963 <input type
='button' class='addgroup' id
='addgroup' value
=<?php
xl('Add Group','e','\'','\''); ?
>/>
968 $prevgroup = "!@#asdf1234"; // an unlikely group name
969 $firstgroup = true; // flag indicates it's the first group to be displayed
970 while ($row = sqlFetchArray($res)) {
971 if ($row['group_name'] != $prevgroup) {
972 if ($firstgroup == false) { echo "</tbody></table></div>\n"; }
973 echo "<div id='".$row['group_name']."' class='group'>";
974 echo "<div class='text bold layouts_title' style='position:relative; background-color: #eef'>";
975 // echo preg_replace("/^\d+/", "", $row['group_name']);
976 echo substr($row['group_name'], 1);
978 // if not english and set to translate layout labels, then show the translation of group name
979 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
980 // echo "<span class='translation'>>> " . xl(preg_replace("/^\d+/", "", $row['group_name'])) . "</span>";
981 echo "<span class='translation'>>> " . xl(substr($row['group_name'], 1)) . "</span>";
985 echo " <input type='button' class='addfield' id='addto~".$row['group_name']."' value='" . xl('Add Field') . "'/>";
986 echo " ";
987 echo " <input type='button' class='renamegroup' id='".$row['group_name']."' value='" . xl('Rename Group') . "'/>";
988 echo " ";
989 echo " <input type='button' class='deletegroup' id='".$row['group_name']."' value='" . xl('Delete Group') . "'/>";
990 echo " ";
991 echo " <input type='button' class='movegroup' id='".$row['group_name']."~up' value='" . xl('Move Up') . "'/>";
992 echo " ";
993 echo " <input type='button' class='movegroup' id='".$row['group_name']."~down' value='" . xl('Move Down') . "'/>";
1001 <th
><?php
xl('Order','e'); ?
></th
>
1002 <th
<?php
echo " $lbfonly"; ?
>><?php
xl('Source','e'); ?
></th
>
1003 <th
><?php
xl('ID','e'); ?
> 
;<span
class="help" title
=<?php
xl('A unique value to identify this field, not visible to the user','e','\'','\''); ?
> >(?
)</span
></th
>
1004 <th
><?php
xl('Label','e'); ?
> 
;<span
class="help" title
=<?php
xl('The label that appears to the user on the form','e','\'','\''); ?
> >(?
)</span
></th
>
1005 <?php
// if not english and showing layout label translations, then show translation header for title
1006 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
1007 echo "<th>" . xl('Translation')."<span class='help' title='" . xl('The translated label that will appear on the form in current language') . "'> (?)</span></th>";
1009 <th
><?php
xl('UOR','e'); ?
></th
>
1010 <th
><?php
xl('Data Type','e'); ?
></th
>
1011 <th
><?php
xl('Size','e'); ?
></th
>
1012 <th
><?php
xl('Max Size','e'); ?
></th
>
1013 <th
><?php
xl('List','e'); ?
></th
>
1014 <th
><?php
xl('Backup List','e'); ?
></th
>
1015 <th
><?php
xl('Label Cols','e'); ?
></th
>
1016 <th
><?php
xl('Data Cols','e'); ?
></th
>
1017 <th
><?php
xl('Options','e'); ?
></th
>
1018 <th
><?php
xl('Description','e'); ?
></th
>
1019 <?php
// if not english and showing layout label translations, then show translation header for description
1020 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
1021 echo "<th>" . xl('Translation')."<span class='help' title='" . xl('The translation of description in current language')."'> (?)</span></th>";
1023 <th
><?php
echo xlt('?'); ?
></th
>
1029 } // end if-group_name
1031 writeFieldLine($row);
1032 $prevgroup = $row['group_name'];
1040 <?php
echo $extra_html; ?
>
1042 <?php
if ($layout_id) { ?
>
1043 <span style
="font-size:90%">
1044 <?php
xl('With selected:', 'e');?
>
1045 <input type
='button' name
='deletefields' id
='deletefields' value
='<?php xl('Delete
','e
'); ?>' style
="font-size:90%" disabled
="disabled" />
1046 <input type
='button' name
='movefields' id
='movefields' value
='<?php xl('Move to
...','e
'); ?>' style
="font-size:90%" disabled
="disabled" />
1049 <input type
='button' name
='save' id
='save' value
='<?php xl('Save Changes
','e
'); ?>' />
1055 <!-- template DIV that appears when user chooses to rename an existing group
-->
1056 <div id
="renamegroupdetail" style
="border: 1px solid black; padding: 3px; display: none; visibility: hidden; background-color: lightgrey;">
1057 <input type
="hidden" name
="renameoldgroupname" id
="renameoldgroupname" value
="">
1058 <?php
xl('Group Name','e'); ?
>: <input type
="textbox" size
="20" maxlength
="30" name
="renamegroupname" id
="renamegroupname">
1060 <input type
="button" class="saverenamegroup" value
=<?php
xl('Rename Group','e','\'','\''); ?
>>
1061 <input type
="button" class="cancelrenamegroup" value
=<?php
xl('Cancel','e','\'','\''); ?
>>
1064 <!-- template DIV that appears when user chooses to add a
new group
-->
1065 <div id
="groupdetail" style
="border: 1px solid black; padding: 3px; display: none; visibility: hidden; background-color: lightgrey;">
1067 <?php
xl('Group Name','e'); ?
>: <input type
="textbox" size
="20" maxlength
="30" name
="newgroupname" id
="newgroupname">
1069 <table style
="border-collapse: collapse; margin-top: 5px;">
1072 <th
><?php
xl('Order','e'); ?
></th
>
1073 <th
<?php
echo " $lbfonly"; ?
>><?php
xl('Source','e'); ?
></th
>
1074 <th
><?php
xl('ID','e'); ?
> 
;<span
class="help" title
=<?php
xl('A unique value to identify this field, not visible to the user','e','\'','\''); ?
> >(?
)</span
></th
>
1075 <th
><?php
xl('Label','e'); ?
> 
;<span
class="help" title
=<?php
xl('The label that appears to the user on the form','e','\'','\''); ?
> >(?
)</span
></th
>
1076 <th
><?php
xl('UOR','e'); ?
></th
>
1077 <th
><?php
xl('Data Type','e'); ?
></th
>
1078 <th
><?php
xl('Size','e'); ?
></th
>
1079 <th
><?php
xl('Max Size','e'); ?
></th
>
1080 <th
><?php
xl('List','e'); ?
></th
>
1081 <th
><?php
xl('Backup List','e'); ?
></th
>
1082 <th
><?php
xl('Label Cols','e'); ?
></th
>
1083 <th
><?php
xl('Data Cols','e'); ?
></th
>
1084 <th
><?php
xl('Options','e'); ?
></th
>
1085 <th
><?php
xl('Description','e'); ?
></th
>
1090 <td
><input type
="textbox" name
="gnewseq" id
="gnewseq" value
="" size
="2" maxlength
="3"> </td
>
1091 <td
<?php
echo " $lbfonly"; ?
>>
1092 <select name
='gnewsource' id
='gnewsource'>
1094 foreach ($sources as $key => $value) {
1095 echo "<option value='" . attr($key) . "'>" . text($value) . "</option>\n";
1100 <td
><input type
="textbox" name
="gnewid" id
="gnewid" value
="" size
="10" maxlength
="20"
1101 onclick
='FieldIDClicked(this)'> </td
>
1102 <td
><input type
="textbox" name
="gnewtitle" id
="gnewtitle" value
="" size
="20" maxlength
="63"> </td
>
1104 <select name
="gnewuor" id
="gnewuor">
1105 <option value
="0"><?php
xl('Unused','e'); ?
></option
>
1106 <option value
="1" selected
><?php
xl('Optional','e'); ?
></option
>
1107 <option value
="2"><?php
xl('Required','e'); ?
></option
>
1111 <select name
='gnewdatatype' id
='gnewdatatype'>
1112 <option value
=''></option
>
1115 foreach ($datatypes as $key=>$value) {
1116 echo "<option value='$key'>$value</option>";
1121 <td
><input type
="textbox" name
="gnewlengthWidth" id
="gnewlengthWidth" value
="" size
="1" maxlength
="3" title
="<?php echo xla('Width'); ?>">
1122 <input type
="textbox" name
="gnewlengthHeight" id
="gnewlengthHeight" value
="" size
="1" maxlength
="3" title
="<?php echo xla('Height'); ?>"></td
>
1123 <td
><input type
="textbox" name
="gnewmaxSize" id
="gnewmaxSize" value
="" size
="1" maxlength
="3" title
="<?php echo xla('Maximum Size (entering 0 will allow any size)'); ?>"></td
>
1124 <td
><input type
="textbox" name
="gnewlistid" id
="gnewlistid" value
="" size
="8" maxlength
="31" class="listid">
1125 <select name
='gcontextName' id
='gcontextName' style
='display:none'>
1127 $res = sqlStatement("SELECT * FROM customlists WHERE cl_list_type=2 AND cl_deleted=0");
1128 while($row = sqlFetchArray($res)){
1129 echo "<option value='".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES
)."'>".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES
)."</option>";
1134 <td
><input type
="textbox" name
="gnewbackuplistid" id
="gnewbackuplistid" value
="" size
="8" maxlength
="31" class="listid"></td
>
1135 <td
><input type
="textbox" name
="gnewtitlecols" id
="gnewtitlecols" value
="" size
="3" maxlength
="3"> </td
>
1136 <td
><input type
="textbox" name
="gnewdatacols" id
="gnewdatacols" value
="" size
="3" maxlength
="3"> </td
>
1137 <td
><input type
="textbox" name
="gnewedit_options" id
="gnewedit_options" value
="" size
="3" maxlength
="36">
1138 <input type
="hidden" name
="gnewdefault" id
="gnewdefault" value
="" /> </td
>
1139 <td
><input type
="textbox" name
="gnewdesc" id
="gnewdesc" value
="" size
="30" maxlength
="63"> </td
>
1144 <input type
="button" class="savenewgroup" value
=<?php
xl('Save New Group','e','\'','\''); ?
>>
1145 <input type
="button" class="cancelnewgroup" value
=<?php
xl('Cancel','e','\'','\''); ?
>>
1149 <!-- template DIV that appears when user chooses to add a
new field to a group
-->
1150 <div id
="fielddetail" class="fielddetail" style
="display: none; visibility: hidden">
1151 <input type
="hidden" name
="newfieldgroupid" id
="newfieldgroupid" value
="">
1152 <table style
="border-collapse: collapse;">
1155 <th
><?php
xl('Order','e'); ?
></th
>
1156 <th
<?php
echo " $lbfonly"; ?
>><?php
xl('Source','e'); ?
></th
>
1157 <th
><?php
xl('ID','e'); ?
> 
;<span
class="help" title
=<?php
xl('A unique value to identify this field, not visible to the user','e','\'','\''); ?
> >(?
)</span
></th
>
1158 <th
><?php
xl('Label','e'); ?
> 
;<span
class="help" title
=<?php
xl('The label that appears to the user on the form','e','\'','\''); ?
> >(?
)</span
></th
>
1159 <th
><?php
xl('UOR','e'); ?
></th
>
1160 <th
><?php
xl('Data Type','e'); ?
></th
>
1161 <th
><?php
xl('Size','e'); ?
></th
>
1162 <th
><?php
xl('Max Size','e'); ?
></th
>
1163 <th
><?php
xl('List','e'); ?
></th
>
1164 <th
><?php
xl('Backup List','e'); ?
></th
>
1165 <th
><?php
xl('Label Cols','e'); ?
></th
>
1166 <th
><?php
xl('Data Cols','e'); ?
></th
>
1167 <th
><?php
xl('Options','e'); ?
></th
>
1168 <th
><?php
xl('Description','e'); ?
></th
>
1173 <td
><input type
="textbox" name
="newseq" id
="newseq" value
="" size
="2" maxlength
="3"> </td
>
1174 <td
<?php
echo " $lbfonly"; ?
>>
1175 <select name
='newsource' id
='newsource'>
1177 foreach ($sources as $key => $value) {
1178 echo " <option value='" . attr($key) . "'>" . text($value) . "</option>\n";
1183 <td
><input type
="textbox" name
="newid" id
="newid" value
="" size
="10" maxlength
="20"
1184 onclick
='FieldIDClicked(this)'> </td
>
1185 <td
><input type
="textbox" name
="newtitle" id
="newtitle" value
="" size
="20" maxlength
="63"> </td
>
1187 <select name
="newuor" id
="newuor">
1188 <option value
="0"><?php
xl('Unused','e'); ?
></option
>
1189 <option value
="1" selected
><?php
xl('Optional','e'); ?
></option
>
1190 <option value
="2"><?php
xl('Required','e'); ?
></option
>
1194 <select name
='newdatatype' id
='newdatatype'>
1195 <option value
=''></option
>
1198 foreach ($datatypes as $key=>$value) {
1199 echo " <option value='$key'>$value</option>\n";
1204 <td
><input type
="textbox" name
="newlengthWidth" id
="newlengthWidth" value
="" size
="1" maxlength
="3" title
="<?php echo xla('Width'); ?>">
1205 <input type
="textbox" name
="newlengthHeight" id
="newlengthHeight" value
="" size
="1" maxlength
="3" title
="<?php echo xla('Height'); ?>"></td
>
1206 <td
><input type
="textbox" name
="newmaxSize" id
="newmaxSize" value
="" size
="1" maxlength
="3" title
="<?php echo xla('Maximum Size (entering 0 will allow any size)'); ?>"></td
>
1207 <td
><input type
="textbox" name
="newlistid" id
="newlistid" value
="" size
="8" maxlength
="31" class="listid">
1208 <select name
='contextName' id
='contextName' style
='display:none'>
1210 $res = sqlStatement("SELECT * FROM customlists WHERE cl_list_type=2 AND cl_deleted=0");
1211 while($row = sqlFetchArray($res)){
1212 echo "<option value='".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES
)."'>".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES
)."</option>";
1217 <td
><input type
="textbox" name
="newbackuplistid" id
="newbackuplistid" value
="" size
="8" maxlength
="31" class="listid"></td
>
1218 <td
><input type
="textbox" name
="newtitlecols" id
="newtitlecols" value
="" size
="3" maxlength
="3"> </td
>
1219 <td
><input type
="textbox" name
="newdatacols" id
="newdatacols" value
="" size
="3" maxlength
="3"> </td
>
1220 <td
><input type
="textbox" name
="newedit_options" id
="newedit_options" value
="" size
="3" maxlength
="36">
1221 <input type
="hidden" name
="newdefault" id
="newdefault" value
="" /> </td
>
1222 <td
><input type
="textbox" name
="newdesc" id
="newdesc" value
="" size
="30" maxlength
="63"> </td
>
1226 <input type
="button" class="savenewfield" value
=<?php
xl('Save New Field','e','\'','\''); ?
>>
1227 <input type
="button" class="cancelnewfield" value
=<?php
xl('Cancel','e','\'','\''); ?
>>
1236 <script language
="javascript">
1238 // used when selecting a list-name for a field
1241 // Get the next logical sequence number for a field in the specified group.
1242 // Note it guesses and uses the existing increment value.
1243 function getNextSeq(group
) {
1244 var f
= document
.forms
[0];
1247 for (var i
= 1; true; ++i
) {
1248 var gelem
= f
['fld[' + i +
'][group]'];
1250 if (gelem
.value
!= group
) continue;
1251 var tmp
= parseInt(f
['fld[' + i +
'][seq]'].value
);
1252 if (isNaN(tmp
)) continue;
1253 if (tmp
<= seq
) continue;
1260 // jQuery stuff to make the page a little easier to use
1262 $
(document
).ready(function(){
1263 $
("#save").click(function() { SaveChanges(); });
1264 $
("#layout_id").change(function() { $
('#theform').submit(); });
1266 $
(".addgroup").click(function() { AddGroup(this
); });
1267 $
(".savenewgroup").click(function() { SaveNewGroup(this
); });
1268 $
(".deletegroup").click(function() { DeleteGroup(this
); });
1269 $
(".cancelnewgroup").click(function() { CancelNewGroup(this
); });
1271 $
(".movegroup").click(function() { MoveGroup(this
); });
1273 $
(".renamegroup").click(function() { RenameGroup(this
); });
1274 $
(".saverenamegroup").click(function() { SaveRenameGroup(this
); });
1275 $
(".cancelrenamegroup").click(function() { CancelRenameGroup(this
); });
1277 $
(".addfield").click(function() { AddField(this
); });
1278 $
("#deletefields").click(function() { DeleteFields(this
); });
1279 $
(".selectfield").click(function() {
1280 var TRparent
= $
(this
).parent().parent();
1281 $
(TRparent
).children("td").toggleClass("highlight");
1282 // disable the delete-move buttons
1283 $
("#deletefields").attr("disabled", "disabled");
1284 $
("#movefields").attr("disabled", "disabled");
1285 $
(".selectfield").each(function(i
) {
1286 // if any field is selected, enable the delete-move buttons
1287 if ($
(this
).attr("checked") == true) {
1288 $
("#deletefields").removeAttr("disabled");
1289 $
("#movefields").removeAttr("disabled");
1293 $
("#movefields").click(function() { ShowGroups(this
); });
1294 $
(".savenewfield").click(function() { SaveNewField(this
); });
1295 $
(".cancelnewfield").click(function() { CancelNewField(this
); });
1296 $
("#newtitle").blur(function() { if ($
("#newid").val() == "") $
("#newid").val($
("#newtitle").val()); });
1297 $
("#newdatatype").change(function() { ChangeList(this
.value
);});
1298 $
("#gnewdatatype").change(function() { ChangeListg(this
.value
);});
1299 $
(".listid").click(function() { ShowLists(this
); });
1301 // special class that skips the element
1302 $
(".noselect").focus(function() { $
(this
).blur(); });
1304 // Save the changes made to the form
1305 var SaveChanges
= function () {
1306 $
("#formaction").val("save");
1307 $
("#theform").submit();
1310 /****************************************************/
1311 /************ Group functions ***********************/
1312 /****************************************************/
1314 // display the 'new group' DIV
1315 var AddGroup
= function(btnObj
) {
1316 // show the field details DIV
1317 $
('#groupdetail').css('visibility', 'visible');
1318 $
('#groupdetail').css('display', 'block');
1319 $
(btnObj
).parent().append($
("#groupdetail"));
1320 $
('#groupdetail > #newgroupname').focus();
1321 // Assign a sensible default sequence number.
1322 $
('#gnewseq').val(10);
1325 // save the new group to the form
1326 var SaveNewGroup
= function(btnObj
) {
1327 // the group name field can only have letters, numbers, spaces and underscores
1328 // AND it cannot start with a number
1329 if ($
("#newgroupname").val() == "") {
1330 alert("<?php xl('Group names cannot be blank', 'e'); ?>");
1333 if ($
("#newgroupname").val().match(/^
(\d+|\s+
)/)) {
1334 alert("<?php xl('Group names cannot start with numbers or spaces.','e'); ?>");
1337 var validname
= $
("#newgroupname").val().replace(/[^A
-za
-z0
-9 ]/g
, "_"); // match any non-word characters and replace them
1338 $
("#newgroupname").val(validname
);
1340 // now, check the first group field values
1342 // seq must be numeric and less than 999
1343 if (! IsNumeric($
("#gnewseq").val(), 0, 999)) {
1344 alert("<?php xl('Order must be a number between 1 and 999','e'); ?>");
1347 // length must be numeric and less than 999
1348 if (! IsNumeric($
("#gnewlengthWidth").val(), 0, 999)) {
1349 alert("<?php xl('Size must be a number between 1 and 999','e'); ?>");
1352 // titlecols must be numeric and less than 100
1353 if (! IsNumeric($
("#gnewtitlecols").val(), 0, 999)) {
1354 alert("<?php xl('LabelCols must be a number between 1 and 999','e'); ?>");
1357 // datacols must be numeric and less than 100
1358 if (! IsNumeric($
("#gnewdatacols").val(), 0, 999)) {
1359 alert("<?php xl('DataCols must be a number between 1 and 999','e'); ?>");
1362 // some fields cannot be blank
1363 if ($
("#gnewtitle").val() == "") {
1364 alert("<?php xl('Label cannot be blank','e'); ?>");
1367 // the id field can only have letters, numbers and underscores
1368 if ($
("#gnewid").val() == "") {
1369 alert("<?php xl('ID cannot be blank', 'e'); ?>");
1372 var validid
= $
("#gnewid").val().replace(/(\s|\W
)/g
, "_"); // match any non-word characters and replace them
1373 $
("#gnewid").val(validid
);
1374 // similarly with the listid field
1375 validid
= $
("#gnewlistid").val().replace(/(\s|\W
)/g
, "_");
1376 $
("#gnewlistid").val(validid
);
1377 // similarly with the backuplistid field
1378 validid
= $
("#gnewbackuplistid").val().replace(/(\s|\W
)/g
, "_");
1379 $
("#gnewbackuplistid").val(validid
);
1382 // submit the form to add a new field to a specific group
1383 $
("#formaction").val("addgroup");
1384 $
("#theform").submit();
1387 // actually delete an entire group from the database
1388 var DeleteGroup
= function(btnObj
) {
1389 var parts
= $
(btnObj
).attr("id");
1390 var groupname
= parts
.replace(/^\d+
/, "");
1391 if (confirm("<?php xl('WARNING','e','',' - ') . xl('This action cannot be undone.','e','','\n') . xl('Are you sure you wish to delete the entire group named','e','',' '); ?>'"+groupname+
"'?")) {
1392 // submit the form to add a new field to a specific group
1393 $
("#formaction").val("deletegroup");
1394 $
("#deletegroupname").val(parts
);
1395 $
("#theform").submit();
1399 // just hide the new field DIV
1400 var CancelNewGroup
= function(btnObj
) {
1401 // hide the field details DIV
1402 $
('#groupdetail').css('visibility', 'hidden');
1403 $
('#groupdetail').css('display', 'none');
1404 // reset the new group values to a default
1405 $
('#groupdetail > #newgroupname').val("");
1408 // display the 'new field' DIV
1409 var MoveGroup
= function(btnObj
) {
1410 var btnid
= $
(btnObj
).attr("id");
1411 var parts
= btnid
.split("~");
1412 var groupid
= parts
[0];
1413 var direction
= parts
[1];
1415 // submit the form to change group order
1416 $
("#formaction").val("movegroup");
1417 $
("#movegroupname").val(groupid
);
1418 $
("#movedirection").val(direction
);
1419 $
("#theform").submit();
1422 // show the rename group DIV
1423 var RenameGroup
= function(btnObj
) {
1424 $
('#renamegroupdetail').css('visibility', 'visible');
1425 $
('#renamegroupdetail').css('display', 'block');
1426 $
(btnObj
).parent().append($
("#renamegroupdetail"));
1427 $
('#renameoldgroupname').val($
(btnObj
).attr("id"));
1428 $
('#renamegroupname').val($
(btnObj
).attr("id").replace(/^\d+
/, ""));
1431 // save the new group to the form
1432 var SaveRenameGroup
= function(btnObj
) {
1433 // the group name field can only have letters, numbers, spaces and underscores
1434 // AND it cannot start with a number
1435 if ($
("#renamegroupname").val().match(/^\d+
/)) {
1436 alert("<?php xl('Group names cannot start with numbers.','e'); ?>");
1439 var validname
= $
("#renamegroupname").val().replace(/[^A
-za
-z0
-9 ]/g
, "_"); // match any non-word characters and replace them
1440 $
("#renamegroupname").val(validname
);
1442 // submit the form to add a new field to a specific group
1443 $
("#formaction").val("renamegroup");
1444 $
("#theform").submit();
1447 // just hide the new field DIV
1448 var CancelRenameGroup
= function(btnObj
) {
1449 // hide the field details DIV
1450 $
('#renamegroupdetail').css('visibility', 'hidden');
1451 $
('#renamegroupdetail').css('display', 'none');
1452 // reset the rename group values to a default
1453 $
('#renameoldgroupname').val("");
1454 $
('#renamegroupname').val("");
1457 /****************************************************/
1458 /************ Field functions ***********************/
1459 /****************************************************/
1461 // display the 'new field' DIV
1462 var AddField
= function(btnObj
) {
1463 // update the fieldgroup value to be the groupid
1464 var btnid
= $
(btnObj
).attr("id");
1465 var parts
= btnid
.split("~");
1466 var groupid
= parts
[1];
1467 $
('#fielddetail > #newfieldgroupid').attr('value', groupid
);
1468 // show the field details DIV
1469 $
('#fielddetail').css('visibility', 'visible');
1470 $
('#fielddetail').css('display', 'block');
1471 $
(btnObj
).parent().append($
("#fielddetail"));
1472 // Assign a sensible default sequence number.
1473 $
('#newseq').val(getNextSeq(groupid
));
1476 var DeleteFields
= function(btnObj
) {
1477 if (confirm("<?php xl('WARNING','e','',' - ') . xl('This action cannot be undone.','e','','\n') . xl('Are you sure you wish to delete the selected fields?','e'); ?>")) {
1479 $
(".selectfield").each(function(i
) {
1480 // build a list of selected field names to be moved
1481 if ($
(this
).attr("checked") == true) {
1482 var parts
= this
.id
.split("~");
1483 var currval
= $
("#selectedfields").val();
1484 $
("#selectedfields").val(currval+delim+parts
[1]);
1488 // submit the form to delete the field(s)
1489 $
("#formaction").val("deletefields");
1490 $
("#theform").submit();
1494 // save the new field to the form
1495 var SaveNewField
= function(btnObj
) {
1496 // check the new field values for correct formatting
1498 // seq must be numeric and less than 999
1499 if (! IsNumeric($
("#newseq").val(), 0, 999)) {
1500 alert("<?php xl('Order must be a number between 1 and 999','e'); ?>");
1503 // length must be numeric and less than 999
1504 if (! IsNumeric($
("#newlengthWidth").val(), 0, 999)) {
1505 alert("<?php xl('Size must be a number between 1 and 999','e'); ?>");
1508 // titlecols must be numeric and less than 100
1509 if (! IsNumeric($
("#newtitlecols").val(), 0, 999)) {
1510 alert("<?php xl('LabelCols must be a number between 1 and 999','e'); ?>");
1513 // datacols must be numeric and less than 100
1514 if (! IsNumeric($
("#newdatacols").val(), 0, 999)) {
1515 alert("<?php xl('DataCols must be a number between 1 and 999','e'); ?>");
1518 // some fields cannot be blank
1519 if ($
("#newtitle").val() == "") {
1520 alert("<?php xl('Label cannot be blank','e'); ?>");
1523 // the id field can only have letters, numbers and underscores
1524 var validid
= $
("#newid").val().replace(/(\s|\W
)/g
, "_"); // match any non-word characters and replace them
1525 $
("#newid").val(validid
);
1526 // similarly with the listid field
1527 validid
= $
("#newlistid").val().replace(/(\s|\W
)/g
, "_");
1528 $
("#newlistid").val(validid
);
1529 // similarly with the backuplistid field
1530 validid
= $
("#newbackuplistid").val().replace(/(\s|\W
)/g
, "_");
1531 $
("#newbackuplistid").val(validid
);
1533 // submit the form to add a new field to a specific group
1534 $
("#formaction").val("addfield");
1535 $
("#theform").submit();
1538 // just hide the new field DIV
1539 var CancelNewField
= function(btnObj
) {
1540 // hide the field details DIV
1541 $
('#fielddetail').css('visibility', 'hidden');
1542 $
('#fielddetail').css('display', 'none');
1543 // reset the new field values to a default
1544 ResetNewFieldValues();
1547 // show the popup choice of lists
1548 var ShowLists
= function(btnObj
) {
1549 window
.open("./show_lists_popup.php", "lists", "width=300,height=500,scrollbars=yes");
1550 selectedfield
= btnObj
;
1553 // show the popup choice of groups
1554 var ShowGroups
= function(btnObj
) {
1555 window
.open("./show_groups_popup.php?layout_id=<?php echo $layout_id;?>", "groups", "width=300,height=300,scrollbars=yes");
1558 // Show context DD for NationNotes
1559 var ChangeList
= function(btnObj
){
1561 $
('#newlistid').hide();
1562 $
('#contextName').show();
1565 $
('#newlistid').show();
1566 $
('#contextName').hide();
1569 var ChangeListg
= function(btnObj
){
1571 $
('#gnewlistid').hide();
1572 $
('#gcontextName').show();
1575 $
('#gnewlistid').show();
1576 $
('#gcontextName').hide();
1580 // Initialize the list item selectors in skip conditions.
1581 var f
= document
.forms
[0];
1582 for (var lino
= 1; f
['fld[' + lino +
'][id]']; ++lino
) {
1583 for (var seq
= 0; f
['fld[' + lino +
'][condition_itemid][' + seq +
']']; ++seq
) {
1584 setListItemOptions(lino
, seq
, true);
1590 function NationNotesContext(lineitem
,val
){
1592 document
.getElementById("fld["+lineitem+
"][contextName]").style
.display
='';
1593 document
.getElementById("fld["+lineitem+
"][list_id]").style
.display
='none';
1594 document
.getElementById("fld["+lineitem+
"][list_id]").value
='';
1597 document
.getElementById("fld["+lineitem+
"][list_id]").style
.display
='';
1598 document
.getElementById("fld["+lineitem+
"][contextName]").style
.display
='none';
1599 document
.getElementById("fld["+lineitem+
"][list_id]").value
='';
1603 function SetList(listid
) {
1604 $
(selectedfield
).val(listid
);
1607 //////////////////////////////////////////////////////////////////////
1608 // The following supports the field ID selection pop-up.
1609 //////////////////////////////////////////////////////////////////////
1611 var fieldselectfield
;
1613 function elemFromPart(part
) {
1614 var ename
= fieldselectfield
.name
;
1615 // ename is like one of the following:
1616 // fld[$fld_line_no][id]
1619 // and "part" is what we substitute for the "id" part.
1620 var i
= ename
.lastIndexOf('id');
1621 ename
= ename
.substr(0, i
) + part + ename
.substr(i+
2);
1622 return document
.forms
[0][ename
];
1625 function FieldIDClicked(elem
) {
1626 <?php
if (substr($layout_id,0,3) == 'LBF') { ?
>
1627 fieldselectfield
= elem
;
1628 var srcval
= elemFromPart('source').value
;
1629 // If the field ID is for the local form, allow direct entry.
1630 if (srcval
== 'F') return;
1631 // Otherwise pop up the selection window.
1632 window
.open('./field_id_popup.php?source=' + srcval
, 'fields',
1633 'width=600,height=600,scrollbars=yes');
1637 function SetField(field_id
, title
, data_type
, uor
, fld_length
, max_length
,
1638 list_id
, titlecols
, datacols
, edit_options
, description
, fld_rows
)
1640 fieldselectfield
.value
= field_id
;
1641 elemFromPart('title' ).value
= title
;
1642 elemFromPart('datatype' ).value
= data_type
;
1643 elemFromPart('uor' ).value
= uor
;
1644 elemFromPart('lengthWidth' ).value
= fld_length
;
1645 elemFromPart('maxSize' ).value
= max_length
;
1646 elemFromPart('listid' ).value
= list_id
;
1647 elemFromPart('titlecols' ).value
= titlecols
;
1648 elemFromPart('datacols' ).value
= datacols
;
1649 elemFromPart('edit_options').value
= edit_options
;
1650 elemFromPart('desc' ).value
= description
;
1651 elemFromPart('lengthHeight').value
= fld_rows
;
1654 //////////////////////////////////////////////////////////////////////
1655 // End code for field ID selection pop-up.
1656 //////////////////////////////////////////////////////////////////////
1658 /* this is called after the user chooses a new group from the popup window
1659 * it will submit the page so the selected fields can be moved into
1662 function MoveFields(targetgroup
) {
1663 $
("#targetgroup").val(targetgroup
);
1665 $
(".selectfield").each(function(i
) {
1666 // build a list of selected field names to be moved
1667 if ($
(this
).attr("checked") == true) {
1668 var parts
= this
.id
.split("~");
1669 var currval
= $
("#selectedfields").val();
1670 $
("#selectedfields").val(currval+delim+parts
[1]);
1674 $
("#formaction").val("movefields");
1675 $
("#theform").submit();
1678 // set the new-field values to a default state
1679 function ResetNewFieldValues () {
1680 $
("#newseq").val("");
1681 $
("#newsource").val("");
1682 $
("#newid").val("");
1683 $
("#newtitle").val("");
1684 $
("#newuor").val(1);
1685 $
("#newlengthWidth").val("");
1686 $
("#newlengthHeight").val("");
1687 $
("#newmaxSize").val("");
1688 $
("#newdatatype").val("");
1689 $
("#newlistid").val("");
1690 $
("#newbackuplistid").val("");
1691 $
("#newtitlecols").val("");
1692 $
("#newdatacols").val("");
1693 $
("#newedit_options").val("");
1694 $
("#newdefault").val("");
1695 $
("#newdesc").val("");
1698 // is value an integer and between min and max
1699 function IsNumeric(value
, min
, max
) {
1700 if (value
== "" || value
== null) return false;
1702 parseInt(value
) < min ||
1703 parseInt(value
) > max
)
1709 /****************************************************/
1710 /****************************************************/
1711 /****************************************************/
1713 // tell if num is an Integer
1714 function IsN(num
) { return !/\D
/.test(num
); }