Added the interval method in the forms package and updated those packages that should use it.

This commit is contained in:
JT Smith 2002-08-04 21:31:43 +00:00
parent 5dad94ef4d
commit 12fd555889
8 changed files with 170 additions and 16 deletions

View file

@ -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 <b>and</b> 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;

View file

@ -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());

View file

@ -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})
)

View file

@ -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 = '<script language="JavaScript">function doNumCheck(field) {
var valid = "0123456789"
var ok = "yes";
var temp;
for (var i=0; i<field.value.length; i++) {
temp = "" + field.value.substring(i, i+1);
if (valid.indexOf(temp) == "-1") ok = "no";
}
if (ok == "no") {
field.value = field.value.substring(0, (field.value.length) - 1);
}
} </script>';
$output .= '<input type="text" name="'.$name.'_interval" value="'.$intervalValue.'"
size="3" maxlength="11" onKeyUp="doNumCheck(this.form.'.$name.')" '.$extras.'>';
$output .= '<select name="'.$name.'_units">';
foreach $key (keys %units) {
$output .= '<option value="'.$key.'"';
if ($unitsValue eq $key) {
$output .= " selected";
}
$output .= '>'.$units{$key};
}
$output .= '</select>';
$output .= _subtext($subtext);
$output = _tableFormRow($label,$output) unless ($class->{_noTable});
$class->{_data} .= $output;
}
#-------------------------------------------------------------------
=head2 new ( [ noTable, action, extras, method, enctype ] )

View file

