Update of /cvs/scoop/scoop/lib/Scoop/Calendar
In directory lithium.sabren.com:/tmp/cvs-serv21684/lib/Scoop/Calendar
Added Files:
EditCalendar.pm Events.pm Views.pm
Log Message:
Event Calendar module, also includes janra's get_sids() and story_data() patches.
--- NEW FILE: Events.pm ---
package Scoop;
use strict;
my $DEBUG = 0;
=pod
=head1 Events.pm
This file contains the user interface for submitting and updating events.
=over 4
=item $S->submit_event()
The main function called for the submitevent op. Depending on CGI arguments and
permissions, it'll display forms for submitting and updating events, and
managing users invited to view events.
=back
=cut
sub submit_event {
my $S = shift;
warn "(submit_event) starting..." if $DEBUG;
my $tool = $S->cgi->param('tool') || 'submit';
my $id = $S->cgi->param('id');
my $save = $S->cgi->param('save');
my $newchild = $S->cgi->param('newchild');
warn "(submit_event) tool $tool, id $id, new child? $newchild" if $DEBUG;
my ($content, $keys, $cal_id, $eid);
if ( $tool eq 'edit' || $tool eq 'invite' || ($tool eq 'submit' && $newchild) ) {
my $event = $S->get_event($id);
unless ( defined($event) ) {
$S->{UI}->{BLOCKS}->{subtitle} = 'invalid event';
$S->{UI}->{BLOCKS}->{CONTENT} = "Sorry, I couldn't find that event";
return;
}
$cal_id = $S->cgi->param('cal_id') || $event->{cal_id};
$eid = $id;
} else {
warn "(submit_event) new event" if $DEBUG;
$cal_id = $S->cgi->param('cal_id') || $id;
$eid = undef;
}
if ( $save ) {
($keys->{msg},$eid) = $S->_save_event($cal_id,$tool,$eid);
}
if ( $keys->{msg} =~ /saved/i && $tool eq 'submit' ) {
warn "(submit_event) new event saved" if $DEBUG;
my $event = $S->get_event($eid);
if ( $event->{public_view} eq 'invite' || $event->{public_submit} eq 'invite' || $event->{public_edit} eq 'invite' ) {
$content = $S->_invitation_list('event',$eid);
} else {
$content = $S->{UI}->{BLOCKS}->{event_saved_msg};
}
$content = $S->interpolate($content,$event);
} elsif ( ($tool eq 'submit' && $keys->{msg} !~ /saved/i) || $tool eq 'edit' ) {
warn "(submit_event) not saved, or editing event: show form" if $DEBUG;
$content = $S->_build_event_form($tool, $cal_id, $eid);
} elsif ( $tool eq 'invite' ) {
warn "(submit_event) event invitation list" if $DEBUG;
$content = $S->_invitation_list('event',$eid);
}
$keys->{action} = $tool;
$keys->{id} = $id;
$keys->{eid} = $eid;
$keys->{cal_id} = $cal_id;
$S->{UI}->{BLOCKS}->{subtitle} = "Edit Event";
$S->{UI}->{BLOCKS}->{CONTENT} = $S->interpolate($content,$keys);
}
=over 4
=item $S->get_event($eid)
=back
=cut
sub get_event {
my $S = shift;
my $eid = shift;
my $event = {};
return unless $eid;
my ($rv,$sth);
if ( ref($eid) eq 'ARRAY' ) {
# cache multiple events, return nothing
my $in_eids = join(',', map { $S->dbh->quote($_) } (@$eid) );
warn " (get_event) getting events $in_eids..." if $DEBUG;
($rv,$sth) = $S->db_select({
DEBUG => $DEBUG,
WHAT => '*',
FROM => 'events left join calendar_link using (eid)',
WHERE => qq|events.eid IN ($in_eids) AND is_primary_calendar=1|
});
my $cache = $sth->fetchall_hashref('eid');
$sth->finish();
($rv,$sth) = $S->db_select({
DEBUG => $DEBUG,
WHAT => 'eid,property,value',
FROM => 'event_properties',
WHERE => qq|eid IN ($in_eids)|
});
while ( my ($id,$property,$value) = $sth->fetchrow_array() ) {
$cache->{$id}->{$property} = $value;
}
$sth->finish();
($rv,$sth) = $S->db_select({
DEBUG => $DEBUG,
WHAT => 'eid,cal_id',
FROM => 'calendar_link',
WHERE => qq|eid IN ($in_eids)|,
ORDER_BY => 'is_primary_calendar DESC'
});
while ( my ($id,$cal_id) = $sth->fetchrow_array() ) {
push @{$cache->{$id}->{cals}}, $cal_id;
}
$S->{EVENT_DATA_CACHE} = {} unless $S->{EVENT_DATA_CACHE};
# define it so the next line doesn't cause a "Can't use an
# undefined value as a HASH reference" error, but only if it
# doesn't already exist
%{$S->{EVENT_DATA_CACHE}} = (%{$S->{EVENT_DATA_CACHE}}, %$cache);
# it's cached now - call get_event with a single eid to get the info from the cache
return;
} else {
# cache and return one event
warn " (get_event) getting event $eid..." if $DEBUG;
if ( $S->{EVENT_DATA_CACHE}->{$eid} ) {
warn " (get_event) found cached data for event $eid" if $DEBUG;
return $S->{EVENT_DATA_CACHE}->{$eid};
}
my $q_eid = $S->dbh->quote($eid);
warn " (get_event) event $eid not in cache - fetching from db" if $DEBUG;
($rv,$sth) = $S->db_select({
DEBUG => $DEBUG,
WHAT => '*',
FROM => 'events left join calendar_link using (eid)',
WHERE => qq|events.eid = $q_eid AND is_primary_calendar=1|
});
if ( $rv == 1 ) {
$event = $sth->fetchrow_hashref();
$sth->finish;
($rv,$sth) = $S->db_select({
DEBUG => $DEBUG,
WHAT => 'property,value',
FROM => 'event_properties',
WHERE => qq|eid = $q_eid|
});
while ( my ($property,$value) = $sth->fetchrow_array() ) {
$event->{$property} = $value;
}
($rv,$sth) = $S->db_select({
DEBUG => $DEBUG,
WHAT => 'cal_id',
FROM => 'calendar_link',
WHERE => qq|eid = $q_eid|
});
while ( my ($cal_id) = $sth->fetchrow_array() ) {
push @{$event->{cals}}, $cal_id;
}
$S->{EVENT_DATA_CACHE}->{$eid} = $event;
warn " (get_event) saved event $eid ($S->{EVENT_DATA_CACHE}->{$eid}->{title}) to the cache" if $DEBUG;
return $event;
}
return undef;
}
}
=head1 Private Functions
=over 4
=item $S->_build_event_form($cal_id, $action, $eid)
=back
=cut
sub _build_event_form {
my $S = shift;
my $action = shift;
my $cal_id = shift;
my $eid = shift;
my ($fields, $data, $event, $perm) = ('', {}, {}, '');
if ( $action eq 'submit' ) {
$perm = $S->have_calendar_perm($action,$cal_id);
} else {
$perm = $S->have_event_perm($action,$eid);
$event->{invite_link} = $S->{UI}->{BLOCKS}->{event_invitation_link};
}
return "Permission Denied" unless $perm;
warn " (_build_event_form) putting the $action form together" if $DEBUG;
if ( !$S->cgi->param('save') && $eid && $action eq 'edit' ) {
warn " (_build_event_form) getting data from the db" if $DEBUG;
# get the data to fill the form with
$data = $S->get_event($eid);
# do strange things for dates (have to break them into components)
$data->{date_start} =~ /(\d+)-(\d+)-(\d+)/;
$data->{date_start_year} = $1;
$data->{date_start_month} = $2;
$data->{date_start_day} = $3;
$data->{date_end} =~ /(\d+)-(\d+)-(\d+)/;
$data->{date_end_year} = $1;
$data->{date_end_month} = $2;
$data->{date_end_day} = $3;
} elsif ( $S->cgi->param('save') ) {
warn " (_build_event_form) getting data from cgi" if $DEBUG;
# from cgi if event was saved
$data = $S->cgi->Vars_cloned();
$data->{cal_id} = $S->get_event($eid)->{cal_id} unless $data->{cal_id};
$data->{eid} = $eid unless $data->{eid};
$data->{date_start} = "$data->{date_start_year}-$data->{date_start_month}-$data->{date_start_day}";
$data->{date_end} = "$data->{date_end_year}-$data->{date_end_month}-$data->{date_end_day}";
} else {
warn " (_build_event_form) blank form" if $DEBUG;
$data = {};
if ( $S->cgi->param('newchild') ) {
$data->{date_start} = $S->get_event($eid)->{date_start};
#FIXME need to break the date up
}
$data->{cal_id} = $cal_id;
}
$event->{formkey} = $S->get_formkey_element();
my $form = $S->{UI}->{BLOCKS}->{event_edit_form};
unless ( $S->cgi->param('newchild') || $data->{parent} ) {
$form =~ s/%%also_submit_line%%/$S->{UI}->{BLOCKS}->{event_other_calendars}/;
$form =~ s/%%parent_event_line%%/$S->{UI}->{BLOCKS}->{event_parent_line}/;
}
# core event info
$event->{public_submit_checked} = ($data->{public_submit} eq 'public') ? ' CHECKED' : '';
$event->{private_submit_checked} = ($data->{public_submit} eq 'private') ? ' CHECKED' : '';
$event->{invite_submit_checked} = ($data->{public_submit} eq 'invite') ? ' CHECKED' : '';
$event->{public_checked} = ($data->{public_view} eq 'public') ? ' CHECKED' : '';
$event->{private_checked} = ($data->{public_view} eq 'private') ? ' CHECKED' : '';
$event->{invite_checked} = ($data->{public_view} eq 'invite') ? ' CHECKED' : '';
$event->{is_parent} = ($data->{is_parent}) ? ' CHECKED' : '';
$event->{volunteers} = ($data->{volunteers}) ? ' CHECKED' : '';
$event->{parent} = $S->cgi->param('newchild') ? $eid : '';
$event->{newchild} = $S->cgi->param('newchild');
$event->{displaystatus} = ( $perm eq 'admin' ) ? $S->_event_displaystatus_select($eid) : ($eid) ? $S->_event_displaystatus($eid) : 'New Event';
$event->{also_submit} = $S->_calendar_additional_submit($data->{cal_id},$data->{eid});
$event->{date_start} = $data->{date_start};
$event->{date_start_year} = $data->{date_start_year};
$event->{date_start_month} = $data->{date_start_month};
$event->{date_start_day} = $data->{date_start_day};
$event->{date_end} = $data->{date_end};
$event->{date_end_year} = $data->{date_end_year};
$event->{date_end_month} = $data->{date_end_month};
$event->{date_end_day} = $data->{date_end_day};
warn " (_build_event_form) some data: date_start=$event->{date_start}; public_view=$data->{public_view}" if $DEBUG;
$form = $S->interpolate($form,$event);
$form =~ s/%%date_start_year%%/$event->{date_start_year}/g; #interpolate doesn't seem to catch args to boxes
$form =~ s/%%date_start_month%%/$event->{date_start_month}/g;
$form =~ s/%%date_start_day%%/$event->{date_start_day}/g;
$form =~ s/%%date_end_year%%/$event->{date_end_year}/g;
$form =~ s/%%date_end_month%%/$event->{date_end_month}/g;
$form =~ s/%%date_end_day%%/$event->{date_end_day}/g;
# event properties
foreach ( sort {$S->{EVENT_PROPERTIES}->{$a}->{display_order} <=> $S->{EVENT_PROPERTIES}->{$b}->{display_order}} keys %{$S->{EVENT_PROPERTIES}} ) {
my %item = {};
%item = %{$S->{EVENT_PROPERTIES}->{$_}};
next unless $item{enabled};
warn " (_build_event_form) processing $_ ($data->{$_})" if $DEBUG;
$item{required} = $item{required} ? $S->{UI}->{BLOCKS}->{required_pref_marker} : '';
if ( ( $data->{$_} && $S->cgi->param('save') ) || $action eq 'edit' ) {
# a value was passed in while we were trying to save, or we're editing.
$item{value} = $data->{$_};
if ( $item{is_date} ) {
warn " (_build_event_form) $_ is a date" if $DEBUG;
# value is split into parts
if ( $data->{$_} && ( $S->cgi->param('save') || $data->{$_} ne '0000-00-00' ) ) {
$item{use_date} = ' CHECKED';
$item{no_date} = '';
$data->{$_} =~ /(\d+)-(\d+)-(\d+)/;
$item{year} = $data->{"${_}_year"} || $1;
$item{month} = $data->{"${_}_month"} || $2;
$item{day} = $data->{"${_}_day"} || $3;
$item{value} = "$item{year}-$item{month}-$item{day}";
} else {
$item{no_date} = ' CHECKED';
$item{use_date} = '';
}
}
if ( $item{is_time} ) {
warn " (_build_event_form) $_ is a time" if $DEBUG;
# value is split into parts FIXME
}
}
my $field = $S->interpolate($S->{UI}->{BLOCKS}->{$item{field}},\%item);
$field =~ s/%%year%%/$item{year}/g; # interpolate() doesn't seem to catch args to boxes
$field =~ s/%%month%%/$item{month}/g;
$field =~ s/%%day%%/$item{day}/g;
$fields .= $field;
}
$form =~ s/%%event_form_items%%/$fields/;
return $form;
}
=over 4
=item $S->_save_event($cal_id, $action, $eid)
Saves a new or existing event. If saving a new event, $eid is the event ID of
the parent (optional) and a new event ID is created. If editing an existing
event, $eid is the event ID of the event being edited, and is required.
Returns a status/error message and the event ID (mainly useful when a new event
is created).
=back
=cut
sub _save_event {
my $S = shift;
my $cal_id = shift;
my $action = shift;
my $eid = shift;
my $event_props;
my $event;
my $oldevent = $S->get_event($eid);
my $perm;
my $DEBUG = 1;
unless ( $S->check_formkey() ) {
# formkey is only used for new event submission, but
# check_formkey returns true if there's no formkey used.
return $S->{UI}->{BLOCKS}->{formkey_err};
}
if ( $action eq 'submit' ) {
$perm = $S->have_calendar_perm($action,$cal_id);
} else {
$perm = $S->have_event_perm($action,$eid);
}
return "Permission Denied" unless $perm;
my $msg;
my ($rv,$sth);
warn " (_save_event) starting $action" if $DEBUG;
foreach ( keys %{$S->{EVENT_PROPERTIES}} ) {
my $item = $S->{EVENT_PROPERTIES}->{$_};
next unless $item->{enabled};
warn " (_save_event) processing $_" if $DEBUG;
warn " (_save_event) $_ requires $item->{requires} if set" if $DEBUG;
if ( $item->{requires} && $S->cgi->param($_) && !$S->cgi->param($item->{requires}) ) {
$msg .= "<BR>$item->{title} requires a value in $S->{EVENT_PROPERTIES}->{$item->{requires}}->{title}\n";
}
if ( $item->{is_date} ) {
warn " (_save_event) $_ is a date" if $DEBUG;
if ( $S->cgi->param($_) ) {
my $year = $S->cgi->param("${_}_year");
my $month = $S->cgi->param("${_}_month");
my $day = $S->cgi->param("${_}_day");
$month = "0$month" if $month < 10;
$day = "0$day" if $day <10;
my $tmp = $year . "-" . $month . "-" . $day;
warn " (_save_event) $_ changed, validating" if $DEBUG;
if ( Date::Calc::check_date($year,$month,$day) ) {
$event_props->{$_} = $tmp;
} else {
$msg .= "<BR> $item->{title} ($tmp) is not a valid date"
}
} else {
$event_props->{$_} = '0000-00-00';
}
warn " (_save_event) checking $event_props->{$_} against $oldevent->{$_}" if $DEBUG;
if ( $oldevent->{$_} eq $event_props->{$_} ) {
delete $event_props->{$_};
next;
}
} else {
next if ( $oldevent->{$_} eq $S->cgi->param($_) );
$event_props->{$_} = $S->cgi->param($_);
}
if ( $item->{required} && ( !$event_props->{$_} || ( $item->{is_date} && $event_props->{$_} eq '0000-00-00' ) ) ) {
$msg .= "<BR>$item->{title} is required\n";
}
if ( $item->{html} ) {
$event_props->{$_} = $S->filter_comment($event_props->{$_}, 'event');
my $filter_errors = $S->html_checker->errors_as_string;
warn " (_save_event) property $_ generated html error $filter_errors" if ( $filter_errors && $DEBUG );
$msg .= $filter_errors if $filter_errors;
} else {
$event_props->{$_} = $S->filter_subject($event_props->{$_});
}
if ( $item->{regex} && $event_props->{$_} ) {
warn " (_save_event) testing $_ against its regex" if $DEBUG;
unless ( $event_props->{$_} =~ /$item->{regex}/ ) {
$msg .= "<BR>$item->{title} ($event_props->{$_}) does not validate\n";
}
}
} # end foreach EVENT_PROPERTIES
my $uid = $S->dbh->quote($S->{UID});
my $q_cal_id = $S->dbh->quote($cal_id);
map { $event->{$_} = $S->cgi->param($_) || 0 } ('public_view','public_submit','is_parent','parent','volunteers');
if ( $S->have_perm('edit_events') ) {
# site admin
$event->{displaystatus} = $S->cgi->param('displaystatus');
} elsif ( $action eq 'submit' && $perm =~ /^mod/ ) {
$event->{displaystatus} = -2;
} elsif ( $action eq 'submit' ) {
$event->{displaystatus} = 0;
# if we've gotten this far we have permission to submit
# the only question was, moderated or not?
}
# start and end dates
if ( $S->cgi->param('date_start_year') > 0 && $S->cgi->param('date_start_month') > 0 && $S->cgi->param('date_start_day') > 0 ) {
my $tmp = $S->cgi->param('date_start_year') . "-" . $S->cgi->param('date_start_month') . "-" . $S->cgi->param('date_start_day');
warn " (_save_event) checking start date $tmp" if $DEBUG;
if ( Date::Calc::check_date($S->cgi->param("date_start_year"),$S->cgi->param("date_start_month"),$S->cgi->param("date_start_day")) ) {
$event->{date_start} = $tmp;
} else {
$msg .= "<BR> Start Date ($tmp) is not a valid date";
}
} else {
$msg .= "<BR>Event must have a start date\n";
}
if ( $S->cgi->param('date_end') && $S->cgi->param('date_end_year') > 0 && $S->cgi->param('date_end_month') > 0 && $S->cgi->param('date_start_day') > 0 ) {
my $tmp2 = $S->cgi->param('date_end_year') . "-" . $S->cgi->param('date_end_month') . "-" . $S->cgi->param('date_end_day');
warn " (_save_event) checking end date $tmp2" if $DEBUG;
if ( Date::Calc::check_date($S->cgi->param("date_end_year"),$S->cgi->param("date_end_month"),$S->cgi->param("date_end_day")) ) {
$event->{date_end} = $tmp2;
} else {
$msg .= "<BR> End Date ($tmp2) is not a valid date";
}
} else {
$event->{date_end} = 0;
}
map { $event->{$_} = $S->dbh->quote($event->{$_}) } (keys %$event);
return $msg if $msg; # there were validation errors at some point, so skip the save
warn " (_save_event) all filters passed successfully; starting save" if $DEBUG;
# save the event
if ( $action eq 'submit' && $perm ) {
warn " (_save_event) adding a new event" if $DEBUG;
$event->{parent} = $eid || 0;
($rv, $sth) = $S->db_insert({
DEBUG => $DEBUG,
INTO => 'events',
COLS => 'eid,last_update,owner,date_start,date_end,public_view,public_submit,is_parent,parent,volunteers',
VALUES => qq|NULL,NULL,$uid,$event->{date_start},$event->{date_end},$event->{public_view},$event->{public_submit},$event->{is_parent},$event->{parent},$event->{volunteers}|
});
$eid = $S->dbh->{'mysql_insertid'};
if ( $rv == 1 ) {
$S->run_hook('event_new',$uid,$eid);
my $other_cals = $S->cgi->param('other_cals');
($rv,$sth) = $S->db_insert({
DEBUG => $DEBUG,
INTO => 'calendar_link',
COLS => 'eid,cal_id,is_primary_calendar,displaystatus',
VALUES => qq|$eid,$q_cal_id,1,$event->{displaystatus}|
}); # primary calendar
my $values;
if ( ref($other_cals) eq 'ARRAY' ) {
warn " (_save_event) submitting to multiple secondary calendars" if $DEBUG;
foreach my $alt ( @{$other_cals} ) {
my $secondary_perm = $S->have_calendar_perm('submit',$alt);
if ( $secondary_perm =~ /mod/ ) {
$values = qq|$eid, $alt, 0, '-2'|;
} elsif ($secondary_perm) {
$values = qq|$eid, $alt, 0, '0'|;
}
($rv,$sth) = $S->db_insert({
DEBUG => $DEBUG,
INTO => 'calendar_link',
COLS => 'eid,cal_id,is_primary_calendar,displaystatus',
VALUES => $values
}); # secondary calendars
}
} else { # just one
warn " (_save_event) submitting to one secondary calendar" if $DEBUG;
my $secondary_perm = $S->have_calendar_perm('submit',$other_cals);
if ( $secondary_perm =~ /mod/ ) {
$values = qq|$eid, $other_cals, 0, '-2'|;
} elsif ($secondary_perm) {
$values = qq|$eid, $other_cals, 0, 0|;
}
($rv,$sth) = $S->db_insert({
DEBUG => $DEBUG,
INTO => 'calendar_link',
COLS => 'eid,cal_id,is_primary_calendar,displaystatus',
VALUES => $values
}); # secondary calendar
}
} else {
$msg = 'Error saving event: database said ' . $sth->errstr();
}
} elsif ( $action == 'edit' && $eid && $perm ) {
warn " (_save_event) editing an existing event" if $DEBUG;
($rv, $sth) = $S->db_update({
DEBUG => $DEBUG,
WHAT => 'events',
SET => qq|last_update = NULL, date_start = $event->{date_start}, date_end = $event->{date_end}, public_view = $event->{public_view}, public_submit = $event->{public_submit}, is_parent = $event->{is_parent}, volunteers = $event->{volunteers}|,
WHERE => qq|eid = $eid|
});
if ( $rv == 1 ) {
$S->run_hook('event_update',$eid);
my $other_cals = $S->cgi->param('other_cals');
my $DEBUG = 1;
warn " (_save_event) displaystatus is $event->{displaystatus}" if $DEBUG;
if ( defined($event->{displaystatus}) ) {
warn " (_save_event) updating displaystatus" if $DEBUG;
($rv,$sth) = $S->db_update({
DEBUG => $DEBUG,
WHAT => 'calendar_link',
SET => qq|displaystatus = $event->{displaystatus}|,
WHERE => qq|eid = $eid AND cal_id = $q_cal_id|
});
}
# get the list of secondary calendars it's subscribed to already
my @cals_used;
my $q_eid = $S->dbh->quote($eid);
($rv,$sth) = $S->db_select({
DEBUG => $DEBUG,
WHAT => 'cal_id',
FROM => 'calendar_link',
WHERE => qq|eid=$q_eid AND is_primary_calendar=0|
});
while ( my ($cal) = $sth->fetchrow_array() ) {
push @cals_used,$cal;
}
# get the list of calendars we're allowed to submit to
my @cals_allowed;
my $cal;
foreach ( keys %{$S->{CALENDARS}} ) {
$cal = $S->get_calendar($_);
next if $cal->{cal_id} == $cal_id;
next unless $S->have_calendar_perm('submit',$cal->{cal_id});
push @cals_allowed,$cal->{cal_id};
}
my $values;
if ( ref($other_cals) eq 'ARRAY' ) {
warn " (_save_event) submitting to multiple secondary calendars" if $DEBUG;
foreach my $alt ( @cals_allowed ) {
my $q_alt = $S->dbh->quote($alt);
# adding/removing secondary calendars
if ( grep { /^$alt$/ } (@cals_used) ) {
warn " (_save_event) $alt is in the db" if $DEBUG;
next if grep { /^$alt$/ } (@$other_cals);
warn " (_save_event) $alt is unchecked: removing" if $DEBUG;
# a delete for those not checked
($rv,$sth) = $S->db_delete({
DEBUG => $DEBUG,
FROM => 'calendar_link',
WHERE => qq|eid=$q_eid AND cal_id=$q_alt|
});
} else {
warn " (_save_event) $alt is not in the db" if $DEBUG;
next if !grep { /^$alt$/ } (@$other_cals);
warn " (_save_event) $alt is checked: adding" if $DEBUG;
# an insert for those checked
my $secondary_perm = $S->have_calendar_perm('submit',$alt);
if ( $secondary_perm =~ /mod/ ) {
$values = qq|$eid, $alt, 0, '-2'|;
} elsif ($secondary_perm) {
$values = qq|$eid, $alt, 0, '0'|;
}
($rv,$sth) = $S->db_insert({
DEBUG => $DEBUG,
INTO => 'calendar_link',
COLS => 'eid,cal_id,is_primary_calendar,displaystatus',
VALUES => $values
});
}
} # end foreach @cals_allowed
} else { # just one (or none)
warn " (_save_event) submitting to one (or no) secondary calendar" if $DEBUG;
foreach my $alt ( @cals_allowed ) {
my $q_alt = $S->dbh->quote($alt);
if ( grep { /^$alt$/ } (@cals_used) ) {
warn " (_save_event) $alt is in the db" if $DEBUG;
next if $alt eq $other_cals;
warn " (_save_event) $alt is unchecked: removing" if $DEBUG;
# a delete for those not checked
($rv,$sth) = $S->db_delete({
DEBUG => $DEBUG,
FROM => 'calendar_link',
WHERE => qq|eid=$q_eid AND cal_id=$q_alt|
});
} else {
warn " (_save_event) $alt is not in the db" if $DEBUG;
next unless $alt eq $other_cals;
warn " (_save_event) $alt is checked: adding" if $DEBUG;
# an insert for the one checked
my $secondary_perm = $S->have_calendar_perm('submit',$other_cals);
if ( $secondary_perm =~ /mod/ ) {
$values = qq|$eid, $other_cals, 0, '-2'|;
} elsif ($secondary_perm) {
$values = qq|$eid, $other_cals, 0, 0|;
}
($rv,$sth) = $S->db_insert({
DEBUG => $DEBUG,
INTO => 'calendar_link',
COLS => 'eid,cal_id,is_primary_calendar,displaystatus',
VALUES => $values
});
}
} # end foreach @cals_allowed
}
} else {
$msg = 'Error updating event: database said ' . $sth->errstr();
}
} else {
#error - not a valid action or no permission
return 'Error';
}
return $msg if $msg; # there was a save error in the event, so don't save the properties
# save the event properties
foreach ( keys %$event_props ) {
my $q_eid = $S->dbh->quote($eid);
my $q_key = $S->dbh->quote($_);
my $q_value = $S->dbh->quote($event_props->{$_});
($rv,$sth) = $S->db_update({
DEBUG => $DEBUG,
WHAT => 'event_properties',
SET => qq|value = $q_value|,
WHERE => qq|property = $q_key AND eid=$q_eid|
});
$sth->finish;
warn " (_save_event) tried update: db rv is $rv" if $DEBUG;
if ($rv != 1) { # couldn't update, try inserting
($rv,$sth) = $S->db_insert({
DEBUG => $DEBUG,
INTO => 'event_properties',
COLS => 'eid,property,value',
VALUES => qq|$q_eid,$q_key,$q_value|
});
$sth->finish;
}
}
if ( $perm =~ /^mod/ ) {
$msg = "Saved event $eid\n<BR>Your event will appear in the calendar once the moderator approves it";
} else {
$msg = "Saved event $eid";
}
#refresh the cache
delete $S->{EVENT_DATA_CACHE}->{$eid};
return ($msg,$eid);
}
=over 4
=item $S->_event_displaystatus_select($eid)
=back
=cut
sub _event_displaystatus_select {
my $S = shift;
my $eid = shift;
my $selectbox = $S->{UI}->{BLOCKS}->{event_edit_displaystatus};
my ($keys, $dispstat);
if ( $eid ) {
my ($rv,$sth) = $S->db_select({
DEBUG => $DEBUG,
WHAT => 'displaystatus',
FROM => 'calendar_link',
WHERE => "eid=$eid AND is_primary_calendar=1"
});
($dispstat) = $sth->fetchrow_array();
}
$keys->{pending_selected} = ' SELECTED' if $dispstat == -2;
$keys->{never_selected} = ' SELECTED' if $dispstat == -1;
$keys->{always_selected} = ' SELECTED' if $dispstat == 0;
return $S->interpolate($selectbox,$keys);
}
=over 4
=item $S->_event_displaystatus($eid)
=back
=cut
sub _event_displaystatus {
my $S = shift;
my $eid = shift;
my $dispstat;
my $DEBUG = 1;
if ($eid) {
my ($rv,$sth) = $S->db_select({
DEBUG => $DEBUG,
WHAT => 'd.name',
FROM => 'calendar_link c left join displaycodes d on c.displaystatus=d.code',
WHERE => "c.eid=$eid AND c.is_primary_calendar=1"
});
($dispstat) = $sth->fetchrow_array();
warn "(_event_displaystatus) event $eid has displaystatus $dispstat" if $DEBUG;
}
return $dispstat;
}
=over 4
=item $S->_calendar_additional_submit($cal_id)
=back
=cut
sub _calendar_additional_submit {
my $S = shift;
my $cal_id = shift;
my $eid = shift;
my ($content, $cal, $keys);
my ($rv,$sth);
my @cals_used;
return unless ( $S->var('allow_user_calendars') );
warn " (_calendar_additional_submit) building list for $eid, subscribed to $cal_id" if $DEBUG;
if ( $eid ) {
# need a list of the calendars this event is filed in
my $q_eid = $S->dbh->quote($eid);
($rv,$sth) = $S->db_select({
DEBUG => $DEBUG,
WHAT => 'cal_id',
FROM => 'calendar_link',
WHERE => qq|eid=$q_eid AND is_primary_calendar=0|
});
while ( ($cal) = $sth->fetchrow_array() ) {
push @cals_used,$cal;
}
warn " (_calendar_additional_submit) currently subscribed to calendars @cals_used" if $DEBUG;
}
my $cals = $S->_cal_submit_list();
foreach ( @$cals ) {
$cal = $S->get_calendar($_);
warn " (_calendar_additional_submit) making checkbox for $cal->{cal_id} ($cal->{title})" if $DEBUG;
my $item = $S->{UI}->{BLOCKS}->{event_also_submit};
$keys->{cal_value} = $cal->{cal_id};
$keys->{cal_title} = $cal->{title};
if ( grep {/^$cal->{cal_id}$/} @cals_used ) {
$keys->{cal_checked} = ' CHECKED';
} else {
$keys->{cal_checked} = '';
}
$content .= $S->interpolate($item,$keys);
}
return $content;
}
=over 4
=item $S->_cal_submit_list()
Returns an arraryref of calendars the current user may submit events to.
=back
=cut
sub _cal_submit_list {
my $S = shift;
my $cals = [];
my $cal;
foreach ( keys %{$S->{CALENDARS}} ) {
$cal = $S->get_calendar($_);
next unless $S->have_calendar_perm('submit',$cal->{cal_id});
push @$cals,$cal->{cal_id};
}
return $cals;
}
=over 4
=item $S->_event_rsvp()
Handles the RSVP for an event. This will also take the names of volunteers and
send mail to the event owner when somebody volunteers, so they can contact the
volunteer promptly.
=back
=cut
sub _event_rsvp {
my $S = shift;
my $attend = $S->cgi->param('attend') || 0;
my $volunteer = $S->cgi->param('volunteer');
my $eid = $S->cgi->param('eid');
warn " (_event_rsvp) recording RSVP from $S->{UID}" if $DEBUG;
if ( ref($volunteer) eq 'ARRAY' ) {
$volunteer = join(',',@$volunteer);
}
my $q_attend = $S->dbh->quote($attend);
my $q_volunteer = $S->dbh->quote($volunteer);
my $q_eid = $S->dbh->quote($eid);
my $q_uid = $S->dbh->quote($S->{UID});
my ($rv,$sth) = $S->db_insert({
DEBUG => $DEBUG,
INTO => 'event_rsvp',
COLS => 'uid,eid,attend,volunteer',
VALUES => qq|$q_uid,$q_eid,$q_attend,$q_volunteer|
});
if ( $volunteer ) {
warn " (_event_rsvp) somebody volunteered to help" if $DEBUG;
my $event = $S->get_event($eid);
my $body = $S->{UI}->{BLOCKS}->{rsvp_volunteer_email};
$event->{url} = $S->var('site_url') . $S->var('rootdir') . "/events/$eid";
$event->{sitename} = $S->var('sitename');
$event->{owner_nick} = $S->get_nick_from_uid($event->{owner});
$event->{volunteer_nick} = $S->{NICK};
$event->{volunteer_email} = $S->user_data($S->{UID})->{realemail};
$body = $S->interpolate($body,$event);
$S->mail($S->user_data($event->{owner})->{realemail},'New Volunteer for your event',$body);
}
return;
}
1;
--- NEW FILE: Views.pm ---
package Scoop;
use strict;
my $DEBUG = 0;
=pod
=head1 Views.pm
This file contains the display routines for the three different calendar views
(monthly, weekly, and daily), and their associated support functions.
=over 4
=item $S->calendar_monthly($cal_ids,$title)
Formats a monthly calendar view containing events in all calendars listed. One
parameter: an arrayref containing a list of calendars whose events should be
displayed.
=back
=cut
sub calendar_monthly {
my $S = shift;
my $cal_ids = shift; #arrayref
my $title = shift;
my $date = $S->cgi->param('date') || 'today';
my @date = $S->_get_date_array($date);
my @today = $S->time_localize_array(Date::Calc::Today_and_Now(),1);
my $page .= $S->{UI}->{BLOCKS}->{calendar_body_monthly};
my $body;
my $days; #keys for interpolate()
my $first_of_month = Date::Calc::Day_of_Week($date[0],$date[1],1);
my $days_in_month = Date::Calc::Days_in_Month($date[0],$date[1]);
my $tmp = $days_in_month - 28 + $first_of_month;
my $weeks = ( $tmp == 1 ) ? 4 : ( $tmp >= 9 ) ? 6 : 5;
warn "(calendar_monthly) there are $weeks weeks in this month and the first day falls on $first_of_month" if $DEBUG;
foreach my $a (1..$weeks) {
my $wk = $S->{UI}->{BLOCKS}->{calendar_monthly_one_week};
$wk =~ s/%%week%%/$a/g;
$body .= $wk;
}
$page =~ s/%%rows%%/$body/;
my $i = 0;
my ($dow,$wom, at mow); # day of week, week of month, monday of week
# $S->_get_months_events($date[0],$date[1],$cal_ids);
# FIXME commented out until date range issue with event cache is worked out
warn $cal_ids ? "(calendar_monthly) formatting monthly calendar for $date[0]-$date[1]-$date[2] for calendars " . join(',',@{$cal_ids}) : "(calendar_monthly) blank calendar" if $DEBUG;
# the month in question
while ( $i++ < $days_in_month ) {
$dow = Date::Calc::Day_of_Week($date[0],$date[1],$i);
$wom = int(($i + Date::Calc::Day_of_Week($date[0],$date[1],1) - 2) /7)+1;
my $hilight = ($date[0] == $today[0] && $date[1] == $today[1] && $i == $today[2]) ? '1' : '0';
$days->{"wk${wom}_d$dow"} = $S->_calendar_format_one_day(@date[0,1],$i,'monthly',$cal_ids,$hilight);
@mow = Date::Calc::Monday_of_Week(Date::Calc::Week_of_Year($date[0],$date[1],$i));
$days->{"wk$wom"} = "$mow[0]-$mow[1]-$mow[2]";
}
# days outside the month
my $hilight = '2';
#beginning
$i = $first_of_month;
$dow = 1;
while ( --$i > 0 ) {
my @d = Date::Calc::Add_Delta_YMD(@date[0,1],1,0,0,-$i);
$days->{"wk1_d$dow"} = $S->_calendar_format_one_day(@d,'monthly',$cal_ids,$hilight);
$dow++;
}
#ending
$dow = 7;
$i = 8 - Date::Calc::Day_of_Week($date[0],$date[1],$days_in_month);
while ( --$i > 0 ) {
my @d = Date::Calc::Add_Delta_YMD(@date[0,1],$days_in_month,0,0,$i);
$days->{"wk${weeks}_d$dow"} = $S->_calendar_format_one_day(@d,'monthly',$cal_ids,$hilight);
$dow--;
}
$days->{cal_id} = $S->cgi->param('calendar') || 0;
$days->{view} = 'monthly';
$days->{date} = "$date[0]-$date[1]";
$days->{longdate} = Date::Calc::Month_to_Text($date[1]) . " " . $date[0];
$days->{month} = Date::Calc::Month_to_Text($date[1]);
$days->{monthnum} = $date[1];
$days->{year} = $date[0];
$days->{calendar_title} = $title;
if ( ($S->cgi->param('caller_op') eq 'user' || $S->cgi->param('caller_op') =~ /^~(.+)$/ || $S->cgi->param('caller_op') eq 'my') && $S->cgi->param('uid') == $S->{UID} ) {
# show link to subscribe to this calendar
$days->{usercal} = "/user/" . $S->get_nick_from_uid($S->cgi->param('uid'));
}
my $sub_link = $S->_calendar_subscribe_link();
$page =~ s/%%subscribe_link%%/$sub_link/;
return $S->interpolate($page,$days);
}
=over 4
=item $S->calendar_weekly($cal_ids)
Formats a weekly calendar view containing events in all calendars listed.
=back
=cut
sub calendar_weekly {
my $S = shift;
my $cal_ids = shift; #arrayref
my $title = shift;
my $date = $S->cgi->param('date') || 'today';
warn "(calendar_weekly) got date $date" if $DEBUG;
my @date = Date::Calc::Monday_of_Week(Date::Calc::Week_of_Year($S->_get_date_array($date)));
my @today = $S->time_localize_array(Date::Calc::Today_and_Now(),1);
my $page;
my $days; #keys for interpolate()
my $i = 0;
warn $cal_ids ? "(calendar_weekly) formatting weekly calendar for $date[0]-$date[1]-$date[2] for calendars " . join(',',@{$cal_ids}) : "(calendar_weekly) blank calendar" if $DEBUG;
while ( $i++ < 7 ) {
warn "(calendar_weekly) processing " . Date::Calc::Day_of_Week_to_Text($i) if $DEBUG;
my @cdate = Date::Calc::Add_Delta_YMD($date[0],$date[1],$date[2],0,0,$i-1);
my $hilight = ($cdate[0] == $today[0] && $cdate[1] == $today[1] && $cdate[2] == $today[2]) ? '1' : '0';
$days->{"d$i"} = $S->_calendar_format_one_day(@cdate,'weekly',$cal_ids,$hilight);
}
$days->{cal_id} = $S->cgi->param('calendar') || 0;
$days->{view} = 'weekly';
$days->{date} = "$date[0]-$date[1]-$date[2]";
$days->{mediumdate} = Date::Calc::Date_to_Text($date[0],$date[1],$date[2]);
$days->{longdate} = Date::Calc::Date_to_Text_Long($date[0],$date[1],$date[2]);
$days->{month} = Date::Calc::Month_to_Text($date[1]);
$days->{monthnum} = $date[1];
$days->{year} = $date[0];
$days->{day_num} = $date[2];
$days->{day_ord} = Date::Calc::English_Ordinal($date[2]);
$days->{dow} = Date::Calc::Day_of_Week_to_Text(Date::Calc::Day_of_Week($date[0],$date[1],$date[2]));
$days->{dow_short} = Date::Calc::Day_of_Week_Abbreviation(Date::Calc::Day_of_Week($date[0],$date[1],$date[2]));
$days->{calendar_title} = $title;
$page .= $S->{UI}->{BLOCKS}->{calendar_body_weekly};
if ( ($S->cgi->param('caller_op') eq 'user' || $S->cgi->param('caller_op') =~ /^~(.+)$/ || $S->cgi->param('caller_op') eq 'my') && $S->cgi->param('uid') == $S->{UID} ) {
# show link to subscribe to this calendar
$days->{usercal} = "/user/" . $S->get_nick_from_uid($S->cgi->param('uid'));
}
my $sub_link = $S->_calendar_subscribe_link();
$page =~ s/%%subscribe_link%%/$sub_link/;
return $S->interpolate($page,$days);
}
=over 4
=item $S->calendar_daily($cal_ids)
Formats a daily calendar view containing events in all calendars listed.
=back
=cut
sub calendar_daily {
my $S = shift;
my $cal_ids = shift; #arrayref
my $title = shift;
my $date = $S->cgi->param('date') || 'today';
my @date = $S->_get_date_array($date);
my @today = $S->time_localize_array(Date::Calc::Today_and_Now(),1);
my $page;
my $days; #keys for interpolate()
my $i = 0;
warn $cal_ids ? "(calendar_daily) formatting daily calendar for $date[0]-$date[1]-$date[2] for calendars " . join(',',@{$cal_ids}) : "(calendar_daily) blank calendar" if $DEBUG;
my $hilight = ($date[0] == $today[0] && $date[1] == $today[1] && $date[2] == $today[2]) ? '1' : '0';
$days->{day} = $S->_calendar_format_one_day(@date,'daily',$cal_ids,$hilight);
$days->{cal_id} = $S->cgi->param('calendar') || 0;
$days->{view} = 'daily';
$days->{date} = "$date[0]-$date[1]-$date[2]";
$days->{mediumdate} = Date::Calc::Date_to_Text($date[0],$date[1],$date[2]);
$days->{longdate} = Date::Calc::Date_to_Text_Long($date[0],$date[1],$date[2]);
$days->{day_num} = $date[2];
$days->{day_ord} = Date::Calc::English_Ordinal($date[2]);
$days->{month} = Date::Calc::Month_to_Text($date[1]);
$days->{monthnum} = $date[1];
$days->{year} = $date[0];
$days->{dow} = Date::Calc::Day_of_Week_to_Text(Date::Calc::Day_of_Week($date[0],$date[1],$date[2]));
$days->{dow_short} = Date::Calc::Day_of_Week_Abbreviation(Date::Calc::Day_of_Week($date[0],$date[1],$date[2]));
$days->{calendar_title} = $title;
$page .= $S->{UI}->{BLOCKS}->{calendar_body_daily};
if ( ($S->cgi->param('caller_op') eq 'user' || $S->cgi->param('caller_op') =~ /^~(.+)$/ || $S->cgi->param('caller_op') eq 'my') && $S->cgi->param('uid') == $S->{UID} ) {
# show link to subscribe to this calendar
$days->{usercal} = "/user/" . $S->get_nick_from_uid($S->cgi->param('uid'));
}
my $sub_link = $S->_calendar_subscribe_link();
$page =~ s/%%subscribe_link%%/$sub_link/;
return $S->interpolate($page,$days);
}
=over 4
=item $S->calendar_none()
=back
=cut
sub calendar_none {
my $S = shift;
return $S->{UI}->{BLOCKS}->{calendar_error_body};
}
=head1 Private functions
=over 4
=item $S->_calendar_title($id)
Returns the calendar title
=back
=cut
sub _calendar_title {
my $S = shift;
my $id = shift;
$id = $S->dbh->quote($id);
my ($rv, $sth) = $S->db_select({
DEBUG => $DEBUG,
WHAT => 'title',
FROM => 'calendars',
WHERE => qq{cal_id = $id}
});
my ($title) = $sth->fetchrow_array();
$sth->finish;
return $title;
}
=over 4
=item $S->_calendar_date_navigation($view, at date)
Returns an arrayref of hashrefs containing the link and date arrayref for the
current calendar view. The current item has a hash key called 'current' which
is set to true.
The number of items returned on either side of 'current' depends on the Site
Control calendar_navigation_range.
=back
=cut
sub _calendar_date_navigation {
my $S = shift;
my $view = shift;
my @date = @_[0,1,2];
my ($navbar, $i);
my $range = $S->var('calendar_navigation_range');
my $return = [];
my $link_prefix;
if ( $S->cgi->param('caller_op') eq 'user' || $S->cgi->param('caller_op') =~ /^~(.+)$/ || $S->cgi->param('caller_op') eq 'my' ) {
warn "(_calendar_date_navigation) this is a user calendar for " . $S->cgi->param('uid') if $DEBUG;
$link_prefix = "/user/" . $S->get_nick_from_uid($S->cgi->param('uid'));
}
my ($w_year,$w_month,$w_day,$w_item); #working copies of variables
my $cal_id = $S->cgi->param('calendar') || 0;
if ( $view eq 'monthly' ) {
# $range previous
$i = $range +1;
while (--$i > 0) {
($w_year,$w_month,$w_day) = Date::Calc::Add_Delta_YMD(@date,0,-$i,0);
$w_item = {};
$w_item->{date_array} = [$w_year,$w_month,1]; #FIXME can this be an array or must it be an arrayref?
$w_month = ( $w_month < 10 ) ? "0$w_month" : $w_month;
$w_item->{link_url} = "%%rootdir%%$link_prefix/calendar/$view/$cal_id/$w_year-$w_month";
push @$return, $w_item;
}
# current month
$w_item = {};
$w_item->{date_array} = \@date;
$w_item->{link_url} = "%%rootdir%%$link_prefix/calendar/$view/$cal_id/$date[0]-$date[1]";
$w_item->{current} = 1;
push @$return, $w_item;
# $range following
$i = 0;
while ($i++ < $range) {
($w_year,$w_month,$w_day) = Date::Calc::Add_Delta_YMD(@date,0,$i,0);
$w_item = {};
$w_item->{date_array} = [$w_year,$w_month,1];
$w_month = ( $w_month < 10 ) ? "0$w_month" : $w_month;
$w_item->{link_url} = "%%rootdir%%$link_prefix/calendar/$view/$cal_id/$w_year-$w_month";
push @$return, $w_item;
}
} elsif ( $view eq 'weekly' ) {
# range previous
$i = $range +1;
while (--$i > 0) {
($w_year,$w_month,$w_day) = Date::Calc::Add_Delta_YMD(@date,0,0,-$i*7);
$w_item = {};
$w_item->{date_array} = [$w_year,$w_month,$w_day];
$w_month = ( $w_month < 10 ) ? "0$w_month" : $w_month;
$w_day = ( $w_day < 10 ) ? "0$w_day" : $w_day;
$w_item->{link_url} = "%%rootdir%%$link_prefix/calendar/$view/$cal_id/$w_year-$w_month-$w_day";
push @$return, $w_item;
}
# current week
$w_item = {};
$w_item->{date_array} = \@date;
$w_item->{link_url} = "%%rootdir%%$link_prefix/calendar/$view/$cal_id/$date[0]-$date[1]-$date[2]";
$w_item->{current} = 1;
push @$return, $w_item;
# $range following
$i = 0;
while ($i++ < $range) {
($w_year,$w_month,$w_day) = Date::Calc::Add_Delta_YMD(@date,0,0,$i*7);
$w_item = {};
$w_item->{date_array} = [$w_year,$w_month,$w_day];
$w_month = ( $w_month < 10 ) ? "0$w_month" : $w_month;
$w_day = ( $w_day < 10 ) ? "0$w_day" : $w_day;
$w_item->{link_url} = "%%rootdir%%$link_prefix/calendar/$view/$cal_id/$w_year-$w_month-$w_day";
push @$return, $w_item;
}
} elsif ( $view eq 'daily' ) {
# range previous
$i = $range +1;
while (--$i > 0) {
($w_year,$w_month,$w_day) = Date::Calc::Add_Delta_YMD(@date,0,0,-$i);
$w_item = {};
$w_item->{date_array} = [$w_year,$w_month,$w_day];
$w_month = ( $w_month < 10 ) ? "0$w_month" : $w_month;
$w_day = ( $w_day < 10 ) ? "0$w_day" : $w_day;
$w_item->{link_url} = "%%rootdir%%$link_prefix/calendar/$view/$cal_id/$w_year-$w_month-$w_day";
push @$return, $w_item;
}
# current week
$w_item = {};
$w_item->{date_array} = \@date;
$w_item->{link_url} = "%%rootdir%%$link_prefix/calendar/$view/$cal_id/$date[0]-$date[1]-$date[2]";
$w_item->{current} = 1;
push @$return, $w_item;
# $range following
$i = 0;
while ($i++ < $range) {
($w_year,$w_month,$w_day) = Date::Calc::Add_Delta_YMD(@date,0,0,$i);
$w_item = {};
$w_item->{date_array} = [$w_year,$w_month,$w_day];
$w_month = ( $w_month < 10 ) ? "0$w_month" : $w_month;
$w_day = ( $w_day < 10 ) ? "0$w_day" : $w_day;
$w_item->{link_url} = "%%rootdir%%$link_prefix/calendar/$view/$cal_id/$w_year-$w_month-$w_day";
push @$return, $w_item;
}
}
return $return;
}
=over 4
=item $S->_calendar_format_one_day($year,$month,$day,$view,$cal_ids)
Formats one day for use in daily, weekly, and monthly calendars. $view
parameter tells it how much detail to put in, $cal_ids is an arrayref
containing the list of calendars to look in for events.
=back
=cut
sub _calendar_format_one_day {
my $S = shift;
my @date = @_[0,1,2];
my $view = $_[3];
my $cal_ids = $_[4];
warn " (_calendar_format_one_day) formatting $date[0]-$date[1]-$date[2] for calendars " . join(',',@{$cal_ids}) if ( $cal_ids && $DEBUG );
my $keys; #hashref for interpolate()
$keys->{year} = $date[0];
$keys->{month} = $date[1];
$keys->{date_number} = $date[2];
$keys->{cal_id} = $S->cgi->param('calendar') || 0;
$keys->{hilight} = ($_[5] == 1 ) ? $S->{UI}->{BLOCKS}->{calendar_today_hilight} : ($_[5] == 2) ? $S->{UI}->{BLOCKS}->{calendar_other_month_hilight} : '';
if ( $S->cgi->param('caller_op') eq 'user' || $S->cgi->param('caller_op') =~ /^~(.+)$/ || $S->cgi->param('caller_op') eq 'my' ) {
warn "(_calendar_format_one_day) user calendar - preserving user info" if $DEBUG;
$keys->{usercal} = "/user/" . $S->get_nick_from_uid($S->cgi->param('uid'));
}
my ($events, $properties);
my $eventlist = $S->_get_days_events(@date,$cal_ids) if $cal_ids;
if ( $eventlist ) {
my $sql_eids = join(',', map { $S->{DBH}->quote($_) } @{$eventlist});
warn " (_calendar_format_one_day) getting events $sql_eids from db" if $DEBUG;
my ($rv,$sth) = $S->db_select({
DEBUG => $DEBUG,
WHAT => '*',
FROM => 'event_properties',
WHERE => qq|eid IN ($sql_eids)|
});
while ( my $tmp = $sth->fetchrow_hashref() ) {
next unless $tmp->{value};
if ($S->{EVENT_PROPERTIES}->{$tmp->{property}}->{calendar_template}) {
$properties->{$tmp->{eid}}->{$tmp->{property}} = $S->{EVENT_PROPERTIES}->{$tmp->{property}}->{calendar_template};
$properties->{$tmp->{eid}}->{$tmp->{property}} =~ s/%%value%%/$tmp->{value}/;
$properties->{$tmp->{eid}}->{$tmp->{property}} =~ s/%%eid%%/$tmp->{eid}/;
} else {
$properties->{$tmp->{eid}}->{$tmp->{property}} = $tmp->{value};
}
}
$sth->finish;
my $y = $date[0];
my $m = $date[1];
my $d = $date[2];
$m = "0$m" if $m < 10;
$d = "0$d" if $d < 10;
foreach my $eid ( @{$eventlist} ) {
warn "(_calendar_format_one_day) formatting $eid" if $DEBUG;
foreach my $prop ( keys %{$properties->{$eid}} ) {
if ($S->{EVENT_PROPERTIES}->{$prop}->{is_date} && $properties->{$eid}->{$prop} =~ /$y-$m-$d/ ) {
$properties->{$eid}->{alt_date} = $S->{EVENT_PROPERTIES}->{$prop}->{title};
warn "(_calendar_format_one_day) marking as additional date" if $DEBUG;
}
}
$events .= $S->interpolate($S->{UI}->{BLOCKS}->{"event_format_$view"}, $properties->{$eid});
}
$keys->{events} = $events;
}
return $S->interpolate($S->{UI}->{BLOCKS}->{calendar_body_one_day},$keys);
}
=over 4
=item $S->_calendar_subscribe_link();
Creates the subscribe/unsubscribe link for the current calendar, if users can
create their own personal calendar views.
=back
=cut
sub _calendar_subscribe_link {
my $S = shift;
my ($sub_link, $can_subscribe);
my $cal = $S->cgi->param('calendar');
return unless $S->var('allow_personal_calendar_view');
# no point in subscription links if we don't allow personalized views...
warn " (_calendar_subscribe_link) making link for calendar $cal" if $DEBUG;
if ( $cal ) {
# specific calendar requested
warn " (_calendar_subscribe_link) subscription to $cal is " . $S->pref("calendar_${cal}_subscribe") if $DEBUG;
if ( $S->pref("calendar_${cal}_subscribe") eq 'on' ) {
warn " (_calendar_subscribe_link) making unsubscribe link for $cal" if $DEBUG;
# already subscribed
$sub_link = $S->{UI}->{BLOCKS}->{calendar_unsubscribe_link};
} else {
warn " (_calendar_subscribe_link) making subscribe link for $cal" if $DEBUG;
$sub_link = $S->{UI}->{BLOCKS}->{calendar_subscribe_link};
}
} else {
$can_subscribe = $S->_calendar_can_view('all');
warn " (_calendar_subscribe_link) getting subscription info for calendars @$can_subscribe" if $DEBUG;
return unless ( ( ( $S->cgi->param('caller_op') eq 'user' || $S->cgi->param('caller_op') =~ /^~(.+)$/ || $S->cgi->param('caller_op') eq 'my') && $S->cgi->param('uid') == $S->{UID} ) || ( $S->cgi->param('caller_op') eq 'calendar' ));
$sub_link = $S->{UI}->{BLOCKS}->{calendar_subscribe_multi_form};
my $sql_can_sub = join(',', map { $S->{DBH}->quote($_) } @$can_subscribe);
my ($rv,$sth) = $S->db_select({
DEBUG => $DEBUG,
WHAT => 'title,cal_id',
FROM => 'calendars',
WHERE => "cal_id IN ($sql_can_sub)"
});
my ($checkboxes, $checked);
while ( my ($title,$id) = $sth->fetchrow_array() ) {
$checkboxes .= $S->{UI}->{BLOCKS}->{calendar_subscribe_item};
$checkboxes =~ s/%%cal_title%%/$title/g;
$checkboxes =~ s/%%cal_value%%/$id/g;
$checked = ( $S->pref("calendar_${id}_subscribe") eq 'on' ) ? ' CHECKED' : '';
$checkboxes =~ s/%%cal_checked%%/$checked/g;
}
$sth->finish;
$sub_link =~ s/%%calendar_checks%%/$checkboxes/;
}
return $sub_link;
}
1;
--- NEW FILE: EditCalendar.pm ---
package Scoop;
use strict;
my $DEBUG = 0;
=pod
=head1 EditCalendar.pm
This file contains the calendar creation and management functions. Anything to
do with creating calendars, managing calendar permissions, including or
excluding events from calendars, is all here.
=over 4
=item $S->edit_calendar()
This is the function for the editcalendar op. Based on the parameters it gets,
it'll let you create, moderate, and manage individual calendars.
=cut
sub edit_calendar {
my $S = shift;
my $tool = $S->cgi->param('tool') || 'settings';
my $id = $S->cgi->param('id');
my $content;
my $title;
my $msg;
$id = $S->user_calendar($S->{UID}) unless $id;
$id = '' unless $S->have_calendar_perm('edit',$id);
warn "(edit_calendar) starting..." if $DEBUG;
unless ( $S->var('allow_user_calendars') || $S->have_perm('edit_calendars' ) ) {
$S->{UI}->{BLOCKS}->{CONTENT} = "Permission Denied";
return;
}
if ( $tool eq 'moderate' ) {
unless ( $id ) {
$S->{UI}->{BLOCKS}->{CONTENT} = "Permission Denied";
return;
}
$msg = $S->_save_event_moderation($id) if $S->cgi->param('save');
$content = $S->_event_moderation_form($id);
} elsif ( $tool eq 'settings' ) {
$msg = $S->_save_calendar_settings($id) if $S->cgi->param('save');
$content = $S->_calendar_settings_form($id);
} elsif ( $tool eq 'listevents' ) {
unless ( $id ) {
$S->{UI}->{BLOCKS}->{CONTENT} = "Permission Denied";
return;
}
$content = $S->_list_events($id);
# event list...
} elsif ( $tool eq 'addevent' ) {
# will need more capable URL Template for event add/remove/etc
$content = $S->_event_addremove($id);
} elsif ( $tool eq 'invite' ) {
unless ( $id ) {
$S->{UI}->{BLOCKS}->{CONTENT} = "Permission Denied";
return;
}
$content = $S->_invitation_list('calendar',$id);
# manage which users are invited to view/submit
} else {
#error, no other tools
}
my $editcal_links = $S->{UI}->{BLOCKS}->{edit_calendar_links};
$content =~ s/%%edit_calendar_links%%/$editcal_links/;
$content =~ s/%%msg%%/$msg/;
$content =~ s/%%cal_id%%/$id/g;
$S->{UI}->{BLOCKS}->{CONTENT} = $content;
}
=over 4
=item $S->get_calendar($cal_id)
Gets the data for the calendar and returns a hashref with all the info.
=back
=cut
sub get_calendar {
my $S = shift;
my $cal_id = shift;
# my $calendar;
# my $q_id = $S->dbh->quote($cal_id);
#
# my ($rv,$sth) = $S->db_select({
# DEBUG => $DEBUG,
# WHAT => '*',
# FROM => 'calendars',
# WHERE => qq|cal_id=$q_id|
# });
# $calendar = $sth->fetchrow_hashref();
# $sth->finish;
#
# return $calendar;
return $S->{CALENDARS}->{$cal_id};
}
=head1 Private Functions
=over 4
=item $S->_event_moderation_form($id)
=back
=cut
sub _event_moderation_form {
my $S = shift;
my $cal_id = shift;
my $content = $S->{UI}->{BLOCKS}->{event_moderate};
my $q_id = $S->dbh->quote($cal_id);
my $keys;
$keys->{cal_id} = $cal_id;
my ($event,$line,$items);
my ($rv,$sth) = $S->db_select({
DEBUG => $DEBUG,
WHAT => 'events.eid',
FROM => 'events left join calendar_link using (eid)',
WHERE => qq|cal_id=$q_id AND is_primary_calendar = 1 AND displaystatus='-2'|
});
warn " (_event_moderation_form) Getting $rv events from calendar $cal_id" if $DEBUG;
while ( my ($eid) = $sth->fetchrow_array() ) {
warn " (_event_moderation_form) Processing event $eid" if $DEBUG;
$event = $S->get_event($eid);
$line = $S->{UI}->{BLOCKS}->{event_moderate_item};
$event->{owner_nick} = $S->get_nick_from_uid($event->{owner});
$event->{date_delim} = ' to ' if $event->{date_end};
$items .= $S->interpolate($line,$event);
}
$sth->finish;
$keys->{eventlist} = $items;
$content = $S->interpolate($content,$keys);
$S->{UI}->{BLOCKS}->{subtitle} = "Calendars %%bars%% Moderate Events";
return $content;
}
=over 4
=item $S->_save_event_moderation($id)
=back
=cut
sub _save_event_moderation {
my $S = shift;
my $cal_id = shift;
my $vars = $S->cgi->Vars_cloned();
return "Permission Denied" if ( $vars->{id} && $cal_id != $vars->{id} );
# if the cgi param id is set and doesn't match what's passed
# in, somebody is trying to save to a calendar they don't have
# permission to save to, by futzing with the form.
my $msg;
my $q_id = $S->dbh->quote($cal_id);
my ($where, @update_eids);
my ($rv,$sth) = $S->db_select({
DEBUG => $DEBUG,
WHAT => 'events.eid',
FROM => 'events left join calendar_link using (eid)',
WHERE => qq|calendar_link.cal_id=$q_id AND calendar_link.is_primary_calendar=1 AND displaystatus='-2'|
});
while ( my ($eid) = $sth->fetchrow_array() ) {
push @update_eids, $eid if $vars->{$eid};
}
$sth->finish();
$where = "eid IN (" . join (',', map {$S->dbh->quote($_)} (@update_eids)) . ")";
my $ds = ($vars->{action} eq 'approve') ? '0' : '-1';
map { $vars->{$_} = $S->dbh->quote($vars->{$_}) } (keys %$vars);
($rv,$sth) = $S->db_update({
DEBUG => $DEBUG,
WHAT => 'calendar_link',
SET => qq|displaystatus = $ds|,
WHERE => $where
});
if ( $rv > 0 ) {
$msg = 'Saved event moderation';
} else {
$msg = 'Error saving: database said "' . $S->dbh->errstr() . '"';
}
$sth->finish;
return $msg;
}
=over 4
=item $S->_calendar_settings_form($id)
=back
=cut
sub _calendar_settings_form {
my $S = shift;
my $cal_id = shift;
my $content = $S->{UI}->{BLOCKS}->{calendar_settings};
my $keys;
$keys = $S->get_calendar($cal_id);
warn " (_calendar_settings_form) editing calendar $cal_id" if $DEBUG;
if ( $cal_id ) {
$keys->{pagetitle} = "Edit Calendar";
} else {
$keys->{pagetitle} = "Create Calendar";
}
$keys->{view_public_checked} = ( $keys->{public_view} eq 'public' ) ? ' CHECKED' : '';
$keys->{view_invite_checked} = ( $keys->{public_view} eq 'invite' ) ? ' CHECKED' : '';
$keys->{view_private_checked} = ( $keys->{public_view} eq 'private' ) ? ' CHECKED' : '';
$keys->{submit_public_checked} = ( $keys->{public_submit} eq 'public' ) ? ' CHECKED' : '';
$keys->{submit_modpublic_checked} = ( $keys->{public_submit} eq 'modpublic' ) ? ' CHECKED' : '';
$keys->{submit_invite_checked} = ( $keys->{public_submit} eq 'invite' ) ? ' CHECKED' : '';
$keys->{submit_modinvite_checked} = ( $keys->{public_submit} eq 'modinvite' ) ? ' CHECKED' : '';
$keys->{submit_private_checked} = ( $keys->{public_submit} eq 'private' ) ? ' CHECKED' : '';
$content = $S->interpolate($content,$keys);
$S->{UI}->{BLOCKS}->{subtitle} = "Calendars %%bars%% Settings";
return $content;
}
=over 4
=item $S->_save_calendar_settings($cal_id)
=back
=cut
sub _save_calendar_settings {
my $S = shift;
my $cal_id = shift;
my $vars = $S->cgi->Vars_cloned();
return "Permission Denied" if ( $vars->{id} && $cal_id != $vars->{id} );
# if the cgi param id is set and doesn't match what's passed
# in, somebody is trying to save to a calendar they don't have
# permission to save to, by futzing with the form.
my $msg;
my $set;
map { $vars->{$_} = $S->dbh->quote($vars->{$_}) } (keys %$vars);
map { $set .= qq|$_=$vars->{$_},| } (qw(title description public_view public_submit));
$set =~ s/,$//;
my ($rv,$sth) = $S->db_update({
DEBUG => $DEBUG,
WHAT => 'calendars',
SET => $set,
WHERE => qq|cal_id=$vars->{id}|
});
$sth->finish;
if ( $rv != 1 ) {
#update failed, try insert
($rv,$sth) = $S->db_insert({
DEBUG => $DEBUG,
INTO => 'calendars',
COLS => 'cal_id,title,owner,description,public_view,public_submit',
VALUES => qq|NULL,$vars->{title},$S->{UID},$vars->{description},$vars->{public_view},$vars->{public_submit}|
});
if ( $rv == 1 ) {
#success! now subscribe the user to their new calendar
my $new_id = $S->dbh->{'mysql_insertid'};
if ( $S->var('allow_personal_calendar_view') ) {
$S->_save_pref($S->user_data($S->{UID}),"calendar_${new_id}_subscribe","on");
}
$msg = "Created Calendar";
$S->run_hook('calendar_new',$S->{UID},$new_id);
} else {
$msg = "Error saving calendar";
}
$sth->finish;
} else {
$msg = "Updated Calendar";
$S->run_hook('calendar_update',$cal_id);
}
$S->cache->stamp('calendars');
return $msg;
}
=over 4
=item $S->_list_events($cal_id)
=back
=cut
sub _list_events {
my $S = shift;
my $cal_id = shift;
my $content = $S->{UI}->{BLOCKS}->{event_list};
my ($keys,$eid,$event);
my ($item,$list);
my $page = $S->cgi->param('page') || 1;
my $limit = $S->var('storylist');
my $offset = ( ($page -1) * $limit );
warn " (_list_events) getting events for calendar $cal_id" if $DEBUG;
$keys->{cal_id} = $cal_id;
$keys->{nextpage} = $page + 1;
$keys->{prevpage} = $page - 1;
my ($rv,$sth) = $S->db_select({
DEBUG => $DEBUG,
WHAT => 'events.eid',
FROM => 'events left join calendar_link using (eid)',
WHERE => qq|calendar_link.cal_id=$cal_id|,
ORDER_BY => 'date_start DESC',
LIMIT => $limit,
OFFSET => $offset
});
if ( $rv >= $limit ) {
$keys->{nextlink} = $S->{UI}->{BLOCKS}->{next_page_link};
$keys->{nextlink} =~ s/%%LINK%%/?page=$keys->{nextpage}/;
$keys->{nextlink} =~ s/%%maxstories%%/$limit/;
}
if ( $page > 1 ) {
$keys->{prevlink} = $S->{UI}->{BLOCKS}->{prev_page_link};
$keys->{prevlink} =~ s/%%LINK%%/?page=$keys->{prevpage}/;
$keys->{prevlink} =~ s/%%maxstories%%/$limit/;
}
while ( ($eid) = $sth->fetchrow_array() ) {
warn " (_list_events) processing event $eid" if $DEBUG;
$event = $S->get_event($eid);
$item = $S->{UI}->{BLOCKS}->{event_list_item};
$event->{owner_nick} = $S->get_nick_from_uid($event->{owner});
# background colours to show status
if ( $event->{displaystatus} == '-1' ) {
$event->{event_bg} = $S->{UI}->{BLOCKS}->{undisplayedstory_bg};
} elsif ( $event->{displaystatus} == '-2' ) {
$event->{event_bg} = $S->{UI}->{BLOCKS}->{editqueuestory_bg};
} elsif ( $event->{cal_id} == $cal_id ) {
$event->{event_bg} = '';
} else {
$event->{event_bg} = $S->{UI}->{BLOCKS}->{story_mod_bg};
}
# actions
if ( $event->{cal_id} == $cal_id ) {
$event->{actions} .= $S->{UI}->{BLOCKS}->{event_list_action_edit};
if ( $event->{displaystatus} == '-2' ) {
$event->{actions} .= $S->{UI}->{BLOCKS}->{event_list_action_approve};
}
} else {
$event->{actions} .= $S->{UI}->{BLOCKS}->{event_list_action_remove};
$event->{cal_id} = $cal_id; # gotta make sure the right calendar is removed!
}
$item =~ s/%%actions%%/$event->{actions}/;
$list .= $S->interpolate($item,$event);
}
$sth->finish;
$keys->{eventlist} = $list;
$keys->{title} = $S->_calendar_title($cal_id);
$content = $S->interpolate($content,$keys);
$S->{UI}->{BLOCKS}->{subtitle} = "Calendars %%bars%% List Events";
return $content;
}
=over 4
=item $S->_event_addremove($cal_id)
=back
=cut
sub _event_addremove {
my $S = shift;
my $cal_id = shift;
my $eid = $S->cgi->param('eid');
my $action = $S->cgi->param('action');
my $keys;
my $content = $S->{UI}->{BLOCKS}->{event_addremove};
if ( $action eq 'add' ) {
my ($rv,$sth) = $S->db_insert({
DEBUG => $DEBUG,
INTO => 'calendar_link',
COLS => 'eid,cal_id,is_primary_calendar',
VALUES => qq|$eid,$cal_id,'0'|
});
if ( $rv != 1 ) {
$keys->{msg} = qq|Error adding event $eid to calendar $cal_id: database said "| . $S->dbh->errstr() . '"';
}
$sth->finish;
} elsif ( $action eq 'remove' ) {
my ($rv,$sth) = $S->db_delete({
DEBUG => $DEBUG,
FROM => 'calendar_link',
WHERE => qq|eid=$eid AND cal_id=$cal_id|
});
if ( $rv != 1 ) {
$keys->{msg} = qq|Error removing event $eid from calendar $cal_id: database said "| . $S->dbh->errstr() . '"';
}
$sth->finish;
} else {
$keys->{msg} = "invalid command";
}
if ($keys->{msg}) {
# there was an error
return $S->interpolate($content,$keys);
} else {
# back to where we came from
$S->{APACHE}->headers_out->{'Location'} = $S->{REFERER};
}
}
=over 4
=item $S->_invitation_list($type,$id)
=back
=cut
sub _invitation_list {
my $S = shift;
my $type = shift;
my $id = shift;
my $action = $S->cgi->param('action');
my ($rv,$sth);
my ($content,$keys);
$keys->{id} = $id;
# save any changes ($action contains which list (submit/view) was changed)
if ( $action =~ /_add$/ ) {
my $uid = $S->get_uid_from_nick($S->cgi->param('nick'));
my ($list,$act) = split(/_/,$action);
warn " (_invitation_list) adding uid $uid to $type $id $list" if $DEBUG;
my $rv = $S->_save_pref($S->user_data($uid),"${type}_${id}_$list",'on');
$keys->{msg} .= "Added " . $S->cgi->param('nick') . " to $list list" if ( $rv =~ /saved/i );
} elsif ( $action =~ /_remove$/ ) {
my $uid = $S->get_uid_from_nick($S->cgi->param('nick'));
my ($list,$act) = split(/_/,$action);
warn " (_invitation_list) adding uid $uid to $type $id $list" if $DEBUG;
my $rv = $S->_save_pref($S->user_data($uid),"${type}_${id}_$list",'off');
$keys->{msg} .= "Removed " . $S->cgi->param('nick') . " from $list list" if ( $rv =~ /saved/i );
}
warn " (_invitation_list) getting info from $type $id" if $DEBUG;
if ( $type eq 'calendar' ) {
$keys->{op} = 'editcalendar';
$content = $S->{UI}->{BLOCKS}->{calendar_invitations};
($rv,$sth) = $S->db_select({
DEBUG => $DEBUG,
WHAT => '*',
FROM => 'calendars',
WHERE => "cal_id = $id"
});
my $calendar = $sth->fetchrow_hashref();
$sth->finish;
warn " (_invitation_list) calendar $id has view permission $calendar->{public_view}, submit permission $calendar->{public_submit}" if $DEBUG;
if ( $calendar->{public_view} ne 'private' ) {
# it is invite-only
warn " (_invitation_list) checking for people invited to view calendar $id" if $DEBUG;
($rv,$sth) = $S->db_select({
DEBUG => $DEBUG,
WHAT => 'uid',
FROM => 'userprefs',
WHERE => qq|prefname = 'calendar_${id}_invite' && prefvalue = 'on'|
});
if ( $rv == 0 ) {
# nobody invited yet
$keys->{view_list} = 'Nobody has been invited yet';
} else {
# list of invitees
while ( my ($uid) = $sth->fetchrow_array() ) {
my $user_keys;
$user_keys->{op} = 'editcalendar';
my $item = $S->{UI}->{BLOCKS}->{calendar_invitations_item};
$user_keys->{uid} = $uid;
$user_keys->{nickname} = $S->get_nick_from_uid($uid);
$user_keys->{urlnick} = $S->urlify($user_keys->{nickname});
$user_keys->{list} = 'invite';
$keys->{view_list} .= $S->interpolate($item,$user_keys);
}
}
$sth->finish;
# invitee add form
$keys->{view_add} = $S->{UI}->{BLOCKS}->{calendar_invitations_add};
$keys->{view_add} =~ s/%%list%%/invite/;
$keys->{view_add} =~ s/%%op%%/editcalendar/;
} else {
# it is not invite-only
$keys->{view_list} = 'This calendar is not visible to anybody else';
$keys->{view_add} = '';
}
if ( $calendar->{public_submit} =~ /invite$/ ) {
# it is invite-only
warn " (_invitation_list) checking for people invited to submit to calendar $id" if $DEBUG;
($rv,$sth) = $S->db_select({
DEBUG => $DEBUG,
WHAT => 'uid',
FROM => 'userprefs',
WHERE => qq|prefname = 'calendar_${id}_submit' && prefvalue = 'on'|
});
if ( $rv == 0 ) {
# nobody invited yet
$keys->{submit_list} = 'Nobody has been invited yet';
} else {
# list of invitees
while ( my ($uid) = $sth->fetchrow_array() ) {
my $user_keys;
$user_keys->{op} = 'editcalendar';
my $item = $S->{UI}->{BLOCKS}->{calendar_invitations_item};
$user_keys->{uid} = $uid;
$user_keys->{nickname} = $S->get_nick_from_uid($uid);
$user_keys->{urlnick} = $S->urlify($user_keys->{nickname});
$user_keys->{list} = 'submit';
$keys->{submit_list} .= $S->interpolate($item,$user_keys);
}
}
$sth->finish;
# invitee add form
$keys->{submit_add} = $S->{UI}->{BLOCKS}->{calendar_invitations_add};
$keys->{submit_add} =~ s/%%list%%/submit/;
$keys->{submit_add} =~ s/%%op%%/editcalendar/;
} else {
# it is not invite-only
$keys->{submit_list} = 'This calendar does not require an invitation for event submission';
$keys->{submit_add} = '';
}
} elsif ( $type eq 'event' ) {
my $event = $S->get_event($id);
$content = $S->{UI}->{BLOCKS}->{event_invitations};
warn " (_invitation_list) event $id has view permission $event->{public_view}" if $DEBUG;
if ( $event->{public_view} ne 'private' ) {
# it is invite-only
($rv,$sth) = $S->db_select({
DEBUG => $DEBUG,
WHAT => 'uid',
FROM => 'userprefs',
WHERE => qq|prefname = 'event_${id}_invite' && prefvalue = 'on'|
});
if ( $rv == 0 ) {
# nobody invited yet
$keys->{view_list} = 'Nobody has been invited yet';
} else {
# list of invitees
while ( my ($uid) = $sth->fetchrow_array() ) {
my $user_keys;
$user_keys->{op} = 'submitevent';
my $item = $S->{UI}->{BLOCKS}->{calendar_invitations_item};
$user_keys->{uid} = $uid;
$user_keys->{nickname} = $S->get_nick_from_uid($uid);
$user_keys->{urlnick} = $S->urlify($user_keys->{nickname});
$user_keys->{list} = 'invite';
$user_keys->{cal_id} = $id;
$keys->{view_list} .= $S->interpolate($item,$user_keys);
}
}
$sth->finish;
# invitee add form
$keys->{view_add} = $S->{UI}->{BLOCKS}->{calendar_invitations_add};
$keys->{view_add} =~ s/%%list%%/invite/;
$keys->{view_add} =~ s/%%op%%/submitevent/;
$keys->{view_add} =~ s/%%cal_id%%/$id/;
} else {
$keys->{view_list} = 'This event is private';
$keys->{view_add} = '';
}
if ( $event->{public_submit} eq 'invite' ) {
# it is invite-only
warn " (_invitation_list) checking for people invited to submit to event $id" if $DEBUG;
($rv,$sth) = $S->db_select({
DEBUG => $DEBUG,
WHAT => 'uid',
FROM => 'userprefs',
WHERE => qq|prefname = 'event_${id}_submit' && prefvalue = 'on'|
});
if ( $rv == 0 ) {
# nobody invited yet
$keys->{submit_list} = 'Nobody has been invited yet';
} else {
# list of invitees
while ( my ($uid) = $sth->fetchrow_array() ) {
my $user_keys;
$user_keys->{op} = 'submitevent';
my $item = $S->{UI}->{BLOCKS}->{calendar_invitations_item};
$user_keys->{uid} = $uid;
$user_keys->{nickname} = $S->get_nick_from_uid($uid);
$user_keys->{urlnick} = $S->urlify($user_keys->{nickname});
$user_keys->{list} = 'submit';
$user_keys->{cal_id} = $id;
$keys->{submit_list} .= $S->interpolate($item,$user_keys);
}
}
$sth->finish;
# invitee add form
$keys->{submit_add} = $S->{UI}->{BLOCKS}->{calendar_invitations_add};
$keys->{submit_add} =~ s/%%list%%/submit/;
$keys->{submit_add} =~ s/%%op%%/submitevent/;
$keys->{submit_add} =~ s/%%cal_id%%/$id/;
} else {
# it is not invite-only
$keys->{submit_list} = 'This event does not require an invitation for story submission';
$keys->{submit_add} = '';
}
}
return $S->interpolate($content,$keys);
}
=over 4
=item $S->_make_user_invite_list($item_tmpl,$uids)
Builds a list using whatever $item_tmpl (template) you provide it once for each
user in the $uids arrayref.
Supports uid, nickname, urlnick.
=back
=cut
sub _make_user_invite_list {
my $S = shift;
my $item_tmpl = shift;
my $uids = shift;
my $page;
foreach my $uid (@$uids) {
}
return $page;
}
1;