| 1 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | HTML::FormEngine::DBSQL::SkinClassic - the standard FormEngine::DBSQL skin | ||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||
| 5 | =head1 ABOUT | ||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | This is the default skin of FormEngine::DBSQL. It is based on the skin | ||||||||||||||||||||||||||||||||
| 8 | class HTML::FormEngine::SkinClassic. | ||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | Please read its source code for more ;) | ||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | =cut | ||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | ###################################################################### | ||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | package HTML::FormEngine::DBSQL::SkinClassic; | ||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use vars qw(@ISA); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use HTML::FormEngine::SkinClassic; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 21 | 1 | @ISA = qw(HTML::FormEngine::SkinClassic); | |||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | ###################################################################### | ||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | sub get_dbsql_secret { | ||||||||||||||||||||||||||||||
|
Subroutine
get_dbsql_secret: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 26 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 27 | 0 | return $self->{dbsql_secret}; | |||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | ###################################################################### | ||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | =head1 METHODS | ||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | =head2 set_dbsql_secret ( SECRET ) | ||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||
| 36 | If you want to update records, you can use the C<dbsql_update> method | ||||||||||||||||||||||||||||||||
| 37 | of L<HTML::FormEngine::DBSQL> That method uses the given values of the | ||||||||||||||||||||||||||||||||
| 38 | primary key to create where conditions, so that the right records are | ||||||||||||||||||||||||||||||||
| 39 | updated. The weak point is, that someone could corrupt the input data, | ||||||||||||||||||||||||||||||||
| 40 | so that the primary key values are changed and the wrong records are | ||||||||||||||||||||||||||||||||
| 41 | updated. To prevent this, for every record a extra hidden field is | ||||||||||||||||||||||||||||||||
| 42 | created which contains the md5 sum of the primary key concatenated | ||||||||||||||||||||||||||||||||
| 43 | with a secret string. So it is recognized if a primary key value was | ||||||||||||||||||||||||||||||||
| 44 | changed (because the newly created md5 sum won't match the submitted | ||||||||||||||||||||||||||||||||
| 45 | md5 sum). | ||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | With this method you can set the secret string. By default it is set | ||||||||||||||||||||||||||||||||
| 48 | to NULL, which means that calling C<dbsql_conf> will raise an | ||||||||||||||||||||||||||||||||
| 49 | error. For security reason an update isn't allowed without a secret | ||||||||||||||||||||||||||||||||
| 50 | string, except you pass false (0) to the C<dbsql_set_hide_pkey> method | ||||||||||||||||||||||||||||||||
| 51 | of L<HTML::FormEngine::DBSQL>, which will allow changing the primary | ||||||||||||||||||||||||||||||||
| 52 | key and so no secret string will be needed. | ||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | Another possibilty is changing the value of C<dbsql_secret> in the | ||||||||||||||||||||||||||||||||
| 55 | C<_init_child> method of this package. By that you would set a valid | ||||||||||||||||||||||||||||||||
| 56 | default secret string. But be careful, someone might just edit | ||||||||||||||||||||||||||||||||
| 57 | SkinClassic.pm and so get the secret string, whereas using diffrent | ||||||||||||||||||||||||||||||||
| 58 | keys in your scripts is much more secure. | ||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | It is recommended that you set the read permissions of scripts which | ||||||||||||||||||||||||||||||||
| 61 | define secret keys as restrictive as possible. For cgi scripts this | ||||||||||||||||||||||||||||||||
| 62 | means, that only the webserver user (mostly I<nobody> or I<www-data>) | ||||||||||||||||||||||||||||||||
| 63 | must be able to read them. | ||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | =cut | ||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | ###################################################################### | ||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | sub set_dbsql_secret { | ||||||||||||||||||||||||||||||
|
Subroutine
set_dbsql_secret: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 70 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 71 | 0 | $self->{dbsql_secret} = shift; | |||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | ###################################################################### | ||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | =head2 get_dbsql_dthandler ( NAME ) | ||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||
| 78 | Returns a reference on the datatype handler with the given name. If | ||||||||||||||||||||||||||||||||
| 79 | name is not given a hash reference with all datatype handlers is | ||||||||||||||||||||||||||||||||
| 80 | returned. | ||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | =cut | ||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||
| 84 | ###################################################################### | ||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub get_dbsql_dthandler { | ||||||||||||||||||||||||||||||
|
Subroutine
get_dbsql_dthandler: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 87 | 0 | my($self, $name) = @_; | |||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | return $self->{dbsql_dthandler}->{$name} if($name); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 89 | 0 | return $self->{dbsql_dthandler}; | |||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | ###################################################################### | ||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | =head2 set_dbsql_dthandler ( HASHREF ) | ||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||
| 96 | Expects a hash reference with the handler names as keys and the | ||||||||||||||||||||||||||||||||
| 97 | referenced handler functions as elements. It overwrites the current | ||||||||||||||||||||||||||||||||
| 98 | dthandler settings completly, its not recommended to use this method. | ||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | =cut | ||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | ###################################################################### | ||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | sub set_dbsql_dthandler { | ||||||||||||||||||||||||||||||
|
Subroutine
set_dbsql_dthandler: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 105 | 0 | my($self, $dthandler) = @_; | |||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | $self->{dbsql_dthandler} = $dthandler and return 1 if(ref($dthandler) eq 'HASH'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
ref $dthandler eq 'HASH' && (($self->{'dbsql_dthandler'} = $dthandler) && (return 1))
$self->{"dbsql_dthandler"} = $dthandler and return 1
MC/DC0%0/2
ref $dthandler eq 'HASH' && (($self->{'dbsql_dthandler'} = $dthandler) && (return 1))
ref $dthandler eq 'HASH'
$self->{"dbsql_dthandler"} = $dthandler
Truth table0%0/3
A && B
A= ref $dthandler eq 'HASH'B= $self->{"dbsql_dthandler"} = $dthandler
| |||||||||||||||||||||||||||||||||
| 107 | 0 | return 0; | |||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||
| 110 | ###################################################################### | ||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||
| 112 | =head2 alter_dbsql_dthandler ( HASHREF ) | ||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||
| 114 | Expects a hash reference like L<set_dbsql_dthandler ( HASHREF )> but | ||||||||||||||||||||||||||||||||
| 115 | instead of overwriting all settings it just updates the settings. | ||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||
| 117 | =cut | ||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||
| 119 | ###################################################################### | ||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | sub alter_dbsql_dthandler { | ||||||||||||||||||||||||||||||
|
Subroutine
alter_dbsql_dthandler: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 122 | 0 | my($self, $dthandler) = @_; | |||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | $self->{default} = merge($dthandler, $self->{dbsql_dthandler}) and return 1 if(ref($dthandler) eq 'HASH'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
ref $dthandler eq 'HASH' && (($self->{'default'} = merge($dthandler, $self->{'dbsql_dthandler'})) && (return 1))
$self->{"default"} = merge($dthandler, $self->{"dbsql_dthandler"}) and return 1
MC/DC0%0/2
ref $dthandler eq 'HASH' && (($self->{'default'} = merge($dthandler, $self->{'dbsql_dthandler'})) && (return 1))
ref $dthandler eq 'HASH'
$self->{"default"} = merge($dthandler, $self->{"dbsql_dthandler"})
Truth table0%0/3
A && B
A= ref $dthandler eq 'HASH'B= $self->{"default"} = merge($dthandler, $self->{"dbsql_dthandler"})
| |||||||||||||||||||||||||||||||||
| 124 | 0 | return 0; | |||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||
| 127 | #################### | ||||||||||||||||||||||||||||||||
| 128 | # INTERNAL METHODS # | ||||||||||||||||||||||||||||||||
| 129 | #################### | ||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | sub _init_child { | ||||||||||||||||||||||||||||||
|
Subroutine
_init_child: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 132 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 133 | 0 | $self->{dbsql_dthandler} = $self->_get_dbsql_dthandler; | |||||||||||||||||||||||||||||||
| 134 | 0 | $self->{dbsql_secret} = ''; | |||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | sub _get_dbsql_dthandler { | ||||||||||||||||||||||||||||||
|
Subroutine
_get_dbsql_dthandler: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 138 | 0 | require HTML::FormEngine::DBSQL::DtHandler; | |||||||||||||||||||||||||||||||
| 139 | 0 | my %dbsql_dthandler; | |||||||||||||||||||||||||||||||
| 140 | 0 | $dbsql_dthandler{default} = \&HTML::FormEngine::DBSQL::DtHandler::_dbsql_dthandle_string; | |||||||||||||||||||||||||||||||
| 141 | 0 | $dbsql_dthandler{boolean} = \&HTML::FormEngine::DBSQL::DtHandler::_dbsql_dthandle_bool; | |||||||||||||||||||||||||||||||
| 142 | 0 | $dbsql_dthandler{integer} = \&HTML::FormEngine::DBSQL::DtHandler::_dbsql_dthandle_integer; | |||||||||||||||||||||||||||||||
| 143 | 0 | $dbsql_dthandler{date} = \&HTML::FormEngine::DBSQL::DtHandler::_dbsql_dthandle_date; | |||||||||||||||||||||||||||||||
| 144 | 0 | $dbsql_dthandler{text} = \&HTML::FormEngine::DBSQL::DtHandler::_dbsql_dthandle_text; | |||||||||||||||||||||||||||||||
| 145 | 0 | return \%dbsql_dthandler; | |||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | sub _get_templ { | ||||||||||||||||||||||||||||||
|
Subroutine
_get_templ: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 149 | 0 | my %skin = %{HTML::FormEngine::SkinClassic::_get_templ(@_)}; | |||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||
| 151 | 0 | $skin{body} = ' | |||||||||||||||||||||||||||||||
| 152 | <td colspan=3> | ||||||||||||||||||||||||||||||||
| 153 | <table border=0 summary=""><~ | ||||||||||||||||||||||||||||||||
| 154 | <tr><&TEMPL&></tr>~TEMPL~> | ||||||||||||||||||||||||||||||||
| 155 | </table> | ||||||||||||||||||||||||||||||||
| 156 | <~<&HIDDEN&>~HIDDEN~> | ||||||||||||||||||||||||||||||||
| 157 | </td> | ||||||||||||||||||||||||||||||||
| 158 | '; | ||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||
| 160 | 0 | $skin{row} = ' | |||||||||||||||||||||||||||||||
| 161 | <td valign="top"><&ROWNUM&>. </td><~ | ||||||||||||||||||||||||||||||||
| 162 | <td> | ||||||||||||||||||||||||||||||||
| 163 | <table border=0 cellspacing=0 cellpadding=0> | ||||||||||||||||||||||||||||||||
| 164 | <tr><&TEMPL&></tr> | ||||||||||||||||||||||||||||||||
| 165 | </table> | ||||||||||||||||||||||||||||||||
| 166 | </td>~TEMPL~> | ||||||||||||||||||||||||||||||||
| 167 | <~<&HIDDEN&>~HIDDEN~>'; | ||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||
| 169 | 0 | $skin{title} = ' | |||||||||||||||||||||||||||||||
| 170 | <td valign="top"></td><~ | ||||||||||||||||||||||||||||||||
| 171 | <td align="center"><&TITLE&></td>~TITLE~>'; | ||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||
| 173 | 0 | $skin{errmsg} = ' | |||||||||||||||||||||||||||||||
| 174 | <td colspan=3 style="color:#FF0000"> | ||||||||||||||||||||||||||||||||
| 175 | <&#gettext Error&>:<br> | ||||||||||||||||||||||||||||||||
| 176 | <&ERRMSG&> | ||||||||||||||||||||||||||||||||
| 177 | </td> | ||||||||||||||||||||||||||||||||
| 178 | '; | ||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||
| 180 | 0 | $skin{sqlerr} = ' | |||||||||||||||||||||||||||||||
| 181 | <td colspan=3 style="color:#FF0000"> | ||||||||||||||||||||||||||||||||
| 182 | <&#gettext SQL failure&>:<br> | ||||||||||||||||||||||||||||||||
| 183 | <i><&ERRMSG&></i><br> | ||||||||||||||||||||||||||||||||
| 184 | <&#gettext Error number&>: <i><&ERRNUM&></i><br> | ||||||||||||||||||||||||||||||||
| 185 | <&#gettext Statement was&>:<br> | ||||||||||||||||||||||||||||||||
| 186 | <i><&SQLSTAT&></i> | ||||||||||||||||||||||||||||||||
| 187 | </td> | ||||||||||||||||||||||||||||||||
| 188 | '; | ||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||
| 190 | 0 | $skin{empty} = ' | |||||||||||||||||||||||||||||||
| 191 | <td colspan=3> </td> | ||||||||||||||||||||||||||||||||
| 192 | '; | ||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||
| 194 | 0 | $skin{dbsql_hidden} = '<~<~<&#seperate&><input type="hidden" name="<&NAME&>" value="<&#value&>" />~NAME VALUE MAXLEN SIZE POSTFIX SUBTITLE ERROR_IN ID ACCESSKEY READONLY~>~NAME VALUE MAXLEN SIZE POSTFIX SUBTITLE ERROR_IN ID ACCESSKEY READONLY~><&#seperate ,1&>'; | |||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||
| 196 | 0 | return \%skin; | |||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | sub _get_checks { | ||||||||||||||||||||||||||||||
|
Subroutine
_get_checks: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 200 | 0 | my %checks = %{HTML::FormEngine::SkinClassic::_get_checks}; | |||||||||||||||||||||||||||||||
| 201 | 0 | require HTML::FormEngine::DBSQL::Checks; | |||||||||||||||||||||||||||||||
| 202 | 0 | $checks{dbsql_unique} = \&HTML::FormEngine::DBSQL::Checks::_dbsql_check_unique; | |||||||||||||||||||||||||||||||
| 203 | 0 | return \%checks; | |||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | sub _get_confirm_skin { | ||||||||||||||||||||||||||||||
|
Subroutine
_get_confirm_skin: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 207 | 0 | require HTML::FormEngine::DBSQL::SkinClassicConfirm; | |||||||||||||||||||||||||||||||
| 208 | 0 | return new HTML::FormEngine::DBSQL::SkinClassicConfirm; | |||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||
| 211 | 1 | 1; | |||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||
| 213 | __END__ | ||||||||||||||||||||||||||||||||