Skip to content
This repository
branch: DEB_5_7_7
Fetching contributors…

Cannot retrieve contributors at this time

file 139 lines (124 sloc) 3.271 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
# Copyright 2005-2007 Interchange Development Group and others
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: time.widget,v 1.3 2007-03-30 23:40:58 pajamian Exp $

CodeDef time Widget 1
CodeDef time Description Time selector
CodeDef time Routine <<EOR
sub {
my($opt) = @_;

my $name = $opt->{name};
my $val = $opt->{value};

my $now;
if($opt->{time} and $opt->{time_adjust} =~ /([-+]?)(\d+)/) {
my $sign = $1 || '+';
my $adjust = $2;
$adjust *= 3600;
$now = time;
$now += $sign eq '+' ? $adjust : -$adjust;
}

my $sel_extra;
my $opt_extra;
for(qw/ class style extra /) {
my $stag = "select_$_";
my $otag = "option_$_";
my $selapp;
my $optapp;

if($_ eq 'extra') {
$selapp = " $opt->{$stag}";
$optapp = " $opt->{$otag}";
}
else {
$selapp = qq{ $_="$opt->{$stag}"};
$optapp = qq{ $_="$opt->{$otag}"};
}
$sel_extra .= $opt->{$stag} ? $selapp : '';
$opt_extra .= $opt->{$otag} ? $optapp : '';
}

my @t = localtime($now || time);
if (not $val) {
$t[2]++ if $t[2] < 23;
$val = POSIX::strftime("%H00", @t);
}

my $sel = 0;
my $out = qq{<SELECT NAME="$name"$sel_extra>};
my $o;
if ($opt->{blank}) {
$out .= '<OPTION VALUE="0"$opt_extra>------</OPTION>';
}

$val = Vend::Form::round_to_fifteen($val);

if ($opt->{blank}) {
$out .= '<OPTION VALUE="0"$opt_extra>--:--</OPTION>';
}

my $ampm = defined $opt->{ampm} ? $opt->{ampm} : 1;
my $mod = '';
undef $sel;
my %special = qw/ 0 midnight 12 noon /;

my @min;

$opt->{minutes} ||= '';

if($opt->{minutes} =~ /half/i) {
@min = (0,30);
}
elsif($opt->{minutes} =~ /hourly/i) {
@min = (0);
}
elsif($opt->{minutes} =~ /ten/i) {
@min = (0,10,20,30,40,50);
}
elsif($opt->{minutes} =~ /[\0,]/) {
@min = grep /^\d+$/ && $_ <= 59, split /[\0,\s]+/, $opt->{minutes};
}
else {
@min = (0,15,30,45);
}

$opt->{start_hour} ||= 0;
for(qw/start_hour end_hour/) {
$opt->{$_} = int(abs($opt->{$_}));
if($opt->{$_} > 23) {
$opt->{$_} = 0;
}
}
$opt->{start_hour} ||= 0;
$opt->{end_hour} ||= 23;

for my $hr ( $opt->{start_hour} .. $opt->{end_hour} ) {
next if defined $opt->{start_hour} and $hr < $opt->{start_hour};
next if defined $opt->{end_hour} and $hr > $opt->{end_hour};
for my $min ( @min ) {
my $disp_hour = $hr;
if($opt->{ampm}) {
if( $hr < 12) {
$mod = 'am';
}
else {
$mod = 'pm';
$disp_hour = $hr - 12 unless $hr == 12;
}
$mod = errmsg($mod);
$mod = " $mod";
}
if($special{$hr} and $min == 0) {
$disp_hour = errmsg($special{$hr});
}
elsif($ampm) {
$disp_hour = sprintf("%2d:%02d%s", $disp_hour, $min, $mod);
}
else {
$disp_hour = sprintf("%02d:%02d", $hr, $min);
}
my $time = sprintf "%02d%02d", $hr, $min;
$o = sprintf qq{<OPTION VALUE="%s"$opt_extra>%s}, $time, $disp_hour;
($out .= $o, next) unless ! $sel and $val;
#::logDebug("prospect=$time actual=$val");
$o =~ s/>/ SELECTED>/ && $sel++
if $val eq $time;
$out .= $o;
}
}
$out .= "</SELECT>";
return $out;
}
EOR
Something went wrong with that request. Please try again.