ongoing new datepicker project
[openemr.git] / interface / super / edit_layout.php
blob028f74733bbdbbd2f0ec655e0636c504b4cb5c50
1 <?php
2 /**
3 * Copyright (C) 2014-2016 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>.
16 * @package OpenEMR
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");
25 $layouts = array(
26 'DEM' => xl('Demographics'),
27 'HIS' => xl('History'),
28 'FACUSR' => xl('Facility Specific User Information')
30 if ($GLOBALS['ippf_specific']) {
31 $layouts['GCA'] = xl('Abortion Issues');
32 $layouts['CON'] = xl('Contraception Issues');
35 // Include Layout Based Transaction Forms.
36 $lres = sqlStatement("SELECT * FROM list_options " .
37 "WHERE list_id = 'transactions' AND activity = 1 ORDER BY seq, title");
38 while ($lrow = sqlFetchArray($lres)) {
39 $layouts[$lrow['option_id']] = xl_list_label($lrow['title']);
42 // Include Layout Based Encounter Forms.
43 $lres = sqlStatement("SELECT * FROM list_options " .
44 "WHERE list_id = 'lbfnames' AND activity = 1 ORDER BY seq, title");
45 while ($lrow = sqlFetchArray($lres)) {
46 $layouts[$lrow['option_id']] = xl_list_label($lrow['title']);
49 // Include predefined Validation Rules from list
50 $validations = array();
51 $lres = sqlStatement("SELECT * FROM list_options " .
52 "WHERE list_id = 'LBF_Validations' AND activity = 1 ORDER BY seq, title");
53 while ($lrow = sqlFetchArray($lres)) {
54 $validations[$lrow['option_id']] = xl_list_label($lrow['title']);
56 // array of the data_types of the fields
57 $datatypes = array(
58 "1" => xl("List box"),
59 "2" => xl("Textbox"),
60 "3" => xl("Textarea"),
61 "4" => xl("Text-date"),
62 "10" => xl("Providers"),
63 "11" => xl("Providers NPI"),
64 "12" => xl("Pharmacies"),
65 "13" => xl("Squads"),
66 "14" => xl("Organizations"),
67 "15" => xl("Billing codes"),
68 "16" => xl("Insurances"),
69 "18" => xl("Visit Categories"),
70 "21" => xl("Checkbox list"),
71 "22" => xl("Textbox list"),
72 "23" => xl("Exam results"),
73 "24" => xl("Patient allergies"),
74 "25" => xl("Checkbox w/text"),
75 "26" => xl("List box w/add"),
76 "27" => xl("Radio buttons"),
77 "28" => xl("Lifestyle status"),
78 "31" => xl("Static Text"),
79 "32" => xl("Smoking Status"),
80 "33" => xl("Race and Ethnicity"),
81 "34" => xl("NationNotes"),
82 "35" => xl("Facilities"),
83 "36" => xl("Multiple Select List"),
84 "40" => xl("Image canvas"),
87 $sources = array(
88 'F' => xl('Form'),
89 'D' => xl('Patient'),
90 'H' => xl('History'),
91 'E' => xl('Visit'),
92 'V' => xl('VisForm'),
95 function nextGroupOrder($order) {
96 if ($order == '9') $order = 'A';
97 else if ($order == 'Z') $order = 'a';
98 else $order = chr(ord($order) + 1);
99 return $order;
102 // Call this when adding or removing a layout field. This will create or drop
103 // the corresponding table column when appropriate. Table columns are not
104 // dropped if they contain any non-empty values.
105 function addOrDeleteColumn($layout_id, $field_id, $add=TRUE) {
106 if (substr($layout_id,0,3) == 'LBF' || substr($layout_id,0,3) == 'LBT' || $layout_id == "FACUSR") return;
108 if ($layout_id == "DEM") $tablename = "patient_data";
109 else if ($layout_id == "HIS") $tablename = "history_data";
110 else if ($layout_id == "SRH") $tablename = "lists_ippf_srh";
111 else if ($layout_id == "CON") $tablename = "lists_ippf_con";
112 else if ($layout_id == "GCA") $tablename = "lists_ippf_gcac";
113 else die('Internal error in addOrDeleteColumn()');
115 // Check if the column currently exists.
116 $tmp = sqlQuery("SHOW COLUMNS FROM `$tablename` LIKE '$field_id'");
117 $column_exists = !empty($tmp);
119 if ($add && !$column_exists) {
120 sqlStatement("ALTER TABLE `$tablename` ADD `$field_id` TEXT");
121 newEvent("alter_table", $_SESSION['authUser'], $_SESSION['authProvider'], 1,
122 "$tablename ADD $field_id");
124 else if (!$add && $column_exists) {
125 // Do not drop a column that has any data.
126 $tmp = sqlQuery("SELECT `$field_id` FROM `$tablename` WHERE " .
127 "`$field_id` IS NOT NULL AND `$field_id` != '' LIMIT 1");
128 if (!isset($tmp['field_id'])) {
129 sqlStatement("ALTER TABLE `$tablename` DROP `$field_id`");
130 newEvent("alter_table", $_SESSION['authUser'], $_SESSION['authProvider'], 1,
131 "$tablename DROP $field_id ");
136 // Check authorization.
137 $thisauth = acl_check('admin', 'super');
138 if (!$thisauth) die(xl('Not authorized'));
140 // The layout ID identifies the layout to be edited.
141 $layout_id = empty($_REQUEST['layout_id']) ? '' : $_REQUEST['layout_id'];
143 // Tag style for stuff to hide if not an LBF layout. Currently just for the Source column.
144 $lbfonly = substr($layout_id,0,3) == 'LBF' ? "" : "style='display:none;'";
146 // Handle the Form actions
148 if ($_POST['formaction'] == "save" && $layout_id) {
149 // If we are saving, then save.
150 $fld = $_POST['fld'];
151 for ($lino = 1; isset($fld[$lino]['id']); ++$lino) {
152 $iter = $fld[$lino];
153 $field_id = formTrim($iter['id']);
154 $data_type = formTrim($iter['data_type']);
155 $listval = $data_type == 34 ? formTrim($iter['contextName']) : formTrim($iter['list_id']);
157 // Skip conditions for the line are stored as a serialized array.
158 $condarr = array();
159 for ($cix = 0; !empty($iter['condition_id'][$cix]); ++$cix) {
160 $andor = empty($iter['condition_andor'][$cix]) ? '' : $iter['condition_andor'][$cix];
161 $condarr[$cix] = array(
162 'id' => strip_escape_custom($iter['condition_id' ][$cix]),
163 'itemid' => strip_escape_custom($iter['condition_itemid' ][$cix]),
164 'operator' => strip_escape_custom($iter['condition_operator'][$cix]),
165 'value' => strip_escape_custom($iter['condition_value' ][$cix]),
166 'andor' => strip_escape_custom($andor),
169 $conditions = empty($condarr) ? '' : serialize($condarr);
170 if ($field_id) {
171 sqlStatement("UPDATE layout_options SET " .
172 "source = '" . formTrim($iter['source']) . "', " .
173 "title = '" . formTrim($iter['title']) . "', " .
174 "group_name = '" . formTrim($iter['group']) . "', " .
175 "seq = '" . formTrim($iter['seq']) . "', " .
176 "uor = '" . formTrim($iter['uor']) . "', " .
177 "fld_length = '" . formTrim($iter['lengthWidth']) . "', " .
178 "fld_rows = '" . formTrim($iter['lengthHeight']) . "', " .
179 "max_length = '" . formTrim($iter['maxSize']) . "', " .
180 "titlecols = '" . formTrim($iter['titlecols']) . "', " .
181 "datacols = '" . formTrim($iter['datacols']) . "', " .
182 "data_type= '$data_type', " .
183 "list_id= '" . $listval . "', " .
184 "list_backup_id= '" . formTrim($iter['list_backup_id']) . "', " .
185 "edit_options = '" . formTrim($iter['edit_options']) . "', " .
186 "default_value = '" . formTrim($iter['default']) . "', " .
187 "description = '" . formTrim($iter['desc']) . "', " .
188 "conditions = '" . add_escape_custom($conditions) . "', " .
189 "validation = '" . formTrim($iter['validation']) . "' " .
190 "WHERE form_id = '$layout_id' AND field_id = '$field_id'");
195 else if ($_POST['formaction'] == "addfield" && $layout_id) {
196 // Add a new field to a specific group
197 $data_type = formTrim($_POST['newdatatype']);
198 $max_length = $data_type == 3 ? 3 : 255;
199 $listval = $data_type == 34 ? formTrim($_POST['contextName']) : formTrim($_POST['newlistid']);
200 sqlStatement("INSERT INTO layout_options (" .
201 " form_id, source, field_id, title, group_name, seq, uor, fld_length, fld_rows" .
202 ", titlecols, datacols, data_type, edit_options, default_value, description" .
203 ", max_length, list_id, list_backup_id " .
204 ") VALUES ( " .
205 "'" . formTrim($_POST['layout_id'] ) . "'" .
206 ",'" . formTrim($_POST['newsource'] ) . "'" .
207 ",'" . formTrim($_POST['newid'] ) . "'" .
208 ",'" . formTrim($_POST['newtitle'] ) . "'" .
209 ",'" . formTrim($_POST['newfieldgroupid']) . "'" .
210 ",'" . formTrim($_POST['newseq'] ) . "'" .
211 ",'" . formTrim($_POST['newuor'] ) . "'" .
212 ",'" . formTrim($_POST['newlengthWidth'] ) . "'" .
213 ",'" . formTrim($_POST['newlengthHeight'] ) . "'" .
214 ",'" . formTrim($_POST['newtitlecols'] ) . "'" .
215 ",'" . formTrim($_POST['newdatacols'] ) . "'" .
216 ",'$data_type'" .
217 ",'" . formTrim($_POST['newedit_options']) . "'" .
218 ",'" . formTrim($_POST['newdefault'] ) . "'" .
219 ",'" . formTrim($_POST['newdesc'] ) . "'" .
220 ",'" . formTrim($_POST['newmaxSize']) . "'" .
221 ",'" . $listval . "'" .
222 ",'" . formTrim($_POST['newbackuplistid']) . "'" .
223 " )");
224 addOrDeleteColumn($layout_id, formTrim($_POST['newid']), TRUE);
227 else if ($_POST['formaction'] == "movefields" && $layout_id) {
228 // Move field(s) to a new group in the layout
229 $sqlstmt = "UPDATE layout_options SET ".
230 " group_name='". $_POST['targetgroup']."' ".
231 " WHERE ".
232 " form_id = '".$_POST['layout_id']."' ".
233 " AND field_id IN (";
234 $comma = "";
235 foreach (explode(" ", $_POST['selectedfields']) as $onefield) {
236 $sqlstmt .= $comma."'".$onefield."'";
237 $comma = ", ";
239 $sqlstmt .= ")";
240 //echo $sqlstmt;
241 sqlStatement($sqlstmt);
244 else if ($_POST['formaction'] == "deletefields" && $layout_id) {
245 // Delete a field from a specific group
246 $sqlstmt = "DELETE FROM layout_options WHERE ".
247 " form_id = '".$_POST['layout_id']."' ".
248 " AND field_id IN (";
249 $comma = "";
250 foreach (explode(" ", $_POST['selectedfields']) as $onefield) {
251 $sqlstmt .= $comma."'".$onefield."'";
252 $comma = ", ";
254 $sqlstmt .= ")";
255 sqlStatement($sqlstmt);
256 foreach (explode(" ", $_POST['selectedfields']) as $onefield) {
257 addOrDeleteColumn($layout_id, $onefield, FALSE);
261 else if ($_POST['formaction'] == "addgroup" && $layout_id) {
262 // all group names are prefixed with a number indicating their display order
263 // this new group is prefixed with the net highest number given the
264 // layout_id
265 $results = sqlStatement("select distinct(group_name) as gname ".
266 " from layout_options where ".
267 " form_id = '".$_POST['layout_id']."'"
269 $maxnum = '1';
270 while ($result = sqlFetchArray($results)) {
271 $tmp = substr($result['gname'], 0, 1);
272 if ($tmp >= $maxnum) $maxnum = nextGroupOrder($tmp);
275 $data_type = formTrim($_POST['gnewdatatype']);
276 $max_length = $data_type == 3 ? 3 : 255;
277 $listval = $data_type == 34 ? formTrim($_POST['gcontextName']) : formTrim($_POST['gnewlistid']);
278 // add a new group to the layout, with the defined field
279 sqlStatement("INSERT INTO layout_options (" .
280 " form_id, source, field_id, title, group_name, seq, uor, fld_length, fld_rows" .
281 ", titlecols, datacols, data_type, edit_options, default_value, description" .
282 ", max_length, list_id, list_backup_id " .
283 ") VALUES ( " .
284 "'" . formTrim($_POST['layout_id'] ) . "'" .
285 ",'" . formTrim($_POST['gnewsource'] ) . "'" .
286 ",'" . formTrim($_POST['gnewid'] ) . "'" .
287 ",'" . formTrim($_POST['gnewtitle'] ) . "'" .
288 ",'" . formTrim($maxnum . $_POST['newgroupname']) . "'" .
289 ",'" . formTrim($_POST['gnewseq'] ) . "'" .
290 ",'" . formTrim($_POST['gnewuor'] ) . "'" .
291 ",'" . formTrim($_POST['gnewlengthWidth'] ) . "'" .
292 ",'" . formTrim($_POST['gnewlengthHeight'] ) . "'" .
293 ",'" . formTrim($_POST['gnewtitlecols'] ) . "'" .
294 ",'" . formTrim($_POST['gnewdatacols'] ) . "'" .
295 ",'$data_type'" .
296 ",'" . formTrim($_POST['gnewedit_options']) . "'" .
297 ",'" . formTrim($_POST['gnewdefault'] ) . "'" .
298 ",'" . formTrim($_POST['gnewdesc'] ) . "'" .
299 ",'" . formTrim($_POST['gnewmaxSize']) . "'" .
300 ",'" . $listval . "'" .
301 ",'" . formTrim($_POST['gnewbackuplistid'] ) . "'" .
302 " )");
303 addOrDeleteColumn($layout_id, formTrim($_POST['gnewid']), TRUE);
306 else if ($_POST['formaction'] == "deletegroup" && $layout_id) {
307 // drop the fields from the related table (this is critical)
308 $res = sqlStatement("SELECT field_id FROM layout_options WHERE " .
309 "form_id = '" . $_POST['layout_id'] . "' ".
310 "AND group_name = '" . $_POST['deletegroupname'] . "'");
311 while ($row = sqlFetchArray($res)) {
312 addOrDeleteColumn($layout_id, $row['field_id'], FALSE);
314 // Delete an entire group from the form
315 sqlStatement("DELETE FROM layout_options WHERE ".
316 " form_id = '".$_POST['layout_id']."' ".
317 " AND group_name = '".$_POST['deletegroupname']."'"
321 else if ($_POST['formaction'] == "movegroup" && $layout_id) {
322 $results = sqlStatement("SELECT DISTINCT(group_name) AS gname " .
323 "FROM layout_options WHERE form_id = '$layout_id' " .
324 "ORDER BY gname");
325 $garray = array();
326 $i = 0;
327 while ($result = sqlFetchArray($results)) {
328 if ($result['gname'] == $_POST['movegroupname']) {
329 if ($_POST['movedirection'] == 'up') { // moving up
330 if ($i > 0) {
331 $garray[$i] = $garray[$i - 1];
332 $garray[$i - 1] = $result['gname'];
333 $i++;
335 else {
336 $garray[$i++] = $result['gname'];
339 else { // moving down
340 $garray[$i++] = '';
341 $garray[$i++] = $result['gname'];
344 else if ($i > 1 && $garray[$i - 2] == '') {
345 $garray[$i - 2] = $result['gname'];
347 else {
348 $garray[$i++] = $result['gname'];
351 $nextord = '1';
352 foreach ($garray as $value) {
353 if ($value === '') continue;
354 $newname = $nextord . substr($value, 1);
355 sqlStatement("UPDATE layout_options SET " .
356 "group_name = '$newname' WHERE " .
357 "form_id = '$layout_id' AND " .
358 "group_name = '$value'");
359 $nextord = nextGroupOrder($nextord);
363 else if ($_POST['formaction'] == "renamegroup" && $layout_id) {
364 $currpos = substr($_POST['renameoldgroupname'], 0, 1);
365 // update the database rows
366 sqlStatement("UPDATE layout_options SET " .
367 "group_name = '" . $currpos . $_POST['renamegroupname'] . "' ".
368 "WHERE form_id = '$layout_id' AND ".
369 "group_name = '" . $_POST['renameoldgroupname'] . "'");
372 // Get the selected form's elements.
373 if ($layout_id) {
374 $res = sqlStatement("SELECT * FROM layout_options WHERE " .
375 "form_id = '$layout_id' ORDER BY group_name, seq");
378 // global counter for field numbers
379 $fld_line_no = 0;
381 $extra_html = '';
383 // This is called to generate a select option list for fields within this form.
384 // Used for selecting a field for testing in a skip condition.
386 function genFieldOptionList($current='') {
387 global $layout_id;
388 $option_list = "<option value=''>-- " . xlt('Please Select') . " --</option>";
389 if ($layout_id) {
390 $query = "SELECT field_id FROM layout_options WHERE form_id = ? ORDER BY group_name, seq";
391 $res = sqlStatement($query, array($layout_id));
392 while ($row = sqlFetchArray($res)) {
393 $field_id = $row['field_id'];
394 $option_list .= "<option value='" . attr($field_id) . "'";
395 if ($field_id == $current) $option_list .= " selected";
396 $option_list .= ">" . text($field_id) . "</option>";
399 return $option_list;
402 // Write one option line to the form.
404 function writeFieldLine($linedata) {
405 global $fld_line_no, $sources, $lbfonly, $extra_html,$validations;
406 ++$fld_line_no;
407 $checked = $linedata['default_value'] ? " checked" : "";
409 //echo " <tr bgcolor='$bgcolor'>\n";
410 echo " <tr id='fld[$fld_line_no]' class='".($fld_line_no % 2 ? 'even' : 'odd')."'>\n";
412 echo " <td class='optcell' style='width:4%' nowrap>";
413 // tuck the group_name INPUT in here
414 echo "<input type='hidden' name='fld[$fld_line_no][group]' value='" .
415 htmlspecialchars($linedata['group_name'], ENT_QUOTES) . "' class='optin' />";
417 echo "<input type='checkbox' class='selectfield' ".
418 "name='".$linedata['group_name']."~".$linedata['field_id']."' ".
419 "id='".$linedata['group_name']."~".$linedata['field_id']."' ".
420 "title='".htmlspecialchars(xl('Select field', ENT_QUOTES))."'>";
422 echo "<input type='text' name='fld[$fld_line_no][seq]' id='fld[$fld_line_no][seq]' value='" .
423 htmlspecialchars($linedata['seq'], ENT_QUOTES) . "' size='2' maxlength='3' " .
424 "class='optin' style='width:36pt' />";
425 echo "</td>\n";
427 echo " <td align='center' class='optcell' $lbfonly style='width:3%'>";
428 echo "<select name='fld[$fld_line_no][source]' class='optin noselect' $lbfonly>";
429 foreach ($sources as $key => $value) {
430 echo "<option value='" . attr($key) . "'";
431 if ($key == $linedata['source']) echo " selected";
432 echo ">" . text($value) . "</option>\n";
434 echo "</select>";
435 echo "</td>\n";
437 echo " <td align='left' class='optcell' style='width:10%'>";
438 echo "<input type='text' name='fld[$fld_line_no][id]' value='" .
439 htmlspecialchars($linedata['field_id'], ENT_QUOTES) . "' size='15' maxlength='63'
440 class='optin noselect' style='width:100%' />";
441 // class='optin noselect' onclick='FieldIDClicked(this)' />";
443 echo "<input type='hidden' name='fld[$fld_line_no][id]' value='" .
444 htmlspecialchars($linedata['field_id'], ENT_QUOTES) . "' />";
445 echo htmlspecialchars($linedata['field_id'], ENT_QUOTES);
447 echo "</td>\n";
449 echo " <td align='center' class='optcell' style='width:12%'>";
450 echo "<input type='text' id='fld[$fld_line_no][title]' name='fld[$fld_line_no][title]' value='" .
451 htmlspecialchars($linedata['title'], ENT_QUOTES) . "' size='15' maxlength='63' class='optin' style='width:100%' />";
452 echo "</td>\n";
454 // if not english and set to translate layout labels, then show the translation
455 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
456 echo "<td align='center' class='translation' style='width:10%'>" . htmlspecialchars(xl($linedata['title']), ENT_QUOTES) . "</td>\n";
459 echo " <td align='center' class='optcell' style='width:4%'>";
460 echo "<select name='fld[$fld_line_no][uor]' class='optin'>";
461 foreach (array(0 =>xl('Unused'), 1 =>xl('Optional'), 2 =>xl('Required')) as $key => $value) {
462 echo "<option value='$key'";
463 if ($key == $linedata['uor']) echo " selected";
464 echo ">$value</option>\n";
466 echo "</select>";
467 echo "</td>\n";
469 echo " <td align='center' class='optcell' style='width:8%'>";
470 echo "<select name='fld[$fld_line_no][data_type]' id='fld[$fld_line_no][data_type]' onchange=NationNotesContext('".$fld_line_no."',this.value)>";
471 echo "<option value=''></option>";
472 GLOBAL $datatypes;
473 foreach ($datatypes as $key=>$value) {
474 if ($linedata['data_type'] == $key)
475 echo "<option value='$key' selected>$value</option>";
476 else
477 echo "<option value='$key'>$value</option>";
479 echo "</select>";
480 echo " </td>";
482 echo " <td align='center' class='optcell' style='width:4%'>";
483 if ($linedata['data_type'] == 2 || $linedata['data_type'] == 3 ||
484 $linedata['data_type'] == 21 || $linedata['data_type'] == 22 ||
485 $linedata['data_type'] == 23 || $linedata['data_type'] == 25 ||
486 $linedata['data_type'] == 27 || $linedata['data_type'] == 28 ||
487 $linedata['data_type'] == 32 || $linedata['data_type'] == 15 ||
488 $linedata['data_type'] == 40
490 // Show the width field
491 echo "<input type='text' name='fld[$fld_line_no][lengthWidth]' value='" .
492 htmlspecialchars($linedata['fld_length'], ENT_QUOTES) .
493 "' size='2' maxlength='10' class='optin' title='" . xla('Width') . "' />";
494 if ($linedata['data_type'] == 3 || $linedata['data_type'] == 40) {
495 // Show the height field
496 echo "<input type='text' name='fld[$fld_line_no][lengthHeight]' value='" .
497 htmlspecialchars($linedata['fld_rows'], ENT_QUOTES) .
498 "' size='2' maxlength='10' class='optin' title='" . xla('Height') . "' />";
500 else {
501 // Hide the height field
502 echo "<input type='hidden' name='fld[$fld_line_no][lengthHeight]' value=''>";
505 else {
506 // all other data_types (hide both the width and height fields
507 echo "<input type='hidden' name='fld[$fld_line_no][lengthWidth]' value=''>";
508 echo "<input type='hidden' name='fld[$fld_line_no][lengthHeight]' value=''>";
510 echo "</td>\n";
512 echo " <td align='center' class='optcell' style='width:4%'>";
513 echo "<input type='text' name='fld[$fld_line_no][maxSize]' value='" .
514 htmlspecialchars($linedata['max_length'], ENT_QUOTES) .
515 "' size='1' maxlength='10' class='optin' style='width:100%' " .
516 "title='" . xla('Maximum Size (entering 0 will allow any size)') . "' />";
517 echo "</td>\n";
519 echo " <td align='center' class='optcell' style='width:8%'>";
520 if ($linedata['data_type'] == 1 || $linedata['data_type'] == 21 ||
521 $linedata['data_type'] == 22 || $linedata['data_type'] == 23 ||
522 $linedata['data_type'] == 25 || $linedata['data_type'] == 26 ||
523 $linedata['data_type'] == 27 || $linedata['data_type'] == 32 ||
524 $linedata['data_type'] == 33 || $linedata['data_type'] == 34 ||
525 $linedata['data_type'] == 36)
527 $type = "";
528 $disp = "style='display:none'";
529 if($linedata['data_type'] == 34){
530 $type = "style='display:none'";
531 $disp = "";
533 echo "<input type='text' name='fld[$fld_line_no][list_id]' id='fld[$fld_line_no][list_id]' value='" .
534 htmlspecialchars($linedata['list_id'], ENT_QUOTES) . "'".$type.
535 " size='6' maxlength='30' class='optin listid' style='width:100%;cursor:pointer'".
536 "title='". xl('Choose list') . "' />";
538 echo "<select name='fld[$fld_line_no][contextName]' id='fld[$fld_line_no][contextName]' ".$disp.">";
539 $res = sqlStatement("SELECT * FROM customlists WHERE cl_list_type=2 AND cl_deleted=0");
540 while($row = sqlFetchArray($res)){
541 $sel = '';
542 if ($linedata['list_id'] == $row['cl_list_item_long'])
543 $sel = 'selected';
544 echo "<option value='".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES)."' ".$sel.">".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES)."</option>";
546 echo "</select>";
548 else {
549 // all other data_types
550 echo "<input type='hidden' name='fld[$fld_line_no][list_id]' value=''>";
552 echo "</td>\n";
554 //Backup List Begin
555 echo " <td align='center' class='optcell' style='width:4%'>";
556 if ($linedata['data_type'] == 1 || $linedata['data_type'] == 26 ||
557 $linedata['data_type'] == 33 || $linedata['data_type'] == 36)
559 echo "<input type='text' name='fld[$fld_line_no][list_backup_id]' value='" .
560 htmlspecialchars($linedata['list_backup_id'], ENT_QUOTES) .
561 "' size='3' maxlength='10' class='optin listid' style='cursor:pointer; width:100%' />";
563 else {
564 echo "<input type='hidden' name='fld[$fld_line_no][list_backup_id]' value=''>";
566 echo "</td>\n";
567 //Backup List End
569 echo " <td align='center' class='optcell' style='width:4%'>";
570 echo "<input type='text' name='fld[$fld_line_no][titlecols]' value='" .
571 htmlspecialchars($linedata['titlecols'], ENT_QUOTES) . "' size='3' maxlength='10' class='optin' style='width:100%' />";
572 echo "</td>\n";
574 echo " <td align='center' class='optcell' style='width:4%'>";
575 echo "<input type='text' name='fld[$fld_line_no][datacols]' value='" .
576 htmlspecialchars($linedata['datacols'], ENT_QUOTES) . "' size='3' maxlength='10' class='optin' style='width:100%' />";
577 echo "</td>\n";
579 echo " <td align='center' class='optcell' style='width:5%' title='" .
580 "A = " . xla('Age') .
581 ", B = " . xla('Gestational Age') .
582 ", C = " . xla('Capitalize') .
583 ", D = " . xla('Dup Check') .
584 ", E = " . xla('Dup Check on only Edit') .
585 ", W = " . xla('Dup Check on only New') .
586 ", G = " . xla('Graphable') .
587 ", L = " . xla('Lab Order') .
588 ", N = " . xla('New Patient Form') .
589 ", O = " . xla('Order Processor') .
590 ", P = " . xla('Default to previous value') .
591 ", R = " . xla('Distributor') .
592 ", T = " . xla('Description is default text') .
593 ", U = " . xla('Capitalize all') .
594 ", V = " . xla('Vendor') .
595 ", 0 = " . xla('Read Only') .
596 ", 1 = " . xla('Write Once') .
597 ", 2 = " . xla('Billing Code Descriptions') .
599 "'>";
600 echo "<input type='text' name='fld[$fld_line_no][edit_options]' value='" .
601 htmlspecialchars($linedata['edit_options'], ENT_QUOTES) . "' size='3' " .
602 "maxlength='36' class='optin' style='width:100%' />";
603 echo "</td>\n";
605 /*****************************************************************
606 echo " <td align='center' class='optcell'>";
607 if ($linedata['data_type'] == 2) {
608 echo "<input type='text' name='fld[$fld_line_no][default]' value='" .
609 htmlspecialchars($linedata['default_value'], ENT_QUOTES) . "' size='10' maxlength='63' class='optin' />";
610 } else {
611 echo "&nbsp;";
613 echo "</td>\n";
615 echo " <td align='center' class='optcell'>";
616 echo "<input type='text' name='fld[$fld_line_no][desc]' value='" .
617 htmlspecialchars($linedata['description'], ENT_QUOTES) . "' size='20' maxlength='63' class='optin' />";
618 echo "</td>\n";
620 // if not english and showing layout labels, then show the translation of Description
621 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
622 echo "<td align='center' class='translation'>" . htmlspecialchars(xl($linedata['description']), ENT_QUOTES) . "</td>\n";
624 *****************************************************************/
626 if ($linedata['data_type'] == 31) {
627 echo " <td align='center' class='optcell' style='width:24%'>";
628 echo "<textarea name='fld[$fld_line_no][desc]' rows='3' cols='35' class='optin' style='width:100%'>" .
629 $linedata['description'] . "</textarea>";
630 echo "<input type='hidden' name='fld[$fld_line_no][default]' value='" .
631 htmlspecialchars($linedata['default_value'], ENT_QUOTES) . "' />";
632 echo "</td>\n";
634 else {
635 echo " <td align='center' class='optcell' style='width:24%'>";
636 echo "<input type='text' name='fld[$fld_line_no][desc]' value='" .
637 htmlspecialchars($linedata['description'], ENT_QUOTES) .
638 "' size='30' class='optin' style='width:100%' />";
639 echo "<input type='hidden' name='fld[$fld_line_no][default]' value='" .
640 htmlspecialchars($linedata['default_value'], ENT_QUOTES) . "' />";
641 echo "</td>\n";
642 // if not english and showing layout labels, then show the translation of Description
643 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
644 echo "<td align='center' class='translation' style='width:10%'>" .
645 htmlspecialchars(xl($linedata['description']), ENT_QUOTES) . "</td>\n";
649 // The "?" to click on for yet more field attributes.
650 echo " <td class='bold' id='querytd_$fld_line_no' style='cursor:pointer;";
651 if (!empty($linedata['conditions']) || !empty($linedata['validation'])) echo "background-color:#77ff77;";
652 echo "' onclick='extShow($fld_line_no, this)' align='center' ";
653 echo "title='" . xla('Click here to view/edit more details') . "'>";
654 echo "&nbsp;?&nbsp;";
655 echo "</td>\n";
657 echo " </tr>\n";
659 // Create a floating div for the additional attributes of this field.
660 $conditions = empty($linedata['conditions']) ?
661 array(0 => array('id' => '', 'itemid' => '', 'operator' => '', 'value' => '')) :
662 unserialize($linedata['conditions']);
664 $extra_html .= "<div id='ext_$fld_line_no' " .
665 "style='position:absolute;width:750px;border:1px solid black;" .
666 "padding:2px;background-color:#cccccc;visibility:hidden;" .
667 "z-index:1000;left:-1000px;top:0px;font-size:9pt;'>\n" .
668 "<table width='100%'>\n" .
669 " <tr>\n" .
670 " <th colspan='3' align='left' class='bold'>\"" . text($linedata['field_id']) . "\" " .
671 xlt('will be hidden if') . ":</th>\n" .
672 " <th colspan='2' align='right' class='text'><input type='button' " .
673 "value='" . xla('Close') . "' onclick='extShow($fld_line_no, false)' />&nbsp;</th>\n" .
674 " </tr>\n" .
675 " <tr>\n" .
676 " <th align='left' class='bold'>" . xlt('Field ID') . "</th>\n" .
677 " <th align='left' class='bold'>" . xlt('List item ID') . "</th>\n" .
678 " <th align='left' class='bold'>" . xlt('Operator') . "</th>\n" .
679 " <th align='left' class='bold'>" . xlt('Value if comparing') . "</th>\n" .
680 " <th align='left' class='bold'>&nbsp;</th>\n" .
681 " </tr>\n";
682 // There may be multiple condition lines for each field.
683 foreach ($conditions as $i => $condition) {
684 $extra_html .=
685 " <tr>\n" .
686 " <td align='left'>\n" .
687 " <select name='fld[$fld_line_no][condition_id][$i]' onchange='cidChanged($fld_line_no, $i)'>" .
688 genFieldOptionList($condition['id']) . " </select>\n" .
689 " </td>\n" .
690 " <td align='left'>\n" .
691 // List item choices are populated on the client side but will need the current value,
692 // so we insert a temporary option here to hold that value.
693 " <select name='fld[$fld_line_no][condition_itemid][$i]'><option value='" .
694 attr($condition['itemid']) . "'>...</option></select>\n" .
695 " </td>\n" .
696 " <td align='left'>\n" .
697 " <select name='fld[$fld_line_no][condition_operator][$i]'>\n";
698 foreach (array(
699 'eq' => xl('Equals' ),
700 'ne' => xl('Does not equal' ),
701 'se' => xl('Is selected' ),
702 'ns' => xl('Is not selected'),
703 ) as $key => $value) {
704 $extra_html .= " <option value='$key'";
705 if ($key == $condition['operator']) $extra_html .= " selected";
706 $extra_html .= ">" . text($value) . "</option>\n";
708 $extra_html .=
709 " </select>\n" .
710 " </td>\n" .
711 " <td align='left' title='" . xla('Only for comparisons') . "'>\n" .
712 " <input type='text' name='fld[$fld_line_no][condition_value][$i]' value='" .
713 attr($condition['value']) . "' size='15' maxlength='63' />\n" .
714 " </td>\n";
715 if (count($conditions) == $i + 1) {
716 $extra_html .=
717 " <td align='right' title='" . xla('Add a condition') . "'>\n" .
718 " <input type='button' value='+' onclick='extAddCondition($fld_line_no,this)' />\n" .
719 " </td>\n";
721 else {
722 $extra_html .=
723 " <td align='right'>\n" .
724 " <select name='fld[$fld_line_no][condition_andor][$i]'>\n";
725 foreach (array(
726 'and' => xl('And'),
727 'or' => xl('Or' ),
728 ) as $key => $value) {
729 $extra_html .= " <option value='$key'";
730 if ($key == $condition['andor']) $extra_html .= " selected";
731 $extra_html .= ">" . text($value) . "</option>\n";
733 $extra_html .=
734 " </select>\n" .
735 " </td>\n";
737 $extra_html .=
738 " </tr>\n";
740 $extra_html .=
741 "</table>\n";
743 $extra_html .= "<table width='100%'>\n" .
744 " <tr>\n" .
745 " <td colspan='3' align='left' class='bold'>\"" . text($linedata['field_id']) . "\" " .
746 xlt('will have the following validation rules') . ":</td>\n" .
747 " </tr>\n" .
748 " <tr>\n" .
749 " <td align='left' class='bold'>" . xlt('Validation rule') . " </td>\n" .
750 " </tr>\n".
751 " <tr>\n" .
752 " <td align='left' title='" . xla('Select a validation rule') . "'>\n" .
755 " <select name='fld[$fld_line_no][validation]' onchange='valChanged($fld_line_no)'>\n" .
756 " <option value=''";
757 if (empty($linedata['validation'])) $extra_html .= " selected";
758 $extra_html .= ">-- " . xlt('Please Select') . " --</option>";
759 foreach ($validations as $key=>$value){
760 $extra_html .= " <option value='$key'";
761 if ($key == $linedata['validation']) $extra_html .= " selected";
762 $extra_html .= ">" . text($value) . "</option>\n";
764 $extra_html .="</select>\n" .
765 " </td>\n";
767 $extra_html .=
768 "</table>\n" .
769 "</div>\n";
772 <html>
774 <head>
775 <?php html_header_show();?>
777 <!-- supporting javascript code -->
778 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-2-1/index.js"></script>
780 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
782 <title><?php xl('Layout Editor','e'); ?></title>
784 <style>
785 tr.head { font-size:10pt; background-color:#cccccc; }
786 tr.detail { font-size:10pt; }
787 td { font-size:10pt; }
788 input { font-size:10pt; }
789 a, a:visited, a:hover { color:#0000cc; }
790 .optcell { }
791 .optin { background: transparent; }
792 .group {
793 margin: 0pt 0pt 8pt 0pt;
794 padding :0pt;
795 width: 100%;
798 .group table {
799 border-collapse: collapse;
800 width: 100%;
803 .odd td {
804 background-color: #ddddff;
805 padding: 3px 0px 3px 0px;
807 .even td {
808 background-color: #ffdddd;
809 padding: 3px 0px 3px 0px;
811 .help { cursor: help; }
812 .layouts_title { font-size: 110%; }
813 .translation {
814 color: green;
815 font-size:10pt;
817 .highlight * {
818 border: 2px solid blue;
819 background-color: yellow;
820 color: black;
823 </style>
825 <script language="JavaScript">
827 // Helper functions for positioning the floating divs.
828 function extGetX(elem) {
829 var x = 0;
830 while(elem != null) {
831 x += elem.offsetLeft;
832 elem = elem.offsetParent;
834 return x;
836 function extGetY(elem) {
837 var y = 0;
838 while(elem != null) {
839 y += elem.offsetTop;
840 elem = elem.offsetParent;
842 return y;
845 // Show or hide the "extras" div for a row.
846 var extdiv = null;
847 function extShow(lino, show) {
848 var thisdiv = document.getElementById("ext_" + lino);
849 if (extdiv) {
850 extdiv.style.visibility = 'hidden';
851 extdiv.style.left = '-1000px';
852 extdiv.style.top = '0px';
854 if (show && thisdiv != extdiv) {
855 extdiv = thisdiv;
856 var dw = window.innerWidth ? window.innerWidth - 20 : document.body.clientWidth;
857 x = dw - extdiv.offsetWidth;
858 if (x < 0) x = 0;
859 var y = extGetY(show) + show.offsetHeight;
860 extdiv.style.left = x;
861 extdiv.style.top = y;
862 extdiv.style.visibility = 'visible';
864 else {
865 extdiv = null;
869 // Add an extra condition line for the given row.
870 function extAddCondition(lino, btnelem) {
871 var f = document.forms[0];
872 var i = 0;
874 // Get index of next condition line.
875 while (f['fld[' + lino + '][condition_id][' + i + ']']) ++i;
876 if (i == 0) alert('f["fld[' + lino + '][condition_id][' + i + ']"] <?php echo xls('not found') ?>');
878 // Get containing <td>, <tr> and <table> nodes of the "+" button.
879 var tdplus = btnelem.parentNode;
880 var trelem = tdplus.parentNode;
881 var telem = trelem.parentNode;
883 // Replace contents of the tdplus cell.
884 tdplus.innerHTML =
885 "<select name='fld[" + lino + "][condition_andor][" + i + "]'>" +
886 "<option value='and'><?php echo xls('And') ?></option>" +
887 "<option value='or' ><?php echo xls('Or' ) ?></option>" +
888 "</select>";
890 // Add the new row.
891 var newtrelem = telem.insertRow(i+2);
892 newtrelem.innerHTML =
893 "<td align='left'>" +
894 "<select name='fld[" + lino + "][condition_id][" + i + "]' onchange='cidChanged(" + lino + "," + i + ")'>" +
895 "<?php echo addslashes(genFieldOptionList()) ?>" +
896 "</select>" +
897 "</td>" +
898 "<td align='left'>" +
899 "<select name='fld[" + lino + "][condition_itemid][" + i + "]' style='display:none' />" +
900 "</td>" +
901 "<td align='left'>" +
902 "<select name='fld[" + lino + "][condition_operator][" + i + "]'>" +
903 "<option value='eq'><?php echo xls('Equals' ) ?></option>" +
904 "<option value='ne'><?php echo xls('Does not equal' ) ?></option>" +
905 "<option value='se'><?php echo xls('Is selected' ) ?></option>" +
906 "<option value='ns'><?php echo xls('Is not selected') ?></option>" +
907 "</select>" +
908 "</td>" +
909 "<td align='left'>" +
910 "<input type='text' name='fld[" + lino + "][condition_value][" + i + "]' value='' size='15' maxlength='63' />" +
911 "</td>" +
912 "<td align='right'>" +
913 "<input type='button' value='+' onclick='extAddCondition(" + lino + ",this)' />" +
914 "</td>";
917 // This is called when a field ID is chosen for testing within a skip condition.
918 // It checks to see if a corresponding list item must also be chosen for the test, and
919 // if so then inserts the dropdown for selecting an item from the appropriate list.
920 function setListItemOptions(lino, seq, init) {
921 var f = document.forms[0];
922 var target = 'fld[' + lino + '][condition_itemid][' + seq + ']';
923 // field_id is the ID of the field that the condition will test.
924 var field_id = f['fld[' + lino + '][condition_id][' + seq + ']'].value;
925 if (!field_id) {
926 f[target].options.length = 0;
927 f[target].style.display = 'none';
928 return;
930 // Find the occurrence of that field in the layout.
931 var i = 1;
932 while (true) {
933 var idname = 'fld[' + i + '][id]';
934 if (!f[idname]) {
935 alert('<?php echo xls('Condition field not found') ?>: ' + field_id);
936 return;
938 if (f[idname].value == field_id) break;
939 ++i;
941 // If this is startup initialization then preserve the current value.
942 var current = init ? f[target].value : '';
943 f[target].options.length = 0;
944 // Get the corresponding data type and list ID.
945 var data_type = f['fld[' + i + '][data_type]'].value;
946 var list_id = f['fld[' + i + '][list_id]'].value;
947 // WARNING: If new data types are defined the following test may need enhancing.
948 // We're getting out if the type does not generate multiple fields with different names.
949 if (data_type != '21' && data_type != '22' && data_type != '23' && data_type != '25') {
950 f[target].style.display = 'none';
951 return;
953 // OK, list item IDs do apply so go get 'em.
954 // This happens asynchronously so the generated code needs to stand alone.
955 f[target].style.display = '';
956 $.getScript('layout_listitems_ajax.php' +
957 '?listid=' + encodeURIComponent(list_id) +
958 '&target=' + encodeURIComponent(target) +
959 '&current=' + encodeURIComponent(current));
962 // This is called whenever a condition's field ID selection is changed.
963 function cidChanged(lino, seq) {
964 changeColor(lino);
965 setListItemOptions(lino, seq, false);
968 // This is called whenever a validation rule field ID selection is changed.
969 function valChanged(lino) {
970 changeColor(lino);
973 function changeColor(lino){
974 var thisid = document.forms[0]['fld[' + lino + '][condition_id][0]'].value;
975 var thisValId = document.forms[0]['fld[' + lino + '][validation]'].value;
976 var thistd = document.getElementById("querytd_" + lino);
977 if(thisid !='' || thisValId!='') {
978 thistd.style.backgroundColor = '#77ff77';
979 }else{
980 thistd.style.backgroundColor ='';
984 // Call this to disable the warning about unsaved changes and submit the form.
985 function mySubmit() {
986 somethingChanged = false;
987 top.restoreSession();
988 document.forms[0].submit();
991 // User is about to do something that would discard any unsaved changes.
992 // Return true if that is OK.
993 function myChangeCheck() {
994 if (somethingChanged) {
995 if (!confirm('<?php echo xls('You have unsaved changes. Abandon them?'); ?>')) {
996 return false;
998 // Do not set somethingChanged to false here because if they cancel the
999 // action then the previously changed values will still be of interest.
1001 return true;
1004 </script>
1006 </head>
1008 <body class="body_top admin-layout">
1010 <form method='post' name='theform' id='theform' action='edit_layout.php'>
1011 <input type="hidden" name="formaction" id="formaction" value="">
1012 <!-- elements used to identify a field to delete -->
1013 <input type="hidden" name="deletefieldid" id="deletefieldid" value="">
1014 <input type="hidden" name="deletefieldgroup" id="deletefieldgroup" value="">
1015 <!-- elements used to identify a group to delete -->
1016 <input type="hidden" name="deletegroupname" id="deletegroupname" value="">
1017 <!-- elements used to change the group order -->
1018 <input type="hidden" name="movegroupname" id="movegroupname" value="">
1019 <input type="hidden" name="movedirection" id="movedirection" value="">
1020 <!-- elements used to select more than one field -->
1021 <input type="hidden" name="selectedfields" id="selectedfields" value="">
1022 <input type="hidden" id="targetgroup" name="targetgroup" value="">
1023 <div class="menubar">
1024 <div>
1025 <b><?php xl('Edit layout','e'); ?>:</b>&nbsp;
1026 <select name='layout_id' id='layout_id'>
1027 <option value=''>-- <?php echo xl('Select') ?> --</option>
1028 <?php
1029 foreach ($layouts as $key => $value) {
1030 echo " <option value='$key'";
1031 if ($key == $layout_id) echo " selected";
1032 echo ">$value</option>\n";
1035 </select></div><div><p>
1036 <?php if ($layout_id) { ?>
1037 <input type='button' class='addgroup' id='addgroup' value=<?php xl('Add Group','e','\'','\''); ?>/>
1038 <span style="font-size:90%"> &nbsp;
1039 <input type='button' name='save' id='save' value='<?php xl('Save Changes','e'); ?>' /></span> &nbsp;&nbsp;
1040 <?php xl('With selected:', 'e');?>
1041 <input type='button' name='deletefields' id='deletefields' value='<?php xl('Delete','e'); ?>' style="font-size:90%" disabled="disabled" />
1042 <input type='button' name='movefields' id='movefields' value='<?php xl('Move to...','e'); ?>' style="font-size:90%" disabled="disabled" /></span>
1043 </p></div>
1044 </div>
1045 <div class="container">
1046 <?php } ?>
1047 <?php
1048 $prevgroup = "!@#asdf1234"; // an unlikely group name
1049 $firstgroup = true; // flag indicates it's the first group to be displayed
1050 while ($row = sqlFetchArray($res)) {
1051 if ($row['group_name'] != $prevgroup) {
1052 if ($firstgroup == false) { echo "</tbody></table></div>\n"; }
1053 echo "<div id='".$row['group_name']."' class='group'>";
1054 echo "<div class='text bold layouts_title' style='position:relative; background-color: #eef'>";
1055 // echo preg_replace("/^\d+/", "", $row['group_name']);
1056 echo substr($row['group_name'], 1);
1057 echo "&nbsp; ";
1058 // if not english and set to translate layout labels, then show the translation of group name
1059 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
1060 // echo "<span class='translation'>>>&nbsp; " . xl(preg_replace("/^\d+/", "", $row['group_name'])) . "</span>";
1061 echo "<span class='translation'>>>&nbsp; " . xl(substr($row['group_name'], 1)) . "</span>";
1062 echo "&nbsp; ";
1064 echo "&nbsp; ";
1065 echo " <input type='button' class='addfield' id='addto~".$row['group_name']."' value='" . xl('Add Field') . "'/>";
1066 echo "&nbsp; &nbsp; ";
1067 echo " <input type='button' class='renamegroup' id='".$row['group_name']."' value='" . xl('Rename Group') . "'/>";
1068 echo "&nbsp; &nbsp; ";
1069 echo " <input type='button' class='deletegroup' id='".$row['group_name']."' value='" . xl('Delete Group') . "'/>";
1070 echo "&nbsp; &nbsp; ";
1071 echo " <input type='button' class='movegroup' id='".$row['group_name']."~up' value='" . xl('Move Up') . "'/>";
1072 echo "&nbsp; &nbsp; ";
1073 echo " <input type='button' class='movegroup' id='".$row['group_name']."~down' value='" . xl('Move Down') . "'/>";
1074 echo "</div>";
1075 $firstgroup = false;
1077 <table>
1078 <thead>
1079 <tr class='head'>
1080 <th><?php xl('Order','e'); ?></th>
1081 <th<?php echo " $lbfonly"; ?>><?php xl('Source','e'); ?></th>
1082 <th><?php xl('ID','e'); ?>&nbsp;<span class="help" title=<?php xl('A unique value to identify this field, not visible to the user','e','\'','\''); ?> >(?)</span></th>
1083 <th><?php xl('Label','e'); ?>&nbsp;<span class="help" title=<?php xl('The label that appears to the user on the form','e','\'','\''); ?> >(?)</span></th>
1084 <?php // if not english and showing layout label translations, then show translation header for title
1085 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
1086 echo "<th>" . xl('Translation')."<span class='help' title='" . xl('The translated label that will appear on the form in current language') . "'>&nbsp;(?)</span></th>";
1087 } ?>
1088 <th><?php xl('UOR','e'); ?></th>
1089 <th><?php xl('Data Type','e'); ?></th>
1090 <th><?php xl('Size','e'); ?></th>
1091 <th><?php xl('Max Size','e'); ?></th>
1092 <th><?php xl('List','e'); ?></th>
1093 <th><?php xl('Backup List','e'); ?></th>
1094 <th><?php xl('Label Cols','e'); ?></th>
1095 <th><?php xl('Data Cols','e'); ?></th>
1096 <th><?php xl('Options','e'); ?></th>
1097 <th><?php xl('Description','e'); ?></th>
1098 <?php // if not english and showing layout label translations, then show translation header for description
1099 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
1100 echo "<th>" . xl('Translation')."<span class='help' title='" . xl('The translation of description in current language')."'>&nbsp;(?)</span></th>";
1101 } ?>
1102 <th><?php echo xlt('?'); ?></th>
1103 </tr>
1104 </thead>
1105 <tbody>
1107 <?php
1108 } // end if-group_name
1110 writeFieldLine($row);
1111 $prevgroup = $row['group_name'];
1113 } // end while loop
1116 </tbody>
1117 </table></div>
1119 <?php echo $extra_html; ?>
1121 </form>
1123 <!-- template DIV that appears when user chooses to rename an existing group -->
1124 <div id="renamegroupdetail" style="border: 1px solid black; padding: 3px; display: none; visibility: hidden; background-color: lightgrey;">
1125 <input type="hidden" name="renameoldgroupname" id="renameoldgroupname" value="">
1126 <?php xl('Group Name','e'); ?>: <input type="textbox" size="20" maxlength="30" name="renamegroupname" id="renamegroupname">
1127 <br>
1128 <input type="button" class="saverenamegroup" value=<?php xl('Rename Group','e','\'','\''); ?>>
1129 <input type="button" class="cancelrenamegroup" value=<?php xl('Cancel','e','\'','\''); ?>>
1130 </div>
1132 <!-- template DIV that appears when user chooses to add a new group -->
1133 <div id="groupdetail" style="border: 1px solid black; padding: 3px; display: none; visibility: hidden; background-color: lightgrey;">
1134 <span class='bold'>
1135 <?php xl('Group Name','e'); ?>: <input type="textbox" size="20" maxlength="30" name="newgroupname" id="newgroupname">
1136 <br>
1137 <table style="border-collapse: collapse; margin-top: 5px;">
1138 <thead>
1139 <tr class='head'>
1140 <th><?php xl('Order','e'); ?></th>
1141 <th<?php echo " $lbfonly"; ?>><?php xl('Source','e'); ?></th>
1142 <th><?php xl('ID','e'); ?>&nbsp;<span class="help" title=<?php xl('A unique value to identify this field, not visible to the user','e','\'','\''); ?> >(?)</span></th>
1143 <th><?php xl('Label','e'); ?>&nbsp;<span class="help" title=<?php xl('The label that appears to the user on the form','e','\'','\''); ?> >(?)</span></th>
1144 <th><?php xl('UOR','e'); ?></th>
1145 <th><?php xl('Data Type','e'); ?></th>
1146 <th><?php xl('Size','e'); ?></th>
1147 <th><?php xl('Max Size','e'); ?></th>
1148 <th><?php xl('List','e'); ?></th>
1149 <th><?php xl('Backup List','e'); ?></th>
1150 <th><?php xl('Label Cols','e'); ?></th>
1151 <th><?php xl('Data Cols','e'); ?></th>
1152 <th><?php xl('Options','e'); ?></th>
1153 <th><?php xl('Description','e'); ?></th>
1154 </tr>
1155 </thead>
1156 <tbody>
1157 <tr class='center'>
1158 <td ><input type="textbox" name="gnewseq" id="gnewseq" value="" size="2" maxlength="3"> </td>
1159 <td<?php echo " $lbfonly"; ?>>
1160 <select name='gnewsource' id='gnewsource'>
1161 <?php
1162 foreach ($sources as $key => $value) {
1163 echo "<option value='" . attr($key) . "'>" . text($value) . "</option>\n";
1166 </select>
1167 </td>
1168 <td><input type="textbox" name="gnewid" id="gnewid" value="" size="10" maxlength="20"
1169 onclick='FieldIDClicked(this)'> </td>
1170 <td><input type="textbox" name="gnewtitle" id="gnewtitle" value="" size="20" maxlength="63"> </td>
1171 <td>
1172 <select name="gnewuor" id="gnewuor">
1173 <option value="0"><?php xl('Unused','e'); ?></option>
1174 <option value="1" selected><?php xl('Optional','e'); ?></option>
1175 <option value="2"><?php xl('Required','e'); ?></option>
1176 </select>
1177 </td>
1178 <td align='center'>
1179 <select name='gnewdatatype' id='gnewdatatype'>
1180 <option value=''></option>
1181 <?php
1182 global $datatypes;
1183 foreach ($datatypes as $key=>$value) {
1184 echo "<option value='$key'>$value</option>";
1187 </select>
1188 </td>
1189 <td><input type="textbox" name="gnewlengthWidth" id="gnewlengthWidth" value="" size="1" maxlength="3" title="<?php echo xla('Width'); ?>">
1190 <input type="textbox" name="gnewlengthHeight" id="gnewlengthHeight" value="" size="1" maxlength="3" title="<?php echo xla('Height'); ?>"></td>
1191 <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>
1192 <td><input type="textbox" name="gnewlistid" id="gnewlistid" value="" size="8" maxlength="31" class="listid">
1193 <select name='gcontextName' id='gcontextName' style='display:none'>
1194 <?php
1195 $res = sqlStatement("SELECT * FROM customlists WHERE cl_list_type=2 AND cl_deleted=0");
1196 while($row = sqlFetchArray($res)){
1197 echo "<option value='".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES)."'>".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES)."</option>";
1200 </select>
1201 </td>
1202 <td><input type="textbox" name="gnewbackuplistid" id="gnewbackuplistid" value="" size="8" maxlength="31" class="listid"></td>
1203 <td><input type="textbox" name="gnewtitlecols" id="gnewtitlecols" value="" size="3" maxlength="3"> </td>
1204 <td><input type="textbox" name="gnewdatacols" id="gnewdatacols" value="" size="3" maxlength="3"> </td>
1205 <td><input type="textbox" name="gnewedit_options" id="gnewedit_options" value="" size="3" maxlength="36">
1206 <input type="hidden" name="gnewdefault" id="gnewdefault" value="" /> </td>
1207 <td><input type="textbox" name="gnewdesc" id="gnewdesc" value="" size="30" maxlength="63"> </td>
1208 </tr>
1209 </tbody>
1210 </table>
1211 <br>
1212 <input type="button" class="savenewgroup" value=<?php xl('Save New Group','e','\'','\''); ?>>
1213 <input type="button" class="cancelnewgroup" value=<?php xl('Cancel','e','\'','\''); ?>>
1214 </span>
1215 </div>
1217 <!-- template DIV that appears when user chooses to add a new field to a group -->
1218 <div id="fielddetail" class="fielddetail" style="display: none; visibility: hidden">
1219 <input type="hidden" name="newfieldgroupid" id="newfieldgroupid" value="">
1220 <table style="border-collapse: collapse;">
1221 <thead>
1222 <tr class='head'>
1223 <th><?php xl('Order','e'); ?></th>
1224 <th<?php echo " $lbfonly"; ?>><?php xl('Source','e'); ?></th>
1225 <th><?php xl('ID','e'); ?>&nbsp;<span class="help" title=<?php xl('A unique value to identify this field, not visible to the user','e','\'','\''); ?> >(?)</span></th>
1226 <th><?php xl('Label','e'); ?>&nbsp;<span class="help" title=<?php xl('The label that appears to the user on the form','e','\'','\''); ?> >(?)</span></th>
1227 <th><?php xl('UOR','e'); ?></th>
1228 <th><?php xl('Data Type','e'); ?></th>
1229 <th><?php xl('Size','e'); ?></th>
1230 <th><?php xl('Max Size','e'); ?></th>
1231 <th><?php xl('List','e'); ?></th>
1232 <th><?php xl('Backup List','e'); ?></th>
1233 <th><?php xl('Label Cols','e'); ?></th>
1234 <th><?php xl('Data Cols','e'); ?></th>
1235 <th><?php xl('Options','e'); ?></th>
1236 <th><?php xl('Description','e'); ?></th>
1237 </tr>
1238 </thead>
1239 <tbody>
1240 <tr class='center'>
1241 <td ><input type="textbox" name="newseq" id="newseq" value="" size="2" maxlength="3"> </td>
1242 <td<?php echo " $lbfonly"; ?>>
1243 <select name='newsource' id='newsource'>
1244 <?php
1245 foreach ($sources as $key => $value) {
1246 echo " <option value='" . attr($key) . "'>" . text($value) . "</option>\n";
1249 </select>
1250 </td>
1251 <td ><input type="textbox" name="newid" id="newid" value="" size="10" maxlength="20"
1252 onclick='FieldIDClicked(this)'> </td>
1253 <td><input type="textbox" name="newtitle" id="newtitle" value="" size="20" maxlength="63"> </td>
1254 <td>
1255 <select name="newuor" id="newuor">
1256 <option value="0"><?php xl('Unused','e'); ?></option>
1257 <option value="1" selected><?php xl('Optional','e'); ?></option>
1258 <option value="2"><?php xl('Required','e'); ?></option>
1259 </select>
1260 </td>
1261 <td align='center'>
1262 <select name='newdatatype' id='newdatatype'>
1263 <option value=''></option>
1264 <?php
1265 global $datatypes;
1266 foreach ($datatypes as $key=>$value) {
1267 echo " <option value='$key'>$value</option>\n";
1270 </select>
1271 </td>
1272 <td><input type="textbox" name="newlengthWidth" id="newlengthWidth" value="" size="1" maxlength="3" title="<?php echo xla('Width'); ?>">
1273 <input type="textbox" name="newlengthHeight" id="newlengthHeight" value="" size="1" maxlength="3" title="<?php echo xla('Height'); ?>"></td>
1274 <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>
1275 <td><input type="textbox" name="newlistid" id="newlistid" value="" size="8" maxlength="31" class="listid">
1276 <select name='contextName' id='contextName' style='display:none'>
1277 <?php
1278 $res = sqlStatement("SELECT * FROM customlists WHERE cl_list_type=2 AND cl_deleted=0");
1279 while($row = sqlFetchArray($res)){
1280 echo "<option value='".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES)."'>".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES)."</option>";
1283 </select>
1284 </td>
1285 <td><input type="textbox" name="newbackuplistid" id="newbackuplistid" value="" size="8" maxlength="31" class="listid"></td>
1286 <td><input type="textbox" name="newtitlecols" id="newtitlecols" value="" size="3" maxlength="3"> </td>
1287 <td><input type="textbox" name="newdatacols" id="newdatacols" value="" size="3" maxlength="3"> </td>
1288 <td><input type="textbox" name="newedit_options" id="newedit_options" value="" size="3" maxlength="36">
1289 <input type="hidden" name="newdefault" id="newdefault" value="" /> </td>
1290 <td><input type="textbox" name="newdesc" id="newdesc" value="" size="30" maxlength="63"> </td>
1291 </tr>
1292 <tr>
1293 <td colspan="9">
1294 <input type="button" class="savenewfield" value=<?php xl('Save New Field','e','\'','\''); ?>>
1295 <input type="button" class="cancelnewfield" value=<?php xl('Cancel','e','\'','\''); ?>>
1296 </td>
1297 </tr>
1298 </tbody>
1299 </table>
1300 </div>
1302 </body>
1304 <script language="javascript">
1306 // used when selecting a list-name for a field
1307 var selectedfield;
1309 // Support for beforeunload handler.
1310 var somethingChanged = false;
1312 // Get the next logical sequence number for a field in the specified group.
1313 // Note it guesses and uses the existing increment value.
1314 function getNextSeq(group) {
1315 var f = document.forms[0];
1316 var seq = 0;
1317 var delta = 10;
1318 for (var i = 1; true; ++i) {
1319 var gelem = f['fld[' + i + '][group]'];
1320 if (!gelem) break;
1321 if (gelem.value != group) continue;
1322 var tmp = parseInt(f['fld[' + i + '][seq]'].value);
1323 if (isNaN(tmp)) continue;
1324 if (tmp <= seq) continue;
1325 delta = tmp - seq;
1326 seq = tmp;
1328 return seq + delta;
1331 // jQuery stuff to make the page a little easier to use
1333 $(document).ready(function(){
1334 $("#save").click(function() { SaveChanges(); });
1335 $("#layout_id").change(function() {
1336 if (!myChangeCheck()) {
1337 $("#layout_id").val("<?php echo $layout_id; ?>");
1338 return;
1340 mySubmit();
1343 $(".addgroup").click(function() { AddGroup(this); });
1344 $(".savenewgroup").click(function() { SaveNewGroup(this); });
1345 $(".deletegroup").click(function() { DeleteGroup(this); });
1346 $(".cancelnewgroup").click(function() { CancelNewGroup(this); });
1347 $(".movegroup").click(function() { MoveGroup(this); });
1348 $(".renamegroup").click(function() { RenameGroup(this); });
1349 $(".saverenamegroup").click(function() { SaveRenameGroup(this); });
1350 $(".cancelrenamegroup").click(function() { CancelRenameGroup(this); });
1351 $(".addfield").click(function() { AddField(this); });
1352 $("#deletefields").click(function() { DeleteFields(this); });
1353 $(".selectfield").click(function() {
1354 var TRparent = $(this).parent().parent();
1355 $(TRparent).children("td").toggleClass("highlight");
1356 // disable the delete-move buttons
1357 $("#deletefields").attr("disabled", "disabled");
1358 $("#movefields").attr("disabled", "disabled");
1359 $(".selectfield").each(function(i) {
1360 // if any field is selected, enable the delete-move buttons
1361 if ($(this).attr("checked") == true) {
1362 $("#deletefields").removeAttr("disabled");
1363 $("#movefields").removeAttr("disabled");
1368 $("#movefields").click(function() { ShowGroups(this); });
1369 $(".savenewfield").click(function() { SaveNewField(this); });
1370 $(".cancelnewfield").click(function() { CancelNewField(this); });
1371 $("#newtitle").blur(function() { if ($("#newid").val() == "") $("#newid").val($("#newtitle").val()); });
1372 $("#newdatatype").change(function() { ChangeList(this.value);});
1373 $("#gnewdatatype").change(function() { ChangeListg(this.value);});
1374 $(".listid").click(function() { ShowLists(this); });
1376 // special class that skips the element
1377 $(".noselect").focus(function() { $(this).blur(); });
1379 // Save the changes made to the form
1380 var SaveChanges = function () {
1381 $("#formaction").val("save");
1382 mySubmit();
1385 /****************************************************/
1386 /************ Group functions ***********************/
1387 /****************************************************/
1389 // display the 'new group' DIV
1390 var AddGroup = function(btnObj) {
1391 if (!myChangeCheck()) return;
1392 $("#save").attr("disabled", true);
1393 // show the field details DIV
1394 $('#groupdetail').css('visibility', 'visible');
1395 $('#groupdetail').css('display', 'block');
1396 $(btnObj).parent().append($("#groupdetail"));
1397 $('#groupdetail > #newgroupname').focus();
1398 // Assign a sensible default sequence number.
1399 $('#gnewseq').val(10);
1402 // save the new group to the form
1403 var SaveNewGroup = function(btnObj) {
1404 // the group name field can only have letters, numbers, spaces and underscores
1405 // AND it cannot start with a number
1406 if ($("#newgroupname").val() == "") {
1407 alert("<?php xl('Group names cannot be blank', 'e'); ?>");
1408 return false;
1410 if ($("#newgroupname").val().match(/^(\d+|\s+)/)) {
1411 alert("<?php xl('Group names cannot start with numbers or spaces.','e'); ?>");
1412 return false;
1414 var validname = $("#newgroupname").val().replace(/[^A-za-z0-9 ]/g, "_"); // match any non-word characters and replace them
1415 $("#newgroupname").val(validname);
1417 // now, check the first group field values
1419 // seq must be numeric and less than 999
1420 if (! IsNumeric($("#gnewseq").val(), 0, 999)) {
1421 alert("<?php xl('Order must be a number between 1 and 999','e'); ?>");
1422 return false;
1424 // length must be numeric and less than 999
1425 if (! IsNumeric($("#gnewlengthWidth").val(), 0, 999)) {
1426 alert("<?php xl('Size must be a number between 1 and 999','e'); ?>");
1427 return false;
1429 // titlecols must be numeric and less than 100
1430 if (! IsNumeric($("#gnewtitlecols").val(), 0, 999)) {
1431 alert("<?php xl('LabelCols must be a number between 1 and 999','e'); ?>");
1432 return false;
1434 // datacols must be numeric and less than 100
1435 if (! IsNumeric($("#gnewdatacols").val(), 0, 999)) {
1436 alert("<?php xl('DataCols must be a number between 1 and 999','e'); ?>");
1437 return false;
1439 // some fields cannot be blank
1440 if ($("#gnewtitle").val() == "") {
1441 alert("<?php xl('Label cannot be blank','e'); ?>");
1442 return false;
1444 // the id field can only have letters, numbers and underscores
1445 if ($("#gnewid").val() == "") {
1446 alert("<?php xl('ID cannot be blank', 'e'); ?>");
1447 return false;
1449 var validid = $("#gnewid").val().replace(/(\s|\W)/g, "_"); // match any non-word characters and replace them
1450 $("#gnewid").val(validid);
1451 // similarly with the listid field
1452 validid = $("#gnewlistid").val().replace(/(\s|\W)/g, "_");
1453 $("#gnewlistid").val(validid);
1454 // similarly with the backuplistid field
1455 validid = $("#gnewbackuplistid").val().replace(/(\s|\W)/g, "_");
1456 $("#gnewbackuplistid").val(validid);
1459 // submit the form to add a new field to a specific group
1460 $("#formaction").val("addgroup");
1461 mySubmit();
1464 // actually delete an entire group from the database
1465 var DeleteGroup = function(btnObj) {
1466 var parts = $(btnObj).attr("id");
1467 var groupname = parts.replace(/^\d+/, "");
1468 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+"'?")) {
1469 // submit the form to add a new field to a specific group
1470 $("#formaction").val("deletegroup");
1471 $("#deletegroupname").val(parts);
1472 $("#theform").submit();
1476 // just hide the new field DIV
1477 var CancelNewGroup = function(btnObj) {
1478 // hide the field details DIV
1479 $('#groupdetail').css('visibility', 'hidden');
1480 $('#groupdetail').css('display', 'none');
1481 // reset the new group values to a default
1482 $('#groupdetail > #newgroupname').val("");
1483 $("#save").attr("disabled", false);
1486 // display the 'new field' DIV
1487 var MoveGroup = function(btnObj) {
1488 if (!myChangeCheck()) return;
1489 var btnid = $(btnObj).attr("id");
1490 var parts = btnid.split("~");
1491 var groupid = parts[0];
1492 var direction = parts[1];
1493 // submit the form to change group order
1494 $("#formaction").val("movegroup");
1495 $("#movegroupname").val(groupid);
1496 $("#movedirection").val(direction);
1497 mySubmit();
1500 // show the rename group DIV
1501 var RenameGroup = function(btnObj) {
1502 if (!myChangeCheck()) return;
1503 $("#save").attr("disabled", true);
1504 $('#renamegroupdetail').css('visibility', 'visible');
1505 $('#renamegroupdetail').css('display', 'block');
1506 $(btnObj).parent().append($("#renamegroupdetail"));
1507 $('#renameoldgroupname').val($(btnObj).attr("id"));
1508 $('#renamegroupname').val($(btnObj).attr("id").replace(/^\d+/, ""));
1511 // save the new group to the form
1512 var SaveRenameGroup = function(btnObj) {
1513 // the group name field can only have letters, numbers, spaces and underscores
1514 // AND it cannot start with a number
1515 if ($("#renamegroupname").val().match(/^\d+/)) {
1516 alert("<?php xl('Group names cannot start with numbers.','e'); ?>");
1517 return false;
1519 var validname = $("#renamegroupname").val().replace(/[^A-za-z0-9 ]/g, "_"); // match any non-word characters and replace them
1520 $("#renamegroupname").val(validname);
1522 // submit the form to add a new field to a specific group
1523 $("#formaction").val("renamegroup");
1524 mySubmit();
1527 // just hide the new field DIV
1528 var CancelRenameGroup = function(btnObj) {
1529 // hide the field details DIV
1530 $('#renamegroupdetail').css('visibility', 'hidden');
1531 $('#renamegroupdetail').css('display', 'none');
1532 // reset the rename group values to a default
1533 $('#renameoldgroupname').val("");
1534 $('#renamegroupname').val("");
1537 /****************************************************/
1538 /************ Field functions ***********************/
1539 /****************************************************/
1541 // display the 'new field' DIV
1542 var AddField = function(btnObj) {
1543 if (!myChangeCheck()) return;
1544 $("#save").attr("disabled", true);
1545 // update the fieldgroup value to be the groupid
1546 var btnid = $(btnObj).attr("id");
1547 var parts = btnid.split("~");
1548 var groupid = parts[1];
1549 $('#fielddetail > #newfieldgroupid').attr('value', groupid);
1550 // show the field details DIV
1551 $('#fielddetail').css('visibility', 'visible');
1552 $('#fielddetail').css('display', 'block');
1553 $(btnObj).parent().append($("#fielddetail"));
1554 // Assign a sensible default sequence number.
1555 $('#newseq').val(getNextSeq(groupid));
1558 var DeleteFields = function(btnObj) {
1559 if (!myChangeCheck()) return;
1560 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'); ?>")) {
1561 var delim = "";
1562 $(".selectfield").each(function(i) {
1563 // build a list of selected field names to be moved
1564 if ($(this).attr("checked") == true) {
1565 var parts = this.id.split("~");
1566 var currval = $("#selectedfields").val();
1567 $("#selectedfields").val(currval+delim+parts[1]);
1568 delim = " ";
1571 // submit the form to delete the field(s)
1572 $("#formaction").val("deletefields");
1573 mySubmit();
1577 // save the new field to the form
1578 var SaveNewField = function(btnObj) {
1579 // check the new field values for correct formatting
1581 // seq must be numeric and less than 999
1582 if (! IsNumeric($("#newseq").val(), 0, 999)) {
1583 alert("<?php xl('Order must be a number between 1 and 999','e'); ?>");
1584 return false;
1586 // length must be numeric and less than 999
1587 if (! IsNumeric($("#newlengthWidth").val(), 0, 999)) {
1588 alert("<?php xl('Size must be a number between 1 and 999','e'); ?>");
1589 return false;
1591 // titlecols must be numeric and less than 100
1592 if (! IsNumeric($("#newtitlecols").val(), 0, 999)) {
1593 alert("<?php xl('LabelCols must be a number between 1 and 999','e'); ?>");
1594 return false;
1596 // datacols must be numeric and less than 100
1597 if (! IsNumeric($("#newdatacols").val(), 0, 999)) {
1598 alert("<?php xl('DataCols must be a number between 1 and 999','e'); ?>");
1599 return false;
1601 // some fields cannot be blank
1602 if ($("#newtitle").val() == "") {
1603 alert("<?php xl('Label cannot be blank','e'); ?>");
1604 return false;
1606 // the id field can only have letters, numbers and underscores
1607 var validid = $("#newid").val().replace(/(\s|\W)/g, "_"); // match any non-word characters and replace them
1608 $("#newid").val(validid);
1609 // similarly with the listid field
1610 validid = $("#newlistid").val().replace(/(\s|\W)/g, "_");
1611 $("#newlistid").val(validid);
1612 // similarly with the backuplistid field
1613 validid = $("#newbackuplistid").val().replace(/(\s|\W)/g, "_");
1614 $("#newbackuplistid").val(validid);
1616 // submit the form to add a new field to a specific group
1617 $("#formaction").val("addfield");
1618 mySubmit();
1621 // just hide the new field DIV
1622 var CancelNewField = function(btnObj) {
1623 // hide the field details DIV
1624 $('#fielddetail').css('visibility', 'hidden');
1625 $('#fielddetail').css('display', 'none');
1626 // reset the new field values to a default
1627 ResetNewFieldValues();
1628 $("#save").attr("disabled", false);
1631 // show the popup choice of lists
1632 var ShowLists = function(btnObj) {
1633 window.open("./show_lists_popup.php", "lists", "width=300,height=500,scrollbars=yes");
1634 selectedfield = btnObj;
1637 // show the popup choice of groups
1638 var ShowGroups = function(btnObj) {
1639 if (!myChangeCheck()) return;
1640 window.open("./show_groups_popup.php?layout_id=<?php echo $layout_id;?>", "groups", "width=300,height=300,scrollbars=yes");
1643 // Show context DD for NationNotes
1644 var ChangeList = function(btnObj){
1645 if(btnObj==34){
1646 $('#newlistid').hide();
1647 $('#contextName').show();
1649 else{
1650 $('#newlistid').show();
1651 $('#contextName').hide();
1654 var ChangeListg = function(btnObj){
1655 if(btnObj==34){
1656 $('#gnewlistid').hide();
1657 $('#gcontextName').show();
1659 else{
1660 $('#gnewlistid').show();
1661 $('#gcontextName').hide();
1665 // Initialize the list item selectors in skip conditions.
1666 var f = document.forms[0];
1667 for (var lino = 1; f['fld[' + lino + '][id]']; ++lino) {
1668 for (var seq = 0; f['fld[' + lino + '][condition_itemid][' + seq + ']']; ++seq) {
1669 setListItemOptions(lino, seq, true);
1673 // Support for beforeunload handler.
1674 $('tbody input, tbody select, tbody textarea').not('.selectfield').change(function() {
1675 somethingChanged = true;
1677 window.addEventListener("beforeunload", function (e) {
1678 if (somethingChanged && !top.timed_out) {
1679 var msg = "<?php echo xls('You have unsaved changes.'); ?>";
1680 e.returnValue = msg; // Gecko, Trident, Chrome 34+
1681 return msg; // Gecko, WebKit, Chrome <34
1687 function NationNotesContext(lineitem,val){
1688 if(val==34){
1689 document.getElementById("fld["+lineitem+"][contextName]").style.display='';
1690 document.getElementById("fld["+lineitem+"][list_id]").style.display='none';
1691 document.getElementById("fld["+lineitem+"][list_id]").value='';
1693 else{
1694 document.getElementById("fld["+lineitem+"][list_id]").style.display='';
1695 document.getElementById("fld["+lineitem+"][contextName]").style.display='none';
1696 document.getElementById("fld["+lineitem+"][list_id]").value='';
1700 function SetList(listid) {
1701 $(selectedfield).val(listid);
1704 //////////////////////////////////////////////////////////////////////
1705 // The following supports the field ID selection pop-up.
1706 //////////////////////////////////////////////////////////////////////
1708 var fieldselectfield;
1710 function elemFromPart(part) {
1711 var ename = fieldselectfield.name;
1712 // ename is like one of the following:
1713 // fld[$fld_line_no][id]
1714 // gnewid
1715 // newid
1716 // and "part" is what we substitute for the "id" part.
1717 var i = ename.lastIndexOf('id');
1718 ename = ename.substr(0, i) + part + ename.substr(i+2);
1719 return document.forms[0][ename];
1722 function FieldIDClicked(elem) {
1723 <?php if (substr($layout_id,0,3) == 'LBF') { ?>
1724 fieldselectfield = elem;
1725 var srcval = elemFromPart('source').value;
1726 // If the field ID is for the local form, allow direct entry.
1727 if (srcval == 'F') return;
1728 // Otherwise pop up the selection window.
1729 window.open('./field_id_popup.php?source=' + srcval, 'fields',
1730 'width=600,height=600,scrollbars=yes');
1731 <?php } ?>
1734 function SetField(field_id, title, data_type, uor, fld_length, max_length,
1735 list_id, titlecols, datacols, edit_options, description, fld_rows)
1737 fieldselectfield.value = field_id;
1738 elemFromPart('title' ).value = title;
1739 elemFromPart('datatype' ).value = data_type;
1740 elemFromPart('uor' ).value = uor;
1741 elemFromPart('lengthWidth' ).value = fld_length;
1742 elemFromPart('maxSize' ).value = max_length;
1743 elemFromPart('listid' ).value = list_id;
1744 elemFromPart('titlecols' ).value = titlecols;
1745 elemFromPart('datacols' ).value = datacols;
1746 elemFromPart('edit_options').value = edit_options;
1747 elemFromPart('desc' ).value = description;
1748 elemFromPart('lengthHeight').value = fld_rows;
1751 //////////////////////////////////////////////////////////////////////
1752 // End code for field ID selection pop-up.
1753 //////////////////////////////////////////////////////////////////////
1755 /* this is called after the user chooses a new group from the popup window
1756 * it will submit the page so the selected fields can be moved into
1757 * the target group
1759 function MoveFields(targetgroup) {
1760 $("#targetgroup").val(targetgroup);
1761 var delim = "";
1762 $(".selectfield").each(function(i) {
1763 // build a list of selected field names to be moved
1764 if ($(this).attr("checked") == true) {
1765 var parts = this.id.split("~");
1766 var currval = $("#selectedfields").val();
1767 $("#selectedfields").val(currval+delim+parts[1]);
1768 delim = " ";
1771 $("#formaction").val("movefields");
1772 mySubmit();
1775 // set the new-field values to a default state
1776 function ResetNewFieldValues () {
1777 $("#newseq").val("");
1778 $("#newsource").val("");
1779 $("#newid").val("");
1780 $("#newtitle").val("");
1781 $("#newuor").val(1);
1782 $("#newlengthWidth").val("");
1783 $("#newlengthHeight").val("");
1784 $("#newmaxSize").val("");
1785 $("#newdatatype").val("");
1786 $("#newlistid").val("");
1787 $("#newbackuplistid").val("");
1788 $("#newtitlecols").val("");
1789 $("#newdatacols").val("");
1790 $("#newedit_options").val("");
1791 $("#newdefault").val("");
1792 $("#newdesc").val("");
1795 // is value an integer and between min and max
1796 function IsNumeric(value, min, max) {
1797 if (value == "" || value == null) return false;
1798 if (! IsN(value) ||
1799 parseInt(value) < min ||
1800 parseInt(value) > max)
1801 return false;
1803 return true;
1806 /****************************************************/
1807 /****************************************************/
1808 /****************************************************/
1810 // tell if num is an Integer
1811 function IsN(num) { return !/\D/.test(num); }
1813 </script>
1815 </html>