File Coverage

blib/lib/Labyrinth/Plugin/Event/Talks.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             package Labyrinth::Plugin::Event::Talks;
2              
3 3     3   12343 use warnings;
  3         5  
  3         90  
4 3     3   10 use strict;
  3         3  
  3         77  
5              
6 3     3   10 use vars qw($VERSION);
  3         4  
  3         156  
7             $VERSION = '1.10';
8              
9             =head1 NAME
10              
11             Labyrinth::Plugin::Event::Talks - Event Talk handler for the Labyrinth framework.
12              
13             =head1 DESCRIPTION
14              
15             Contains all the event talk functionality for Labyrinth.
16              
17             =cut
18              
19             # -------------------------------------
20             # Library Modules
21              
22 3     3   11 use base qw(Labyrinth::Plugin::Base);
  3         3  
  3         1847  
23              
24             use Clone qw(clone);
25              
26             use Labyrinth::DBUtils;
27             use Labyrinth::MLUtils;
28             use Labyrinth::Session;
29             use Labyrinth::Support;
30             use Labyrinth::Users;
31             use Labyrinth::Variables;
32              
33             # -------------------------------------
34             # Variables
35              
36             # type: 0 = optional, 1 = mandatory
37             # html: 0 = none, 1 = text, 2 = textarea
38              
39              
40             my %fields = (
41             eventid => { type => 1, html => 0 },
42             talkid => { type => 0, html => 0 },
43             userid => { type => 1, html => 0 },
44             guest => { type => 0, html => 0 },
45             talktitle => { type => 1, html => 1 },
46             abstract => { type => 1, html => 2 },
47             resource => { type => 0, html => 2 },
48             );
49              
50             my (@mandatory,@allfields);
51             for(keys %fields) {
52             push @mandatory, $_ if($fields{$_}->{type});
53             push @allfields, $_;
54             }
55              
56             # -------------------------------------
57             # The Subs
58              
59             =head1 ADMIN INTERFACE METHODS
60              
61             =over 4
62              
63             =item Admin
64              
65             Provides list of the talks currently available.
66              
67             =item Add
68              
69             Add a new talk.
70              
71             =item Edit
72              
73             Edit an existing talk.
74              
75             =item Save
76              
77             Save the current talk.
78              
79             =item Delete
80              
81             Delete a talk.
82              
83             =item EventSelect
84              
85             Provides a dropdown list of events available.
86              
87             =back
88              
89             =cut
90              
91             sub Admin {
92             return unless AccessUser(EDITOR);
93              
94             if($cgiparams{doaction}) {
95             if($cgiparams{doaction} eq 'Delete') { Delete(); }
96             }
97              
98             my @rows = $dbi->GetQuery('hash','AllTechTalks');
99             $tvars{data} = \@rows if(@rows);
100             }
101              
102             sub Add {
103             my $self = shift;
104              
105             return unless AccessUser(EDITOR);
106             return unless AuthorCheck('GetEventByID','eventid',EDITOR);
107              
108             $tvars{data}{ddusers} = UserSelect(0,1,0,'Speaker',1);
109             $tvars{data}{ddevents} = $self->EventSelect($cgiparams{eventid});
110             }
111              
112             sub Edit {
113             my $self = shift;
114              
115             return unless AccessUser(EDITOR);
116             return unless AuthorCheck('GetEventByID','eventid',EDITOR);
117              
118             if($cgiparams{talkid}) {
119             my @rows = $dbi->GetQuery('hash','GetTechTalkByID',$cgiparams{talkid});
120             $tvars{data} = $rows[0] if(@rows);
121             $tvars{data}{abstracted} = $tvars{data}{abstract};
122             $tvars{data}{resourced} = $tvars{data}{resource};
123             $cgiparams{eventid} ||= $tvars{data}{eventid};
124             }
125              
126             my $opt = $cgiparams{talkid} ? $tvars{data}{userid} : 0;
127             $tvars{data}{ddusers} = UserSelect($opt,1,0,'Speaker',1);
128             $tvars{data}{ddevents} = $self->EventSelect($cgiparams{eventid});
129             }
130              
131             sub Save {
132             return unless AccessUser(EDITOR);
133             return unless AuthorCheck('GetEventByID','eventid',EDITOR);
134              
135             my $opt = $cgiparams{talkid} ? $tvars{data}{userid} : 0;
136             $tvars{data}{ddusers} = UserSelect($opt,1,0,'Speaker',1);
137              
138             return if FieldCheck(\@allfields,\@mandatory);
139              
140             $tvars{data}{guest} = ($tvars{data}{guest} ? 1 : 0);
141             for(keys %fields) {
142             next unless($fields{$_});
143             if($fields{$_}->{html} == 1) { $tvars{data}{$_} = CleanHTML($tvars{data}{$_}) }
144             elsif($fields{$_}->{html} == 2) { $tvars{data}{$_} = CleanTags($tvars{data}{$_}) }
145             }
146              
147              
148             my @fields = ( $tvars{data}{eventid},
149             $tvars{data}{userid},
150             $tvars{data}{guest},
151             $tvars{data}{talktitle},
152             $tvars{data}{abstract},
153             $tvars{data}{resource}
154             );
155              
156             if($cgiparams{talkid})
157             { $dbi->DoQuery('SaveTechTalk',@fields,$cgiparams{talkid}); }
158             else { $cgiparams{talkid} = $dbi->IDQuery('AddTechTalk',@fields); }
159             }
160              
161             sub Delete {
162             return unless AccessUser(ADMIN);
163             my @ids = CGIArray('LISTED');
164             return unless @ids;
165              
166             for my $id (@ids) {
167             $cgiparams{'talkid'} = $id;
168             next unless AuthorCheck('GetTechTalkByID','talkid',EDITOR);
169              
170             $dbi->DoQuery('DeleteTechTalk',$cgiparams{'talkid'});
171             }
172             }
173              
174             sub EventSelect {
175             my ($self,$opt,$blank) = @_;
176             $blank ||= 0;
177              
178             my @list;
179             my @rows = $dbi->GetQuery('hash','AllTalkEvents');
180             for(@rows) { push @list, { id => $_->{eventid}, value => $_->{eventdate} . ' - ' . $_->{title} }; }
181             unshift @list, { id => 0, value => 'Select Event'} if($blank == 1);
182             DropDownRows($opt,'eventid','id','value',@list);
183             }
184              
185             1;
186              
187             __END__