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 "16" => xl("Insurances"),
46 "21" => xl("Checkbox list"),
47 "22" => xl("Textbox list"),
48 "23" => xl("Exam results"),
49 "24" => xl("Patient allergies"),
50 "25" => xl("Checkbox w/text"),
51 "26" => xl("List box w/add"),
52 "27" => xl("Radio buttons"),
53 "28" => xl("Lifestyle status"),
54 "31" => xl("Static Text"),
55 "32" => xl("Smoking Status"),
56 "33" => xl("Race and Ethnicity"),
57 "34" => xl("NationNotes"),
58 "35" => xl("Facilities"),
59 "36" => xl("Multiple Select List")
62 function nextGroupOrder($order) {
63 if ($order == '9') $order = 'A';
64 else if ($order == 'Z') $order = 'a';
65 else $order = chr(ord($order) +
1);
69 // Check authorization.
70 $thisauth = acl_check('admin', 'super');
71 if (!$thisauth) die(xl('Not authorized'));
73 // The layout ID identifies the layout to be edited.
74 $layout_id = empty($_REQUEST['layout_id']) ?
'' : $_REQUEST['layout_id'];
76 // Handle the Form actions
78 if ($_POST['formaction'] == "save" && $layout_id) {
79 // If we are saving, then save.
81 for ($lino = 1; isset($fld[$lino]['id']); ++
$lino) {
83 $field_id = formTrim($iter['id']);
84 $data_type = formTrim($iter['data_type']);
85 $listval = $data_type == 34 ?
formTrim($iter['contextName']) : formTrim($iter['list_id']);
87 sqlStatement("UPDATE layout_options SET " .
88 "title = '" . formTrim($iter['title']) . "', " .
89 "group_name = '" . formTrim($iter['group']) . "', " .
90 "seq = '" . formTrim($iter['seq']) . "', " .
91 "uor = '" . formTrim($iter['uor']) . "', " .
92 "fld_length = '" . formTrim($iter['lengthWidth']) . "', " .
93 "fld_rows = '" . formTrim($iter['lengthHeight']) . "', " .
94 "max_length = '" . formTrim($iter['maxSize']) . "', " .
95 "titlecols = '" . formTrim($iter['titlecols']) . "', " .
96 "datacols = '" . formTrim($iter['datacols']) . "', " .
97 "data_type= '$data_type', " .
98 "list_id= '" . $listval . "', " .
99 "list_backup_id= '" . formTrim($iter['list_backup_id']) . "', " .
100 "edit_options = '" . formTrim($iter['edit_options']) . "', " .
101 "default_value = '" . formTrim($iter['default']) . "', " .
102 "description = '" . formTrim($iter['desc']) . "' " .
103 "WHERE form_id = '$layout_id' AND field_id = '$field_id'");
108 else if ($_POST['formaction'] == "addfield" && $layout_id) {
109 // Add a new field to a specific group
110 $data_type = formTrim($_POST['newdatatype']);
111 $max_length = $data_type == 3 ?
3 : 255;
112 $listval = $data_type == 34 ?
formTrim($_POST['contextName']) : formTrim($_POST['newlistid']);
113 sqlStatement("INSERT INTO layout_options (" .
114 " form_id, field_id, title, group_name, seq, uor, fld_length, fld_rows" .
115 ", titlecols, datacols, data_type, edit_options, default_value, description" .
116 ", max_length, list_id, list_backup_id " .
118 "'" . formTrim($_POST['layout_id'] ) . "'" .
119 ",'" . formTrim($_POST['newid'] ) . "'" .
120 ",'" . formTrim($_POST['newtitle'] ) . "'" .
121 ",'" . formTrim($_POST['newfieldgroupid']) . "'" .
122 ",'" . formTrim($_POST['newseq'] ) . "'" .
123 ",'" . formTrim($_POST['newuor'] ) . "'" .
124 ",'" . formTrim($_POST['newlengthWidth'] ) . "'" .
125 ",'" . formTrim($_POST['newlengthHeight'] ) . "'" .
126 ",'" . formTrim($_POST['newtitlecols'] ) . "'" .
127 ",'" . formTrim($_POST['newdatacols'] ) . "'" .
129 ",'" . formTrim($_POST['newedit_options']) . "'" .
130 ",'" . formTrim($_POST['newdefault'] ) . "'" .
131 ",'" . formTrim($_POST['newdesc'] ) . "'" .
132 ",'" . formTrim($_POST['newmaxSize']) . "'" .
133 ",'" . $listval . "'" .
134 ",'" . formTrim($_POST['newbackuplistid']) . "'" .
137 if (substr($layout_id,0,3) != 'LBF' && $layout_id != "FACUSR") {
138 // Add the field to the table too (this is critical)
139 if ($layout_id == "DEM") { $tablename = "patient_data"; }
140 else if ($layout_id == "HIS") { $tablename = "history_data"; }
141 else if ($layout_id == "REF") { $tablename = "transactions"; }
142 else if ($layout_id == "SRH") { $tablename = "lists_ippf_srh"; }
143 else if ($layout_id == "CON") { $tablename = "lists_ippf_con"; }
144 else if ($layout_id == "GCA") { $tablename = "lists_ippf_gcac"; }
145 sqlStatement("ALTER TABLE `" . $tablename . "` ADD ".
146 "`" . formTrim($_POST['newid']) . "`" .
148 newEvent("alter_table", $_SESSION['authUser'], $_SESSION['authProvider'], 1,
149 $tablename . " ADD " . formTrim($_POST['newid']));
153 else if ($_POST['formaction'] == "movefields" && $layout_id) {
154 // Move field(s) to a new group in the layout
155 $sqlstmt = "UPDATE layout_options SET ".
156 " group_name='". $_POST['targetgroup']."' ".
158 " form_id = '".$_POST['layout_id']."' ".
159 " AND field_id IN (";
161 foreach (explode(" ", $_POST['selectedfields']) as $onefield) {
162 $sqlstmt .= $comma."'".$onefield."'";
167 sqlStatement($sqlstmt);
170 else if ($_POST['formaction'] == "deletefields" && $layout_id) {
171 // Delete a field from a specific group
172 $sqlstmt = "DELETE FROM layout_options WHERE ".
173 " form_id = '".$_POST['layout_id']."' ".
174 " AND field_id IN (";
176 foreach (explode(" ", $_POST['selectedfields']) as $onefield) {
177 $sqlstmt .= $comma."'".$onefield."'";
181 sqlStatement($sqlstmt);
183 if (substr($layout_id,0,3) != 'LBF' && $layout_id != "FACUSR") {
184 // drop the field from the table too (this is critical)
185 if ($layout_id == "DEM") { $tablename = "patient_data"; }
186 else if ($layout_id == "HIS") { $tablename = "history_data"; }
187 else if ($layout_id == "REF") { $tablename = "transactions"; }
188 else if ($layout_id == "SRH") { $tablename = "lists_ippf_srh"; }
189 else if ($layout_id == "CON") { $tablename = "lists_ippf_con"; }
190 else if ($layout_id == "GCA") { $tablename = "lists_ippf_gcac"; }
191 foreach (explode(" ", $_POST['selectedfields']) as $onefield) {
192 sqlStatement("ALTER TABLE `".$tablename."` DROP `".$onefield."`");
193 newEvent("alter_table", $_SESSION['authUser'], $_SESSION['authProvider'], 1, $tablename." DROP ".$onefield);
198 else if ($_POST['formaction'] == "addgroup" && $layout_id) {
199 // all group names are prefixed with a number indicating their display order
200 // this new group is prefixed with the net highest number given the
202 $results = sqlStatement("select distinct(group_name) as gname ".
203 " from layout_options where ".
204 " form_id = '".$_POST['layout_id']."'"
207 while ($result = sqlFetchArray($results)) {
208 $tmp = substr($result['gname'], 0, 1);
209 if ($tmp >= $maxnum) $maxnum = nextGroupOrder($tmp);
212 $data_type = formTrim($_POST['gnewdatatype']);
213 $max_length = $data_type == 3 ?
3 : 255;
214 $listval = $data_type == 34 ?
formTrim($_POST['gcontextName']) : formTrim($_POST['gnewlistid']);
215 // add a new group to the layout, with the defined field
216 sqlStatement("INSERT INTO layout_options (" .
217 " form_id, field_id, title, group_name, seq, uor, fld_length, fld_rows" .
218 ", titlecols, datacols, data_type, edit_options, default_value, description" .
219 ", max_length, list_id, list_backup_id " .
221 "'" . formTrim($_POST['layout_id'] ) . "'" .
222 ",'" . formTrim($_POST['gnewid'] ) . "'" .
223 ",'" . formTrim($_POST['gnewtitle'] ) . "'" .
224 ",'" . formTrim($maxnum . $_POST['newgroupname']) . "'" .
225 ",'" . formTrim($_POST['gnewseq'] ) . "'" .
226 ",'" . formTrim($_POST['gnewuor'] ) . "'" .
227 ",'" . formTrim($_POST['gnewlengthWidth'] ) . "'" .
228 ",'" . formTrim($_POST['gnewlengthHeight'] ) . "'" .
229 ",'" . formTrim($_POST['gnewtitlecols'] ) . "'" .
230 ",'" . formTrim($_POST['gnewdatacols'] ) . "'" .
232 ",'" . formTrim($_POST['gnewedit_options']) . "'" .
233 ",'" . formTrim($_POST['gnewdefault'] ) . "'" .
234 ",'" . formTrim($_POST['gnewdesc'] ) . "'" .
235 ",'" . formTrim($_POST['gnewmaxSize']) . "'" .
236 ",'" . $listval . "'" .
237 ",'" . formTrim($_POST['gnewbackuplistid'] ) . "'" .
240 if (substr($layout_id,0,3) != 'LBF' && $layout_id != "FACUSR") {
241 // Add the field to the table too (this is critical)
242 if ($layout_id == "DEM") { $tablename = "patient_data"; }
243 else if ($layout_id == "HIS") { $tablename = "history_data"; }
244 else if ($layout_id == "REF") { $tablename = "transactions"; }
245 else if ($layout_id == "SRH") { $tablename = "lists_ippf_srh"; }
246 else if ($layout_id == "CON") { $tablename = "lists_ippf_con"; }
247 else if ($layout_id == "GCA") { $tablename = "lists_ippf_gcac"; }
248 sqlStatement("ALTER TABLE `" . $tablename . "` ADD ".
249 "`" . formTrim($_POST['gnewid']) . "`" .
251 newEvent("alter_table", $_SESSION['authUser'], $_SESSION['authProvider'], 1,
252 $tablename . " ADD " . formTrim($_POST['gnewid']));
256 else if ($_POST['formaction'] == "deletegroup" && $layout_id) {
257 // drop the fields from the related table (this is critical)
258 if (substr($layout_id,0,3) != 'LBF' && $layout_id != "FACUSR") {
259 $res = sqlStatement("SELECT field_id FROM layout_options WHERE " .
260 " form_id = '".$_POST['layout_id']."' ".
261 " AND group_name = '".$_POST['deletegroupname']."'"
263 while ($row = sqlFetchArray($res)) {
264 // drop the field from the table too (this is critical)
265 if ($layout_id == "DEM") { $tablename = "patient_data"; }
266 else if ($layout_id == "HIS") { $tablename = "history_data"; }
267 else if ($layout_id == "REF") { $tablename = "transactions"; }
268 else if ($layout_id == "SRH") { $tablename = "lists_ippf_srh"; }
269 else if ($layout_id == "CON") { $tablename = "lists_ippf_con"; }
270 else if ($layout_id == "GCA") { $tablename = "lists_ippf_gcac"; }
271 sqlStatement("ALTER TABLE `".$tablename."` DROP `".$row['field_id']."`");
272 newEvent("alter_table", $_SESSION['authUser'], $_SESSION['authProvider'], 1, $tablename." DROP ".trim($row['field_id']));
276 // Delete an entire group from the form
277 sqlStatement("DELETE FROM layout_options WHERE ".
278 " form_id = '".$_POST['layout_id']."' ".
279 " AND group_name = '".$_POST['deletegroupname']."'"
283 else if ($_POST['formaction'] == "movegroup" && $layout_id) {
284 $results = sqlStatement("SELECT DISTINCT(group_name) AS gname " .
285 "FROM layout_options WHERE form_id = '$layout_id' " .
289 while ($result = sqlFetchArray($results)) {
290 if ($result['gname'] == $_POST['movegroupname']) {
291 if ($_POST['movedirection'] == 'up') { // moving up
293 $garray[$i] = $garray[$i - 1];
294 $garray[$i - 1] = $result['gname'];
298 $garray[$i++
] = $result['gname'];
301 else { // moving down
303 $garray[$i++
] = $result['gname'];
306 else if ($i > 1 && $garray[$i - 2] == '') {
307 $garray[$i - 2] = $result['gname'];
310 $garray[$i++
] = $result['gname'];
314 foreach ($garray as $value) {
315 if ($value === '') continue;
316 $newname = $nextord . substr($value, 1);
317 sqlStatement("UPDATE layout_options SET " .
318 "group_name = '$newname' WHERE " .
319 "form_id = '$layout_id' AND " .
320 "group_name = '$value'");
321 $nextord = nextGroupOrder($nextord);
325 else if ($_POST['formaction'] == "renamegroup" && $layout_id) {
326 $currpos = substr($_POST['renameoldgroupname'], 0, 1);
327 // update the database rows
328 sqlStatement("UPDATE layout_options SET " .
329 "group_name = '" . $currpos . $_POST['renamegroupname'] . "' ".
330 "WHERE form_id = '$layout_id' AND ".
331 "group_name = '" . $_POST['renameoldgroupname'] . "'");
334 // Get the selected form's elements.
336 $res = sqlStatement("SELECT * FROM layout_options WHERE " .
337 "form_id = '$layout_id' ORDER BY group_name, seq");
340 // global counter for field numbers
343 // Write one option line to the form.
345 function writeFieldLine($linedata) {
348 $checked = $linedata['default_value'] ?
" checked" : "";
350 //echo " <tr bgcolor='$bgcolor'>\n";
351 echo " <tr id='fld[$fld_line_no]' class='".($fld_line_no %
2 ?
'even' : 'odd')."'>\n";
353 echo " <td class='optcell' nowrap>";
354 // tuck the group_name INPUT in here
355 echo "<input type='hidden' name='fld[$fld_line_no][group]' value='" .
356 htmlspecialchars($linedata['group_name'], ENT_QUOTES
) . "' class='optin' />";
358 echo "<input type='checkbox' class='selectfield' ".
359 "name='".$linedata['group_name']."~".$linedata['field_id']."' ".
360 "id='".$linedata['group_name']."~".$linedata['field_id']."' ".
361 "title='".htmlspecialchars(xl('Select field', ENT_QUOTES
))."'>";
363 echo "<input type='text' name='fld[$fld_line_no][seq]' id='fld[$fld_line_no][seq]' value='" .
364 htmlspecialchars($linedata['seq'], ENT_QUOTES
) . "' size='2' maxlength='3' class='optin' />";
367 echo " <td align='left' class='optcell'>";
368 echo "<input type='text' name='fld[$fld_line_no][id]' value='" .
369 htmlspecialchars($linedata['field_id'], ENT_QUOTES
) . "' size='15' maxlength='63' class='optin noselect' />";
371 echo "<input type='hidden' name='fld[$fld_line_no][id]' value='" .
372 htmlspecialchars($linedata['field_id'], ENT_QUOTES) . "' />";
373 echo htmlspecialchars($linedata['field_id'], ENT_QUOTES);
377 echo " <td align='center' class='optcell'>";
378 echo "<input type='text' id='fld[$fld_line_no][title]' name='fld[$fld_line_no][title]' value='" .
379 htmlspecialchars($linedata['title'], ENT_QUOTES
) . "' size='15' maxlength='63' class='optin' />";
382 // if not english and set to translate layout labels, then show the translation
383 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
384 echo "<td align='center' class='translation'>" . htmlspecialchars(xl($linedata['title']), ENT_QUOTES
) . "</td>\n";
387 echo " <td align='center' class='optcell'>";
388 echo "<select name='fld[$fld_line_no][uor]' class='optin'>";
389 foreach (array(0 =>xl('Unused'), 1 =>xl('Optional'), 2 =>xl('Required')) as $key => $value) {
390 echo "<option value='$key'";
391 if ($key == $linedata['uor']) echo " selected";
392 echo ">$value</option>\n";
397 echo " <td align='center' class='optcell'>";
398 echo "<select name='fld[$fld_line_no][data_type]' id='fld[$fld_line_no][data_type]' onchange=NationNotesContext('".$fld_line_no."',this.value)>";
399 echo "<option value=''></option>";
401 foreach ($datatypes as $key=>$value) {
402 if ($linedata['data_type'] == $key)
403 echo "<option value='$key' selected>$value</option>";
405 echo "<option value='$key'>$value</option>";
410 echo " <td align='center' class='optcell'>";
411 if ($linedata['data_type'] == 2 ||
$linedata['data_type'] == 3 ||
412 $linedata['data_type'] == 21 ||
$linedata['data_type'] == 22 ||
413 $linedata['data_type'] == 23 ||
$linedata['data_type'] == 25 ||
414 $linedata['data_type'] == 27 ||
$linedata['data_type'] == 28 ||
415 $linedata['data_type'] == 32)
417 // Show the width field
418 echo "<input type='text' name='fld[$fld_line_no][lengthWidth]' value='" .
419 htmlspecialchars($linedata['fld_length'], ENT_QUOTES
) .
420 "' size='1' maxlength='10' class='optin' title='" . xla('Width') . "' />";
421 if ($linedata['data_type'] == 3) {
422 // Show the height field
423 echo "<input type='text' name='fld[$fld_line_no][lengthHeight]' value='" .
424 htmlspecialchars($linedata['fld_rows'], ENT_QUOTES
) .
425 "' size='1' maxlength='10' class='optin' title='" . xla('Height') . "' />";
428 // Hide the height field
429 echo "<input type='hidden' name='fld[$fld_line_no][lengthHeight]' value=''>";
433 // all other data_types (hide both the width and height fields
434 echo "<input type='hidden' name='fld[$fld_line_no][lengthWidth]' value=''>";
435 echo "<input type='hidden' name='fld[$fld_line_no][lengthHeight]' value=''>";
439 echo " <td align='center' class='optcell'>";
440 echo "<input type='text' name='fld[$fld_line_no][maxSize]' value='" .
441 htmlspecialchars($linedata['max_length'], ENT_QUOTES
) .
442 "' size='1' maxlength='10' class='optin' title='" . xla('Maximum Size (entering 0 will allow any size)') . "' />";
445 echo " <td align='center' class='optcell'>";
446 if ($linedata['data_type'] == 1 ||
$linedata['data_type'] == 21 ||
447 $linedata['data_type'] == 22 ||
$linedata['data_type'] == 23 ||
448 $linedata['data_type'] == 25 ||
$linedata['data_type'] == 26 ||
449 $linedata['data_type'] == 27 ||
$linedata['data_type'] == 32 ||
450 $linedata['data_type'] == 33 ||
$linedata['data_type'] == 34 ||
451 $linedata['data_type'] == 36)
454 $disp = "style='display:none'";
455 if($linedata['data_type'] == 34){
456 $type = "style='display:none'";
459 echo "<input type='text' name='fld[$fld_line_no][list_id]' id='fld[$fld_line_no][list_id]' value='" .
460 htmlspecialchars($linedata['list_id'], ENT_QUOTES
) . "'".$type.
461 " size='6' maxlength='30' class='optin listid' style='cursor: pointer'".
462 "title='". xl('Choose list') . "' />";
464 echo "<select name='fld[$fld_line_no][contextName]' id='fld[$fld_line_no][contextName]' ".$disp.">";
465 $res = sqlStatement("SELECT * FROM customlists WHERE cl_list_type=2 AND cl_deleted=0");
466 while($row = sqlFetchArray($res)){
468 if ($linedata['list_id'] == $row['cl_list_item_long'])
470 echo "<option value='".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES
)."' ".$sel.">".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES
)."</option>";
475 // all other data_types
476 echo "<input type='hidden' name='fld[$fld_line_no][list_id]' value=''>";
481 echo " <td align='center' class='optcell'>";
482 if ($linedata['data_type'] == 1 ||
$linedata['data_type'] == 26 ||
483 $linedata['data_type'] == 33 ||
$linedata['data_type'] == 36)
486 echo "<input type='text' name='fld[$fld_line_no][list_backup_id]' value='" .
487 htmlspecialchars($linedata['list_backup_id'], ENT_QUOTES
) .
488 "' size='3' maxlength='10' class='optin listid' style='cursor: pointer' />";
491 echo "<input type='hidden' name='fld[$fld_line_no][list_backup_id]' value=''>";
496 echo " <td align='center' class='optcell'>";
497 echo "<input type='text' name='fld[$fld_line_no][titlecols]' value='" .
498 htmlspecialchars($linedata['titlecols'], ENT_QUOTES
) . "' size='3' maxlength='10' class='optin' />";
502 echo " <td align='center' class='optcell'>";
503 echo "<input type='text' name='fld[$fld_line_no][datacols]' value='" .
504 htmlspecialchars($linedata['datacols'], ENT_QUOTES
) . "' size='3' maxlength='10' class='optin' />";
507 echo " <td align='center' class='optcell' title='" .
508 "C = " . xla('Capitalize') .
509 ", D = " . xla('Dup Check') .
510 ", G = " . xla('Graphable') .
511 ", H = " . xla('Read-only from History') .
512 ", L = " . xla('Lab Order') .
513 ", N = " . xla('New Patient Form') .
514 ", O = " . xla('Order Processor') .
515 ", R = " . xla('Distributor') .
516 ", T = " . xla('Description is default text') .
517 ", U = " . xla('Capitalize all') .
518 ", V = " . xla('Vendor') .
519 ", 1 = " . xla('Write Once') .
520 ", 2 = " . xla('Billing Code Descriptions') .
522 echo "<input type='text' name='fld[$fld_line_no][edit_options]' value='" .
523 htmlspecialchars($linedata['edit_options'], ENT_QUOTES
) . "' size='3' maxlength='36' class='optin' />";
526 /*****************************************************************
527 echo " <td align='center' class='optcell'>";
528 if ($linedata['data_type'] == 2) {
529 echo "<input type='text' name='fld[$fld_line_no][default]' value='" .
530 htmlspecialchars($linedata['default_value'], ENT_QUOTES) . "' size='10' maxlength='63' class='optin' />";
536 echo " <td align='center' class='optcell'>";
537 echo "<input type='text' name='fld[$fld_line_no][desc]' value='" .
538 htmlspecialchars($linedata['description'], ENT_QUOTES) . "' size='20' maxlength='63' class='optin' />";
541 // if not english and showing layout labels, then show the translation of Description
542 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
543 echo "<td align='center' class='translation'>" . htmlspecialchars(xl($linedata['description']), ENT_QUOTES) . "</td>\n";
545 *****************************************************************/
547 if ($linedata['data_type'] == 31) {
548 echo " <td align='center' class='optcell'>";
549 echo "<textarea name='fld[$fld_line_no][desc]' rows='3' cols='35' class='optin'>" .
550 $linedata['description'] . "</textarea>";
551 echo "<input type='hidden' name='fld[$fld_line_no][default]' value='" .
552 htmlspecialchars($linedata['default_value'], ENT_QUOTES
) . "' />";
556 echo " <td align='center' class='optcell'>";
557 echo "<input type='text' name='fld[$fld_line_no][desc]' value='" .
558 htmlspecialchars($linedata['description'], ENT_QUOTES
) .
559 "' size='30' maxlength='63' class='optin' />";
560 echo "<input type='hidden' name='fld[$fld_line_no][default]' value='" .
561 htmlspecialchars($linedata['default_value'], ENT_QUOTES
) . "' />";
563 // if not english and showing layout labels, then show the translation of Description
564 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
565 echo "<td align='center' class='translation'>" .
566 htmlspecialchars(xl($linedata['description']), ENT_QUOTES
) . "</td>\n";
576 <?php
html_header_show();?
>
578 <!-- supporting javascript code
-->
579 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script
>
581 <link rel
="stylesheet" href
='<?php echo $css_header ?>' type
='text/css'>
583 <title
><?php
xl('Layout Editor','e'); ?
></title
>
586 tr
.head
{ font
-size
:10pt
; background
-color
:#cccccc; }
587 tr
.detail
{ font
-size
:10pt
; }
588 td
{ font
-size
:10pt
; }
589 input
{ font
-size
:10pt
; }
590 a
, a
:visited
, a
:hover
{ color
:#0000cc; }
592 .optin
{ background
: transparent
; }
594 margin
: 0pt
0pt
8pt
0pt
;
599 border
-collapse
: collapse
;
603 background
-color
: #ddddff;
604 padding
: 3px
0px
3px
0px
;
607 background
-color
: #ffdddd;
608 padding
: 3px
0px
3px
0px
;
610 .help
{ cursor
: help
; }
611 .layouts_title
{ font
-size
: 110%
; }
617 border
: 2px solid blue
;
618 background
-color
: yellow
;
625 <body
class="body_top">
627 <form method
='post' name
='theform' id
='theform' action
='edit_layout.php'>
628 <input type
="hidden" name
="formaction" id
="formaction" value
="">
629 <!-- elements used to identify a field to delete
-->
630 <input type
="hidden" name
="deletefieldid" id
="deletefieldid" value
="">
631 <input type
="hidden" name
="deletefieldgroup" id
="deletefieldgroup" value
="">
632 <!-- elements used to identify a group to delete
-->
633 <input type
="hidden" name
="deletegroupname" id
="deletegroupname" value
="">
634 <!-- elements used to change the group order
-->
635 <input type
="hidden" name
="movegroupname" id
="movegroupname" value
="">
636 <input type
="hidden" name
="movedirection" id
="movedirection" value
="">
637 <!-- elements used to select more than one field
-->
638 <input type
="hidden" name
="selectedfields" id
="selectedfields" value
="">
639 <input type
="hidden" id
="targetgroup" name
="targetgroup" value
="">
641 <p
><b
><?php
xl('Edit layout','e'); ?
>:</b
> 
;
642 <select name
='layout_id' id
='layout_id'>
643 <option value
=''>-- <?php
echo xl('Select') ?
> --</option
>
645 foreach ($layouts as $key => $value) {
646 echo " <option value='$key'";
647 if ($key == $layout_id) echo " selected";
648 echo ">$value</option>\n";
653 <?php
if ($layout_id) { ?
>
654 <div style
='margin: 0 0 8pt 0;'>
655 <input type
='button' class='addgroup' id
='addgroup' value
=<?php
xl('Add Group','e','\'','\''); ?
>/>
660 $prevgroup = "!@#asdf1234"; // an unlikely group name
661 $firstgroup = true; // flag indicates it's the first group to be displayed
662 while ($row = sqlFetchArray($res)) {
663 if ($row['group_name'] != $prevgroup) {
664 if ($firstgroup == false) { echo "</tbody></table></div>\n"; }
665 echo "<div id='".$row['group_name']."' class='group'>";
666 echo "<div class='text bold layouts_title' style='position:relative; background-color: #eef'>";
667 // echo preg_replace("/^\d+/", "", $row['group_name']);
668 echo substr($row['group_name'], 1);
670 // if not english and set to translate layout labels, then show the translation of group name
671 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
672 // echo "<span class='translation'>>> " . xl(preg_replace("/^\d+/", "", $row['group_name'])) . "</span>";
673 echo "<span class='translation'>>> " . xl(substr($row['group_name'], 1)) . "</span>";
677 echo " <input type='button' class='addfield' id='addto~".$row['group_name']."' value='" . xl('Add Field') . "'/>";
678 echo " ";
679 echo " <input type='button' class='renamegroup' id='".$row['group_name']."' value='" . xl('Rename Group') . "'/>";
680 echo " ";
681 echo " <input type='button' class='deletegroup' id='".$row['group_name']."' value='" . xl('Delete Group') . "'/>";
682 echo " ";
683 echo " <input type='button' class='movegroup' id='".$row['group_name']."~up' value='" . xl('Move Up') . "'/>";
684 echo " ";
685 echo " <input type='button' class='movegroup' id='".$row['group_name']."~down' value='" . xl('Move Down') . "'/>";
693 <th
><?php
xl('Order','e'); ?
></th
>
694 <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
>
695 <th
><?php
xl('Label','e'); ?
> <span
class="help" title
=<?php
xl('The label that appears to the user on the form','e','\'','\''); ?
> >(?
)</span
></th
>
696 <?php
// if not english and showing layout label translations, then show translation header for title
697 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
698 echo "<th>" . xl('Translation')."<span class='help' title='" . xl('The translated label that will appear on the form in current language') . "'> (?)</span></th>";
700 <th
><?php
xl('UOR','e'); ?
></th
>
701 <th
><?php
xl('Data Type','e'); ?
></th
>
702 <th
><?php
xl('Size','e'); ?
></th
>
703 <th
><?php
xl('Maximum Size','e'); ?
></th
>
704 <th
><?php
xl('List','e'); ?
></th
>
705 <th
><?php
xl('Backup List','e'); ?
></th
>
706 <th
><?php
xl('Label Cols','e'); ?
></th
>
707 <th
><?php
xl('Data Cols','e'); ?
></th
>
708 <th
><?php
xl('Options','e'); ?
></th
>
709 <th
><?php
xl('Description','e'); ?
></th
>
710 <?php
// if not english and showing layout label translations, then show translation header for description
711 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
712 echo "<th>" . xl('Translation')."<span class='help' title='" . xl('The translation of description in current language')."'> (?)</span></th>";
719 } // end if-group_name
721 writeFieldLine($row);
722 $prevgroup = $row['group_name'];
730 <?php
if ($layout_id) { ?
>
731 <span style
="font-size:90%">
732 <?php
xl('With selected:', 'e');?
>
733 <input type
='button' name
='deletefields' id
='deletefields' value
='<?php xl('Delete
','e
'); ?>' style
="font-size:90%" disabled
="disabled" />
734 <input type
='button' name
='movefields' id
='movefields' value
='<?php xl('Move to
...','e
'); ?>' style
="font-size:90%" disabled
="disabled" />
737 <input type
='button' name
='save' id
='save' value
='<?php xl('Save Changes
','e
'); ?>' />
743 <!-- template DIV that appears when user chooses to rename an existing group
-->
744 <div id
="renamegroupdetail" style
="border: 1px solid black; padding: 3px; display: none; visibility: hidden; background-color: lightgrey;">
745 <input type
="hidden" name
="renameoldgroupname" id
="renameoldgroupname" value
="">
746 <?php
xl('Group Name','e'); ?
>: <input type
="textbox" size
="20" maxlength
="30" name
="renamegroupname" id
="renamegroupname">
748 <input type
="button" class="saverenamegroup" value
=<?php
xl('Rename Group','e','\'','\''); ?
>>
749 <input type
="button" class="cancelrenamegroup" value
=<?php
xl('Cancel','e','\'','\''); ?
>>
752 <!-- template DIV that appears when user chooses to add a
new group
-->
753 <div id
="groupdetail" style
="border: 1px solid black; padding: 3px; display: none; visibility: hidden; background-color: lightgrey;">
755 <?php
xl('Group Name','e'); ?
>: <input type
="textbox" size
="20" maxlength
="30" name
="newgroupname" id
="newgroupname">
757 <table style
="border-collapse: collapse; margin-top: 5px;">
760 <th
><?php
xl('Order','e'); ?
></th
>
761 <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
>
762 <th
><?php
xl('Label','e'); ?
> <span
class="help" title
=<?php
xl('The label that appears to the user on the form','e','\'','\''); ?
> >(?
)</span
></th
>
763 <th
><?php
xl('UOR','e'); ?
></th
>
764 <th
><?php
xl('Data Type','e'); ?
></th
>
765 <th
><?php
xl('Size','e'); ?
></th
>
766 <th
><?php
xl('Maximum Size','e'); ?
></th
>
767 <th
><?php
xl('List','e'); ?
></th
>
768 <th
><?php
xl('Backup List','e'); ?
></th
>
769 <th
><?php
xl('Label Cols','e'); ?
></th
>
770 <th
><?php
xl('Data Cols','e'); ?
></th
>
771 <th
><?php
xl('Options','e'); ?
></th
>
772 <th
><?php
xl('Description','e'); ?
></th
>
777 <td
><input type
="textbox" name
="gnewseq" id
="gnewseq" value
="" size
="2" maxlength
="3"> </td
>
778 <td
><input type
="textbox" name
="gnewid" id
="gnewid" value
="" size
="10" maxlength
="20"> </td
>
779 <td
><input type
="textbox" name
="gnewtitle" id
="gnewtitle" value
="" size
="20" maxlength
="63"> </td
>
781 <select name
="gnewuor" id
="gnewuor">
782 <option value
="0"><?php
xl('Unused','e'); ?
></option
>
783 <option value
="1" selected
><?php
xl('Optional','e'); ?
></option
>
784 <option value
="2"><?php
xl('Required','e'); ?
></option
>
788 <select name
='gnewdatatype' id
='gnewdatatype'>
789 <option value
=''></option
>
792 foreach ($datatypes as $key=>$value) {
793 echo "<option value='$key'>$value</option>";
798 <td
><input type
="textbox" name
="gnewlengthWidth" id
="gnewlengthWidth" value
="" size
="1" maxlength
="3" title
="<?php echo xla('Width'); ?>">
799 <input type
="textbox" name
="gnewlengthHeight" id
="gnewlengthHeight" value
="" size
="1" maxlength
="3" title
="<?php echo xla('Height'); ?>"></td
>
800 <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
>
801 <td
><input type
="textbox" name
="gnewlistid" id
="gnewlistid" value
="" size
="8" maxlength
="31" class="listid">
802 <select name
='gcontextName' id
='gcontextName' style
='display:none'>
804 $res = sqlStatement("SELECT * FROM customlists WHERE cl_list_type=2 AND cl_deleted=0");
805 while($row = sqlFetchArray($res)){
806 echo "<option value='".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES
)."'>".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES
)."</option>";
811 <td
><input type
="textbox" name
="gnewbackuplistid" id
="gnewbackuplistid" value
="" size
="8" maxlength
="31" class="listid"></td
>
812 <td
><input type
="textbox" name
="gnewtitlecols" id
="gnewtitlecols" value
="" size
="3" maxlength
="3"> </td
>
813 <td
><input type
="textbox" name
="gnewdatacols" id
="gnewdatacols" value
="" size
="3" maxlength
="3"> </td
>
814 <td
><input type
="textbox" name
="gnewedit_options" id
="gnewedit_options" value
="" size
="3" maxlength
="36">
815 <input type
="hidden" name
="gnewdefault" id
="gnewdefault" value
="" /> </td
>
816 <td
><input type
="textbox" name
="gnewdesc" id
="gnewdesc" value
="" size
="30" maxlength
="63"> </td
>
821 <input type
="button" class="savenewgroup" value
=<?php
xl('Save New Group','e','\'','\''); ?
>>
822 <input type
="button" class="cancelnewgroup" value
=<?php
xl('Cancel','e','\'','\''); ?
>>
826 <!-- template DIV that appears when user chooses to add a
new field to a group
-->
827 <div id
="fielddetail" class="fielddetail" style
="display: none; visibility: hidden">
828 <input type
="hidden" name
="newfieldgroupid" id
="newfieldgroupid" value
="">
829 <table style
="border-collapse: collapse;">
832 <th
><?php
xl('Order','e'); ?
></th
>
833 <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
>
834 <th
><?php
xl('Label','e'); ?
> <span
class="help" title
=<?php
xl('The label that appears to the user on the form','e','\'','\''); ?
> >(?
)</span
></th
>
835 <th
><?php
xl('UOR','e'); ?
></th
>
836 <th
><?php
xl('Data Type','e'); ?
></th
>
837 <th
><?php
xl('Size','e'); ?
></th
>
838 <th
><?php
xl('Maximum Size','e'); ?
></th
>
839 <th
><?php
xl('List','e'); ?
></th
>
840 <th
><?php
xl('Backup List','e'); ?
></th
>
841 <th
><?php
xl('Label Cols','e'); ?
></th
>
842 <th
><?php
xl('Data Cols','e'); ?
></th
>
843 <th
><?php
xl('Options','e'); ?
></th
>
844 <th
><?php
xl('Description','e'); ?
></th
>
849 <td
><input type
="textbox" name
="newseq" id
="newseq" value
="" size
="2" maxlength
="3"> </td
>
850 <td
><input type
="textbox" name
="newid" id
="newid" value
="" size
="10" maxlength
="20"> </td
>
851 <td
><input type
="textbox" name
="newtitle" id
="newtitle" value
="" size
="20" maxlength
="63"> </td
>
853 <select name
="newuor" id
="newuor">
854 <option value
="0"><?php
xl('Unused','e'); ?
></option
>
855 <option value
="1" selected
><?php
xl('Optional','e'); ?
></option
>
856 <option value
="2"><?php
xl('Required','e'); ?
></option
>
860 <select name
='newdatatype' id
='newdatatype'>
861 <option value
=''></option
>
864 foreach ($datatypes as $key=>$value) {
865 echo " <option value='$key'>$value</option>\n";
870 <td
><input type
="textbox" name
="newlengthWidth" id
="newlengthWidth" value
="" size
="1" maxlength
="3" title
="<?php echo xla('Width'); ?>">
871 <input type
="textbox" name
="newlengthHeight" id
="newlengthHeight" value
="" size
="1" maxlength
="3" title
="<?php echo xla('Height'); ?>"></td
>
872 <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
>
873 <td
><input type
="textbox" name
="newlistid" id
="newlistid" value
="" size
="8" maxlength
="31" class="listid">
874 <select name
='contextName' id
='contextName' style
='display:none'>
876 $res = sqlStatement("SELECT * FROM customlists WHERE cl_list_type=2 AND cl_deleted=0");
877 while($row = sqlFetchArray($res)){
878 echo "<option value='".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES
)."'>".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES
)."</option>";
883 <td
><input type
="textbox" name
="newbackuplistid" id
="newbackuplistid" value
="" size
="8" maxlength
="31" class="listid"></td
>
884 <td
><input type
="textbox" name
="newtitlecols" id
="newtitlecols" value
="" size
="3" maxlength
="3"> </td
>
885 <td
><input type
="textbox" name
="newdatacols" id
="newdatacols" value
="" size
="3" maxlength
="3"> </td
>
886 <td
><input type
="textbox" name
="newedit_options" id
="newedit_options" value
="" size
="3" maxlength
="36">
887 <input type
="hidden" name
="newdefault" id
="newdefault" value
="" /> </td
>
888 <td
><input type
="textbox" name
="newdesc" id
="newdesc" value
="" size
="30" maxlength
="63"> </td
>
892 <input type
="button" class="savenewfield" value
=<?php
xl('Save New Field','e','\'','\''); ?
>>
893 <input type
="button" class="cancelnewfield" value
=<?php
xl('Cancel','e','\'','\''); ?
>>
902 <script language
="javascript">
904 // used when selecting a list-name for a field
907 // jQuery stuff to make the page a little easier to use
909 $
(document
).ready(function(){
910 $
("#save").click(function() { SaveChanges(); });
911 $
("#layout_id").change(function() { $
('#theform').submit(); });
913 $
(".addgroup").click(function() { AddGroup(this
); });
914 $
(".savenewgroup").click(function() { SaveNewGroup(this
); });
915 $
(".deletegroup").click(function() { DeleteGroup(this
); });
916 $
(".cancelnewgroup").click(function() { CancelNewGroup(this
); });
918 $
(".movegroup").click(function() { MoveGroup(this
); });
920 $
(".renamegroup").click(function() { RenameGroup(this
); });
921 $
(".saverenamegroup").click(function() { SaveRenameGroup(this
); });
922 $
(".cancelrenamegroup").click(function() { CancelRenameGroup(this
); });
924 $
(".addfield").click(function() { AddField(this
); });
925 $
("#deletefields").click(function() { DeleteFields(this
); });
926 $
(".selectfield").click(function() {
927 var TRparent
= $
(this
).parent().parent();
928 $
(TRparent
).children("td").toggleClass("highlight");
929 // disable the delete-move buttons
930 $
("#deletefields").attr("disabled", "disabled");
931 $
("#movefields").attr("disabled", "disabled");
932 $
(".selectfield").each(function(i
) {
933 // if any field is selected, enable the delete-move buttons
934 if ($
(this
).attr("checked") == true) {
935 $
("#deletefields").removeAttr("disabled");
936 $
("#movefields").removeAttr("disabled");
940 $
("#movefields").click(function() { ShowGroups(this
); });
941 $
(".savenewfield").click(function() { SaveNewField(this
); });
942 $
(".cancelnewfield").click(function() { CancelNewField(this
); });
943 $
("#newtitle").blur(function() { if ($
("#newid").val() == "") $
("#newid").val($
("#newtitle").val()); });
944 $
("#newdatatype").change(function() { ChangeList(this
.value
);});
945 $
("#gnewdatatype").change(function() { ChangeListg(this
.value
);});
946 $
(".listid").click(function() { ShowLists(this
); });
948 // special class that skips the element
949 $
(".noselect").focus(function() { $
(this
).blur(); });
951 // Save the changes made to the form
952 var SaveChanges
= function () {
953 $
("#formaction").val("save");
954 $
("#theform").submit();
957 /****************************************************/
958 /************ Group functions ***********************/
959 /****************************************************/
961 // display the 'new group' DIV
962 var AddGroup
= function(btnObj
) {
963 // show the field details DIV
964 $
('#groupdetail').css('visibility', 'visible');
965 $
('#groupdetail').css('display', 'block');
966 $
(btnObj
).parent().append($
("#groupdetail"));
967 $
('#groupdetail > #newgroupname').focus();
970 // save the new group to the form
971 var SaveNewGroup
= function(btnObj
) {
972 // the group name field can only have letters, numbers, spaces and underscores
973 // AND it cannot start with a number
974 if ($
("#newgroupname").val() == "") {
975 alert("<?php xl('Group names cannot be blank', 'e'); ?>");
978 if ($
("#newgroupname").val().match(/^
(\d+|\s+
)/)) {
979 alert("<?php xl('Group names cannot start with numbers or spaces.','e'); ?>");
982 var validname
= $
("#newgroupname").val().replace(/[^A
-za
-z0
-9 ]/g
, "_"); // match any non-word characters and replace them
983 $
("#newgroupname").val(validname
);
985 // now, check the first group field values
987 // seq must be numeric and less than 999
988 if (! IsNumeric($
("#gnewseq").val(), 0, 999)) {
989 alert("<?php xl('Order must be a number between 1 and 999','e'); ?>");
992 // length must be numeric and less than 999
993 if (! IsNumeric($
("#gnewlengthWidth").val(), 0, 999)) {
994 alert("<?php xl('Size must be a number between 1 and 999','e'); ?>");
997 // titlecols must be numeric and less than 100
998 if (! IsNumeric($
("#gnewtitlecols").val(), 0, 999)) {
999 alert("<?php xl('LabelCols must be a number between 1 and 999','e'); ?>");
1002 // datacols must be numeric and less than 100
1003 if (! IsNumeric($
("#gnewdatacols").val(), 0, 999)) {
1004 alert("<?php xl('DataCols must be a number between 1 and 999','e'); ?>");
1007 // some fields cannot be blank
1008 if ($
("#gnewtitle").val() == "") {
1009 alert("<?php xl('Label cannot be blank','e'); ?>");
1012 // the id field can only have letters, numbers and underscores
1013 if ($
("#gnewid").val() == "") {
1014 alert("<?php xl('ID cannot be blank', 'e'); ?>");
1017 var validid
= $
("#gnewid").val().replace(/(\s|\W
)/g
, "_"); // match any non-word characters and replace them
1018 $
("#gnewid").val(validid
);
1019 // similarly with the listid field
1020 validid
= $
("#gnewlistid").val().replace(/(\s|\W
)/g
, "_");
1021 $
("#gnewlistid").val(validid
);
1022 // similarly with the backuplistid field
1023 validid
= $
("#gnewbackuplistid").val().replace(/(\s|\W
)/g
, "_");
1024 $
("#gnewbackuplistid").val(validid
);
1027 // submit the form to add a new field to a specific group
1028 $
("#formaction").val("addgroup");
1029 $
("#theform").submit();
1032 // actually delete an entire group from the database
1033 var DeleteGroup
= function(btnObj
) {
1034 var parts
= $
(btnObj
).attr("id");
1035 var groupname
= parts
.replace(/^\d+
/, "");
1036 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+
"'?")) {
1037 // submit the form to add a new field to a specific group
1038 $
("#formaction").val("deletegroup");
1039 $
("#deletegroupname").val(parts
);
1040 $
("#theform").submit();
1044 // just hide the new field DIV
1045 var CancelNewGroup
= function(btnObj
) {
1046 // hide the field details DIV
1047 $
('#groupdetail').css('visibility', 'hidden');
1048 $
('#groupdetail').css('display', 'none');
1049 // reset the new group values to a default
1050 $
('#groupdetail > #newgroupname').val("");
1053 // display the 'new field' DIV
1054 var MoveGroup
= function(btnObj
) {
1055 var btnid
= $
(btnObj
).attr("id");
1056 var parts
= btnid
.split("~");
1057 var groupid
= parts
[0];
1058 var direction
= parts
[1];
1060 // submit the form to change group order
1061 $
("#formaction").val("movegroup");
1062 $
("#movegroupname").val(groupid
);
1063 $
("#movedirection").val(direction
);
1064 $
("#theform").submit();
1067 // show the rename group DIV
1068 var RenameGroup
= function(btnObj
) {
1069 $
('#renamegroupdetail').css('visibility', 'visible');
1070 $
('#renamegroupdetail').css('display', 'block');
1071 $
(btnObj
).parent().append($
("#renamegroupdetail"));
1072 $
('#renameoldgroupname').val($
(btnObj
).attr("id"));
1073 $
('#renamegroupname').val($
(btnObj
).attr("id").replace(/^\d+
/, ""));
1076 // save the new group to the form
1077 var SaveRenameGroup
= function(btnObj
) {
1078 // the group name field can only have letters, numbers, spaces and underscores
1079 // AND it cannot start with a number
1080 if ($
("#renamegroupname").val().match(/^\d+
/)) {
1081 alert("<?php xl('Group names cannot start with numbers.','e'); ?>");
1084 var validname
= $
("#renamegroupname").val().replace(/[^A
-za
-z0
-9 ]/g
, "_"); // match any non-word characters and replace them
1085 $
("#renamegroupname").val(validname
);
1087 // submit the form to add a new field to a specific group
1088 $
("#formaction").val("renamegroup");
1089 $
("#theform").submit();
1092 // just hide the new field DIV
1093 var CancelRenameGroup
= function(btnObj
) {
1094 // hide the field details DIV
1095 $
('#renamegroupdetail').css('visibility', 'hidden');
1096 $
('#renamegroupdetail').css('display', 'none');
1097 // reset the rename group values to a default
1098 $
('#renameoldgroupname').val("");
1099 $
('#renamegroupname').val("");
1102 /****************************************************/
1103 /************ Field functions ***********************/
1104 /****************************************************/
1106 // display the 'new field' DIV
1107 var AddField
= function(btnObj
) {
1108 // update the fieldgroup value to be the groupid
1109 var btnid
= $
(btnObj
).attr("id");
1110 var parts
= btnid
.split("~");
1111 var groupid
= parts
[1];
1112 $
('#fielddetail > #newfieldgroupid').attr('value', groupid
);
1114 // show the field details DIV
1115 $
('#fielddetail').css('visibility', 'visible');
1116 $
('#fielddetail').css('display', 'block');
1117 $
(btnObj
).parent().append($
("#fielddetail"));
1120 var DeleteFields
= function(btnObj
) {
1121 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'); ?>")) {
1123 $
(".selectfield").each(function(i
) {
1124 // build a list of selected field names to be moved
1125 if ($
(this
).attr("checked") == true) {
1126 var parts
= this
.id
.split("~");
1127 var currval
= $
("#selectedfields").val();
1128 $
("#selectedfields").val(currval+delim+parts
[1]);
1132 // submit the form to delete the field(s)
1133 $
("#formaction").val("deletefields");
1134 $
("#theform").submit();
1138 // save the new field to the form
1139 var SaveNewField
= function(btnObj
) {
1140 // check the new field values for correct formatting
1142 // seq must be numeric and less than 999
1143 if (! IsNumeric($
("#newseq").val(), 0, 999)) {
1144 alert("<?php xl('Order must be a number between 1 and 999','e'); ?>");
1147 // length must be numeric and less than 999
1148 if (! IsNumeric($
("#newlengthWidth").val(), 0, 999)) {
1149 alert("<?php xl('Size must be a number between 1 and 999','e'); ?>");
1152 // titlecols must be numeric and less than 100
1153 if (! IsNumeric($
("#newtitlecols").val(), 0, 999)) {
1154 alert("<?php xl('LabelCols must be a number between 1 and 999','e'); ?>");
1157 // datacols must be numeric and less than 100
1158 if (! IsNumeric($
("#newdatacols").val(), 0, 999)) {
1159 alert("<?php xl('DataCols must be a number between 1 and 999','e'); ?>");
1162 // some fields cannot be blank
1163 if ($
("#newtitle").val() == "") {
1164 alert("<?php xl('Label cannot be blank','e'); ?>");
1167 // the id field can only have letters, numbers and underscores
1168 var validid
= $
("#newid").val().replace(/(\s|\W
)/g
, "_"); // match any non-word characters and replace them
1169 $
("#newid").val(validid
);
1170 // similarly with the listid field
1171 validid
= $
("#newlistid").val().replace(/(\s|\W
)/g
, "_");
1172 $
("#newlistid").val(validid
);
1173 // similarly with the backuplistid field
1174 validid
= $
("#newbackuplistid").val().replace(/(\s|\W
)/g
, "_");
1175 $
("#newbackuplistid").val(validid
);
1177 // submit the form to add a new field to a specific group
1178 $
("#formaction").val("addfield");
1179 $
("#theform").submit();
1182 // just hide the new field DIV
1183 var CancelNewField
= function(btnObj
) {
1184 // hide the field details DIV
1185 $
('#fielddetail').css('visibility', 'hidden');
1186 $
('#fielddetail').css('display', 'none');
1187 // reset the new field values to a default
1188 ResetNewFieldValues();
1191 // show the popup choice of lists
1192 var ShowLists
= function(btnObj
) {
1193 window
.open("./show_lists_popup.php", "lists", "width=300,height=500,scrollbars=yes");
1194 selectedfield
= btnObj
;
1197 // show the popup choice of groups
1198 var ShowGroups
= function(btnObj
) {
1199 window
.open("./show_groups_popup.php?layout_id=<?php echo $layout_id;?>", "groups", "width=300,height=300,scrollbars=yes");
1202 // Show context DD for NationNotes
1203 var ChangeList
= function(btnObj
){
1205 $
('#newlistid').hide();
1206 $
('#contextName').show();
1209 $
('#newlistid').show();
1210 $
('#contextName').hide();
1213 var ChangeListg
= function(btnObj
){
1215 $
('#gnewlistid').hide();
1216 $
('#gcontextName').show();
1219 $
('#gnewlistid').show();
1220 $
('#gcontextName').hide();
1226 function NationNotesContext(lineitem
,val
){
1228 document
.getElementById("fld["+lineitem+
"][contextName]").style
.display
='';
1229 document
.getElementById("fld["+lineitem+
"][list_id]").style
.display
='none';
1230 document
.getElementById("fld["+lineitem+
"][list_id]").value
='';
1233 document
.getElementById("fld["+lineitem+
"][list_id]").style
.display
='';
1234 document
.getElementById("fld["+lineitem+
"][contextName]").style
.display
='none';
1235 document
.getElementById("fld["+lineitem+
"][list_id]").value
='';
1238 function SetList(listid
) { $
(selectedfield
).val(listid
); }
1241 /* this is called after the user chooses a new group from the popup window
1242 * it will submit the page so the selected fields can be moved into
1245 function MoveFields(targetgroup
) {
1246 $
("#targetgroup").val(targetgroup
);
1248 $
(".selectfield").each(function(i
) {
1249 // build a list of selected field names to be moved
1250 if ($
(this
).attr("checked") == true) {
1251 var parts
= this
.id
.split("~");
1252 var currval
= $
("#selectedfields").val();
1253 $
("#selectedfields").val(currval+delim+parts
[1]);
1257 $
("#formaction").val("movefields");
1258 $
("#theform").submit();
1262 // set the new-field values to a default state
1263 function ResetNewFieldValues () {
1264 $
("#newseq").val("");
1265 $
("#newid").val("");
1266 $
("#newtitle").val("");
1267 $
("#newuor").val(1);
1268 $
("#newlengthWidth").val("");
1269 $
("#newlengthHeight").val("");
1270 $
("#newmaxSize").val("");
1271 $
("#newdatatype").val("");
1272 $
("#newlistid").val("");
1273 $
("#newbackuplistid").val("");
1274 $
("#newtitlecols").val("");
1275 $
("#newdatacols").val("");
1276 $
("#newedit_options").val("");
1277 $
("#newdefault").val("");
1278 $
("#newdesc").val("");
1281 // is value an integer and between min and max
1282 function IsNumeric(value
, min
, max
) {
1283 if (value
== "" || value
== null) return false;
1285 parseInt(value
) < min ||
1286 parseInt(value
) > max
)
1292 /****************************************************/
1293 /****************************************************/
1294 /****************************************************/
1296 // tell if num is an Integer
1297 function IsN(num
) { return !/\D
/.test(num
); }