@ -80,7 +80,8 @@ sub www_editGroup {
$f->readOnly($session{form}{gid},WebGUI::International::get(379));
$f->text("groupName",WebGUI::International::get(84),$group{groupName});
$f->textarea("description",WebGUI::International::get(85),$group{description});
$f->integer("expireAfter",WebGUI::International::get(367),$group{expireAfter});
$f->interval("expireAfter",WebGUI::International::get(367),
WebGUI::DateTime::secondsToInterval($group{expireAfter}));
if ($session{setting}{useKarma}) {
$f->integer("karmaThreshold",WebGUI::International::get(538),$group{karmaThreshold});
} else {
@ -122,7 +123,9 @@ sub www_editGroupSave {
WebGUI::SQL->write("insert into groups (groupId) values ($session{form}{gid})");
}
WebGUI::SQL->write("update groups set groupName=".quote($session{form}{groupName}).",
description=".quote($session{form}{description}).", expireAfter='$session{form}{expireAfter}',
description=".quote($session{form}{description}).",
expireAfter='".WebGUI::DateTime::intervalToSeconds($session{form}{expireAfter_interval},
$session{form}{expireAfter_units})."',
karmaThreshold='$session{form}{karmaThreshold}'
where groupId=".$session{form}{gid});
return www_listGroups();

View file

@ -12,6 +12,7 @@ package WebGUI::Operation::Settings;
use Exporter;
use strict;
use WebGUI::DateTime;
use WebGUI::HTMLForm;
use WebGUI::Icon;
use WebGUI::International;
@ -45,7 +46,7 @@ sub www_editUserSettings {
$f->group("onNewUserAlertGroup",WebGUI::International::get(535),[$session{setting}{onNewUserAlertGroup}]);
$f->yesNo("useKarma",WebGUI::International::get(539),$session{setting}{useKarma});
$f->integer("karmaPerLogin",WebGUI::International::get(540),$session{setting}{karmaPerLogin});
$f->integer("sessionTimeout",WebGUI::International::get(142),$session{setting}{sessionTimeout});
$f->interval("sessionTimeout",WebGUI::International::get(142),WebGUI::DateTime::secondsToInterval($session{setting}{sessionTimeout}));
$f->select("authMethod",\%authMethod,WebGUI::International::get(119),[$session{setting}{authMethod}]);
$f->yesNo("usernameBinding",WebGUI::International::get(306),$session{setting}{usernameBinding});
$f->url("ldapURL",WebGUI::International::get(120),$session{setting}{ldapURL});
@ -63,6 +64,8 @@ sub www_editUserSettings {
#-------------------------------------------------------------------
sub www_editUserSettingsSave {
if (WebGUI::Privilege::isInGroup(3)) {
$session{form}{sessionTimeout} = WebGUI::DateTime::intervalToSeconds($session{form}{sessionTimeout_interval},
$session{form}{sessionTimeout_units});
_saveSetting("sessionTimeout");
_saveSetting("onNewUserAlertGroup");
_saveSetting("alertOnNewUser");

View file

@ -99,7 +99,7 @@ sub discussionProperties {
%moderationType = (before=>WebGUI::International::get(567),after=>WebGUI::International::get(568));
$f = WebGUI::HTMLForm->new;
if ($_[0]->get("wobjectId") eq "new") {
$editTimeout = 1;
$editTimeout = 3600;
$moderationType = 'after';
} else {
$editTimeout = $_[0]->get("editTimeout");
@ -107,7 +107,7 @@ sub discussionProperties {
}
$groupToModerate = $_[0]->get("groupToModerate") || 4;
$f->group("groupToPost",WebGUI::International::get(564),[$_[0]->get("groupToPost")]);
$f->integer("editTimeout",WebGUI::International::get(566),$editTimeout);
$f->interval("editTimeout",WebGUI::International::get(566),WebGUI::DateTime::secondsToInterval($editTimeout));
if ($session{setting}{useKarma}) {
$f->integer("karmaPerPost",WebGUI::International::get(541),$_[0]->get("karmaPerPost"));
} else {
@ -478,7 +478,7 @@ sub www_editSave {
karmaPerPost=>$session{form}{karmaPerPost},
groupToPost=>$session{form}{groupToPost},
groupToModerate=>$session{form}{groupToModerate},
editTimeout=>$session{form}{editTimeout},
editTimeout=>WebGUI::DateTime::intervalToSeconds($session{form}{editTimeout_interval},$session{form}{editTimeout_units}),
moderationType=>$session{form}{moderationType}
});
return "";

View file

@ -51,9 +51,11 @@ sub _calendarLayout {
$calendar->monthname(WebGUI::DateTime::getMonthName($calendar->month));
$calendar->header('<h2 align="center">'.$calendar->monthname.' '.$calendar->year.'</h2>');
($start,$end) = monthStartEnd($_[1]);
$sth = WebGUI::SQL->read("select * from EventsCalendar_event where wobjectId=".$_[0]->get("wobjectId")." order by startDate,endDate");
$sth = WebGUI::SQL->read("select * from EventsCalendar_event where wobjectId="
.$_[0]->get("wobjectId")." order by startDate,endDate");
while (%event = $sth->hash) {
if (epochToHuman($event{startDate},"%M %y") eq $thisMonth || epochToHuman($event{endDate},"%M %y") eq $thisMonth) {
if (epochToHuman($event{startDate},"%M %y") eq $thisMonth
|| epochToHuman($event{endDate},"%M %y") eq $thisMonth) {
$message = "";
if ($session{var}{adminOn}) {
$message = deleteIcon('func=deleteEvent&wid='.$_[0]->get("wobjectId").'&eid='.$event{eventId}
@ -93,7 +95,8 @@ sub duplicate {
calendarLayout=>$_[0]->get("calendarLayout"),
paginateAfter=>$_[0]->get("paginateAfter")
});
$sth = WebGUI::SQL->read("select * from EventsCalendar_event where wobjectId=".$_[0]->get("wobjectId")." order by recurringEventId");
$sth = WebGUI::SQL->read("select * from EventsCalendar_event where wobjectId="
.$_[0]->get("wobjectId")." order by recurringEventId");
while (@row = $sth->array) {
$newEventId = getNextId("eventId");
if ($row[6] > 0 && $row[6] != $previousRecurringEventId) {
@ -397,6 +400,14 @@ sub www_view {
return $_[0]->processMacros($output);
}
#-------------------------------------------------------------------
sub www_viewEvent {
my ($output, %event);
tie %event, 'Tie::CPHash';
%event = WebGUI::SQL->quickHash("select * from EventsCalendar_event where eventId=$session{form}{eid}");
return $output;
}
1;