Highway to PSR2
[openemr.git] / interface / super / edit_layout.php
blob9fab6af213514ce427374934b5dd7109063d942a
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']);
57 // array of the data_types of the fields
58 $datatypes = array(
59 "1" => xl("List box"),
60 "2" => xl("Textbox"),
61 "3" => xl("Textarea"),
62 "4" => xl("Text-date"),
63 "10" => xl("Providers"),
64 "11" => xl("Providers NPI"),
65 "12" => xl("Pharmacies"),
66 "13" => xl("Squads"),
67 "14" => xl("Organizations"),
68 "15" => xl("Billing codes"),
69 "16" => xl("Insurances"),
70 "18" => xl("Visit Categories"),
71 "21" => xl("Checkbox list"),
72 "22" => xl("Textbox list"),
73 "23" => xl("Exam results"),
74 "24" => xl("Patient allergies"),
75 "25" => xl("Checkbox w/text"),
76 "26" => xl("List box w/add"),
77 "27" => xl("Radio buttons"),
78 "28" => xl("Lifestyle status"),
79 "31" => xl("Static Text"),
80 "32" => xl("Smoking Status"),
81 "33" => xl("Race and Ethnicity"),
82 "34" => xl("NationNotes"),
83 "35" => xl("Facilities"),
84 "36" => xl("Multiple Select List"),
85 "40" => xl("Image canvas"),
88 $sources = array(
89 'F' => xl('Form'),
90 'D' => xl('Patient'),
91 'H' => xl('History'),
92 'E' => xl('Visit'),
93 'V' => xl('VisForm'),
96 function nextGroupOrder($order)
98 if ($order == '9') {
99 $order = 'A';
100 } else if ($order == 'Z') {
101 $order = 'a';
102 } else {
103 $order = chr(ord($order) + 1);
106 return $order;
109 // Call this when adding or removing a layout field. This will create or drop
110 // the corresponding table column when appropriate. Table columns are not
111 // dropped if they contain any non-empty values.
112 function addOrDeleteColumn($layout_id, $field_id, $add = true)
114 if (substr($layout_id, 0, 3) == 'LBF' || substr($layout_id, 0, 3) == 'LBT' || $layout_id == "FACUSR") {
115 return;
118 if ($layout_id == "DEM") {
119 $tablename = "patient_data";
120 } else if ($layout_id == "HIS") {
121 $tablename = "history_data";
122 } else if ($layout_id == "SRH") {
123 $tablename = "lists_ippf_srh";
124 } else if ($layout_id == "CON") {
125 $tablename = "lists_ippf_con";
126 } else if ($layout_id == "GCA") {
127 $tablename = "lists_ippf_gcac";
128 } else {
129 die('Internal error in addOrDeleteColumn()');
132 // Check if the column currently exists.
133 $tmp = sqlQuery("SHOW COLUMNS FROM `$tablename` LIKE '$field_id'");
134 $column_exists = !empty($tmp);
136 if ($add && !$column_exists) {
137 sqlStatement("ALTER TABLE `$tablename` ADD `$field_id` TEXT");
138 newEvent(
139 "alter_table",
140 $_SESSION['authUser'],
141 $_SESSION['authProvider'],
143 "$tablename ADD $field_id"
145 } else if (!$add && $column_exists) {
146 // Do not drop a column that has any data.
147 $tmp = sqlQuery("SELECT `$field_id` FROM `$tablename` WHERE " .
148 "`$field_id` IS NOT NULL AND `$field_id` != '' LIMIT 1");
149 if (!isset($tmp['field_id'])) {
150 sqlStatement("ALTER TABLE `$tablename` DROP `$field_id`");
151 newEvent(
152 "alter_table",
153 $_SESSION['authUser'],
154 $_SESSION['authProvider'],
156 "$tablename DROP $field_id "
162 // Check authorization.
163 $thisauth = acl_check('admin', 'super');
164 if (!$thisauth) {
165 die(xl('Not authorized'));
168 // The layout ID identifies the layout to be edited.
169 $layout_id = empty($_REQUEST['layout_id']) ? '' : $_REQUEST['layout_id'];
171 // Tag style for stuff to hide if not an LBF layout. Currently just for the Source column.
172 $lbfonly = substr($layout_id, 0, 3) == 'LBF' ? "" : "style='display:none;'";
174 // Handle the Form actions
176 if ($_POST['formaction'] == "save" && $layout_id) {
177 // If we are saving, then save.
178 $fld = $_POST['fld'];
179 for ($lino = 1; isset($fld[$lino]['id']); ++$lino) {
180 $iter = $fld[$lino];
181 $field_id = formTrim($iter['id']);
182 $data_type = formTrim($iter['data_type']);
183 $listval = $data_type == 34 ? formTrim($iter['contextName']) : formTrim($iter['list_id']);
185 // Skip conditions for the line are stored as a serialized array.
186 $condarr = array();
187 for ($cix = 0; !empty($iter['condition_id'][$cix]); ++$cix) {
188 $andor = empty($iter['condition_andor'][$cix]) ? '' : $iter['condition_andor'][$cix];
189 $condarr[$cix] = array(
190 'id' => strip_escape_custom($iter['condition_id' ][$cix]),
191 'itemid' => strip_escape_custom($iter['condition_itemid' ][$cix]),
192 'operator' => strip_escape_custom($iter['condition_operator'][$cix]),
193 'value' => strip_escape_custom($iter['condition_value' ][$cix]),
194 'andor' => strip_escape_custom($andor),
198 $conditions = empty($condarr) ? '' : serialize($condarr);
199 if ($field_id) {
200 sqlStatement("UPDATE layout_options SET " .
201 "source = '" . formTrim($iter['source']) . "', " .
202 "title = '" . formTrim($iter['title']) . "', " .
203 "group_name = '" . formTrim($iter['group']) . "', " .
204 "seq = '" . formTrim($iter['seq']) . "', " .
205 "uor = '" . formTrim($iter['uor']) . "', " .
206 "fld_length = '" . formTrim($iter['lengthWidth']) . "', " .
207 "fld_rows = '" . formTrim($iter['lengthHeight']) . "', " .
208 "max_length = '" . formTrim($iter['maxSize']) . "', " .
209 "titlecols = '" . formTrim($iter['titlecols']) . "', " .
210 "datacols = '" . formTrim($iter['datacols']) . "', " .
211 "data_type= '$data_type', " .
212 "list_id= '" . $listval . "', " .
213 "list_backup_id= '" . formTrim($iter['list_backup_id']) . "', " .
214 "edit_options = '" . formTrim($iter['edit_options']) . "', " .
215 "default_value = '" . formTrim($iter['default']) . "', " .
216 "description = '" . formTrim($iter['desc']) . "', " .
217 "conditions = '" . add_escape_custom($conditions) . "', " .
218 "validation = '" . formTrim($iter['validation']) . "' " .
219 "WHERE form_id = '$layout_id' AND field_id = '$field_id'");
222 } else if ($_POST['formaction'] == "addfield" && $layout_id) {
223 // Add a new field to a specific group
224 $data_type = formTrim($_POST['newdatatype']);
225 $max_length = $data_type == 3 ? 3 : 255;
226 $listval = $data_type == 34 ? formTrim($_POST['contextName']) : formTrim($_POST['newlistid']);
227 sqlStatement("INSERT INTO layout_options (" .
228 " form_id, source, field_id, title, group_name, seq, uor, fld_length, fld_rows" .
229 ", titlecols, datacols, data_type, edit_options, default_value, description" .
230 ", max_length, list_id, list_backup_id " .
231 ") VALUES ( " .
232 "'" . formTrim($_POST['layout_id']) . "'" .
233 ",'" . formTrim($_POST['newsource']) . "'" .
234 ",'" . formTrim($_POST['newid']) . "'" .
235 ",'" . formTrim($_POST['newtitle']) . "'" .
236 ",'" . formTrim($_POST['newfieldgroupid']) . "'" .
237 ",'" . formTrim($_POST['newseq']) . "'" .
238 ",'" . formTrim($_POST['newuor']) . "'" .
239 ",'" . formTrim($_POST['newlengthWidth']) . "'" .
240 ",'" . formTrim($_POST['newlengthHeight']) . "'" .
241 ",'" . formTrim($_POST['newtitlecols']) . "'" .
242 ",'" . formTrim($_POST['newdatacols']) . "'" .
243 ",'$data_type'" .
244 ",'" . formTrim($_POST['newedit_options']) . "'" .
245 ",'" . formTrim($_POST['newdefault']) . "'" .
246 ",'" . formTrim($_POST['newdesc']) . "'" .
247 ",'" . formTrim($_POST['newmaxSize']) . "'" .
248 ",'" . $listval . "'" .
249 ",'" . formTrim($_POST['newbackuplistid']) . "'" .
250 " )");
251 addOrDeleteColumn($layout_id, formTrim($_POST['newid']), true);
252 } else if ($_POST['formaction'] == "movefields" && $layout_id) {
253 // Move field(s) to a new group in the layout
254 $sqlstmt = "UPDATE layout_options SET ".
255 " group_name='". $_POST['targetgroup']."' ".
256 " WHERE ".
257 " form_id = '".$_POST['layout_id']."' ".
258 " AND field_id IN (";
259 $comma = "";
260 foreach (explode(" ", $_POST['selectedfields']) as $onefield) {
261 $sqlstmt .= $comma."'".$onefield."'";
262 $comma = ", ";
265 $sqlstmt .= ")";
266 //echo $sqlstmt;
267 sqlStatement($sqlstmt);
268 } else if ($_POST['formaction'] == "deletefields" && $layout_id) {
269 // Delete a field from a specific group
270 $sqlstmt = "DELETE FROM layout_options WHERE ".
271 " form_id = '".$_POST['layout_id']."' ".
272 " AND field_id IN (";
273 $comma = "";
274 foreach (explode(" ", $_POST['selectedfields']) as $onefield) {
275 $sqlstmt .= $comma."'".$onefield."'";
276 $comma = ", ";
279 $sqlstmt .= ")";
280 sqlStatement($sqlstmt);
281 foreach (explode(" ", $_POST['selectedfields']) as $onefield) {
282 addOrDeleteColumn($layout_id, $onefield, false);
284 } else if ($_POST['formaction'] == "addgroup" && $layout_id) {
285 // all group names are prefixed with a number indicating their display order
286 // this new group is prefixed with the net highest number given the
287 // layout_id
288 $results = sqlStatement("select distinct(group_name) as gname ".
289 " from layout_options where ".
290 " form_id = '".$_POST['layout_id']."'");
291 $maxnum = '1';
292 while ($result = sqlFetchArray($results)) {
293 $tmp = substr($result['gname'], 0, 1);
294 if ($tmp >= $maxnum) {
295 $maxnum = nextGroupOrder($tmp);
299 $data_type = formTrim($_POST['gnewdatatype']);
300 $max_length = $data_type == 3 ? 3 : 255;
301 $listval = $data_type == 34 ? formTrim($_POST['gcontextName']) : formTrim($_POST['gnewlistid']);
302 // add a new group to the layout, with the defined field
303 sqlStatement("INSERT INTO layout_options (" .
304 " form_id, source, field_id, title, group_name, seq, uor, fld_length, fld_rows" .
305 ", titlecols, datacols, data_type, edit_options, default_value, description" .
306 ", max_length, list_id, list_backup_id " .
307 ") VALUES ( " .
308 "'" . formTrim($_POST['layout_id']) . "'" .
309 ",'" . formTrim($_POST['gnewsource']) . "'" .
310 ",'" . formTrim($_POST['gnewid']) . "'" .
311 ",'" . formTrim($_POST['gnewtitle']) . "'" .
312 ",'" . formTrim($maxnum . $_POST['newgroupname']) . "'" .
313 ",'" . formTrim($_POST['gnewseq']) . "'" .
314 ",'" . formTrim($_POST['gnewuor']) . "'" .
315 ",'" . formTrim($_POST['gnewlengthWidth']) . "'" .
316 ",'" . formTrim($_POST['gnewlengthHeight']) . "'" .
317 ",'" . formTrim($_POST['gnewtitlecols']) . "'" .
318 ",'" . formTrim($_POST['gnewdatacols']) . "'" .
319 ",'$data_type'" .
320 ",'" . formTrim($_POST['gnewedit_options']) . "'" .
321 ",'" . formTrim($_POST['gnewdefault']) . "'" .
322 ",'" . formTrim($_POST['gnewdesc']) . "'" .
323 ",'" . formTrim($_POST['gnewmaxSize']) . "'" .
324 ",'" . $listval . "'" .
325 ",'" . formTrim($_POST['gnewbackuplistid']) . "'" .
326 " )");
327 addOrDeleteColumn($layout_id, formTrim($_POST['gnewid']), true);
328 } else if ($_POST['formaction'] == "deletegroup" && $layout_id) {
329 // drop the fields from the related table (this is critical)
330 $res = sqlStatement("SELECT field_id FROM layout_options WHERE " .
331 "form_id = '" . $_POST['layout_id'] . "' ".
332 "AND group_name = '" . $_POST['deletegroupname'] . "'");
333 while ($row = sqlFetchArray($res)) {
334 addOrDeleteColumn($layout_id, $row['field_id'], false);
337 // Delete an entire group from the form
338 sqlStatement("DELETE FROM layout_options WHERE ".
339 " form_id = '".$_POST['layout_id']."' ".
340 " AND group_name = '".$_POST['deletegroupname']."'");
341 } else if ($_POST['formaction'] == "movegroup" && $layout_id) {
342 $results = sqlStatement("SELECT DISTINCT(group_name) AS gname " .
343 "FROM layout_options WHERE form_id = '$layout_id' " .
344 "ORDER BY gname");
345 $garray = array();
346 $i = 0;
347 while ($result = sqlFetchArray($results)) {
348 if ($result['gname'] == $_POST['movegroupname']) {
349 if ($_POST['movedirection'] == 'up') { // moving up
350 if ($i > 0) {
351 $garray[$i] = $garray[$i - 1];
352 $garray[$i - 1] = $result['gname'];
353 $i++;
354 } else {
355 $garray[$i++] = $result['gname'];
357 } else { // moving down
358 $garray[$i++] = '';
359 $garray[$i++] = $result['gname'];
361 } else if ($i > 1 && $garray[$i - 2] == '') {
362 $garray[$i - 2] = $result['gname'];
363 } else {
364 $garray[$i++] = $result['gname'];
368 $nextord = '1';
369 foreach ($garray as $value) {
370 if ($value === '') {
371 continue;
374 $newname = $nextord . substr($value, 1);
375 sqlStatement("UPDATE layout_options SET " .
376 "group_name = '$newname' WHERE " .
377 "form_id = '$layout_id' AND " .
378 "group_name = '$value'");
379 $nextord = nextGroupOrder($nextord);
381 } else if ($_POST['formaction'] == "renamegroup" && $layout_id) {
382 $currpos = substr($_POST['renameoldgroupname'], 0, 1);
383 // update the database rows
384 sqlStatement("UPDATE layout_options SET " .
385 "group_name = '" . $currpos . $_POST['renamegroupname'] . "' ".
386 "WHERE form_id = '$layout_id' AND ".
387 "group_name = '" . $_POST['renameoldgroupname'] . "'");
390 // Get the selected form's elements.
391 if ($layout_id) {
392 $res = sqlStatement("SELECT * FROM layout_options WHERE " .
393 "form_id = '$layout_id' ORDER BY group_name, seq");
396 // global counter for field numbers
397 $fld_line_no = 0;
399 $extra_html = '';
401 // This is called to generate a select option list for fields within this form.
402 // Used for selecting a field for testing in a skip condition.
404 function genFieldOptionList($current = '')
406 global $layout_id;
407 $option_list = "<option value=''>-- " . xlt('Please Select') . " --</option>";
408 if ($layout_id) {
409 $query = "SELECT field_id FROM layout_options WHERE form_id = ? ORDER BY group_name, seq";
410 $res = sqlStatement($query, array($layout_id));
411 while ($row = sqlFetchArray($res)) {
412 $field_id = $row['field_id'];
413 $option_list .= "<option value='" . attr($field_id) . "'";
414 if ($field_id == $current) {
415 $option_list .= " selected";
418 $option_list .= ">" . text($field_id) . "</option>";
422 return $option_list;
425 // Write one option line to the form.
427 function writeFieldLine($linedata)
429 global $fld_line_no, $sources, $lbfonly, $extra_html,$validations;
430 ++$fld_line_no;
431 $checked = $linedata['default_value'] ? " checked" : "";
433 //echo " <tr bgcolor='$bgcolor'>\n";
434 echo " <tr id='fld[$fld_line_no]' class='".($fld_line_no % 2 ? 'even' : 'odd')."'>\n";
436 echo " <td class='optcell' style='width:4%' nowrap>";
437 // tuck the group_name INPUT in here
438 echo "<input type='hidden' name='fld[$fld_line_no][group]' value='" .
439 htmlspecialchars($linedata['group_name'], ENT_QUOTES) . "' class='optin' />";
441 echo "<input type='checkbox' class='selectfield' ".
442 "name='".$linedata['group_name']."~".$linedata['field_id']."' ".
443 "id='".$linedata['group_name']."~".$linedata['field_id']."' ".
444 "title='".htmlspecialchars(xl('Select field', ENT_QUOTES))."'>";
446 echo "<input type='text' name='fld[$fld_line_no][seq]' id='fld[$fld_line_no][seq]' value='" .
447 htmlspecialchars($linedata['seq'], ENT_QUOTES) . "' size='2' maxlength='3' " .
448 "class='optin' style='width:36pt' />";
449 echo "</td>\n";
451 echo " <td align='center' class='optcell' $lbfonly style='width:3%'>";
452 echo "<select name='fld[$fld_line_no][source]' class='optin noselect' $lbfonly>";
453 foreach ($sources as $key => $value) {
454 echo "<option value='" . attr($key) . "'";
455 if ($key == $linedata['source']) {
456 echo " selected";
459 echo ">" . text($value) . "</option>\n";
462 echo "</select>";
463 echo "</td>\n";
465 echo " <td align='left' class='optcell' style='width:10%'>";
466 echo "<input type='text' name='fld[$fld_line_no][id]' value='" .
467 htmlspecialchars($linedata['field_id'], ENT_QUOTES) . "' size='15' maxlength='63'
468 class='optin noselect' style='width:100%' />";
469 // class='optin noselect' onclick='FieldIDClicked(this)' />";
471 echo "<input type='hidden' name='fld[$fld_line_no][id]' value='" .
472 htmlspecialchars($linedata['field_id'], ENT_QUOTES) . "' />";
473 echo htmlspecialchars($linedata['field_id'], ENT_QUOTES);
475 echo "</td>\n";
477 echo " <td align='center' class='optcell' style='width:12%'>";
478 echo "<input type='text' id='fld[$fld_line_no][title]' name='fld[$fld_line_no][title]' value='" .
479 htmlspecialchars($linedata['title'], ENT_QUOTES) . "' size='15' maxlength='63' class='optin' style='width:100%' />";
480 echo "</td>\n";
482 // if not english and set to translate layout labels, then show the translation
483 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
484 echo "<td align='center' class='translation' style='width:10%'>" . htmlspecialchars(xl($linedata['title']), ENT_QUOTES) . "</td>\n";
487 echo " <td align='center' class='optcell' style='width:4%'>";
488 echo "<select name='fld[$fld_line_no][uor]' class='optin'>";
489 foreach (array(0 =>xl('Unused'), 1 =>xl('Optional'), 2 =>xl('Required')) as $key => $value) {
490 echo "<option value='$key'";
491 if ($key == $linedata['uor']) {
492 echo " selected";
495 echo ">$value</option>\n";
498 echo "</select>";
499 echo "</td>\n";
501 echo " <td align='center' class='optcell' style='width:8%'>";
502 echo "<select name='fld[$fld_line_no][data_type]' id='fld[$fld_line_no][data_type]' onchange=NationNotesContext('".$fld_line_no."',this.value)>";
503 echo "<option value=''></option>";
504 global $datatypes;
505 foreach ($datatypes as $key => $value) {
506 if ($linedata['data_type'] == $key) {
507 echo "<option value='$key' selected>$value</option>";
508 } else {
509 echo "<option value='$key'>$value</option>";
513 echo "</select>";
514 echo " </td>";
516 echo " <td align='center' class='optcell' style='width:4%'>";
517 if ($linedata['data_type'] == 2 || $linedata['data_type'] == 3 ||
518 $linedata['data_type'] == 21 || $linedata['data_type'] == 22 ||
519 $linedata['data_type'] == 23 || $linedata['data_type'] == 25 ||
520 $linedata['data_type'] == 27 || $linedata['data_type'] == 28 ||
521 $linedata['data_type'] == 32 || $linedata['data_type'] == 15 ||
522 $linedata['data_type'] == 40
524 // Show the width field
525 echo "<input type='text' name='fld[$fld_line_no][lengthWidth]' value='" .
526 htmlspecialchars($linedata['fld_length'], ENT_QUOTES) .
527 "' size='2' maxlength='10' class='optin' title='" . xla('Width') . "' />";
528 if ($linedata['data_type'] == 3 || $linedata['data_type'] == 40) {
529 // Show the height field
530 echo "<input type='text' name='fld[$fld_line_no][lengthHeight]' value='" .
531 htmlspecialchars($linedata['fld_rows'], ENT_QUOTES) .
532 "' size='2' maxlength='10' class='optin' title='" . xla('Height') . "' />";
533 } else {
534 // Hide the height field
535 echo "<input type='hidden' name='fld[$fld_line_no][lengthHeight]' value=''>";
537 } else {
538 // all other data_types (hide both the width and height fields
539 echo "<input type='hidden' name='fld[$fld_line_no][lengthWidth]' value=''>";
540 echo "<input type='hidden' name='fld[$fld_line_no][lengthHeight]' value=''>";
543 echo "</td>\n";
545 echo " <td align='center' class='optcell' style='width:4%'>";
546 echo "<input type='text' name='fld[$fld_line_no][maxSize]' value='" .
547 htmlspecialchars($linedata['max_length'], ENT_QUOTES) .
548 "' size='1' maxlength='10' class='optin' style='width:100%' " .
549 "title='" . xla('Maximum Size (entering 0 will allow any size)') . "' />";
550 echo "</td>\n";
552 echo " <td align='center' class='optcell' style='width:8%'>";
553 if ($linedata['data_type'] == 1 || $linedata['data_type'] == 21 ||
554 $linedata['data_type'] == 22 || $linedata['data_type'] == 23 ||
555 $linedata['data_type'] == 25 || $linedata['data_type'] == 26 ||
556 $linedata['data_type'] == 27 || $linedata['data_type'] == 32 ||
557 $linedata['data_type'] == 33 || $linedata['data_type'] == 34 ||
558 $linedata['data_type'] == 36) {
559 $type = "";
560 $disp = "style='display:none'";
561 if ($linedata['data_type'] == 34) {
562 $type = "style='display:none'";
563 $disp = "";
566 echo "<input type='text' name='fld[$fld_line_no][list_id]' id='fld[$fld_line_no][list_id]' value='" .
567 htmlspecialchars($linedata['list_id'], ENT_QUOTES) . "'".$type.
568 " size='6' maxlength='30' class='optin listid' style='width:100%;cursor:pointer'".
569 "title='". xl('Choose list') . "' />";
571 echo "<select name='fld[$fld_line_no][contextName]' id='fld[$fld_line_no][contextName]' ".$disp.">";
572 $res = sqlStatement("SELECT * FROM customlists WHERE cl_list_type=2 AND cl_deleted=0");
573 while ($row = sqlFetchArray($res)) {
574 $sel = '';
575 if ($linedata['list_id'] == $row['cl_list_item_long']) {
576 $sel = 'selected';
579 echo "<option value='".htmlspecialchars($row['cl_list_item_long'], ENT_QUOTES)."' ".$sel.">".htmlspecialchars($row['cl_list_item_long'], ENT_QUOTES)."</option>";
582 echo "</select>";
583 } else {
584 // all other data_types
585 echo "<input type='hidden' name='fld[$fld_line_no][list_id]' value=''>";
588 echo "</td>\n";
590 //Backup List Begin
591 echo " <td align='center' class='optcell' style='width:4%'>";
592 if ($linedata['data_type'] == 1 || $linedata['data_type'] == 26 ||
593 $linedata['data_type'] == 33 || $linedata['data_type'] == 36) {
594 echo "<input type='text' name='fld[$fld_line_no][list_backup_id]' value='" .
595 htmlspecialchars($linedata['list_backup_id'], ENT_QUOTES) .
596 "' size='3' maxlength='10' class='optin listid' style='cursor:pointer; width:100%' />";
597 } else {
598 echo "<input type='hidden' name='fld[$fld_line_no][list_backup_id]' value=''>";
601 echo "</td>\n";
602 //Backup List End
604 echo " <td align='center' class='optcell' style='width:4%'>";
605 echo "<input type='text' name='fld[$fld_line_no][titlecols]' value='" .
606 htmlspecialchars($linedata['titlecols'], ENT_QUOTES) . "' size='3' maxlength='10' class='optin' style='width:100%' />";
607 echo "</td>\n";
609 echo " <td align='center' class='optcell' style='width:4%'>";
610 echo "<input type='text' name='fld[$fld_line_no][datacols]' value='" .
611 htmlspecialchars($linedata['datacols'], ENT_QUOTES) . "' size='3' maxlength='10' class='optin' style='width:100%' />";
612 echo "</td>\n";
614 echo " <td align='center' class='optcell' style='width:5%' title='" .
615 "A = " . xla('Age') .
616 ", B = " . xla('Gestational Age') .
617 ", C = " . xla('Capitalize') .
618 ", D = " . xla('Dup Check') .
619 ", E = " . xla('Dup Check on only Edit') .
620 ", W = " . xla('Dup Check on only New') .
621 ", G = " . xla('Graphable') .
622 ", L = " . xla('Lab Order') .
623 ", N = " . xla('New Patient Form') .
624 ", O = " . xla('Order Processor') .
625 ", P = " . xla('Default to previous value') .
626 ", R = " . xla('Distributor') .
627 ", T = " . xla('Description is default text') .
628 ", U = " . xla('Capitalize all') .
629 ", V = " . xla('Vendor') .
630 ", 0 = " . xla('Read Only') .
631 ", 1 = " . xla('Write Once') .
632 ", 2 = " . xla('Billing Code Descriptions') .
634 "'>";
635 echo "<input type='text' name='fld[$fld_line_no][edit_options]' value='" .
636 htmlspecialchars($linedata['edit_options'], ENT_QUOTES) . "' size='3' " .
637 "maxlength='36' class='optin' style='width:100%' />";
638 echo "</td>\n";
640 /*****************************************************************
641 echo " <td align='center' class='optcell'>";
642 if ($linedata['data_type'] == 2) {
643 echo "<input type='text' name='fld[$fld_line_no][default]' value='" .
644 htmlspecialchars($linedata['default_value'], ENT_QUOTES) . "' size='10' maxlength='63' class='optin' />";
645 } else {
646 echo "&nbsp;";
648 echo "</td>\n";
650 echo " <td align='center' class='optcell'>";
651 echo "<input type='text' name='fld[$fld_line_no][desc]' value='" .
652 htmlspecialchars($linedata['description'], ENT_QUOTES) . "' size='20' maxlength='63' class='optin' />";
653 echo "</td>\n";
655 // if not english and showing layout labels, then show the translation of Description
656 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
657 echo "<td align='center' class='translation'>" . htmlspecialchars(xl($linedata['description']), ENT_QUOTES) . "</td>\n";
659 *****************************************************************/
661 if ($linedata['data_type'] == 31) {
662 echo " <td align='center' class='optcell' style='width:24%'>";
663 echo "<textarea name='fld[$fld_line_no][desc]' rows='3' cols='35' class='optin' style='width:100%'>" .
664 $linedata['description'] . "</textarea>";
665 echo "<input type='hidden' name='fld[$fld_line_no][default]' value='" .
666 htmlspecialchars($linedata['default_value'], ENT_QUOTES) . "' />";
667 echo "</td>\n";
668 } else {
669 echo " <td align='center' class='optcell' style='width:24%'>";
670 echo "<input type='text' name='fld[$fld_line_no][desc]' value='" .
671 htmlspecialchars($linedata['description'], ENT_QUOTES) .
672 "' size='30' class='optin' style='width:100%' />";
673 echo "<input type='hidden' name='fld[$fld_line_no][default]' value='" .
674 htmlspecialchars($linedata['default_value'], ENT_QUOTES) . "' />";
675 echo "</td>\n";
676 // if not english and showing layout labels, then show the translation of Description
677 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
678 echo "<td align='center' class='translation' style='width:10%'>" .
679 htmlspecialchars(xl($linedata['description']), ENT_QUOTES) . "</td>\n";
683 // The "?" to click on for yet more field attributes.
684 echo " <td class='bold' id='querytd_$fld_line_no' style='cursor:pointer;";
685 if (!empty($linedata['conditions']) || !empty($linedata['validation'])) {
686 echo "background-color:#77ff77;";
689 echo "' onclick='extShow($fld_line_no, this)' align='center' ";
690 echo "title='" . xla('Click here to view/edit more details') . "'>";
691 echo "&nbsp;?&nbsp;";
692 echo "</td>\n";
694 echo " </tr>\n";
696 // Create a floating div for the additional attributes of this field.
697 $conditions = empty($linedata['conditions']) ?
698 array(0 => array('id' => '', 'itemid' => '', 'operator' => '', 'value' => '')) :
699 unserialize($linedata['conditions']);
701 $extra_html .= "<div id='ext_$fld_line_no' " .
702 "style='position:absolute;width:750px;border:1px solid black;" .
703 "padding:2px;background-color:#cccccc;visibility:hidden;" .
704 "z-index:1000;left:-1000px;top:0px;font-size:9pt;'>\n" .
705 "<table width='100%'>\n" .
706 " <tr>\n" .
707 " <th colspan='3' align='left' class='bold'>\"" . text($linedata['field_id']) . "\" " .
708 xlt('will be hidden if') . ":</th>\n" .
709 " <th colspan='2' align='right' class='text'><input type='button' " .
710 "value='" . xla('Close') . "' onclick='extShow($fld_line_no, false)' />&nbsp;</th>\n" .
711 " </tr>\n" .
712 " <tr>\n" .
713 " <th align='left' class='bold'>" . xlt('Field ID') . "</th>\n" .
714 " <th align='left' class='bold'>" . xlt('List item ID') . "</th>\n" .
715 " <th align='left' class='bold'>" . xlt('Operator') . "</th>\n" .
716 " <th align='left' class='bold'>" . xlt('Value if comparing') . "</th>\n" .
717 " <th align='left' class='bold'>&nbsp;</th>\n" .
718 " </tr>\n";
719 // There may be multiple condition lines for each field.
720 foreach ($conditions as $i => $condition) {
721 $extra_html .=
722 " <tr>\n" .
723 " <td align='left'>\n" .
724 " <select name='fld[$fld_line_no][condition_id][$i]' onchange='cidChanged($fld_line_no, $i)'>" .
725 genFieldOptionList($condition['id']) . " </select>\n" .
726 " </td>\n" .
727 " <td align='left'>\n" .
728 // List item choices are populated on the client side but will need the current value,
729 // so we insert a temporary option here to hold that value.
730 " <select name='fld[$fld_line_no][condition_itemid][$i]'><option value='" .
731 attr($condition['itemid']) . "'>...</option></select>\n" .
732 " </td>\n" .
733 " <td align='left'>\n" .
734 " <select name='fld[$fld_line_no][condition_operator][$i]'>\n";
735 foreach (array(
736 'eq' => xl('Equals'),
737 'ne' => xl('Does not equal'),
738 'se' => xl('Is selected'),
739 'ns' => xl('Is not selected'),
740 ) as $key => $value) {
741 $extra_html .= " <option value='$key'";
742 if ($key == $condition['operator']) {
743 $extra_html .= " selected";
746 $extra_html .= ">" . text($value) . "</option>\n";
749 $extra_html .=
750 " </select>\n" .
751 " </td>\n" .
752 " <td align='left' title='" . xla('Only for comparisons') . "'>\n" .
753 " <input type='text' name='fld[$fld_line_no][condition_value][$i]' value='" .
754 attr($condition['value']) . "' size='15' maxlength='63' />\n" .
755 " </td>\n";
756 if (count($conditions) == $i + 1) {
757 $extra_html .=
758 " <td align='right' title='" . xla('Add a condition') . "'>\n" .
759 " <input type='button' value='+' onclick='extAddCondition($fld_line_no,this)' />\n" .
760 " </td>\n";
761 } else {
762 $extra_html .=
763 " <td align='right'>\n" .
764 " <select name='fld[$fld_line_no][condition_andor][$i]'>\n";
765 foreach (array(
766 'and' => xl('And'),
767 'or' => xl('Or'),
768 ) as $key => $value) {
769 $extra_html .= " <option value='$key'";
770 if ($key == $condition['andor']) {
771 $extra_html .= " selected";
774 $extra_html .= ">" . text($value) . "</option>\n";
777 $extra_html .=
778 " </select>\n" .
779 " </td>\n";
782 $extra_html .=
783 " </tr>\n";
786 $extra_html .=
787 "</table>\n";
789 $extra_html .= "<table width='100%'>\n" .
790 " <tr>\n" .
791 " <td colspan='3' align='left' class='bold'>\"" . text($linedata['field_id']) . "\" " .
792 xlt('will have the following validation rules') . ":</td>\n" .
793 " </tr>\n" .
794 " <tr>\n" .
795 " <td align='left' class='bold'>" . xlt('Validation rule') . " </td>\n" .
796 " </tr>\n".
797 " <tr>\n" .
798 " <td align='left' title='" . xla('Select a validation rule') . "'>\n" .
801 " <select name='fld[$fld_line_no][validation]' onchange='valChanged($fld_line_no)'>\n" .
802 " <option value=''";
803 if (empty($linedata['validation'])) {
804 $extra_html .= " selected";
807 $extra_html .= ">-- " . xlt('Please Select') . " --</option>";
808 foreach ($validations as $key => $value) {
809 $extra_html .= " <option value='$key'";
810 if ($key == $linedata['validation']) {
811 $extra_html .= " selected";
814 $extra_html .= ">" . text($value) . "</option>\n";
817 $extra_html .="</select>\n" .
818 " </td>\n";
820 $extra_html .=
821 "</table>\n" .
822 "</div>\n";
825 <html>
827 <head>
828 <?php html_header_show();?>
830 <!-- supporting javascript code -->
831 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-2-2/index.js"></script>
833 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
835 <title><?php xl('Layout Editor', 'e'); ?></title>
837 <style>
838 tr.head { font-size:10pt; background-color:#cccccc; }
839 tr.detail { font-size:10pt; }
840 td { font-size:10pt; }
841 input { font-size:10pt; }
842 a, a:visited, a:hover { color:#0000cc; }
843 .optcell { }
844 .optin { background: transparent; }
845 .group {
846 margin: 0pt 0pt 8pt 0pt;
847 padding :0pt;
848 width: 100%;
851 .group table {
852 border-collapse: collapse;
853 width: 100%;
856 .odd td {
857 background-color: #ddddff;
858 padding: 3px 0px 3px 0px;
860 .even td {
861 background-color: #ffdddd;
862 padding: 3px 0px 3px 0px;
864 .help { cursor: help; }
865 .layouts_title { font-size: 110%; }
866 .translation {
867 color: green;
868 font-size:10pt;
870 .highlight * {
871 border: 2px solid blue;
872 background-color: yellow;
873 color: black;
876 </style>
878 <script language="JavaScript">
880 // Helper functions for positioning the floating divs.
881 function extGetX(elem) {
882 var x = 0;
883 while(elem != null) {
884 x += elem.offsetLeft;
885 elem = elem.offsetParent;
887 return x;
889 function extGetY(elem) {
890 var y = 0;
891 while(elem != null) {
892 y += elem.offsetTop;
893 elem = elem.offsetParent;
895 return y;
898 // Show or hide the "extras" div for a row.
899 var extdiv = null;
900 function extShow(lino, show) {
901 var thisdiv = document.getElementById("ext_" + lino);
902 if (extdiv) {
903 extdiv.style.visibility = 'hidden';
904 extdiv.style.left = '-1000px';
905 extdiv.style.top = '0px';
907 if (show && thisdiv != extdiv) {
908 extdiv = thisdiv;
909 var dw = window.innerWidth ? window.innerWidth - 20 : document.body.clientWidth;
910 x = dw - extdiv.offsetWidth;
911 if (x < 0) x = 0;
912 var y = extGetY(show) + show.offsetHeight;
913 extdiv.style.left = x;
914 extdiv.style.top = y;
915 extdiv.style.visibility = 'visible';
917 else {
918 extdiv = null;
922 // Add an extra condition line for the given row.
923 function extAddCondition(lino, btnelem) {
924 var f = document.forms[0];
925 var i = 0;
927 // Get index of next condition line.
928 while (f['fld[' + lino + '][condition_id][' + i + ']']) ++i;
929 if (i == 0) alert('f["fld[' + lino + '][condition_id][' + i + ']"] <?php echo xls('not found') ?>');
931 // Get containing <td>, <tr> and <table> nodes of the "+" button.
932 var tdplus = btnelem.parentNode;
933 var trelem = tdplus.parentNode;
934 var telem = trelem.parentNode;
936 // Replace contents of the tdplus cell.
937 tdplus.innerHTML =
938 "<select name='fld[" + lino + "][condition_andor][" + i + "]'>" +
939 "<option value='and'><?php echo xls('And') ?></option>" +
940 "<option value='or' ><?php echo xls('Or') ?></option>" +
941 "</select>";
943 // Add the new row.
944 var newtrelem = telem.insertRow(i+2);
945 newtrelem.innerHTML =
946 "<td align='left'>" +
947 "<select name='fld[" + lino + "][condition_id][" + i + "]' onchange='cidChanged(" + lino + "," + i + ")'>" +
948 "<?php echo addslashes(genFieldOptionList()) ?>" +
949 "</select>" +
950 "</td>" +
951 "<td align='left'>" +
952 "<select name='fld[" + lino + "][condition_itemid][" + i + "]' style='display:none' />" +
953 "</td>" +
954 "<td align='left'>" +
955 "<select name='fld[" + lino + "][condition_operator][" + i + "]'>" +
956 "<option value='eq'><?php echo xls('Equals') ?></option>" +
957 "<option value='ne'><?php echo xls('Does not equal') ?></option>" +
958 "<option value='se'><?php echo xls('Is selected') ?></option>" +
959 "<option value='ns'><?php echo xls('Is not selected') ?></option>" +
960 "</select>" +
961 "</td>" +
962 "<td align='left'>" +
963 "<input type='text' name='fld[" + lino + "][condition_value][" + i + "]' value='' size='15' maxlength='63' />" +
964 "</td>" +
965 "<td align='right'>" +
966 "<input type='button' value='+' onclick='extAddCondition(" + lino + ",this)' />" +
967 "</td>";
970 // This is called when a field ID is chosen for testing within a skip condition.
971 // It checks to see if a corresponding list item must also be chosen for the test, and
972 // if so then inserts the dropdown for selecting an item from the appropriate list.
973 function setListItemOptions(lino, seq, init) {
974 var f = document.forms[0];
975 var target = 'fld[' + lino + '][condition_itemid][' + seq + ']';
976 // field_id is the ID of the field that the condition will test.
977 var field_id = f['fld[' + lino + '][condition_id][' + seq + ']'].value;
978 if (!field_id) {
979 f[target].options.length = 0;
980 f[target].style.display = 'none';
981 return;
983 // Find the occurrence of that field in the layout.
984 var i = 1;
985 while (true) {
986 var idname = 'fld[' + i + '][id]';
987 if (!f[idname]) {
988 alert('<?php echo xls('Condition field not found') ?>: ' + field_id);
989 return;
991 if (f[idname].value == field_id) break;
992 ++i;
994 // If this is startup initialization then preserve the current value.
995 var current = init ? f[target].value : '';
996 f[target].options.length = 0;
997 // Get the corresponding data type and list ID.
998 var data_type = f['fld[' + i + '][data_type]'].value;
999 var list_id = f['fld[' + i + '][list_id]'].value;
1000 // WARNING: If new data types are defined the following test may need enhancing.
1001 // We're getting out if the type does not generate multiple fields with different names.
1002 if (data_type != '21' && data_type != '22' && data_type != '23' && data_type != '25') {
1003 f[target].style.display = 'none';
1004 return;
1006 // OK, list item IDs do apply so go get 'em.
1007 // This happens asynchronously so the generated code needs to stand alone.
1008 f[target].style.display = '';
1009 $.getScript('layout_listitems_ajax.php' +
1010 '?listid=' + encodeURIComponent(list_id) +
1011 '&target=' + encodeURIComponent(target) +
1012 '&current=' + encodeURIComponent(current));
1015 // This is called whenever a condition's field ID selection is changed.
1016 function cidChanged(lino, seq) {
1017 changeColor(lino);
1018 setListItemOptions(lino, seq, false);
1021 // This is called whenever a validation rule field ID selection is changed.
1022 function valChanged(lino) {
1023 changeColor(lino);
1026 function changeColor(lino){
1027 var thisid = document.forms[0]['fld[' + lino + '][condition_id][0]'].value;
1028 var thisValId = document.forms[0]['fld[' + lino + '][validation]'].value;
1029 var thistd = document.getElementById("querytd_" + lino);
1030 if(thisid !='' || thisValId!='') {
1031 thistd.style.backgroundColor = '#77ff77';
1032 }else{
1033 thistd.style.backgroundColor ='';
1037 // Call this to disable the warning about unsaved changes and submit the form.
1038 function mySubmit() {
1039 somethingChanged = false;
1040 top.restoreSession();
1041 document.forms[0].submit();
1044 // User is about to do something that would discard any unsaved changes.
1045 // Return true if that is OK.
1046 function myChangeCheck() {
1047 if (somethingChanged) {
1048 if (!confirm('<?php echo xls('You have unsaved changes. Abandon them?'); ?>')) {
1049 return false;
1051 // Do not set somethingChanged to false here because if they cancel the
1052 // action then the previously changed values will still be of interest.
1054 return true;
1057 </script>
1059 </head>
1061 <body class="body_top admin-layout">
1063 <form method='post' name='theform' id='theform' action='edit_layout.php'>
1064 <input type="hidden" name="formaction" id="formaction" value="">
1065 <!-- elements used to identify a field to delete -->
1066 <input type="hidden" name="deletefieldid" id="deletefieldid" value="">
1067 <input type="hidden" name="deletefieldgroup" id="deletefieldgroup" value="">
1068 <!-- elements used to identify a group to delete -->
1069 <input type="hidden" name="deletegroupname" id="deletegroupname" value="">
1070 <!-- elements used to change the group order -->
1071 <input type="hidden" name="movegroupname" id="movegroupname" value="">
1072 <input type="hidden" name="movedirection" id="movedirection" value="">
1073 <!-- elements used to select more than one field -->
1074 <input type="hidden" name="selectedfields" id="selectedfields" value="">
1075 <input type="hidden" id="targetgroup" name="targetgroup" value="">
1076 <div class="menubar">
1077 <div>
1078 <b><?php xl('Edit layout', 'e'); ?>:</b>&nbsp;
1079 <select name='layout_id' id='layout_id'>
1080 <option value=''>-- <?php echo xl('Select') ?> --</option>
1081 <?php
1082 foreach ($layouts as $key => $value) {
1083 echo " <option value='$key'";
1084 if ($key == $layout_id) {
1085 echo " selected";
1088 echo ">$value</option>\n";
1091 </select></div><div><p>
1092 <?php if ($layout_id) { ?>
1093 <input type='button' class='addgroup' id='addgroup' value=<?php xl('Add Group', 'e', '\'', '\''); ?>/>
1094 <span style="font-size:90%"> &nbsp;
1095 <input type='button' name='save' id='save' value='<?php xl('Save Changes', 'e'); ?>' /></span> &nbsp;&nbsp;
1096 <?php xl('With selected:', 'e');?>
1097 <input type='button' name='deletefields' id='deletefields' value='<?php xl('Delete', 'e'); ?>' style="font-size:90%" disabled="disabled" />
1098 <input type='button' name='movefields' id='movefields' value='<?php xl('Move to...', 'e'); ?>' style="font-size:90%" disabled="disabled" /></span>
1099 </p></div>
1100 </div>
1101 <div class="container">
1102 <?php } ?>
1103 <?php
1104 $prevgroup = "!@#asdf1234"; // an unlikely group name
1105 $firstgroup = true; // flag indicates it's the first group to be displayed
1106 while ($row = sqlFetchArray($res)) {
1107 if ($row['group_name'] != $prevgroup) {
1108 if ($firstgroup == false) {
1109 echo "</tbody></table></div>\n";
1112 echo "<div id='".$row['group_name']."' class='group'>";
1113 echo "<div class='text bold layouts_title' style='position:relative; background-color: #eef'>";
1114 // echo preg_replace("/^\d+/", "", $row['group_name']);
1115 echo substr($row['group_name'], 1);
1116 echo "&nbsp; ";
1117 // if not english and set to translate layout labels, then show the translation of group name
1118 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
1119 // echo "<span class='translation'>>>&nbsp; " . xl(preg_replace("/^\d+/", "", $row['group_name'])) . "</span>";
1120 echo "<span class='translation'>>>&nbsp; " . xl(substr($row['group_name'], 1)) . "</span>";
1121 echo "&nbsp; ";
1124 echo "&nbsp; ";
1125 echo " <input type='button' class='addfield' id='addto~".$row['group_name']."' value='" . xl('Add Field') . "'/>";
1126 echo "&nbsp; &nbsp; ";
1127 echo " <input type='button' class='renamegroup' id='".$row['group_name']."' value='" . xl('Rename Group') . "'/>";
1128 echo "&nbsp; &nbsp; ";
1129 echo " <input type='button' class='deletegroup' id='".$row['group_name']."' value='" . xl('Delete Group') . "'/>";
1130 echo "&nbsp; &nbsp; ";
1131 echo " <input type='button' class='movegroup' id='".$row['group_name']."~up' value='" . xl('Move Up') . "'/>";
1132 echo "&nbsp; &nbsp; ";
1133 echo " <input type='button' class='movegroup' id='".$row['group_name']."~down' value='" . xl('Move Down') . "'/>";
1134 echo "</div>";
1135 $firstgroup = false;
1137 <table>
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 <?php // if not english and showing layout label translations, then show translation header for title
1145 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
1146 echo "<th>" . xl('Translation')."<span class='help' title='" . xl('The translated label that will appear on the form in current language') . "'>&nbsp;(?)</span></th>";
1147 } ?>
1148 <th><?php xl('UOR', 'e'); ?></th>
1149 <th><?php xl('Data Type', 'e'); ?></th>
1150 <th><?php xl('Size', 'e'); ?></th>
1151 <th><?php xl('Max Size', 'e'); ?></th>
1152 <th><?php xl('List', 'e'); ?></th>
1153 <th><?php xl('Backup List', 'e'); ?></th>
1154 <th><?php xl('Label Cols', 'e'); ?></th>
1155 <th><?php xl('Data Cols', 'e'); ?></th>
1156 <th><?php xl('Options', 'e'); ?></th>
1157 <th><?php xl('Description', 'e'); ?></th>
1158 <?php // if not english and showing layout label translations, then show translation header for description
1159 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
1160 echo "<th>" . xl('Translation')."<span class='help' title='" . xl('The translation of description in current language')."'>&nbsp;(?)</span></th>";
1161 } ?>
1162 <th><?php echo xlt('?'); ?></th>
1163 </tr>
1164 </thead>
1165 <tbody>
1167 <?php
1168 } // end if-group_name
1170 writeFieldLine($row);
1171 $prevgroup = $row['group_name'];
1172 } // end while loop
1175 </tbody>
1176 </table></div>
1178 <?php echo $extra_html; ?>
1180 </form>
1182 <!-- template DIV that appears when user chooses to rename an existing group -->
1183 <div id="renamegroupdetail" style="border: 1px solid black; padding: 3px; display: none; visibility: hidden; background-color: lightgrey;">
1184 <input type="hidden" name="renameoldgroupname" id="renameoldgroupname" value="">
1185 <?php xl('Group Name', 'e'); ?>: <input type="textbox" size="20" maxlength="30" name="renamegroupname" id="renamegroupname">
1186 <br>
1187 <input type="button" class="saverenamegroup" value=<?php xl('Rename Group', 'e', '\'', '\''); ?>>
1188 <input type="button" class="cancelrenamegroup" value=<?php xl('Cancel', 'e', '\'', '\''); ?>>
1189 </div>
1191 <!-- template DIV that appears when user chooses to add a new group -->
1192 <div id="groupdetail" style="border: 1px solid black; padding: 3px; display: none; visibility: hidden; background-color: lightgrey;">
1193 <span class='bold'>
1194 <?php xl('Group Name', 'e'); ?>: <input type="textbox" size="20" maxlength="30" name="newgroupname" id="newgroupname">
1195 <br>
1196 <table style="border-collapse: collapse; margin-top: 5px;">
1197 <thead>
1198 <tr class='head'>
1199 <th><?php xl('Order', 'e'); ?></th>
1200 <th<?php echo " $lbfonly"; ?>><?php xl('Source', 'e'); ?></th>
1201 <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>
1202 <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>
1203 <th><?php xl('UOR', 'e'); ?></th>
1204 <th><?php xl('Data Type', 'e'); ?></th>
1205 <th><?php xl('Size', 'e'); ?></th>
1206 <th><?php xl('Max Size', 'e'); ?></th>
1207 <th><?php xl('List', 'e'); ?></th>
1208 <th><?php xl('Backup List', 'e'); ?></th>
1209 <th><?php xl('Label Cols', 'e'); ?></th>
1210 <th><?php xl('Data Cols', 'e'); ?></th>
1211 <th><?php xl('Options', 'e'); ?></th>
1212 <th><?php xl('Description', 'e'); ?></th>
1213 </tr>
1214 </thead>
1215 <tbody>
1216 <tr class='center'>
1217 <td ><input type="textbox" name="gnewseq" id="gnewseq" value="" size="2" maxlength="3"> </td>
1218 <td<?php echo " $lbfonly"; ?>>
1219 <select name='gnewsource' id='gnewsource'>
1220 <?php
1221 foreach ($sources as $key => $value) {
1222 echo "<option value='" . attr($key) . "'>" . text($value) . "</option>\n";
1225 </select>
1226 </td>
1227 <td><input type="textbox" name="gnewid" id="gnewid" value="" size="10" maxlength="20"
1228 onclick='FieldIDClicked(this)'> </td>
1229 <td><input type="textbox" name="gnewtitle" id="gnewtitle" value="" size="20" maxlength="63"> </td>
1230 <td>
1231 <select name="gnewuor" id="gnewuor">
1232 <option value="0"><?php xl('Unused', 'e'); ?></option>
1233 <option value="1" selected><?php xl('Optional', 'e'); ?></option>
1234 <option value="2"><?php xl('Required', 'e'); ?></option>
1235 </select>
1236 </td>
1237 <td align='center'>
1238 <select name='gnewdatatype' id='gnewdatatype'>
1239 <option value=''></option>
1240 <?php
1241 global $datatypes;
1242 foreach ($datatypes as $key => $value) {
1243 echo "<option value='$key'>$value</option>";
1246 </select>
1247 </td>
1248 <td><input type="textbox" name="gnewlengthWidth" id="gnewlengthWidth" value="" size="1" maxlength="3" title="<?php echo xla('Width'); ?>">
1249 <input type="textbox" name="gnewlengthHeight" id="gnewlengthHeight" value="" size="1" maxlength="3" title="<?php echo xla('Height'); ?>"></td>
1250 <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>
1251 <td><input type="textbox" name="gnewlistid" id="gnewlistid" value="" size="8" maxlength="31" class="listid">
1252 <select name='gcontextName' id='gcontextName' style='display:none'>
1253 <?php
1254 $res = sqlStatement("SELECT * FROM customlists WHERE cl_list_type=2 AND cl_deleted=0");
1255 while ($row = sqlFetchArray($res)) {
1256 echo "<option value='".htmlspecialchars($row['cl_list_item_long'], ENT_QUOTES)."'>".htmlspecialchars($row['cl_list_item_long'], ENT_QUOTES)."</option>";
1259 </select>
1260 </td>
1261 <td><input type="textbox" name="gnewbackuplistid" id="gnewbackuplistid" value="" size="8" maxlength="31" class="listid"></td>
1262 <td><input type="textbox" name="gnewtitlecols" id="gnewtitlecols" value="" size="3" maxlength="3"> </td>
1263 <td><input type="textbox" name="gnewdatacols" id="gnewdatacols" value="" size="3" maxlength="3"> </td>
1264 <td><input type="textbox" name="gnewedit_options" id="gnewedit_options" value="" size="3" maxlength="36">
1265 <input type="hidden" name="gnewdefault" id="gnewdefault" value="" /> </td>
1266 <td><input type="textbox" name="gnewdesc" id="gnewdesc" value="" size="30" maxlength="63"> </td>
1267 </tr>
1268 </tbody>
1269 </table>
1270 <br>
1271 <input type="button" class="savenewgroup" value=<?php xl('Save New Group', 'e', '\'', '\''); ?>>
1272 <input type="button" class="cancelnewgroup" value=<?php xl('Cancel', 'e', '\'', '\''); ?>>
1273 </span>
1274 </div>
1276 <!-- template DIV that appears when user chooses to add a new field to a group -->
1277 <div id="fielddetail" class="fielddetail" style="display: none; visibility: hidden">
1278 <input type="hidden" name="newfieldgroupid" id="newfieldgroupid" value="">
1279 <table style="border-collapse: collapse;">
1280 <thead>
1281 <tr class='head'>
1282 <th><?php xl('Order', 'e'); ?></th>
1283 <th<?php echo " $lbfonly"; ?>><?php xl('Source', 'e'); ?></th>
1284 <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>
1285 <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>
1286 <th><?php xl('UOR', 'e'); ?></th>
1287 <th><?php xl('Data Type', 'e'); ?></th>
1288 <th><?php xl('Size', 'e'); ?></th>
1289 <th><?php xl('Max Size', 'e'); ?></th>
1290 <th><?php xl('List', 'e'); ?></th>
1291 <th><?php xl('Backup List', 'e'); ?></th>
1292 <th><?php xl('Label Cols', 'e'); ?></th>
1293 <th><?php xl('Data Cols', 'e'); ?></th>
1294 <th><?php xl('Options', 'e'); ?></th>
1295 <th><?php xl('Description', 'e'); ?></th>
1296 </tr>
1297 </thead>
1298 <tbody>
1299 <tr class='center'>
1300 <td ><input type="textbox" name="newseq" id="newseq" value="" size="2" maxlength="3"> </td>
1301 <td<?php echo " $lbfonly"; ?>>
1302 <select name='newsource' id='newsource'>
1303 <?php
1304 foreach ($sources as $key => $value) {
1305 echo " <option value='" . attr($key) . "'>" . text($value) . "</option>\n";
1308 </select>
1309 </td>
1310 <td ><input type="textbox" name="newid" id="newid" value="" size="10" maxlength="20"
1311 onclick='FieldIDClicked(this)'> </td>
1312 <td><input type="textbox" name="newtitle" id="newtitle" value="" size="20" maxlength="63"> </td>
1313 <td>
1314 <select name="newuor" id="newuor">
1315 <option value="0"><?php xl('Unused', 'e'); ?></option>
1316 <option value="1" selected><?php xl('Optional', 'e'); ?></option>
1317 <option value="2"><?php xl('Required', 'e'); ?></option>
1318 </select>
1319 </td>
1320 <td align='center'>
1321 <select name='newdatatype' id='newdatatype'>
1322 <option value=''></option>
1323 <?php
1324 global $datatypes;
1325 foreach ($datatypes as $key => $value) {
1326 echo " <option value='$key'>$value</option>\n";
1329 </select>
1330 </td>
1331 <td><input type="textbox" name="newlengthWidth" id="newlengthWidth" value="" size="1" maxlength="3" title="<?php echo xla('Width'); ?>">
1332 <input type="textbox" name="newlengthHeight" id="newlengthHeight" value="" size="1" maxlength="3" title="<?php echo xla('Height'); ?>"></td>
1333 <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>
1334 <td><input type="textbox" name="newlistid" id="newlistid" value="" size="8" maxlength="31" class="listid">
1335 <select name='contextName' id='contextName' style='display:none'>
1336 <?php
1337 $res = sqlStatement("SELECT * FROM customlists WHERE cl_list_type=2 AND cl_deleted=0");
1338 while ($row = sqlFetchArray($res)) {
1339 echo "<option value='".htmlspecialchars($row['cl_list_item_long'], ENT_QUOTES)."'>".htmlspecialchars($row['cl_list_item_long'], ENT_QUOTES)."</option>";
1342 </select>
1343 </td>
1344 <td><input type="textbox" name="newbackuplistid" id="newbackuplistid" value="" size="8" maxlength="31" class="listid"></td>
1345 <td><input type="textbox" name="newtitlecols" id="newtitlecols" value="" size="3" maxlength="3"> </td>
1346 <td><input type="textbox" name="newdatacols" id="newdatacols" value="" size="3" maxlength="3"> </td>
1347 <td><input type="textbox" name="newedit_options" id="newedit_options" value="" size="3" maxlength="36">
1348 <input type="hidden" name="newdefault" id="newdefault" value="" /> </td>
1349 <td><input type="textbox" name="newdesc" id="newdesc" value="" size="30" maxlength="63"> </td>
1350 </tr>
1351 <tr>
1352 <td colspan="9">
1353 <input type="button" class="savenewfield" value=<?php xl('Save New Field', 'e', '\'', '\''); ?>>
1354 <input type="button" class="cancelnewfield" value=<?php xl('Cancel', 'e', '\'', '\''); ?>>
1355 </td>
1356 </tr>
1357 </tbody>
1358 </table>
1359 </div>
1361 </body>
1363 <script language="javascript">
1365 // used when selecting a list-name for a field
1366 var selectedfield;
1368 // Support for beforeunload handler.
1369 var somethingChanged = false;
1371 // Get the next logical sequence number for a field in the specified group.
1372 // Note it guesses and uses the existing increment value.
1373 function getNextSeq(group) {
1374 var f = document.forms[0];
1375 var seq = 0;
1376 var delta = 10;
1377 for (var i = 1; true; ++i) {
1378 var gelem = f['fld[' + i + '][group]'];
1379 if (!gelem) break;
1380 if (gelem.value != group) continue;
1381 var tmp = parseInt(f['fld[' + i + '][seq]'].value);
1382 if (isNaN(tmp)) continue;
1383 if (tmp <= seq) continue;
1384 delta = tmp - seq;
1385 seq = tmp;
1387 return seq + delta;
1390 // jQuery stuff to make the page a little easier to use
1392 $(document).ready(function(){
1393 $("#save").click(function() { SaveChanges(); });
1394 $("#layout_id").change(function() {
1395 if (!myChangeCheck()) {
1396 $("#layout_id").val("<?php echo $layout_id; ?>");
1397 return;
1399 mySubmit();
1402 $(".addgroup").click(function() { AddGroup(this); });
1403 $(".savenewgroup").click(function() { SaveNewGroup(this); });
1404 $(".deletegroup").click(function() { DeleteGroup(this); });
1405 $(".cancelnewgroup").click(function() { CancelNewGroup(this); });
1406 $(".movegroup").click(function() { MoveGroup(this); });
1407 $(".renamegroup").click(function() { RenameGroup(this); });
1408 $(".saverenamegroup").click(function() { SaveRenameGroup(this); });
1409 $(".cancelrenamegroup").click(function() { CancelRenameGroup(this); });
1410 $(".addfield").click(function() { AddField(this); });
1411 $("#deletefields").click(function() { DeleteFields(this); });
1412 $(".selectfield").click(function() {
1413 var TRparent = $(this).parent().parent();
1414 $(TRparent).children("td").toggleClass("highlight");
1415 // disable the delete-move buttons
1416 $("#deletefields").attr("disabled", "disabled");
1417 $("#movefields").attr("disabled", "disabled");
1418 $(".selectfield").each(function(i) {
1419 // if any field is selected, enable the delete-move buttons
1420 if ($(this).attr("checked") == true) {
1421 $("#deletefields").removeAttr("disabled");
1422 $("#movefields").removeAttr("disabled");
1427 $("#movefields").click(function() { ShowGroups(this); });
1428 $(".savenewfield").click(function() { SaveNewField(this); });
1429 $(".cancelnewfield").click(function() { CancelNewField(this); });
1430 $("#newtitle").blur(function() { if ($("#newid").val() == "") $("#newid").val($("#newtitle").val()); });
1431 $("#newdatatype").change(function() { ChangeList(this.value);});
1432 $("#gnewdatatype").change(function() { ChangeListg(this.value);});
1433 $(".listid").click(function() { ShowLists(this); });
1435 // special class that skips the element
1436 $(".noselect").focus(function() { $(this).blur(); });
1438 // Save the changes made to the form
1439 var SaveChanges = function () {
1440 $("#formaction").val("save");
1441 mySubmit();
1444 /****************************************************/
1445 /************ Group functions ***********************/
1446 /****************************************************/
1448 // display the 'new group' DIV
1449 var AddGroup = function(btnObj) {
1450 if (!myChangeCheck()) return;
1451 $("#save").attr("disabled", true);
1452 // show the field details DIV
1453 $('#groupdetail').css('visibility', 'visible');
1454 $('#groupdetail').css('display', 'block');
1455 $(btnObj).parent().append($("#groupdetail"));
1456 $('#groupdetail > #newgroupname').focus();
1457 // Assign a sensible default sequence number.
1458 $('#gnewseq').val(10);
1461 // save the new group to the form
1462 var SaveNewGroup = function(btnObj) {
1463 // the group name field can only have letters, numbers, spaces and underscores
1464 // AND it cannot start with a number
1465 if ($("#newgroupname").val() == "") {
1466 alert("<?php xl('Group names cannot be blank', 'e'); ?>");
1467 return false;
1469 if ($("#newgroupname").val().match(/^(\d+|\s+)/)) {
1470 alert("<?php xl('Group names cannot start with numbers or spaces.', 'e'); ?>");
1471 return false;
1473 var validname = $("#newgroupname").val().replace(/[^A-za-z0-9 ]/g, "_"); // match any non-word characters and replace them
1474 $("#newgroupname").val(validname);
1476 // now, check the first group field values
1478 // seq must be numeric and less than 999
1479 if (! IsNumeric($("#gnewseq").val(), 0, 999)) {
1480 alert("<?php xl('Order must be a number between 1 and 999', 'e'); ?>");
1481 return false;
1483 // length must be numeric and less than 999
1484 if (! IsNumeric($("#gnewlengthWidth").val(), 0, 999)) {
1485 alert("<?php xl('Size must be a number between 1 and 999', 'e'); ?>");
1486 return false;
1488 // titlecols must be numeric and less than 100
1489 if (! IsNumeric($("#gnewtitlecols").val(), 0, 999)) {
1490 alert("<?php xl('LabelCols must be a number between 1 and 999', 'e'); ?>");
1491 return false;
1493 // datacols must be numeric and less than 100
1494 if (! IsNumeric($("#gnewdatacols").val(), 0, 999)) {
1495 alert("<?php xl('DataCols must be a number between 1 and 999', 'e'); ?>");
1496 return false;
1498 // some fields cannot be blank
1499 if ($("#gnewtitle").val() == "") {
1500 alert("<?php xl('Label cannot be blank', 'e'); ?>");
1501 return false;
1503 // the id field can only have letters, numbers and underscores
1504 if ($("#gnewid").val() == "") {
1505 alert("<?php xl('ID cannot be blank', 'e'); ?>");
1506 return false;
1508 var validid = $("#gnewid").val().replace(/(\s|\W)/g, "_"); // match any non-word characters and replace them
1509 $("#gnewid").val(validid);
1510 // similarly with the listid field
1511 validid = $("#gnewlistid").val().replace(/(\s|\W)/g, "_");
1512 $("#gnewlistid").val(validid);
1513 // similarly with the backuplistid field
1514 validid = $("#gnewbackuplistid").val().replace(/(\s|\W)/g, "_");
1515 $("#gnewbackuplistid").val(validid);
1518 // submit the form to add a new field to a specific group
1519 $("#formaction").val("addgroup");
1520 mySubmit();
1523 // actually delete an entire group from the database
1524 var DeleteGroup = function(btnObj) {
1525 var parts = $(btnObj).attr("id");
1526 var groupname = parts.replace(/^\d+/, "");
1527 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+"'?")) {
1528 // submit the form to add a new field to a specific group
1529 $("#formaction").val("deletegroup");
1530 $("#deletegroupname").val(parts);
1531 $("#theform").submit();
1535 // just hide the new field DIV
1536 var CancelNewGroup = function(btnObj) {
1537 // hide the field details DIV
1538 $('#groupdetail').css('visibility', 'hidden');
1539 $('#groupdetail').css('display', 'none');
1540 // reset the new group values to a default
1541 $('#groupdetail > #newgroupname').val("");
1542 $("#save").attr("disabled", false);
1545 // display the 'new field' DIV
1546 var MoveGroup = function(btnObj) {
1547 if (!myChangeCheck()) return;
1548 var btnid = $(btnObj).attr("id");
1549 var parts = btnid.split("~");
1550 var groupid = parts[0];
1551 var direction = parts[1];
1552 // submit the form to change group order
1553 $("#formaction").val("movegroup");
1554 $("#movegroupname").val(groupid);
1555 $("#movedirection").val(direction);
1556 mySubmit();
1559 // show the rename group DIV
1560 var RenameGroup = function(btnObj) {
1561 if (!myChangeCheck()) return;
1562 $("#save").attr("disabled", true);
1563 $('#renamegroupdetail').css('visibility', 'visible');
1564 $('#renamegroupdetail').css('display', 'block');
1565 $(btnObj).parent().append($("#renamegroupdetail"));
1566 $('#renameoldgroupname').val($(btnObj).attr("id"));
1567 $('#renamegroupname').val($(btnObj).attr("id").replace(/^\d+/, ""));
1570 // save the new group to the form
1571 var SaveRenameGroup = function(btnObj) {
1572 // the group name field can only have letters, numbers, spaces and underscores
1573 // AND it cannot start with a number
1574 if ($("#renamegroupname").val().match(/^\d+/)) {
1575 alert("<?php xl('Group names cannot start with numbers.', 'e'); ?>");
1576 return false;
1578 var validname = $("#renamegroupname").val().replace(/[^A-za-z0-9 ]/g, "_"); // match any non-word characters and replace them
1579 $("#renamegroupname").val(validname);
1581 // submit the form to add a new field to a specific group
1582 $("#formaction").val("renamegroup");
1583 mySubmit();
1586 // just hide the new field DIV
1587 var CancelRenameGroup = function(btnObj) {
1588 // hide the field details DIV
1589 $('#renamegroupdetail').css('visibility', 'hidden');
1590 $('#renamegroupdetail').css('display', 'none');
1591 // reset the rename group values to a default
1592 $('#renameoldgroupname').val("");
1593 $('#renamegroupname').val("");
1596 /****************************************************/
1597 /************ Field functions ***********************/
1598 /****************************************************/
1600 // display the 'new field' DIV
1601 var AddField = function(btnObj) {
1602 if (!myChangeCheck()) return;
1603 $("#save").attr("disabled", true);
1604 // update the fieldgroup value to be the groupid
1605 var btnid = $(btnObj).attr("id");
1606 var parts = btnid.split("~");
1607 var groupid = parts[1];
1608 $('#fielddetail > #newfieldgroupid').attr('value', groupid);
1609 // show the field details DIV
1610 $('#fielddetail').css('visibility', 'visible');
1611 $('#fielddetail').css('display', 'block');
1612 $(btnObj).parent().append($("#fielddetail"));
1613 // Assign a sensible default sequence number.
1614 $('#newseq').val(getNextSeq(groupid));
1617 var DeleteFields = function(btnObj) {
1618 if (!myChangeCheck()) return;
1619 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'); ?>")) {
1620 var delim = "";
1621 $(".selectfield").each(function(i) {
1622 // build a list of selected field names to be moved
1623 if ($(this).attr("checked") == true) {
1624 var parts = this.id.split("~");
1625 var currval = $("#selectedfields").val();
1626 $("#selectedfields").val(currval+delim+parts[1]);
1627 delim = " ";
1630 // submit the form to delete the field(s)
1631 $("#formaction").val("deletefields");
1632 mySubmit();
1636 // save the new field to the form
1637 var SaveNewField = function(btnObj) {
1638 // check the new field values for correct formatting
1640 // seq must be numeric and less than 999
1641 if (! IsNumeric($("#newseq").val(), 0, 999)) {
1642 alert("<?php xl('Order must be a number between 1 and 999', 'e'); ?>");
1643 return false;
1645 // length must be numeric and less than 999
1646 if (! IsNumeric($("#newlengthWidth").val(), 0, 999)) {
1647 alert("<?php xl('Size must be a number between 1 and 999', 'e'); ?>");
1648 return false;
1650 // titlecols must be numeric and less than 100
1651 if (! IsNumeric($("#newtitlecols").val(), 0, 999)) {
1652 alert("<?php xl('LabelCols must be a number between 1 and 999', 'e'); ?>");
1653 return false;
1655 // datacols must be numeric and less than 100
1656 if (! IsNumeric($("#newdatacols").val(), 0, 999)) {
1657 alert("<?php xl('DataCols must be a number between 1 and 999', 'e'); ?>");
1658 return false;
1660 // some fields cannot be blank
1661 if ($("#newtitle").val() == "") {
1662 alert("<?php xl('Label cannot be blank', 'e'); ?>");
1663 return false;
1665 // the id field can only have letters, numbers and underscores
1666 var validid = $("#newid").val().replace(/(\s|\W)/g, "_"); // match any non-word characters and replace them
1667 $("#newid").val(validid);
1668 // similarly with the listid field
1669 validid = $("#newlistid").val().replace(/(\s|\W)/g, "_");
1670 $("#newlistid").val(validid);
1671 // similarly with the backuplistid field
1672 validid = $("#newbackuplistid").val().replace(/(\s|\W)/g, "_");
1673 $("#newbackuplistid").val(validid);
1675 // submit the form to add a new field to a specific group
1676 $("#formaction").val("addfield");
1677 mySubmit();
1680 // just hide the new field DIV
1681 var CancelNewField = function(btnObj) {
1682 // hide the field details DIV
1683 $('#fielddetail').css('visibility', 'hidden');
1684 $('#fielddetail').css('display', 'none');
1685 // reset the new field values to a default
1686 ResetNewFieldValues();
1687 $("#save").attr("disabled", false);
1690 // show the popup choice of lists
1691 var ShowLists = function(btnObj) {
1692 window.open("./show_lists_popup.php", "lists", "width=300,height=500,scrollbars=yes");
1693 selectedfield = btnObj;
1696 // show the popup choice of groups
1697 var ShowGroups = function(btnObj) {
1698 if (!myChangeCheck()) return;
1699 window.open("./show_groups_popup.php?layout_id=<?php echo $layout_id;?>", "groups", "width=300,height=300,scrollbars=yes");
1702 // Show context DD for NationNotes
1703 var ChangeList = function(btnObj){
1704 if(btnObj==34){
1705 $('#newlistid').hide();
1706 $('#contextName').show();
1708 else{
1709 $('#newlistid').show();
1710 $('#contextName').hide();
1713 var ChangeListg = function(btnObj){
1714 if(btnObj==34){
1715 $('#gnewlistid').hide();
1716 $('#gcontextName').show();
1718 else{
1719 $('#gnewlistid').show();
1720 $('#gcontextName').hide();
1724 // Initialize the list item selectors in skip conditions.
1725 var f = document.forms[0];
1726 for (var lino = 1; f['fld[' + lino + '][id]']; ++lino) {
1727 for (var seq = 0; f['fld[' + lino + '][condition_itemid][' + seq + ']']; ++seq) {
1728 setListItemOptions(lino, seq, true);
1732 // Support for beforeunload handler.
1733 $('tbody input, tbody select, tbody textarea').not('.selectfield').change(function() {
1734 somethingChanged = true;
1736 window.addEventListener("beforeunload", function (e) {
1737 if (somethingChanged && !top.timed_out) {
1738 var msg = "<?php echo xls('You have unsaved changes.'); ?>";
1739 e.returnValue = msg; // Gecko, Trident, Chrome 34+
1740 return msg; // Gecko, WebKit, Chrome <34
1746 function NationNotesContext(lineitem,val){
1747 if(val==34){
1748 document.getElementById("fld["+lineitem+"][contextName]").style.display='';
1749 document.getElementById("fld["+lineitem+"][list_id]").style.display='none';
1750 document.getElementById("fld["+lineitem+"][list_id]").value='';
1752 else{
1753 document.getElementById("fld["+lineitem+"][list_id]").style.display='';
1754 document.getElementById("fld["+lineitem+"][contextName]").style.display='none';
1755 document.getElementById("fld["+lineitem+"][list_id]").value='';
1759 function SetList(listid) {
1760 $(selectedfield).val(listid);
1763 //////////////////////////////////////////////////////////////////////
1764 // The following supports the field ID selection pop-up.
1765 //////////////////////////////////////////////////////////////////////
1767 var fieldselectfield;
1769 function elemFromPart(part) {
1770 var ename = fieldselectfield.name;
1771 // ename is like one of the following:
1772 // fld[$fld_line_no][id]
1773 // gnewid
1774 // newid
1775 // and "part" is what we substitute for the "id" part.
1776 var i = ename.lastIndexOf('id');
1777 ename = ename.substr(0, i) + part + ename.substr(i+2);
1778 return document.forms[0][ename];
1781 function FieldIDClicked(elem) {
1782 <?php if (substr($layout_id, 0, 3) == 'LBF') { ?>
1783 fieldselectfield = elem;
1784 var srcval = elemFromPart('source').value;
1785 // If the field ID is for the local form, allow direct entry.
1786 if (srcval == 'F') return;
1787 // Otherwise pop up the selection window.
1788 window.open('./field_id_popup.php?source=' + srcval, 'fields',
1789 'width=600,height=600,scrollbars=yes');
1790 <?php } ?>
1793 function SetField(field_id, title, data_type, uor, fld_length, max_length,
1794 list_id, titlecols, datacols, edit_options, description, fld_rows)
1796 fieldselectfield.value = field_id;
1797 elemFromPart('title' ).value = title;
1798 elemFromPart('datatype' ).value = data_type;
1799 elemFromPart('uor' ).value = uor;
1800 elemFromPart('lengthWidth' ).value = fld_length;
1801 elemFromPart('maxSize' ).value = max_length;
1802 elemFromPart('listid' ).value = list_id;
1803 elemFromPart('titlecols' ).value = titlecols;
1804 elemFromPart('datacols' ).value = datacols;
1805 elemFromPart('edit_options').value = edit_options;
1806 elemFromPart('desc' ).value = description;
1807 elemFromPart('lengthHeight').value = fld_rows;
1810 //////////////////////////////////////////////////////////////////////
1811 // End code for field ID selection pop-up.
1812 //////////////////////////////////////////////////////////////////////
1814 /* this is called after the user chooses a new group from the popup window
1815 * it will submit the page so the selected fields can be moved into
1816 * the target group
1818 function MoveFields(targetgroup) {
1819 $("#targetgroup").val(targetgroup);
1820 var delim = "";
1821 $(".selectfield").each(function(i) {
1822 // build a list of selected field names to be moved
1823 if ($(this).attr("checked") == true) {
1824 var parts = this.id.split("~");
1825 var currval = $("#selectedfields").val();
1826 $("#selectedfields").val(currval+delim+parts[1]);
1827 delim = " ";
1830 $("#formaction").val("movefields");
1831 mySubmit();
1834 // set the new-field values to a default state
1835 function ResetNewFieldValues () {
1836 $("#newseq").val("");
1837 $("#newsource").val("");
1838 $("#newid").val("");
1839 $("#newtitle").val("");
1840 $("#newuor").val(1);
1841 $("#newlengthWidth").val("");
1842 $("#newlengthHeight").val("");
1843 $("#newmaxSize").val("");
1844 $("#newdatatype").val("");
1845 $("#newlistid").val("");
1846 $("#newbackuplistid").val("");
1847 $("#newtitlecols").val("");
1848 $("#newdatacols").val("");
1849 $("#newedit_options").val("");
1850 $("#newdefault").val("");
1851 $("#newdesc").val("");
1854 // is value an integer and between min and max
1855 function IsNumeric(value, min, max) {
1856 if (value == "" || value == null) return false;
1857 if (! IsN(value) ||
1858 parseInt(value) < min ||
1859 parseInt(value) > max)
1860 return false;
1862 return true;
1865 /****************************************************/
1866 /****************************************************/
1867 /****************************************************/
1869 // tell if num is an Integer
1870 function IsN(num) { return !/\D/.test(num); }
1872 </script>
1874 </html>