2 // Copyright (C) 2007-2010 Rod Roark <rod@sunsetsystems.com>
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 require_once("../globals.php");
10 require_once("$srcdir/acl.inc");
11 require_once("$srcdir/log.inc");
12 require_once("$srcdir/formdata.inc.php");
15 'DEM' => xl('Demographics'),
16 'HIS' => xl('History'),
17 'REF' => xl('Referrals'),
18 'FACUSR' => xl('Facility Specific User Information')
20 if ($GLOBALS['ippf_specific']) {
21 $layouts['GCA'] = xl('Abortion Issues');
22 $layouts['CON'] = xl('Contraception Issues');
23 // $layouts['SRH'] = xl('SRH Visit Form');
26 // Include Layout Based Encounter Forms.
27 $lres = sqlStatement("SELECT * FROM list_options " .
28 "WHERE list_id = 'lbfnames' ORDER BY seq, title");
29 while ($lrow = sqlFetchArray($lres)) {
30 $layouts[$lrow['option_id']] = $lrow['title'];
33 // array of the data_types of the fields
35 "1" => xl("List box"),
37 "3" => xl("Textarea"),
38 "4" => xl("Text-date"),
39 "10" => xl("Providers"),
40 "11" => xl("Providers NPI"),
41 "12" => xl("Pharmacies"),
43 "14" => xl("Organizations"),
44 "15" => xl("Billing codes"),
45 "21" => xl("Checkbox list"),
46 "22" => xl("Textbox list"),
47 "23" => xl("Exam results"),
48 "24" => xl("Patient allergies"),
49 "25" => xl("Checkbox w/text"),
50 "26" => xl("List box w/add"),
51 "27" => xl("Radio buttons"),
52 "28" => xl("Lifestyle status"),
53 "31" => xl("Static Text"),
54 "32" => xl("Smoking Status"),
55 "33" => xl("Race and Ethnicity"),
56 "34" => xl("NationNotes"),
57 "35" => xl("Facilities")
60 function nextGroupOrder($order) {
61 if ($order == '9') $order = 'A';
62 else if ($order == 'Z') $order = 'a';
63 else $order = chr(ord($order) +
1);
67 // Check authorization.
68 $thisauth = acl_check('admin', 'super');
69 if (!$thisauth) die(xl('Not authorized'));
71 // The layout ID identifies the layout to be edited.
72 $layout_id = empty($_REQUEST['layout_id']) ?
'' : $_REQUEST['layout_id'];
74 // Handle the Form actions
76 if ($_POST['formaction'] == "save" && $layout_id) {
77 // If we are saving, then save.
79 for ($lino = 1; isset($fld[$lino]['id']); ++
$lino) {
81 $field_id = formTrim($iter['id']);
82 $data_type = formTrim($iter['data_type']);
83 $listval = $data_type == 34 ?
formTrim($iter['contextName']) : formTrim($iter['list_id']);
85 sqlStatement("UPDATE layout_options SET " .
86 "title = '" . formTrim($iter['title']) . "', " .
87 "group_name = '" . formTrim($iter['group']) . "', " .
88 "seq = '" . formTrim($iter['seq']) . "', " .
89 "uor = '" . formTrim($iter['uor']) . "', " .
90 "fld_length = '" . formTrim($iter['lengthWidth']) . "', " .
91 "fld_rows = '" . formTrim($iter['lengthHeight']) . "', " .
92 "max_length = '" . formTrim($iter['maxSize']) . "', " .
93 "titlecols = '" . formTrim($iter['titlecols']) . "', " .
94 "datacols = '" . formTrim($iter['datacols']) . "', " .
95 "data_type= '$data_type', " .
96 "list_id= '" . $listval . "', " .
97 "edit_options = '" . formTrim($iter['edit_options']) . "', " .
98 "default_value = '" . formTrim($iter['default']) . "', " .
99 "description = '" . formTrim($iter['desc']) . "' " .
100 "WHERE form_id = '$layout_id' AND field_id = '$field_id'");
105 else if ($_POST['formaction'] == "addfield" && $layout_id) {
106 // Add a new field to a specific group
107 $data_type = formTrim($_POST['newdatatype']);
108 $max_length = $data_type == 3 ?
3 : 255;
109 $listval = $data_type == 34 ?
formTrim($_POST['contextName']) : formTrim($_POST['newlistid']);
110 sqlStatement("INSERT INTO layout_options (" .
111 " form_id, field_id, title, group_name, seq, uor, fld_length, fld_rows" .
112 ", titlecols, datacols, data_type, edit_options, default_value, description" .
113 ", max_length, list_id " .
115 "'" . formTrim($_POST['layout_id'] ) . "'" .
116 ",'" . formTrim($_POST['newid'] ) . "'" .
117 ",'" . formTrim($_POST['newtitle'] ) . "'" .
118 ",'" . formTrim($_POST['newfieldgroupid']) . "'" .
119 ",'" . formTrim($_POST['newseq'] ) . "'" .
120 ",'" . formTrim($_POST['newuor'] ) . "'" .
121 ",'" . formTrim($_POST['newlengthWidth'] ) . "'" .
122 ",'" . formTrim($_POST['newlengthHeight'] ) . "'" .
123 ",'" . formTrim($_POST['newtitlecols'] ) . "'" .
124 ",'" . formTrim($_POST['newdatacols'] ) . "'" .
126 ",'" . formTrim($_POST['newedit_options']) . "'" .
127 ",'" . formTrim($_POST['newdefault'] ) . "'" .
128 ",'" . formTrim($_POST['newdesc'] ) . "'" .
129 ",'" . formTrim($_POST['newmaxSize']) . "'" .
130 ",'" . $listval . "'" .
133 if (substr($layout_id,0,3) != 'LBF' && $layout_id != "FACUSR") {
134 // Add the field to the table too (this is critical)
135 if ($layout_id == "DEM") { $tablename = "patient_data"; }
136 else if ($layout_id == "HIS") { $tablename = "history_data"; }
137 else if ($layout_id == "REF") { $tablename = "transactions"; }
138 else if ($layout_id == "SRH") { $tablename = "lists_ippf_srh"; }
139 else if ($layout_id == "CON") { $tablename = "lists_ippf_con"; }
140 else if ($layout_id == "GCA") { $tablename = "lists_ippf_gcac"; }
141 sqlStatement("ALTER TABLE `" . $tablename . "` ADD ".
142 "`" . formTrim($_POST['newid']) . "`" .
144 newEvent("alter_table", $_SESSION['authUser'], $_SESSION['authProvider'], 1,
145 $tablename . " ADD " . formTrim($_POST['newid']));
149 else if ($_POST['formaction'] == "movefields" && $layout_id) {
150 // Move field(s) to a new group in the layout
151 $sqlstmt = "UPDATE layout_options SET ".
152 " group_name='". $_POST['targetgroup']."' ".
154 " form_id = '".$_POST['layout_id']."' ".
155 " AND field_id IN (";
157 foreach (explode(" ", $_POST['selectedfields']) as $onefield) {
158 $sqlstmt .= $comma."'".$onefield."'";
163 sqlStatement($sqlstmt);
166 else if ($_POST['formaction'] == "deletefields" && $layout_id) {
167 // Delete a field from a specific group
168 $sqlstmt = "DELETE FROM layout_options WHERE ".
169 " form_id = '".$_POST['layout_id']."' ".
170 " AND field_id IN (";
172 foreach (explode(" ", $_POST['selectedfields']) as $onefield) {
173 $sqlstmt .= $comma."'".$onefield."'";
177 sqlStatement($sqlstmt);
179 if (substr($layout_id,0,3) != 'LBF' && $layout_id != "FACUSR") {
180 // drop the field from the table too (this is critical)
181 if ($layout_id == "DEM") { $tablename = "patient_data"; }
182 else if ($layout_id == "HIS") { $tablename = "history_data"; }
183 else if ($layout_id == "REF") { $tablename = "transactions"; }
184 else if ($layout_id == "SRH") { $tablename = "lists_ippf_srh"; }
185 else if ($layout_id == "CON") { $tablename = "lists_ippf_con"; }
186 else if ($layout_id == "GCA") { $tablename = "lists_ippf_gcac"; }
187 foreach (explode(" ", $_POST['selectedfields']) as $onefield) {
188 sqlStatement("ALTER TABLE `".$tablename."` DROP `".$onefield."`");
189 newEvent("alter_table", $_SESSION['authUser'], $_SESSION['authProvider'], 1, $tablename." DROP ".$onefield);
194 else if ($_POST['formaction'] == "addgroup" && $layout_id) {
195 // all group names are prefixed with a number indicating their display order
196 // this new group is prefixed with the net highest number given the
198 $results = sqlStatement("select distinct(group_name) as gname ".
199 " from layout_options where ".
200 " form_id = '".$_POST['layout_id']."'"
203 while ($result = sqlFetchArray($results)) {
204 $tmp = substr($result['gname'], 0, 1);
205 if ($tmp >= $maxnum) $maxnum = nextGroupOrder($tmp);
208 $data_type = formTrim($_POST['gnewdatatype']);
209 $max_length = $data_type == 3 ?
3 : 255;
210 $listval = $data_type == 34 ?
formTrim($_POST['gcontextName']) : formTrim($_POST['gnewlistid']);
211 // add a new group to the layout, with the defined field
212 sqlStatement("INSERT INTO layout_options (" .
213 " form_id, field_id, title, group_name, seq, uor, fld_length, fld_rows" .
214 ", titlecols, datacols, data_type, edit_options, default_value, description" .
215 ", max_length, list_id " .
217 "'" . formTrim($_POST['layout_id'] ) . "'" .
218 ",'" . formTrim($_POST['gnewid'] ) . "'" .
219 ",'" . formTrim($_POST['gnewtitle'] ) . "'" .
220 ",'" . formTrim($maxnum . $_POST['newgroupname']) . "'" .
221 ",'" . formTrim($_POST['gnewseq'] ) . "'" .
222 ",'" . formTrim($_POST['gnewuor'] ) . "'" .
223 ",'" . formTrim($_POST['gnewlengthWidth'] ) . "'" .
224 ",'" . formTrim($_POST['gnewlengthHeight'] ) . "'" .
225 ",'" . formTrim($_POST['gnewtitlecols'] ) . "'" .
226 ",'" . formTrim($_POST['gnewdatacols'] ) . "'" .
228 ",'" . formTrim($_POST['gnewedit_options']) . "'" .
229 ",'" . formTrim($_POST['gnewdefault'] ) . "'" .
230 ",'" . formTrim($_POST['gnewdesc'] ) . "'" .
231 ",'" . formTrim($_POST['gnewmaxSize']) . "'" .
232 ",'" . $listval . "'" .
235 if (substr($layout_id,0,3) != 'LBF' && $layout_id != "FACUSR") {
236 // Add the field to the table too (this is critical)
237 if ($layout_id == "DEM") { $tablename = "patient_data"; }
238 else if ($layout_id == "HIS") { $tablename = "history_data"; }
239 else if ($layout_id == "REF") { $tablename = "transactions"; }
240 else if ($layout_id == "SRH") { $tablename = "lists_ippf_srh"; }
241 else if ($layout_id == "CON") { $tablename = "lists_ippf_con"; }
242 else if ($layout_id == "GCA") { $tablename = "lists_ippf_gcac"; }
243 sqlStatement("ALTER TABLE `" . $tablename . "` ADD ".
244 "`" . formTrim($_POST['gnewid']) . "`" .
246 newEvent("alter_table", $_SESSION['authUser'], $_SESSION['authProvider'], 1,
247 $tablename . " ADD " . formTrim($_POST['gnewid']));
251 else if ($_POST['formaction'] == "deletegroup" && $layout_id) {
252 // drop the fields from the related table (this is critical)
253 if (substr($layout_id,0,3) != 'LBF' && $layout_id != "FACUSR") {
254 $res = sqlStatement("SELECT field_id FROM layout_options WHERE " .
255 " form_id = '".$_POST['layout_id']."' ".
256 " AND group_name = '".$_POST['deletegroupname']."'"
258 while ($row = sqlFetchArray($res)) {
259 // drop the field from the table too (this is critical)
260 if ($layout_id == "DEM") { $tablename = "patient_data"; }
261 else if ($layout_id == "HIS") { $tablename = "history_data"; }
262 else if ($layout_id == "REF") { $tablename = "transactions"; }
263 else if ($layout_id == "SRH") { $tablename = "lists_ippf_srh"; }
264 else if ($layout_id == "CON") { $tablename = "lists_ippf_con"; }
265 else if ($layout_id == "GCA") { $tablename = "lists_ippf_gcac"; }
266 sqlStatement("ALTER TABLE `".$tablename."` DROP `".$row['field_id']."`");
267 newEvent("alter_table", $_SESSION['authUser'], $_SESSION['authProvider'], 1, $tablename." DROP ".trim($row['field_id']));
271 // Delete an entire group from the form
272 sqlStatement("DELETE FROM layout_options WHERE ".
273 " form_id = '".$_POST['layout_id']."' ".
274 " AND group_name = '".$_POST['deletegroupname']."'"
278 else if ($_POST['formaction'] == "movegroup" && $layout_id) {
279 $results = sqlStatement("SELECT DISTINCT(group_name) AS gname " .
280 "FROM layout_options WHERE form_id = '$layout_id' " .
284 while ($result = sqlFetchArray($results)) {
285 if ($result['gname'] == $_POST['movegroupname']) {
286 if ($_POST['movedirection'] == 'up') { // moving up
288 $garray[$i] = $garray[$i - 1];
289 $garray[$i - 1] = $result['gname'];
293 $garray[$i++
] = $result['gname'];
296 else { // moving down
298 $garray[$i++
] = $result['gname'];
301 else if ($i > 1 && $garray[$i - 2] == '') {
302 $garray[$i - 2] = $result['gname'];
305 $garray[$i++
] = $result['gname'];
309 foreach ($garray as $value) {
310 if ($value === '') continue;
311 $newname = $nextord . substr($value, 1);
312 sqlStatement("UPDATE layout_options SET " .
313 "group_name = '$newname' WHERE " .
314 "form_id = '$layout_id' AND " .
315 "group_name = '$value'");
316 $nextord = nextGroupOrder($nextord);
320 else if ($_POST['formaction'] == "renamegroup" && $layout_id) {
321 $currpos = substr($_POST['renameoldgroupname'], 0, 1);
322 // update the database rows
323 sqlStatement("UPDATE layout_options SET " .
324 "group_name = '" . $currpos . $_POST['renamegroupname'] . "' ".
325 "WHERE form_id = '$layout_id' AND ".
326 "group_name = '" . $_POST['renameoldgroupname'] . "'");
329 // Get the selected form's elements.
331 $res = sqlStatement("SELECT * FROM layout_options WHERE " .
332 "form_id = '$layout_id' ORDER BY group_name, seq");
335 // global counter for field numbers
338 // Write one option line to the form.
340 function writeFieldLine($linedata) {
343 $checked = $linedata['default_value'] ?
" checked" : "";
345 //echo " <tr bgcolor='$bgcolor'>\n";
346 echo " <tr id='fld[$fld_line_no]' class='".($fld_line_no %
2 ?
'even' : 'odd')."'>\n";
348 echo " <td class='optcell' nowrap>";
349 // tuck the group_name INPUT in here
350 echo "<input type='hidden' name='fld[$fld_line_no][group]' value='" .
351 htmlspecialchars($linedata['group_name'], ENT_QUOTES
) . "' class='optin' />";
353 echo "<input type='checkbox' class='selectfield' ".
354 "name='".$linedata['group_name']."~".$linedata['field_id']."' ".
355 "id='".$linedata['group_name']."~".$linedata['field_id']."' ".
356 "title='".htmlspecialchars(xl('Select field', ENT_QUOTES
))."'>";
358 echo "<input type='text' name='fld[$fld_line_no][seq]' id='fld[$fld_line_no][seq]' value='" .
359 htmlspecialchars($linedata['seq'], ENT_QUOTES
) . "' size='2' maxlength='3' class='optin' />";
362 echo " <td align='left' class='optcell'>";
363 echo "<input type='text' name='fld[$fld_line_no][id]' value='" .
364 htmlspecialchars($linedata['field_id'], ENT_QUOTES
) . "' size='15' maxlength='63' class='optin noselect' />";
366 echo "<input type='hidden' name='fld[$fld_line_no][id]' value='" .
367 htmlspecialchars($linedata['field_id'], ENT_QUOTES) . "' />";
368 echo htmlspecialchars($linedata['field_id'], ENT_QUOTES);
372 echo " <td align='center' class='optcell'>";
373 echo "<input type='text' id='fld[$fld_line_no][title]' name='fld[$fld_line_no][title]' value='" .
374 htmlspecialchars($linedata['title'], ENT_QUOTES
) . "' size='15' maxlength='63' class='optin' />";
377 // if not english and set to translate layout labels, then show the translation
378 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
379 echo "<td align='center' class='translation'>" . htmlspecialchars(xl($linedata['title']), ENT_QUOTES
) . "</td>\n";
382 echo " <td align='center' class='optcell'>";
383 echo "<select name='fld[$fld_line_no][uor]' class='optin'>";
384 foreach (array(0 =>xl('Unused'), 1 =>xl('Optional'), 2 =>xl('Required')) as $key => $value) {
385 echo "<option value='$key'";
386 if ($key == $linedata['uor']) echo " selected";
387 echo ">$value</option>\n";
392 echo " <td align='center' class='optcell'>";
393 echo "<select name='fld[$fld_line_no][data_type]' id='fld[$fld_line_no][data_type]' onchange=NationNotesContext('".$fld_line_no."',this.value)>";
394 echo "<option value=''></option>";
396 foreach ($datatypes as $key=>$value) {
397 if ($linedata['data_type'] == $key)
398 echo "<option value='$key' selected>$value</option>";
400 echo "<option value='$key'>$value</option>";
405 echo " <td align='center' class='optcell'>";
406 if ($linedata['data_type'] == 2 ||
$linedata['data_type'] == 3 ||
407 $linedata['data_type'] == 21 ||
$linedata['data_type'] == 22 ||
408 $linedata['data_type'] == 23 ||
$linedata['data_type'] == 25 ||
409 $linedata['data_type'] == 27 ||
$linedata['data_type'] == 28 ||
410 $linedata['data_type'] == 32)
412 // Show the width field
413 echo "<input type='text' name='fld[$fld_line_no][lengthWidth]' value='" .
414 htmlspecialchars($linedata['fld_length'], ENT_QUOTES
) .
415 "' size='1' maxlength='10' class='optin' title='" . xla('Width') . "' />";
416 if ($linedata['data_type'] == 3) {
417 // Show the height field
418 echo "<input type='text' name='fld[$fld_line_no][lengthHeight]' value='" .
419 htmlspecialchars($linedata['fld_rows'], ENT_QUOTES
) .
420 "' size='1' maxlength='10' class='optin' title='" . xla('Height') . "' />";
423 // Hide the height field
424 echo "<input type='hidden' name='fld[$fld_line_no][lengthHeight]' value=''>";
428 // all other data_types (hide both the width and height fields
429 echo "<input type='hidden' name='fld[$fld_line_no][lengthWidth]' value=''>";
430 echo "<input type='hidden' name='fld[$fld_line_no][lengthHeight]' value=''>";
434 echo " <td align='center' class='optcell'>";
435 echo "<input type='text' name='fld[$fld_line_no][maxSize]' value='" .
436 htmlspecialchars($linedata['max_length'], ENT_QUOTES
) .
437 "' size='1' maxlength='10' class='optin' title='" . xla('Maximum Size (entering 0 will allow any size)') . "' />";
440 echo " <td align='center' class='optcell'>";
441 if ($linedata['data_type'] == 1 ||
$linedata['data_type'] == 21 ||
442 $linedata['data_type'] == 22 ||
$linedata['data_type'] == 23 ||
443 $linedata['data_type'] == 25 ||
$linedata['data_type'] == 26 ||
444 $linedata['data_type'] == 27 ||
$linedata['data_type'] == 32 ||
445 $linedata['data_type'] == 33 ||
$linedata['data_type'] == 34)
448 $disp = "style='display:none'";
449 if($linedata['data_type'] == 34){
450 $type = "style='display:none'";
453 echo "<input type='text' name='fld[$fld_line_no][list_id]' id='fld[$fld_line_no][list_id]' value='" .
454 htmlspecialchars($linedata['list_id'], ENT_QUOTES
) . "'".$type.
455 " size='6' maxlength='30' class='optin listid' style='cursor: pointer'".
456 "title='". xl('Choose list') . "' />";
458 echo "<select name='fld[$fld_line_no][contextName]' id='fld[$fld_line_no][contextName]' ".$disp.">";
459 $res = sqlStatement("SELECT * FROM customlists WHERE cl_list_type=2 AND cl_deleted=0");
460 while($row = sqlFetchArray($res)){
462 if ($linedata['list_id'] == $row['cl_list_item_long'])
464 echo "<option value='".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES
)."' ".$sel.">".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES
)."</option>";
469 // all other data_types
470 echo "<input type='hidden' name='fld[$fld_line_no][list_id]' value=''>";
474 echo " <td align='center' class='optcell'>";
475 echo "<input type='text' name='fld[$fld_line_no][titlecols]' value='" .
476 htmlspecialchars($linedata['titlecols'], ENT_QUOTES
) . "' size='3' maxlength='10' class='optin' />";
479 echo " <td align='center' class='optcell'>";
480 echo "<input type='text' name='fld[$fld_line_no][datacols]' value='" .
481 htmlspecialchars($linedata['datacols'], ENT_QUOTES
) . "' size='3' maxlength='10' class='optin' />";
484 echo " <td align='center' class='optcell' title='C = " . xl('Capitalize') .
485 ", D = " . xl('Dup Check') . ", G = " . xl('Graphable') .
486 ", N = " . xl('New Patient Form') . ", O = " . xl('Order Processor') .
487 ", V = " . xl('Vendor') . "'>";
488 echo "<input type='text' name='fld[$fld_line_no][edit_options]' value='" .
489 htmlspecialchars($linedata['edit_options'], ENT_QUOTES
) . "' size='3' maxlength='36' class='optin' />";
492 /*****************************************************************
493 echo " <td align='center' class='optcell'>";
494 if ($linedata['data_type'] == 2) {
495 echo "<input type='text' name='fld[$fld_line_no][default]' value='" .
496 htmlspecialchars($linedata['default_value'], ENT_QUOTES) . "' size='10' maxlength='63' class='optin' />";
502 echo " <td align='center' class='optcell'>";
503 echo "<input type='text' name='fld[$fld_line_no][desc]' value='" .
504 htmlspecialchars($linedata['description'], ENT_QUOTES) . "' size='20' maxlength='63' class='optin' />";
507 // if not english and showing layout labels, then show the translation of Description
508 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
509 echo "<td align='center' class='translation'>" . htmlspecialchars(xl($linedata['description']), ENT_QUOTES) . "</td>\n";
511 *****************************************************************/
513 if ($linedata['data_type'] == 31) {
514 echo " <td align='center' class='optcell'>";
515 echo "<textarea name='fld[$fld_line_no][desc]' rows='3' cols='35' class='optin'>" .
516 $linedata['description'] . "</textarea>";
517 echo "<input type='hidden' name='fld[$fld_line_no][default]' value='" .
518 htmlspecialchars($linedata['default_value'], ENT_QUOTES
) . "' />";
522 echo " <td align='center' class='optcell'>";
523 echo "<input type='text' name='fld[$fld_line_no][desc]' value='" .
524 htmlspecialchars($linedata['description'], ENT_QUOTES
) .
525 "' size='30' maxlength='63' class='optin' />";
526 echo "<input type='hidden' name='fld[$fld_line_no][default]' value='" .
527 htmlspecialchars($linedata['default_value'], ENT_QUOTES
) . "' />";
529 // if not english and showing layout labels, then show the translation of Description
530 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
531 echo "<td align='center' class='translation'>" .
532 htmlspecialchars(xl($linedata['description']), ENT_QUOTES
) . "</td>\n";
542 <?php
html_header_show();?
>
544 <!-- supporting javascript code
-->
545 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script
>
547 <link rel
="stylesheet" href
='<?php echo $css_header ?>' type
='text/css'>
549 <title
><?php
xl('Layout Editor','e'); ?
></title
>
552 tr
.head
{ font
-size
:10pt
; background
-color
:#cccccc; }
553 tr
.detail
{ font
-size
:10pt
; }
554 td
{ font
-size
:10pt
; }
555 input
{ font
-size
:10pt
; }
556 a
, a
:visited
, a
:hover
{ color
:#0000cc; }
558 .optin
{ background
: transparent
; }
560 margin
: 0pt
0pt
8pt
0pt
;
565 border
-collapse
: collapse
;
569 background
-color
: #ddddff;
570 padding
: 3px
0px
3px
0px
;
573 background
-color
: #ffdddd;
574 padding
: 3px
0px
3px
0px
;
576 .help
{ cursor
: help
; }
577 .layouts_title
{ font
-size
: 110%
; }
583 border
: 2px solid blue
;
584 background
-color
: yellow
;
591 <body
class="body_top">
593 <form method
='post' name
='theform' id
='theform' action
='edit_layout.php'>
594 <input type
="hidden" name
="formaction" id
="formaction" value
="">
595 <!-- elements used to identify a field to delete
-->
596 <input type
="hidden" name
="deletefieldid" id
="deletefieldid" value
="">
597 <input type
="hidden" name
="deletefieldgroup" id
="deletefieldgroup" value
="">
598 <!-- elements used to identify a group to delete
-->
599 <input type
="hidden" name
="deletegroupname" id
="deletegroupname" value
="">
600 <!-- elements used to change the group order
-->
601 <input type
="hidden" name
="movegroupname" id
="movegroupname" value
="">
602 <input type
="hidden" name
="movedirection" id
="movedirection" value
="">
603 <!-- elements used to select more than one field
-->
604 <input type
="hidden" name
="selectedfields" id
="selectedfields" value
="">
605 <input type
="hidden" id
="targetgroup" name
="targetgroup" value
="">
607 <p
><b
><?php
xl('Edit layout','e'); ?
>:</b
> 
;
608 <select name
='layout_id' id
='layout_id'>
609 <option value
=''>-- <?php
echo xl('Select') ?
> --</option
>
611 foreach ($layouts as $key => $value) {
612 echo " <option value='$key'";
613 if ($key == $layout_id) echo " selected";
614 echo ">$value</option>\n";
619 <?php
if ($layout_id) { ?
>
620 <div style
='margin: 0 0 8pt 0;'>
621 <input type
='button' class='addgroup' id
='addgroup' value
=<?php
xl('Add Group','e','\'','\''); ?
>/>
626 $prevgroup = "!@#asdf1234"; // an unlikely group name
627 $firstgroup = true; // flag indicates it's the first group to be displayed
628 while ($row = sqlFetchArray($res)) {
629 if ($row['group_name'] != $prevgroup) {
630 if ($firstgroup == false) { echo "</tbody></table></div>\n"; }
631 echo "<div id='".$row['group_name']."' class='group'>";
632 echo "<div class='text bold layouts_title' style='position:relative; background-color: #eef'>";
633 // echo preg_replace("/^\d+/", "", $row['group_name']);
634 echo substr($row['group_name'], 1);
636 // if not english and set to translate layout labels, then show the translation of group name
637 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
638 // echo "<span class='translation'>>> " . xl(preg_replace("/^\d+/", "", $row['group_name'])) . "</span>";
639 echo "<span class='translation'>>> " . xl(substr($row['group_name'], 1)) . "</span>";
643 echo " <input type='button' class='addfield' id='addto~".$row['group_name']."' value='" . xl('Add Field') . "'/>";
644 echo " ";
645 echo " <input type='button' class='renamegroup' id='".$row['group_name']."' value='" . xl('Rename Group') . "'/>";
646 echo " ";
647 echo " <input type='button' class='deletegroup' id='".$row['group_name']."' value='" . xl('Delete Group') . "'/>";
648 echo " ";
649 echo " <input type='button' class='movegroup' id='".$row['group_name']."~up' value='" . xl('Move Up') . "'/>";
650 echo " ";
651 echo " <input type='button' class='movegroup' id='".$row['group_name']."~down' value='" . xl('Move Down') . "'/>";
659 <th
><?php
xl('Order','e'); ?
></th
>
660 <th
><?php
xl('ID','e'); ?
> <span
class="help" title
=<?php
xl('A unique value to identify this field, not visible to the user','e','\'','\''); ?
> >(?
)</span
></th
>
661 <th
><?php
xl('Label','e'); ?
> <span
class="help" title
=<?php
xl('The label that appears to the user on the form','e','\'','\''); ?
> >(?
)</span
></th
>
662 <?php
// if not english and showing layout label translations, then show translation header for title
663 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
664 echo "<th>" . xl('Translation')."<span class='help' title='" . xl('The translated label that will appear on the form in current language') . "'> (?)</span></th>";
666 <th
><?php
xl('UOR','e'); ?
></th
>
667 <th
><?php
xl('Data Type','e'); ?
></th
>
668 <th
><?php
xl('Size','e'); ?
></th
>
669 <th
><?php
xl('Maximum Size','e'); ?
></th
>
670 <th
><?php
xl('List','e'); ?
></th
>
671 <th
><?php
xl('Label Cols','e'); ?
></th
>
672 <th
><?php
xl('Data Cols','e'); ?
></th
>
673 <th
><?php
xl('Options','e'); ?
></th
>
674 <th
><?php
xl('Description','e'); ?
></th
>
675 <?php
// if not english and showing layout label translations, then show translation header for description
676 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
677 echo "<th>" . xl('Translation')."<span class='help' title='" . xl('The translation of description in current language')."'> (?)</span></th>";
684 } // end if-group_name
686 writeFieldLine($row);
687 $prevgroup = $row['group_name'];
695 <?php
if ($layout_id) { ?
>
696 <span style
="font-size:90%">
697 <?php
xl('With selected:', 'e');?
>
698 <input type
='button' name
='deletefields' id
='deletefields' value
='<?php xl('Delete
','e
'); ?>' style
="font-size:90%" disabled
="disabled" />
699 <input type
='button' name
='movefields' id
='movefields' value
='<?php xl('Move to
...','e
'); ?>' style
="font-size:90%" disabled
="disabled" />
702 <input type
='button' name
='save' id
='save' value
='<?php xl('Save Changes
','e
'); ?>' />
708 <!-- template DIV that appears when user chooses to rename an existing group
-->
709 <div id
="renamegroupdetail" style
="border: 1px solid black; padding: 3px; display: none; visibility: hidden; background-color: lightgrey;">
710 <input type
="hidden" name
="renameoldgroupname" id
="renameoldgroupname" value
="">
711 <?php
xl('Group Name','e'); ?
>: <input type
="textbox" size
="20" maxlength
="30" name
="renamegroupname" id
="renamegroupname">
713 <input type
="button" class="saverenamegroup" value
=<?php
xl('Rename Group','e','\'','\''); ?
>>
714 <input type
="button" class="cancelrenamegroup" value
=<?php
xl('Cancel','e','\'','\''); ?
>>
717 <!-- template DIV that appears when user chooses to add a
new group
-->
718 <div id
="groupdetail" style
="border: 1px solid black; padding: 3px; display: none; visibility: hidden; background-color: lightgrey;">
720 <?php
xl('Group Name','e'); ?
>: <input type
="textbox" size
="20" maxlength
="30" name
="newgroupname" id
="newgroupname">
722 <table style
="border-collapse: collapse; margin-top: 5px;">
725 <th
><?php
xl('Order','e'); ?
></th
>
726 <th
><?php
xl('ID','e'); ?
> <span
class="help" title
=<?php
xl('A unique value to identify this field, not visible to the user','e','\'','\''); ?
> >(?
)</span
></th
>
727 <th
><?php
xl('Label','e'); ?
> <span
class="help" title
=<?php
xl('The label that appears to the user on the form','e','\'','\''); ?
> >(?
)</span
></th
>
728 <th
><?php
xl('UOR','e'); ?
></th
>
729 <th
><?php
xl('Data Type','e'); ?
></th
>
730 <th
><?php
xl('Size','e'); ?
></th
>
731 <th
><?php
xl('Maximum Size','e'); ?
></th
>
732 <th
><?php
xl('List','e'); ?
></th
>
733 <th
><?php
xl('Label Cols','e'); ?
></th
>
734 <th
><?php
xl('Data Cols','e'); ?
></th
>
735 <th
><?php
xl('Options','e'); ?
></th
>
736 <th
><?php
xl('Description','e'); ?
></th
>
741 <td
><input type
="textbox" name
="gnewseq" id
="gnewseq" value
="" size
="2" maxlength
="3"> </td
>
742 <td
><input type
="textbox" name
="gnewid" id
="gnewid" value
="" size
="10" maxlength
="20"> </td
>
743 <td
><input type
="textbox" name
="gnewtitle" id
="gnewtitle" value
="" size
="20" maxlength
="63"> </td
>
745 <select name
="gnewuor" id
="gnewuor">
746 <option value
="0"><?php
xl('Unused','e'); ?
></option
>
747 <option value
="1" selected
><?php
xl('Optional','e'); ?
></option
>
748 <option value
="2"><?php
xl('Required','e'); ?
></option
>
752 <select name
='gnewdatatype' id
='gnewdatatype'>
753 <option value
=''></option
>
756 foreach ($datatypes as $key=>$value) {
757 echo "<option value='$key'>$value</option>";
762 <td
><input type
="textbox" name
="gnewlengthWidth" id
="gnewlengthWidth" value
="" size
="1" maxlength
="3" title
="<?php echo xla('Width'); ?>">
763 <input type
="textbox" name
="gnewlengthHeight" id
="gnewlengthHeight" value
="" size
="1" maxlength
="3" title
="<?php echo xla('Height'); ?>"></td
>
764 <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
>
765 <td
><input type
="textbox" name
="gnewlistid" id
="gnewlistid" value
="" size
="8" maxlength
="31" class="listid">
766 <select name
='gcontextName' id
='gcontextName' style
='display:none'>
768 $res = sqlStatement("SELECT * FROM customlists WHERE cl_list_type=2 AND cl_deleted=0");
769 while($row = sqlFetchArray($res)){
770 echo "<option value='".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES
)."'>".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES
)."</option>";
775 <td
><input type
="textbox" name
="gnewtitlecols" id
="gnewtitlecols" value
="" size
="3" maxlength
="3"> </td
>
776 <td
><input type
="textbox" name
="gnewdatacols" id
="gnewdatacols" value
="" size
="3" maxlength
="3"> </td
>
777 <td
><input type
="textbox" name
="gnewedit_options" id
="gnewedit_options" value
="" size
="3" maxlength
="36">
778 <input type
="hidden" name
="gnewdefault" id
="gnewdefault" value
="" /> </td
>
779 <td
><input type
="textbox" name
="gnewdesc" id
="gnewdesc" value
="" size
="30" maxlength
="63"> </td
>
784 <input type
="button" class="savenewgroup" value
=<?php
xl('Save New Group','e','\'','\''); ?
>>
785 <input type
="button" class="cancelnewgroup" value
=<?php
xl('Cancel','e','\'','\''); ?
>>
789 <!-- template DIV that appears when user chooses to add a
new field to a group
-->
790 <div id
="fielddetail" class="fielddetail" style
="display: none; visibility: hidden">
791 <input type
="hidden" name
="newfieldgroupid" id
="newfieldgroupid" value
="">
792 <table style
="border-collapse: collapse;">
795 <th
><?php
xl('Order','e'); ?
></th
>
796 <th
><?php
xl('ID','e'); ?
> <span
class="help" title
=<?php
xl('A unique value to identify this field, not visible to the user','e','\'','\''); ?
> >(?
)</span
></th
>
797 <th
><?php
xl('Label','e'); ?
> <span
class="help" title
=<?php
xl('The label that appears to the user on the form','e','\'','\''); ?
> >(?
)</span
></th
>
798 <th
><?php
xl('UOR','e'); ?
></th
>
799 <th
><?php
xl('Data Type','e'); ?
></th
>
800 <th
><?php
xl('Size','e'); ?
></th
>
801 <th
><?php
xl('Maximum Size','e'); ?
></th
>
802 <th
><?php
xl('List','e'); ?
></th
>
803 <th
><?php
xl('Label Cols','e'); ?
></th
>
804 <th
><?php
xl('Data Cols','e'); ?
></th
>
805 <th
><?php
xl('Options','e'); ?
></th
>
806 <th
><?php
xl('Description','e'); ?
></th
>
811 <td
><input type
="textbox" name
="newseq" id
="newseq" value
="" size
="2" maxlength
="3"> </td
>
812 <td
><input type
="textbox" name
="newid" id
="newid" value
="" size
="10" maxlength
="20"> </td
>
813 <td
><input type
="textbox" name
="newtitle" id
="newtitle" value
="" size
="20" maxlength
="63"> </td
>
815 <select name
="newuor" id
="newuor">
816 <option value
="0"><?php
xl('Unused','e'); ?
></option
>
817 <option value
="1" selected
><?php
xl('Optional','e'); ?
></option
>
818 <option value
="2"><?php
xl('Required','e'); ?
></option
>
822 <select name
='newdatatype' id
='newdatatype'>
823 <option value
=''></option
>
826 foreach ($datatypes as $key=>$value) {
827 echo " <option value='$key'>$value</option>\n";
832 <td
><input type
="textbox" name
="newlengthWidth" id
="newlengthWidth" value
="" size
="1" maxlength
="3" title
="<?php echo xla('Width'); ?>">
833 <input type
="textbox" name
="newlengthHeight" id
="newlengthHeight" value
="" size
="1" maxlength
="3" title
="<?php echo xla('Height'); ?>"></td
>
834 <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
>
835 <td
><input type
="textbox" name
="newlistid" id
="newlistid" value
="" size
="8" maxlength
="31" class="listid">
836 <select name
='contextName' id
='contextName' style
='display:none'>
838 $res = sqlStatement("SELECT * FROM customlists WHERE cl_list_type=2 AND cl_deleted=0");
839 while($row = sqlFetchArray($res)){
840 echo "<option value='".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES
)."'>".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES
)."</option>";
845 <td
><input type
="textbox" name
="newtitlecols" id
="newtitlecols" value
="" size
="3" maxlength
="3"> </td
>
846 <td
><input type
="textbox" name
="newdatacols" id
="newdatacols" value
="" size
="3" maxlength
="3"> </td
>
847 <td
><input type
="textbox" name
="newedit_options" id
="newedit_options" value
="" size
="3" maxlength
="36">
848 <input type
="hidden" name
="newdefault" id
="newdefault" value
="" /> </td
>
849 <td
><input type
="textbox" name
="newdesc" id
="newdesc" value
="" size
="30" maxlength
="63"> </td
>
853 <input type
="button" class="savenewfield" value
=<?php
xl('Save New Field','e','\'','\''); ?
>>
854 <input type
="button" class="cancelnewfield" value
=<?php
xl('Cancel','e','\'','\''); ?
>>
863 <script language
="javascript">
865 // used when selecting a list-name for a field
868 // jQuery stuff to make the page a little easier to use
870 $
(document
).ready(function(){
871 $
("#save").click(function() { SaveChanges(); });
872 $
("#layout_id").change(function() { $
('#theform').submit(); });
874 $
(".addgroup").click(function() { AddGroup(this
); });
875 $
(".savenewgroup").click(function() { SaveNewGroup(this
); });
876 $
(".deletegroup").click(function() { DeleteGroup(this
); });
877 $
(".cancelnewgroup").click(function() { CancelNewGroup(this
); });
879 $
(".movegroup").click(function() { MoveGroup(this
); });
881 $
(".renamegroup").click(function() { RenameGroup(this
); });
882 $
(".saverenamegroup").click(function() { SaveRenameGroup(this
); });
883 $
(".cancelrenamegroup").click(function() { CancelRenameGroup(this
); });
885 $
(".addfield").click(function() { AddField(this
); });
886 $
("#deletefields").click(function() { DeleteFields(this
); });
887 $
(".selectfield").click(function() {
888 var TRparent
= $
(this
).parent().parent();
889 $
(TRparent
).children("td").toggleClass("highlight");
890 // disable the delete-move buttons
891 $
("#deletefields").attr("disabled", "disabled");
892 $
("#movefields").attr("disabled", "disabled");
893 $
(".selectfield").each(function(i
) {
894 // if any field is selected, enable the delete-move buttons
895 if ($
(this
).attr("checked") == true) {
896 $
("#deletefields").removeAttr("disabled");
897 $
("#movefields").removeAttr("disabled");
901 $
("#movefields").click(function() { ShowGroups(this
); });
902 $
(".savenewfield").click(function() { SaveNewField(this
); });
903 $
(".cancelnewfield").click(function() { CancelNewField(this
); });
904 $
("#newtitle").blur(function() { if ($
("#newid").val() == "") $
("#newid").val($
("#newtitle").val()); });
905 $
("#newdatatype").change(function() { ChangeList(this
.value
);});
906 $
("#gnewdatatype").change(function() { ChangeListg(this
.value
);});
907 $
(".listid").click(function() { ShowLists(this
); });
909 // special class that skips the element
910 $
(".noselect").focus(function() { $
(this
).blur(); });
912 // Save the changes made to the form
913 var SaveChanges
= function () {
914 $
("#formaction").val("save");
915 $
("#theform").submit();
918 /****************************************************/
919 /************ Group functions ***********************/
920 /****************************************************/
922 // display the 'new group' DIV
923 var AddGroup
= function(btnObj
) {
924 // show the field details DIV
925 $
('#groupdetail').css('visibility', 'visible');
926 $
('#groupdetail').css('display', 'block');
927 $
(btnObj
).parent().append($
("#groupdetail"));
928 $
('#groupdetail > #newgroupname').focus();
931 // save the new group to the form
932 var SaveNewGroup
= function(btnObj
) {
933 // the group name field can only have letters, numbers, spaces and underscores
934 // AND it cannot start with a number
935 if ($
("#newgroupname").val() == "") {
936 alert("<?php xl('Group names cannot be blank', 'e'); ?>");
939 if ($
("#newgroupname").val().match(/^
(\d+|\s+
)/)) {
940 alert("<?php xl('Group names cannot start with numbers or spaces.','e'); ?>");
943 var validname
= $
("#newgroupname").val().replace(/[^A
-za
-z0
-9 ]/g
, "_"); // match any non-word characters and replace them
944 $
("#newgroupname").val(validname
);
946 // now, check the first group field values
948 // seq must be numeric and less than 999
949 if (! IsNumeric($
("#gnewseq").val(), 0, 999)) {
950 alert("<?php xl('Order must be a number between 1 and 999','e'); ?>");
953 // length must be numeric and less than 999
954 if (! IsNumeric($
("#gnewlengthWidth").val(), 0, 999)) {
955 alert("<?php xl('Size must be a number between 1 and 999','e'); ?>");
958 // titlecols must be numeric and less than 100
959 if (! IsNumeric($
("#gnewtitlecols").val(), 0, 999)) {
960 alert("<?php xl('LabelCols must be a number between 1 and 999','e'); ?>");
963 // datacols must be numeric and less than 100
964 if (! IsNumeric($
("#gnewdatacols").val(), 0, 999)) {
965 alert("<?php xl('DataCols must be a number between 1 and 999','e'); ?>");
968 // some fields cannot be blank
969 if ($
("#gnewtitle").val() == "") {
970 alert("<?php xl('Label cannot be blank','e'); ?>");
973 // the id field can only have letters, numbers and underscores
974 if ($
("#gnewid").val() == "") {
975 alert("<?php xl('ID cannot be blank', 'e'); ?>");
978 var validid
= $
("#gnewid").val().replace(/(\s|\W
)/g
, "_"); // match any non-word characters and replace them
979 $
("#gnewid").val(validid
);
980 // similarly with the listid field
981 validid
= $
("#gnewlistid").val().replace(/(\s|\W
)/g
, "_");
982 $
("#gnewlistid").val(validid
);
984 // submit the form to add a new field to a specific group
985 $
("#formaction").val("addgroup");
986 $
("#theform").submit();
989 // actually delete an entire group from the database
990 var DeleteGroup
= function(btnObj
) {
991 var parts
= $
(btnObj
).attr("id");
992 var groupname
= parts
.replace(/^\d+
/, "");
993 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+
"'?")) {
994 // submit the form to add a new field to a specific group
995 $
("#formaction").val("deletegroup");
996 $
("#deletegroupname").val(parts
);
997 $
("#theform").submit();
1001 // just hide the new field DIV
1002 var CancelNewGroup
= function(btnObj
) {
1003 // hide the field details DIV
1004 $
('#groupdetail').css('visibility', 'hidden');
1005 $
('#groupdetail').css('display', 'none');
1006 // reset the new group values to a default
1007 $
('#groupdetail > #newgroupname').val("");
1010 // display the 'new field' DIV
1011 var MoveGroup
= function(btnObj
) {
1012 var btnid
= $
(btnObj
).attr("id");
1013 var parts
= btnid
.split("~");
1014 var groupid
= parts
[0];
1015 var direction
= parts
[1];
1017 // submit the form to change group order
1018 $
("#formaction").val("movegroup");
1019 $
("#movegroupname").val(groupid
);
1020 $
("#movedirection").val(direction
);
1021 $
("#theform").submit();
1024 // show the rename group DIV
1025 var RenameGroup
= function(btnObj
) {
1026 $
('#renamegroupdetail').css('visibility', 'visible');
1027 $
('#renamegroupdetail').css('display', 'block');
1028 $
(btnObj
).parent().append($
("#renamegroupdetail"));
1029 $
('#renameoldgroupname').val($
(btnObj
).attr("id"));
1030 $
('#renamegroupname').val($
(btnObj
).attr("id").replace(/^\d+
/, ""));
1033 // save the new group to the form
1034 var SaveRenameGroup
= function(btnObj
) {
1035 // the group name field can only have letters, numbers, spaces and underscores
1036 // AND it cannot start with a number
1037 if ($
("#renamegroupname").val().match(/^\d+
/)) {
1038 alert("<?php xl('Group names cannot start with numbers.','e'); ?>");
1041 var validname
= $
("#renamegroupname").val().replace(/[^A
-za
-z0
-9 ]/g
, "_"); // match any non-word characters and replace them
1042 $
("#renamegroupname").val(validname
);
1044 // submit the form to add a new field to a specific group
1045 $
("#formaction").val("renamegroup");
1046 $
("#theform").submit();
1049 // just hide the new field DIV
1050 var CancelRenameGroup
= function(btnObj
) {
1051 // hide the field details DIV
1052 $
('#renamegroupdetail').css('visibility', 'hidden');
1053 $
('#renamegroupdetail').css('display', 'none');
1054 // reset the rename group values to a default
1055 $
('#renameoldgroupname').val("");
1056 $
('#renamegroupname').val("");
1059 /****************************************************/
1060 /************ Field functions ***********************/
1061 /****************************************************/
1063 // display the 'new field' DIV
1064 var AddField
= function(btnObj
) {
1065 // update the fieldgroup value to be the groupid
1066 var btnid
= $
(btnObj
).attr("id");
1067 var parts
= btnid
.split("~");
1068 var groupid
= parts
[1];
1069 $
('#fielddetail > #newfieldgroupid').attr('value', groupid
);
1071 // show the field details DIV
1072 $
('#fielddetail').css('visibility', 'visible');
1073 $
('#fielddetail').css('display', 'block');
1074 $
(btnObj
).parent().append($
("#fielddetail"));
1077 var DeleteFields
= function(btnObj
) {
1078 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'); ?>")) {
1080 $
(".selectfield").each(function(i
) {
1081 // build a list of selected field names to be moved
1082 if ($
(this
).attr("checked") == true) {
1083 var parts
= this
.id
.split("~");
1084 var currval
= $
("#selectedfields").val();
1085 $
("#selectedfields").val(currval+delim+parts
[1]);
1089 // submit the form to delete the field(s)
1090 $
("#formaction").val("deletefields");
1091 $
("#theform").submit();
1095 // save the new field to the form
1096 var SaveNewField
= function(btnObj
) {
1097 // check the new field values for correct formatting
1099 // seq must be numeric and less than 999
1100 if (! IsNumeric($
("#newseq").val(), 0, 999)) {
1101 alert("<?php xl('Order must be a number between 1 and 999','e'); ?>");
1104 // length must be numeric and less than 999
1105 if (! IsNumeric($
("#newlengthWidth").val(), 0, 999)) {
1106 alert("<?php xl('Size must be a number between 1 and 999','e'); ?>");
1109 // titlecols must be numeric and less than 100
1110 if (! IsNumeric($
("#newtitlecols").val(), 0, 999)) {
1111 alert("<?php xl('LabelCols must be a number between 1 and 999','e'); ?>");
1114 // datacols must be numeric and less than 100
1115 if (! IsNumeric($
("#newdatacols").val(), 0, 999)) {
1116 alert("<?php xl('DataCols must be a number between 1 and 999','e'); ?>");
1119 // some fields cannot be blank
1120 if ($
("#newtitle").val() == "") {
1121 alert("<?php xl('Label cannot be blank','e'); ?>");
1124 // the id field can only have letters, numbers and underscores
1125 var validid
= $
("#newid").val().replace(/(\s|\W
)/g
, "_"); // match any non-word characters and replace them
1126 $
("#newid").val(validid
);
1127 // similarly with the listid field
1128 validid
= $
("#newlistid").val().replace(/(\s|\W
)/g
, "_");
1129 $
("#newlistid").val(validid
);
1131 // submit the form to add a new field to a specific group
1132 $
("#formaction").val("addfield");
1133 $
("#theform").submit();
1136 // just hide the new field DIV
1137 var CancelNewField
= function(btnObj
) {
1138 // hide the field details DIV
1139 $
('#fielddetail').css('visibility', 'hidden');
1140 $
('#fielddetail').css('display', 'none');
1141 // reset the new field values to a default
1142 ResetNewFieldValues();
1145 // show the popup choice of lists
1146 var ShowLists
= function(btnObj
) {
1147 window
.open("./show_lists_popup.php", "lists", "width=300,height=500,scrollbars=yes");
1148 selectedfield
= btnObj
;
1151 // show the popup choice of groups
1152 var ShowGroups
= function(btnObj
) {
1153 window
.open("./show_groups_popup.php?layout_id=<?php echo $layout_id;?>", "groups", "width=300,height=300,scrollbars=yes");
1156 // Show context DD for NationNotes
1157 var ChangeList
= function(btnObj
){
1159 $
('#newlistid').hide();
1160 $
('#contextName').show();
1163 $
('#newlistid').show();
1164 $
('#contextName').hide();
1167 var ChangeListg
= function(btnObj
){
1169 $
('#gnewlistid').hide();
1170 $
('#gcontextName').show();
1173 $
('#gnewlistid').show();
1174 $
('#gcontextName').hide();
1180 function NationNotesContext(lineitem
,val
){
1182 document
.getElementById("fld["+lineitem+
"][contextName]").style
.display
='';
1183 document
.getElementById("fld["+lineitem+
"][list_id]").style
.display
='none';
1184 document
.getElementById("fld["+lineitem+
"][list_id]").value
='';
1187 document
.getElementById("fld["+lineitem+
"][list_id]").style
.display
='';
1188 document
.getElementById("fld["+lineitem+
"][contextName]").style
.display
='none';
1189 document
.getElementById("fld["+lineitem+
"][list_id]").value
='';
1192 function SetList(listid
) { $
(selectedfield
).val(listid
); }
1195 /* this is called after the user chooses a new group from the popup window
1196 * it will submit the page so the selected fields can be moved into
1199 function MoveFields(targetgroup
) {
1200 $
("#targetgroup").val(targetgroup
);
1202 $
(".selectfield").each(function(i
) {
1203 // build a list of selected field names to be moved
1204 if ($
(this
).attr("checked") == true) {
1205 var parts
= this
.id
.split("~");
1206 var currval
= $
("#selectedfields").val();
1207 $
("#selectedfields").val(currval+delim+parts
[1]);
1211 $
("#formaction").val("movefields");
1212 $
("#theform").submit();
1216 // set the new-field values to a default state
1217 function ResetNewFieldValues () {
1218 $
("#newseq").val("");
1219 $
("#newid").val("");
1220 $
("#newtitle").val("");
1221 $
("#newuor").val(1);
1222 $
("#newlengthWidth").val("");
1223 $
("#newlengthHeight").val("");
1224 $
("#newmaxSize").val("");
1225 $
("#newdatatype").val("");
1226 $
("#newlistid").val("");
1227 $
("#newtitlecols").val("");
1228 $
("#newdatacols").val("");
1229 $
("#newedit_options").val("");
1230 $
("#newdefault").val("");
1231 $
("#newdesc").val("");
1234 // is value an integer and between min and max
1235 function IsNumeric(value
, min
, max
) {
1236 if (value
== "" || value
== null) return false;
1238 parseInt(value
) < min ||
1239 parseInt(value
) > max
)
1245 /****************************************************/
1246 /****************************************************/
1247 /****************************************************/
1249 // tell if num is an Integer
1250 function IsN(num
) { return !/\D
/.test(num
); }