| 1 | #!perl -w | ||
| 2 | # | ||
| 3 | # CGI::Bus::tm - database Transaction page Manager to view and edit data | ||
| 4 | # | ||
| 5 | # admiral | ||
| 6 | # | ||
| 7 | # | ||
| 8 | |||
| 9 | package CGI::Bus::tm; | ||
| 10 | require 5.000; | ||
| 11 | use strict; | ||
| 12 | use CGI::Carp qw(fatalsToBrowser warningsToBrowser); | ||
| 13 | use CGI::Bus::Base; | ||
| 14 | use vars qw(@ISA); | ||
| 15 | @ISA =qw(CGI::Bus::Base); | ||
| 16 | |||
| 17 | my %img = | ||
| 18 | (-lgn=>'small/key.gif' # small/key link | ||
| 19 | ,-nap=>'portal.gif' # portal hand.up up | ||
| 20 | ,-nup=>'hand.up.gif' # hand.up up | ||
| 21 | ,-nth=>'script.gif' | ||
| 22 | ,-bck=>'back.gif' # back left | ||
| 23 | ,-lst=>'text.gif' | ||
| 24 | ,-lsr=>'text.gif' | ||
| 25 | ,-qry=>'index.gif' | ||
| 26 | ,-crt=>'generic.gif' # generic c burst | ||
| 27 | ,-sel=>'up.gif' # forward up | ||
| 28 | ,-prn=>'p.gif' # | ||
| 29 | ,-edt=>'quill.gif' # quill image1 | ||
| 30 | ,-frm=>'forward.gif' # f layout forward continued | ||
| 31 | ,-upd=>'down.gif' # quill down | ||
| 32 | ,-del=>'broken.gif' # bomb broken | ||
| 33 | ,-ins=>'burst.gif' | ||
| 34 | ,-hlp=>'unknown.gif' | ||
| 35 | ); | ||
| 36 | # %img =(); # !!! comment to turn off toolbar image buttons !!! | ||
| 37 | |||
| 38 | 1; | ||
| 39 | |||
| 40 | |||
| 41 | |||
| 42 | sub new { | ||
| 43 | my $c=shift; | ||
| 44 | my $s ={}; | ||
| 45 | bless $s,$c; | ||
| 46 | $s =$s->CGI::Bus::Base::initialize(@_); | ||
| 47 | $s->parent->set('-reset')->{'-' .$s->classt}=1 if $s->parent; | ||
| 48 | $s =$s->initialize(@_); | ||
| 49 | } | ||
| 50 | |||
| 51 | |||
| 52 | sub initialize { | ||
| 53 | my $s =shift; | ||
| 54 | %$s =( # Actual slots | ||
| 55 | ## Predefined for children only | ||
| 56 | # ----------------------- | ||
| 57 | -cmd =>undef # Transaction command | ||
| 58 | #,-cmdg =>undef # Generic Transaction command (exclude -frm -ins -upd) | ||
| 59 | #,-cmdc =>undef # Transaction command cached by cnd | ||
| 60 | #,-cmde =>undef # Transaction edit mode | ||
| 61 | |||
| 62 | ,-pxcb =>'_tcb_' # Transaction command or button prefix | ||
| 63 | ,-pxsw =>'_tsw_' # Special widget prefix | ||
| 64 | ,-pxpv =>'_tpv_' # Previous value parameter prefix for -upd | ||
| 65 | ,-pxqc =>'_tqc_' # Query condition parameter prefix for save by -lst | ||
| 66 | |||
| 67 | #,-cnd =>undef # Transaction condition string | ||
| 68 | |||
| 69 | #,-tbarl =>undef # ToolBar Left | ||
| 70 | #,-tbarr =>undef # ToolBar Right | ||
| 71 | |||
| 72 | #,-opflg =>undef # Operations allowed: '<','a'll,'c'reate,'e'dit,'v'iew,'l'ist,'q'uery,'i'nsert,'u'pdate,'d'elete,'s'elect | ||
| 73 | # -form =>undef ## Data form description | ||
| 74 | #,-fields =>undef ## Fields from Form, by _formarrange() | ||
| 75 | #,-keyfld =>undef ## Key field (for versioning and file store) | ||
| 76 | #,-ftext =>undef ## Full-text search expression template | ||
| 77 | #,-formtgf=>undef # Form Target Frame: '_BLANK', '', undef | ||
| 78 | #,-lists =>undef # Data views description | ||
| 79 | ,-listrnm=>256 ## View Rows Number Default Margin | ||
| 80 | ,-lboxrnm=>1024 ## Listbox Rows Number Margin | ||
| 81 | #,-filter =>undef ## Data filter string or sub | ||
| 82 | #,-fltsel =>undef ## Select filter string or sub | ||
| 83 | #,-fltlst =>undef ## List filter string or sub | ||
| 84 | #,-fltedt =>undef ## Edit filter string or sub | ||
| 85 | #,-rowlst =>undef ## Row Listing filter | ||
| 86 | #,-rowsel =>undef # Row Select to view allow | ||
| 87 | #,-rowedt =>undef # Row Edit mode allow | ||
| 88 | #,-rowsav =>undef ## Row Save allow | ||
| 89 | #,-rowsav1=>undef ## Row Save allow before SQL for edited record | ||
| 90 | #,-rowsav2=>undef ## Row Save allow before each SQL | ||
| 91 | #,-rowins =>undef ## Row Insert allow | ||
| 92 | #,-rowupd =>undef ## Row Update allow | ||
| 93 | #,-rowdel =>undef ## Row Delete allow | ||
| 94 | |||
| 95 | #,-vsd =>undef ## Version Store Definition | ||
| 96 | #,-fsd =>undef ## File Store Definition | ||
| 97 | #,-acd =>undef ## Access Control Definition | ||
| 98 | |||
| 99 | #,-htmlts =>undef # HTML table start for form or view, default is <table> | ||
| 100 | #,-htmlte =>undef # HTML table end for form or view, default is </table> | ||
| 101 | #,-width =>undef # HTML table width for form or view, default is window width | ||
| 102 | |||
| 103 | #,-gensel =>undef ## Generated SQL Select | ||
| 104 | #,-genlstm=>undef ## Genetared SQL Select List Message | ||
| 105 | #,-genedt =>undef ## Generated SQL Insert | Update | Delete | ||
| 106 | #,-genwhr =>undef ## Generated Where | ||
| 107 | #,-genfrom=>undef ## Generated From | ||
| 108 | |||
| 109 | ); | ||
| 110 | $s->set(@_); | ||
| 111 | $s | ||
| 112 | } | ||
| 113 | |||
| 114 | |||
| 115 | sub set { | ||
| 116 | return(keys(%{$_[0]})) if scalar(@_) ==1; | ||
| 117 | return($_[0]->{$_[1]}) if scalar(@_) ==2; | ||
| 118 | my ($s, %opt) =@_; | ||
| 119 | foreach my $k (keys(%opt)) { | ||
| 120 | $s->{$k} =$opt{$k}; | ||
| 121 | } | ||
| 122 | $s->_setform if $opt{-form}; | ||
| 123 | $s->_setlists if $opt{-lists}; | ||
| 124 | $s | ||
| 125 | } | ||
| 126 | |||
| 127 | |||
| 128 | sub _setform { # Arrange Form | ||
| 129 | my $s =shift; | ||
| 130 | $s->{-fields} ={}; | ||
| 131 | my ($st, $sta); | ||
| 132 | my $lng =$s->lngname; | ||
| 133 | my $lngl ='-lbl' .($lng ? "_$lng" : ''); | ||
| 134 | my $lngc ='-cmt' .($lng ? "_$lng" : ''); | ||
| 135 | foreach my $f (@{$s->{-form}}) { | ||
| 136 | next if !ref($f) || ref($f) eq 'CODE' ||!$f->{-fld}; | ||
| 137 | $s->{-fields}->{$f->{-fld}} =$f; | ||
| 138 | if ($lng) { | ||
| 139 | $f->{-lbl} =$f->{$lngl} if $f->{$lngl}; | ||
| 140 | $f->{-cmt} =$f->{$lngc} if $f->{$lngc}; | ||
| 141 | } | ||
| 142 | } | ||
| 143 | $s | ||
| 144 | } | ||
| 145 | |||
| 146 | |||
| 147 | sub _setlists { # Arrange Lists | ||
| 148 | my $s =shift; | ||
| 149 | my $lng =$s->lngname; | ||
| 150 | my $lngl ='-lbl' .($lng ? "_$lng" : ''); | ||
| 151 | my $lngn ='-lst' .($lng ? "_$lng" : ''); | ||
| 152 | my $lngc ='-cmt' .($lng ? "_$lng" : ''); | ||
| 153 | return if !$lng; | ||
| 154 | foreach my $f (values %{$s->{-lists}}) { | ||
| 155 | next if !ref($f) || ref($f) eq 'CODE'; | ||
| 156 | if ($lng) { | ||
| 157 | $f->{-lbl} =$f->{$lngl} if $f->{$lngl}; | ||
| 158 | $f->{-lst} =$f->{$lngn} if $f->{$lngn}; | ||
| 159 | $f->{-cmt} =$f->{$lngc} if $f->{$lngc}; | ||
| 160 | } | ||
| 161 | } | ||
| 162 | $s | ||
| 163 | } | ||
| 164 | |||
| 165 | |||
| 166 | |||
| 167 | ################################### | ||
| 168 | # UTILITY METHODS | ||
| 169 | ################################### | ||
| 170 | |||
| 171 | |||
| 172 | sub _img { | ||
| 173 | $_[0]->parent->{-iurl} && $img{$_[1]} | ||
| 174 | ? ('<img src="' .$_[0]->parent->{-iurl} .'/' .$img{$_[1]} .'" alt="" border=0 />') | ||
| 175 | : '' | ||
| 176 | } | ||
| 177 | |||
| 178 | sub pxnme { # Prefixed Name | ||
| 179 | $_[0]->{$_[1]} .(substr($_[2],0,1) eq '-' ? substr($_[2],1) : $_[2]) | ||
| 180 | } | ||
| 181 | |||
| 182 | sub pxcb { # Command button name | ||
| 183 | shift->pxnme(-pxcb=>@_) | ||
| 184 | } | ||
| 185 | |||
| 186 | sub pxsw { # Special widget name | ||
| 187 | shift->pxnme(-pxsw=>@_) | ||
| 188 | } | ||
| 189 | |||
| 190 | sub pxpv { # Previous value name | ||
| 191 | shift->pxnme(-pxpv=>@_) | ||
| 192 | } | ||
| 193 | |||
| 194 | sub pxqc { # Query condition name | ||
| 195 | shift->pxnme(-pxqc=>@_) | ||
| 196 | } | ||
| 197 | |||
| 198 | sub qparamsw { # Special widget value | ||
| 199 | $_[0]->parent->qparam( | ||
| 200 | ref($_[1]) eq 'ARRAY' | ||
| 201 | ? [map {$_[0]->pxnme(-pxsw=>$_)} @{$_[1]}] | ||
| 202 | : $_[0]->pxnme(-pxsw=>$_[1]) | ||
| 203 | ,@_[2..$#_]) | ||
| 204 | } | ||
| 205 | |||
| 206 | sub qparampv { # Query param previous value | ||
| 207 | $_[0]->parent->qparam( | ||
| 208 | ref($_[1]) eq 'ARRAY' | ||
| 209 | ? [map {$_[0]->pxnme(-pxpv=>$_)} @{$_[1]}] | ||
| 210 | : $_[0]->pxnme(-pxpv=>$_[1]) | ||
| 211 | ,@_[2..$#_]) | ||
| 212 | } | ||
| 213 | |||
| 214 | |||
| 215 | sub qparampx { # Prefixed query parameters | ||
| 216 | my $s =shift; | ||
| 217 | my $px =shift; # param name prefix | ||
| 218 | $px =!defined($px) ? '' | ||
| 219 | : substr($px,0,1) eq '-' ? ($s->{$px} ||$px) | ||
| 220 | : $px; | ||
| 221 | if (!defined($_[0])) {} | ||
| 222 | elsif (ref($_[0]) eq 'ARRAY') {return $s->parent->qparam([map {$px .$_} @{$_[0]}], @_[1..$#_])} | ||
| 223 | elsif (ref($_[0]) eq 'HASH') {return $s->parent->qparam({map {$px .$_ => $_[0]->{$_}} keys %{$_[0]}}, @_[1..$#_])} | ||
| 224 | else {return $s->parent->qparam($px .$_[0], @_[1..$#_])} | ||
| 225 | my $r =[]; | ||
| 226 | foreach my $e ($s->cgi->param) { | ||
| 227 | next if $px ne '' ? substr($e,0,length($px)) ne $px | ||
| 228 | : grep {$s->{$_} eq substr($e,0,length($s->{$_}))} qw(-pxpv -pxsw -pxcb -pxqc); | ||
| 229 | push @$r, $e; | ||
| 230 | } | ||
| 231 | $r | ||
| 232 | } | ||
| 233 | |||
| 234 | sub qloval { # query list option value compose | ||
| 235 | # (self, list name, param=>val,...) | ||
| 236 | join("\t", $_[1], map {defined($_) ? $_ : '' | ||
| 237 | } @_[2..(lc($_[$#_ -1]) eq lc(pxnme($_[0],-pxsw=>'listurm')) | ||
| 238 | ? $#_ -2 : $#_)]) | ||
| 239 | } | ||
| 240 | |||
| 241 | sub qlourl { # query list option url | ||
| 242 | $_[0]->qurl('' # (self, list name, param=>val,...) | ||
| 243 | ,pxnme($_[0],-pxcb=>'cmd') =>'-lst' | ||
| 244 | ,pxnme($_[0],-pxsw=>'LIST')=>$_[1] | ||
| 245 | ,pxnme($_[0],-pxsw=>'LSO') =>qloval(@_) | ||
| 246 | ,(map { my ($n, $v) =($_,$_[0]->qparam($_)); | ||
| 247 | !defined($v) || $v eq '' | ||
| 248 | || substr($n,0,length($_[0]->{-pxcb})) eq $_[0]->{-pxcb} | ||
| 249 | || substr($n,0,length($_[0]->{-pxpv})) eq $_[0]->{-pxpv} | ||
| 250 | || $n eq '_login' | ||
| 251 | || $n eq pxnme($_[0],-pxsw=>'FRMCOUNT') | ||
| 252 | || $n eq pxnme($_[0],-pxsw=>'LIST') | ||
| 253 | || $n eq pxnme($_[0],-pxsw=>'LSO') | ||
| 254 | || $n eq pxnme($_[0],-pxsw=>'listurm') | ||
| 255 | ? () | ||
| 256 | : ($n=>$v) | ||
| 257 | } $_[0]->cgi->param) | ||
| 258 | ,lc($_[$#_ -1]) eq lc(pxnme($_[0],-pxsw=>'listurm')) | ||
| 259 | ? (@_[($#_ -1)..$#_]) | ||
| 260 | : ()) | ||
| 261 | } | ||
| 262 | |||
| 263 | sub qlowgh { # query list option hidden widget | ||
| 264 | # (self, ?default value) | ||
| 265 | $_[0]->qparam(pxnme($_[0],-pxsw=>'LSO')) | ||
| 266 | ? '' | ||
| 267 | : ($_[0]->cgi->hidden(-name=>pxnme($_[0],-pxsw=>'LSO') | ||
| 268 | , $#_ >0 | ||
| 269 | ? (-value=>$_[0]->qparam(pxnme($_[0],-pxsw=>'LSO'), qloval(@_)) | ||
| 270 | , -override=>1) | ||
| 271 | : ()) ."\n") | ||
| 272 | } | ||
| 273 | |||
| 274 | sub qlowgl { # query list option hyperlink widget | ||
| 275 | my $s =shift; # (self, ?(options), label, list name, param=>val,...) | ||
| 276 | my $o =ref($_[0]) ? (shift @_) : undef; | ||
| 277 | my $v =qloval($s,@_[1..$#_]); | ||
| 278 | my $c =$v eq ($s->qparam(pxnme($s,-pxsw=>'LSO'))||''); | ||
| 279 | $s->cgi->a({$o ? %$o : () | ||
| 280 | , -href=>qlourl($s,@_[1..$#_]) | ||
| 281 | , $c ? (-style=>'{ text-decoration: none; font-weight: bolder; }') : () | ||
| 282 | # font-style: italic; font-weight: bolder; | ||
| 283 | # , -onClick=>'{' .pxnme($s,-pxsw=>'LSO') .'.value="' # !!! read marking? | ||
| 284 | # .do{ $v =~s/([\\"])/\\$1/g; | ||
| 285 | # $v =~s/([\x00-\x1f])/sprintf("\\x%02x",ord($1))/eg; | ||
| 286 | # $v} .'"; ' | ||
| 287 | # .pxnme($s,-pxsw=>'LIST') .'.value="' .$_[1] .'"; ' | ||
| 288 | # .pxnme($s,-pxcb=>'cmdi') .'.value="-lst"; submit(); return(false)}' | ||
| 289 | }, $_[0]) | ||
| 290 | } | ||
| 291 | |||
| 292 | sub qloparse { # query list option parse | ||
| 293 | my $g =$_[0]->cgi; # (self) | ||
| 294 | my $v =$g->param(pxnme($_[0],-pxsw=>'LSO')); | ||
| 295 | return(undef) if !$v | ||
| 296 | || $v !~/^([^\t]+)\t+(.+)$/ | ||
| 297 | || lc($1) ne lc($g->param(pxnme($_[0],-pxsw=>'LIST'))); | ||
| 298 | local $^W=undef; | ||
| 299 | my %p =(split /\t/, $2); | ||
| 300 | my $w =pxnme($_[0],-pxsw=>'WHERE'); | ||
| 301 | foreach my $k (keys %p) { | ||
| 302 | next if !defined($p{$k}) || $p{$k} eq ''; | ||
| 303 | $g->param($k | ||
| 304 | , $k ne $w | ||
| 305 | ? $p{$k} | ||
| 306 | : $g->param($w) && index(lc($g->param($w)||''), lc($p{$k})) <0 | ||
| 307 | ? '(' .$g->param($w) .') AND (' .$p{$k} .')' | ||
| 308 | : $p{$k}); | ||
| 309 | } | ||
| 310 | $_[0] | ||
| 311 | } | ||
| 312 | |||
| 313 | |||
| 314 | ################################### | ||
| 315 | # DECLARATIONS UTILITY METHODS | ||
| 316 | ################################### | ||
| 317 | |||
| 318 | |||
| 319 | sub qlst { # Query List Name | ||
| 320 | my $s =shift; | ||
| 321 | my $l =$s->qparamsw('LIST'); | ||
| 322 | return($l) if $l && $s->{-lists} && $s->{-lists}->{$l}; | ||
| 323 | return(undef) if !$s->{-lists}; | ||
| 324 | my @a =sort keys %{$s->{-lists}}; | ||
| 325 | foreach my $v (@a) { | ||
| 326 | return($l =$v) | ||
| 327 | if ($v && substr($v,length($v)-1) eq '_') | ||
| 328 | || &{sub{$_[0] && substr($_[0],length($_[0])-1) eq '_'}} | ||
| 329 | (ref($s->{-lists}->{$v}) eq 'HASH' && $s->{-lists}->{$v}->{-lbl}) | ||
| 330 | } | ||
| 331 | $l =$a[0]; | ||
| 332 | } | ||
| 333 | |||
| 334 | |||
| 335 | sub qlstnmes { # Lists Names | ||
| 336 | my $l =$_[0]->{-lists}; | ||
| 337 | my $r =[]; | ||
| 338 | if ($l) { | ||
| 339 | foreach my $e (keys %$l) { | ||
| 340 | next if substr($e,0,1) eq '_'; | ||
| 341 | push @$r, $e | ||
| 342 | } | ||
| 343 | } | ||
| 344 | [sort {lc($l->{$a}->{-lbl}||$l->{$a}->{-lst}||$a) cmp lc($l->{$b}->{-lbl}||$l->{$b}->{-lst}||$b)} @$r] | ||
| 345 | } | ||
| 346 | |||
| 347 | |||
| 348 | sub qlstlbls { # Lists Labels | ||
| 349 | my $l =$_[0]->{-lists}; | ||
| 350 | my $r ={}; | ||
| 351 | if ($l) { | ||
| 352 | foreach my $e (keys %$l) { | ||
| 353 | next if substr($e,0,1) eq '_' || !($l->{$e}->{-lbl}||$l->{$e}->{-lst}); | ||
| 354 | $r->{$e} =($l->{$e}->{-lbl}||$l->{$e}->{-lst}) | ||
| 355 | } | ||
| 356 | } | ||
| 357 | $r | ||
| 358 | } | ||
| 359 | |||
| 360 | |||
| 361 | |||
| 362 | ################################### | ||
| 363 | # TRANSACTION METHODS | ||
| 364 | ################################### | ||
| 365 | |||
| 366 | |||
| 367 | sub cmd { # Transaction command schema | ||
| 368 | if (!defined($_[0]->{-cmd})) { # Init command | ||
| 369 | my $s =$_[0]; | ||
| 370 | my $g =$s->cgi; | ||
| 371 | if ($g->param($s->pxnme(-pxcb=>'-lgn'))) { | ||
| 372 | $s->parent->userauth | ||
| 373 | } | ||
| 374 | $s->{-opflg} =$s->parent->uguest ? 'qv' : 'a' # a!v | ||
| 375 | if !defined($s->{-opflg}); | ||
| 376 | foreach my $p (qw(-lst -lsr -qry -crt -sel -edt -frm -ins -upd -del -hlp)) { # post | ||
| 377 | next if !($g->param($s->pxnme(-pxcb=>$p)) | ||
| 378 | ||$g->param($s->pxnme(-pxcb=>$p .'.x'))); | ||
| 379 | $g->delete($s->pxnme(-pxcb=>$p .'.x')); | ||
| 380 | $g->delete($s->pxnme(-pxcb=>$p .'.y')); | ||
| 381 | $g->param ($s->pxnme(-pxcb=>$p), 1); | ||
| 382 | $s->{-cmd} =$p; last | ||
| 383 | } | ||
| 384 | $s->{-cmd} =$g->param($s->pxnme(-pxcb=>'-cmdi')) if !$s->{-cmd}; | ||
| 385 | $s->{-cmdg}=$s->{-cmd} ||$g->param($s->pxnme(-pxcb=>'-cmd')) # get | ||
| 386 | ||$g->param('_cmd') || $s->parent->qrun ||'-lst'; | ||
| 387 | if (!$s->{-cmd}) { | ||
| 388 | $s->{-cmd} =$g->request_method() eq 'POST' | ||
| 389 | && (!$s->{-cmdg} ||$s->{-cmdg} ne '-lst') | ||
| 390 | ? '-frm' : ($s->{-cmdg} ||'-lst' ||''); | ||
| 391 | } | ||
| 392 | foreach my $v (undef, $g->param($s->pxnme(-pxcb=>'-cmd')), '') { | ||
| 393 | last if $s->{-cmdg} && !grep {$s->{-cmdg} eq $_} qw(-frm -ins -upd); | ||
| 394 | $s->{-cmdg} =$v | ||
| 395 | } | ||
| 396 | if (($s->{-opflg} !~/!v/ ||$s->{-opflg} =~/[av]/) && $s->{-cmd} eq '-sel') { | ||
| 397 | $g->delete($s->pxsw('EDIT')) # !!! !v <-> [av] !!! | ||
| 398 | } | ||
| 399 | if ($s->{-cmd} eq '-edt') { | ||
| 400 | $s->{-cmd} =$s->{-cmdg} ='-sel'; | ||
| 401 | # $s->{-cmd} ='-frm'; | ||
| 402 | $s->qparamsw('EDIT',!$s->qparamsw('EDIT')); | ||
| 403 | $g->delete($s->pxsw('EDIT')) if !$s->qparamsw('EDIT') | ||
| 404 | } | ||
| 405 | if ($s->{-cmd} eq '-lsr') { # convert '-lsr'->'-lst' | ||
| 406 | $s->{-cmd} = $s->{-cmdg}='-lst'; | ||
| 407 | my $l=length($s->{-pxqc}); | ||
| 408 | foreach my $p ($g->param) { | ||
| 409 | next if (substr($p, 0, $l) eq $s->{-pxqc}); | ||
| 410 | $g->delete($p) | ||
| 411 | } | ||
| 412 | foreach my $p ($g->param) { | ||
| 413 | next if (substr($p, 0, $l) ne $s->{-pxqc}); | ||
| 414 | my $n =$s->pxnme(-pxqc=>$p); | ||
| 415 | $g->param($p, $g->param($n)); | ||
| 416 | $g->delete($n) | ||
| 417 | } | ||
| 418 | } | ||
| 419 | $s->{-cmde} =$s->cmdg('-crt') | ||
| 420 | ||($s->cmdg('-sel') | ||
| 421 | && ($s->{-opflg} =~/!v/ | ||
| 422 | || $s->{-opflg} !~/[av]/ | ||
| 423 | || ($s->{-opflg} =~/[av]/ | ||
| 424 | && $s->qparamsw('EDIT')))); | ||
| 425 | $s->{-formtgf} ='_BLANK' if !defined($s->{-formtgf}) | ||
| 426 | && $s->cgi->user_agent =~/Lotus-Notes/i; # & StarOffice without jvm | ||
| 427 | } | ||
| 428 | |||
| 429 | if (!$_[1]) { # Current command | ||
| 430 | return $_[0]->{-cmd} | ||
| 431 | } | ||
| 432 | elsif ( $_[1] eq '-cmd') { # Run all defined | ||
| 433 | my $l =$_[0]->cmd('-lst') && $_[0]->qlst && $_[0]->{-lists}->{$_[0]->qlst}; | ||
| 434 | foreach my $c (qw(-chk -ins -upd -del -sel -crt -qry -htm -frm -lst -hlp)) { | ||
| 435 | next if !$_[0]->cmd($c); | ||
| 436 | my $cmd ='cmd' .substr($c,1); | ||
| 437 | if ($l && $l->{"-$cmd"}) { | ||
| 438 | &{$l->{"-$cmd"}}($_[0],$c); | ||
| 439 | last if $c eq '-htm' | ||
| 440 | && !$_[0]->parent->{-cache}->{-htmlstart}; | ||
| 441 | } | ||
| 442 | elsif ($_[0]->{"-$cmd"}) { | ||
| 443 | &{$_[0]->{"-$cmd"}}($_[0],$c) | ||
| 444 | } | ||
| 445 | else { | ||
| 446 | $_[0]->$cmd() | ||
| 447 | } | ||
| 448 | } | ||
| 449 | return (1) | ||
| 450 | } | ||
| 451 | my $c =$_[0]->{-cmd}; # Used command | ||
| 452 | my $f =$_[0]->{-opflg}; # Allow flags | ||
| 453 | my $q =$_[1]; # Queried command | ||
| 454 | my $r =($q eq $c | ||
| 455 | ||($q eq '-chk' && grep {$c eq $_} qw(-ins -upd -del)) | ||
| 456 | # check fields before insert or update | ||
| 457 | ||($q eq '-ret' && grep {$c eq $_} qw(-ins -upd -del)) | ||
| 458 | # return after edit - optional | ||
| 459 | ||($q eq '-sel' && grep {$c eq $_} qw(-ins -upd)) | ||
| 460 | # select after insert, update | ||
| 461 | ||($q eq '-htm' && $c ne '-hlp') | ||
| 462 | # html before list, create, select, message | ||
| 463 | ||($q eq '-frm' && grep {$c eq $_} qw(-qry -ins -upd -crt -sel)) | ||
| 464 | # form after create, select | ||
| 465 | ||($q eq '-end') # end transaction; result message | ||
| 466 | )&&($q eq '-sel' ? $f =~/[avcieud]/ | ||
| 467 | :$q eq '-qry' ? $f =~/[aq]/ && $f !~/![q]/ | ||
| 468 | :$q eq '-ins' ? $f =~/[aci]/ && $f !~/![ci]/ | ||
| 469 | :$q eq '-upd' ? $f =~/[aeu]/ && $f !~/![eu]/ | ||
| 470 | :$q eq '-del' ? $f =~/[ad]/ && $f !~/![d]/ | ||
| 471 | :$q | ||
| 472 | ); | ||
| 473 | $r | ||
| 474 | } | ||
| 475 | |||
| 476 | |||
| 477 | sub cmdg { # Transaction generic command | ||
| 478 | my $c =$_[0]->{-cmdg} || ($_[0]->cmd, $_[0]->{-cmdg}); | ||
| 479 | return($c) if @_ <2; | ||
| 480 | grep {$c eq $_} @_ | ||
| 481 | } | ||
| 482 | |||
| 483 | |||
| 484 | sub cmdfe { # Form edit operation | ||
| 485 | $_[0]->qparamsw('EDIT') | ||
| 486 | ||($_[0]->cmdg('-sel') && (($_[0]->{-opflg}||'') !~/[av]/ || ($_[0]->{-opflg}||'')=~/!v/)) | ||
| 487 | || $_[0]->cmdg('-crt') | ||
| 488 | || $_[0]->cmdg('-qry') | ||
| 489 | } | ||
| 490 | |||
| 491 | |||
| 492 | sub cnd { # Transaction command SQL condition string | ||
| 493 | my $s =shift; | ||
| 494 | return $s->{-cnd} if !defined($_[0]); | ||
| 495 | |||
| 496 | my $g =$s->cgi; | ||
| 497 | my $c =$s->{-cmdc} =substr($_[0],0,1) eq '-' ? shift : ($s->{-cmdc} ||'-sel'); | ||
| 498 | my $fb =$_[0] =~/\-(and|or)/i ? shift && $1 : ''; # prepend 'and' || 'or' | ||
| 499 | my $fe =$_[0] =~/\+(and|or)/i ? shift && $1 : ''; # append 'and' || 'or' | ||
| 500 | $s->cmd() if !$s->{-cmd}; | ||
| 501 | |||
| 502 | my $fl =$c eq '-lst'; # flag list: expressions use | ||
| 503 | my $fp =$c =~/-upd|-del/ # flag param prefix | ||
| 504 | ?$s->{-pxpv} :''; | ||
| 505 | my $px =''; # current colname prefix | ||
| 506 | my $rs =''; # return string | ||
| 507 | while (@_) { | ||
| 508 | my ($pp, $pf, $pm, $pv); | ||
| 509 | if (substr($_[0],-1) eq '.') { # prefix | ||
| 510 | $px = $_[0] eq '.' ? '' : $_[0]; shift | ||
| 511 | } | ||
| 512 | $pp =shift; # field | ||
| 513 | if (substr($_[0],-1) eq '=') { # column | ||
| 514 | $pf = substr($_[0],0,-1); shift | ||
| 515 | } | ||
| 516 | else { | ||
| 517 | $pf =$pp | ||
| 518 | } | ||
| 519 | $pf =$px .$pf; # full qualified colname | ||
| 520 | if ($_[0] =~/^[kw'"]*$/ | ||
| 521 | ||$_[0] =~/\?/ ||ref($_[0])){# mask | ||
| 522 | $pm =shift; | ||
| 523 | } | ||
| 524 | else { | ||
| 525 | $pm =''; | ||
| 526 | } | ||
| 527 | $pv =$g->param($fp .$pp); # value | ||
| 528 | next if $fl && (!defined($pv) || $pv eq ''); | ||
| 529 | if ($fl && $pv =~/^([=><]|is |like |in )/i) { | ||
| 530 | $pv =~s/(\&|\|) +([=><]|is |like |in )/$1 $pf $2/ig; | ||
| 531 | $rs .=' AND ' .$pf .$pv; | ||
| 532 | next; | ||
| 533 | } | ||
| 534 | elsif ($fl && $pv =~/^null/i) {$rs .=' AND ' .$pf .' is NULL'; next} | ||
| 535 | elsif (!defined($pv)) {$rs .=' AND ' .$pf .' is NULL'; next} | ||
| 536 | |||
| 537 | $rs .=' AND ' .$pf .'='; | ||
| 538 | if (ref($pm)) { # sub | ||
| 539 | local $_ =$pv; | ||
| 540 | $rs .=&{$pm}($s,$pv) | ||
| 541 | } | ||
| 542 | elsif ($pm =~/'"/) { # quote | ||
| 543 | $rs .=($s->dbi ? $s->dbi->quote($pv) :"'$pv'") | ||
| 544 | } | ||
| 545 | elsif ($pm =~/[^\\]\?/) { # text mask with '?' placeholders | ||
| 546 | my $t =$pm; $t =~s/\?/$pv/g; | ||
| 547 | $rs .=$t | ||
| 548 | } | ||
| 549 | else { # do not quote | ||
| 550 | $rs .=$pv | ||
| 551 | } | ||
| 552 | |||
| 553 | } | ||
| 554 | if ($rs) { # return string | ||
| 555 | $rs =substr($rs,5); | ||
| 556 | $rs =($fb ? " $fb " : '') ."($rs)" .($fe ? " $fe " : ''); | ||
| 557 | } | ||
| 558 | $s->{-cnd} =$rs | ||
| 559 | } | ||
| 560 | |||
| 561 | |||
| 562 | sub htmlbar { # Transaction batton bar html | ||
| 563 | my ($s, $o) =@_; | ||
| 564 | my $p =$s->parent; | ||
| 565 | my $g =$p->cgi; | ||
| 566 | my $guest =$p->uguest; | ||
| 567 | $o =($s->{-opflg} ||($guest ? 'qv' : 'a')) # a!v | ||
| 568 | if !defined($o); | ||
| 569 | my $r =''; | ||
| 570 | $s->cmd() if !$s->{-cmd}; | ||
| 571 | if ($s->{-cmd} eq '-ins') { | ||
| 572 | # $s->{-cmd} ='-sel'; | ||
| 573 | $s->{-cmdg} ='-sel' | ||
| 574 | } | ||
| 575 | my $vv = $s->{-vsd} && | ||
| 576 | ( $s->{-vsd}->{-npf} && $g->param($s->{-vsd}->{-npf}) | ||
| 577 | || $s->{-vsd}->{-sf} && ($g->param($s->{-vsd}->{-sf})||'') eq ($s->{-vsd}->{-sd}||'')); | ||
| 578 | my $vm = $vv || !$s->{-cmde}; | ||
| 579 | if ($s->{-logo}) { | ||
| 580 | $r .=$s->_htmlbare($s->{-logo} !~/<a /i | ||
| 581 | ? '<a href="' .$p->surl .'">' .($s->{-logo} !~/</ ? '<img src="' .$s->{-logo} .'" alt="" border=0 title="' .$s->lng(1,'-nap') .'" />' : $s->{-logo}) .'</a>' | ||
| 582 | : $s->{-logo}); | ||
| 583 | } | ||
| 584 | #if ((!$ENV{HTTP_REFERER} | ||
| 585 | # ||eval {my $rfr =lc(($ENV{HTTP_REFERER}||'') =~/^(.+?)\/([^\/]+)$/ ? $1 : $ENV{HTTP_REFERER}) ||''; | ||
| 586 | # lc(substr($s->parent->url, 0, length($rfr))) ne $rfr}) | ||
| 587 | #&& $guest) { | ||
| 588 | # $r .=$s->_htmlbare(-lgn => $s->uauth->authurl); | ||
| 589 | #} | ||
| 590 | if (index($o,'<') >=0) { | ||
| 591 | $r .=$s->_htmlbare(-nap, $p->surl) if !$s->{-logo}; | ||
| 592 | my $nth =$s->qurl; | ||
| 593 | my $nup =$s->qparamsw('REFERER') ||$ENV{HTTP_REFERER} ||($s->burl .'/'); | ||
| 594 | $nup =$s->burl .'/' if lc(substr($nup,0,length($nth))) eq lc($nth); | ||
| 595 | # $r .=$s->_htmlbare(-nup, $nup); | ||
| 596 | $r .=$s->_htmlbare(-nth, $nth); | ||
| 597 | $r .=$g->hidden(-name=>$s->pxnme(-pxsw=>'REFERER') | ||
| 598 | ,-value=>$s->param($s->pxnme(-pxsw=>'REFERER')) ||$ENV{HTTP_REFERER} ||$s->burl | ||
| 599 | ,-override=>1) ."\n"; | ||
| 600 | } | ||
| 601 | if ($s->{-tbarl}) { | ||
| 602 | $r .=$g->hidden(-name=>$s->pxnme(-pxsw=>'REFERER')) ."\n" | ||
| 603 | if $g->param($s->pxnme(-pxsw=>'REFERER')) | ||
| 604 | && (ref($s->{-tbarl}) eq 'CODE'); | ||
| 605 | $r .=$s->_htmlbare(ref($s->{-tbarl}) eq 'CODE' | ||
| 606 | ? &{$s->{-tbarl}}($s, $g->param($s->pxnme(-pxsw=>'REFERER'))) | ||
| 607 | : $s->{-tbarl}); | ||
| 608 | } | ||
| 609 | if ($s->cmdg('-lst')) { | ||
| 610 | $r .=$s->_htmlbare(-bck => $p->{-iurl} && $img{-bck} ? $p->qurl : 0 | ||
| 611 | ,-onClick=>'{window.history.back(); return(false)}') #window.event.returnValue=false; | ||
| 612 | if !$s->{-formtgf}; | ||
| 613 | $r .=$s->_htmlbare(-lgn => $s->uauth->authurl) | ||
| 614 | if $guest && $s->uauth->authurl; | ||
| 615 | $r .=$s->_htmlbare($g->popup_menu(-name=>$s->pxnme(-pxsw=>'LIST') | ||
| 616 | ,-values=>$s->qlstnmes | ||
| 617 | ,-labels=>$s->qlstlbls | ||
| 618 | ,-default=>$s->qlst | ||
| 619 | ,-onChange=> (!$p->{-iurl} | ||
| 620 | ? $s->pxnme(-pxcb=>'-lst') .'.click()' | ||
| 621 | : '{' .$s->pxnme(-pxcb=>'-cmdi') .'.value="-lst"; submit(); return(false);}') | ||
| 622 | ,-class=>'MenuArea MenuInput' | ||
| 623 | )) | ||
| 624 | if $s->{-lists} && scalar(keys %{$s->{-lists}}) >1; | ||
| 625 | $r .=$s->_htmlbare($p->htmltextfield(-name =>$s->pxsw('FTEXT') | ||
| 626 | ,-title=>$s->lng(1,'F-TEXT') | ||
| 627 | ,-asize=>4 | ||
| 628 | ,-class=>'MenuArea MenuInput' | ||
| 629 | )) | ||
| 630 | if $s->{-ftext}; | ||
| 631 | $r .=$s->_htmlbare('-lst'); | ||
| 632 | $r .=$s->_htmlbare('-qry') if $o =~/[aq]/; | ||
| 633 | } | ||
| 634 | else { | ||
| 635 | $s->cgi->delete($s->pxnme(-pxsw=>'FRMCOUNT')) if $s->cmd('-crt'); | ||
| 636 | $r .=$s->_htmlbare('-bck'=> $p->{-iurl} && $img{-bck} ? $p->qurl : 0 | ||
| 637 | ,-onClick=>'{' | ||
| 638 | .($g->param($s->pxnme(-pxsw=>'FRMCOUNT'))||1 >1 | ||
| 639 | ? 'window.history.go(-' .($g->param($s->pxnme(-pxsw=>'FRMCOUNT'))||1 -1) .'); ' | ||
| 640 | : '') | ||
| 641 | . 'window.history.back(); return(false)}') | ||
| 642 | if !$s->{-formtgf}; | ||
| 643 | $r .=$s->_htmlbare(-lgn => $s->uauth->authurl) | ||
| 644 | if $guest && $s->uauth->authurl; | ||
| 645 | } | ||
| 646 | if ($s->cmdg('-qry') && $o =~/[aq]/) { | ||
| 647 | $r .=$s->_htmlbare('-lst'); | ||
| 648 | $r .=$s->_htmlbare('-frm'); | ||
| 649 | } | ||
| 650 | if (!$s->cmdg('-lst','-qry')) { | ||
| 651 | # $r .=$s->_htmlbare('-lsr') if !$s->{-formtgf}; | ||
| 652 | $r .=$s->_htmlbare(-qry =>$s->htmlurl($s->qurl,$s->pxcb('-cmd')=>'-qry')) | ||
| 653 | if $o =~/[aq]/ && $o !~/![q]/ | ||
| 654 | && !$s->{-formtgf} && ($vm || $o =~/!v/); | ||
| 655 | |||
| 656 | local $s->{-keyval} =$s->keyval # !!! single field keys only | ||
| 657 | if $s->{-keyfld} && ($s->{-vsd} ||$s->{-fsd}) | ||
| 658 | && !$s->cmdg('-crt'); | ||
| 659 | |||
| 660 | $r .=$s->_htmlbare('-prn'=>$s->htmlurl($s->qurl,$s->pxcb('-cmd')=>'-sel' | ||
| 661 | ,$s->keyfld=>$s->{-keyval}, | ||
| 662 | ,'_tsw_MIN'=>'bhpvr' | ||
| 663 | )) if $vm && $o =~/[av]/ | ||
| 664 | && $s->{-keyval}; | ||
| 665 | |||
| 666 | $r .=$s->_htmlbare('-sel') if $o =~/[aev]/ && $s->cmdg eq '-sel' && $o !~/![s]/ && !$vv && !$guest; | ||
| 667 | $r .=$s->_htmlbare('-edt') if $o =~/[av]/ && $s->cmdg eq '-sel' && $o !~/![veu]/ && $vm && !$vv && !$guest; | ||
| 668 | |||
| 669 | delete $s->{-keyval}; | ||
| 670 | $r .=$s->_htmlbare('-frm') if $o =~/[aeu]/ && $s->cmdg ne '-del' && !$vm; | ||
| 671 | $r .=$s->_htmlbare('-upd') if $o =~/[aeu]/ && $o !~/![eu]/ && $s->cmdg eq '-sel' && !$vm && !$vv; | ||
| 672 | $r .=$s->_htmlbare('-ins') if $o =~/[aci]/ && $o !~/![ci]/ && $s->cmdg ne '-del' && !$vm; | ||
| 673 | $r .=$s->_htmlbare('-del') if $o =~/[ad]/ && $o !~/![d]/ && $s->cmdg eq '-sel' && !$vv; | ||
| 674 | } | ||
| 675 | if ($o =~/[aci]/ && $o !~/![ci]/ && !$s->cmdg('-qry') && !$vv) { | ||
| 676 | local $s->{-keyval} =$s->keyval # !!! single field keys only | ||
| 677 | if $s->{-keyfld} && ($s->{-vsd} ||$s->{-fsd}); | ||
| 678 | if (!$s->{-formtgf}) { | ||
| 679 | $r .=$s->_htmlbare('-crt') | ||
| 680 | } | ||
| 681 | else { | ||
| 682 | $r .=$s->_htmlbare('-crt' | ||
| 683 | ,$s->htmlurl($s->qurl, $s->pxcb('-cmd')=>'-crt') | ||
| 684 | ,-target=>$s->{-formtgf}) | ||
| 685 | } | ||
| 686 | } | ||
| 687 | if ($s->{-tbarr}) { | ||
| 688 | $r .=$s->_htmlbare($s->{-tbarr}); | ||
| 689 | } | ||
| 690 | if (1) { | ||
| 691 | $r .=$s->_htmlbare('-hlp' | ||
| 692 | ,$s->htmlurl($s->qurl,$s->pxcb('-cmd')=>'-hlp') | ||
| 693 | ,-target=>$s->{-formtgf}); | ||
| 694 | } | ||
| 695 | if (1) { | ||
| 696 | $r .='<td class="MenuArea" valign="middle" align="right">'; | ||
| 697 | $r .=' [' .$s->lng(0,$s->cmd) | ||
| 698 | .(!$s->cmdg ||$s->cmd eq $s->cmdg ?'' : ('/' .$s->lng(0,$s->cmdg))) | ||
| 699 | .'] '; | ||
| 700 | $r .="</td>\n" | ||
| 701 | } | ||
| 702 | $r ="<div class=\"MenuArea\"><table class=\"MenuArea\" cellpadding=0><tr>\n" | ||
| 703 | .$r ."</tr></table></div>\n" | ||
| 704 | .($s->cmd('-lst') && ($s->{-refresh} || $s->{-lists} && $s->qlst && $s->{-lists}->{$s->qlst}->{-refresh}) | ||
| 705 | ? '' | ||
| 706 | :('<script for="window" event="onload">{' | ||
| 707 | ."var w=window.document.getElementsByTagName('table')[0]||window.document.getElementsByTagName('table')[0];" | ||
| 708 | ."if(w){w.focus()}}</script>\n")); | ||
| 709 | if ($s->{-banner}) { | ||
| 710 | my $v =ref($s->{-banner}) ? &{$s->{-banner}}($s) : $s->{-banner}; | ||
| 711 | $r =($v ? "<div class=\"MenuArea MenuBanner\">$v</div>\n" : '') .$r; | ||
| 712 | } | ||
| 713 | #$r .='<hr />'; | ||
| 714 | $r | ||
| 715 | } | ||
| 716 | |||
| 717 | |||
| 718 | sub _htmlbare { # Transaction batton bar element | ||
| 719 | my ($s, $b, $u, %a) =@_; | ||
| 720 | my $p =$s->parent; | ||
| 721 | my $g =$p->cgi; | ||
| 722 | my ($v, $t); | ||
| 723 | ($v, $t) =($s->lng(0,$b), $s->lng(1,$b)) if !ref($b) && $s->lng($b); | ||
| 724 | my $j =$a{-onClick} ||'if (window.event.srcElement.children[0]) {window.event.srcElement.children[0].click()}'; | ||
| 725 | delete $a{-onClick}; | ||
| 726 | # $a{-onclick} ||$a{-onClick} || '{window.event.srcElement.children(0).click(); return(false)}'; | ||
| 727 | my $h = ref($b) | ||
| 728 | ? join('</td><td valign="middle" class="MenuArea MenuButton">', @$b) | ||
| 729 | : $u ? $g->a({-href=>$u,-title=>$t | ||
| 730 | ,-class=>'MenuArea MenuButton' | ||
| 731 | ,%a} | ||
| 732 | , $p->{-iurl} && $img{$b} | ||
| 733 | ? '<img src="' .$p->{-iurl} .'/' .$img{$b} | ||
| 734 | .'" border=0 align="bottom" class="MenuArea MenuButton"' | ||
| 735 | .($b eq '-lgn' ? ' width=20 height=22 />' : ' />') | ||
| 736 | .$p->htmlescape($v) | ||
| 737 | : $p->htmlescape($v)) .' ' | ||
| 738 | : $v ? ( $p->{-iurl} && $img{$b} | ||
| 739 | ? $g->image_button(-name=>$s->pxnme(-pxcb=>$b) | ||
| 740 | ,-value=>$v | ||
| 741 | ,-src=>$p->{-iurl} .'/' .$img{$b} | ||
| 742 | ,-align=>'bottom' | ||
| 743 | ,-accesskey=>substr($v,0,1) | ||
| 744 | ,-title=>$v .'. ' .$t | ||
| 745 | ,-class=>'MenuArea MenuButton' | ||
| 746 | ,-style=>'cursor: default;' | ||
| 747 | ,%a) | ||
| 748 | .((($b =~/^-(?:ins|upd|del|frm)/) || | ||
| 749 | (!$s->{-keyval} && $b =~/^-q(?:sel|edt)/)) && 1 | ||
| 750 | ?$g->span({ | ||
| 751 | -title=>$t | ||
| 752 | ,-class=>'MenuArea MenuButton' | ||
| 753 | ,-style=>'cursor: default;' | ||
| 754 | ,-onClick=>$j='{' .$s->pxnme(-pxcb=>'-cmdi') .'.value="'.$b .'"; submit(); return(false)}'} | ||
| 755 | ,$p->htmlescape($v)) | ||
| 756 | :$g->a({href=>$s->qurl('',$s->pxnme(-pxcb=>'-cmd')=>$b, !$s->{-keyval} ? () : ($s->keyfld=>$s->{-keyval})) | ||
| 757 | ,-title=>$t | ||
| 758 | ,-class=>'MenuArea MenuButton' | ||
| 759 | ,-onClick=>$j='{' .$s->pxnme(-pxcb=>'-cmdi') .'.value="'.$b .'"; submit(); return(false)}'} | ||
| 760 | ,$p->htmlescape($v) | ||
| 761 | )) | ||
| 762 | # !!! variants below does not works, -cmdi hidden variable added for above !!! | ||
| 763 | # .'<font size=-1>' .$g->a({href=>$s->qurl('',$s->pxnme(-pxcb=>'-cmd')=>$b), -onClick=>'{' .$s->pxnme(-pxcb=>$b).'.click(); return(false)}'}, $p->htmlescape($v)) .'</font>' | ||
| 764 | # .'<font size=-1>' .$g->a({href=>$s->qurl('',$s->pxnme(-pxcb=>'-cmd')=>$b), -onClick=>$s->pxnme(-pxcb=>$b).'.click()'}, $p->htmlescape($v)) .'</font>' | ||
| 765 | : defined($u) | ||
| 766 | ? $g->button(-name=>$s->pxnme(-pxcb=>$b) | ||
| 767 | ,-class=>'MenuArea MenuButton' | ||
| 768 | ,-value=>$b eq '-bck' ? '<-' : $v | ||
| 769 | ,-accesskey=>substr($v,0,1) | ||
| 770 | ,-title=>$t | ||
| 771 | ,%a | ||
| 772 | ) | ||
| 773 | : $g->submit(-name=>$s->pxnme(-pxcb=>$b) | ||
| 774 | ,-class=>'MenuArea MenuButton' | ||
| 775 | ,-value=>$v | ||
| 776 | ,-accesskey=>substr($v,0,1) | ||
| 777 | ,-title=>$t | ||
| 778 | ,%a) | ||
| 779 | ) .' ' | ||
| 780 | : do{$j =''; $b}; | ||
| 781 | chomp($h); | ||
| 782 | #$j =''; | ||
| 783 | '<td class="MenuArea MenuButton" valign="middle"' | ||
| 784 | .($p->{-iurl} | ||
| 785 | ? ' style="border-width: thin; border-style: outset;"' | ||
| 786 | .($j | ||
| 787 | ? ' onmousedown="if(window.event.button==1){this.style.borderStyle="inset"}" onmouseout="this.style.borderStyle="outset"" onclick="' .$p->htmlescape($j) .'" title="' .$p->htmlescape($v .'. ' .$t) .'"' | ||
| 788 | # onmouseup="this.style.borderStyle="outset"" | ||
| 789 | : '') | ||
| 790 | : '') | ||
| 791 | .">\n<nobr>" | ||
| 792 | .$h | ||
| 793 | ."</nobr></td>\n" | ||
| 794 | } | ||
| 795 | |||
| 796 | |||
| 797 | sub htmlhid { # Transaction hidden html | ||
| 798 | my $s =shift; | ||
| 799 | my $c =$_[0] && substr($_[0],0,1) eq '-' ? shift : ''; | ||
| 800 | my $r =''; | ||
| 801 | my $g =$s->cgi; | ||
| 802 | my $lp=length($s->{-pxpv}); | ||
| 803 | my $lb=length($s->{-pxcb}); | ||
| 804 | my $lq=length($s->{-pxqc}); | ||
| 805 | my $ls=length($s->{-pxsw}); | ||
| 806 | # store generic transaction command | ||
| 807 | $r .=$g->hidden(-name=>$s->pxnme(-pxcb=>'-cmd') | ||
| 808 | ,-value=>$s->{-cmdg} | ||
| 809 | ,-override=>1) ."\n" | ||
| 810 | if $c ne '-lst'; | ||
| 811 | # declare immediate or image transaction command | ||
| 812 | $r .=$g->hidden(-name=>$s->pxnme(-pxcb=>'-cmdi') | ||
| 813 | ,-value=>'' | ||
| 814 | ,-override=>1) ."\n"; | ||
| 815 | |||
| 816 | if ($s->cmd(-sel)) { # -sel: save previos values after record selection | ||
| 817 | foreach my $p ($g->param) { | ||
| 818 | next if substr($p, 0, $lp) eq $s->{-pxpv}; | ||
| 819 | next if substr($p, 0, $lb) eq $s->{-pxcb}; | ||
| 820 | next if substr($p, 0, $lq) eq $s->{-pxqc}; | ||
| 821 | next if substr($p, 0, $ls) eq $s->{-pxsw}; | ||
| 822 | $r .=$g->hidden(-name=>$s->pxnme(-pxpv=>$p) | ||
| 823 | ,-value=>$g->param($p),-override=>1) ."\n" | ||
| 824 | } | ||
| 825 | } | ||
| 826 | |||
| 827 | if ($s->{-cmde}) { | ||
| 828 | $r .=$g->hidden(-name=>$s->pxsw('EDIT'), -value=>'1') ."\n" | ||
| 829 | } | ||
| 830 | |||
| 831 | if ($s->cmd eq '-frm') { # -frm: preserve -pxpv in form recalculations | ||
| 832 | foreach my $p ($g->param) { | ||
| 833 | next if substr($p, 0, $lp) ne $s->{-pxpv}; | ||
| 834 | next if substr($p, 0, $lb) eq $s->{-pxcb}; | ||
| 835 | $r .=$g->hidden(-name=>$p | ||
| 836 | ,-value=>$g->param($p),-override=>1) ."\n" | ||
| 837 | } | ||
| 838 | } | ||
| 839 | |||
| 840 | if ($s->cmd(-lst)) { # -lst: set -pxqc, preserve other fields | ||
| 841 | unless ($s->{-lists} | ||
| 842 | && $s->qlst | ||
| 843 | && $s->{-lists}->{$s->qlst} | ||
| 844 | && $s->{-lists}->{$s->qlst}->{-cmdhtm}) { | ||
| 845 | foreach my $p ($g->param) { | ||
| 846 | next if substr($p, 0, $lq) eq $s->{-pxqc}; | ||
| 847 | next if substr($p, 0, $lb) eq $s->{-pxcb}; | ||
| 848 | next if $p eq $s->pxnme(-pxsw=>'FRMCOUNT') | ||
| 849 | || $p eq $s->pxnme(-pxsw=>'FTEXT') | ||
| 850 | || $p eq $s->pxnme(-pxsw=>'EDIT') | ||
| 851 | || $p eq $s->pxnme(-pxsw=>'LIST'); | ||
| 852 | # $r .=$g->hidden(-name=>$s->pxnme(-pxqc=>$p) # pxqc off | ||
| 853 | # ,-value=>$g->param($p),-override=>1) ."\n"; | ||
| 854 | $r .=$g->hidden(-name=>$p | ||
| 855 | ,-value=>$g->param($p),-override=>1) ."\n" | ||
| 856 | } | ||
| 857 | } | ||
| 858 | } | ||
| 859 | else { # preserve -pxqc when data edit | ||
| 860 | # foreach my $p ($g->param) { # pxqc off | ||
| 861 | # next if substr($p, 0, $lq) ne $s->{-pxqc}; | ||
| 862 | # next if substr($p, 0, $lb) eq $s->{-pxcb}; | ||
| 863 | # $r .=$g->hidden(-name=>$p | ||
| 864 | # ,-value=>$g->param($p),-override=>1) ."\n" | ||
| 865 | # } | ||
| 866 | #$r .=$g->hidden(-name=>'_run' # cargo | ||
| 867 | # ,-value=>$g->param('_run') | ||
| 868 | # ,-override=>1) ."\n" | ||
| 869 | # if $g->param('_run') && $s->cmd(-qry); | ||
| 870 | $r .=$g->hidden(-name=>$s->pxnme(-pxsw=>'LSO') # list options | ||
| 871 | ,-value=>$g->param($s->pxnme(-pxsw=>'LSO')) | ||
| 872 | ,-override=>1) ."\n" | ||
| 873 | if $g->param($s->pxnme(-pxsw=>'LSO')) && $s->cmd(-qry); | ||
| 874 | $r .=$g->hidden(-name=>$s->pxnme(-pxsw=>'FRMCOUNT') | ||
| 875 | ,-value=>($g->param($s->pxnme(-pxsw=>'FRMCOUNT'))||0) +1 | ||
| 876 | ,-override=>1) ."\n" | ||
| 877 | } | ||
| 878 | |||
| 879 | $r ."\n" | ||
| 880 | } | ||
| 881 | |||
| 882 | |||
| 883 | sub htmlself { # Self Hyperlink | ||
| 884 | my $s =shift; | ||
| 885 | my $d =pop; | ||
| 886 | my $a =ref($_[$#_]) ? pop : ref($_[0]) ? shift :[]; | ||
| 887 | $s->a({href=>$s->htmlurl($s->qurl,$s->pxnme(-pxcb=>'-cmd'), @_) | ||
| 888 | ,-target=>$s->{-formtgf} | ||
| 889 | ,(ref($a) eq 'ARRAY' ? @$a : %$a)} | ||
| 890 | ,$d) | ||
| 891 | } | ||
| 892 | |||
| 893 | |||
| 894 | sub htmlres { # Transaction command result msg html | ||
| 895 | my $s =$_[0]; | ||
| 896 | my $g =$s->cgi; | ||
| 897 | my $c =defined($_[1]) ? $_[1] : !$@; | ||
| 898 | my $m =defined($_[2]) ? $_[2] : $@||''; | ||
| 899 | my $t =scalar(@{$s->pushmsg}) >1 ||(scalar(@{$s->pushmsg}) ==1 && $s->pushmsg->[0] ne 'COMMIT'); | ||
| 900 | my $r =''; | ||
| 901 | if (!$s->parent->{-cache} ||!$s->parent->{-cache}->{-httpheader}) { | ||
| 902 | $r =$s->parent->htpgstart; | ||
| 903 | } | ||
| 904 | |||
| 905 | if (!$c) { | ||
| 906 | my $h=$s->lng(0,'Failure') ." '" .$s->lng(0,$s->{-cmd}) ."': "; | ||
| 907 | my $e=$s->htmlescape($m); | ||
| 908 | $r .='<span class="FooterArea" onclick="{_tsw_FooterArea.style.display=(_tsw_FooterArea.style.display==\'none\' ? \'inline\' : \'none\')}" style="cursor: hand; ">'; | ||
| 909 | $r .='<span class="FooterArea ErrorMessage">' .$g->hr ."<h1 class=\"FooterArea ErrorMessage\">$h</h1>" .$e ."</span>\n"; | ||
| 910 | $r .='<hr class="FooterArea" />'; | ||
| 911 | } | ||
| 912 | elsif ((grep {$s->{-cmd} eq $_} qw(-sel -ins -upd -del)) ||$t) { | ||
| 913 | $r .='<span class="FooterArea" onclick="{_tsw_FooterArea.style.display=(_tsw_FooterArea.style.display==\'none\' ? \'inline\' : \'none\')}" style="cursor: hand; ">' | ||
| 914 | .'<hr class="FooterArea" />' | ||
| 915 | .'<strong class="FooterArea">' | ||
| 916 | .($s->cmd('-lst') && $s->{-genlstm} | ||
| 917 | ? $s->{-genlstm} | ||
| 918 | : ($s->lng(0,'Success') ." '" .$s->lng(0,$s->{-cmd}) ."'")) | ||
| 919 | ."</strong>\n"; | ||
| 920 | $r .=$s->htmlescape($s->parent->set('-problem')) ."\n" if $s->parent->set('-problem') | ||
| 921 | } | ||
| 922 | if ($r && (!$c || ($s->parent->{-debug}) >0)) { | ||
| 923 | my $r1 =join(";<br /><br />\n" | ||
| 924 | , map { $_ =~/^((?:WARN|WARNING|ERROR|DIE)[:.,\s]+)(.*)$/i | ||
| 925 | ? "<strong>$1</strong>" .$s->htmlescape($2) | ||
| 926 | : $s->htmlescape($_) | ||
| 927 | } @{$s->pushmsg}); | ||
| 928 | $r1 ='<span id="_tsw_FooterArea" style="' | ||
| 929 | .(($s->parent->{-debug} ||0) >1 ? 'display: inline; ' : 'display: none; ') | ||
| 930 | .'font-size: smaller; ">' | ||
| 931 | .$r1 | ||
| 932 | .'</span>'; | ||
| 933 | $r .="<br />\n" .$r1 | ||
| 934 | } | ||
| 935 | if (!$c) { | ||
| 936 | $s->pushlog('Error ' .$m, @{$s->pushmsg}, '<---Error'); | ||
| 937 | } | ||
| 938 | elsif ($t && (grep {$s->{-cmd} eq $_} qw(-ins -upd -del))) { | ||
| 939 | my @t; | ||
| 940 | foreach my $t (@{$s->pushmsg}) { | ||
| 941 | next if $t !~/^(insert|update|delete)\s/i; | ||
| 942 | push @t, $t | ||
| 943 | } | ||
| 944 | $s->pushlog(@t); | ||
| 945 | } | ||
| 946 | $r .='</span>' if $r; | ||
| 947 | $r | ||
| 948 | } | ||
| 949 | |||
| 950 | |||
| 951 | sub eval { # Transaction run | ||
| 952 | my $s =shift; | ||
| 953 | my $r =ref($_[$#_]) eq 'CODE' ? pop : sub{$s->cmd('-cmd')}; | ||
| 954 | my $e =undef; | ||
| 955 | local $s->parent->{-problem} =''; | ||
| 956 | if (!CORE::eval { | ||
| 957 | $r =&$r($s); | ||
| 958 | 1; | ||
| 959 | }) { | ||
| 960 | $e =$@ ||'Undefined Error'; | ||
| 961 | $r =undef | ||
| 962 | } | ||
| 963 | print $s->htmlres(!$e,$e) if $e ||($s->qparamsw('MIN')||'') !~/r/; | ||
| 964 | $r | ||
| 965 | } | ||
| 966 | |||
| 967 | |||
| 968 | sub evaluate { # Execution of tm | ||
| 969 | my $s =shift; | ||
| 970 | my $p =$s->parent; | ||
| 971 | $s->userauthopt; | ||
| 972 | $p->{-debug} && $p->{-cache}->{-RevertToSelf} | ||
| 973 | && $s->pushmsg('w32IISdpsn(' .(defined($p->{-w32IISdpsn}) ? $p->{-w32IISdpsn} : 'undef') .')'.($p->{-debug} >2 ? ' '. $p->{-cache}->{-RevertToSelf} : '')); | ||
| 974 | if (($p->qrun||'') =~/^(SEARCH|SETUP)$/) { | ||
| 975 | my $a =$p->{-upws}; | ||
| 976 | my $w =$p->upws; | ||
| 977 | if ($p->qrun eq 'SEARCH') { | ||
| 978 | return(undef) if $p->{-cache}->{-RevertToSelf}; | ||
| 979 | $w->{-searchms} =1 | ||
| 980 | if !$a | ||
| 981 | && $^O eq 'MSWin32' | ||
| 982 | && (($ENV{SERVER_SOFTWARE}||'') =~/IIS/); | ||
| 983 | } | ||
| 984 | return($w->evaluate()) | ||
| 985 | } | ||
| 986 | $s->cmd; | ||
| 987 | $s->{-cmdhtm} =sub{$s->cmdhtm(sub{; | ||
| 988 | my $rfr =!$s->cmd('-lst') ? 0 | ||
| 989 | :(($s->{-lists} && $s->qlst ? $s->{-lists}->{$s->qlst}->{-refresh} : 0) | ||
| 990 | ||$s->{-refresh}); | ||
| 991 | $p->print->htpgstart(undef | ||
| 992 | ,{-class=> $s->cmd('-lst') | ||
| 993 | ? 'Form List' | ||
| 994 | : $s->cmdg('-qry') | ||
| 995 | ? 'Form QBF' | ||
| 996 | : 'Form' | ||
| 997 | , $rfr | ||
| 998 | ? ($p->{-htpgstart} ? %{$p->{-htpgstart}} :() | ||
| 999 | ,-head=>(($p->{-htpgstart} && $p->{-htpgstart}->{-head}) | ||
| 1000 | ||($p->{-htmlstart} && $p->{-htmlstart}->{-head}) | ||
| 1001 | ||'') | ||
| 1002 | ."<meta http-equiv=\"refresh\" content=$rfr>") | ||
| 1003 | : $s->cmd('-lst') ||$s->cmd('-hlp') | ||
| 1004 | ? %{$p->{-htpgstart}} | ||
| 1005 | : %{$p->{-htpfstart}}}); | ||
| 1006 | # !!!Multipart forms should be escaped as possible: used only for file uploads | ||
| 1007 | $p->print( $s->{-fsd} && $s->{-fsd}->{-url} | ||
| 1008 | && $s->cmdg !~/lst|qry/i | ||
| 1009 | && !($ENV{MOD_PERL} && $p->cgi->user_agent =~/Lotus-Notes|StarOffice/i) | ||
| 1010 | ? $s->start_multipart_form(-method=>$rfr ? 'get' : 'post', -action=>$s->qurl, -acceptcharset=>$p->{-httpheader} ?$p->{-httpheader}->{-charset} :undef) | ||
| 1011 | : $s->startform(-method=>$rfr ? 'get' : 'post', -action=>$s->qurl, -acceptcharset=>$p->{-httpheader} ?$p->{-httpheader}->{-charset} :undef)); | ||
| 1012 | })} if !$s->{-cmdhtm}; | ||
| 1013 | $p->print->htpfstart(undef, {-class=>'Help', %{$p->{-htpgstart}}}) | ||
| 1014 | if $s->cmd('-hlp'); | ||
| 1015 | $s->eval(); | ||
| 1016 | $p->print->htpfend if $p->{-cache}->{-htmlstart} ||!$s->cmd('-lst'); | ||
| 1017 | } | ||
| 1018 | |||
| 1019 | |||
| 1020 | |||
| 1021 | ################################### | ||
| 1022 | # TRANSACTION COMMANDS | ||
| 1023 | ################################### | ||
| 1024 | |||
| 1025 | |||
| 1026 | sub cmdchk { # Check / Calculate Data before save | ||
| 1027 | my $s =shift; | ||
| 1028 | my $g =$s->cgi; | ||
| 1029 | my $c =$s->cmd; | ||
| 1030 | my @diag; | ||
| 1031 | foreach my $f (@{$s->{-form}}) { | ||
| 1032 | next if !ref($f) || ref($f) eq 'CODE' || !$f->{-fld}; | ||
| 1033 | local $_ =$g->param($f->{-fld}); | ||
| 1034 | if (!$s->cmd('-del')) { | ||
| 1035 | my $n =$f->{-lbl}||$f->{-fld}; | ||
| 1036 | if ($f->{-flg} =~/[mk]/ && $f->{-flg} !~/[g]/ && (!defined($_)|| $_ eq '')) { | ||
| 1037 | push @diag, $s->lng(1,'fldReq',$n) | ||
| 1038 | } | ||
| 1039 | elsif (!$f->{-chk}) {} | ||
| 1040 | elsif (!ref($f->{-chk})) { | ||
| 1041 | push @diag, "'$n' !'" .$f->{-chk} ."'" if !CORE::eval $f->{-chk}; | ||
| 1042 | } | ||
| 1043 | elsif (ref($f->{-chk}) eq 'CODE') { | ||
| 1044 | push @diag, "'$n'" if !&{$f->{-chk}}($s); | ||
| 1045 | } | ||
| 1046 | elsif (ref($f->{-chk}) eq 'ARRAY') { | ||
| 1047 | push @diag, "'$n' !'" .$f->{-chk}->[1] ."'" if !&{$f->{-chk}->[0]}($s); | ||
| 1048 | } | ||
| 1049 | } | ||
| 1050 | foreach my $c (qw(-frm -sav)) { | ||
| 1051 | next if !defined($f->{$c}); | ||
| 1052 | $g->param($f->{-fld}, ref($f->{$c}) ? &{$f->{$c}}($s) : $f->{$c}) | ||
| 1053 | } | ||
| 1054 | if (grep {$c eq $_} qw(-ins -upd -del)) { | ||
| 1055 | next if !defined($f->{$c}); | ||
| 1056 | $g->param($f->{-fld}, ref($f->{$c}) ? &{$f->{$c}}($s) : $f->{$c}) | ||
| 1057 | } | ||
| 1058 | } | ||
| 1059 | $s->die($s->lng(1,'!constr') .': ' .join('; ',@diag) ."\n") if scalar(@diag); | ||
| 1060 | $s | ||
| 1061 | } | ||
| 1062 | |||
| 1063 | |||
| 1064 | |||
| 1065 | sub cmdcrt { # Create Fields | ||
| 1066 | my $s =shift; | ||
| 1067 | my $g =$s->cgi; | ||
| 1068 | foreach my $f (@{$s->{-form}}) { | ||
| 1069 | next if !ref($f) || ref($f) eq 'CODE' || !$f->{-fld} || !defined($f->{-crt}); | ||
| 1070 | local $_ =$g->param($f->{-fld}); | ||
| 1071 | my $v =ref($f->{-crt}) eq 'CODE' ? &{$f->{-crt}}($s) | ||
| 1072 | :$f->{-crt}; | ||
| 1073 | $g->param($f->{-fld},$v) if defined($v); | ||
| 1074 | } | ||
| 1075 | foreach my $f (@{$s->{-form}}) { | ||
| 1076 | next if !ref($f) || ref($f) eq 'CODE' || !$f->{-fld} || defined($f->{-crt}); | ||
| 1077 | $g->delete($f->{-fld}); | ||
| 1078 | } | ||
| 1079 | $s | ||
| 1080 | } | ||
| 1081 | |||
| 1082 | |||
| 1083 | |||
| 1084 | sub cmdqry { # Query Condition Init | ||
| 1085 | my $s =shift; | ||
| 1086 | my $g =$s->cgi; | ||
| 1087 | foreach my $f (@{$s->{-form}}) { | ||
| 1088 | next if !ref($f) || ref($f) eq 'CODE' || !$f->{-fld} || !defined($f->{-qry}) | ||
| 1089 | || defined($g->param($f->{-fld})); | ||
| 1090 | my $v =ref($f->{-qry}) eq 'CODE' ? &{$f->{-qry}}($s) | ||
| 1091 | :$f->{-qry}; | ||
| 1092 | $g->param($f->{-fld},$v) if defined($v); | ||
| 1093 | } | ||
| 1094 | $s | ||
| 1095 | } | ||
| 1096 | |||
| 1097 | |||
| 1098 | |||
| 1099 | sub cmdhtm { # Common HTML | ||
| 1100 | my $s =shift; | ||
| 1101 | |||
| 1102 | $s->die($s->lng(1,'op!let',$s->lng(0,'-sel')) ."\n") | ||
| 1103 | if $s->{-rowsel} && $s->cmd(-sel) && !&{$s->{-rowsel}}($s); | ||
| 1104 | $s->{-cmde} =undef if $s->{-rowedt} && $s->{-cmde} && !&{$s->{-rowedt}}($s); | ||
| 1105 | |||
| 1106 | &{shift @_}(@_) if ref($_[0]) eq 'CODE'; | ||
| 1107 | $s->print($s->htmlbar) if ($s->qparamsw('MIN')||'') !~/b/; | ||
| 1108 | $s->print($s->htmlhid); | ||
| 1109 | $s | ||
| 1110 | } | ||
| 1111 | |||
| 1112 | |||
| 1113 | |||
| 1114 | sub cmdfrm { # Record form for Query or Edit | ||
| 1115 | my $s =shift; | ||
| 1116 | my $p =$s->parent; | ||
| 1117 | my $g =$p->cgi; | ||
| 1118 | my $c =$_[1] ||substr($s->cmdg||$s->cmd,1,1); | ||
| 1119 | $c ='e' if $c eq 's' || $c eq 'f'; | ||
| 1120 | my $vm= !$s->{-cmde} && $c eq 'e' && $s->{-opflg} !~/!v/; | ||
| 1121 | my $mp= $vm && ($s->qparamsw('MIN')||'') =~/bh/i; | ||
| 1122 | my $rskip =1; | ||
| 1123 | my $tskip =0; | ||
| 1124 | if (($s->qparamsw('MIN')||'') !~/h/) { | ||
| 1125 | $p->print('<div class="MenuArea"><strong class="MenuArea MenuHeader">' | ||
| 1126 | ,$p->htmlescape($p->{-htmlstart}->{-title}||$p->{-htpgstart}->{-title}||'') | ||
| 1127 | ,'</strong><hr class="MenuArea MenuHeader"/></div>',"\n"); | ||
| 1128 | } | ||
| 1129 | $p->print($s->{-htmlts} ? $s->{-htmlts} : '<table class="Form">', "\n<tr>\n"); | ||
| 1130 | $p->print('<th colspan=20><nobr>' | ||
| 1131 | ,(' ' x $s->{-width}) | ||
| 1132 | ,"</nobr></th></tr>\n<tr>\n" | ||
| 1133 | ) if $s->{-width}; | ||
| 1134 | foreach my $f (@{$s->{-form}}) { | ||
| 1135 | if ($f eq '') {$rskip =1; next} | ||
| 1136 | elsif ($f eq "\t") { | ||
| 1137 | $p->print('</tr><tr>') if !$rskip; | ||
| 1138 | $rskip =1; | ||
| 1139 | $p->print->td(' '); | ||
| 1140 | next | ||
| 1141 | } | ||
| 1142 | elsif ($f eq "\f") { | ||
| 1143 | $tskip =1; | ||
| 1144 | $p->print("\n</tr>\n", $s->{-htmlte} ? $s->{-htmlte} : "\n</table>\n"); | ||
| 1145 | next | ||
| 1146 | } | ||
| 1147 | elsif ($f eq "</table>") { | ||
| 1148 | $tskip =2; | ||
| 1149 | $p->print("\n</tr>\n", $s->{-htmlte} ? $s->{-htmlte} : "\n</table>\n"); | ||
| 1150 | next | ||
| 1151 | } | ||
| 1152 | elsif (!ref($f)) {$p->print($f); next} | ||
| 1153 | elsif (ref($f) eq 'CODE') {$p->print(&$f($s)); next} | ||
| 1154 | elsif (!$f->{-flg} | ||
| 1155 | ||$f->{-flg} =~/^["'ls]*$/) {next} | ||
| 1156 | next if !$f->{-fld}; | ||
| 1157 | |||
| 1158 | local $_ =$g->param($f->{-fld}); | ||
| 1159 | my $excl =$f->{-flg} !~/[a$c]/ && !($c =~/[ce]/ && $f->{-flg} =~/[av$c]/); | ||
| 1160 | my $hide =$c ne 'q' | ||
| 1161 | && ((ref($f->{-hide}) eq 'CODE' ? &{$f->{-hide}}($s) : $f->{-hide}) | ||
| 1162 | || (ref($f->{-hidel}) eq 'CODE' ? &{$f->{-hidel}}($s) : $f->{-hidel})); | ||
| 1163 | my $view =$vm | ||
| 1164 | ||($f->{-flg} !~/$c[^v]/ | ||
| 1165 | &&( $f->{-flg} =~/[a$c]v/ | ||
| 1166 | ||($f->{-flg} !~/[a$c]/ && $f->{-flg} =~/v/))); | ||
| 1167 | |||
| 1168 | $p->print('</tr><tr>') if !$rskip && !$tskip; | ||
| 1169 | my $lbl =$p->htmlescape($f->{-lbl}||$f->{-fld}); | ||
| 1170 | my $cmt =($f->{-cmt}||$f->{-lbl}||$f->{-fld}) .' [' .$f->{-fld} .': ' .$f->{-flg} .']'; | ||
| 1171 | |||
| 1172 | my $wgh; | ||
| 1173 | if (!($hide||$excl) && defined($f->{-inphtml})) { | ||
| 1174 | $wgh =$f->{-inphtml}; | ||
| 1175 | if (ref($wgh) eq 'CODE') { | ||
| 1176 | $wgh =&$wgh($s); | ||
| 1177 | $_ =$g->param($f->{-fld}); | ||
| 1178 | } | ||
| 1179 | $wgh =~s/< *input\b[^<>]*>//ig if $vm; | ||
| 1180 | $wgh =~s/<[\/\s]*a\b[^>]*>//ig if $mp; | ||
| 1181 | } | ||
| 1182 | |||
| 1183 | if ($f->{-frm} && !$vm && !$view && !$excl && !$hide) { | ||
| 1184 | $s->param($f->{-fld}, $_ =&{$f->{-frm}}($s, $_ =$s->param($f->{-fld}))) | ||
| 1185 | } | ||
| 1186 | |||
| 1187 | if ($excl||$hide) { | ||
| 1188 | $lbl =' ' | ||
| 1189 | } | ||
| 1190 | elsif (defined($f->{-lblhtml})) { | ||
| 1191 | my $l =$f->{-lblhtml}; | ||
| 1192 | $l =&$l($s) if ref($l) eq 'CODE'; | ||
| 1193 | $l =~s/< *input\b[^<>]*>//ig if $vm; | ||
| 1194 | $l =~s/<[\/\s]*a\b[^>]*>//ig if $mp; | ||
| 1195 | $l =~s/\$_/$lbl/; | ||
| 1196 | $lbl =$l; | ||
| 1197 | } | ||
| 1198 | $p->print($tskip || $lbl =~/^\s*<t[dh]\b/i | ||
| 1199 | ? $lbl | ||
| 1200 | : $p->th({-align=>'left',-valign=>'top',-title=>$cmt||'',-class=>'Form'} | ||
| 1201 | ,$lbl)) | ||
| 1202 | if ($tskip<2) && !($hide && $f->{-hidel}); | ||
| 1203 | |||
| 1204 | my $wgp =''; | ||
| 1205 | if ($excl) {} | ||
| 1206 | elsif ($hide) { | ||
| 1207 | $wgp .=$g->hidden(-name=>$f->{-fld}) if !$mp; | ||
| 1208 | # $wgp =' ' | ||
| 1209 | } | ||
| 1210 | elsif ($view) { | ||
| 1211 | my $v =$p->param($f->{-fld}); | ||
| 1212 | $v ='' if !defined($v); | ||
| 1213 | $wgp .=$g->hidden(-name=>$f->{-fld}) if !$mp; | ||
| 1214 | if (ref($f->{-inp}) eq 'ARRAY') { | ||
| 1215 | my $t =$f->{-inp}->[0]; | ||
| 1216 | my %a =$f->{-inp}->[1] ? %{$f->{-inp}->[1]} : (); | ||
| 1217 | $wgp .=$s->$t(-name=>$f->{-fld},%a,-disabled=>'true',-title=>$cmt); | ||
| 1218 | # -readonly, -disabled | ||
| 1219 | } | ||
| 1220 | elsif (ref($f->{-inp}) ne 'HASH') { | ||
| 1221 | $wgp .=$p->htmlescape($v) | ||
| 1222 | } | ||
| 1223 | elsif ($f->{-inp}->{-htmlopt} && $p->ishtml($v)) { | ||
| 1224 | $wgp .=$v | ||
| 1225 | } | ||
| 1226 | elsif ($f->{-inp}->{-hrefs}) { | ||
| 1227 | $wgp .='<code class="Form">' if $v =~/ {2,}/; | ||
| 1228 | while ($v =~/\b([\w-]{3,7}:\/\/[^\s\t,()<>\[\]"']+[^\s\t.,;()<>\[\]"'])/) { | ||
| 1229 | my $r =$1; | ||
| 1230 | $v =$'; | ||
| 1231 | my $w =$p->htmlescape($`); $w =~s/( {2,})/' ' x length($1)/ge; $w =~s/\n/<br \/>\n/g; $w =~s/\r//g; | ||
| 1232 | $wgp .=$w; | ||
| 1233 | $r =~s/^(host|urlh):\/\//\//; | ||
| 1234 | $r =~s/^(url|urlr):\/\//$s->url(-relative=>1)/e; | ||
| 1235 | $r =~s/^(fsurl|urlf):\/\//($s->fsurl||$s->fsurf) .'\/'/e; | ||
| 1236 | $wgp .=$g->a({-href=>$r, -target=>'_blank', -title=>$r, -class=>'Form'} | ||
| 1237 | , $p->htmlescape(length($r) >49 ? substr($r,0,47) .'...' : $r)); | ||
| 1238 | } | ||
| 1239 | $v =$p->htmlescape($v); $v =~s/( {2,})/' ' x length($1)/ge; $v =~s/\n/<br \/>\n/g; $v =~s/\r//g; | ||
| 1240 | $wgp .=$v; | ||
| 1241 | $wgp .='</code>' if $wgp =~/<code class="Form">/; | ||
| 1242 | } | ||
| 1243 | elsif (exists($f->{-inp}->{-arows}) ||exists($f->{-inp}->{-rows}) ||exists($f->{-inp}->{-cols})) { | ||
| 1244 | $v =$p->htmlescape($v); $v =~s/( {2,})/' ' x length($1)/ge; $v =~s/\n/<br \/>\n/g; $v =~s/\r//g; | ||
| 1245 | $v ="<code class=\"Form\">$v</code>" if $v =~/  /; | ||
| 1246 | $wgp .=$v; | ||
| 1247 | } | ||
| 1248 | elsif ($f->{-inp}->{-labels}) { | ||
| 1249 | my $fi =$f->{-inp}; | ||
| 1250 | $fi->{-labels} =&{$fi->{-labels}}($s) if ref($fi->{-labels}) eq 'CODE'; | ||
| 1251 | $v =$fi->{-labels}->{$v} if defined($fi->{-labels}->{$v}); | ||
| 1252 | $wgp .=$p->htmlescape($v) | ||
| 1253 | } | ||
| 1254 | elsif (ref($f->{-inp}->{-values}) eq 'HASH') { | ||
| 1255 | $wgp .=$p->htmlescape(exists($f->{-inp}->{-values}->{$v}) ? $f->{-inp}->{-values}->{$v} : $v) | ||
| 1256 | } | ||
| 1257 | else { | ||
| 1258 | $wgp .=$p->htmlescape($v) | ||
| 1259 | } | ||
| 1260 | } | ||
| 1261 | elsif (!$f->{-inp}) { | ||
| 1262 | # $wgp .=$g->textfield(-name=>$f->{-fld},-title=>$cmt) | ||
| 1263 | $wgp .=$p->htmltextfield(-name=>$f->{-fld},-asize=>20,-title=>$cmt,-class=>'Form') | ||
| 1264 | } | ||
| 1265 | elsif (ref($f->{-inp}) eq 'HASH') { | ||
| 1266 | if (exists $f->{-inp}->{-arows}) { | ||
| 1267 | $f->{-inp}->{-arows} =$f->{-inp}->{-arows} ||3; | ||
| 1268 | $wgp .=$p->htmltextarea(-name=>$f->{-fld},%{$f->{-inp}},-title=>$cmt,-class=>'Form') | ||
| 1269 | } | ||
| 1270 | elsif (exists ($f->{-inp}->{-rows}) ||exists($f->{-inp}->{-cols}) || $f->{-inp}->{-hrefs}) { | ||
| 1271 | $wgp .=$p->htmltextarea(-name=>$f->{-fld},%{$f->{-inp}},-title=>$cmt, -class=>'Form') | ||
| 1272 | } | ||
| 1273 | elsif (exists $f->{-inp}->{-asize}) { | ||
| 1274 | $f->{-inp}->{-asize} =$f->{-inp}->{-asize} ||20; | ||
| 1275 | $wgp .=$p->htmltextfield(-name=>$f->{-fld},%{$f->{-inp}},-title=>$cmt,-class=>'Form') | ||
| 1276 | } | ||
| 1277 | elsif ($f->{-inp}->{-values} ||$f->{-inp}->{-labels}) { | ||
| 1278 | my $fi =$f->{-inp}; | ||
| 1279 | $fi->{-values} =&{$fi->{-values}}($s) if ref($fi->{-values}) eq 'CODE'; | ||
| 1280 | $fi->{-labels} =&{$fi->{-labels}}($s) if ref($fi->{-labels}) eq 'CODE'; | ||
| 1281 | $fi->{-values} =[sort {lc($fi->{-labels}->{$a}) cmp lc($fi->{-labels}->{$b})} keys %{$fi->{-labels}}] | ||
| 1282 | if !$fi->{-values}; | ||
| 1283 | $wgp .=$p->popup_menu(-name=>$f->{-fld},%{$f->{-inp}},-title=>$cmt,-class=>'Form') | ||
| 1284 | } | ||
| 1285 | else { | ||
| 1286 | $wgp .=$p->htmltextfield(-name=>$f->{-fld},%{$f->{-inp}},-title=>$cmt,-class=>'Form') | ||
| 1287 | } | ||
| 1288 | } | ||
| 1289 | elsif (ref($f->{-inp}) eq 'ARRAY') { | ||
| 1290 | my $t =$f->{-inp}->[0]; | ||
| 1291 | my %a =$f->{-inp}->[1] ? %{$f->{-inp}->[1]} : (); | ||
| 1292 | $wgp .=$s->$t(-name=>$f->{-fld},%a,-title=>$cmt) | ||
| 1293 | } | ||
| 1294 | if (defined($wgh)) { | ||
| 1295 | $wgh =~s/\$_/$wgp/; | ||
| 1296 | $wgp =$wgh; | ||
| 1297 | if ($mp || ($wgp =~/< *input[^<>]*>/i)) {} | ||
| 1298 | elsif ($wgp !~/<\/t[dh]\b/i) { | ||
| 1299 | $wgp .=$g->hidden(-name=>$f->{-fld}) | ||
| 1300 | } | ||
| 1301 | else { | ||
| 1302 | $wgp =~s/(<\/t[dh]\b)/$g->hidden(-name=>$f->{-fld}) .$1/ie; | ||
| 1303 | } | ||
| 1304 | } | ||
| 1305 | |||
| 1306 | $wgp ='<td valign="top" align="left" class="Form"' | ||
| 1307 | .($f->{-colspan} ? ' colspan=' .$f->{-colspan} :'') | ||
| 1308 | .($f->{-width} && $f->{-width} =~/\D/ ? ' width=' .$f->{-width} :'') | ||
| 1309 | .(!$vm ? ' title="' .$p->htmlescape($cmt||'') .'"' : '') | ||
| 1310 | .'>' .$wgp .'</td>' | ||
| 1311 | if !$tskip && $wgp !~/^\s*<t[dh]\b/i && !($hide && $f->{-hidel}); | ||
| 1312 | $p->print($wgp, "\n"); | ||
| 1313 | $rskip =undef; | ||
| 1314 | } | ||
| 1315 | $p->print("\n</tr>\n", $s->{-htmlte} ? $s->{-htmlte} : "\n</table>\n") | ||
| 1316 | if !$tskip; | ||
| 1317 | $s | ||
| 1318 | } | ||
| 1319 | |||
| 1320 | |||
| 1321 | |||
| 1322 | sub cmdhlp { # Help Command | ||
| 1323 | my $s =shift; | ||
| 1324 | my $p =$s->parent; | ||
| 1325 | my $g =$p->cgi; | ||
| 1326 | my $o =defined($_[0]) && substr($_[0],0,1) eq '-' ? shift : '-tolfc'; | ||
| 1327 | # 't'itle, 'o'ther, 'l'ists, 'f'ields, 'c'ommands | ||
| 1328 | my $ta={-align=>'left',-valign=>'top'}; | ||
| 1329 | my $sh=''; | ||
| 1330 | if ($o =~/t/) { | ||
| 1331 | $sh ='Help'; | ||
| 1332 | my $t =$s->parent->{-htmlstart}->{-title}||$s->parent->{-htpgstart}->{-title}||''; | ||
| 1333 | print '<div class="MenuArea"><table class="MenuArea" cellpadding=0><tr>' | ||
| 1334 | , $s->{-formtgf} ? '' :$s->_htmlbare(-bck=> $p->{-iurl} && $img{-bck} ? $p->qurl : 0, -onClick=>'{window.history.back(); return(false)}') | ||
| 1335 | , '</td><th valign="middle" class="MenuArea MenuHeader">' | ||
| 1336 | , $s->htmlescape(($t ? "$t - " : '') .$s->lng(0, $sh)) | ||
| 1337 | , "</th></tr></table><hr /></div>\n"; | ||
| 1338 | } | ||
| 1339 | if ($o =~/[fo]/ && $s->{-form}) { | ||
| 1340 | $sh ='Fields'; | ||
| 1341 | print $g->h2($s->htmlescape($s->lng(0, $sh))),"\n"; | ||
| 1342 | $sh =$s->lng(1, $sh); | ||
| 1343 | print $g->p($s->htmlescape($sh)),"\n" if $sh; | ||
| 1344 | print "<table>\n"; | ||
| 1345 | foreach my $f (@{$s->{-form}}) { | ||
| 1346 | next if !$f || ref($f) ne 'HASH' || !$f->{-fld} || !$f->{-cmt}; | ||
| 1347 | print "<tr>"; | ||
| 1348 | print $g->td($ta, '<code>' .$s->htmlescape('[' .$f->{-flg} .']') .'</code>'); | ||
| 1349 | print $g->th($ta, $s->htmlescape($f->{-lbl}||$f->{-fld})); | ||
| 1350 | print $g->td($ta, '<code>' .$s->htmlescape($f->{-fld}) .'</code>'); | ||
| 1351 | print $g->td($ta, $s->htmlescape($f->{-cmt}) | ||
| 1352 | .($f->{-col} && $f->{-col} =~/\(/ | ||
| 1353 | ? ('<br /><code> = ' .$s->htmlescape($f->{-col}) .'</code>') | ||
| 1354 | : '')); | ||
| 1355 | print "</tr>\n"; | ||
| 1356 | } | ||
| 1357 | print "</table>\n"; | ||
| 1358 | } | ||
| 1359 | if ($o =~/[lo]/ && $s->{-lists}) { | ||
| 1360 | $sh ='Lists'; | ||
| 1361 | print $g->h2($s->htmlescape($s->lng(0, $sh))),"\n"; | ||
| 1362 | $sh =$s->lng(1, $sh); | ||
| 1363 | print $g->p($s->htmlescape($sh)),"\n" if $sh; | ||
| 1364 | my $l =$s->{-lists}; | ||
| 1365 | my @a =sort {lc($l->{$a}->{-lbl}||$l->{$a}->{-lst}||$a) cmp lc($l->{$b}->{-lbl}||$l->{$b}->{-lst}||$b)} keys %$l; | ||
| 1366 | print "<table>\n"; | ||
| 1367 | foreach my $e (@a) { | ||
| 1368 | next if !$l->{$e}->{-cmt}; | ||
| 1369 | print "<tr>"; | ||
| 1370 | print $g->th($ta, $s->htmlescape($l->{$e}->{-lbl}||$l->{$e}->{-lst}||$e)); | ||
| 1371 | print $g->td($ta, (ref($l->{$e}->{-cmt}) eq 'ARRAY' | ||
| 1372 | ? join('<br />', map {$s->htmlescape($_)} @{$l->{$e}->{-cmt}}) | ||
| 1373 | : $s->htmlescape($l->{$e}->{-cmt})) | ||
| 1374 | .'<code>' | ||
| 1375 | .(ref($l->{$e}->{-fields}) | ||
| 1376 | ? ('<br /> = ' .$s->htmlescape(join(', ',@{$l->{$e}->{-fields}}))) | ||
| 1377 | : '') | ||
| 1378 | .(ref($l->{$e}->{-key}) | ||
| 1379 | ? (' KEY ' .$s->htmlescape(join(', ',@{$l->{$e}->{-key}}))) | ||
| 1380 | : '') | ||
| 1381 | .(ref($l->{$e}->{-orderby}) | ||
| 1382 | ? (' ORDER BY ' .$s->htmlescape(join(', ',@{$l->{$e}->{-orderby}}))) | ||
| 1383 | : '') | ||
| 1384 | .($l->{$e}->{-orderby} | ||
| 1385 | ? (' ORDER BY ' .$s->htmlescape($l->{$e}->{-orderby})) | ||
| 1386 | : '') | ||
| 1387 | .'</code>' | ||
| 1388 | ); | ||
| 1389 | print "</tr>\n"; | ||
| 1390 | } | ||
| 1391 | print "</table>\n"; | ||
| 1392 | } | ||
| 1393 | if ($o =~/[co]/) { | ||
| 1394 | $sh ='Commands'; | ||
| 1395 | print $g->h2($s->htmlescape($s->lng(0, $sh))),"\n"; | ||
| 1396 | $sh =$s->lng(1, $sh); | ||
| 1397 | print $g->p($s->htmlescape($sh)),"\n" if $sh; | ||
| 1398 | print "<table>\n"; # -nup | ||
| 1399 | foreach my $c (index($s->{-opflg}||'','<') >=0 ? qw(-nap -nth) : () | ||
| 1400 | ,qw(-bck -lgn -lst -qry -crt -sel -prn -edt -frm -ins -upd -del -hlp)) { | ||
| 1401 | next if !$s->lng($c); | ||
| 1402 | print "<tr>"; | ||
| 1403 | print $g->th($ta | ||
| 1404 | ,'<nobr>' | ||
| 1405 | ,($p->{-iurl} && $img{$c} | ||
| 1406 | ? '<img src="' . $p->{-iurl} .'/' .$img{$c} .'" border=0 align="top"' . ($img{$c} =~m{small/}i ? ' width=20 height=22' : '').' />' | ||
| 1407 | : '') | ||
| 1408 | .$s->htmlescape($s->lng(0,$c)) | ||
| 1409 | .'</nobr>'); | ||
| 1410 | print $g->td($ta, $s->htmlescape($s->lng(1,$c))); | ||
| 1411 | print "</tr>\n"; | ||
| 1412 | } | ||
| 1413 | print "</table>\n"; | ||
| 1414 | } | ||
| 1415 | $s | ||
| 1416 | } | ||
| 1417 | |||
| 1418 |