From 12fd555889d5da8dfccbb3fb4b34a1c2e379743f Mon Sep 17 00:00:00 2001 From: JT Smith Date: Sun, 4 Aug 2002 21:31:43 +0000 Subject: [PATCH] Added the interval method in the forms package and updated those packages that should use it. --- docs/upgrades/upgrade_4.4.1-4.5.0.sql | 3 +- lib/WebGUI/DateTime.pm | 58 ++++++++++++++++-- lib/WebGUI/Discussion.pm | 2 +- lib/WebGUI/HTMLForm.pm | 88 +++++++++++++++++++++++++++ lib/WebGUI/Operation/Group.pm | 7 ++- lib/WebGUI/Operation/Settings.pm | 5 +- lib/WebGUI/Wobject.pm | 6 +- lib/WebGUI/Wobject/EventsCalendar.pm | 17 +++++- 8 files changed, 170 insertions(+), 16 deletions(-) diff --git a/docs/upgrades/upgrade_4.4.1-4.5.0.sql b/docs/upgrades/upgrade_4.4.1-4.5.0.sql index 7aa8c029a..70dde00a5 100644 --- a/docs/upgrades/upgrade_4.4.1-4.5.0.sql +++ b/docs/upgrades/upgrade_4.4.1-4.5.0.sql @@ -19,13 +19,14 @@ update international set message='Month(s)' where internationalId=702 and langua update international set message='Year(s)' where internationalId=703 and languageId=1; insert into international values (704,'WebGUI',1,'Second(s)'); insert into international values (705,'WebGUI',1,'Minute(s)'); -insert into international values (706,'WebGUI',1,'Hours(s)'); +insert into international values (706,'WebGUI',1,'Hour(s)'); delete from international where namespace='EventsCalendar' and internationalId=10; delete from international where namespace='EventsCalendar' and internationalId=11; insert into international values (75,'EventsCalendar',1,'Which do you wish to do?'); insert into international values (76,'EventsCalendar',1,'Delete only this event.'); insert into international values (77,'EventsCalendar',1,'Delete this event and all of its recurrences.'); insert into international values (78,'EventsCalendar',1,'Don\'t delete anything, I made a mistake.'); +update wobject set editTimeout=editTimeout*3600; diff --git a/lib/WebGUI/DateTime.pm b/lib/WebGUI/DateTime.pm index 7d8920d0d..084403cd7 100644 --- a/lib/WebGUI/DateTime.pm +++ b/lib/WebGUI/DateTime.pm @@ -15,6 +15,7 @@ use Exporter; use strict; use WebGUI::International; use WebGUI::Session; +use WebGUI::Utility; our @ISA = qw(Exporter); our @EXPORT = qw(&localtime &time &addToTime &addToDate &epochToHuman &epochToSet &humanToEpoch &setToEpoch &monthStartEnd); @@ -39,7 +40,7 @@ sub addToTime { #------------------------------------------------------------------- sub epochToHuman { - my ($offset, $temp, $hour12, $value, $output, @date, %weekday, %month); + my ($offset, $temp, $hour12, $value, $output, @date, $day, $month); $offset = $session{user}{timeOffset} || 0; $offset = $offset*3600; $temp = $_[0] || time(); @@ -63,16 +64,16 @@ sub epochToHuman { $output =~ s/\%m/$value/g; $output =~ s/\%M/$date[1]/g; if ($output =~ /\%c/) { - %month = getMonthName(); - $output =~ s/\%c/$month{$date[1]}/g; + $month = getMonthName($date[1]); + $output =~ s/\%c/$month/g; } #---day stuff $value = sprintf("%02d",$date[2]); $output =~ s/\%d/$value/g; $output =~ s/\%D/$date[2]/g; if ($output =~ /\%w/) { - %weekday = getDayName(); - $output =~ s/\%w/$weekday{$date[6]}/g; + $day = getDayName($date[6]); + $output =~ s/\%w/$day/g; } #---hour stuff $hour12 = $date[3]; @@ -174,6 +175,25 @@ sub humanToEpoch { return $output; } +#------------------------------------------------------------------- +sub intervalToSeconds { + if ($_[1] eq "years") { + return ($_[0]*31536000); + } elsif ($_[1] eq "months") { + return ($_[0]*2592000); + } elsif ($_[1] eq "weeks") { + return ($_[0]*604800); + } elsif ($_[1] eq "days") { + return ($_[0]*86400); + } elsif ($_[1] eq "hours") { + return ($_[0]*3600); + } elsif ($_[1] eq "minutes") { + return ($_[0]*60); + } else { + return $_[0]; + } +} + #------------------------------------------------------------------- sub localtime { return Date::Calc::Localtime($_[0]); @@ -189,6 +209,34 @@ sub monthStartEnd { return ($start, $end); } +#------------------------------------------------------------------- +sub secondsToInterval { + my ($interval, $units); + if ($_[0] >= 31536000) { + $interval = round($_[0]/31536000); + $units = "years"; + } elsif ($_[0] >= 2592000) { + $interval = round($_[0]/2592000); + $units = "months"; + } elsif ($_[0] >= 604800) { + $interval = round($_[0]/604800); + $units = "weeks"; + } elsif ($_[0] >= 86400) { + $interval = round($_[0]/86400); + $units = "days"; + } elsif ($_[0] >= 3600) { + $interval = round($_[0]/3600); + $units = "hours"; + } elsif ($_[0] >= 60) { + $interval = round($_[0]/60); + $units = "minutes"; + } else { + $interval = $_[0]; + $units = "seconds"; + } + return ($interval, $units); +} + #------------------------------------------------------------------- sub setToEpoch { my @date = &localtime(time()); diff --git a/lib/WebGUI/Discussion.pm b/lib/WebGUI/Discussion.pm index 330a41aeb..1b2d9a61c 100644 --- a/lib/WebGUI/Discussion.pm +++ b/lib/WebGUI/Discussion.pm @@ -99,7 +99,7 @@ sub canEditMessage { %message = getMessage($_[1]); if ( # is the message owner ( - (time()-$message{dateOfPost}) < 3600*$_[0]->get("editTimeout") + (time()-$message{dateOfPost}) < $_[0]->get("editTimeout") && $message{userId} eq $session{user}{userId} && !($message{locked}) ) diff --git a/lib/WebGUI/HTMLForm.pm b/lib/WebGUI/HTMLForm.pm index 82c23815d..83a41b5b2 100644 --- a/lib/WebGUI/HTMLForm.pm +++ b/lib/WebGUI/HTMLForm.pm @@ -664,6 +664,94 @@ sub integer { $class->{_data} .= $output; } +#------------------------------------------------------------------- + +=head2 interval ( name [ label, intervalValue, unitsValue, extras, subtext ] ) + + Adds a time interval row to this form. + +=item name + + The the base name for this form element. This form element actually + returns two values under different names. They are name_interval and + name_units. + +=item label + + The left column label for this form row. + +=item intervalValue + + The default value for interval portion of this form element. Defaults + to '1'. + +=item unitsValue + + The default value for units portion of this form element. Defaults + to 'seconds'. Possible values are 'seconds', 'minutes', 'hours', + 'days', 'weeks', 'months', and 'years'. + +=item extras + + If you want to add anything special to this form element like + javascript actions, or stylesheet information, you'd add it in + here as follows: + + 'onChange="this.form.submit()"' + +=item subtext + + Extra text to describe this form element or to provide special + instructions. + +=cut + +sub interval { + my ($subtext, %units, $item, $key, $class, $output, $name, $label, $extras, $intervalValue, $unitsValue); + $class = shift; + $name = shift; + $label = shift; + $intervalValue = shift || 1; + $unitsValue = shift || "seconds"; + $extras = shift; + $subtext = shift; + tie %units, 'Tie::IxHash'; + %units = ('seconds'=>WebGUI::International::get(704), + 'minutes'=>WebGUI::International::get(705), + 'hours'=>WebGUI::International::get(706), + 'days'=>WebGUI::International::get(700), + 'weeks'=>WebGUI::International::get(701), + 'months'=>WebGUI::International::get(702), + 'years'=>WebGUI::International::get(703)); + $output = ''; + $output .= ''; + $output .= '