AutoForm.pm

filter: Statementstmt 3.7% 46 / 1213 Branchbran 0.0% 0 / 718 Conditioncond 0.0% 0 / 301 MC/DCmcdc 0.0% 0 / 164 Subroutinesub 5.1% 5 / 98 Podpod 51.3% 39 / 76 totaltotal 3.5% 90 / 2570 CC 486 SCAR 62.1
CC
486
Cov
2%
field_template
2352.0
normalize_query
1056.0
validate_query
992.0
CRAP 497.3
↑ Summary AutoForm/Session.pm »
1 # AutoForm.pm
2 #
3 # $Id: AutoForm.pm,v 1.19 2005/04/11 17:02:35 scottb Exp $
4 #
5  
6 package CGI::AutoForm;
7  
8 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use DBIx::IO::Mask;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use DBIx::IO::Search;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use DBIx::IO::Table;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use DBIx::IO::GenLib ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15 1 *CGI::AutoForm::VERSION = \'1.05';
16  
17 1 *CGI::AutoForm::DISPLAY_ONLY_GROUP = \'DISPLAY ONLY';
18 1 *CGI::AutoForm::INSERT_GROUP = \'INSERTABLE';
19 1 *CGI::AutoForm::EDIT_GROUP = \'DISPLAY EDIT';
20 1 *CGI::AutoForm::SEARCH_GROUP = \'SEARCHABLE';
21  
22 1 *CGI::AutoForm::DEFAULT_RADIO_CHECKBOX_COLS = \2;
23  
24 1 *CGI::AutoForm::DEFAULT_FIELD_LENGTH = \50;
25  
26 1 *CGI::AutoForm::DEFAULT_MULTI_VALUE_DELIMITER = \':';
27  
28 1 my @months = ('',qw(
29 January
30 February
31 March
32 April
33 May
34 June
35 July
36 August
37 September
38 October
39 November
40 December
41 ));
42 1 my $month_field = {
43 FIELD_NAME => '_MONTH',
44 INPUT_CONTROL_TYPE => 'SELECT',
45 SEARCH_CONTROL_TYPE => 'SELECT',
46 };
47 my $month_picklist = [
48 1 map { { ID => $_, MASK => $months[$_] } } ('01'..'12')
49 ];
50  
51 1 my $day_field = {
52 FIELD_NAME => '_DAY',
53 INPUT_CONTROL_TYPE => 'SELECT',
54 SEARCH_CONTROL_TYPE => 'SELECT',
55 };
56 my $day_picklist = [
57 1 map { { ID => $_, MASK => int($_) } } ('01'..'31')
58 ];
59  
60 1 my $year_field = {
61 FIELD_NAME => '_YEAR',
62 INPUT_CONTROL_TYPE => 'SELECT',
63 SEARCH_CONTROL_TYPE => 'SELECT',
64 };
65 1 my $this_year = substr(DBIx::IO::GenLib::local_normal_sysdate(),0,4);
66  
67 1 my $hour_field = {
68 FIELD_NAME => '_HOUR',
69 INPUT_CONTROL_TYPE => 'SELECT',
70 SEARCH_CONTROL_TYPE => 'SELECT',
71 };
72 my $hour_picklist = [
73 1 map { { ID => $_, MASK => $_ } } ('00'..'23')
74 ];
75  
76 1 my $min_field = {
77 FIELD_NAME => '_MIN',
78 INPUT_CONTROL_TYPE => 'SELECT',
79 SEARCH_CONTROL_TYPE => 'SELECT',
80 };
81 my $min_picklist = [
82 1 map { { ID => $_, MASK => $_ } } ('00'..'59')
83 ];
84  
85 1 my $rel_quantity_field = {
86 FIELD_NAME => '_QUANT',
87 INPUT_CONTROL_TYPE => 'TEXT',
88 SEARCH_CONTROL_TYPE => 'TEXT',
89 DATATYPE => 'INT',
90 INPUT_SIZE => 4,
91 INPUT_MAXLENGTH => 7,
92 };
93  
94 1 my $rel_unit_field = {
95 FIELD_NAME => '_UNIT',
96 INPUT_CONTROL_TYPE => 'SELECT',
97 SEARCH_CONTROL_TYPE => 'SELECT',
98 };
99 1 my $rel_unit_picklist = [
100 { ID => 'MINS', MASK => 'Minute(s)' },
101 { ID => 'HRS', MASK => 'Hour(s)' },
102 { ID => 'DAYS', MASK => 'Day(s)' },
103 { ID => 'MONTHS', MASK => 'Month(s)' },
104 { ID => 'YEARS', MASK => 'Years(s)' },
105 ];
106  
107 1 my $use_range_field = {
108 FIELD_NAME => '_UR',
109 INPUT_CONTROL_TYPE => 'CHECKBOX',
110 SEARCH_CONTROL_TYPE => 'CHECKBOX',
111 };
112 1 my $use_range_picklist = [
113 { ID => 1, MASK => 'Check to use this date range criteria' },
114 ];
115  
116 1 my $start_range_field = {
117 FIELD_NAME => '_RS',
118 INPUT_CONTROL_TYPE => 'TEXT',
119 SEARCH_CONTROL_TYPE => 'TEXT',
120 };
121  
122 1 my $end_range_field = {
123 FIELD_NAME => '_RE',
124 INPUT_CONTROL_TYPE => 'TEXT',
125 SEARCH_CONTROL_TYPE => 'TEXT',
126 };
127  
128 =head1 NAME
129  
130 CGI::AutoForm - Automated abstraction of HTML forms from a data source
131  
132 =head1 SYNOPSIS
133  
134
135 use CGI::AutoForm;
136  
137  
138 $form = new CGI::AutoForm($dbh,$form_name);
139  
140 $form->action($action_url);
141  
142 $form->add_group($CGI::AutoForm::EDIT_GROUP,$table_name);
143  
144 $form->add_record($current_record);
145  
146 $form_html = $self->prepare();
147  
148 # insert $form_html into the BODY section of an (X)HTML document via a template
149  
150  
151 $group = $form->group_by_name($group_name);
152  
153 $bool = $form->validate_query($query,$callback);
154  
155 $records = $form->format_query($query);
156  
157 $form_copy = $form->clone();
158  
159 $form->reset_group();
160  
161
162 #
163 # an example of customizing a data group's fields...
164 #
165  
166 $rv = $form->add_group($CGI::AutoForm::INSERT_GROUP,undef,'Vote For Your Favorite Artist','ARTIST_VOTE');
167  
168 $fields = $form->db_fields('ARTIST',$CGI::AutoForm::INSERT_GROUP);
169  
170 $form->push_field($fields->{ARTIST_NAME});
171  
172 $form->add_field( {
173 FIELD_NAME => 'VOTE',
174 INPUT_CONTROL_TYPE => 'RADIO',
175 REQUIRED => 'Y',
176 HEADING => 'Vote',
177 DATATYPE => 'CHAR',
178 INSERTABLE => 'Y',
179 },
180 [
181 { ID => '1', MASK => '*', },
182 { ID => '2', MASK => '**', },
183 { ID => '3', MASK => '***', },
184 { ID => '4', MASK => '****', },
185 ]);
186  
187 $form_html = $self->prepare( { 'ARTIST_VOTE.ARTIST_NAME' => 'Nonpoint', 'ARTIST_VOTE.VOTE' => 4 } );
188  
189  
190  
191 =head1 DESCRIPTION
192  
193 There are many CGI form abstractions available, (e.g. CGI.pm).
194 A unique and powerful advantage with this abstraction is that it can be tied closely
195 with a database schema. Each group of fields in the form can represent a database table (or view)
196 and the table/column properties and constraints are automagically discovered so your DBA can make DDL
197 changes that will be immediately reflected in the HTML forms (no duplication of the data dictionary in your code).
198  
199 All user/operator input is checked tightly against database constraints and there is built-in magic
200 to provide convenient select lists, etc, and to enforce a discreet set of valid values against unique/primary keys in lookup tables
201 (see B<Select lists & ID masking>). This means referential integrity even for MySQL. Metadata in MySQL's C<SET> and C<ENUM> types are also supported.
202 This also gives the operator a chance to correct mistakes with helpful hints instead of just getting a meaningless db error code.
203  
204 This design allows you to get secure, database-driven web apps up and running is as little as a few
205 hours (see Cruddy! for an implementation L<http://www.thesmbexchange.com/cruddy/index.html>).
206 This is made possible with the help of the DBIx::IO abstraction, please refer to it for further details.
207  
208 Another advantage this abstraction provides is the separation of presentation and style using style sheets and having human-friendly presentation
209 attributes stored in a database table that can be managed by non-engineers.
210  
211 Typical CGI apps are characterized by collecting, updating, reporting and formatting data using forms and tables.
212 Form creation and processing can be divided into the following tasks:
213  
214 1) Deciding what data to collect in order to perform the desired function.
215  
216 2) Deciding how the operator will convey the desired information (input fields, checkboxes etc).
217  
218 3) Form layout.
219  
220 4) Imposing integrity constraints on the collected data.
221  
222 5) Presentation and style.
223  
224 6) Directing the collected data.
225  
226 This class allows (but doesn't force) form elements and constraints to be defined in a database.
227 This way, the definitions are organized in a central repository, so they can be managed
228 in a shared environment separate from the code. Vanilla HTML is generated and several HTML classes
229 are used so that presentation and style can be dictated with style sheets (again separate from the code).
230 For flexibility, methods are given to modify form definitions and layout programmatically as well.
231  
232 =head1 DETAILS
233  
234 =head2 Form object structure
235  
236 A form contains of a list of data groups. Each data group contains a list of form fields, and
237 a list of 0 or more data records that correspond to the form fields. Each form field is a hash
238 of attributes describing how the field should be rendered as a form element along with constraints, access controls and such.
239  
240 A form object is blessed and will be referred throughout these docs as $form. Of its many attributes,
241 it holds an arrayref and a hashref of data groups, each referred to as $group. Each $group is
242 a (non-blessed) object-like hashref (sub-object) and of its many attributes, it holds an arrayref
243 and a hashref of data fields, each referred to as $field. Each $field in turn is a (non-blessed) object-like
244 hashref (sub-object) as well. Because these sub-objects are stored as a list and a hash by their parent,
245 it is best to use the methods provided when mutating the list/hash structures themselves. However,
246 modifying individual sub-object attributes may be done by accessing the hash keys directly (or iterating the lists).
247  
248 If using a database on the backend to manage form data, a data group would correspond to a table,
249 each of its fields would correspond to columns, likewise, with the group's list of records.
250  
251 One of the primary attributes of a data group is its type or usage and must be one of the following:
252  
253 =over 2
254  
255 =item Insert
256  
257 Gather and validate data, e.g. for subsequent database insert.
258  
259 =item Display/Update
260  
261 Display a record with certain fields available for editing.
262  
263 =item Search
264  
265 Gather criteria for running a database report (with the help of DBIx::IO::Search).
266  
267 =item Display Only
268  
269 Display read-only data, e.g. a database report generated from a search form.
270  
271 =back
272  
273 Each of these types is referred to as $usage throughout these docs (see C<add_group> for defined constants).
274  
275 Each form object will be in a certain state with respect to the groups, fields
276 and records associated with it. The state is defined in terms of the current
277 group#, record# and field#. The state is altered when adding a new data group to a form or through the iterative
278 methods such as C<next_group>, C<next_record>, C<next_field>. C<reset_group> will zero these
279 state properties. State is important for methods such as C<add_record>, C<push_field>
280 and such. Methods dependent on state will be annotated accordingly.
281  
282  
283 =head2 Form field attire
284  
285 Form field attributes may be kept and managed in a database table (see contrib/ for DDL contained in the Cruddy! distribution L<http://www.thesmbexchange.com/cruddy/index.html>).
286 The default name of the table
287 that holds these attributes is C<UI_TABLE_COLUMN> and may be overridden per $form object by setting $form->{attr_defn_table_name}.
288 NOTE MySQL users! If your database has case-sensitive table names then pay attention to this name.
289  
290 Each record in C<UI_TABLE_COLUMN> describes attributes/constraints of a single field in an HTML form. Each HTML form field
291 usually corresponds to a table column (or a view column for search forms or possibly updatable views otherwise).
292 The data dictionary will be queried if a form's field group corresponds to a table
293 that does not have any fields defined in C<UI_TABLE_COLUMN> and appropriate default attributes will be used (schema auto-discovery).
294 NOTE! however that this is all or nothing - if using a database table to store form data and that table has at least one field defined in C<UI_TABLE_COLUMN>, then
295 all fields in that table must have a record in C<UI_TABLE_COLUMN> or bad things can happen. The exception here are Oracle LOB type fields
296 (BLOB, etc) - these fields are completely ignored by this module.
297  
298 You may also elect to leave some of the fields in C<UI_TABLE_COLUMN> NULL and they will be taken from the data dictionary. This is recommended
299 to avoid data duplication/syncing issues; essentially, it allows
300 the DBA to make changes that will be automagically reflected in the HTML forms (see C<use_data_dict>).
301  
302 The following is a list of fields in C<UI_TABLE_COLUMN> and how each influences the form HTML, presentation, access control, constraint checking, etc:
303  
304 =over 2
305  
306 =item TABLE_NAME
307  
308 UPPER CASE name of a table (or group of fields) that corresponds to a data group of a form object
309  
310 =item FIELD_NAME
311  
312 UPPER CASE name of a field associated with table_name
313  
314 =item APPEAR_ORDER
315  
316 Relative order the fields will appear in the form's data group (integer, recommended to use sequence of 10's - 10, 20, 30...)
317  
318 =item HEADING
319  
320 User-friendly name of FIELD_NAME that will appear in the form
321  
322 =item SEARCHABLE
323  
324 True/false - allows this field to appear in a search group
325  
326 =item UPDATABLE
327  
328 True/false - allows this field to be updated (e.g. set false for a primary key sequence)
329  
330 =item INSERTABLE
331  
332 True/false - allows this field to be defined by the operator for inserts (e.g. set false for auto-generated primary key sequence)
333  
334 =item INPUT_CONTROL_TYPE
335  
336 Form control type for operator input (update/insert groups) one of: TEXT, TEXTAREA, PASSWORD, DATE, DATETIME, FILE, SELECT, RADIO, CHECKGROUP
337  
338 =item MULTI_INSERT_DELIMITER
339  
340 For the CHECKGROUP input control, will insert multiple values as one field with each value serialized by this string (deserialized automagically on display)
341  
342 =item SEARCH_CONTROL_TYPE
343  
344 Form control type for search groups, one of: SELECT, CHECKBOX, RADIO, TEXT, MATCH TEXT, COMMALIST, DATE, DATETIME, DATERANGE, DATETRANGE (query on a range of date + time), RANGE
345  
346 =item SEARCH_MULT_SELECT
347  
348 For search groups, allow multi-select on a select box (values will be OR'ed using the IN operator) accepts an integer that gives the height of the control
349  
350 =item USE_DATA_DICT
351  
352 If true, datatype, default_value, required, input_size and input_maxlength will be taken from the data dictionary if those fields are NULL (recommended to use this whenever possible)
353  
354 =item DATATYPE
355  
356 Datatype constraint for this field, one of CHAR, DATE, NUMBER, DATETIME, INT, INT UNSIGNED
357  
358 =item DEFAULT_VALUE
359  
360 Default value for insert groups, can be the special value _SYSDATE for date types, meaning insert the current date
361  
362 =item REQUIRED
363  
364 True/false constraint - is empty input (NULL) acceptable?
365  
366 =item INPUT_SIZE
367  
368 For input_control_type of TEXT or PASSWORD - the width of the control box
369  
370 =item INPUT_MAXLENGTH
371  
372 For input_control_type of TEXT, PASSWORD - the maximum length of text that can be entered
373  
374 =item BRIEF_HEADING
375  
376 Short, user-friendly heading for the brief tabular display results (see B<Tabular data groups>)
377  
378 =item ALT_MASK_FIELD
379  
380 For auto-recognition of associated lookup table, an alternative name for the USER_MASK field (see B<Select lists & ID masking>)
381  
382 =item MASK_TABLE_NAME
383  
384 For configured recognition of associated lookup table, the name of the table with primary keys that match this foreign key (see B<Select lists & ID masking>)
385  
386 =item MASK_FIELD_NAME
387  
388 For configured recognition of associated lookup table, the name of the field that contains the user-friendly values (see B<Select lists & ID masking>)
389  
390 =item ID_FIELD_NAME
391  
392 For configured recognition of associated lookup table, the name of the field that contains the ID values as a unique or primary key (see B<Select lists & ID masking>)
393  
394 =item NO_CACHE
395  
396 True/false - use this for caching of the lookup table. If the records in the lookup table change frequently set this to TRUE. The default is FALSE,
397 which will cache the lookup table
398  
399 =item RADIO_CHECKBOX_COLS
400  
401 Integer value of the number of columns of buttons/controls for RADIO, CHECKBOX and CHECKGROUP controls.
402  
403 =item FIELD_GROUP
404  
405 Special considerations for a group of controls that govern a single field, only supported value is CONFIRM, which is useful for PASSWORD fields
406  
407 =item ELEMENT_ATTRS
408  
409 Additional attributes that will be added to the HTML control element (e.g. enter 'rows="5" cols="10"' to size a TEXTAREA control box)
410  
411 =item HELP_SUMMARY
412  
413 The heading of this field will be an active link and when clicked, will render this summary as a js alert giving useful hints to the operator about the use of this field
414  
415 =back
416  
417 Notes:
418  
419 All values in TABLE_NAME and FIELD_NAME must be UPPER CASE. If you have use an RDBMS where table names are case-sensitive (MySQL on Linux/UNIX)
420 and you have two or more tables with the same name but different letter cases, this is probably not a good idea to begin with but there is no workaround.
421  
422 True/false fields accept 'Y', 'N' or NULL only (NULL => false).
423  
424 Doesn't make much sense to have a value for C<input_control_type> if C<insertable> AND C<updatable> are set FALSE.
425  
426 Values left NULL will be given reasonable defaults.
427  
428 If C<CONFIRM> is used for C<field_group>, two controls will be presented and the values entered into each must match. This is useful for PASSWORD fields
429 where the operator can't see the input or other important fields that can be mistyped (email TEXT box, for example).
430  
431 For a well-defined set of records (with a common C<table_name>, where C<use_data_dict> is FALSE) C<table_name> does not have to refer to
432 a database table or any RDBMS entity at all. Feel free to make up a schema that doesn't even exist - I've done this to
433 manage an LDAP tree on the backend. You can even create your own data groups/controls that don't exist in C<UI_TABLE_COLUMN> by defining a record in a perl hash variable with
434 the keys of the hash being field names of C<UI_TABLE_COLUMN> (in UPPER CASE, example given in B<SYNOPSIS>).
435  
436 You'll want to set C<use_data_dict> TRUE if the data group is supported by a database table so that properties/constraints are
437 automagically taken from the database schema.
438  
439 For updates/inserts of submitted data, you may want to use only those fields that are updatable/insertable;
440 e.g. $table->insert({ %{$rec}{ map { $_->{UPDATABLE} eq 'Y' ? $_->{FIELD_NAME} : () } @$field_list } }).
441  
442 For search groups, multiple values selected in a select box or checkbox will be OR'ed together using the C<IN> SQL operator.
443  
444 Either alt_mask_field is populated or (mask_table_name, mask_field_name, id_field_name) as a group is populated (or none at all).
445 See B<Select lists & ID masking> for details.
446  
447 Careful with NO_CACHE as it can be confusing - the default (false) is to cache the underlying lookup table for the set of acceptable values.
448 If you have meta-data that changes on a daily basis (which is many times the case) set this to true ('Y').
449  
450 This module caches data dictionary info from the database. So if you're using a persistent interpreter (mod_perl), you'll
451 need to restart the webserver to recognize changes to the database structures (DDL modifications).
452  
453 Clarification on RADIO, CHECKBOX and CHECKGROUP control types.
454  
455 A RADIO set of controls only allows one value to be selected. CHECKBOX allows multiple values to be selected and is valid for C<SEARCH_CONTROL_TYPE>
456 where the values are or'd together in the search criteria (SELECT with C<SEARCH_MULT_SELECT> set to an integer value will have the same behavior).
457 CHECKGROUP allows for multiple values on INSERT and UPDATES such that these values are serialized into one field by the value of C<MULTI_INSERT_DELIMITER>.
458 If you use CHECKGROUP then you'll want to set C<MULTI_INSERT_DELIMITER> or the default value will be used, which is not what you want.
459 This behavior is very similar to the MySQL C<SET> data type. In fact you should be using CHECKGROUP for any MySQL C<SET> fields, in which
460 case the value for C<MULTI_INSERT_DELIMITER> is optional and ignored anyway because MySQL always uses a comma.
461  
462 Using CHECKBOX (or SELECT with C<SEARCH_MULT_SELECT> set to an integer value) for C<SEARCH_CONTROL_TYPE> where C<INPUT_CONTROL_TYPE> is set to CHECKBOX will
463 probably not do what you want. If you want to do subset searching within a field of multiple values, use C<MATCH TEXT>, which will
464 accept C<%> as a wildcard.
465  
466 Tip: use a select list for C<search_control_type> and text input box for C<input_control_type> for tables with numeric ID's as
467 the primary key. This will give a select list when doing a search masked with readable names and will give the numeric
468 ID value on inspection (not recommended for large tables as the select list becomes too large).
469  
470 =head2 Select lists & ID masking
471  
472 There is a significant amount of magic to mask ID values
473 with related lookup tables (meta-data) and verify referential integrity thereof. Take the example of a schema model of a CD
474 collection:
475  
476 ARTIST
477 +-------------------------+
478 | artist_id |
479 | artist_name (user_mask) |
480 | ... |
481 +-------------------------+
482 |
483 |
484 |
485 TITLE /|\
486 +--------------+
487 | artist_id |
488 | title |
489 | year |
490 | ... |
491 +--------------+
492  
493 In this simple example, you'd want to join these tables and present C<artist_name> to the operator rather
494 than the meaningless-to-humans C<artist_id>. The magic starts by specifying a discreet HTML form control type
495 (C<UI_TABLE_COLUMN.INPUT_CONTROL_TYPE>) e.g. SELECT or RADIO where table_name = 'TITLE' and field_name = 'ARTIST_ID'.
496 This is enough to automagically populate the control
497 with values from the related lookup table (ARTIST) with the meaningful artist names and will put a constraint check
498 on the server side (I claimed "high" security after all) to verify referential integrity.
499 The masked values will then be translated back on insert/update.
500  
501 This magic occurs when an appropriate control type is used and when there is a singular foreign key
502 where the foreign key column name (with the C<_ID> suffix stripped off, if present) matches a table name containing the unique/primary keys.
503 Additionally, the ID field name in the lookup
504 table must match the foreign key name and the human-friendly mask field must be named C<user_mask>.
505  
506 In this example above, all conditions are met except the mask field name is C<artist_name> (not C<user_mask>) so we'll
507 populate the set of fields (mask_table_name, mask_field_name, id_field_name) with ('ARTIST', 'ARTIST_ID', 'ARTIST_NAME') respectively where field_name = C<ARTIST_ID>
508 and table_name = C<TITLE>
509 for ultimate control over table/field names of related lookup tables.
510  
511 An example where you might use just alt_mask_field instead of the set (of fields (mask_table_name, mask_field_name, id_field_name) is perhaps
512 if you have a table COUNTRY with fields (country, user_mask) where country is the country code and user_mask is the country name
513 and a field in ARTIST (ARTIST.ORIGIN_COUNTRY) you'd simply set UI_TABLE_COLUMN.ALT_MASK_FIELD to 'COUNTRY' where field_name = C<ORIGIN_COUNTRY>
514 and table_name = C<ARTIST> and the magic will happen.
515  
516 If the underlying RDBMS is MySQL some additional magic parses allowed values for C<SET> and C<ENUM> data types to obtain
517 this pick list (no related table with a foreign key is necessary).
518  
519 If using a form control that demands a discreet set of values where none of the above conditions apply,
520 you must specify the list (see $pick_list under C<create_field>).
521  
522 This magic provides a great deal of convenience and security not only for translating ID values for human operators
523 but also for enforcing a discreet set of allowable values for certain form fields.
524  
525 =head2 Tabular data groups
526  
527 If passing a true value for $tabular to C<add_group>, that group's data (via C<add_record>) will be displayed
528 in a tabular form - one column for each field in the record (read-only). This is how you display multiple records in a data group.
529 The only fields that will be shown in a tabular view are the ones with a non-empty value for C<UI_TABLE_COLUMN.BRIEF_HEADING>.
530  
531 If $tabular is false (the default), a vertical form with a field heading and field value on each line is produced;
532 each use HTML C<table> elements however (see B<Form preparation, HTML generation & customization> for details).
533  
534 =head2 Form preparation, HTML generation & customization
535  
536 Once the data group(s) of the form object have been defined, C<prepare>
537 will generate the HTML, which should be inserted into the BODY section
538 of an HTML document (presumably using a templating system).
539 The structure of the generated HTML follows:
540  
541 Form Heading
542 <form>
543 <div>Data Group1 Heading</div>
544 <table>
545 tabular view of search results (see below)
546 -or-
547 vertical view of data group1 fields (see below)
548 </table>
549 [<div>Data Group2 Heading...</div>
550 ...]
551 </form>
552  
553 for the tabular view of a data group:
554 <thead><tr><th>Field1 name</th>[<th>Field2 name</th>...]</tr></thead>
555 <tr><td>Value1</td>[<td>Value2</td>...]</tr>
556 ...
557  
558 for the vertical view of a data group (updatable/insertable groups):
559 <tr><td><label>field name</label></td><td>field value/form control</td></tr>
560 ...
561  
562 See C<prepare> for further details of the layout.
563 See the Cruddy! demo for the default layout:
564  
565 L<http://www.thesmbexchange.com/cruddy/index.html>
566  
567 The HTML generated by C<prepare> can be influenced by a number of attributes
568 of the form object and group/field sub-object(s) (manipulate via hash keys, only some accessor methods have been defined as yet).
569 To get the $field sub-object (hashref) try C<$group-E<gt>{field_hash}{FIELD_NAME}> (see also C<field_hash>).
570 Some of the following attributes may have content already so it is best to append to them, rather
571 than assign/replace their values. C<prepare> also accepts some callbacks to allow further customization.
572 Unless otherwise noted, custom content is expected to be HTML (encode with HTML entities, etc, see C<escape>).
573  
574 =over
575  
576 =item $form->{top_message}
577  
578 Content displayed at the very top of the form.
579  
580 =item $form->{heading} (or $form->heading())
581  
582 Header content near the top of the form describing the form. Will be enclosed in an C<h2> block.
583  
584 =item $form->{heading2}
585  
586 Sub-header content near the top of the form.
587  
588 =item $form->{verr_msg}
589  
590 Error message displayed near the top of the form when there are validation errors (see C<validate_query>).
591  
592 =item $form->{noscript}
593  
594 Content enclosed in a C<noscript> block.
595  
596 =item $form->{name} (or $form->name())
597  
598 Will be used in the C<name> attribute of the C<form> element.
599  
600 =item $form->{action} (or $form->action() this needs to be set somewhere in your code)
601  
602 Will be used in the C<action> attribute of the C<form> element.
603  
604 =item $form->{submit_value} (or $form->submit_value())
605  
606 Will be used in the C<value> attribute of the submit button.
607 The value will be HTML-escaped (don't encode with HTML entities).
608  
609 =item $form->{submit_button_attrs}
610  
611 Appended to the list of attributes of the C<input> button controls (submit, reset, etc).
612  
613 =item $group->{heading}
614  
615 Header content at the top of the data group describing that group.
616  
617 =item $group->{GT}
618  
619 Appended to the list of attributes of the outermost C<table> element of each group.
620  
621 =item $group->{js}
622  
623 A block of javascript added to the HTML block of each data group.
624  
625 =item $form->{head_html}
626  
627 =item $form->{tail_html}
628  
629 =item $group->{head_html}
630  
631 =item $group->{tail_html}
632  
633 If these are defined before calling C<prepare>, their contents completely override those blocks of HTML (see C<prepare> for details).
634  
635 =item The following affect the presentation of data groups in the tabular view
636  
637 =over 2
638  
639 =item $group->{TABULAR_TH_ATTRS}
640  
641 For a tabular data group, this will append attributes to all C<th> elements in the data group (don't include a C<class> attribute).
642  
643 =item $field->{TABULAR_TH_ATTRS}
644  
645 For a tabular data group, this will append attributes to the C<th> element for
646 a particular $field sub-object (don't include a C<class> attribute).
647  
648 =item $field->{TABULAR_TD_ATTRS}
649  
650 For a tabular data group, this will append attributes to the C<td> elements
651 for a particular $field sub-object (don't include a C<class> attribute).
652  
653 =item $field->{TABULAR_TD_STYLE}
654  
655 For a tabular data group, this will append style properties to the C<style>
656 attribute of the C<td> elements for a particular $field sub-object.
657  
658 =item $group->{TABULAR_TD_TAIL_ATTRS}
659  
660 For a tabular data group, this will append attributes to the C<td> elements
661 on the final row in the table only (don't include a C<class> attribute).
662  
663 =item $group->{TABULAR_TD_TAIL_STYLE}
664  
665 For a tabular data group, this will append style properties to the C<style>
666 attribute of the C<td> elements on the final row in the table only.
667  
668 =item $group->{TABULAR_TR_TAIL_ATTRS}
669  
670 For a tabular data group, this will add to the list of attributes of the C<tr> element on the final
671 row in the table only.
672  
673 =back
674  
675 =item The following affect the presentation of data groups in the vertical view (updatable/insertable)
676  
677 =over 2
678  
679 =item $form->{VFR}
680  
681 For vertical view data groups (update/insert), this will add to the list of attributes of the C<tr> elements.
682  
683 =item $form->{VFL}
684  
685 For vertical view data groups (update/insert), this will add to the list of attributes of the C<td> elements containing the label.
686  
687 =item $form->{VFE}
688  
689 For vertical view data groups (update/insert), this will add to the list of attributes of the C<td> elements containing the value (control).
690  
691 =back
692  
693 =item $form->{dontescape}
694  
695 =item $form->{dontunescape}
696  
697 These don't really affect the presentation but for lack of a better place to document, these attributes
698 prevent any (un)escaping of HTML content (using HTML entities) during HTML generation (dontescape)
699 or during query extraction/normalization/validation (dontunescape).
700  
701 =back
702  
703 =head2 Style sheets
704  
705 Class attributes are hooked into the HTML that is generated to allow custom styling with CSS.
706 The following is a list of class names and how/where they influence the presentation.
707  
708 =over
709  
710 =item REQ
711  
712 For fields that require input (NOT NULL), C<label> elements will be tagged with this class.
713  
714 =item REQI
715  
716 For fields that require input (NOT NULL), C<input> elements will be tagged with this class.
717  
718 =item GH
719  
720 For each data group heading, the opening C<div> element will be tagged with this class.
721  
722 =item GT
723  
724 For each data group, the outermost C<table> element will be tagged with this class.
725  
726 =item TABULAR_TH
727  
728 For a tabular data group, the C<th> elements will be tagged with this class.
729  
730 =item TABULAR_TD
731  
732 For a tabular data group, the C<td> elements will be tagged with this class.
733  
734 =item GTAIL_TR
735  
736 For a tabular data group, the C<tr> element will be tagged with this class on the final
737 row in the table only.
738  
739 =item AS
740  
741 For fields with UI_TABLE_COLUMN.HELP_SUMMARY populated, the C<a> element will be tagged with this class.
742  
743 =item VFR
744  
745 For vertical view data groups (update/insert), the C<tr> elements will be tagged with this class.
746  
747 =item VFL
748  
749 For vertical view data groups (update/insert), the C<td> elements containing the label will be tagged with this class.
750  
751 =item VFE
752  
753 For vertical view data groups (update/insert), the C<td> elements containing the value (control) will be tagged with this class.
754  
755 =item CONFIRM
756  
757 For fields that use C<CONFIRM> for UI_TABLE_COLUMN.FIELD_GROUP, the C<label> element will be tagged with this class
758 for the second confirmation field.
759  
760 =item VERR_MSG
761  
762 If there are validation errors (see C<validate_query>) the enclosing C<div> tag of the error
763 message will be tagged with this class.
764  
765 =item VERR
766  
767 If there are validation errors C<font>, C<span> and C<label> elements of the vertical view of a data group will be tagged with this
768 class for invalid fields. For tabular groups, the C<td> elements of invalid fields will be tagged.
769  
770 =back
771  
772 =head2 Form field names
773  
774 To help avoid form field namespace collisions, the C<name> attribute of form controls will use the following format:
775  
776 E<lt>group_nameE<gt>.E<lt>field_nameE<gt>
777  
778 where E<lt>group_nameE<gt> is typically the name of the table but must be unique.
779  
780 C<structure_query>, C<extract_query_group> and C<extract_cut_query_group> provide handy ways
781 of organizing form data with this naming convention.
782  
783 =head1 METHODS
784  
785 =over 4
786  
787  
788 =item C<new> (constructor)
789  
790 $form = new CGI::AutoForm([$dbh],[$form_name]);
791  
792 Create a new $form object given an optional database handle
793 and optional name, which is helpful for CGI::AutoForm::Session.
794  
795 =cut
796 sub new
797 0 ▶{
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
798 0 my ($caller,$dbh,$name) = @_;
799 0 ▶ my $class = ref($caller) || $caller;
Condition0%0/3
ref $caller || $caller
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $caller || $caller
ref $caller $caller
Truth table0%0/3
A || B
A= ref $callerB= $caller
ABresult
1X1
011
000
800 0 my $self = bless({},$class);
801  
802 0 $self->{dbh} = $dbh;
803 0 $self->{curr_group_no} = -1;
804 0 $self->{curr_rec_no} = -1;
805 0 $self->{curr_field_no} = -1;
806 0 $self->{group_hash} = {};
807 0 $self->{group_list} = [];
808 0 $self->name($name);
809 0 $self->{hidden} = {};
810  
811 0 $self->{attr_defn_table_name} = 'ui_table_column';
812  
813 0 return $self;
814 }
815  
816 =pod
817  
818 =head2 Form Attribute Accessors/Modifiers
819  
820 Get the values of these READ-ONLY attributes.
821  
822 $dbh = $form->dbh();
823  
824 Get or set the values of these attributes.
825  
826 $bool = $form->readonly();
827 $name = $form->name();
828 $action = $form->action();
829 $heading = $form->heading();
830 $submit_value = $form->submit_value();
831 $hidden_fields = $form->hidden();
832 $meta = $form->meta();
833 $continue = $form->continue();
834  
835  
836 =cut
837 sub dbh
838 0 ▶{
Subroutine dbh: not called CC=1 SCAR=6.9
Pod undocumented
839 0 my $self = shift;
840 0 return $self->{dbh};
841 }
842  
843 =pod
844  
845 =item C<readonly>
846  
847  
848 Setting this attribute will force all data to be displayed
849 as read-only such that no form controls will be used.
850  
851 =cut
852 sub readonly
853 0 ▶{
Subroutine readonly: not called CC=2 SCAR=17.9
Pod documented
854 0 my ($self,$readonly) = @_;
855 0 ▶ if (defined($readonly))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $readonly) 0 0 0
856 {
857 0 $self->{readonly} = $readonly;
858 }
859 0 return $self->{readonly};
860 }
861  
862 sub meta
863 0 ▶{
Subroutine meta: not called CC=1 SCAR=6.9
Pod undocumented
864 0 my $self = shift;
865 0 return $self->{meta};
866 }
867  
868 sub continue
869 0 ▶{
Subroutine continue: not called CC=1 SCAR=6.9
Pod undocumented
870 0 my $self = shift;
871 0 return $self->{continue};
872 }
873  
874 #=pod
875 #
876 #=item C<name>
877 #
878 #
879 #Associate a name with $form. Will be used
880 #in the C<name> attribute of the HTML C<form> element.
881 #
882 #=cut
883 sub name
884 0 ▶{
Subroutine name: not called CC=2 SCAR=17.9
Pod documented
885 0 my ($self,$name) = @_;
886 0 ▶ if (defined($name))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name) 0 0 0
887 {
888 0 $self->{name} = $name;
889 }
890 0 return $self->{name};
891 }
892  
893 #=pod
894 #
895 #=item C<action>
896 #
897 #
898 #Specify the ACTION attribute of an HTML FORM element, e.g. a URI.
899 #
900 #=cut
901 sub action
902 0 ▶{
Subroutine action: not called CC=2 SCAR=17.9
Pod documented
903 0 my ($self,$action) = @_;
904 0 ▶ if (defined($action))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $action) 0 0 0
905 {
906 0 $self->{action} = $action;
907 }
908 0 return $self->{action};
909 }
910  
911 #=pod
912 #
913 #=item C<heading>
914 #
915 #The heading will be displayed near the top of the form in HTML.
916 #
917 #=cut
918 sub heading
919 0 ▶{
Subroutine heading: not called CC=2 SCAR=17.9
Pod documented
920 0 my ($self,$heading) = @_;
921 0 ▶ if (defined($heading))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $heading) 0 0 0
922 {
923 0 $self->{heading} = $heading;
924 }
925 0 return $self->{heading};
926 }
927  
928 #=pod
929 #
930 #=item C<submit_value>
931 #
932 #Override the text that appears in the form's SUBMIT button.
933 #
934 #=cut
935 sub submit_value
936 0 ▶{
Subroutine submit_value: not called CC=2 SCAR=17.9
Pod documented
937 0 my ($self,$submit_value) = @_;
938 0 ▶ if (defined($submit_value))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $submit_value) 0 0 0
939 {
940 0 $self->{submit_value} = $submit_value;
941 }
942 0 return $self->{submit_value};
943 }
944  
945 =pod
946  
947 =item C<add_group>
948  
949 $group_count = $form->add_group($usage[,$table_name,$heading,$group_name,$tabular,$defaults,$mid]);
950  
951 Add a data group to $form of type $usage. Elements of the group are taken from UI_TABLE_COLUMN
952 according to $usage and $table_name.
953  
954 $usage can be one of:
955  
956 $CGI::AutoForm::DISPLAY_ONLY_GROUP
957 $CGI::AutoForm::INSERT_GROUP
958 $CGI::AutoForm::EDIT_GROUP
959 $CGI::AutoForm::SEARCH_GROUP
960  
961 If $table_name is given,
962 fields of the group are taken from UI_TABLE_COLUMN or the data dictionary
963 as a last resort for that table name. If $table_name is not given, you are expected to add fields (see C<create_field> or C<add_field>).
964  
965 $heading is used to label the group on the HTML form
966 and has a reasonable default according to $group_name. $group_name
967 defaults to $table_name and can be specified in the case where
968 more than one group with the same $table_name will appear on the
969 same form. The groups of a form must have unique names.
970  
971 A true value for $tabular means the data that the group accumulates
972 will be displayed in a tabular view (see B<Tabular data groups>). If false, it does not make sense
973 to include more than one record for C<add_record> (or simply passing $query to C<prepare> is sufficient).
974  
975 $defaults can be specified as a hashref of FIELD_NAME => value
976 pairs to be used as default values for fields in the group.
977 These values will override those in UI_TABLE_COLUMN.DEFAULT_VALUE or those determined from the data dictionary.
978  
979 $mid will insert the group at a midpoint in the group list.
980 Default is the end of the list; index starts at 0 so say you want to insert a group
981 at position 4 on the form - you would specify 3 for $mid.
982  
983 Return the new number of groups for $form if successful.
984 Return 0 if no fields exist in UI_TABLE_COLUMN or the data dictionary for $table_name.
985 Return -1 if a pick_list could not be determined but is required (see C<create_field>).
986 Return -2 if $group_name is not unique.
987 Return -3 if data dictionary attributes were requested via UI_TABLE_COLUMN but could not be found.
988 Return undef if db error.
989  
990 This method affects the state of $form by incrementing the group#.
991  
992 =cut
993 ##at should rename this add_table_group() then have an add_static_group() for non-db lookups
994 sub add_group
995 0 ▶{
Subroutine add_group: not called CC=5 SCAR=34.0
Pod documented
996 0 my ($self,$usage,$table_name,$heading,$group_name,$tabular,$defaults,$mid) = @_;
997 0 my $group = $self->create_group($table_name,$heading,$group_name,$usage,$tabular);
998 0 ▶ my $elems = $self->push_group($group,$mid) || return -2;
Condition0%0/2
$self->push_group($group, $mid) || (return -2)
l!l
00
MC/DC0%0/1
$self->push_group($group, $mid) || (return -2)
$self->push_group($group, $mid)
Truth table0%0/2
A
A= $self->push_group($group, $mid)
Aresult
11
00
999 0 ▶ return 1 unless $table_name;
Branch: 1 branch
BranchTrueFalseTotal
unless $table_name 0 0 0
1000 0 my $fields = $self->field_template($usage,$table_name,$defaults);
1001 0 ▶ unless ($fields > 0)
Branch: 1 branch
BranchTrueFalseTotal
unless ($fields > 0) 0 0 0
1002 {
1003 0 return $fields;
1004 }
1005 0 my ($key,$val);
1006 0 ▶ while (($key,$val) = each(%$fields))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$fields) 0 0 0
1007 {
1008 0 $group->{$key} = $val;
1009 }
1010 0 return $elems;
1011 }
1012  
1013 =pod
1014  
1015 =head2 Group Attribute Accessors/Modifiers
1016  
1017 Get the values of these READ-ONLY group attributes. These are state dependent (refer to B<Form object structure>).
1018  
1019  
1020 $name = $form->current_group_name();
1021 $usage = $form->group_usage();
1022 $name = $form->curr_table_name();
1023  
1024  
1025 =cut
1026 sub current_group_name
1027 0 ▶{
Subroutine current_group_name: not called CC=1 SCAR=6.9
Pod undocumented
1028 0 my ($self) = @_;
1029 0 my $group = $self->current_group();
1030 0 return $group->{group_name};
1031 }
1032  
1033 sub group_usage
1034 0 ▶{
Subroutine group_usage: not called CC=1 SCAR=6.9
Pod undocumented
1035 0 my ($self) = @_;
1036 0 my $group = $self->current_group();
1037 0 return $group->{usage};
1038 }
1039  
1040 sub curr_table_name
1041 0 ▶{
Subroutine curr_table_name: not called CC=1 SCAR=6.9
Pod undocumented
1042 0 my ($self) = @_;
1043 0 my $group = $self->current_group();
1044 0 return $group->{table_name};
1045 }
1046  
1047 =pod
1048  
1049 =item C<current_group>
1050  
1051 $rec = $form->current_group();
1052  
1053 Return the $group structure of the current group.
1054 If there is no current group, the first one will be returned and curr_group_no modified.
1055  
1056 =cut
1057 sub current_group
1058 0 ▶{
Subroutine current_group: not called CC=2 SCAR=17.9
Pod documented
1059 0 my ($self) = @_;
1060 0 my $i = $self->{curr_group_no};
1061 0 ▶ $i = 0 if $i < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $i < 0 0 0 0
1062 0 return $self->{group_list}[$i];
1063 }
1064  
1065 =pod
1066  
1067 =item C<group_by_name>
1068  
1069 $group = $form->group_by_name($group_name);
1070  
1071 Return the $group structure identified by $group_name.
1072  
1073 =cut
1074 sub group_by_name
1075 0 ▶{
Subroutine group_by_name: not called CC=1 SCAR=6.9
Pod documented
1076 0 my ($self,$group_name) = @_;
1077 ##at really need to use Tie::IxHash - should set $self->{group_no} to the index of group_name
1078 0 return $self->{group_hash}{$group_name};
1079 }
1080  
1081 =pod
1082  
1083 =item C<reset_group>
1084  
1085 $form->reset_group();
1086  
1087 Zero the state of $form by resetting the group#, record# and field#.
1088  
1089 =cut
1090 sub reset_group
1091 0 ▶{
Subroutine reset_group: not called CC=1 SCAR=6.9
Pod documented
1092 0 my ($self) = @_;
1093 0 $self->{curr_group_no} = -1;
1094 0 $self->{curr_field_no} = -1;
1095 0 $self->{curr_rec_no} = -1;
1096  
1097 0 return 1;
1098 }
1099  
1100 # The VALUE or DISPLAY_VALUE attribute of the next field will be set
1101 # depending on the group usage, after making a copy of the field's hash stored in $group->{field_list}
1102 # the VALUE attribute can be an array ref of values where multiple values are
1103 # allowed.
1104  
1105 # Returns either a hashref of the next field's attributes, or
1106 # an array ref of field attributes in the case where a field
1107 # represents a group of form fields (e.g. an insert date field)
1108  
1109 # depends on curr_rec_no being incremented - DO NOT USE THIS METHOD WITHOUT next_record method
1110 sub next_field
1111 0 ▶{
Subroutine next_field: not called CC=6 SCAR=37.4
Pod undocumented
1112 0 my ($self) = @_;
1113 0 my $field_list = $self->field_list();
1114 0 my $field = $field_list->[++$self->{curr_field_no}];
1115 0 ▶ if (ref($field) && %$field)
Branch: 2 branches
BranchTrueFalseTotal
if (ref $field and %$field) { } 0 0 0
elsif (ref $field) { } 0 0 0
Condition0%0/3
ref $field and %$field
!ll&&!rl&&r
000
MC/DC0%0/2
ref $field and %$field
ref $field %$field
Truth table0%0/3
A and B
A= ref $fieldB= %$field
ABresult
0X0
100
111
1116 {
1117 0 ▶ unless ($field = $self->_export_field($field))
Branch: 1 branch
BranchTrueFalseTotal
unless ($field = $self->_export_field($field)) 0 0 0
1118 {
1119 0 ▶ defined($field) || return $field;
Branch: 1 branch
BranchTrueFalseTotal
defined $field or return $field 0 0 0
1120 0 return $self->next_field();
1121 }
1122 }
1123 elsif (ref($field))
1124 {
1125 # some kind of bug in perl?? an empty hash ref is an element beyond the number of elements in $field_list?
1126 0 undef($field);
1127 }
1128 0 return $field;
1129 }
1130  
1131 =pod
1132  
1133 =item C<control_type>
1134  
1135 $control_type = $form->control_type($field);
1136  
1137 Return the control type of $field specified in either UI_TABLE_COLUMN.INPUT_CONTROL_TYPE or UI_TABLE_COLUMN.SEARCH_CONTROL_TYPE
1138 depending upon the usage of the current data group (state dependent).
1139  
1140 =cut
1141 sub control_type
1142 0 ▶{
Subroutine control_type: not called CC=3 SCAR=24.8
Pod documented
1143 0 my ($self,$field,$usage) = @_;
1144 0 ▶ $usage ||= $self->group_usage();
Condition0%0/3
$usage ||= $self->group_usage
l!l&&r!l&&!r
000
MC/DC0%0/2
$usage ||= $self->group_usage
$usage $self->group_usage
Truth table0%0/3
A ||= B
A= $usageB= $self->group_usage
ABresult
1X1
011
000
1145 0 ▶ return ($usage eq $CGI::AutoForm::SEARCH_GROUP ? $field->{SEARCH_CONTROL_TYPE} : $field->{INPUT_CONTROL_TYPE});
Branch: 1 branch
BranchTrueFalseTotal
$usage eq $CGI::AutoForm::SEARCH_GROUP ? : 0 0 0
1146 }
1147  
1148 # for backwards compatibility
1149 sub _control_type
1150 0 ▶{
Subroutine _control_type: not called CC=1 SCAR=6.9
1151 0 &control_type;
1152 }
1153  
1154 =pod
1155  
1156 =head2 Customizing groups & fields
1157  
1158 The following methods allow you to manipulate
1159 and customize form definitions taken from UI_TABLE_COLUMN or the data dictionary. You may even roll your own
1160 fields by creating a hashref of NAME => value pairs that emulate a record from UI_TABLE_COLUMN.
1161  
1162 =cut
1163  
1164 =pod
1165  
1166 =item C<create_field>
1167  
1168 $group_field = $form->create_field($field[,$pick_list,$all_db_defn]);
1169  
1170 Given $field - a hashref of NAME => value pairs that resembles a record in UI_TABLE_COLUMN, return
1171 a hashref that is suitable to add to an existing data group structure ($group) using
1172 C<push_field>, C<unshift_field>, etc.
1173  
1174 $field is copied so be sure to use the return value.
1175  
1176 $pick_list is a list of discreet values that may be used for a field with a SELECT
1177 control list, RADIO or CHECKBOX group, etc. It is an arrayref of hashes, each hash with two keys:
1178 ID => C<value> attribute of the control element
1179 MASK => the human-friendly description the operator sees.
1180 You may also add/replace/modify the picklist after calling this method using C<replace_picklist>
1181 or by manipulating the following structures:
1182 $field->{PICK_LIST}
1183 $field->{PICK_HASH}
1184  
1185 If this field has a control type of C<SELECT>, C<RADIO>, C<CHECKBOX>, etc., or if $all_db_defn is true, a picklist will be looked for
1186 in the database or data dictionary (see B<Select lists & ID masking>) unless
1187 $pick_list is passed to this method.
1188  
1189 Advanced:
1190 The $field->{REQUIRED} attribute is always set false for SEARCHABLE data groups as no fields are required for running reports.
1191 If you really know what you're doing, it is OK to set this to true after calling
1192 this method.
1193  
1194 May return 0 if $pick_list was not given for a C<SELECT>, C<RADIO> or C<CHECKBOX> field and one could not be generated
1195 from the database using DBIx::IO::Mask.
1196 May return undef if a db error occurred with DBIx::IO::Mask
1197  
1198 =cut
1199 # If $no_group is true, $field->{FORM_ELEMENT_NAME} will not be defined (normally defined
1200 # using the namespace of the current group name). This means you'll have to define it elsewhere.
1201 # $usage must be one of the valid group usage identifiers.
1202 sub create_field
1203 0 ▶{
Subroutine create_field: not called CC=27 SCAR=66.3
Pod documented
1204 0 my ($self,$field_attrs,$pick_list,$all_db_defn,$no_group,$usage) = @_;
1205 0 $field_attrs = { %$field_attrs };
1206 0 ▶ $pick_list ||= $field_attrs->{PICK_LIST};
Condition0%0/3
$pick_list ||= $field_attrs->{"PICK_LIST"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$pick_list ||= $field_attrs->{"PICK_LIST"}
$pick_list $field_attrs->{"PICK_LIST"}
Truth table0%0/3
A ||= B
A= $pick_listB= $field_attrs->{"PICK_LIST"}
ABresult
1X1
011
000
1207 0 my $pick_hash;
1208 0 my $type = $self->control_type($field_attrs,$usage);
1209 0 my $fname = $field_attrs->{FIELD_NAME};
1210  
1211 0 my $group = $self->current_group();
1212 0 ▶ $pick_list = [ @{$group->{table}{io}{picklist}{$fname}} ] if (!ref($pick_list) && exists($group->{table}{io}{picklist}{$fname}) && @{$group->{table}{io}{picklist}{$fname}});
Branch: 1 branch
BranchTrueFalseTotal
if not ref $pick_list and exists $group->{"table"}{"io"}{"picklist"}{$fname} and @{$group->{"table"}{"io"}{"picklist"}{$fname};} 0 0 0
Condition0%0/6
not ref $pick_list and exists $group->{"table"}{"io"}{"picklist"}{$fname} and @{$group->{"table"}{"io"}{"picklist"}{$fname};}
!ll&&!rl&&r
000
not ref $pick_list and exists $group->{"table"}{"io"}{"picklist"}{$fname}
!ll&&!rl&&r
000
MC/DC0%0/3
not ref $pick_list and exists $group->{"table"}{"io"}{"picklist"}{$fname} and @{$group->{"table"}{"io"}{"picklist"}{$fname};}
not ref $pick_list exists $group->{"table"}{"io"}{"picklist"}{$fname} @{$group->{"table"}{"io"}{"picklist"}{$fname};}
Truth table0%0/4
not(A) and B and C
A= not ref $pick_listB= exists $group->{"table"}{"io"}{"picklist"}{$fname}C= @{$group->{"table"}{"io"}{"picklist"}{$fname};}
ABCresult
0XX0
10X0
1100
1111
1213  
1214 0 ▶ if (($type eq 'SELECT' || $type eq 'RADIO' || $type eq 'CHECKBOX' || $type eq 'CHECKGROUP' || $all_db_defn) && !ref($pick_list))
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'SELECT' || $type eq 'RADIO' || $type eq 'CHECKBOX' || $type eq 'CHECKGROUP' || $all_db_defn and not ref $pick_list) { } 0 0 0
elsif (ref $pick_list) { } 0 0 0
Condition0%0/15
$type eq "SELECT" || $type eq "RADIO" || $type eq "CHECKBOX" || $type eq "CHECKGROUP" || $all_db_defn and not ref $pick_list
!ll&&!rl&&r
000
$type eq "SELECT" or $type eq "RADIO" or $type eq "CHECKBOX" or $type eq "CHECKGROUP" or $all_db_defn
l!l&&r!l&&!r
000
$type eq "SELECT" or $type eq "RADIO" or $type eq "CHECKBOX" or $type eq "CHECKGROUP"
l!l&&r!l&&!r
000
$type eq "SELECT" or $type eq "RADIO" or $type eq "CHECKBOX"
l!l&&r!l&&!r
000
$type eq "SELECT" or $type eq "RADIO"
l!l&&r!l&&!r
000
MC/DC0%0/6
$type eq "SELECT" || $type eq "RADIO" || $type eq "CHECKBOX" || $type eq "CHECKGROUP" || $all_db_defn and not ref $pick_list
$type eq "SELECT" $type eq "RADIO" $type eq "CHECKBOX" $type eq "CHECKGROUP" $all_db_defn not ref $pick_list
Truth table0%0/11
A or B or C or D or E and not(F)
A= $type eq "SELECT"B= $type eq "RADIO"C= $type eq "CHECKBOX"D= $type eq "CHECKGROUP"E= $all_db_defnF= not ref $pick_list
ABCDEFresult
00000X0
1XXXX00
01XXX00
001XX00
0001X00
0000100
1XXXX11
01XXX11
001XX11
0001X11
0000111
1215 {
1216 0 my $dbh = $self->dbh();
1217 0 my $oldp = $dbh->{PrintError};
1218 0 $dbh->{PrintError} = 0;
1219 my $masker = new DBIx::IO::Mask($self->dbh(),($field_attrs->{ALT_MASK_FIELD} || lc($fname)),
1220 0 ▶ $field_attrs->{MASK_TABLE_NAME},$field_attrs->{MASK_FIELD_NAME},$field_attrs->{ID_FIELD_NAME},($field_attrs->{NO_CACHE} eq 'Y'));
Condition0%0/3
$field_attrs->{'ALT_MASK_FIELD'} || lc $fname
l!l&&r!l&&!r
000
MC/DC0%0/2
$field_attrs->{'ALT_MASK_FIELD'} || lc $fname
$field_attrs->{'ALT_MASK_FIELD'} lc $fname
Truth table0%0/3
A || B
A= $field_attrs->{'ALT_MASK_FIELD'}B= lc $fname
ABresult
1X1
011
000
1221 0 $dbh->{PrintError} = $oldp;
1222 0 ▶ if ($masker)
Branch: 1 branch
BranchTrueFalseTotal
if ($masker) { } 0 0 0
1223 {
1224 0 $pick_list = $masker->pick_list();
1225 0 $pick_hash = $masker->ids_to_mask();
1226 }
1227 else
1228 {
1229 0 ▶ unless ($all_db_defn)
Branch: 1 branch
BranchTrueFalseTotal
unless ($all_db_defn) 0 0 0
1230 {
1231 0 ▶ if (defined($masker))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $masker) { } 0 0 0
1232 {
1233 # may add picklist after creating the field!! warn("No mask list found for " . $fname);
1234 # return $masker;
1235 }
1236 else
1237 {
1238 0 warn("No mask list found for $field_attrs->{TABLE_NAME}.$fname, perhaps you need to set UI_TABLE_COLUMN.MASK_TABLE_NAME et al appropriately.\n",$dbh->errstr());
1239 0 return $masker;
1240 }
1241 }
1242 }
1243 }
1244 elsif (ref($pick_list))
1245 {
1246 0 $pick_hash = { map { $_->{ID} => $_->{MASK} } @$pick_list };
1247 }
1248  
1249 0 ▶ if ($all_db_defn && ref($pick_list))
Branch: 1 branch
BranchTrueFalseTotal
if ($all_db_defn and ref $pick_list) 0 0 0
Condition0%0/3
$all_db_defn and ref $pick_list
!ll&&!rl&&r
000
MC/DC0%0/2
$all_db_defn and ref $pick_list
$all_db_defn ref $pick_list
Truth table0%0/3
A and B
A= $all_db_defnB= ref $pick_list
ABresult
0X0
100
111
1250 {
1251 # if mask test is true and all defn come from db, set SEARCH_MULT_SELECT (will only affect SEARCHABLE groups)
1252 0 $field_attrs->{INPUT_CONTROL_TYPE} = 'SELECT';
1253 0 $field_attrs->{SEARCH_CONTROL_TYPE} = 'SELECT';
1254 0 $field_attrs->{SEARCH_MULT_SELECT} = 3;
1255  
1256 # Special magic for MySQL's SET type
1257 0 ▶ if ($group->{table}{io}{column_types}{$fname} eq 'SET')
Branch: 1 branch
BranchTrueFalseTotal
if ($group->{"table"}{"io"}{"column_types"}{$fname} eq "SET") 0 0 0
1258 {
1259 0 $field_attrs->{INPUT_CONTROL_TYPE} = 'CHECKGROUP';
1260 0 $field_attrs->{SEARCH_CONTROL_TYPE} = 'MATCH TEXT';
1261 0 $field_attrs->{SEARCH_MULT_SELECT} = undef;
1262 }
1263  
1264 0 $type = $self->control_type($field_attrs,$usage);
1265 }
1266  
1267 # Special magic for MySQL's SET type
1268 0 ▶ $field_attrs->{MULTI_INSERT_DELIMITER} = ',' if $group->{table}{io}{column_types}{$fname} eq 'SET';
Branch: 1 branch
BranchTrueFalseTotal
if $group->{"table"}{"io"}{"column_types"}{$fname} eq "SET" 0 0 0
1269  
1270 0 $field_attrs->{PICK_LIST} = $pick_list;
1271 0 $field_attrs->{PICK_HASH} = $pick_hash;
1272  
1273 0 ▶ return $field_attrs if $no_group;
Branch: 1 branch
BranchTrueFalseTotal
if $no_group 0 0 0
1274
1275 0 my $group_name = $self->current_group_name();
1276 0 my $elem_name_app;
1277 0 ▶ if ($type eq 'TEXT' && _isdate($field_attrs) && !$usage)
Branch: 4 branches
BranchTrueFalseTotal
if ($type eq 'TEXT' and _isdate($field_attrs) and not $usage) { } 0 0 0
elsif ($type eq 'MATCH TEXT') { } 0 0 0
elsif ($type eq 'CHECKGROUP') { } 0 0 0
elsif ($type eq 'COMMALIST') { } 0 0 0
Condition0%0/6
$type eq "TEXT" and _isdate($field_attrs) and not $usage
!ll&&!rl&&r
000
$type eq "TEXT" and _isdate($field_attrs)
!ll&&!rl&&r
000
MC/DC0%0/3
$type eq "TEXT" and _isdate($field_attrs) and not $usage
$type eq "TEXT" _isdate($field_attrs) not $usage
Truth table0%0/4
A and B and not(C)
A= $type eq "TEXT"B= _isdate($field_attrs)C= not $usage
ABCresult
0XX0
10X0
1100
1111
1278 {
1279 # this extension will be stripped via normalize_query()
1280 # This will signal when a TEXT field needs to be checked that it holds a parseable date string
1281 0 $elem_name_app = "._DT";
1282 }
1283 elsif ($type eq 'MATCH TEXT')
1284 {
1285 # this signals when a search should use wildcards
1286 0 $elem_name_app = "._WM";
1287 }
1288 elsif ($type eq 'CHECKGROUP')
1289 {
1290 0 $elem_name_app = "._CG";
1291 }
1292 elsif ($type eq 'COMMALIST')
1293 {
1294 0 $elem_name_app = "._CL";
1295 }
1296 0 $field_attrs->{FORM_ELEMENT_NAME} = "$group_name." . $fname . $elem_name_app;
1297 0 return $field_attrs;
1298 }
1299  
1300 =pod
1301  
1302 =item C<add_field>
1303  
1304 $field_count = $form->add_field($field[,$picklist,$mid]);
1305  
1306 Conveniently combines C<create_field> and C<push_field>.
1307  
1308 =cut
1309 ##at on this and related methods, should check to make sure a group exists!!
1310 sub add_field
1311 0 ▶{
Subroutine add_field: not called CC=2 SCAR=17.9
Pod documented
1312 0 my ($self,$field,$picklist,$mid) = @_;
1313 0 ▶ unless ($field = $self->create_field($field,$picklist))
Branch: 1 branch
BranchTrueFalseTotal
unless ($field = $self->create_field($field, $picklist)) 0 0 0
1314 {
1315 0 return $field;
1316 }
1317 0 return $self->push_field($field,$mid);
1318 }
1319  
1320 =pod
1321  
1322 =item C<replace_picklist>
1323  
1324 $pick_hash = $form->replace_picklist($field_name,$pick_list[,$group]);
1325  
1326 Replace the picklist of $field_name with $pick_list for $group (which defaults
1327 to the current group).
1328  
1329 =cut
1330 sub replace_picklist
1331 0 ▶{
Subroutine replace_picklist: not called CC=2 SCAR=17.9
Pod documented
1332 0 my ($self,$field_name,$pick_list,$group) = @_;
1333 0 $field_name = uc($field_name);
1334 0 ▶ $group ||= $self->current_group();
Condition0%0/3
$group ||= $self->current_group
l!l&&r!l&&!r
000
MC/DC0%0/2
$group ||= $self->current_group
$group $self->current_group
Truth table0%0/3
A ||= B
A= $groupB= $self->current_group
ABresult
1X1
011
000
1335 0 $group->{field_hash}{$field_name}{PICK_LIST} = $pick_list;
1336 0 my $pick_hash = { map { $_->{ID} => $_->{MASK} } @$pick_list };
1337 0 return $group->{field_hash}{$field_name}{PICK_HASH} = $pick_hash;
1338 }
1339  
1340 =pod
1341  
1342 =item C<push_group>
1343  
1344 $group_count = $form->push_group($group[,$mid]);
1345  
1346 Push $group on to the end of the group list or at the position $mid (using splice) if provided.
1347 Alters the current group number (state) to point to the $group just added.
1348  
1349 =cut
1350 sub push_group
1351 0 ▶{
Subroutine push_group: not called CC=3 SCAR=24.8
Pod documented
1352 0 my ($self,$group,$mid) = @_;
1353 0 ▶ defined($mid) || ($mid = @{$self->{group_list}});
Branch: 1 branch
BranchTrueFalseTotal
defined $mid or $mid = @{$self->{"group_list"};} 0 0 0
1354 0 my $name = $group->{group_name};
1355 0 ▶ exists($self->{group_hash}{$name}) && (warn("\$group_name [$name] not unique"),return undef);
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{"group_hash"}{$name} and warn("\$group_name [$name] not unique"), (return undef) 0 0 0
1356 0 $self->{group_hash}{$name} = $group;
1357 0 splice(@{$self->{group_list}},$mid,0,$group);
1358 0 my $elems = @{$self->{group_list}};
1359 0 $self->{curr_group_no} = $mid;
1360 0 return $elems;
1361 }
1362  
1363 =pod
1364  
1365 =item C<push_field>
1366  
1367 $field_count = $form->push_field($field[,$mid]);
1368  
1369 Push $field (see C<create_field>) on to the end of the field list of the current group (or at the position $mid if provided).
1370  
1371 =cut
1372 sub push_field
1373 0 ▶{
Subroutine push_field: not called CC=2 SCAR=17.9
Pod documented
1374 0 my ($self,$field,$mid) = @_;
1375 0 my $field_list = $self->field_list();
1376 0 ▶ defined($mid) || ($mid = @{$field_list});
Branch: 1 branch
BranchTrueFalseTotal
defined $mid or $mid = @{$field_list;} 0 0 0
1377 0 my $field_hash = $self->field_hash();
1378 0 $field_hash->{$field->{FIELD_NAME}} = $field;
1379 0 splice(@{$field_list},$mid,0,$field);
1380 0 return scalar(@{$field_list});
1381 }
1382  
1383  
1384 ##at would be nice to have a field {NEVER_SHOW} that flagged if it should be included in the record at all (hidden or otherwise)
1385  
1386 =pod
1387  
1388 =item C<unshift_field>
1389  
1390 $field_count = $form->unshift_field($field);
1391  
1392 unshift $field (see C<create_field>) on to the beginning of the field list of the current group.
1393  
1394 =cut
1395 sub unshift_field
1396 0 ▶{
Subroutine unshift_field: not called CC=1 SCAR=6.9
Pod documented
1397 0 my ($self,$field) = @_;
1398 0 my $field_list = $self->field_list();
1399 0 my $field_hash = $self->field_hash();
1400 0 $field_hash->{$field->{FIELD_NAME}} = $field;
1401 0 return unshift(@{$field_list},$field);
1402 }
1403  
1404 sub pop_field
1405 0 ▶{
Subroutine pop_field: not called CC=2 SCAR=17.9
Pod undocumented
1406 0 my ($self) = @_;
1407 0 my $field_list = $self->field_list();
1408 0 my $field_hash = $self->field_hash();
1409 0 my $field = pop(@{$field_list});
1410 0 ▶ delete($field_hash->{$field->{FIELD_NAME}}) if ref($field);
Branch: 1 branch
BranchTrueFalseTotal
if ref $field 0 0 0
1411 0 return $field;
1412 }
1413  
1414 sub shift_field
1415 0 ▶{
Subroutine shift_field: not called CC=2 SCAR=17.9
Pod undocumented
1416 0 my ($self) = @_;
1417 0 my $field_list = $self->field_list();
1418 0 my $field_hash = $self->field_hash();
1419 0 my $field = shift(@{$field_list});
1420 0 ▶ delete($field_hash->{$field->{FIELD_NAME}}) if ref($field);
Branch: 1 branch
BranchTrueFalseTotal
if ref $field 0 0 0
1421 0 return $field;
1422 }
1423  
1424 =pod
1425  
1426 =item C<delete_field>
1427  
1428 $deleted_field = $form->delete_field($field_name[,$group]);
1429  
1430 Delete the field hashref identified by $field_name from $group (defaults
1431 to the current group). Return the deleted field hashref.
1432  
1433 =cut
1434 # Assumes that FIELD_NAME is unique
1435 # Modifies by reference (no copying is done)
1436 sub delete_field
1437 0 ▶{
Subroutine delete_field: not called CC=5 SCAR=34.0
Pod documented
1438 0 my ($self,$field_name,$group) = @_;
1439 0 $field_name = uc($field_name);
1440 0 my $field_list;
1441 my $field_hash;
1442 0 ▶ if ($group)
Branch: 1 branch
BranchTrueFalseTotal
if ($group) { } 0 0 0
1443 {
1444 0 $field_list = $group->{field_list};
1445 0 $field_hash = $group->{field_hash};
1446 }
1447 else
1448 {
1449 0 $field_list = $self->field_list();
1450 0 $field_hash = $self->field_hash();
1451 }
1452 0 my $i = 0;
1453 0 foreach my $field (@{$field_list})
1454 {
1455 0 ▶ next if $field->{FIELD_NAME} eq $field_name;
Branch: 1 branch
BranchTrueFalseTotal
if $field->{"FIELD_NAME"} eq $field_name 0 0 0
1456 0 $field_list->[$i] = $field;
1457 0 $i++;
1458 }
1459 0 ▶ return if @{$field_list} == $i;
Branch: 1 branch
BranchTrueFalseTotal
if @{$field_list;} == $i 0 0 0
1460 0 pop(@{$field_list});
1461 0 return delete($field_hash->{$field_name});
1462 }
1463  
1464 =pod
1465  
1466 =item C<db_fields>
1467  
1468 $fields = $form->db_fields($table_name,$usage);
1469  
1470 Return a hashref of $field structures from the database using $table_name. Check UI_TABLE_COLUMN first and then the data dictionary. This
1471 is useful for customizing a data group or adding fields from different tables into the same
1472 data group, etc.
1473  
1474 Return 0 if no fields exist in UI_TABLE_COLUMN or the data dictionary for $table_name.
1475 Return -1 if a pick_list could not be determined but is required (see C<create_field>).
1476 Return -3 if data dictionary attributes were requested via UI_TABLE_COLUMN but could not be found.
1477 Return undef if db error.
1478  
1479 =cut
1480 sub db_fields
1481 0 ▶{
Subroutine db_fields: not called CC=2 SCAR=17.9
Pod documented
1482 0 my ($self,$table_name,$usage) = @_;
1483 0 my $fields = $self->field_template($usage,$table_name,undef,1);
1484 0 ▶ unless ($fields > 0)
Branch: 1 branch
BranchTrueFalseTotal
unless ($fields > 0) 0 0 0
1485 {
1486 0 return $fields;
1487 }
1488 0 return $fields->{field_hash};
1489 }
1490  
1491 # By convention, all TABLE_NAME GROUP_NAME and FIELD_NAME are case-sensitive and always UPPER CASE
1492  
1493 # If successful, return a hashref where:
1494 # field_list => fields in the order they should appear on the form
1495 # field_hash => fields keyed by UI_TABLE_COLUMN.FIELD_NAME
1496 # fields may be defined in UI_TABLE_COLUMN or may be derived from the db dict via table_name
1497  
1498 # Return 0 if no fields exist in UI_TABLE_COLUMN for $table_name
1499 # Return -1 if a pick_list could not be culled using DBIx::IO::Mask
1500 # Return -3 if data dictionary attributes were requested but could not be found
1501 # Return undef if db error
1502  
1503 # $defaults override those listed in the db
1504 ##at maybe cache field_list for the entire class??
1505 sub field_template
1506 0 ▶{
Subroutine field_template: not called CC=48 SCAR=77.6
Pod undocumented
1507 0 my ($self,$usage,$table_name,$defaults,$no_group) = @_;
1508 0 ▶ $defaults ||= {};
Condition0%0/2
$defaults ||= {}
l!l
00
MC/DC0%0/1
$defaults ||= {}
$defaults
Truth table0%0/2
A
A= $defaults
Aresult
11
00
1509 0 my $orig_table_name = $table_name;
1510 0 $table_name = uc($table_name);
1511  
1512 0 my $group = $self->current_group();
1513  
1514 0 my $recs = [];
1515 0 my $searcher = new DBIx::IO::Search($self->dbh(),$self->{attr_defn_table_name});
1516 0 ▶ if (ref($searcher))
Branch: 2 branches
BranchTrueFalseTotal
if (ref $searcher) { } 0 0 0
elsif (not defined $searcher) { } 0 0 0
1517 {
1518 0 $searcher->build_scalar_crit('TABLE_NAME','=',$table_name);
1519 ##at $searcher->build_scalar_crit($usage,'=','Y') unless $usage eq $CGI::AutoForm::DISPLAY_ONLY_GROUP || $usage eq $CGI::AutoForm::EDIT_GROUP;
1520 0 ▶ $recs = $searcher->search(undef,[ 'APPEAR_ORDER' ]) || return undef;
Condition0%0/2
$searcher->search(undef, ['APPEAR_ORDER']) || (return undef)
l!l
00
MC/DC0%0/1
$searcher->search(undef, ['APPEAR_ORDER']) || (return undef)
$searcher->search(undef, ['APPEAR_ORDER'])
Truth table0%0/2
A
A= $searcher->search(undef, ['APPEAR_ORDER'])
Aresult
11
00
1521 }
1522 elsif (!defined($searcher))
1523 {
1524 0 return undef;
1525 }
1526  
1527 0 my $all_db_defn;
1528 my $table;
1529 0 ▶ unless (@$recs)
Branch: 1 branch
BranchTrueFalseTotal
unless (@$recs) 0 0 0
1530 {
1531 # Try and see if a table exists
1532 0 ▶ if ($table = new DBIx::IO::Table($self->dbh(),undef,undef,$orig_table_name))
Branch: 1 branch
BranchTrueFalseTotal
if ($table = 'DBIx::IO::Table'->new($self->dbh, undef, undef, $orig_table_name)) { } 0 0 0
1533 {
1534 0 foreach my $col (@{$table->{io}{col_list}})
1535 {
1536 # Ignore LOB types completely (Oracle)
1537 push(@$recs, { TABLE_NAME => $table_name, FIELD_NAME => $col, UPDATABLE => 'Y', SEARCHABLE => 'Y', INSERTABLE => 'Y', })
1538 0 ▶ unless $table->{io}->is_ignore_type($table->column_type($col));
Branch: 1 branch
BranchTrueFalseTotal
unless $table->{"io"}->is_ignore_type($table->column_type($col)) 0 0 0
1539 }
1540 0 ▶ unless ($no_group)
Branch: 1 branch
BranchTrueFalseTotal
unless ($no_group) 0 0 0
1541 {
1542 0 $group->{table} = $table;
1543 }
1544 0 $all_db_defn++;
1545 }
1546 else
1547 {
1548 0 ▶ defined($table) || return $table;
Branch: 1 branch
BranchTrueFalseTotal
defined $table or return $table 0 0 0
1549 }
1550 0 ▶ @$recs || (warn("No fields defined for $orig_table_name"),return 0);
Branch: 1 branch
BranchTrueFalseTotal
@$recs or warn("No fields defined for $orig_table_name"), (return 0) 0 0 0
1551 }
1552 0 my $field_hash = {};
1553 0 my $fields = [];
1554 0 foreach my $rec (@$recs)
1555 {
1556 0 my $fname = uc($rec->{FIELD_NAME});
1557 0 $rec->{FIELD_NAME} = $fname;
1558 0 ▶ if ($rec->{USE_DATA_DICT} eq 'Y' || $all_db_defn)
Branch: 1 branch
BranchTrueFalseTotal
if ($rec->{'USE_DATA_DICT'} eq 'Y' or $all_db_defn) { } 0 0 0
Condition0%0/3
$rec->{"USE_DATA_DICT"} eq "Y" or $all_db_defn
l!l&&r!l&&!r
000
MC/DC0%0/2
$rec->{"USE_DATA_DICT"} eq "Y" or $all_db_defn
$rec->{"USE_DATA_DICT"} eq "Y" $all_db_defn
Truth table0%0/3
A or B
A= $rec->{"USE_DATA_DICT"} eq "Y"B= $all_db_defn
ABresult
1X1
011
000
1559 {
1560 0 my $rv;
1561 0 ▶ unless ($rv = $self->use_data_dict($rec,$orig_table_name,$table,$no_group))
Branch: 1 branch
BranchTrueFalseTotal
unless ($rv = $self->use_data_dict($rec, $orig_table_name, $table, $no_group)) 0 0 0
1562 {
1563 0 ▶ defined($rv) && return -3;
Branch: 1 branch
BranchTrueFalseTotal
defined $rv and return -3 0 0 0
1564 0 return $rv;
1565 }
1566 }
1567 else
1568 {
1569 0 ▶ $rec->{DATATYPE} = 'CHAR' unless $rec->{DATATYPE};
Branch: 1 branch
BranchTrueFalseTotal
unless $rec->{"DATATYPE"} 0 0 0
1570 0 ▶ $rec->{INPUT_SIZE} ||= $CGI::AutoForm::DEFAULT_FIELD_LENGTH;
Condition0%0/3
$rec->{"INPUT_SIZE"} ||= $CGI::AutoForm::DEFAULT_FIELD_LENGTH
l!l&&r!l&&!r
000
MC/DC0%0/2
$rec->{"INPUT_SIZE"} ||= $CGI::AutoForm::DEFAULT_FIELD_LENGTH
$rec->{"INPUT_SIZE"} $CGI::AutoForm::DEFAULT_FIELD_LENGTH
Truth table0%0/3
A ||= B
A= $rec->{"INPUT_SIZE"}B= $CGI::AutoForm::DEFAULT_FIELD_LENGTH
ABresult
1X1
011
000
1571 0 ▶ $rec->{INPUT_MAXLENGTH} ||= $CGI::AutoForm::DEFAULT_FIELD_LENGTH;
Condition0%0/3
$rec->{"INPUT_MAXLENGTH"} ||= $CGI::AutoForm::DEFAULT_FIELD_LENGTH
l!l&&r!l&&!r
000
MC/DC0%0/2
$rec->{"INPUT_MAXLENGTH"} ||= $CGI::AutoForm::DEFAULT_FIELD_LENGTH
$rec->{"INPUT_MAXLENGTH"} $CGI::AutoForm::DEFAULT_FIELD_LENGTH
Truth table0%0/3
A ||= B
A= $rec->{"INPUT_MAXLENGTH"}B= $CGI::AutoForm::DEFAULT_FIELD_LENGTH
ABresult
1X1
011
000
1572 }
1573 0 ▶ if (!$rec->{SEARCH_CONTROL_TYPE} && $usage eq $CGI::AutoForm::SEARCH_GROUP)
Branch: 2 branches
BranchTrueFalseTotal
if (not $rec->{'SEARCH_CONTROL_TYPE'} and $usage eq $CGI::AutoForm::SEARCH_GROUP) { } 0 0 0
elsif (not $rec->{'INPUT_CONTROL_TYPE'} || $self->is_readonly($rec)) { } 0 0 0
Condition0%0/3
not $rec->{"SEARCH_CONTROL_TYPE"} and $usage eq $CGI::AutoForm::SEARCH_GROUP
!ll&&!rl&&r
000
MC/DC0%0/2
not $rec->{"SEARCH_CONTROL_TYPE"} and $usage eq $CGI::AutoForm::SEARCH_GROUP
not $rec->{"SEARCH_CONTROL_TYPE"} $usage eq $CGI::AutoForm::SEARCH_GROUP
Truth table0%0/3
not(A) and B
A= not $rec->{"SEARCH_CONTROL_TYPE"}B= $usage eq $CGI::AutoForm::SEARCH_GROUP
ABresult
0X0
100
111
1574 {
1575 0 my $ir = $rec->{INPUT_CONTROL_TYPE};
1576 0 ▶ if ($ir)
Branch: 2 branches
BranchTrueFalseTotal
if ($ir) { } 0 0 0
elsif (_isdate($rec)) { } 0 0 0
1577 {
1578 0 ▶ $rec->{SEARCH_CONTROL_TYPE} = 'DATERANGE' if $ir eq 'DATE';
Branch: 1 branch
BranchTrueFalseTotal
if $ir eq "DATE" 0 0 0
1579 0 ▶ $rec->{SEARCH_CONTROL_TYPE} = 'DATETRANGE' if $ir eq 'DATETIME';
Branch: 1 branch
BranchTrueFalseTotal
if $ir eq "DATETIME" 0 0 0
1580 0 ▶ $rec->{SEARCH_CONTROL_TYPE} = 'SELECT' if $ir eq 'SELECT';
Branch: 1 branch
BranchTrueFalseTotal
if $ir eq "SELECT" 0 0 0
1581 0 ▶ $rec->{SEARCH_CONTROL_TYPE} = 'RADIO' if $ir eq 'RADIO';
Branch: 1 branch
BranchTrueFalseTotal
if $ir eq "RADIO" 0 0 0
1582 }
1583 elsif (_isdate($rec))
1584 {
1585 0 ▶ $rec->{SEARCH_CONTROL_TYPE} = 'DATETRANGE' if $rec->{DATATYPE} eq 'DATETIME';
Branch: 1 branch
BranchTrueFalseTotal
if $rec->{"DATATYPE"} eq "DATETIME" 0 0 0
1586 0 ▶ $rec->{SEARCH_CONTROL_TYPE} = 'DATERANGE' if $rec->{DATATYPE} eq 'DATE';
Branch: 1 branch
BranchTrueFalseTotal
if $rec->{"DATATYPE"} eq "DATE" 0 0 0
1587 }
1588 else
1589 {
1590 0 $rec->{SEARCH_CONTROL_TYPE} = 'TEXT';
1591 }
1592 }
1593 ▶ elsif (!$rec->{INPUT_CONTROL_TYPE} && !$self->is_readonly($rec))
Condition0%0/3
$rec->{'INPUT_CONTROL_TYPE'} || $self->is_readonly($rec)
l!l&&r!l&&!r
000
MC/DC0%0/2
$rec->{'INPUT_CONTROL_TYPE'} || $self->is_readonly($rec)
$rec->{'INPUT_CONTROL_TYPE'} $self->is_readonly($rec)
Truth table0%0/3
A || B
A= $rec->{'INPUT_CONTROL_TYPE'}B= $self->is_readonly($rec)
ABresult
1X1
011
000
1594 {
1595 0 ▶ if (_isdate($rec))
Branch: 1 branch
BranchTrueFalseTotal
if (_isdate($rec)) { } 0 0 0
1596 {
1597 0 ▶ $rec->{INPUT_CONTROL_TYPE} = 'DATETIME' if $rec->{DATATYPE} eq 'DATETIME';
Branch: 1 branch
BranchTrueFalseTotal
if $rec->{"DATATYPE"} eq "DATETIME" 0 0 0
1598 0 ▶ $rec->{INPUT_CONTROL_TYPE} = 'DATE' if $rec->{DATATYPE} eq 'DATE';
Branch: 1 branch
BranchTrueFalseTotal
if $rec->{"DATATYPE"} eq "DATE" 0 0 0
1599 }
1600 else
1601 {
1602 0 $rec->{INPUT_CONTROL_TYPE} = 'TEXT';
1603 }
1604 }
1605  
1606 # Disable searches for Oracle LONG or RAW types (they will error)
1607 0 my $type = '';
1608 $rec->{SEARCHABLE} = 'N'
1609 0 ▶ if $group->{table} && ($type = $group->{table}->column_type($rec->{FIELD_NAME})) && $group->{table}{ioclass} eq 'DBIx::IO::OracleIO' &&
Branch: 1 branch
BranchTrueFalseTotal
if $group->{"table"} and $type = $group->{"table"}->column_type($rec->{"FIELD_NAME"}) and $group->{"table"}{"ioclass"} eq "DBIx::IO::OracleIO" and $type eq "LONG" || $type eq "RAW" || $type eq "LONG RAW" 0 0 0
Condition0%0/15
$group->{"table"} and $type = $group->{"table"}->column_type($rec->{"FIELD_NAME"}) and $group->{"table"}{"ioclass"} eq "DBIx::IO::OracleIO" and $type eq "LONG" || $type eq "RAW" || $type eq "LONG RAW"
!ll&&!rl&&r
000
$group->{"table"} and $type = $group->{"table"}->column_type($rec->{"FIELD_NAME"}) and $group->{"table"}{"ioclass"} eq "DBIx::IO::OracleIO"
!ll&&!rl&&r
000
$group->{"table"} and $type = $group->{"table"}->column_type($rec->{"FIELD_NAME"})
!ll&&!rl&&r
000
$type eq "LONG" or $type eq "RAW" or $type eq "LONG RAW"
l!l&&r!l&&!r
000
$type eq "LONG" or $type eq "RAW"
l!l&&r!l&&!r
000
MC/DC0%0/6
$group->{"table"} and $type = $group->{"table"}->column_type($rec->{"FIELD_NAME"}) and $group->{"table"}{"ioclass"} eq "DBIx::IO::OracleIO" and $type eq "LONG" || $type eq "RAW" || $type eq "LONG RAW"
$group->{"table"} $type = $group->{"table"}->column_type($rec->{"FIELD_NAME"}) $group->{"table"}{"ioclass"} eq "DBIx::IO::OracleIO" $type eq "LONG" $type eq "RAW" $type eq "LONG RAW"
Truth table0%0/7
A and B and C and D or E or F
A= $group->{"table"}B= $type = $group->{"table"}->column_type($rec->{"FIELD_NAME"})C= $group->{"table"}{"ioclass"} eq "DBIx::IO::OracleIO"D= $type eq "LONG"E= $type eq "RAW"F= $type eq "LONG RAW"
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110000
1111XX1
11101X1
1110011
1610 ($type eq 'LONG' || $type eq 'RAW' || $type eq 'LONG RAW');
1611  
1612 # the required field, therefore only applies to a non-searchable group (exept as noted above where you can set it explicitly)
1613 # this needs clearer docs: the REQUIRED field DOES NOT APPLY TO groups that are designated as $CGI::AutoForm::SEARCH_GROUP, the REQUIRED field is unset (undef())
1614 # you can, however explicitly set $group->{REQUIRED} = 'Y' after calling add_group()
1615 0 ▶ undef($rec->{REQUIRED}) if $usage eq $CGI::AutoForm::SEARCH_GROUP;
Branch: 1 branch
BranchTrueFalseTotal
if $usage eq $CGI::AutoForm::SEARCH_GROUP 0 0 0
1616 0 ▶ $rec->{DEFAULT_VALUE} = $defaults->{$fname} if defined($defaults->{$fname});
Branch: 1 branch
BranchTrueFalseTotal
if defined $defaults->{$fname} 0 0 0
1617 0 ▶ $rec->{HEADING} = $fname unless length($rec->{HEADING});
Branch: 1 branch
BranchTrueFalseTotal
unless length $rec->{"HEADING"} 0 0 0
1618 0 ▶ $rec->{BRIEF_HEADING} = $fname if !length($rec->{BRIEF_HEADING}) && $all_db_defn;
Branch: 1 branch
BranchTrueFalseTotal
if not length $rec->{"BRIEF_HEADING"} and $all_db_defn 0 0 0
Condition0%0/3
not length $rec->{"BRIEF_HEADING"} and $all_db_defn
!ll&&!rl&&r
000
MC/DC0%0/2
not length $rec->{"BRIEF_HEADING"} and $all_db_defn
not length $rec->{"BRIEF_HEADING"} $all_db_defn
Truth table0%0/3
not(A) and B
A= not length $rec->{"BRIEF_HEADING"}B= $all_db_defn
ABresult
0X0
100
111
1619 0 my $field = $self->create_field($rec,undef,$all_db_defn,$no_group,$usage);
1620 0 ▶ unless ($field)
Branch: 1 branch
BranchTrueFalseTotal
unless ($field) 0 0 0
1621 {
1622 0 ▶ defined($field) && return -1;
Branch: 1 branch
BranchTrueFalseTotal
defined $field and return -1 0 0 0
1623 0 return $field;
1624 }
1625 0 push(@$fields,$field);
1626 0 $field_hash->{$fname} = $field;
1627 }
1628 0 return { field_list => $fields, field_hash => $field_hash };
1629 }
1630  
1631 ##at because intrinsic date types can differ from explicit ones, this should always be executed if a table exists and tableIO is performed
1632  
1633 # Return 0 if FIELD_NAME does not exist in table
1634 sub use_data_dict
1635 0 ▶{
Subroutine use_data_dict: not called CC=20 SCAR=60.4
Pod undocumented
1636 0 my ($self,$field,$table_name,$table,$no_group) = @_;
1637 0 ▶ unless ($table && %$table)
Branch: 1 branch
BranchTrueFalseTotal
unless ($table and %$table) 0 0 0
Condition0%0/3
$table and %$table
!ll&&!rl&&r
000
MC/DC0%0/2
$table and %$table
$table %$table
Truth table0%0/3
A and B
A= $tableB= %$table
ABresult
0X0
100
111
1638 {
1639 0 ▶ unless ($table = new DBIx::IO::Table($self->dbh(),undef,undef,$table_name))
Branch: 1 branch
BranchTrueFalseTotal
unless ($table = "DBIx::IO::Table"->new($self->dbh, undef, undef, $table_name)) 0 0 0
1640 {
1641 0 return $table;
1642 }
1643 0 ▶ unless ($no_group)
Branch: 1 branch
BranchTrueFalseTotal
unless ($no_group) 0 0 0
1644 {
1645 0 my $group = $self->current_group();
1646 0 $group->{table} = $table;
1647 }
1648 }
1649 0 my $io = $table->{io};
1650 0 my $fname = $field->{FIELD_NAME};
1651 0 ▶ return 0 unless $io->column_type($fname);
Branch: 1 branch
BranchTrueFalseTotal
unless $io->column_type($fname) 0 0 0
1652 0 ▶ if ($io->is_datetime($fname))
Branch: 2 branches
BranchTrueFalseTotal
if ($io->is_datetime($fname)) { } 0 0 0
elsif ($io->is_date($fname)) { } 0 0 0
1653 {
1654 0 $field->{_imp_datetype} = 'DATETIME';
1655 }
1656 elsif ($io->is_date($fname))
1657 {
1658 0 $field->{_imp_datetype} = 'DATE';
1659 }
1660 0 ▶ unless ($field->{DATATYPE})
Branch: 1 branch
BranchTrueFalseTotal
unless ($field->{"DATATYPE"}) 0 0 0
1661 {
1662 0 ▶ $field->{DATATYPE} = $field->{_imp_datetype} if $field->{_imp_datetype};
Branch: 1 branch
BranchTrueFalseTotal
if $field->{"_imp_datetype"} 0 0 0
1663 }
1664 0 my $dval = $io->default_value($fname);
1665 # Dates cannot have default values from the data dictionary, I don't want to bother with formatting them!
1666 0 ▶ undef($dval) if $field->{_imp_datetype};
Branch: 1 branch
BranchTrueFalseTotal
if $field->{"_imp_datetype"} 0 0 0
1667 0 ▶ $field->{DEFAULT_VALUE} = $dval unless length($field->{DEFAULT_VALUE}) || !length($dval);
Branch: 1 branch
BranchTrueFalseTotal
unless length $field->{"DEFAULT_VALUE"} or not length $dval 0 0 0
Condition0%0/3
length $field->{"DEFAULT_VALUE"} or not length $dval
l!l&&r!l&&!r
000
MC/DC0%0/2
length $field->{"DEFAULT_VALUE"} or not length $dval
length $field->{"DEFAULT_VALUE"} not length $dval
Truth table0%0/3
A or not(B)
A= length $field->{"DEFAULT_VALUE"}B= not length $dval
ABresult
1X1
011
000
1668 0 ▶ $field->{REQUIRED} = ($io->required($fname) ? 'Y' : undef) unless $field->{REQUIRED};
Branch: 2 branches
BranchTrueFalseTotal
unless $field->{"REQUIRED"} 0 0 0
$io->required($fname) ? : 0 0 0
1669 0 my $flen = $io->field_length($fname);
1670 0 ▶ if ($field->{DATATYPE} eq 'DATE')
Branch: 2 branches
BranchTrueFalseTotal
if ($field->{'DATATYPE'} eq 'DATE') { } 0 0 0
elsif ($field->{'DATATYPE'} eq 'DATETIME') { } 0 0 0
1671 {
1672 ##at const depends on output date format
1673 0 $flen = 11;
1674 }
1675 elsif ($field->{DATATYPE} eq 'DATETIME')
1676 {
1677 ##at const depends on output date format
1678 0 $flen = 17;
1679 }
1680 $field->{INPUT_SIZE} = ($flen > $CGI::AutoForm::DEFAULT_FIELD_LENGTH ? $CGI::AutoForm::DEFAULT_FIELD_LENGTH : $flen)
1681 0 ▶ unless $field->{INPUT_SIZE};
Branch: 2 branches
BranchTrueFalseTotal
unless $field->{"INPUT_SIZE"} 0 0 0
$flen > $CGI::AutoForm::DEFAULT_FIELD_LENGTH ? : 0 0 0
1682 0 ▶ $field->{INPUT_MAXLENGTH} = $flen unless $field->{INPUT_MAXLENGTH};
Branch: 1 branch
BranchTrueFalseTotal
unless $field->{"INPUT_MAXLENGTH"} 0 0 0
1683 0 return $field;
1684 }
1685  
1686 # Set the html attribute of $field with, and return a string of HTML
1687 # according to INPUT_CONTROL_TYPE.
1688 # Note that INPUT_CONTROL_TYPE may have been set by _export_field() depending
1689 # on the way $field will be used in the form.
1690 sub field_html
1691 0 ▶{
Subroutine field_html: not called CC=12 SCAR=50.5
Pod undocumented
1692 0 my ($self,$field) = @_;
1693 0 my $type = $self->control_type($field);
1694 0 ▶ if ($type eq 'TEXT' || $type eq 'PASSWORD' || $type eq 'MATCH TEXT' || $type eq 'COMMALIST')
Branch: 7 branches
BranchTrueFalseTotal
if ($type eq 'TEXT' or $type eq 'PASSWORD' or $type eq 'MATCH TEXT' or $type eq 'COMMALIST') { } 0 0 0
elsif ($type eq 'TEXTAREA') { } 0 0 0
elsif ($type eq 'SELECT') { } 0 0 0
elsif ($type eq $CGI::AutoForm::DISPLAY_ONLY_GROUP) { } 0 0 0
elsif ($type eq 'CHECKBOX' or $type eq 'CHECKGROUP') { } 0 0 0
elsif ($type eq 'RADIO') { } 0 0 0
elsif ($type eq 'FILE') { } 0 0 0
Condition0%0/9
$type eq "TEXT" or $type eq "PASSWORD" or $type eq "MATCH TEXT" or $type eq "COMMALIST"
l!l&&r!l&&!r
000
$type eq "TEXT" or $type eq "PASSWORD" or $type eq "MATCH TEXT"
l!l&&r!l&&!r
000
$type eq "TEXT" or $type eq "PASSWORD"
l!l&&r!l&&!r
000
MC/DC0%0/4
$type eq "TEXT" or $type eq "PASSWORD" or $type eq "MATCH TEXT" or $type eq "COMMALIST"
$type eq "TEXT" $type eq "PASSWORD" $type eq "MATCH TEXT" $type eq "COMMALIST"
Truth table0%0/5
A or B or C or D
A= $type eq "TEXT"B= $type eq "PASSWORD"C= $type eq "MATCH TEXT"D= $type eq "COMMALIST"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1695 {
1696 0 return ($field->{html} = $self->text_pass_html($field,$type));
1697 }
1698 elsif ($type eq 'TEXTAREA')
1699 {
1700 0 return ($field->{html} = $self->textarea_html($field));
1701 }
1702 elsif ($type eq 'SELECT')
1703 {
1704 0 return ($field->{html} = $self->select_html($field));
1705 }
1706 elsif ($type eq $CGI::AutoForm::DISPLAY_ONLY_GROUP)
1707 {
1708 0 return ($field->{html} = $self->display_html($field));
1709 }
1710 ▶ elsif ($type eq 'CHECKBOX' or $type eq 'CHECKGROUP')
Condition0%0/3
$type eq "CHECKBOX" or $type eq "CHECKGROUP"
l!l&&r!l&&!r
000
MC/DC0%0/2
$type eq "CHECKBOX" or $type eq "CHECKGROUP"
$type eq "CHECKBOX" $type eq "CHECKGROUP"
Truth table0%0/3
A or B
A= $type eq "CHECKBOX"B= $type eq "CHECKGROUP"
ABresult
1X1
011
000
1711 {
1712 0 return ($field->{html} = $self->checkbox_html($field));
1713 }
1714 elsif ($type eq 'RADIO')
1715 {
1716 0 return ($field->{html} = $self->radio_html($field));
1717 }
1718 elsif ($type eq 'FILE')
1719 {
1720 0 return ($field->{html} = $self->fileupload_html($field));
1721 }
1722 else
1723 {
1724 0 die("Field type [$type] not recognized for $field->{FIELD_NAME}");
1725 0 return undef;
1726 }
1727 }
1728  
1729 # File type input.
1730 ##at not sure if the comments below are correct?
1731 ## In order for file uploads to work on a form,
1732 ## the enctype="file" attribute needs to be added to the form tag.
1733 sub fileupload_html
1734 0 ▶{
Subroutine fileupload_html: not called CC=4 SCAR=30.0
Pod undocumented
1735 0 my ($self,$field) = @_;
1736  
1737 0 my $need_req = $field->{REQUIRED} eq 'Y';
1738 0 my $need_req_class = 0;
1739 0 ▶ if ($need_req)
Branch: 1 branch
BranchTrueFalseTotal
if ($need_req) 0 0 0
1740 {
1741 $need_req_class = 1 unless $field->{ELEMENT_ATTRS} =~
1742 0 ▶ s/CLASS\s*=\s*['"]?(.*?)['"]?/CLASS="$1 REQI"/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $field->{"ELEMENT_ATTRS"} =~ s/CLASS\s*=\s*['"]?(.*?)['"]?/CLASS="$1 REQI"/i 0 0 0
1743 }
1744  
1745 0 my $name = qq[name="] . $self->escape($field->{FORM_ELEMENT_NAME}) . qq["];
1746 0 ▶ my $class = $need_req_class ? qq[CLASS="REQI" ] : "";
Branch: 1 branch
BranchTrueFalseTotal
$need_req_class ? : 0 0 0
1747 0 my $attrs = $field->{ELEMENT_ATTRS};
1748  
1749 0 my $html = qq[<input type="file" $class $name $attrs>];
1750  
1751 0 $self->{form_enctype_attr} = qq[enctype="multipart/form-data"];
1752  
1753 0 return $html;
1754 }
1755  
1756 # A checkbox field results in a series of checkboxes, one for each
1757 # PICK_LIST element, multiple values may be checked for the same field.
1758 # A PICK_LIST attribute of $field is necessary (see create_field())
1759  
1760 # The default layout of the checkboxes will be a tabular with
1761 # $CGI::AutoForm::DEFAULT_RADIO_CHECKBOX_COLS number of rows, this can
1762 # be overridden by specifying UI_TABLE_COLUMN.RADIO_CHECKBOX_COLS
1763 sub checkbox_html
1764 0 ▶{
Subroutine checkbox_html: not called CC=11 SCAR=48.8
Pod undocumented
1765 0 my ($self,$field) = @_;
1766  
1767 0 my %checked;
1768 0 ▶ if (ref($field->{VALUE}) eq 'ARRAY')
Branch: 2 branches
BranchTrueFalseTotal
if (ref $field->{'VALUE'} eq 'ARRAY') { } 0 0 0
elsif (not ref $field->{'VALUE'}) { } 0 0 0
1769 {
1770 0 map { $checked{$_} = 'CHECKED ' } (@{$field->{VALUE}});
1771 }
1772 elsif (!ref($field->{VALUE}))
1773 {
1774 0 ▶ $checked{$field->{VALUE}} = 'CHECKED ' if defined($field->{VALUE});
Branch: 1 branch
BranchTrueFalseTotal
if defined $field->{"VALUE"} 0 0 0
1775 }
1776 else
1777 {
1778 0 die "A horrible death";
1779 }
1780  
1781 0 my $need_req = $field->{REQUIRED} eq 'Y';
1782 0 my $need_req_class = 0;
1783 0 ▶ if ($need_req)
Branch: 1 branch
BranchTrueFalseTotal
if ($need_req) 0 0 0
1784 {
1785 0 ▶ $need_req_class = 1 unless $field->{ELEMENT_ATTRS} =~ s/CLASS\s*=\s*['"]?(.*?)['"]?/CLASS="$1 REQI"/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $field->{"ELEMENT_ATTRS"} =~ s/CLASS\s*=\s*['"]?(.*?)['"]?/CLASS="$1 REQI"/i 0 0 0
1786 }
1787  
1788 ##at should have a {RADIO_CHECKBOX_COLS} = 0 where no <TABLE> and related tags are generated
1789 0 my $ret = '<TABLE><TR>';
1790 0 my $i;
1791 0 ▶ my $cols = ($field->{RADIO_CHECKBOX_COLS} ? $field->{RADIO_CHECKBOX_COLS} : $CGI::AutoForm::DEFAULT_RADIO_CHECKBOX_COLS);
Branch: 1 branch
BranchTrueFalseTotal
$field->{'RADIO_CHECKBOX_COLS'} ? : 0 0 0
1792 0 foreach my $opt (@{$field->{PICK_LIST}})
1793 {
1794 0 ▶ my $new_row = $i && !($i % $cols);
Condition0%0/3
$i && !($i % $cols)
!ll&&!rl&&r
000
MC/DC0%0/2
$i && !($i % $cols)
$i !($i % $cols)
Truth table0%0/3
A && not(B)
A= $iB= !($i % $cols)
ABresult
0X0
100
111
1795 0 ▶ $new_row && ($ret .= '</TR><TR>');
Branch: 1 branch
BranchTrueFalseTotal
$new_row and $ret .= '</TR><TR>' 0 0 0
1796  
1797 $ret .= '<TD><INPUT TYPE="CHECKBOX" ' .
1798 qq[NAME="] . $self->escape($field->{FORM_ELEMENT_NAME}) . '" ' .
1799 qq[VALUE="] . $self->escape($opt->{ID}) . '" ' .
1800 $checked{$opt->{ID}} .
1801 ($need_req_class ? qq[CLASS="REQI" ] : "") .
1802 "$field->{ELEMENT_ATTRS}>" .
1803 0 ▶ $self->escape($opt->{MASK}) . '</TD>';
Branch: 1 branch
BranchTrueFalseTotal
$need_req_class ? : 0 0 0
1804 0 $i++;
1805 }
1806 0 $ret .= '</TR></TABLE>';
1807 0 return $ret;
1808 }
1809  
1810 # A radio field results in an HTML radio control group
1811 # where each element can be toggled but only 1 element
1812 # in the group can be in the on position. This differs from
1813 # a checkbox group in that the field can have only 1 value.
1814 # Choices for the field value are taken from the field's PICK_LIST;
1815 # a PICK_LIST attribute of $field must exist (see create_field())
1816  
1817 # Refer to checkbox_html() for a description of the layout of the
1818 # radio group.
1819 sub radio_html
1820 0 ▶{
Subroutine radio_html: not called CC=10 SCAR=47.0
Pod undocumented
1821 0 my ($self,$field) = @_;
1822 0 my $val = $field->{VALUE};
1823 0 ▶ ref($val) && (die("Radio groups cannot be muti-valued"),return undef);
Branch: 1 branch
BranchTrueFalseTotal
ref $val and die("Radio groups cannot be muti-valued"), (return undef) 0 0 0
1824 0 my %checked;
1825 0 ▶ $checked{$val} = 'CHECKED ' if defined($val);
Branch: 1 branch
BranchTrueFalseTotal
if defined $val 0 0 0
1826 0 my $ret = '<TABLE><TR>';
1827 0 my $i;
1828 0 ▶ my $cols = ($field->{RADIO_CHECKBOX_COLS} ? $field->{RADIO_CHECKBOX_COLS} : $CGI::AutoForm::DEFAULT_RADIO_CHECKBOX_COLS);
Branch: 1 branch
BranchTrueFalseTotal
$field->{'RADIO_CHECKBOX_COLS'} ? : 0 0 0
1829  
1830 0 my $need_req = $field->{REQUIRED} eq 'Y';
1831 0 my $need_req_class = 0;
1832 0 ▶ if ($need_req)
Branch: 1 branch
BranchTrueFalseTotal
if ($need_req) 0 0 0
1833 {
1834 0 ▶ $need_req_class = 1 unless $field->{ELEMENT_ATTRS} =~ s/CLASS\s*=\s*['"]?(.*?)['"]?/CLASS="$1 REQI"/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $field->{"ELEMENT_ATTRS"} =~ s/CLASS\s*=\s*['"]?(.*?)['"]?/CLASS="$1 REQI"/i 0 0 0
1835 }
1836  
1837 0 foreach my $opt (@{$field->{PICK_LIST}})
1838 {
1839 0 ▶ my $new_row = $i && !($i % $cols);
Condition0%0/3
$i && !($i % $cols)
!ll&&!rl&&r
000
MC/DC0%0/2
$i && !($i % $cols)
$i !($i % $cols)
Truth table0%0/3
A && not(B)
A= $iB= !($i % $cols)
ABresult
0X0
100
111
1840 0 ▶ $new_row && ($ret .= '</TR><TR>');
Branch: 1 branch
BranchTrueFalseTotal
$new_row and $ret .= '</TR><TR>' 0 0 0
1841  
1842 $ret .= '<TD><INPUT TYPE="RADIO" ' .
1843 qq[NAME="] . $self->escape($field->{FORM_ELEMENT_NAME}) . '" ' .
1844 qq[VALUE="] . $self->escape($opt->{ID}) . '" ' .
1845 $checked{$opt->{ID}} .
1846 ($need_req_class ? qq[CLASS="REQI" ] : "") .
1847 "$field->{ELEMENT_ATTRS}>" .
1848 0 ▶ $self->escape($opt->{MASK}) . '</TD>';
Branch: 1 branch
BranchTrueFalseTotal
$need_req_class ? : 0 0 0
1849 0 $i++;
1850 }
1851 0 $ret .= '</TR></TABLE>';
1852 0 return $ret;
1853 }
1854  
1855 ##at new field_group of 'COMBO' would be nice to accept free-form or a select list
1856  
1857 sub display_html
1858 0 ▶{
Subroutine display_html: not called CC=3 SCAR=24.8
Pod undocumented
1859 0 my ($self,$field) = @_;
1860 0 my $val = $field->{DISPLAY_VALUE};
1861 0 my $dval = '';
1862 0 ▶ if (ref($val))
Branch: 1 branch
BranchTrueFalseTotal
if (ref $val) { } 0 0 0
1863 {
1864 0 foreach my $v (@$val)
1865 {
1866 0 $dval .= $self->escape($val) . '<BR>';
1867 }
1868 0 chop($dval);
1869 0 chop($dval);
1870 0 chop($dval);
1871 0 chop($dval);
1872 }
1873 else
1874 {
1875 0 $dval = $self->escape($val);
1876 0 $dval =~ s/\r?\n/<BR>/gs;
1877 }
1878 0 return $dval;
1879 }
1880  
1881 sub select_html
1882 0 ▶{
Subroutine select_html: not called CC=12 SCAR=50.5
Pod undocumented
1883 0 my ($self,$field) = @_;
1884  
1885 0 my $need_req = $field->{REQUIRED} eq 'Y';
1886 0 my $need_req_class = 0;
1887 0 ▶ if ($need_req)
Branch: 1 branch
BranchTrueFalseTotal
if ($need_req) 0 0 0
1888 {
1889 0 ▶ $need_req_class = 1 unless $field->{ELEMENT_ATTRS} =~ s/CLASS\s*=\s*['"]?(.*?)['"]?/CLASS="$1 REQI"/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $field->{"ELEMENT_ATTRS"} =~ s/CLASS\s*=\s*['"]?(.*?)['"]?/CLASS="$1 REQI"/i 0 0 0
1890 }
1891  
1892 my $ret = '<SELECT ' .
1893 0 ▶ qq[NAME="] . $self->escape($field->{FORM_ELEMENT_NAME}) . '" ' .
Branch: 1 branch
BranchTrueFalseTotal
$need_req_class ? : 0 0 0
1894 "$field->{ELEMENT_ATTRS} " .
1895 ($need_req_class ? qq[CLASS="REQI" ] : "");
1896  
1897 0 my %selected;
1898 0 ▶ if (ref($field->{VALUE}) eq 'ARRAY')
Branch: 2 branches
BranchTrueFalseTotal
if (ref $field->{'VALUE'} eq 'ARRAY') { } 0 0 0
elsif (not ref $field->{'VALUE'}) { } 0 0 0
1899 {
1900 0 map { $selected{$_} = 'SELECTED ' } (@{$field->{VALUE}});
1901 }
1902 elsif (!ref($field->{VALUE}))
1903 {
1904 0 ▶ $selected{$field->{VALUE}} = 'SELECTED ' if defined($field->{VALUE});
Branch: 1 branch
BranchTrueFalseTotal
if defined $field->{"VALUE"} 0 0 0
1905 }
1906 else
1907 {
1908 0 die "The value of $field->{FIELD_NAME} must be an array ref or scalar, found [$field->{VALUE}]";
1909 }
1910  
1911 0 my $usage = $self->group_usage();
1912 0 ▶ if ($usage eq $CGI::AutoForm::SEARCH_GROUP)
Branch: 1 branch
BranchTrueFalseTotal
if ($usage eq $CGI::AutoForm::SEARCH_GROUP) 0 0 0
1913 {
1914 0 ▶ $ret .= ($field->{SEARCH_MULT_SELECT} ? qq[MULTIPLE SIZE="$field->{SEARCH_MULT_SELECT}" ] : '');
Branch: 1 branch
BranchTrueFalseTotal
$field->{'SEARCH_MULT_SELECT'} ? : 0 0 0
1915 }
1916 0 $ret .= '>';
1917 0 ▶ unless ($need_req)
Branch: 1 branch
BranchTrueFalseTotal
unless ($need_req) 0 0 0
1918 {
1919 0 ▶ $ret .= '<OPTION VALUE="" ' . (%selected ? '' : 'SELECTED ') . '>&nbsp;</OPTION>';
Branch: 1 branch
BranchTrueFalseTotal
%selected ? : 0 0 0
1920 }
1921  
1922 0 foreach my $opt (@{$field->{PICK_LIST}})
1923 {
1924 0 $ret .= qq[<OPTION VALUE="] . $self->escape($opt->{ID}) . qq[" $selected{$opt->{ID}}>] . $self->escape($opt->{MASK}) . '</OPTION>';
1925 }
1926 0 $ret .= '</SELECT>';
1927 0 return $ret;
1928 }
1929  
1930 sub text_pass_html
1931 0 ▶{
Subroutine text_pass_html: not called CC=12 SCAR=50.5
Pod undocumented
1932 0 my ($self,$field,$type) = @_;
1933  
1934 0 my $html_type = $type;
1935  
1936 0 my $need_req = $field->{REQUIRED} eq 'Y';
1937 0 my $need_req_class = 0;
1938 0 ▶ if ($need_req)
Branch: 1 branch
BranchTrueFalseTotal
if ($need_req) 0 0 0
1939 {
1940 0 ▶ $need_req_class = 1 unless $field->{ELEMENT_ATTRS} =~ s/CLASS\s*=\s*['"]?(.*?)['"]?/CLASS="$1 REQI"/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $field->{"ELEMENT_ATTRS"} =~ s/CLASS\s*=\s*['"]?(.*?)['"]?/CLASS="$1 REQI"/i 0 0 0
1941 }
1942  
1943 0 my $val = $field->{VALUE};
1944  
1945 0 ▶ $self->{_ast_match}++,$html_type = 'TEXT' if $type eq 'MATCH TEXT';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "MATCH TEXT" 0 0 0
1946  
1947 0 ▶ if ($type eq 'COMMALIST')
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "COMMALIST") 0 0 0
1948 {
1949 0 $self->{_cst_match}++;
1950 0 $html_type = 'TEXT';
1951 0 undef($field->{INPUT_MAXLENGTH});
1952 0 $field->{INPUT_SIZE} *= 2;
1953 0 ▶ $val = join(',',@$val) if ref($val);
Branch: 1 branch
BranchTrueFalseTotal
if ref $val 0 0 0
1954 }
1955  
1956 0 ▶ $val = '**INVALID REFERENCE**' if ref($val);
Branch: 1 branch
BranchTrueFalseTotal
if ref $val 0 0 0
1957  
1958 return qq[<INPUT TYPE="$html_type" ] .
1959 qq[NAME="] . $self->escape($field->{FORM_ELEMENT_NAME}) . '" ' .
1960 qq[VALUE="] . $self->escape($val) . '" ' .
1961 ($field->{INPUT_SIZE} ? qq[SIZE="$field->{INPUT_SIZE}" ] : '') .
1962 0 ▶ ($field->{INPUT_MAXLENGTH} ? qq[MAXLENGTH="$field->{INPUT_MAXLENGTH}" ] : '') .
Branch: 5 branches
BranchTrueFalseTotal
$field->{'INPUT_SIZE'} ? : 0 0 0
$field->{'INPUT_MAXLENGTH'} ? : 0 0 0
$need_req_class ? : 0 0 0
$type eq 'MATCH TEXT' ? : 0 0 0
$type eq 'COMMALIST' ? : 0 0 0
1963 ($need_req_class ? qq[CLASS="REQI" ] : "") .
1964 "$field->{ELEMENT_ATTRS}>" .
1965 ($type eq 'MATCH TEXT' ? '**' : '') .
1966 ($type eq 'COMMALIST' ? '***' : '');
1967 }
1968  
1969 sub textarea_html
1970 0 ▶{
Subroutine textarea_html: not called CC=5 SCAR=34.0
Pod undocumented
1971 0 my ($self,$field) = @_;
1972  
1973 0 my $need_req = $field->{REQUIRED} eq 'Y';
1974 0 my $need_req_class = 0;
1975 0 ▶ if ($need_req)
Branch: 1 branch
BranchTrueFalseTotal
if ($need_req) 0 0 0
1976 {
1977 0 ▶ $need_req_class = 1 unless $field->{ELEMENT_ATTRS} =~ s/CLASS\s*=\s*['"]?(.*?)['"]?/CLASS="$1 REQI"/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $field->{"ELEMENT_ATTRS"} =~ s/CLASS\s*=\s*['"]?(.*?)['"]?/CLASS="$1 REQI"/i 0 0 0
1978 }
1979  
1980 0 my $val = $field->{VALUE};
1981 0 ▶ $val = '**INVALID REFERENCE**' if ref($val);
Branch: 1 branch
BranchTrueFalseTotal
if ref $val 0 0 0
1982  
1983 return '<TEXTAREA ' .
1984 0 ▶ qq[NAME="] . $self->escape($field->{FORM_ELEMENT_NAME}) . '" ' .
Branch: 1 branch
BranchTrueFalseTotal
$need_req_class ? : 0 0 0
1985 ($need_req_class ? qq[CLASS="REQI" ] : "") .
1986 "$field->{ELEMENT_ATTRS}>" .
1987 $self->escape($val,1) .
1988 '</TEXTAREA>';
1989 }
1990  
1991 =pod
1992  
1993 =head2 HTML Generation and Other Accessors
1994  
1995 =item C<hidden>
1996  
1997  
1998 C<hidden> is a form object attribute that stores a hashref of name => value
1999 pairs that will be included as hidden INPUT form elements.
2000 The hash can be accessed via this method or directly with $form->{hidden}.
2001  
2002 The values of the hash can be a scalar or an array ref where multiple form elements of
2003 the same name for each array value will be rendered.
2004  
2005 You can add/remove keys from this hash but don't replace it as it is updated internally.
2006 Keys will be removed internally if they conflict with updatable/insertable visible
2007 form fields.
2008 Keys may be overwritten if $query is used (see C<prepare>) or by C<add_record()>
2009 for an updatable group.
2010  
2011 The HTML from this hash is automatically stored in the html attr.
2012  
2013 =cut
2014 sub hidden
2015 0 ▶{
Subroutine hidden: not called CC=2 SCAR=17.9
Pod documented
2016 0 my ($self,$hidden) = @_;
2017 0 ▶ if (defined($hidden))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hidden) 0 0 0
2018 {
2019 0 $self->{hidden} = $hidden;
2020 }
2021 0 return $self->{hidden};
2022 }
2023  
2024 =pod
2025  
2026 =item C<hidden_html>
2027  
2028 $html_block = $form->hidden_html();
2029  
2030 Create a block of HTML hidden INPUT elements
2031 using the $form->{hidden} attribute hash.
2032  
2033 =cut
2034 sub hidden_html
2035 0 ▶{
Subroutine hidden_html: not called CC=5 SCAR=34.0
Pod documented
2036 0 my ($self) = @_;
2037 0 my ($name,$val);
2038 0 my $ret;
2039 0 ▶ while (($name,$val) = each(%{$self->{hidden}}))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$self{"hidden"};}) 0 0 0
2040 {
2041 0 ▶ if (!ref($val))
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $val) { } 0 0 0
elsif (not ref $val eq 'ARRAY') { } 0 0 0
2042 {
2043 0 $val = [ $val ];
2044 }
2045 elsif (!(ref($val) eq 'ARRAY'))
2046 {
2047 0 die "The hidden field [$name] must be an array ref or scalar, found [$val]";
2048 }
2049  
2050 0 foreach my $subval (@$val)
2051 {
2052 0 $ret .= qq[<INPUT TYPE="HIDDEN" NAME="] . $self->escape($name) . '" VALUE="' . $self->escape($subval) . '">';
2053 }
2054 }
2055 0 $self->{hidden_html} = $ret;
2056 0 return $ret;
2057 }
2058  
2059 # create a copy of $field processing and return the new $field
2060 sub _export_field
2061 0 ▶{
Subroutine _export_field: not called CC=5 SCAR=34.0
2062 0 my ($self,$field) = @_;
2063 0 $field = { %$field };
2064 0 my $usage = $self->group_usage();
2065  
2066 # First check if its read-only at the record level
2067 # because an updatable record might have a read-only field
2068 # which will be handled differently in the updatable context
2069 0 ▶ if ($self->is_readonly())
Branch: 4 branches
BranchTrueFalseTotal
if ($self->is_readonly) { } 0 0 0
elsif ($usage eq $CGI::AutoForm::EDIT_GROUP) { } 0 0 0
elsif ($usage eq $CGI::AutoForm::SEARCH_GROUP) { } 0 0 0
elsif ($usage eq $CGI::AutoForm::INSERT_GROUP) { } 0 0 0
2070 {
2071 0 return $self->_export_ro($field);
2072 }
2073 elsif ($usage eq $CGI::AutoForm::EDIT_GROUP)
2074 {
2075 0 return $self->_export_update($field);
2076 }
2077 elsif ($usage eq $CGI::AutoForm::SEARCH_GROUP)
2078 {
2079 0 return $self->_export_search($field);
2080 }
2081 elsif ($usage eq $CGI::AutoForm::INSERT_GROUP)
2082 {
2083 0 return $self->_export_insert($field);
2084 }
2085 else
2086 {
2087 0 die("Group type [$usage] not recognized");
2088 }
2089 }
2090  
2091 # add to hidden a record from {data} if it exists
2092 sub _export_update
2093 0 ▶{
Subroutine _export_update: not called CC=4 SCAR=30.0
2094 0 my ($self,$field) = @_;
2095 0 my ($rec,$val);
2096 0 my $isdate = _isdate($field);
2097 0 my $fname = $field->{FIELD_NAME};
2098 0 my $gname = $self->current_group_name();
2099 0 $rec = $self->{struct_query}{$gname};
2100  
2101 # may have empty records if no fields in the record require a value
2102 # unless (($rec = $self->{struct_query}{$gname}) && ref($rec))
2103 # {
2104 # die("No record exists for field: " . $fname);
2105 # return undef;
2106 # }
2107  
2108 0 ▶ if ($self->is_readonly($field))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_readonly($field)) { } 0 0 0
2109 {
2110 0 $self->_assign_ro_val($field,$rec->{$fname},$isdate);
2111 }
2112 else
2113 {
2114 0 $val = $self->_extract_query_val($fname);
2115 0 ▶ if ($self->_isdate_inscontrol($field))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_isdate_inscontrol($field)) { } 0 0 0
2116 {
2117 0 return $self->expand_date_fields($field,$val);
2118 }
2119 else
2120 {
2121 0 ▶ if ($field->{INPUT_CONTROL_TYPE} eq 'CHECKGROUP')
Branch: 1 branch
BranchTrueFalseTotal
if ($field->{"INPUT_CONTROL_TYPE"} eq "CHECKGROUP") 0 0 0
2122 {
2123 0 $val = [ split($field->{MULTI_INSERT_DELIMITER}, $val) ];
2124 }
2125 0 $field->{VALUE} = $val;
2126 }
2127 }
2128 0 my $group = $self->current_group();
2129 0 push(@{$group->{export_rec}[$self->{curr_rec_no}]},$field);
2130 0 return $field;
2131 }
2132  
2133 ##at a query must only be introduced through prepare() in order for it to be cleaned,
2134 ##at structured and recognized properly in next_field()
2135  
2136 # some elements of hidden may be deleted if _extract_query_val() is called with $delete_end = TRUE (currently only true if 'INSERTABLE')
2137  
2138 # delete query element(s) and if last field in rec, delete all query elements of that group
2139 sub _extract_query_val
2140 0 ▶{
Subroutine _extract_query_val: not called CC=3 SCAR=24.8
2141 0 my ($self,$fname,$delete_end) = @_;
2142 0 my ($rec,$val);
2143 ##at for updates, $form_pre must match $fen exactly for this to work
2144 0 my $form_pre = $self->current_group_name() . '.' . $fname;
2145 0 my $hidden = $self->hidden();
2146 0 $val = $hidden->{$form_pre};
2147  
2148 0 delete($hidden->{$form_pre});
2149 0 ▶ if ($delete_end)
Branch: 1 branch
BranchTrueFalseTotal
if ($delete_end) 0 0 0
2150 {
2151 0 my $field_list = $self->field_list();
2152 0 ▶ $self->delete_hidden_group() if ($self->{curr_field_no} == $#$field_list);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"curr_field_no"} == $field_list->$#* 0 0 0
2153 }
2154 0 return $val;
2155 }
2156  
2157 sub delete_hidden_group
2158 0 ▶{
Subroutine delete_hidden_group: not called CC=3 SCAR=24.8
Pod undocumented
2159 0 my ($self) = @_;
2160 0 my $hidden = $self->hidden();
2161 0 my $name = $self->current_group_name();
2162 0 $name = quotemeta($name);
2163 0 foreach my $field_name (keys(%$hidden))
2164 {
2165 0 ▶ delete($hidden->{$field_name}) if $field_name =~ /^$name\./;
Branch: 1 branch
BranchTrueFalseTotal
if $field_name =~ /^$name\./ 0 0 0
2166 }
2167 0 return $hidden
2168 }
2169  
2170 ##at should be able to give an insert group default values and have some of those default values
2171 ##at be non-insertable but simply informational so that the user knows what its value will be
2172 ##at and can't change it this will require an insert group supporting readonly fields
2173  
2174 sub _export_insert
2175 0 ▶{
Subroutine _export_insert: not called CC=9 SCAR=45.0
2176 0 my ($self,$field) = @_;
2177 0 ▶ return 0 unless $field->{INSERTABLE} eq 'Y';
Branch: 1 branch
BranchTrueFalseTotal
unless $field->{"INSERTABLE"} eq "Y" 0 0 0
2178 0 my ($rec,$val);
2179 0 ▶ if (exists($self->{struct_query}{$self->current_group_name()}))
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->{'struct_query'}{$self->current_group_name}) { } 0 0 0
elsif ($rec = $self->current_record) { } 0 0 0
2180 {
2181 0 $val = $self->_extract_query_val($field->{FIELD_NAME},1);
2182 }
2183 elsif ($rec = $self->current_record())
2184 {
2185 0 $val = $rec->{$field->{FIELD_NAME}};
2186 0 ▶ $val = $field->{DEFAULT_VALUE} if !length($val) && $self->{coalesce_default_insert};
Branch: 1 branch
BranchTrueFalseTotal
if not length $val and $self->{"coalesce_default_insert"} 0 0 0
Condition0%0/3
not length $val and $self->{"coalesce_default_insert"}
!ll&&!rl&&r
000
MC/DC0%0/2
not length $val and $self->{"coalesce_default_insert"}
not length $val $self->{"coalesce_default_insert"}
Truth table0%0/3
not(A) and B
A= not length $valB= $self->{"coalesce_default_insert"}
ABresult
0X0
100
111
2187 }
2188 else
2189 {
2190 0 $val = $field->{DEFAULT_VALUE};
2191 }
2192  
2193 0 ▶ if ($self->_isdate_inscontrol($field))
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_isdate_inscontrol($field)) { } 0 0 0
elsif ($field->{'FIELD_GROUP'} eq 'CONFIRM') { } 0 0 0
2194 {
2195 0 return $self->expand_date_fields($field,$val);
2196 }
2197 elsif ($field->{FIELD_GROUP} eq 'CONFIRM')
2198 {
2199 # Only for inserts
2200 0 return $self->expand_confirm_fields($field);
2201 }
2202 0 ▶ if ($field->{INPUT_CONTROL_TYPE} eq 'CHECKGROUP')
Branch: 1 branch
BranchTrueFalseTotal
if ($field->{"INPUT_CONTROL_TYPE"} eq "CHECKGROUP") 0 0 0
2203 {
2204 0 $val = [ split($field->{MULTI_INSERT_DELIMITER}, $val) ];
2205 }
2206 0 $field->{VALUE} = $val;
2207 0 my $group = $self->current_group();
2208 0 push(@{$group->{export_rec}[$self->{curr_rec_no}]},$field);
2209 0 return $field;
2210 }
2211  
2212 # Only for inserts
2213 sub expand_confirm_fields
2214 0 ▶{
Subroutine expand_confirm_fields: not called CC=1 SCAR=6.9
Pod undocumented
2215 0 my ($self,$field) = @_;
2216 0 my $new_field = { %$field };
2217 0 $new_field->{FIELD_NAME} = '_CONFIRM1';
2218 0 my $conf = _copy_field($new_field,$field);
2219 0 $conf = $self->create_field($conf);
2220 0 my $group = $self->current_group();
2221 0 push(@{$group->{export_rec}[$self->{curr_rec_no}]},$conf);
2222 0 $new_field->{FIELD_NAME} = '_CONFIRM2';
2223 0 my $conf2 = _copy_field($new_field,$field);
2224 0 $conf2 = $self->create_field($conf2);
2225 0 $conf2->{HEADING} = 'Re-enter';
2226 0 push(@{$group->{export_rec}[$self->{curr_rec_no}]},$conf2);
2227  
2228 0 return [ $conf,$conf2 ];
2229 }
2230  
2231 sub _isdate
2232 0 ▶{
Subroutine _isdate: not called CC=2 SCAR=17.9
2233 0 my ($field) = @_;
2234 0 ▶ return ($field->{DATATYPE} eq $DBIx::IO::GenLib::DATE_TYPE || $field->{DATATYPE} eq $DBIx::IO::GenLib::DATETIME_TYPE);
Condition0%0/3
$field->{'DATATYPE'} eq $DBIx::IO::GenLib::DATE_TYPE || $field->{'DATATYPE'} eq $DBIx::IO::GenLib::DATETIME_TYPE
l!l&&r!l&&!r
000
MC/DC0%0/2
$field->{'DATATYPE'} eq $DBIx::IO::GenLib::DATE_TYPE || $field->{'DATATYPE'} eq $DBIx::IO::GenLib::DATETIME_TYPE
$field->{'DATATYPE'} eq $DBIx::IO::GenLib::DATE_TYPE $field->{'DATATYPE'} eq $DBIx::IO::GenLib::DATETIME_TYPE
Truth table0%0/3
A || B
A= $field->{'DATATYPE'} eq $DBIx::IO::GenLib::DATE_TYPEB= $field->{'DATATYPE'} eq $DBIx::IO::GenLib::DATETIME_TYPE
ABresult
1X1
011
000
2235 }
2236  
2237 sub _isdate_inscontrol
2238 0 ▶{
Subroutine _isdate_inscontrol: not called CC=2 SCAR=17.9
2239 0 my ($self,$field) = @_;
2240 0 my $type = $self->control_type($field);
2241 0 ▶ return ($type eq 'DATE' || $type eq 'DATETIME');
Condition0%0/3
$type eq 'DATE' || $type eq 'DATETIME'
l!l&&r!l&&!r
000
MC/DC0%0/2
$type eq 'DATE' || $type eq 'DATETIME'
$type eq 'DATE' $type eq 'DATETIME'
Truth table0%0/3
A || B
A= $type eq 'DATE'B= $type eq 'DATETIME'
ABresult
1X1
011
000
2242 }
2243  
2244 sub _export_search
2245 0 ▶{
Subroutine _export_search: not called CC=17 SCAR=57.2
2246 0 my ($self,$field) = @_;
2247 0 ▶ return 0 unless $field->{SEARCHABLE} eq 'Y';
Branch: 1 branch
BranchTrueFalseTotal
unless $field->{"SEARCHABLE"} eq "Y" 0 0 0
2248 0 my $qhit;
2249 0 my $gname = $self->current_group_name();
2250 0 my $fname = $field->{FIELD_NAME};
2251 0 ▶ $qhit++ if (exists($self->{struct_query}{$gname}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"struct_query"}{$gname} 0 0 0
2252 0 my $rec = $self->current_record();
2253 0 ▶ ref($rec) && (die("Data record exists for search crit"),return undef);
Branch: 1 branch
BranchTrueFalseTotal
ref $rec and die("Data record exists for search crit"), (return undef) 0 0 0
2254 0 my $type = $field->{SEARCH_CONTROL_TYPE};
2255 0 ▶ if ($type eq 'DATERANGE' || $type eq 'DATETRANGE')
Branch: 5 branches
BranchTrueFalseTotal
if ($type eq 'DATERANGE' or $type eq 'DATETRANGE') { } 0 0 0
elsif ($type eq 'DATE' or $type eq 'DATETIME') { } 0 0 0
elsif ($type eq 'RANGE') { } 0 0 0
elsif ($type eq 'MATCH TEXT') { } 0 0 0
elsif ($type eq 'COMMALIST') { } 0 0 0
Condition0%0/3
$type eq "DATERANGE" or $type eq "DATETRANGE"
l!l&&r!l&&!r
000
MC/DC0%0/2
$type eq "DATERANGE" or $type eq "DATETRANGE"
$type eq "DATERANGE" $type eq "DATETRANGE"
Truth table0%0/3
A or B
A= $type eq "DATERANGE"B= $type eq "DATETRANGE"
ABresult
1X1
011
000
2256 {
2257 0 my ($ur,$rs,$re);
2258 0 ▶ if ($qhit)
Branch: 1 branch
BranchTrueFalseTotal
if ($qhit) 0 0 0
2259 {
2260 0 $ur = $self->_extract_query_val("$fname._UR");
2261 0 $rs = $self->_extract_query_val("$fname._RS");
2262 0 $re = $self->_extract_query_val("$fname._RE",1);
2263 }
2264 0 return $self->expand_date_search_fields($field,$ur,$rs,$re);
2265 }
2266 ▶ elsif ($type eq 'DATE' || $type eq 'DATETIME')
Condition0%0/3
$type eq "DATE" or $type eq "DATETIME"
l!l&&r!l&&!r
000
MC/DC0%0/2
$type eq "DATE" or $type eq "DATETIME"
$type eq "DATE" $type eq "DATETIME"
Truth table0%0/3
A or B
A= $type eq "DATE"B= $type eq "DATETIME"
ABresult
1X1
011
000
2267 {
2268 0 my $dval = '_SYSDATE';
2269 0 ▶ $dval = $self->_extract_query_val($fname,1) if ($qhit);
Branch: 1 branch
BranchTrueFalseTotal
if $qhit 0 0 0
2270 0 return $self->expand_date_fields($field,$dval);
2271 }
2272 elsif ($type eq 'RANGE')
2273 {
2274 0 my ($rs,$re);
2275 0 ▶ if ($qhit)
Branch: 1 branch
BranchTrueFalseTotal
if ($qhit) 0 0 0
2276 {
2277 0 $rs = $self->_extract_query_val("$fname._RS");
2278 0 $re = $self->_extract_query_val("$fname._RE",1);
2279 }
2280 0 return $self->expand_range_fields($field,$rs,$re);
2281 }
2282 elsif ($type eq 'MATCH TEXT')
2283 {
2284 0 ▶ $field->{VALUE} = $self->_extract_query_val("$fname._WM",1) if ($qhit);
Branch: 1 branch
BranchTrueFalseTotal
if $qhit 0 0 0
2285 }
2286 elsif ($type eq 'COMMALIST')
2287 {
2288 0 ▶ $field->{VALUE} = [split(/,/,$self->_extract_query_val("$fname._CL",1))] if ($qhit);
Branch: 1 branch
BranchTrueFalseTotal
if $qhit 0 0 0
2289 }
2290 else
2291 {
2292 0 ▶ $field->{VALUE} = $self->_extract_query_val($fname,1) if ($qhit);
Branch: 1 branch
BranchTrueFalseTotal
if $qhit 0 0 0
2293 }
2294 0 my $group = $self->current_group();
2295 0 push(@{$group->{export_rec}[$self->{curr_rec_no}]},$field);
2296 0 return $field;
2297 }
2298  
2299 sub expand_range_fields
2300 0 ▶{
Subroutine expand_range_fields: not called CC=1 SCAR=6.9
Pod undocumented
2301 0 my ($self,$field,$rs,$re) = @_;
2302 0 my @fields;
2303 0 my $startf = _copy_field($start_range_field,$field);
2304 0 $startf = $self->create_field($startf);
2305 0 $startf->{VALUE} = $rs;
2306 0 push(@fields,$startf);
2307 0 my $endf = _copy_field($end_range_field,$field);
2308 0 $endf = $self->create_field($endf);
2309 0 $endf->{VALUE} = $re;
2310 0 push(@fields,$endf);
2311 0 my $group = $self->current_group();
2312 0 push(@{$group->{export_rec}[$self->{curr_rec_no}]},@fields);
2313 0 return \@fields;
2314 }
2315  
2316 # set the read-only flag according to form -> group -> if read-only, do not transmit form element properties
2317 sub _export_ro
2318 0 ▶{
Subroutine _export_ro: not called CC=13 SCAR=52.0
2319 0 my ($self,$field) = @_;
2320 0 my ($rec,$val);
2321 0 my $isdate = _isdate($field);
2322  
2323 0 my $usage = $self->group_usage();
2324 0 my $group = $self->current_group();
2325  
2326 # Check $group->{data} BEFORE any {hidden} fields because an incomplete record may be passed
2327 # around in the hidden fields but display of the full record is normally desired
2328 # e.g. passing around the record's PK is useful but the full record should be displayed
2329 0 ▶ if ($rec = $self->current_record())
Branch: 2 branches
BranchTrueFalseTotal
if ($rec = $self->current_record) { } 0 0 0
elsif (exists $self->{'struct_query'}{$self->current_group_name}) { } 0 0 0
2330 {
2331 }
2332 elsif (exists($self->{struct_query}{$self->current_group_name()}))
2333 {
2334 0 $rec = $self->{struct_query}{$self->current_group_name()};
2335 }
2336  
2337 0 ▶ $rec = {} unless $rec;
Branch: 1 branch
BranchTrueFalseTotal
unless $rec 0 0 0
2338  
2339 # If the group is being used for display, then display only those values contained in $rec
2340 # If the original group usage is other than DISPLAY ONLY, we want to show all user input, and lack of input
2341 # e.g. if we're conducting a session and are showing the summary screen, any fields left blank by the user should be revealed
2342 # unless the field is empty and the user is not allowed to enter a value for the field
2343 exists($rec->{$field->{FIELD_NAME}}) || return 0 if ($usage eq $CGI::AutoForm::DISPLAY_ONLY_GROUP && !$group->{tabular}) ||
2344 ($usage eq $CGI::AutoForm::INSERT_GROUP && $field->{INSERTABLE} ne 'Y') ||
2345 ($usage eq $CGI::AutoForm::EDIT_GROUP && $field->{UPDATABLE} ne 'Y') ||
2346 0 ▶ ($usage eq $CGI::AutoForm::SEARCH_GROUP && $field->{SEARCHABLE} ne 'Y');
Branch: 1 branch
BranchTrueFalseTotal
if $usage eq $CGI::AutoForm::DISPLAY_ONLY_GROUP and not $group->{"tabular"} or $usage eq $CGI::AutoForm::INSERT_GROUP and $field->{"INSERTABLE"} ne "Y" or $usage eq $CGI::AutoForm::EDIT_GROUP and $field->{"UPDATABLE"} ne "Y" or $usage eq $CGI::AutoForm::SEARCH_GROUP and $field->{"SEARCHABLE"} ne "Y" 0 0 0
Condition0%0/26
($usage eq $CGI::AutoForm::DISPLAY_ONLY_GROUP && !$group->{'tabular'} || $usage eq $CGI::AutoForm::INSERT_GROUP && $field->{'INSERTABLE'} ne 'Y' || $usage eq $CGI::AutoForm::EDIT_GROUP && $field->{'UPDATABLE'} ne 'Y' || $usage eq $CGI::AutoForm::SEARCH_GROUP && $field->{'SEARCHABLE'} ne 'Y') && (exists $$rec{$field->{'FIELD_NAME'}} || (return 0))
!ll&&!rl&&r
000
$usage eq $CGI::AutoForm::DISPLAY_ONLY_GROUP and not $group->{"tabular"} or $usage eq $CGI::AutoForm::INSERT_GROUP and $field->{"INSERTABLE"} ne "Y" or $usage eq $CGI::AutoForm::EDIT_GROUP and $field->{"UPDATABLE"} ne "Y" or $usage eq $CGI::AutoForm::SEARCH_GROUP and $field->{"SEARCHABLE"} ne "Y"
l!l&&r!l&&!r
000
$usage eq $CGI::AutoForm::DISPLAY_ONLY_GROUP and not $group->{"tabular"} or $usage eq $CGI::AutoForm::INSERT_GROUP and $field->{"INSERTABLE"} ne "Y" or $usage eq $CGI::AutoForm::EDIT_GROUP and $field->{"UPDATABLE"} ne "Y"
l!l&&r!l&&!r
000
$usage eq $CGI::AutoForm::DISPLAY_ONLY_GROUP and not $group->{"tabular"} or $usage eq $CGI::AutoForm::INSERT_GROUP and $field->{"INSERTABLE"} ne "Y"
l!l&&r!l&&!r
000
$usage eq $CGI::AutoForm::DISPLAY_ONLY_GROUP and not $group->{"tabular"}
!ll&&!rl&&r
000
$usage eq $CGI::AutoForm::INSERT_GROUP and $field->{"INSERTABLE"} ne "Y"
!ll&&!rl&&r
000
$usage eq $CGI::AutoForm::EDIT_GROUP and $field->{"UPDATABLE"} ne "Y"
!ll&&!rl&&r
000
$usage eq $CGI::AutoForm::SEARCH_GROUP and $field->{"SEARCHABLE"} ne "Y"
!ll&&!rl&&r
000
exists $$rec{$field->{"FIELD_NAME"}} or return 0
l!l
00
MC/DC0%0/9
($usage eq $CGI::AutoForm::DISPLAY_ONLY_GROUP && !$group->{'tabular'} || $usage eq $CGI::AutoForm::INSERT_GROUP && $field->{'INSERTABLE'} ne 'Y' || $usage eq $CGI::AutoForm::EDIT_GROUP && $field->{'UPDATABLE'} ne 'Y' || $usage eq $CGI::AutoForm::SEARCH_GROUP && $field->{'SEARCHABLE'} ne 'Y') && (exists $$rec{$field->{'FIELD_NAME'}} || (return 0))
$usage eq $CGI::AutoForm::DISPLAY_ONLY_GROUP not $group->{"tabular"} $usage eq $CGI::AutoForm::INSERT_GROUP $field->{"INSERTABLE"} ne "Y" $usage eq $CGI::AutoForm::EDIT_GROUP $field->{"UPDATABLE"} ne "Y" $usage eq $CGI::AutoForm::SEARCH_GROUP $field->{"SEARCHABLE"} ne "Y" exists $$rec{$field->{"FIELD_NAME"}}
Truth table0%0/46
A and not(B) or C and D or E and F or G and H && I
A= $usage eq $CGI::AutoForm::DISPLAY_ONLY_GROUPB= not $group->{"tabular"}C= $usage eq $CGI::AutoForm::INSERT_GROUPD= $field->{"INSERTABLE"} ne "Y"E= $usage eq $CGI::AutoForm::EDIT_GROUPF= $field->{"UPDATABLE"} ne "Y"G= $usage eq $CGI::AutoForm::SEARCH_GROUPH= $field->{"SEARCHABLE"} ne "Y"I= exists $$rec{$field->{"FIELD_NAME"}}
ABCDEFGHIresult
0X0X0X0XX0
0X0X0X10X0
0X0X100XX0
0X0X1010X0
0X100X0XX0
0X100X10X0
0X10100XX0
0X101010X0
100X0X0XX0
100X0X10X0
100X100XX0
100X1010X0
10100X0XX0
10100X10X0
1010100XX0
10101010X0
11XXXXXX00
0X11XXXX00
1011XXXX00
0X0X11XX00
0X1011XX00
100X11XX00
101011XX00
0X0X0X1100
0X0X101100
0X100X1100
0X10101100
100X0X1100
100X101100
10100X1100
1010101100
11XXXXXX11
0X11XXXX11
1011XXXX11
0X0X11XX11
0X1011XX11
100X11XX11
101011XX11
0X0X0X1111
0X0X101111
0X100X1111
0X10101111
100X0X1111
100X101111
10100X1111
1010101111
2347  
2348 0 $val = $rec->{$field->{FIELD_NAME}};
2349  
2350 0 $self->_assign_ro_val($field,$val,$isdate);
2351 0 push(@{$group->{export_rec}[$self->{curr_rec_no}]},$field);
2352 0 return $field;
2353 }
2354  
2355 sub _assign_ro_val
2356 0 ▶{
Subroutine _assign_ro_val: not called CC=7 SCAR=40.3
2357 0 my ($self,$field,$val,$isdate) = @_;
2358 0 ▶ $val = _display_normal_date($val,$field->{DATATYPE}) if ($isdate);
Branch: 1 branch
BranchTrueFalseTotal
if $isdate 0 0 0
2359  
2360 0 ▶ if ($field->{INPUT_CONTROL_TYPE} eq 'CHECKGROUP' && ref($field->{PICK_HASH}))
Branch: 1 branch
BranchTrueFalseTotal
if ($field->{'INPUT_CONTROL_TYPE'} eq 'CHECKGROUP' and ref $field->{'PICK_HASH'}) { } 0 0 0
Condition0%0/3
$field->{"INPUT_CONTROL_TYPE"} eq "CHECKGROUP" and ref $field->{"PICK_HASH"}
!ll&&!rl&&r
000
MC/DC0%0/2
$field->{"INPUT_CONTROL_TYPE"} eq "CHECKGROUP" and ref $field->{"PICK_HASH"}
$field->{"INPUT_CONTROL_TYPE"} eq "CHECKGROUP" ref $field->{"PICK_HASH"}
Truth table0%0/3
A and B
A= $field->{"INPUT_CONTROL_TYPE"} eq "CHECKGROUP"B= ref $field->{"PICK_HASH"}
ABresult
0X0
100
111
2361 {
2362 0 foreach my $sp (split($field->{MULTI_INSERT_DELIMITER},$val))
2363 {
2364 0 ▶ $field->{DISPLAY_VALUE} .= (exists($field->{PICK_HASH}{$sp}) ? $field->{PICK_HASH}{$sp} : 'INVALID!') . ', ';
Branch: 1 branch
BranchTrueFalseTotal
exists $field->{'PICK_HASH'}{$sp} ? : 0 0 0
2365 }
2366 0 chop($field->{DISPLAY_VALUE});
2367 0 chop($field->{DISPLAY_VALUE});
2368 }
2369 else
2370 {
2371 0 ▶ $field->{DISPLAY_VALUE} = (ref($field->{PICK_HASH}) ? $field->{PICK_HASH}{$val} : $val);
Branch: 1 branch
BranchTrueFalseTotal
ref $field->{'PICK_HASH'} ? : 0 0 0
2372 }
2373  
2374 0 $field->{INPUT_CONTROL_TYPE} = $CGI::AutoForm::DISPLAY_ONLY_GROUP;
2375 0 delete($field->{FORM_ELEMENT_NAME});
2376 }
2377  
2378 sub _display_normal_date
2379 0 ▶{
Subroutine _display_normal_date: not called CC=3 SCAR=24.8
2380 0 my ($dateval,$type) = @_;
2381 0 my ($year,$mon,$day,$hr,$min,$sec) = $dateval =~ /(\d\d\d\d)(\d\d)(\d\d)(\d\d)?(\d\d)?(\d\d)?/;
2382 0 my $date = $day . '-' . substr($months[$mon],0,3) . '-' . $year;
2383 0 ▶ if ($type eq $DBIx::IO::GenLib::DATE_TYPE)
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq $DBIx::IO::GenLib::DATE_TYPE) { } 0 0 0
elsif ($type eq $DBIx::IO::GenLib::DATETIME_TYPE) { } 0 0 0
2384 {
2385 0 return $date;
2386 }
2387 elsif ($type eq $DBIx::IO::GenLib::DATETIME_TYPE)
2388 {
2389 0 return "$date $hr:$min";
2390 }
2391 else
2392 {
2393 0 die("Invalid date type: $type");
2394 0 return undef;
2395 }
2396 }
2397  
2398 =pod
2399  
2400 =item C<prepare>
2401  
2402 $form_html = $self->prepare([$query],[$val_callback],[$rec_callback],[$head_callback]);
2403  
2404 $query can be given to impose a state on forms
2405 between instantiations via otherwise stateless HTTP (see also CGI::AutoForm::Session).
2406 $query is a hashref of NAME => value pairs where the value can be a scalar or arrayref.
2407 An arrayref is used where NAME is associated with more than one value. $query is typically
2408 derived from a GET query string or POST name=value pairs from an HTTP response.
2409  
2410 If present, $query values are sticky in the sense that they
2411 will override any defaults and any values introduced with C<add_record>.
2412  
2413 For vertical views (insert/update groups), assign values to the fields
2414 according to the following priority scheme:
2415 1) If a query was submitted, use it as a source of data if it has values for the current group.
2416 2) If a current record exists for the current group, use it as a data source.
2417 3) Use the field's DEFAULT_VALUE attribute, if any.
2418 The exception here is that if the $form->{coalesce_default_insert} attribute is true then:
2419 Use the value from current record if it exists
2420 otherwise use the DEFAULT_VALUE attribute, if any.
2421  
2422  
2423 To give you more control over the HTML that is generated, callback functions are accepted.
2424 $head_callback and $val_callback functions will be called for each field in the form as (except for tabular groups where $head_callback is not called at all):
2425  
2426 &callback($value,$field,$form)
2427  
2428 and must return the desired HTML snippet for that element. $field is a hashref of all columns
2429 in UI_TABLE_COLUMN plus any added by this class while processing (see C<create_field>). $form is the form object.
2430  
2431 For $head_callback, $value will be the heading text to be displayed for each field.
2432  
2433 For $val_callback, $value will be the display value or HTML form input element
2434 depending on the type of data group it is part of (read-only/writable).
2435  
2436 For $rec_callback, the prototype follows:
2437  
2438 &callback($value,$field,$group,$form)
2439  
2440 where $value will be the entire HTML row C<tr> block and $group is the data group structure.
2441 For a tabular display of search results, $field will instead be the data record for that row (hashref of NAME => value pairs).
2442  
2443 An ugly, unformatted gob of HTML is returned as a scalar reference for performance reasons.
2444 If only certain parts of the HTML generated are useful, the following attributes can
2445 be used to extract certain sections. Some can also be completely overridden
2446 if defined before calling this method (see B<Form preparation, HTML generation & customization>), in which case they should contain certain opening/closing HTML elements
2447 noted below:
2448  
2449 For each field in $group->{export_rec}:
2450 $field->{html}
2451  
2452 Note that the export_rec attr for each group is only available
2453 after calling this method.
2454  
2455 For each $group in $form:
2456  
2457 $group->{html}, a composite of:
2458 $group->{head_html} (must contain the opening C<table> tag)
2459 $group->{body_html}
2460 $group->{tail_html} (must contain the closing C<table> tag)
2461
2462 $form->{body_html}, a composite of:
2463 $form->{hidden_html}
2464 $group->{html} for each group in $form
2465
2466 $form->{html}, a composite of:
2467 $form->{head_html} (must contain the opening C<form> tag)
2468 $form->{body_html}
2469 $form->{tail_html} (must contain the closing C<form> tag and submit button)
2470  
2471 =cut
2472 ##at how about a group_callback???
2473 ##at default head and tail html (and other default HTML) should be available as a constant
2474 # populate export attr of each group and integrate query into hidden fields
2475 # the query passed in will be structured, date compressed, and validated (see structure_query(),validate_query())
2476 #
2477 # Advanced:
2478 # All $query values will be also added to the form's hidden attribute, except if they
2479 # have been used to override values in the current form (we don't want to confuse these with data
2480 # submitted by the operator).
2481  
2482 sub prepare
2483 0 ▶{
Subroutine prepare: not called CC=3 SCAR=24.8
Pod documented
2484 0 my ($self,$query,$val_callback,$rec_callback,$head_callback) = @_;
2485 0 $self->{val_callback} = $val_callback;
2486 0 $self->{head_callback} = $head_callback;
2487 0 $self->{rec_callback} = $rec_callback;
2488 0 ▶ $query ||= {};
Condition0%0/2
$query ||= {}
l!l
00
MC/DC0%0/1
$query ||= {}
$query
Truth table0%0/2
A
A= $query
Aresult
11
00
2489 0 my $hidden = $self->hidden();
2490 0 my ($key,$val);
2491  
2492 # this will overwrite any values for keys in {hidden} with those values in $q
2493 0 ▶ while (($key,$val) = each(%$query))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$query) 0 0 0
2494 {
2495 0 $hidden->{$key} = $val;
2496 }
2497 0 $self->{hidden} = $self->normalize_query($hidden);
2498 0 $self->{struct_query} = $self->structure_query($self->{hidden});
2499 0 $self->prepare_export();
2500 0 return \$self->{html};
2501 }
2502  
2503 ##at should have a <NOSCRIPT> html tag to explain that the header help links will not be accessible
2504  
2505 sub prepare_export
2506 0 ▶{
Subroutine prepare_export: not called CC=27 SCAR=66.3
Pod undocumented
2507 0 my ($self) = @_;
2508 0 $self->reset_group();
2509 0 my ($group,$field_s);
2510 0 ▶ while ($group = $self->next_group())
Branch: 1 branch
BranchTrueFalseTotal
if ($group = $self->next_group) 0 0 0
2511 {
2512 0 my $record;
2513 my $rec_no;
2514 0 my $rec_count = $#{$group->{data}};
2515 ##at sharing $hidden with $record (in add_record()) is a bad idea could cause discrepancies below
2516 ##at are you sure?? I think if the user keeps their own namespace when using hidden there should be no problems???
2517 ##at what is really happening is that whatever is in hidden will take precedence over parameter keys in $record
2518 0 ▶ while ($record = $self->next_record())
Branch: 1 branch
BranchTrueFalseTotal
if ($record = $self->next_record) 0 0 0
2519 {
2520 0 my $head_rec;
2521 my $fields;
2522 0 my $tail_rec = 0;
2523 0 ▶ if ($group->{tabular} && $rec_no == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($group->{"tabular"} and $rec_no == 0) 0 0 0
Condition0%0/3
$group->{"tabular"} and $rec_no == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$group->{"tabular"} and $rec_no == 0
$group->{"tabular"} $rec_no == 0
Truth table0%0/3
A and B
A= $group->{"tabular"}B= $rec_no == 0
ABresult
0X0
100
111
2524 {
2525 0 ▶ (($group->{body_html} = "No records found"),next) unless %$record;
Branch: 1 branch
BranchTrueFalseTotal
unless %$record 0 0 0
2526 0 $head_rec = '<THEAD><TR>';
2527 }
2528 0 ▶ if ($group->{tabular} && $rec_no == $rec_count)
Branch: 1 branch
BranchTrueFalseTotal
if ($group->{"tabular"} and $rec_no == $rec_count) 0 0 0
Condition0%0/3
$group->{"tabular"} and $rec_no == $rec_count
!ll&&!rl&&r
000
MC/DC0%0/2
$group->{"tabular"} and $rec_no == $rec_count
$group->{"tabular"} $rec_no == $rec_count
Truth table0%0/3
A and B
A= $group->{"tabular"}B= $rec_no == $rec_count
ABresult
0X0
100
111
2529 {
2530 0 $tail_rec = 1;
2531 }
2532 0 ▶ while ($field_s = $self->next_field())
Branch: 1 branch
BranchTrueFalseTotal
if ($field_s = $self->next_field) 0 0 0
2533 {
2534 0 ▶ $fields .= $self->field_group_html($field_s,$group,undef,($head_rec ? \$head_rec : undef()),$tail_rec);
Branch: 1 branch
BranchTrueFalseTotal
$head_rec ? : 0 0 0
2535 }
2536 0 ▶ if ($group->{tabular})
Branch: 1 branch
BranchTrueFalseTotal
if ($group->{"tabular"}) 0 0 0
2537 {
2538 0 ▶ if ($rec_no == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($rec_no == 0) 0 0 0
2539 {
2540 0 $head_rec .= '</TR></THEAD>';
2541 0 $group->{body_html} .= $head_rec;
2542 }
2543 0 ▶ $fields = &{$self->{rec_callback}}($fields,$record,$group,$self) if ref($self->{rec_callback}) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"rec_callback"} eq "CODE" 0 0 0
2544 0 ▶ $fields = "<TR" . ($tail_rec ? ' '.$group->{TABULAR_TR_TAIL_ATTRS} . ' CLASS="GTAIL_TR"' : '') . ">$fields</TR>";
Branch: 1 branch
BranchTrueFalseTotal
$tail_rec ? : 0 0 0
2545 }
2546 0 $group->{body_html} .= $fields;
2547 0 $rec_no++;
2548 }
2549 0 ▶ $group->{body_html} = qq[<SCRIPT LANGUAGE="JavaScript"><!--\r\n$group->{js}\r\n--></SCRIPT>$group->{body_html}] if $group->{js};
Branch: 1 branch
BranchTrueFalseTotal
if $group->{"js"} 0 0 0
2550 ##at for each css class there should be a form/group object attribute
2551 ##at with the same name as the class, any HTML attributes it contains will be inserted into the tag after the CLASS attr
2552 # GT => group table GH => Group Heading
2553 0 ▶ $group->{head_html} = qq[<DIV CLASS="GH">$group->{heading}</DIV><TABLE CLASS="GT" $self->{GT}>] unless defined($group->{head_html});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $group->{"head_html"} 0 0 0
2554 0 ▶ $group->{tail_html} = qq[</TABLE>] unless defined($group->{tail_html});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $group->{"tail_html"} 0 0 0
2555 0 $group->{html} = "$group->{head_html}$group->{body_html}$group->{tail_html}";
2556 0 $self->{body_html} .= "<P>$group->{html}</P>";
2557 }
2558 0 ▶ $self->{heading} = qq[<H2>$self->{heading}</H2>] if $self->{heading};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"heading"} 0 0 0
2559 $self->{head_html} = qq[$self->{heading}<FORM NAME="$self->{name}" ACTION="$self->{action}" METHOD="POST" $self->{form_enctype_attr}>]
2560 0 ▶ unless defined($self->{head_html});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"head_html"} 0 0 0
2561 0 ▶ if ($self->{valid_error})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"valid_error"}) 0 0 0
2562 {
2563 0 ▶ $self->{verr_msg} = '!----INPUT ERROR: Please correct the fields marked below----!' unless $self->{verr_msg};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"verr_msg"} 0 0 0
2564 0 $self->{head_html} .= qq[<P><B><FONT COLOR="RED"><DIV ALIGN="CENTER" CLASS="VERR_MSG">$self->{verr_msg}</DIV></FONT></B></P>];
2565 }
2566 0 my $submit_val = $self->escape($self->{submit_value});
2567 0 ▶ $submit_val = qq[VALUE="$submit_val"] if length($self->{submit_value});
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"submit_value"} 0 0 0
2568 ##at shouldn't use WIDTH and ALIGN attrs - use classes/CSS instead
2569 $self->{tail_html} = qq[<P><TABLE WIDTH="100%"><TR><TD style="text-align: right;"><INPUT $self->{submit_button_attrs} TYPE="RESET"></TD><TD style="width: 30px;"></TD>] .
2570 0 ▶ qq[<TD style="text-align: left;"><INPUT $self->{submit_button_attrs} TYPE="SUBMIT" $submit_val></TD></TR></TABLE></P></FORM>] unless defined($self->{tail_html});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"tail_html"} 0 0 0
2571 0 ▶ $self->{tail_html} .= qq[<DIV>* Indicates required field</DIV>] if $self->{ast_foot};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ast_foot"} 0 0 0
2572 0 my $wmess = $self->escape("** Field accepts '\%' as a wildcard matching operator");
2573 0 my $cmess = $self->escape("*** Field accepts a comma-separated list of values");
2574 0 ▶ $self->{tail_html} .= qq[<DIV>$wmess</DIV>] if $self->{_ast_match};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_ast_match"} 0 0 0
2575 0 ▶ $self->{tail_html} .= qq[<DIV>$cmess</DIV>] if $self->{_cst_match};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_cst_match"} 0 0 0
2576 0 $self->{body_html} = $self->hidden_html() . $self->{body_html};
2577 0 my $tmess = $self->{top_message};
2578 0 my $noscript = '';
2579 0 ▶ $noscript = qq[<NOSCRIPT><P>$self->{noscript}</NOSCRIPT>] if $self->{noscript};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"noscript"} 0 0 0
2580 0 $self->{html} = "$noscript$tmess$self->{head_html}$self->{heading2}$self->{body_html}$self->{tail_html}";
2581 0 $self->reset_group();
2582 }
2583  
2584 sub field_group_html
2585 0 ▶{
Subroutine field_group_html: not called CC=28 SCAR=67.0
Pod undocumented
2586 0 my ($self,$field_s,$group,$label_class_add,$head_rec,$tail_rec) = @_;
2587 0 my ($val,$head,$headadd);
2588 0 ▶ if (ref($field_s) eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $field_s eq 'ARRAY') { } 0 0 0
2589 {
2590 0 ▶ if (ref($field_s->[1]) eq 'ARRAY')
Branch: 4 branches
BranchTrueFalseTotal
if (ref $field_s->[1] eq 'ARRAY') { } 0 0 0
elsif (substr($field_s->[0]{'FORM_ELEMENT_NAME'}, -6) eq '_MONTH') { } 0 0 0
elsif ($self->group_usage eq $CGI::AutoForm::SEARCH_GROUP) { } 0 0 0
elsif ($field_s->[0]{'FIELD_GROUP'} eq 'CONFIRM') { } 0 0 0
2591 {
2592 0 ▶ if ($self->group_usage() eq $CGI::AutoForm::SEARCH_GROUP)
Branch: 2 branches
BranchTrueFalseTotal
if ($self->group_usage eq $CGI::AutoForm::SEARCH_GROUP) { } 0 0 0
elsif ($field_s->[1][0]{'FIELD_GROUP'} eq 'CONFIRM') { } 0 0 0
2593 {
2594 # SEARCHABLE date range group
2595 0 ($headadd,$val) = $self->search_date_html($field_s,$group);
2596 0 $field_s = $field_s->[0];
2597 }
2598 elsif ($field_s->[1][0]{FIELD_GROUP} eq 'CONFIRM')
2599 {
2600 # For a confirmable date group (will this EVER happen!!)
2601 0 my $ret = $self->field_group_html($field_s->[0],$group);
2602  
2603 # using CSS content generation, can set a different heading for CONFIRM fields in the style sheet by setting a class property
2604 0 ▶ $ret .= $self->field_group_html($field_s->[1],$group,'CONFIRM') unless $group->{tabular};
Branch: 1 branch
BranchTrueFalseTotal
unless $group->{"tabular"} 0 0 0
2605 0 return $ret;
2606 }
2607 0 else { die "A horrible death"; }
2608 }
2609 elsif (substr($field_s->[0]{FORM_ELEMENT_NAME},-6) eq '_MONTH')
2610 {
2611 # Must be a date group
2612 0 $val .= '<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0"><TR>';
2613 0 $val .= $self->date_group_html($field_s);
2614 0 $val .= '</TR></TABLE>';
2615 0 $field_s = $field_s->[0];
2616 }
2617 elsif ($self->group_usage() eq $CGI::AutoForm::SEARCH_GROUP)
2618 {
2619 # Must be a plain search range with 'TEXT' controls
2620 0 $val = $self->search_range_html($field_s,$group);
2621 0 $field_s = $field_s->[0];
2622 }
2623 elsif ($field_s->[0]{FIELD_GROUP} eq 'CONFIRM')
2624 {
2625 0 my $ret = $self->field_group_html($field_s->[0],$group);
2626 0 ▶ $ret .= $self->field_group_html($field_s->[1],$group,'CONFIRM') unless $group->{tabular};
Branch: 1 branch
BranchTrueFalseTotal
unless $group->{"tabular"} 0 0 0
2627 0 return $ret;
2628 }
2629 0 else { die "A horrible death"; }
2630 }
2631 else
2632 {
2633 0 $val = $self->field_html($field_s);
2634 }
2635
2636 0 ▶ if ($group->{tabular})
Branch: 1 branch
BranchTrueFalseTotal
if ($group->{'tabular'}) { } 0 0 0
2637 {
2638 0 ▶ return '' unless length($field_s->{BRIEF_HEADING});
Branch: 1 branch
BranchTrueFalseTotal
unless length $field_s->{"BRIEF_HEADING"} 0 0 0
2639 0 ▶ if ($head_rec)
Branch: 1 branch
BranchTrueFalseTotal
if ($head_rec) 0 0 0
2640 {
2641 0 $head = $self->escape($field_s->{BRIEF_HEADING});
2642 ##at could also support TABULAR_TH_ATTRS, TABULAR_TD_ATTRS, etc management by adding it to UI_TABLE_COLUMN and pod up
2643 0 $$head_rec .= qq[<TH CLASS="TABULAR_TH" $group->{TABULAR_TH_ATTRS} $field_s->{TABULAR_TH_ATTRS}>$head</TH>];
2644 }
2645 0 ▶ $val = &{$self->{val_callback}}($val,$field_s,$self) if ref($self->{val_callback});
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"val_callback"} 0 0 0
2646 0 ▶ if ($tail_rec && $group->{TABULAR_TD_TAIL_STYLE})
Branch: 1 branch
BranchTrueFalseTotal
if ($tail_rec and $group->{"TABULAR_TD_TAIL_STYLE"}) 0 0 0
Condition0%0/3
$tail_rec and $group->{"TABULAR_TD_TAIL_STYLE"}
!ll&&!rl&&r
000
MC/DC0%0/2
$tail_rec and $group->{"TABULAR_TD_TAIL_STYLE"}
$tail_rec $group->{"TABULAR_TD_TAIL_STYLE"}
Truth table0%0/3
A and B
A= $tail_recB= $group->{"TABULAR_TD_TAIL_STYLE"}
ABresult
0X0
100
111
2647 {
2648 0 $field_s->{TABULAR_TD_STYLE} .= $group->{TABULAR_TD_TAIL_STYLE};
2649 }
2650 0 my $style = '';
2651 0 ▶ if ($field_s->{TABULAR_TD_STYLE})
Branch: 1 branch
BranchTrueFalseTotal
if ($field_s->{"TABULAR_TD_STYLE"}) 0 0 0
2652 {
2653 0 $style = qq[style="$field_s->{TABULAR_TD_STYLE}"];
2654 }
2655 return "<TD" . ($field_s->{VALID_ERROR} ? ' CLASS="VERR TABULAR_TD"' : ' CLASS="TABULAR_TD"') . " $field_s->{TABULAR_TD_ATTRS}" .
2656 0 ▶ ($tail_rec ? ' '. $group->{TABULAR_TD_TAIL_ATTRS} : '') . " $style>" . (length($val) ? $val : '&nbsp;' ) . "</TD>";
Branch: 3 branches
BranchTrueFalseTotal
$field_s->{'VALID_ERROR'} ? : 0 0 0
$tail_rec ? : 0 0 0
length $val ? : 0 0 0
2657 }
2658 else
2659 {
2660 0 my $valerr = $self->escape($field_s->{VALID_ERROR});
2661 0 $head = $self->escape($field_s->{HEADING});
2662 0 $head = $self->_process_field_head($field_s,$head,$group);
2663  
2664 # all callbacks must be responsible for escaping any added HTML
2665 0 ▶ $val = &{$self->{val_callback}}($val,$field_s,$self) if ref($self->{val_callback});
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"val_callback"} 0 0 0
2666  
2667 0 my $class;
2668 0 ▶ $class .= "$label_class_add " if $label_class_add;
Branch: 1 branch
BranchTrueFalseTotal
if $label_class_add 0 0 0
2669 0 ▶ $class .= "REQ " if $field_s->{REQUIRED} eq 'Y';
Branch: 1 branch
BranchTrueFalseTotal
if $field_s->{"REQUIRED"} eq "Y" 0 0 0
2670 0 ▶ $class .= "VERR " if $valerr;
Branch: 1 branch
BranchTrueFalseTotal
if $valerr 0 0 0
2671 0 chop($class);
2672 0 ▶ $class = qq[ CLASS="$class" ] if $class;
Branch: 1 branch
BranchTrueFalseTotal
if $class 0 0 0
2673 0 ▶ $headadd = qq[<P>$headadd</P>] if $headadd;
Branch: 1 branch
BranchTrueFalseTotal
if $headadd 0 0 0
2674  
2675 # this can be overridden on-the-fly also
2676 0 ▶ $valerr = qq[<FONT COLOR="RED" CLASS="VERR"><SPAN CLASS="VERR">$valerr</SPAN></FONT>]
Branch: 1 branch
BranchTrueFalseTotal
if $valerr 0 0 0
2677 if $valerr;
2678  
2679 0 my $ret = qq[<TD CLASS="VFL" $self->{VFL}><LABEL$class>$head $valerr</LABEL>$headadd</TD><TD CLASS="VFE" $self->{VFE}>&nbsp;$val</TD>];
2680 0 ▶ $ret = &{$self->{rec_callback}}($ret,$field_s,$group,$self) if ref($self->{rec_callback}) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"rec_callback"} eq "CODE" 0 0 0
2681 0 return qq[<TR CLASS="VFR" $self->{VFR}>$ret</TR>];
2682 }
2683 }
2684  
2685 # If callback differs, don't add alert_summary
2686 sub _process_field_head
2687 0 ▶{
Subroutine _process_field_head: not called CC=8 SCAR=42.8
2688 0 my ($self,$field_s,$head,$group) = @_;
2689 # {head_callback} does not apply to tabular headings
2690 0 ▶ if (ref($self->{head_callback}))
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{'head_callback'}) { } 0 0 0
2691 {
2692 0 my $call_head = &{$self->{head_callback}}($head,$field_s,$self);
2693 0 ▶ return $call_head if $head ne $call_head;
Branch: 1 branch
BranchTrueFalseTotal
if $head ne $call_head 0 0 0
2694 }
2695 else
2696 {
2697 0 $head = qq[$head:&nbsp;];
2698 0 my $usage = $self->group_usage();
2699 0 ▶ if (!$self->readonly() && $field_s->{REQUIRED} eq 'Y' && ($usage eq $CGI::AutoForm::INSERT_GROUP || $usage eq $CGI::AutoForm::EDIT_GROUP))
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->readonly and $field_s->{"REQUIRED"} eq "Y" and $usage eq $CGI::AutoForm::INSERT_GROUP || $usage eq $CGI::AutoForm::EDIT_GROUP) 0 0 0
Condition0%0/9
not $self->readonly and $field_s->{"REQUIRED"} eq "Y" and $usage eq $CGI::AutoForm::INSERT_GROUP || $usage eq $CGI::AutoForm::EDIT_GROUP
!ll&&!rl&&r
000
not $self->readonly and $field_s->{"REQUIRED"} eq "Y"
!ll&&!rl&&r
000
$usage eq $CGI::AutoForm::INSERT_GROUP or $usage eq $CGI::AutoForm::EDIT_GROUP
l!l&&r!l&&!r
000
MC/DC0%0/4
not $self->readonly and $field_s->{"REQUIRED"} eq "Y" and $usage eq $CGI::AutoForm::INSERT_GROUP || $usage eq $CGI::AutoForm::EDIT_GROUP
not $self->readonly $field_s->{"REQUIRED"} eq "Y" $usage eq $CGI::AutoForm::INSERT_GROUP $usage eq $CGI::AutoForm::EDIT_GROUP
Truth table0%0/5
not(A) and B and C or D
A= not $self->readonlyB= $field_s->{"REQUIRED"} eq "Y"C= $usage eq $CGI::AutoForm::INSERT_GROUPD= $usage eq $CGI::AutoForm::EDIT_GROUP
ABCDresult
0XXX0
10XX0
11000
111X1
11011
2700 {
2701 0 $head .= '*';
2702 0 $self->{ast_foot}++;
2703 }
2704 }
2705 0 ▶ if (length($field_s->{HELP_SUMMARY}))
Branch: 1 branch
BranchTrueFalseTotal
if (length $field_s->{"HELP_SUMMARY"}) 0 0 0
2706 {
2707 0 my $sum = $field_s->{HELP_SUMMARY};
2708 0 $sum =~ s/\"/\\"/gs;
2709 0 $sum =~ s/\r?\n/\\n/gs;
2710 0 my $func_name = $field_s->{FORM_ELEMENT_NAME};
2711 0 $func_name =~ s/\./_/gs;
2712 0 $func_name = "${func_name}_ALRT_SUM";
2713 0 $group->{js} .= qq[function $func_name(){alert("$sum");}\n];
2714 0 $head = qq[<A CLASS="AS" HREF="javascript:$func_name();">$head </A>];
2715 }
2716 0 return $head;
2717 }
2718  
2719 =pod
2720  
2721 =item C<require_js>
2722  
2723 $form->require_js();
2724  
2725 Add a default C<noscript> summary to require the client to support javascript.
2726 You may also set $form->{noscript} yourself.
2727  
2728 =cut
2729 sub require_js
2730 0 ▶{
Subroutine require_js: not called CC=1 SCAR=6.9
Pod documented
2731 0 my ($self) = @_;
2732 0 $self->{noscript} = qq[This application requires that you enable javascript in your browser.<BR>Refer to your browser's documentation] .
2733 qq[ to enable javascript and then return to this page.];
2734 }
2735  
2736 sub search_date_html
2737 0 ▶{
Subroutine search_date_html: not called CC=1 SCAR=6.9
Pod undocumented
2738 0 my ($self,$field_s,$group) = @_;
2739 0 my ($val,$head);
2740 0 $val .= '<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0">';
2741 0 $val .= '<TR><TD>Between&nbsp;</TD>' . $self->date_group_html($field_s->[1]) . '</TR>';
2742 0 $val .= '<TR><TD>And</TD>' . $self->date_group_html($field_s->[2]) . '</TR>';
2743 0 $val .= '<TR><TD>OR within the past&nbsp;</TD>' . $self->date_rel_html($field_s->[3]) . '</TR>';
2744 0 $val .= '</TABLE>';
2745 0 $head = $self->field_html($field_s->[0]);
2746 0 return ($head,$val);
2747 }
2748  
2749 sub search_range_html
2750 0 ▶{
Subroutine search_range_html: not called CC=1 SCAR=6.9
Pod undocumented
2751 0 my ($self,$field_s,$group) = @_;
2752 0 my $val;
2753 0 $val .= '<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0">';
2754 0 $val .= '<TR><TD>Between&nbsp;</TD><TD>' . $self->field_html($field_s->[0]) . '</TD></TR>';
2755 0 $val .= '<TR><TD>And</TD><TD>' . $self->field_html($field_s->[1]) . '</TD></TR>';
2756 0 $val .= '</TABLE>';
2757 0 return $val;
2758 }
2759  
2760 ##at should include javascript functions for days of month, leap year, etc
2761 sub date_group_html
2762 0 ▶{
Subroutine date_group_html: not called CC=7 SCAR=40.3
Pod undocumented
2763 0 my ($self,$dateset) = @_;
2764 0 my $ret;
2765 0 foreach my $date (@$dateset)
2766 {
2767 0 my ($tit) = $date->{FORM_ELEMENT_NAME} =~ /\.(\w+)$/;
2768 0 my $fill;
2769 0 ▶ if ($tit eq '_MONTH')
Branch: 5 branches
BranchTrueFalseTotal
if ($tit eq '_MONTH') { } 0 0 0
elsif ($tit eq '_DAY') { } 0 0 0
elsif ($tit eq '_YEAR') { } 0 0 0
elsif ($tit eq '_HOUR') { } 0 0 0
elsif ($tit eq '_MIN') { } 0 0 0
2770 {
2771 0 $tit = 'Month';
2772 0 $fill = '-';
2773 }
2774 elsif ($tit eq '_DAY')
2775 {
2776 0 $tit = 'Day';
2777 0 $fill = '-';
2778 }
2779 elsif ($tit eq '_YEAR')
2780 {
2781 0 $tit = 'Year';
2782 0 $fill = '&nbsp;';
2783 }
2784 elsif ($tit eq '_HOUR')
2785 {
2786 0 $tit = 'Hour';
2787 0 $fill = ':';
2788 }
2789 elsif ($tit eq '_MIN')
2790 {
2791 0 $tit = 'Min';
2792 0 $fill = '';
2793 }
2794 0 $ret .= "<TD><DIV>$tit</DIV>". $self->field_html($date) . "$fill</TD>";
2795 }
2796 0 return $ret;
2797 }
2798  
2799 sub date_rel_html
2800 0 ▶{
Subroutine date_rel_html: not called CC=4 SCAR=30.0
Pod undocumented
2801 0 my ($self,$dateset) = @_;
2802 0 my $ret;
2803 0 foreach my $date (@$dateset)
2804 {
2805 0 my ($tit) = $date->{FORM_ELEMENT_NAME} =~ /\.(\w+)$/;
2806 0 my $fill;
2807 0 ▶ if ($tit eq '_QUANT')
Branch: 2 branches
BranchTrueFalseTotal
if ($tit eq '_QUANT') { } 0 0 0
elsif ($tit eq '_UNIT') { } 0 0 0
2808 {
2809 0 $tit = 'Quantity';
2810 0 $fill = '';
2811 0 $ret .= "<TD><DIV>$tit</DIV>". $self->field_html($date) . "$fill</TD>";
2812 }
2813 elsif ($tit eq '_UNIT')
2814 {
2815 0 $tit = 'Units';
2816 0 $fill = '';
2817 0 $ret .= "<TD COLSPAN=\"2\"><DIV>$tit</DIV>". $self->field_html($date) . "$fill</TD>";
2818 }
2819 }
2820 0 return $ret;
2821 }
2822  
2823 =pod
2824  
2825 =item C<field_by_name>
2826  
2827 $field = $form->field_by_name($field_name);
2828  
2829 Return a hashref of properties for $field_name from the current group including attributes
2830 from UI_TABLE_COLUMN and VALUE that will be displayed determined
2831 from the priority list (see C<prepare> and C<_export_field>).
2832  
2833 The returned $field structure is a copy so don't expect to change
2834 its attributes and have them be reflected in the generated HTML. To manipulate
2835 field attributes that will affect the generated HTML, access the field hashref
2836 directly using C<$form-E<gt>field_hash()-E<gt>{field_name}>
2837  
2838 =cut
2839 sub field_by_name
2840 0 ▶{
Subroutine field_by_name: not called CC=2 SCAR=17.9
Pod documented
2841 0 my ($self,$field_name) = @_;
2842 0 $field_name = uc($field_name);
2843 0 my $field_hash = $self->field_hash();
2844 0 my $field = $field_hash->{$field_name};
2845 0 ▶ if (defined($field))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $field) 0 0 0
2846 {
2847 0 $field = $self->_export_field($field);
2848 }
2849 0 return $field;
2850 }
2851  
2852 =pod
2853  
2854 =item C<field_list>
2855  
2856 $fields = $form->field_list();
2857  
2858 Return a list of fields from the current group.
2859  
2860 =cut
2861 sub field_list
2862 0 ▶{
Subroutine field_list: not called CC=1 SCAR=6.9
Pod documented
2863 0 my ($self) = @_;
2864 0 my $group = $self->current_group();
2865 0 return $group->{field_list};
2866 }
2867  
2868 =pod
2869  
2870 =item C<field_hash>
2871  
2872 $fields = $form->field_hash();
2873  
2874 Return a list of fields from the current group.
2875  
2876 =cut
2877 sub field_hash
2878 0 ▶{
Subroutine field_hash: not called CC=1 SCAR=6.9
Pod documented
2879 0 my ($self) = @_;
2880 0 my $group = $self->current_group();
2881 0 return $group->{field_hash};
2882 }
2883  
2884 sub next_record
2885 0 ▶{
Subroutine next_record: not called CC=3 SCAR=24.8
Pod undocumented
2886 0 my ($self) = @_;
2887 0 $self->{curr_field_no} = -1;
2888 0 my $group = $self->current_group();
2889 0 my $rec = $group->{data}[++$self->{curr_rec_no}];
2890 ##at if no data exists, an empty record {} will be returned the first time this sub is called for any given group
2891 ##at otherwise false will be returned
2892 0 ▶ !$rec && ($self->{curr_rec_no} == 0) && ($rec = {});
Branch: 1 branch
BranchTrueFalseTotal
not $rec and $self->{"curr_rec_no"} == 0 and $rec = {} 0 0 0
Condition0%0/3
not $rec and $self->{"curr_rec_no"} == 0
!ll&&!rl&&r
000
MC/DC0%0/2
not $rec and $self->{"curr_rec_no"} == 0
not $rec $self->{"curr_rec_no"} == 0
Truth table0%0/3
not(A) and B
A= not $recB= $self->{"curr_rec_no"} == 0
ABresult
0X0
100
111
2893 0 return $rec;
2894 }
2895  
2896 =pod
2897  
2898 =item C<next_group>
2899  
2900 $fields = $form->next_group();
2901  
2902 Return the next data group structure (hashref) in the list.
2903 Changes state of $form by incrementing curr_group_no.
2904  
2905 =cut
2906 sub next_group
2907 0 ▶{
Subroutine next_group: not called CC=1 SCAR=6.9
Pod documented
2908 0 my ($self) = @_;
2909 0 $self->{curr_field_no} = -1;
2910 0 $self->{curr_rec_no} = -1;
2911 0 return $self->{group_list}[++$self->{curr_group_no}];
2912 }
2913  
2914 sub create_group
2915 0 ▶{
Subroutine create_group: not called CC=3 SCAR=24.8
Pod undocumented
2916 0 my ($self,$table_name,$heading,$group_name,$usage,$tabular) = @_;
2917 0 ▶ defined($group_name) || ($group_name = $table_name);
Branch: 1 branch
BranchTrueFalseTotal
defined $group_name or $group_name = $table_name 0 0 0
2918 0 ▶ defined($heading) || ($heading = "\u\L$group_name" . ' Info');
Branch: 1 branch
BranchTrueFalseTotal
defined $heading or $heading = ucfirst(lc $group_name) . ' Info' 0 0 0
2919 return {
2920 0 table_name => $table_name,
2921 heading => $heading,
2922 group_name => uc($group_name),
2923 data => [],
2924 export_rec => [],
2925 usage => $usage,
2926 tabular => $tabular,
2927 field_list => [],
2928 field_hash => {},
2929 };
2930 }
2931  
2932 # hidden namespace issues: if you call add_record() and then try and add hidden fields that
2933 # clash with fields in the record (when using it for an update) the added hidden fields
2934 # will overwrite those added via add_record()
2935 # this is because when using add_record(), it actually adds the record to the hidden field group
2936 # for an updatable group
2937  
2938 ##at to improve memory usage under mod_perl - it may be useful to audit all refs used
2939 ##at from external modules and make sure that they are always cloned so the program
2940 ##at doesn't think they will be potentially modified
2941  
2942 =pod
2943  
2944 =item C<is_readonly>
2945  
2946 $bool = $form->is_readonly([$field]);
2947  
2948 Determime if the current data group is read-only, and if the particular $field
2949 is read-only if given. State-dependent.
2950 Search data groups are never read-only.
2951  
2952 =cut
2953 # $form cannot be set readonly if one of it's groups is SEARCHABLE
2954 # if $form is set readonly() then this sub will still return false for any groups that are SEARCHABLE
2955 sub is_readonly
2956 0 ▶{
Subroutine is_readonly: not called CC=7 SCAR=40.3
Pod documented
2957 0 my ($self,$field) = @_;
2958 0 my $usage = $self->group_usage();
2959 0 ▶ return 0 if $usage eq $CGI::AutoForm::SEARCH_GROUP;
Branch: 1 branch
BranchTrueFalseTotal
if $usage eq $CGI::AutoForm::SEARCH_GROUP 0 0 0
2960 0 ▶ return 1 if ($self->readonly() || $usage eq $CGI::AutoForm::DISPLAY_ONLY_GROUP);
Branch: 1 branch
BranchTrueFalseTotal
if $self->readonly or $usage eq $CGI::AutoForm::DISPLAY_ONLY_GROUP 0 0 0
Condition0%0/3
$self->readonly or $usage eq $CGI::AutoForm::DISPLAY_ONLY_GROUP
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->readonly or $usage eq $CGI::AutoForm::DISPLAY_ONLY_GROUP
$self->readonly $usage eq $CGI::AutoForm::DISPLAY_ONLY_GROUP
Truth table0%0/3
A or B
A= $self->readonlyB= $usage eq $CGI::AutoForm::DISPLAY_ONLY_GROUP
ABresult
1X1
011
000
2961 0 ▶ return 1 if $field && $usage eq $CGI::AutoForm::EDIT_GROUP && $field->{UPDATABLE} ne 'Y';
Branch: 1 branch
BranchTrueFalseTotal
if $field and $usage eq $CGI::AutoForm::EDIT_GROUP and $field->{"UPDATABLE"} ne "Y" 0 0 0
Condition0%0/6
$field and $usage eq $CGI::AutoForm::EDIT_GROUP and $field->{"UPDATABLE"} ne "Y"
!ll&&!rl&&r
000
$field and $usage eq $CGI::AutoForm::EDIT_GROUP
!ll&&!rl&&r
000
MC/DC0%0/3
$field and $usage eq $CGI::AutoForm::EDIT_GROUP and $field->{"UPDATABLE"} ne "Y"
$field $usage eq $CGI::AutoForm::EDIT_GROUP $field->{"UPDATABLE"} ne "Y"
Truth table0%0/4
A and B and C
A= $fieldB= $usage eq $CGI::AutoForm::EDIT_GROUPC= $field->{"UPDATABLE"} ne "Y"
ABCresult
0XX0
10X0
1100
1111
2962 0 return 0;
2963 }
2964  
2965 sub add_search_date_fields
2966 0 ▶{
Subroutine add_search_date_fields: not called CC=4 SCAR=30.0
Pod undocumented
2967 0 my ($self,$fields,$attrs,$ur,$rs,$re) = @_;
2968 0 ▶ $rs ||= '_SYSDATE';
Condition0%0/2
$rs ||= "_SYSDATE"
l!l
00
MC/DC0%0/1
$rs ||= "_SYSDATE"
$rs
Truth table0%0/2
A
A= $rs
Aresult
11
00
2969 0 ▶ $re ||= '_SYSDATE';
Condition0%0/2
$re ||= "_SYSDATE"
l!l
00
MC/DC0%0/1
$re ||= "_SYSDATE"
$re
Truth table0%0/2
A
A= $re
Aresult
11
00
2970  
2971 0 my $usef = _copy_field($use_range_field,$attrs,$ur);
2972 0 $usef = $self->create_field($usef,$use_range_picklist);
2973 0 push(@$fields,$usef);
2974  
2975 0 my $subfields1 = [];
2976 0 my $subfields2 = [];
2977 0 my $subfields3 = [];
2978 0 ▶ if ($attrs->{SEARCH_CONTROL_TYPE} eq 'DATERANGE')
Branch: 1 branch
BranchTrueFalseTotal
if ($attrs->{'SEARCH_CONTROL_TYPE'} eq 'DATERANGE') { } 0 0 0
2979 {
2980 0 $self->add_date_fields($subfields1,$attrs,$rs,'_RS');
2981 0 $self->add_date_fields($subfields2,$attrs,$re,'_RE');
2982 }
2983 else
2984 {
2985 0 $self->add_datetime_fields($subfields1,$attrs,$rs,'_RS');
2986 0 $self->add_datetime_fields($subfields2,$attrs,$re,'_RE');
2987 }
2988 0 $self->add_rel_daterange_fields($subfields3,$attrs);
2989 0 push(@$fields,$subfields1,$subfields2,$subfields3);
2990 0 return $fields
2991 }
2992  
2993 sub add_rel_daterange_fields
2994 0 ▶{
Subroutine add_rel_daterange_fields: not called CC=1 SCAR=6.9
Pod undocumented
2995 0 my ($self,$fields,$attrs) = @_;
2996 0 my $relq = _copy_field($rel_quantity_field,$attrs,'','_RS');
2997 0 $relq = $self->create_field($relq,undef,undef,undef,1);
2998 0 push(@$fields,$relq);
2999 0 my $relu = _copy_field($rel_unit_field,$attrs,'','_RS');
3000 0 $relu = $self->create_field($relu,$rel_unit_picklist);
3001 0 push(@$fields,$relu);
3002  
3003 }
3004  
3005 sub add_date_fields
3006 0 ▶{
Subroutine add_date_fields: not called CC=6 SCAR=37.4
Pod undocumented
3007 0 my ($self,$fields,$attrs,$dateval,$name_fill) = @_;
3008 0 ▶ if ($dateval eq '_SYSDATE')
Branch: 1 branch
BranchTrueFalseTotal
if ($dateval eq "_SYSDATE") 0 0 0
3009 {
3010 0 $dateval = DBIx::IO::GenLib::local_normal_sysdate();
3011 }
3012 0 my ($year,$month,$day);
3013 0 ▶ if ($dateval =~ /(\d\d\d\d)(\d\d)(\d\d)/)
Branch: 2 branches
BranchTrueFalseTotal
if ($dateval =~ /(\d\d\d\d)(\d\d)(\d\d)/) { } 0 0 0
elsif (length $dateval) { } 0 0 0
3014 {
3015 0 ($year,$month,$day) = ($1,$2,$3);
3016 }
3017 elsif (length($dateval))
3018 {
3019 0 warn("Date value [$dateval] could not be parsed");
3020 0 undef($dateval);
3021 }
3022  
3023 0 my $monf = _copy_field($month_field,$attrs,$month,$name_fill);
3024 0 $monf = $self->create_field($monf,$month_picklist);
3025 0 push(@$fields,$monf);
3026  
3027 0 my $dayf = _copy_field($day_field,$attrs,$day,$name_fill);
3028 0 $dayf = $self->create_field($dayf,$day_picklist);
3029 0 push(@$fields,$dayf);
3030  
3031 ##at had this default to current year but was ambiguous (if an insert/update field is not touched and meant to be null
3032 ##at this will cause the validate routine to signal an error) so not suitable for the general public
3033 0 ▶ $year = $this_year unless $year != 0 || $attrs->{REQUIRED} ne 'Y';
Branch: 1 branch
BranchTrueFalseTotal
unless $year != 0 or $attrs->{"REQUIRED"} ne "Y" 0 0 0
Condition0%0/3
$year != 0 or $attrs->{"REQUIRED"} ne "Y"
l!l&&r!l&&!r
000
MC/DC0%0/2
$year != 0 or $attrs->{"REQUIRED"} ne "Y"
$year != 0 $attrs->{"REQUIRED"} ne "Y"
Truth table0%0/3
A or B
A= $year != 0B= $attrs->{"REQUIRED"} ne "Y"
ABresult
1X1
011
000
3034 0 my $yearf = _copy_field($year_field,$attrs,$year,$name_fill);
3035 ##at configurable constant 10
3036 0 $yearf = $self->create_field($yearf,[ map { { ID => $_, MASK => $_} } (($this_year-110)..($this_year+10)) ]);
3037 0 push(@$fields,$yearf);
3038  
3039 0 return $dateval;
3040 }
3041  
3042 sub add_datetime_fields
3043 0 ▶{
Subroutine add_datetime_fields: not called CC=1 SCAR=6.9
Pod undocumented
3044 0 my ($self,$fields,$attrs,$dateval,$name_fill) = @_;
3045 0 $dateval = $self->add_date_fields($fields,$attrs,$dateval,$name_fill);
3046 0 my ($hour,$min) = $dateval =~ /\d\d\d\d\d\d\d\d(\d\d)(\d\d)/;
3047  
3048 0 my $hourf = _copy_field($hour_field,$attrs,$hour,$name_fill);
3049 0 $hourf = $self->create_field($hourf,$hour_picklist);
3050 0 push(@$fields,$hourf);
3051 #$field_hash->{$hourf->{FIELD_NAME}} = $hourf;
3052  
3053 0 my $minf = _copy_field($min_field,$attrs,$min,$name_fill);
3054 0 $minf = $self->create_field($minf,$min_picklist);
3055 0 push(@$fields,$minf);
3056 #$field_hash->{$minf->{FIELD_NAME}} = $minf;
3057  
3058 0 return $dateval;
3059 }
3060  
3061 sub _copy_field
3062 0 ▶{
Subroutine _copy_field: not called CC=5 SCAR=34.0
3063 0 my ($field,$templ,$value,$name_fill) = @_;
3064 0 my $target = { %$field };
3065 0 ▶ $target->{FIELD_NAME} = $templ->{FIELD_NAME} . '.' . (length($name_fill) ? "$name_fill." : '') . $field->{FIELD_NAME};
Branch: 1 branch
BranchTrueFalseTotal
length $name_fill ? : 0 0 0
3066 0 $target->{VALUE} = $value;
3067 0 foreach my $prop (qw(
3068 HEADING
3069 DATATYPE
3070 REQUIRED
3071 SEARCHABLE
3072 UPDATABLE
3073 INSERTABLE
3074 FIELD_GROUP
3075 VALID_ERROR
3076 SEARCH_MULT_SELECT
3077 _imp_datetype
3078 INPUT_SIZE
3079 INPUT_MAXLENGTH
3080 ELEMENT_ATTRS
3081 HELP_SUMMARY
3082 ))
3083 {
3084 0 ▶ $target->{$prop} = $templ->{$prop} if exists($templ->{$prop}) && !exists($target->{$prop});
Branch: 1 branch
BranchTrueFalseTotal
if exists $templ->{$prop} and not exists $target->{$prop} 0 0 0
Condition0%0/3
exists $templ->{$prop} and not exists $target->{$prop}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $templ->{$prop} and not exists $target->{$prop}
exists $templ->{$prop} not exists $target->{$prop}
Truth table0%0/3
A and not(B)
A= exists $templ->{$prop}B= not exists $target->{$prop}
ABresult
0X0
100
111
3085 }
3086 0 return $target;
3087 }
3088  
3089 sub expand_date_search_fields
3090 0 ▶{
Subroutine expand_date_search_fields: not called CC=1 SCAR=6.9
Pod undocumented
3091 0 my ($self,$field,$ur,$rs,$re) = @_;
3092 0 my $fields = [];
3093 0 $self->add_search_date_fields($fields,$field,$ur,$rs,$re);
3094 0 my $group = $self->current_group();
3095 0 push(@{$group->{export_rec}[$self->{curr_rec_no}]},@$fields);
3096 0 return $fields;
3097 }
3098  
3099 sub expand_date_fields
3100 0 ▶{
Subroutine expand_date_fields: not called CC=3 SCAR=24.8
Pod undocumented
3101 0 my ($self,$field,$dateval) = @_;
3102 0 my $fields = [];
3103 0 my $type = $self->control_type($field);
3104 0 ▶ if ($type eq 'DATE')
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'DATE') { } 0 0 0
elsif ($type eq 'DATETIME') { } 0 0 0
3105 {
3106 0 $self->add_date_fields($fields,$field,$dateval);
3107 }
3108 elsif ($type eq 'DATETIME')
3109 {
3110 0 $self->add_datetime_fields($fields,$field,$dateval);
3111 }
3112 else
3113 {
3114 0 die("Date type " . $type . " not recognized");
3115 0 return undef;
3116 }
3117 0 my $group = $self->current_group();
3118 0 push(@{$group->{export_rec}[$self->{curr_rec_no}]},@$fields);
3119 0 return $fields;
3120 }
3121  
3122 =pod
3123  
3124 =item C<add_record>
3125  
3126 $rec_count = $form->add_record($record[,$group_name]);
3127  
3128 Add data to $form's current group (state dependent) or the
3129 group identified by $group_name if given.
3130 $record can be a hashref of FIELD_NAME => value pairs
3131 or an arrayref of such records (for tabular groups of type
3132 'DISPLAY ONLY').
3133  
3134 This method should be used for groups of type 'DISPLAY EDIT'
3135 and 'DISPLAY ONLY', which require data to be present (unless passing $query to C<prepare>).
3136  
3137 See C<prepare> for assignment priority when using CGI query data.
3138  
3139 Returns the number of records currently stored.
3140  
3141 =cut
3142 # for edit groups, add to hidden params
3143 ##at for updates, only 1 record can be updated at a time
3144  
3145 ##at could allow add_record() to accept data for SEARCHABLE groups and add the data to query just like UPDATABLE groups
3146 # this can be done by passing a query to prepare(), which is the preferred way.
3147 sub add_record
3148 0 ▶{
Subroutine add_record: not called CC=5 SCAR=34.0
Pod documented
3149 0 my ($self,$record,$group_name) = @_;
3150 0 my $group;
3151 0 ▶ if (defined($group_name))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $group_name) { } 0 0 0
3152 {
3153 0 $group_name = uc($group_name);
3154 0 $group = $self->{group_hash}{$group_name};
3155 }
3156 else
3157 {
3158 0 $group = $self->current_group();
3159 0 $group_name = $self->current_group_name();
3160 }
3161 0 my $usage = $group->{usage};
3162 0 ▶ if ($usage eq $CGI::AutoForm::EDIT_GROUP)
Branch: 1 branch
BranchTrueFalseTotal
if ($usage eq $CGI::AutoForm::EDIT_GROUP) 0 0 0
3163 {
3164 # add to hidden
3165 0 my ($key,$val);
3166 0 ▶ while (($key,$val) = each(%$record))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$record) 0 0 0
3167 {
3168 0 my $fen = "$group_name.$key";
3169 0 $self->{hidden}{$fen} = $val;
3170 }
3171 }
3172 0 ▶ ref($record) eq 'ARRAY' || ($record = [ $record ]);
Branch: 1 branch
BranchTrueFalseTotal
ref $record eq "ARRAY" or $record = [$record] 0 0 0
3173 0 return push(@{$group->{data}},@$record);
3174 }
3175  
3176 =pod
3177  
3178 =item C<current_record>
3179  
3180 $rec = $form->current_record();
3181  
3182 Return the current record.
3183 If there is no current record, the first one will be returned and curr_rec_no modified.
3184  
3185 =cut
3186 sub current_record
3187 0 ▶{
Subroutine current_record: not called CC=2 SCAR=17.9
Pod documented
3188 0 my ($self) = @_;
3189 0 my $group = $self->current_group();
3190 0 ▶ $self->{curr_rec_no} = 0 if $self->{curr_rec_no} < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"curr_rec_no"} < 0 0 0 0
3191 0 my $i = $self->{curr_rec_no};
3192 0 my $rec = $group->{data}[$i];
3193 0 return $rec;
3194 }
3195  
3196 =pod
3197  
3198 =item C<validate_query>
3199  
3200 $bool = $form->validate_query($query[,$callback]);
3201  
3202 Validate input fields submitted from a form previously
3203 created by this class.
3204 The structure of $query is explained
3205 in C<prepare> except that multi-valued fields are not checked, which should never be used for insert/update groups anyway (notwithstanding
3206 pseudo multi-valued fields packed with C<MULTI_INSERT_DELIMITER>, which WILL be split out and individually validated).
3207  
3208 Numerous checks are done and there is magic to validate input that meets database constraints (if using a db on the backend)
3209 so the operator can correct mistakes instead of just getting a meaningless db error code. For discreet value controls (SELECT box, etc)
3210 this will also confirm submitted values fall withing the list (beware hackers).
3211  
3212 For each field that fails, its VALID_ERROR attribute is set
3213 to an appropriate error message/user hint.
3214 Normally if an error occurs this form would be presented to the user again.
3215 The HTML generated from C<prepare> uses the VALID_ERROR attribute
3216 to set an HTML class name of VALID_ERROR for the field's heading
3217 which is enclosed in a LABEL element so emphasis can be placed through style sheets.
3218 Additionally, the error message is displayed inline with the heading
3219 to give the user a hint of what went wrong.
3220  
3221 $callback is optional and allows you to perform further validation checking; it is used as:
3222  
3223 ($success,$err_message) = &$callback($value,$field,$group,$form,$query);
3224  
3225 Where $success indicates valid input, $err_message is set when the input is invalid
3226 (its use is described above). $value is the value to be verified.
3227 $field is the field sub-object,
3228 $group is the data group sub-object structure.
3229 $form is the form object and $query is a normalized version of the $query originally passed in.
3230  
3231 See CGI::AutoForm::Session for an example implementation.
3232  
3233 =cut
3234  
3235 ##at should the javascript be escaped too?
3236  
3237 # this does not allow multiple record inserts per form group however for search field validation
3238 # fields with multiple values can be assumed to come from a select list, radio or checkbox
3239 # in which case all values are already validated :>
3240 # include header content that will be included in {head_html} saying an error was encountered and to please correct
3241 # only single valued query elements are allowed!
3242 ##at should also validate search forms a db error still might occur from badly formed SQL
3243  
3244 # careful when custom defining your own fields that they don't match the name of a field in the database
3245 # as they will be validated as if they were that field!! (see B<Form field names>)
3246  
3247 sub validate_query
3248 0 ▶{
Subroutine validate_query: not called CC=31 SCAR=69.0
Pod documented
3249 ##at $query should be a refref (or ref for backwards compat) and should be assigned the new normalized query if the caller wants it!!
3250 0 my ($self,$inquery,$callback) = @_;
3251 0 my $query = $self->normalize_query($inquery);
3252 0 my $valid = 1;
3253  
3254 0 foreach my $group (@{$self->{group_list}})
3255 {
3256 0 my $usage = $group->{usage};
3257 ##at may still want to validate if a summary form (some values may have been mangled along the way)
3258 0 ▶ next if $usage eq $CGI::AutoForm::DISPLAY_ONLY_GROUP;
Branch: 1 branch
BranchTrueFalseTotal
if $usage eq $CGI::AutoForm::DISPLAY_ONLY_GROUP 0 0 0
3259 0 foreach my $field (@{$group->{field_list}})
3260 {
3261 0 my $fename = "$group->{group_name}.$field->{FIELD_NAME}";
3262 ##at HASH and ARRAY should be consts assigned by ref({}) and ref([])
3263
3264 0 ▶ if (($usage eq $CGI::AutoForm::INSERT_GROUP && $field->{INSERTABLE} ne 'Y') ||
Branch: 1 branch
BranchTrueFalseTotal
if ($usage eq $CGI::AutoForm::INSERT_GROUP and $field->{"INSERTABLE"} ne "Y" or $usage eq $CGI::AutoForm::EDIT_GROUP and $field->{"UPDATABLE"} ne "Y" or $usage eq $CGI::AutoForm::SEARCH_GROUP and $field->{"SEARCHABLE"} ne "Y") 0 0 0
Condition0%0/15
$usage eq $CGI::AutoForm::INSERT_GROUP and $field->{"INSERTABLE"} ne "Y" or $usage eq $CGI::AutoForm::EDIT_GROUP and $field->{"UPDATABLE"} ne "Y" or $usage eq $CGI::AutoForm::SEARCH_GROUP and $field->{"SEARCHABLE"} ne "Y"
l!l&&r!l&&!r
000
$usage eq $CGI::AutoForm::INSERT_GROUP and $field->{"INSERTABLE"} ne "Y" or $usage eq $CGI::AutoForm::EDIT_GROUP and $field->{"UPDATABLE"} ne "Y"
l!l&&r!l&&!r
000
$usage eq $CGI::AutoForm::INSERT_GROUP and $field->{"INSERTABLE"} ne "Y"
!ll&&!rl&&r
000
$usage eq $CGI::AutoForm::EDIT_GROUP and $field->{"UPDATABLE"} ne "Y"
!ll&&!rl&&r
000
$usage eq $CGI::AutoForm::SEARCH_GROUP and $field->{"SEARCHABLE"} ne "Y"
!ll&&!rl&&r
000
MC/DC0%0/6
$usage eq $CGI::AutoForm::INSERT_GROUP and $field->{"INSERTABLE"} ne "Y" or $usage eq $CGI::AutoForm::EDIT_GROUP and $field->{"UPDATABLE"} ne "Y" or $usage eq $CGI::AutoForm::SEARCH_GROUP and $field->{"SEARCHABLE"} ne "Y"
$usage eq $CGI::AutoForm::INSERT_GROUP $field->{"INSERTABLE"} ne "Y" $usage eq $CGI::AutoForm::EDIT_GROUP $field->{"UPDATABLE"} ne "Y" $usage eq $CGI::AutoForm::SEARCH_GROUP $field->{"SEARCHABLE"} ne "Y"
Truth table0%0/15
A and B or C and D or E and F
A= $usage eq $CGI::AutoForm::INSERT_GROUPB= $field->{"INSERTABLE"} ne "Y"C= $usage eq $CGI::AutoForm::EDIT_GROUPD= $field->{"UPDATABLE"} ne "Y"E= $usage eq $CGI::AutoForm::SEARCH_GROUPF= $field->{"SEARCHABLE"} ne "Y"
ABCDEFresult
11XXXX1
0X11XX1
1011XX1
0X0X111
0X10111
100X111
1010111
0X0X0X0
0X0X100
0X100X0
0X10100
100X0X0
100X100
10100X0
1010100
3265 ($usage eq $CGI::AutoForm::EDIT_GROUP && $field->{UPDATABLE} ne 'Y') ||
3266 ($usage eq $CGI::AutoForm::SEARCH_GROUP && $field->{SEARCHABLE} ne 'Y'))
3267 {
3268 0 my $v = $query->{$fename};
3269 0 ▶ next if !length($v) || $usage eq $CGI::AutoForm::EDIT_GROUP;
Branch: 1 branch
BranchTrueFalseTotal
if not length $v or $usage eq $CGI::AutoForm::EDIT_GROUP 0 0 0
Condition0%0/3
not length $v or $usage eq $CGI::AutoForm::EDIT_GROUP
l!l&&r!l&&!r
000
MC/DC0%0/2
not length $v or $usage eq $CGI::AutoForm::EDIT_GROUP
not length $v $usage eq $CGI::AutoForm::EDIT_GROUP
Truth table0%0/3
not(A) or B
A= not length $vB= $usage eq $CGI::AutoForm::EDIT_GROUP
ABresult
1X1
011
000
3270 0 $valid = 0;
3271 0 delete($inquery->{$fename});
3272 0 warn("Value [$v] should be NULL for field [$fename]");
3273 0 next;
3274 }
3275  
3276 0 my $type = $self->control_type($field);
3277 0 ▶ if ($type eq 'RANGE' || $type eq 'DATERANGE' || $type eq 'DATETRANGE')
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'RANGE' or $type eq 'DATERANGE' or $type eq 'DATETRANGE') { } 0 0 0
elsif ($type eq 'MATCH TEXT' or $type eq 'COMMALIST') { } 0 0 0
elsif ($type eq 'CHECKGROUP') { } 0 0 0
Condition0%0/6
$type eq "RANGE" or $type eq "DATERANGE" or $type eq "DATETRANGE"
l!l&&r!l&&!r
000
$type eq "RANGE" or $type eq "DATERANGE"
l!l&&r!l&&!r
000
MC/DC0%0/3
$type eq "RANGE" or $type eq "DATERANGE" or $type eq "DATETRANGE"
$type eq "RANGE" $type eq "DATERANGE" $type eq "DATETRANGE"
Truth table0%0/4
A or B or C
A= $type eq "RANGE"B= $type eq "DATERANGE"C= $type eq "DATETRANGE"
ABCresult
1XX1
01X1
0011
0000
3278 {
3279 0 my $rs = $query->{"$fename._RS"};
3280 0 my $re = $query->{"$fename._RE"};
3281 0 ▶ if ((length($rs) || length($re)) && !(length($rs) && length($re)))
Branch: 1 branch
BranchTrueFalseTotal
if (length $rs || length $re and not length $rs && length $re) { } 0 0 0
Condition0%0/9
length $rs || length $re and not length $rs && length $re
!ll&&!rl&&r
000
length $rs or length $re
l!l&&r!l&&!r
000
length $rs && length $re
!ll&&!rl&&r
000
MC/DC0%0/4
length $rs || length $re and not length $rs && length $re
length $rs length $re length $rs length $re
Truth table0%0/7
A or B and not(C && D)
A= length $rsB= length $reC= length $rsD= length $re
ABCDresult
00XX0
1X110
01110
1X0X1
1X101
010X1
01101
3282 {
3283 0 $valid = 0;
3284 0 ▶ $field->{VALID_ERROR} = "End range value required" if !length($re);
Branch: 1 branch
BranchTrueFalseTotal
unless length $re 0 0 0
3285 0 ▶ $field->{VALID_ERROR} = "Start range value required" if !length($rs);
Branch: 1 branch
BranchTrueFalseTotal
unless length $rs 0 0 0
3286 }
3287 else
3288 {
3289 0 ▶ ($valid = $self->_validate($field,$rs,$valid,$callback,$group)) &&
Branch: 1 branch
BranchTrueFalseTotal
$valid = $self->_validate($field, $rs, $valid, $callback, $group) and $valid = $self->_validate($field, $re, $valid, $callback, $group) 0 0 0
3290 ($valid = $self->_validate($field,$re,$valid,$callback,$group));
3291 }
3292 }
3293 ▶ elsif ($type eq 'MATCH TEXT' || $type eq 'COMMALIST')
Condition0%0/3
$type eq "MATCH TEXT" or $type eq "COMMALIST"
l!l&&r!l&&!r
000
MC/DC0%0/2
$type eq "MATCH TEXT" or $type eq "COMMALIST"
$type eq "MATCH TEXT" $type eq "COMMALIST"
Truth table0%0/3
A or B
A= $type eq "MATCH TEXT"B= $type eq "COMMALIST"
ABresult
1X1
011
000
3294 {
3295 0 next;
3296 }
3297 elsif ($type eq 'CHECKGROUP')
3298 {
3299 # In a CHECKGROUP values appear in a single string separated by the
3300 # multi_insert_delimiter. Split them out and validate individually.
3301 my $delimiter = $field->{MULTI_INSERT_DELIMITER} ?
3302 $field->{MULTI_INSERT_DELIMITER} :
3303 0 ▶ $CGI::AutoForm::DEFAULT_MULTI_VALUE_DELIMITER;
Branch: 1 branch
BranchTrueFalseTotal
$field->{'MULTI_INSERT_DELIMITER'} ? : 0 0 0
3304  
3305 0 my @values = split $delimiter, $query->{$fename};
3306
3307 # Check for an empty required checkgroup.
3308 0 ▶ if ($field->{REQUIRED} eq 'Y' && scalar(@values) == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($field->{'REQUIRED'} eq 'Y' and scalar @values == 0) { } 0 0 0
Condition0%0/3
$field->{"REQUIRED"} eq "Y" and scalar @values == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$field->{"REQUIRED"} eq "Y" and scalar @values == 0
$field->{"REQUIRED"} eq "Y" scalar @values == 0
Truth table0%0/3
A and B
A= $field->{"REQUIRED"} eq "Y"B= scalar @values == 0
ABresult
0X0
100
111
3309 {
3310 0 $field->{VALID_ERROR} = 'At least one checkbox must be selected';
3311 0 $valid = 0;
3312 }
3313 else
3314 {
3315 0 foreach my $v (@values)
3316 {
3317 0 $valid = $self->_validate($field,$v,$valid,$callback,$group,$query);
3318 0 ▶ last unless $valid;
Branch: 1 branch
BranchTrueFalseTotal
unless $valid 0 0 0
3319 }
3320 }
3321  
3322 }
3323 else
3324 {
3325 0 $valid = $self->_validate($field,$query->{$fename},$valid,$callback,$group,$query);
3326 }
3327 }
3328 }
3329 0 ▶ $self->{valid_error}++ unless $valid;
Branch: 1 branch
BranchTrueFalseTotal
unless $valid 0 0 0
3330 0 return $valid;
3331 }
3332  
3333 # will validate field length against $field->{INPUT_MAXLENGTH} and check if valid values for enumerated list fields ($field->{PICK_HASH}), etc...
3334 sub _validate
3335 0 ▶{
Subroutine _validate: not called CC=23 SCAR=63.1
3336 0 my ($self,$field,$val,$valid,$callback,$group,$query) = @_;
3337 # An empty hashref signals a CONFIRM field error where both fields don't match
3338 0 ▶ if (ref($val) eq 'HASH' && !%$val)
Branch: 3 branches
BranchTrueFalseTotal
if (ref $val eq 'HASH' and not %$val) { } 0 0 0
elsif ($field->{'REQUIRED'} eq 'Y' and not length $val) { } 0 0 0
elsif (length $val and not ref $val) { } 0 0 0
Condition0%0/3
ref $val eq "HASH" and not %$val
!ll&&!rl&&r
000
MC/DC0%0/2
ref $val eq "HASH" and not %$val
ref $val eq "HASH" not %$val
Truth table0%0/3
A and not(B)
A= ref $val eq "HASH"B= not %$val
ABresult
0X0
100
111
3339 {
3340 0 $valid = 0;
3341 0 $field->{VALID_ERROR} = "Input error";
3342 ##at use js to validate these are equal
3343 0 $val = '';
3344 }
3345 ▶ elsif ($field->{REQUIRED} eq 'Y' && !length($val))
Condition0%0/3
$field->{"REQUIRED"} eq "Y" and not length $val
!ll&&!rl&&r
000
MC/DC0%0/2
$field->{"REQUIRED"} eq "Y" and not length $val
$field->{"REQUIRED"} eq "Y" not length $val
Truth table0%0/3
A and not(B)
A= $field->{"REQUIRED"} eq "Y"B= not length $val
ABresult
0X0
100
111
3346 {
3347 0 $valid = 0;
3348 0 $field->{VALID_ERROR} = "Input required";
3349 }
3350 ▶ elsif (length($val) && !ref($val))
Condition0%0/3
length $val and not ref $val
!ll&&!rl&&r
000
MC/DC0%0/2
length $val and not ref $val
length $val not ref $val
Truth table0%0/3
A and not(B)
A= length $valB= not ref $val
ABresult
0X0
100
111
3351 {
3352 0 my $ct = '';
3353 0 eval{ $ct = $group->{table}->column_type($field->{FIELD_NAME}); };
3354 0 my $rv;
3355 0 ▶ if (($rv = ($field->{DATATYPE} ? _verify_datatype($val,$field->{DATATYPE},$field->{_imp_datetype}) : 1)) > 0 &&
Branch: 3 branches
BranchTrueFalseTotal
if (($rv = $field->{'DATATYPE'} ? _verify_datatype($val, $field->{'DATATYPE'}, $field->{'_imp_datetype'}) : 1) > 0 and ref $group->{'table'} && length $ct ? ($rv = $group->{'table'}->verify_datatype($val, $field->{'FIELD_NAME'})) > 0 : 1) { } 0 0 0
$field->{'DATATYPE'} ? : 0 0 0
ref $group->{'table'} && length $ct ? : 0 0 0
Condition0%0/6
($rv = $field->{"DATATYPE"} ? _verify_datatype($val, $field->{"DATATYPE"}, $field->{"_imp_datetype"}) : 1) > 0 and ref $group->{"table"} && length $ct ? ($rv = $group->{"table"}->verify_datatype($val, $field->{"FIELD_NAME"})) > 0 : 1
!ll&&!rl&&r
000
ref $group->{"table"} and length $ct
!ll&&!rl&&r
000
MC/DC0%0/3
($rv = $field->{"DATATYPE"} ? _verify_datatype($val, $field->{"DATATYPE"}, $field->{"_imp_datetype"}) : 1) > 0 and ref $group->{"table"} && length $ct ? ($rv = $group->{"table"}->verify_datatype($val, $field->{"FIELD_NAME"})) > 0 : 1
($rv = $field->{"DATATYPE"} ? _verify_datatype($val, $field->{"DATATYPE"}, $field->{"_imp_datetype"}) : 1) > 0 ref $group->{"table"} length $ct
Truth table0%0/4
A and B and C
A= ($rv = $field->{"DATATYPE"} ? _verify_datatype($val, $field->{"DATATYPE"}, $field->{"_imp_datetype"}) : 1) > 0B= ref $group->{"table"}C= length $ct
ABCresult
0XX0
10X0
1100
1111
3356 ( (ref($group->{table}) && length($ct)) ?
3357 ($rv = $group->{table}->verify_datatype($val,$field->{FIELD_NAME})) > 0 : 1))
3358 {
3359 0 ▶ if ($field->{INPUT_MAXLENGTH} && $field->{INPUT_MAXLENGTH} < length($val))
Branch: 3 branches
BranchTrueFalseTotal
if ($field->{'INPUT_MAXLENGTH'} and $field->{'INPUT_MAXLENGTH'} < length $val) { } 0 0 0
elsif (ref $field->{'PICK_HASH'} and not exists $field->{'PICK_HASH'}{$val}) { } 0 0 0
elsif (ref $callback eq 'CODE') { } 0 0 0
Condition0%0/3
$field->{"INPUT_MAXLENGTH"} and $field->{"INPUT_MAXLENGTH"} < length $val
!ll&&!rl&&r
000
MC/DC0%0/2
$field->{"INPUT_MAXLENGTH"} and $field->{"INPUT_MAXLENGTH"} < length $val
$field->{"INPUT_MAXLENGTH"} $field->{"INPUT_MAXLENGTH"} < length $val
Truth table0%0/3
A and B
A= $field->{"INPUT_MAXLENGTH"}B= $field->{"INPUT_MAXLENGTH"} < length $val
ABresult
0X0
100
111
3360 {
3361 0 $valid = 0;
3362 0 $field->{VALID_ERROR} = "Field value too big.";
3363 }
3364 ▶ elsif (ref($field->{PICK_HASH}) && !exists($field->{PICK_HASH}{$val}))
Condition0%0/3
ref $field->{"PICK_HASH"} and not exists $field->{"PICK_HASH"}{$val}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $field->{"PICK_HASH"} and not exists $field->{"PICK_HASH"}{$val}
ref $field->{"PICK_HASH"} not exists $field->{"PICK_HASH"}{$val}
Truth table0%0/3
A and not(B)
A= ref $field->{"PICK_HASH"}B= not exists $field->{"PICK_HASH"}{$val}
ABresult
0X0
100
111
3365 {
3366 0 $valid = 0;
3367 0 $field->{VALID_ERROR} = "Value submitted not in list of valid values.";
3368 }
3369 elsif (ref($callback) eq 'CODE')
3370 {
3371 ##at should verify that $success is even defined, if not there was an error in attempting to validate
3372 0 my ($success,$err_message) = &$callback($val,$field,$group,$self,$query);
3373 0 ▶ unless ($success)
Branch: 1 branch
BranchTrueFalseTotal
unless ($success) 0 0 0
3374 {
3375 0 $valid = 0;
3376 0 ▶ $field->{VALID_ERROR} = ($err_message ? $err_message : 'ERROR');
Branch: 1 branch
BranchTrueFalseTotal
$err_message ? : 0 0 0
3377 }
3378 }
3379 }
3380 else
3381 {
3382 0 $valid = 0;
3383 0 ▶ if ($rv == 0)
Branch: 4 branches
BranchTrueFalseTotal
if ($rv == 0) { } 0 0 0
elsif ($rv == -1) { } 0 0 0
elsif ($rv == -2) { } 0 0 0
elsif ($rv == -3) { } 0 0 0
3384 {
3385 0 $field->{VALID_ERROR} = "Numeric value required";
3386 }
3387 elsif ($rv == -1)
3388 {
3389 0 $field->{VALID_ERROR} = "Integer value required, no decimals";
3390 }
3391 elsif ($rv == -2)
3392 {
3393 0 $field->{VALID_ERROR} = "Negative value not allowed";
3394 }
3395 elsif ($rv == -3)
3396 {
3397 0 $field->{VALID_ERROR} = "Unrecognized date format";
3398 }
3399 else
3400 {
3401 0 $field->{VALID_ERROR} = "Datatype error";
3402 }
3403 }
3404 }
3405 0 return $valid;
3406 }
3407  
3408 sub _verify_datatype
3409 0 ▶{
Subroutine _verify_datatype: not called CC=10 SCAR=47.0
3410 0 my ($val,$type,$imp) = @_;
3411 0 ▶ my $datetype = $imp || $type;
Condition0%0/3
$imp || $type
l!l&&r!l&&!r
000
MC/DC0%0/2
$imp || $type
$imp $type
Truth table0%0/3
A || B
A= $impB= $type
ABresult
1X1
011
000
3412 0 ▶ if ($type eq 'NUMBER')
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'NUMBER') { } 0 0 0
elsif ($type =~ /INT/) { } 0 0 0
elsif ($datetype eq 'DATETIME' || $datetype eq 'DATE' and not $val =~ /^\d{2,14}$/) { } 0 0 0
3413 {
3414 0 return DBIx::IO::GenLib::isreal($val);
3415 }
3416 elsif ($type =~ /INT/)
3417 {
3418 0 ▶ return -1 unless DBIx::IO::GenLib::isint($val);
Branch: 1 branch
BranchTrueFalseTotal
unless DBIx::IO::GenLib::isint($val) 0 0 0
3419 0 ▶ if ($type =~ /UNSIGNED/)
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /UNSIGNED/) 0 0 0
3420 {
3421 0 ▶ return -2 unless $val > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $val > 0 0 0 0
3422 }
3423 }
3424 ▶ elsif (($datetype eq 'DATETIME' || $datetype eq 'DATE') && $val !~ /^\d{2,14}$/)
Condition0%0/6
$datetype eq "DATETIME" || $datetype eq "DATE" and not $val =~ /^\d{2,14}$/
!ll&&!rl&&r
000
$datetype eq "DATETIME" or $datetype eq "DATE"
l!l&&r!l&&!r
000
MC/DC0%0/3
$datetype eq "DATETIME" || $datetype eq "DATE" and not $val =~ /^\d{2,14}$/
$datetype eq "DATETIME" $datetype eq "DATE" not $val =~ /^\d{2,14}$/
Truth table0%0/5
A or B and not(C)
A= $datetype eq "DATETIME"B= $datetype eq "DATE"C= not $val =~ /^\d{2,14}$/
ABCresult
00X0
1X00
0100
1X11
0111
3425 {
3426 0 return -3;
3427 }
3428 0 return 1;
3429 }
3430  
3431 # Return YYYYMMDDHH24MISS format only (pad with zeros as necessary) unless date can't
3432 # be parsed, in which case, $val is passed back untouched
3433 # if month or day or year are == 0 then return undef
3434  
3435 ##at document that it can accept alternate date forms (YYYYMMDDHH24MISS or D?D-MON-YYYY H?H24:MI:SS)
3436 sub _parse_datetime
3437 0 ▶{
Subroutine _parse_datetime: not called CC=5 SCAR=34.0
3438 0 my ($val) = @_;
3439 0 my $norm_date;
3440 0 ▶ if ($val =~ /^(\d\d\d\d)(\d\d)(\d\d)(?:(\d\d)(\d\d)(\d\d)?)?$/)
Branch: 2 branches
BranchTrueFalseTotal
if ($val =~ /^(\d\d\d\d)(\d\d)(\d\d)(?:(\d\d)(\d\d)(\d\d)?)?$/) { } 0 0 0
elsif ($val =~ /^(\d{1,2})\W([A-Za-z]{3})\W(\d{4})(?:\s+(\d{1,2})\W(\d\d)(?:\W(\d\d))?)?$/) { } 0 0 0
3441 {
3442 0 $norm_date = _norm_date($1,$2,$3,$4,$5,$6,'DATETIME');
3443 }
3444 ##at should affirm the correct days in the month also, leap years, etc.
3445 elsif ($val =~ /^(\d{1,2})\W([A-Za-z]{3})\W(\d{4})(?:\s+(\d{1,2})\W(\d\d)(?:\W(\d\d))?)?$/)
3446 {
3447 0 my $m = uc($2);
3448 0 my $i = '00';
3449 0 foreach my $mon (@months)
3450 {
3451 0 ▶ last if $m eq uc(substr($mon,0,3));
Branch: 1 branch
BranchTrueFalseTotal
if $m eq uc substr($mon, 0, 3) 0 0 0
3452 0 $i++;
3453 }
3454 0 $norm_date = _norm_date($3,$i,$1,$4,$5,$6,'DATETIME');
3455 }
3456 else
3457 {
3458 0 $norm_date = $val;
3459 }
3460 0 return $norm_date;
3461 }
3462  
3463 # if month and day are false then date is null
3464 sub _norm_date
3465 0 ▶{
Subroutine _norm_date: not called CC=14 SCAR=53.5
3466 0 my ($y,$m,$d,$h,$mi,$s,$datetype) = @_;
3467 0 ▶ $datetype ||= 'DATETIME';
Condition0%0/2
$datetype ||= "DATETIME"
l!l
00
MC/DC0%0/1
$datetype ||= "DATETIME"
$datetype
Truth table0%0/2
A
A= $datetype
Aresult
11
00
3468 0 ▶ if ($y == 0 || $m == 0 || $d == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($y == 0 or $m == 0 or $d == 0) 0 0 0
Condition0%0/6
$y == 0 or $m == 0 or $d == 0
l!l&&r!l&&!r
000
$y == 0 or $m == 0
l!l&&r!l&&!r
000
MC/DC0%0/3
$y == 0 or $m == 0 or $d == 0
$y == 0 $m == 0 $d == 0
Truth table0%0/4
A or B or C
A= $y == 0B= $m == 0C= $d == 0
ABCresult
1XX1
01X1
0011
0000
3469 {
3470 0 return undef;
3471 }
3472 0 ▶ $m = "0$m" if (length($m) == 1);
Branch: 1 branch
BranchTrueFalseTotal
if length $m == 1 0 0 0
3473 0 ▶ $d = "0$d" if (length($d) == 1);
Branch: 1 branch
BranchTrueFalseTotal
if length $d == 1 0 0 0
3474 0 ▶ $h = "0$h" if (length($h) == 1);
Branch: 1 branch
BranchTrueFalseTotal
if length $h == 1 0 0 0
3475 0 ▶ $mi = "0$mi" if (length($mi) == 1);
Branch: 1 branch
BranchTrueFalseTotal
if length $mi == 1 0 0 0
3476 0 ▶ $s = "0$s" if (length($s) == 1);
Branch: 1 branch
BranchTrueFalseTotal
if length $s == 1 0 0 0
3477 0 ▶ unless (length($h))
Branch: 1 branch
BranchTrueFalseTotal
unless (length $h) 0 0 0
3478 {
3479 0 $h = '00';
3480 0 $mi = '00';
3481 }
3482 0 ▶ length($s) || ($s = '00');
Branch: 1 branch
BranchTrueFalseTotal
length $s or $s = "00" 0 0 0
3483 0 ▶ return "$y$m$d$h$mi$s" if $datetype eq 'DATETIME';
Branch: 1 branch
BranchTrueFalseTotal
if $datetype eq "DATETIME" 0 0 0
3484 ##at should warn if the time element was > 0 that it will be truncated
3485 0 ▶ return "$y$m$d" if $datetype eq 'DATE';
Branch: 1 branch
BranchTrueFalseTotal
if $datetype eq "DATE" 0 0 0
3486 }
3487  
3488 =pod
3489  
3490 =item C<format_query>
3491  
3492 $formatted_query = $form->format_query($query);
3493  
3494 Class or object method. Normalize and structure input fields
3495 submitted by a form created by this class.
3496 The structure of $query is explained in C<prepare>.
3497  
3498 Convenience method that executes C<normalize_query> and then C<structure_query>
3499 on $query (see those methods for details).
3500  
3501 =cut
3502 sub format_query
3503 0 ▶{
Subroutine format_query: not called CC=1 SCAR=6.9
Pod documented
3504 0 my ($caller,$query) = @_;
3505 0 return $caller->structure_query($caller->normalize_query($query));
3506 }
3507  
3508 sub clean_val
3509 0 ▶{
Subroutine clean_val: not called CC=1 SCAR=6.9
Pod undocumented
3510 0 my ($caller,$val) = @_;
3511 0 $val =~ s/^\s+//;
3512 0 $val =~ s/\s+$//;
3513 0 $val =~ s/\000//g;
3514 0 $val = $caller->unescape($val);
3515 0 return $val;
3516 }
3517  
3518  
3519 # only dates in TEXT and date group form fields will be validated
3520 # dates will ALWAYS be normalized with a time element (this is fine for both DATE and DATETIME types in mysql)
3521  
3522 =pod
3523  
3524 =item C<normalize_query>
3525  
3526 $norm_query = $form->normalize_query($query);
3527  
3528 Class or object method (must use as object method for a non-default multi-value delimiter).
3529  
3530 All date fields will be normalized in the YYYYMMDDHH24MISS format (in Oracle-speak) for
3531 consumption by DBIx::IO::Table and friends (see also DBIx::IO::GenLib).
3532 CONFIRM fields are de-duped and checked for equality. If unequal,
3533 the value will be given as an empty hashref.
3534 All field names are converted to UPPER CASE.
3535 Removes leading and trailing whitespace, remove all NULL chars and removes elements
3536 that have an empty or undefined value.
3537  
3538 Whereas C<format_query> will execute this method AND C<structure_query>, sometimes just this call
3539 is useful to manipulate a query in its normalized form before passing to C<prepare>, which won't accept
3540 a structured query.
3541  
3542 See C<prepare> for the structure of $query.
3543  
3544 =cut
3545 sub normalize_query
3546 0 ▶{
Subroutine normalize_query: not called CC=32 SCAR=69.6
Pod documented
3547 0 my ($caller,$query) = @_;
3548 0 my $new_query = {};
3549 0 my ($key,$val);
3550 0 my %confirm_proc;
3551 0 ▶ while (($key,$val) = each(%$query))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$query) 0 0 0
3552 {
3553 0 ▶ if (ref($val) eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $val eq 'ARRAY') { } 0 0 0
3554 {
3555 0 my @newv;
3556 0 foreach my $v (@$val)
3557 {
3558 0 $v = $caller->clean_val($v);
3559 0 ▶ next unless length($v);
Branch: 1 branch
BranchTrueFalseTotal
unless length $v 0 0 0
3560 0 push(@newv,$v);
3561 }
3562 0 ▶ next unless @newv;
Branch: 1 branch
BranchTrueFalseTotal
unless @newv 0 0 0
3563 0 ▶ $val = (@newv > 1 ? \@newv : $newv[0]);
Branch: 1 branch
BranchTrueFalseTotal
@newv > 1 ? : 0 0 0
3564 }
3565 else
3566 {
3567 0 $val = $caller->clean_val($val);
3568 0 ▶ next unless length($val);
Branch: 1 branch
BranchTrueFalseTotal
unless length $val 0 0 0
3569 }
3570 0 $key = $caller->unescape($key);
3571 0 $key = uc($key);
3572 0 my ($key_pre,$key_pre2,$gname,$fname);
3573 0 ▶ if (($key_pre,$key_pre2,$gname,$fname) = $key =~ /((?:__SDAT\.)?(?:SC\.)?((.*?)\.(.*?))(?:\..*?)?)\._(?:QUANT|UNIT|MONTH|YEAR|DAY|MIN|HOUR)$/)
Branch: 2 branches
BranchTrueFalseTotal
if (() = $key =~ /((?:__SDAT\.)?(?:SC\.)?((.*?)\.(.*?))(?:\..*?)?)\._(?:QUANT|UNIT|MONTH|YEAR|DAY|MIN|HOUR)$/) { } 0 0 0
elsif (($key_pre) = $key =~ /(.*)\._CONFIRM[12]$/) { } 0 0 0
3574 {
3575 0 ▶ next if $new_query->{$key_pre};
Branch: 1 branch
BranchTrueFalseTotal
if $new_query->{$key_pre} 0 0 0
3576  
3577 0 my $quant = $query->{"$key_pre._QUANT"};
3578 0 my $unit = $query->{"$key_pre._UNIT"};
3579  
3580 0 ▶ my $dtype = ref($caller) && ref($caller->field_hash()) ? $caller->field_hash()->{$fname}{_imp_datetype} : undef();
Branch: 1 branch
BranchTrueFalseTotal
ref $caller && ref $caller->field_hash ? : 0 0 0
Condition0%0/3
ref $caller and ref $caller->field_hash
!ll&&!rl&&r
000
MC/DC0%0/2
ref $caller and ref $caller->field_hash
ref $caller ref $caller->field_hash
Truth table0%0/3
A and B
A= ref $callerB= ref $caller->field_hash
ABresult
0X0
100
111
3581  
3582 0 my $start_key = $key_pre;
3583 0 my $end_key = $key_pre;
3584 0 $end_key =~ s/_RS$/_RE/;
3585  
3586 # _QUANT/_UNIT fields take precedence
3587 0 ▶ if (length($quant) || length($unit))
Branch: 1 branch
BranchTrueFalseTotal
if (length $quant or length $unit) 0 0 0
Condition0%0/3
length $quant or length $unit
l!l&&r!l&&!r
000
MC/DC0%0/2
length $quant or length $unit
length $quant length $unit
Truth table0%0/3
A or B
A= length $quantB= length $unit
ABresult
1X1
011
000
3588 {
3589 0 ▶ ($new_query->{$start_key} = $new_query->{$end_key} = {},next) unless length($quant) && length($unit) && DBIx::IO::GenLib::isint($quant);
Branch: 1 branch
BranchTrueFalseTotal
unless length $quant and length $unit and DBIx::IO::GenLib::isint($quant) 0 0 0
Condition0%0/6
length $quant and length $unit and DBIx::IO::GenLib::isint($quant)
!ll&&!rl&&r
000
length $quant and length $unit
!ll&&!rl&&r
000
MC/DC0%0/3
length $quant and length $unit and DBIx::IO::GenLib::isint($quant)
length $quant length $unit DBIx::IO::GenLib::isint($quant)
Truth table0%0/4
A and B and C
A= length $quantB= length $unitC= DBIx::IO::GenLib::isint($quant)
ABCresult
0XX0
10X0
1100
1111
3590  
3591 0 my $factor;
3592  
3593 0 ▶ if ($unit eq 'HRS')
Branch: 5 branches
BranchTrueFalseTotal
if ($unit eq 'HRS') { } 0 0 0
elsif ($unit eq 'DAYS') { } 0 0 0
elsif ($unit eq 'MINS') { } 0 0 0
elsif ($unit eq 'MONTHS') { } 0 0 0
elsif ($unit eq 'YEARS') { } 0 0 0
3594 {
3595 0 $factor = 3600;
3596 }
3597 elsif ($unit eq 'DAYS')
3598 {
3599 0 $factor = 3600 * 24;
3600 }
3601 elsif ($unit eq 'MINS')
3602 {
3603 0 $factor = 60;
3604 }
3605 elsif ($unit eq 'MONTHS')
3606 {
3607 # Estimate
3608 0 $factor = 3600 * 24 * 30;
3609 }
3610 elsif ($unit eq 'YEARS')
3611 {
3612 # Estimate
3613 0 $factor = int(3600 * 24 * 365.25);
3614 }
3615 else
3616 {
3617 0 $new_query->{$start_key} = $new_query->{$end_key} = {}; # Empty hash reference signals an error to validate_query()
3618 0 next;
3619 }
3620  
3621 0 my $enow = time;
3622 0 my $then = $enow - $factor * $quant;
3623  
3624 0 my @t = localtime($then);
3625 0 $new_query->{$start_key} = _norm_date($t[5]+1900,$t[4]+1,@t[3,2,1,0],$dtype);
3626  
3627 0 @t = localtime($enow);
3628 0 $new_query->{$end_key} = _norm_date($t[5]+1900,$t[4]+1,@t[3,2,1,0],$dtype);
3629  
3630 0 next;
3631 }
3632  
3633 0 $val = _norm_date(@{$query}{
3634 0 "$key_pre._YEAR",
3635 "$key_pre._MONTH",
3636 "$key_pre._DAY",
3637 "$key_pre._HOUR",
3638 "$key_pre._MIN",
3639 },
3640 '00',
3641 $dtype
3642 );
3643 0 ▶ $val = {} unless length($val);
Branch: 1 branch
BranchTrueFalseTotal
unless length $val 0 0 0
3644 }
3645 elsif (($key_pre) = $key =~ /(.*)\._CONFIRM[12]$/)
3646 {
3647 0 ▶ next if $confirm_proc{$key_pre};
Branch: 1 branch
BranchTrueFalseTotal
if $confirm_proc{$key_pre} 0 0 0
3648 $val =
3649 ($query->{"$key_pre._CONFIRM1"} eq $query->{"$key_pre._CONFIRM2"} ?
3650 0 ▶ $query->{"$key_pre._CONFIRM1"} :
Branch: 1 branch
BranchTrueFalseTotal
$$query{"$key_pre._CONFIRM1"} eq $$query{"$key_pre._CONFIRM2"} ? : 0 0 0
3651 {}); # Empty hash reference signals an error to validate_query()
3652 0 $confirm_proc{$key_pre}++;
3653 }
3654 else
3655 {
3656 0 $key_pre = $key;
3657 }
3658 0 ▶ if ($key =~ /(.*)\._DT$/)
Branch: 2 branches
BranchTrueFalseTotal
if ($key =~ /(.*)\._DT$/) { } 0 0 0
elsif ($key =~ /((.*)\.(.*))\._CG$/) { } 0 0 0
3659 {
3660 0 ▶ $val = _parse_datetime($val) unless ($val =~ /^\d{14}$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $val =~ /^\d{14}$/ 0 0 0
3661 0 $key_pre = $1;
3662 }
3663 # Checkgroup
3664 # This re match needs to return $1=GROUP.FIELD, $2=GROUP, $3=FIELD
3665 elsif ($key =~ /((.*)\.(.*))\._CG$/)
3666 {
3667  
3668 # It is possible that we have been called as a class
3669 # method, ie $form->normalize_query. If so, we will
3670 # not be able to access the multi-value delimiter defined
3671 # in the form object, so we will use a default.
3672 0 my $delimiter = $CGI::AutoForm::DEFAULT_MULTI_VALUE_DELIMITER;
3673  
3674 0 ▶ if (ref($caller))
Branch: 1 branch
BranchTrueFalseTotal
if (ref $caller) 0 0 0
3675 {
3676 # Need to get the multi-value delimiter. Use the field
3677 # name from the re match to access the field_hash;
3678 0 my $field_name = $3;
3679  
3680 0 my $field_attrs = $caller->field_hash()->{$field_name};
3681  
3682 # If the hash value is not set, use the default.
3683 0 ▶ $delimiter = $field_attrs->{MULTI_INSERT_DELIMITER} if $field_attrs->{MULTI_INSERT_DELIMITER};
Branch: 1 branch
BranchTrueFalseTotal
if $field_attrs->{"MULTI_INSERT_DELIMITER"} 0 0 0
3684 }
3685  
3686 # If $val is an array ref then concat all elements
3687 # together into a single string, joining with the
3688 # multi-value separator. Otherwise just use $val as is.
3689 0 $key_pre = $1;
3690 0 ▶ $val = join($delimiter, @$val) if ref($val) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $val eq "ARRAY" 0 0 0
3691  
3692 }
3693 0 $new_query->{$key_pre} = $val;
3694 }
3695 0 return $new_query;
3696 }
3697  
3698 =pod
3699  
3700 =item C<structure_query>
3701  
3702 $struct_query = CGI::AutoForm->structure_query($query);
3703  
3704 Class or object method.
3705  
3706 The returned $struct_query will be structured like C<$struct_query-E<gt>{group_name}{FIELD_NAME}>
3707 from properly named form fields (see B<Form field names>).
3708 This structure
3709 can facilitate record extraction for each group in the form, e.g. $formatted_query->{group_name}
3710 will give a record available for direct insert using DBIx::IO::Table.
3711  
3712 See C<prepare> for the structure of $query.
3713  
3714 =cut
3715 sub structure_query
3716 0 ▶{
Subroutine structure_query: not called CC=4 SCAR=30.0
Pod documented
3717 0 my ($caller,$query) = @_;
3718 0 my ($key,$val);
3719 0 my $struct_query = {};
3720 0 ▶ while (($key,$val) = each(%$query))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$query) 0 0 0
3721 {
3722 0 my $expr = '$struct_query->';
3723 0 foreach my $word (split(/\W+/,$key))
3724 {
3725 0 $expr .= "{$word}";
3726 }
3727 #$expr .= " = " . (defined($val) ? "'$val'" : 'undef()');
3728 0 $expr .= " = " . '$val';
3729 0 eval($expr);
3730 0 ▶ die($@) if $@; # runtime error so OK to die
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
3731 }
3732 0 return $struct_query;
3733 }
3734  
3735 ##at special column names, eg. _MONTH should be lower case by convention to distinguish from 'real' column names
3736  
3737 =pod
3738  
3739 =item C<clone>
3740  
3741 $form_copy = $form->clone();
3742  
3743 Perform a deep copy of $form.
3744 HTML attributes generated from C<prepare> will not
3745 be copied.
3746  
3747 Useful for caching form objects in environments like mod_perl, see CGI::AutoForm::Session
3748 for an example.
3749  
3750 Return the new object.
3751  
3752 =cut
3753 sub clone
3754 0 ▶{
Subroutine clone: not called CC=8 SCAR=42.8
Pod documented
3755 0 my $self = shift;
3756 0 my $clone = $self->new(@_);
3757 0 foreach my $key (keys(%$self))
3758 {
3759 0 ▶ next if ref($self->{$key});
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{$key} 0 0 0
3760 0 $clone->{$key} = $self->{$key};
3761 }
3762 0 $clone->{group_hash} = {};
3763 0 $clone->{group_list} = [];
3764 0 $clone->{hidden} = {};
3765 0 foreach my $group (@{$self->{group_list}})
3766 {
3767 0 my $clone_group = {};
3768 0 foreach my $key (keys(%$group))
3769 {
3770 0 ▶ next if ref($group->{$key});
Branch: 1 branch
BranchTrueFalseTotal
if ref $group->{$key} 0 0 0
3771 0 $clone_group->{$key} = $group->{$key};
3772 }
3773 0 $clone_group->{field_hash} = {};
3774 0 $clone_group->{field_list} = [];
3775 0 $clone_group->{data} = [];
3776 0 $clone_group->{export_rec} = [];
3777 0 foreach my $field (@{$group->{field_list}})
3778 {
3779 0 my $clone_field = {};
3780 0 foreach my $key (keys(%$field))
3781 {
3782 0 $clone_field->{$key} = $field->{$key};
3783 }
3784 0 push(@{$clone_group->{field_list}},$clone_field);
3785 0 $clone_group->{field_hash}{$clone_field->{FIELD_NAME}} = $clone_field;
3786 }
3787 0 push(@{$clone->{group_list}},$clone_group);
3788 0 $clone->{group_hash}{$clone_group->{group_name}} = $clone_group;
3789 }
3790 0 return $clone;
3791 }
3792  
3793 ##at group_names can NOT have a /\W/ in them (should check and return an appropriate error code)
3794  
3795 =pod
3796  
3797 =item C<extract_query_group>
3798  
3799 $form_fields = CGI::AutoForm->extract_query_group($query,$group_name);
3800  
3801 Object or class method.
3802  
3803 Return a hashref of form field 'E<lt>group_nameE<gt>.E<lt>field_nameE<gt>' => value pairs from a data group named $group_name.
3804 Must use properly named form fields (see B<Form field names>).
3805  
3806 See C<prepare> for the structure of $query.
3807  
3808 =cut
3809 sub extract_query_group
3810 0 ▶{
Subroutine extract_query_group: not called CC=3 SCAR=24.8
Pod documented
3811 0 my ($self,$q,$name) = @_;
3812 0 my ($field,$val);
3813 0 my %nq;
3814 0 $name = quotemeta($name);
3815 0 ▶ while (($field,$val) = each(%$q))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$q) 0 0 0
3816 {
3817 0 ▶ $nq{$field} = $val if $field =~ /\b$name\./;
Branch: 1 branch
BranchTrueFalseTotal
if $field =~ /\b$name\./ 0 0 0
3818 }
3819 0 return \%nq;
3820 }
3821  
3822 =pod
3823  
3824 =item C<extract_cut_query_group>
3825  
3826 $form_fields = CGI::AutoForm->extract_cut_query_group($query,$group_name);
3827  
3828 Object or class method.
3829  
3830 Return a hashref of form field E<lt>field_nameE<gt> => value pairs from a data group named $group_name.
3831 Similar to C<extract_query_group> except the keys of the hashref don't have the E<lt>group_nameE<gt> component.
3832 Must use properly named form fields (see B<Form field names>).
3833  
3834 See C<prepare> for the structure of $query.
3835  
3836 =cut
3837 sub extract_cut_query_group
3838 0 ▶{
Subroutine extract_cut_query_group: not called CC=3 SCAR=24.8
Pod documented
3839 0 my ($self,$q,$name) = @_;
3840 0 my ($field,$val);
3841 0 my %nq;
3842 0 $name = quotemeta($name);
3843 0 ▶ while (($field,$val) = each(%$q))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$q) 0 0 0
3844 {
3845 0 ▶ $nq{$1} = $val if $field =~ /\b$name\.(.*)/;
Branch: 1 branch
BranchTrueFalseTotal
if $field =~ /\b$name\.(.*)/ 0 0 0
3846 }
3847 0 return \%nq;
3848 }
3849  
3850 =pod
3851  
3852 =item C<escape>
3853  
3854 $form_fields = CGI::AutoForm->escape($query,$group_name);
3855  
3856 Object or class method (use the object method invocation with the C<dontescape> attribute).
3857  
3858 Utility method to transform text into an HTML compatible format by escaping (encoding) certain characters with HTML entities.
3859 Ignored if $form->{dontescape} is TRUE.
3860  
3861 =cut
3862 sub escape
3863 0 ▶{
Subroutine escape: not called CC=6 SCAR=37.4
Pod documented
3864 0 my ($self,$toencode,$newlinestoo) = @_;
3865 0 ▶ return undef unless defined($toencode);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $toencode 0 0 0
3866 0 ▶ return $toencode if ref($self) && $self->{'dontescape'};
Branch: 1 branch
BranchTrueFalseTotal
if ref $self and $self->{"dontescape"} 0 0 0
Condition0%0/3
ref $self and $self->{"dontescape"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $self and $self->{"dontescape"}
ref $self $self->{"dontescape"}
Truth table0%0/3
A and B
A= ref $selfB= $self->{"dontescape"}
ABresult
0X0
100
111
3867 0 $toencode =~ s{&}{&amp;}gso;
3868 0 $toencode =~ s{<}{&lt;}gso;
3869 0 $toencode =~ s{>}{&gt;}gso;
3870 0 $toencode =~ s{"}{&quot;}gso;
3871  
3872 # bug in some browsers
3873 0 $toencode =~ s{'}{&#39;}gso;
3874 0 $toencode =~ s{\x8b}{&#139;}gso;
3875 0 $toencode =~ s{\x9b}{&#155;}gso;
3876 0 ▶ if (defined $newlinestoo && $newlinestoo) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $newlinestoo and $newlinestoo) 0 0 0
Condition0%0/3
defined $newlinestoo and $newlinestoo
!ll&&!rl&&r
000
MC/DC0%0/2
defined $newlinestoo and $newlinestoo
defined $newlinestoo $newlinestoo
Truth table0%0/3
A and B
A= defined $newlinestooB= $newlinestoo
ABresult
0X0
100
111
3877 0 $toencode =~ s{\012}{&#10;}gso;
3878 0 $toencode =~ s{\015}{&#13;}gso;
3879 }
3880 0 return $toencode;
3881 }
3882  
3883 =pod
3884  
3885 =item C<unescape>
3886  
3887 $form_fields = CGI::AutoForm->unescape($query,$group_name);
3888  
3889 Object or class method (use the object method invocation with the C<dontunescape> attribute).
3890  
3891 Utility method to reverse the transformation of C<escape>.
3892 Ignored if $form->{dontunescape} is TRUE.
3893  
3894 =cut
3895 sub unescape
3896 0 ▶{
Subroutine unescape: not called CC=12 SCAR=50.5
Pod documented
3897 0 my ($self,$string) = @_;
3898 0 ▶ return undef unless defined($string);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string 0 0 0
3899 0 ▶ return $string if ref($self) && $self->{dontunescape};
Branch: 1 branch
BranchTrueFalseTotal
if ref $self and $self->{"dontunescape"} 0 0 0
Condition0%0/3
ref $self and $self->{"dontunescape"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $self and $self->{"dontunescape"}
ref $self $self->{"dontunescape"}
Truth table0%0/3
A and B
A= ref $selfB= $self->{"dontunescape"}
ABresult
0X0
100
111
3900  
3901 0 my $latin = 1;#defined $self->{'.charset'} ? $self->{'.charset'} =~ /^(ISO-8859-1|WINDOWS-1252)$/i : 1;
3902 # thanks to Randal Schwartz for the correct solution to this one
3903 0 $string=~ s[&(.*?);]{
3904 0 local $_ = $1;
3905 0 ▶ /^amp$/i ? "&" :
Branch: 6 branches
BranchTrueFalseTotal
/^amp$/i ? : 0 0 0
/^quot$/i ? : 0 0 0
/^gt$/i ? : 0 0 0
/^lt$/i ? : 0 0 0
/^#(\d+)$/ && $latin ? : 0 0 0
/^#x([0-9a-f]+)$/i && $latin ? : 0 0 0
Condition0%0/6
/^#(\d+)$/ and $latin
!ll&&!rl&&r
000
/^#x([0-9a-f]+)$/i and $latin
!ll&&!rl&&r
000
MC/DC0%0/2
/^#(\d+)$/ and $latin
/^#(\d+)$/ $latin
MC/DC0%0/2
/^#x([0-9a-f]+)$/i and $latin
/^#x([0-9a-f]+)$/i $latin
Truth table0%0/3
A and B
A= /^#(\d+)$/B= $latin
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= /^#x([0-9a-f]+)$/iB= $latin
ABresult
0X0
100
111
3906 /^quot$/i ? '"' :
3907 /^gt$/i ? ">" :
3908 /^lt$/i ? "<" :
3909 /^#(\d+)$/ && $latin ? chr($1) :
3910 /^#x([0-9a-f]+)$/i && $latin ? chr(hex($1)) :
3911 $_
3912 }gex;
3913 0 return $string;
3914 }
3915  
3916 =pod
3917  
3918 =back
3919  
3920 =cut
3921  
3922  
3923 1 1;
3924  
3925 __END__
↑ Summary AutoForm/Session.pm »