CalendarMonthDB.pm untested

filter: Statementstmt 0.0% 0 / 537 Branchbran 0.0% 0 / 220 Conditioncond 0.0% 0 / 186 MC/DCmcdc 0.0% 0 / 116 Subroutinesub 0.0% 0 / 50 Podpod 0.0% 0 / 47 totaltotal 0.0% 0 / 1156 CC 111 SCAR 50.8
CC
111
Cov
0%
editdbcalendar
506.0
getdbcalendar
462.0
as_HTML
156.0
CRAP 160.2
1 # HTML::CalendarMonthDB.pm
2 # Generate persistant or non-persistant HTML calendars.
3 # An alternative to HTML::CalendarMonth and HTML::CalendarMonthSimple
4 # Herein, the symbol $self is used to refer to the object that's being passed around.
5  
6 package HTML::CalendarMonthDB;
7 my $VERSION = "1.0";
8 use strict;
9 use Date::Calc;
10  
11 # Within the constructor is the only place where values are access directly.
12 # Methods are provided for accessing/changing values, and those methods
13 # are used even internally.
14 # Most of the constructor is assigning default values.
15 sub new {
16 my $class = shift; $class = ref($class) || $class;
17 my $self = {}; %$self = @_; # Load ourselves up from the args
18  
19 # Set the month and year to either args or today
20 ($self->{'month'}) || ($self->{'month'} = (Date::Calc::Today)[1]);
21 ($self->{'year'}) || ($self->{'year'} = (Date::Calc::Today)[0]);
22  
23 # Some defaults
24 $self->{'border'} = 5;
25 $self->{'width'} = '100%';
26 $self->{'showdatenumbers'} = 1;
27 $self->{'showweekdayheaders'} = 1;
28 $self->{'cellalignment'} = 'left';
29 $self->{'bgcolor'} = 'ffffff';
30  
31 if ($self->{'dbname'}) {
32 use DBI;
33 # det defaults
34 ($self->{'dbuser'}) || ($self->{'dbuser'} = 'nobody');
35 ($self->{'dbpass'}) || ($self->{'dbpass'} = '');
36 ($self->{'dbcalendar'}) || ($self->{'dbcalendar'} = '');
37 ($self->{'dbclient'}) || ($self->{'dbclient'} = '');
38 ($self->{'dbhost'}) || ($self->{'dbhost'} = '');
39 }
40  
41  
42 # Set the default calendar header
43 $self->{'header'} = sprintf("<center><font size=+2>%s %d</font></center>",
44 Date::Calc::Month_to_Text($self->{'month'}),$self->{'year'});
45  
46 # Get the monthname now so monthname() is fast and efficient
47 $self->{'monthname'} = Date::Calc::Month_to_Text($self->{'month'});
48  
49 # Initialize the (empty) cell content so the keys are representative of the month
50 map { $self->{'content'}->{$_} = ''; } (1 .. Date::Calc::Days_in_Month($self->{'year'},$self->{'month'}));
51 # Initialize the non-standard date buckets: weekdays, etc.
52 foreach my $day ('sunday','monday','tuesday','wednesday','thursday','friday','saturday') {
53 $self->{'content'}->{$day."s"} = ''; # "Mondays", "Tuesdays", etc.
54 foreach my $which (1 .. 5) { $self->{'content'}->{$which.$day} = ''; } # "2Sunday", "3Wednesday", etc.
55 }
56  
57 # All done!
58 bless $self,$class; return $self;
59 }
60  
61 sub as_HTML_list {
62 my $self = shift;
63 my $self1 = {}; %$self1 = @_; # Load ourselves up from the args
64 my $editurl = $self1->{'editurl'} if $self1->{'editurl'};
65 my $addurl = $self1->{'addurl'} if $self1->{'addurl'};
66 my $html = '';
67 my(@days,$weeks,$WEEK,$DAY);
68  
69 my $border = $self->border();
70 my $tablewidth = $self->width();
71 my $header = $self->header();
72 my $bgcolor = $self->bgcolor() || '';
73 my $cellalignment = $self->cellalignment();
74 my $weekdaycolor = $self->weekdaycolor() || $self->bgcolor();
75 my $weekendcolor = $self->weekendcolor() || $self->bgcolor();
76 my $todaycolor = $self->todaycolor() || $self->bgcolor();
77 my $contentcolor = $self->contentcolor() || $self->contentcolor();
78 my $weekdaycontentcolor = $self->weekdaycontentcolor() || $self->contentcolor();
79 my $weekendcontentcolor = $self->weekendcontentcolor() || $self->contentcolor();
80 my $todaycontentcolor = $self->todaycontentcolor() || $self->contentcolor();
81 my $bordercolor = $self->bordercolor() || $self->bordercolor();
82 my $weekdaybordercolor = $self->weekdaybordercolor() || $self->bordercolor();
83 my $weekendbordercolor = $self->weekendbordercolor() || $self->bordercolor();
84 my $todaybordercolor = $self->todaybordercolor() || $self->bordercolor();
85 my $weekdayheadercolor = $self->weekdayheadercolor() || $self->bgcolor();
86 my $weekendheadercolor = $self->weekendheadercolor() || $self->bgcolor();
87 my $headercolor = $self->headercolor() || $self->bgcolor();
88 # Get today's date, in case there's a todaycolor()
89 my($todayyear,$todaymonth,$todaydate) = Date::Calc::Today();
90  
91  
92 # add javascript popup description code
93 $html .= $self->jscode();
94  
95 @days = (1 .. Date::Calc::Days_in_Month($self->year(),$self->month() ) );
96 foreach (1 .. (Date::Calc::Day_of_Week($self->year(),$self->month(),1)%7) ) {
97 unshift(@days,0);
98 }
99 $weeks = int((scalar(@days)+6)/7);
100  
101 $html .= "<table width=\"$tablewidth\" border=\"$border\" bgcolor=\"$bgcolor\" bordercolor=\"$bordercolor\"><tr><td colspan=2 bgcolor=\"$headercolor\">$header</td></tr>";
102
103 foreach $WEEK (0 .. ($weeks-1)) {
104 foreach $DAY (0 .. 6) {
105 my($content,$thisday,$thisbgcolor,$thisbordercolor,$thiscontentcolor);
106 $thisday = $days[((7*$WEEK)+$DAY)];
107 if ($thisday) {
108 $content=$self->getcontent($thisday);
109 if ($self->year == $todayyear && $self->month == $todaymonth && $thisday == $todaydate)
110 { $thisbgcolor = $todaycolor;
111 $thisbordercolor = $todaybordercolor;
112 $thiscontentcolor = $todaycontentcolor;
113 }
114 elsif (($DAY == 0) || ($DAY == 6)){ $thisbgcolor = $weekendcolor;
115 $thisbordercolor = $weekendbordercolor;
116 $thiscontentcolor = $weekendcontentcolor;
117 }
118 else { $thisbgcolor = $weekdaycolor;
119 $thisbordercolor = $weekdaybordercolor;
120 $thiscontentcolor = $weekdaycontentcolor;
121 }
122  
123
124 if (!$content) {
125 $content = '&nbsp;';
126 }
127 $html .= "<tr><td width=\"2%\"><b>$thisday</b>";
128 # Add admin links if specified in function call
129 if ($addurl) {
130 my $calid = $self->calendarid();
131 my $mdate = $self->month().'_'.$thisday.'_'.$self->year();
132 $html .= "<br><font size=\"1\"><a href=\"#\" onclick=popup(\"$addurl?date=$mdate&calid=$calid&view=list\")>[Add]</a></font>";
133 }
134 if ($editurl) {
135 my $calid = $self->calendarid();
136 my $mdate = $self->month().'_'.$thisday.'_'.$self->year();
137 $html .= "<br><font size=\"1\"><a href=\"#\" onclick=popup(\"$editurl?date=$mdate&calid=$calid&view=list\")>[Edit]</a></font>";
138 }
139 $html .= "</td><td bgcolor=\"$thisbgcolor\" bordercolor=\"$thisbordercolor\" align=\"$cellalignment\"><font color=\"$thiscontentcolor\">$content</font></td></tr>\n";
140 }
141 }
142 }
143 $html .= '</table>';
144 return $html;
145 }
146  
147 sub as_HTML {
148 my $self = shift;
149 my $self1 = {}; %$self1 = @_; # Load ourselves up from the args
150 my $editurl = $self1->{'editurl'} if $self1->{'editurl'};
151 my $addurl = $self1->{'addurl'} if $self1->{'addurl'};
152 my $html = '';
153 my(@days,$weeks,$WEEK,$DAY);
154
155 # add javascript popup description code
156 $html .= $self->jscode();
157  
158 # To make the grid even, pad the start of the series with 0s
159 @days = (1 .. Date::Calc::Days_in_Month($self->year(),$self->month() ) );
160 foreach (1 .. (Date::Calc::Day_of_Week($self->year(),$self->month(),1)%7) ) {
161 unshift(@days,0);
162 }
163 $weeks = int((scalar(@days)+6)/7);
164  
165 # Define some scalars for generating the table
166 my $border = $self->border();
167 my $tablewidth = $self->width();
168 $tablewidth =~ m/^(\d+)(\%?)$/; my $cellwidth = (int($1/7))||'14'; if ($2) { $cellwidth .= '%'; }
169 my $header = $self->header();
170 my $cellalignment = $self->cellalignment();
171 my $bgcolor = $self->bgcolor() || '';
172 my $weekdaycolor = $self->weekdaycolor() || $self->bgcolor();
173 my $weekendcolor = $self->weekendcolor() || $self->bgcolor();
174 my $todaycolor = $self->todaycolor() || $self->bgcolor();
175 my $contentcolor = $self->contentcolor() || $self->contentcolor();
176 my $weekdaycontentcolor = $self->weekdaycontentcolor() || $self->contentcolor();
177 my $weekendcontentcolor = $self->weekendcontentcolor() || $self->contentcolor();
178 my $todaycontentcolor = $self->todaycontentcolor() || $self->contentcolor();
179 my $bordercolor = $self->bordercolor() || $self->bordercolor();
180 my $weekdaybordercolor = $self->weekdaybordercolor() || $self->bordercolor();
181 my $weekendbordercolor = $self->weekendbordercolor() || $self->bordercolor();
182 my $todaybordercolor = $self->todaybordercolor() || $self->bordercolor();
183 my $weekdayheadercolor = $self->weekdayheadercolor() || $self->bgcolor();
184 my $weekendheadercolor = $self->weekendheadercolor() || $self->bgcolor();
185 my $headercolor = $self->headercolor() || $self->bgcolor();
186 # Get today's date, in case there's a todaycolor()
187 my($todayyear,$todaymonth,$todaydate) = Date::Calc::Today();
188  
189 $html .= "<TABLE BORDER=\"$border\" WIDTH=\"$tablewidth\" BGCOLOR=\"$bgcolor\" BORDERCOLOR=\"$bordercolor\">\n";
190 $html .= "<tr><td colspan=7 bgcolor=\"$headercolor\">$header</td></tr>\n" if $header;
191 if ($self->showweekdayheaders) {
192 # Ultimately, this will display a hashref contents instead of a static week...
193 #$html .= "<tr>\n<th>Sunday</th>\n<th>Monday</th>\n<th>Tuesday</th>\n<th>Wednesday</th>\n<th>Thursday</th>\n<th>Friday</th>\n<th>Saturday</th>\n</tr>\n";
194 $html .= "<tr>\n<th bgcolor=\"$weekendheadercolor\">Sunday</th>\n<th bgcolor=\"$weekdayheadercolor\">Monday</th>\n<th bgcolor=\"$weekdayheadercolor\">Tuesday</th>\n<th bgcolor=\"$weekdayheadercolor\">Wednesday</th>\n<th bgcolor=\"$weekdayheadercolor\">Thursday</th>\n<th bgcolor=\"$weekdayheadercolor\">Friday</th>\n<th bgcolor=\"$weekendheadercolor\">Saturday</th>\n</tr>\n";
195 }
196 foreach $WEEK (0 .. ($weeks-1)) {
197 $html .= "<TR>\n";
198 foreach $DAY (0 .. 6) {
199 my($thiscontent,$thisday,$thisbgcolor,$thisbordercolor,$thiscontentcolor);
200 $thisday = $days[((7*$WEEK)+$DAY)];
201 # Get the cell content
202 if (! $thisday) { # If it's a dummy cell, no content
203 $thiscontent = '&nbsp;'; }
204 else { # A real date cell with potential content
205 # Get the content
206 if ($self->showdatenumbers()) {
207 $thiscontent = "<p><b>$thisday</b>";
208
209 # Add admin links if specified in function call
210 if ($addurl) {
211 my $calid = $self->calendarid();
212 my $mdate = $self->month().'_'.$thisday.'_'.$self->year();
213 $thiscontent .= " <font size=\"1\"><a href=\"#\" onclick=popup(\"$addurl?date=$mdate&calid=$calid&view=standard\")>[Add]</a></font>";
214 }
215 if ($editurl) {
216 my $calid = $self->calendarid();
217 my $mdate = $self->month().'_'.$thisday.'_'.$self->year();
218 $thiscontent .= " <font size=\"1\"><a href=\"#\" onclick=popup(\"$editurl?date=$mdate&calid=$calid&view=standard\")>[Edit]</a></font>";
219 }
220 $thiscontent .= "</p>\n";
221 }
222 # Content for this specific date
223 $thiscontent .= $self->getcontent($thisday);
224 # Content for "2nd Wednesday", etc.
225 $thiscontent .= $self->getcontent(int(1+($thisday/7.1)).('sunday','monday','tuesday','wednesday','thursday','friday','saturday')[$DAY]);
226 # Content for "Wednesdays", etc.
227 $thiscontent .= $self->getcontent(('sundays','mondays','tuesdays','wednesdays','thursdays','fridays','saturdays')[$DAY]);
228 # Normalize if there's no content
229 $thiscontent .= '&nbsp;';
230 }
231 # Get the cell's coloration
232 if ($self->year == $todayyear && $self->month == $todaymonth && $thisday == $todaydate)
233 { $thisbgcolor = $todaycolor;
234 $thisbordercolor = $todaybordercolor;
235 $thiscontentcolor = $todaycontentcolor;
236 }
237 elsif (($DAY == 0) || ($DAY == 6)) { $thisbgcolor = $weekendcolor;
238 $thisbordercolor = $weekendbordercolor;
239 $thiscontentcolor = $weekendcontentcolor;
240 }
241 else { $thisbgcolor = $weekdaycolor;
242 $thisbordercolor = $weekdaybordercolor;
243 $thiscontentcolor = $weekdaycontentcolor;
244 }
245 # Done with this cell - push it into the table
246 $html .= "<TD WIDTH=\"$cellwidth\" VALIGN=\"$cellalignment\" ALIGN=\"$cellalignment\" BGCOLOR=\"$thisbgcolor\" BORDERCOLOR=\"$thisbordercolor\"><FONT COLOR=\"$thiscontentcolor\">$thiscontent</FONT></TD>\n";
247 }
248 $html .= "</TR>\n";
249 }
250 $html .= "</TABLE>\n";
251 return $html;
252 }
253  
254 sub jscode {
255 my $self = shift;
256 my $jscode = '<div id="object1" style="position:absolute; visibility:show; left:350px; top:-50px; z-index:2">layer hidden off the screen</div><SCRIPT LANGUAGE="JavaScript">
257 <!-- Begin
258 window.onLoad=setupDescriptions();
259 function popup(url) {
260 window.open(url, "popup", "height=480,width=580,menubar=no,scrollbars=yes,status=no,toolbar=no,screenX=100,screenY=0,left=100,top=100");
261 }
262 function setupDescriptions() {
263 var x = navigator.appVersion;
264 y = x.substring(0,4);
265 if (y>=4) setVariables();
266 }
267 var x,y,a,b;
268 function setVariables(){
269 if (navigator.appName == "Netscape") {
270 h=".left=";
271 v=".top=";
272 dS="document.";
273 sD="";
274 }
275 else
276 {
277 h=".pixelLeft=";
278 v=".pixelTop=";
279 dS="";
280 sD=".style";
281 }
282 }
283 var isNav = (navigator.appName.indexOf("Netscape") !=-1);
284 function popLayer(a){
285 var popWidth;
286 if(isNav) {
287 if ((window.innerWidth - x) > (window.innerWidth/2)) {
288 popWidth = window.innerWidth/2;
289 }
290 else {
291 popWidth = window.innerWidth - x - 40;
292 }
293 }
294 else {
295 if ((document.body.clientWidth - x) > (document.body.clientWidth/2)) {
296 popWidth = document.body.clientWidth/2;
297 }
298 else {
299 popWidth = document.body.clientWidth - x - 40;
300 }
301 }
302 desc = "<table cellpadding=3 border=1 bgcolor=ffff11 width=" + popWidth + "><td align=center>";'.$self->jsDescs.'
303 desc += "</td></table>";
304  
305 if(isNav) {
306 document.object1.document.write(desc);
307 document.object1.document.close();
308 document.object1.left=x+5;
309 document.object1.top=y;
310 }
311 else {
312 object1.innerHTML=desc;
313 eval(dS+"object1"+sD+h+(x+5));
314 eval(dS+"object1"+sD+v+y);
315 }
316 }
317 function hideLayer(a){
318 if(isNav) {
319 eval(document.object1.top=a);
320 }
321 else object1.innerHTML="";
322 }
323 function handlerMM(e){
324 x = (isNav) ? e.pageX : event.clientX;
325 y = (isNav) ? e.pageY : event.clientY;
326 }
327 if (isNav){
328 document.captureEvents(Event.MOUSEMOVE);
329 }
330 document.onmousemove = handlerMM;
331 // End -->
332 </script>';
333  
334 $self->{'jscode'} = $jscode;
335  
336 return $self->{'jscode'};
337 }
338  
339 sub weekendcolor {
340 my $self = shift;
341 my $newvalue = shift;
342 if (defined($newvalue)) { $self->{'weekendcolor'} = $newvalue; }
343 return $self->{'weekendcolor'};
344 }
345  
346 sub weekendheadercolor {
347 my $self = shift;
348 my $newvalue = shift;
349 if (defined($newvalue)) { $self->{'weekendheadercolor'} = $newvalue; }
350 return $self->{'weekendheadercolor'};
351 }
352  
353 sub weekdayheadercolor {
354 my $self = shift;
355 my $newvalue = shift;
356 if (defined($newvalue)) { $self->{'weekdayheadercolor'} = $newvalue; }
357 return $self->{'weekdayheadercolor'};
358 }
359  
360 sub weekdaycolor {
361 my $self = shift;
362 my $newvalue = shift;
363 if (defined($newvalue)) { $self->{'weekdaycolor'} = $newvalue; }
364 return $self->{'weekdaycolor'};
365 }
366  
367 sub headercolor {
368 my $self = shift;
369 my $newvalue = shift;
370 if (defined($newvalue)) { $self->{'headercolor'} = $newvalue; }
371 return $self->{'headercolor'};
372 }
373  
374 sub bgcolor {
375 my $self = shift;
376 my $newvalue = shift;
377 if (defined($newvalue)) { $self->{'bgcolor'} = $newvalue; }
378 return $self->{'bgcolor'};
379 }
380  
381 sub todaycolor {
382 my $self = shift;
383 my $newvalue = shift;
384 if (defined($newvalue)) { $self->{'todaycolor'} = $newvalue; }
385 return $self->{'todaycolor'};
386 }
387  
388 sub bordercolor {
389 my $self = shift;
390 my $newvalue = shift;
391 if (defined($newvalue)) { $self->{'bordercolor'} = $newvalue; }
392 return $self->{'bordercolor'};
393 }
394  
395 sub weekdaybordercolor {
396 my $self = shift;
397 my $newvalue = shift;
398 if (defined($newvalue)) { $self->{'weekdaybordercolor'} = $newvalue; }
399 return $self->{'weekdaybordercolor'};
400 }
401  
402 sub weekendbordercolor {
403 my $self = shift;
404 my $newvalue = shift;
405 if (defined($newvalue)) { $self->{'weekendbordercolor'} = $newvalue; }
406 return $self->{'weekendbordercolor'};
407 }
408  
409 sub todaybordercolor {
410 my $self = shift;
411 my $newvalue = shift;
412 if (defined($newvalue)) { $self->{'todaybordercolor'} = $newvalue; }
413 return $self->{'todaybordercolor'};
414 }
415  
416 sub contentcolor {
417 my $self = shift;
418 my $newvalue = shift;
419 if (defined($newvalue)) { $self->{'contentcolor'} = $newvalue; }
420 return $self->{'contentcolor'};
421 }
422  
423 sub weekdaycontentcolor {
424 my $self = shift;
425 my $newvalue = shift;
426 if (defined($newvalue)) { $self->{'weekdaycontentcolor'} = $newvalue; }
427 return $self->{'weekdaycontentcolor'};
428 }
429  
430 sub weekendcontentcolor {
431 my $self = shift;
432 my $newvalue = shift;
433 if (defined($newvalue)) { $self->{'weekendcontentcolor'} = $newvalue; }
434 return $self->{'weekendcontentcolor'};
435 }
436  
437 sub todaycontentcolor {
438 my $self = shift;
439 my $newvalue = shift;
440 if (defined($newvalue)) { $self->{'todaycontentcolor'} = $newvalue; }
441 return $self->{'todaycontentcolor'};
442 }
443  
444 sub getcontent {
445 my $self = shift;
446 my $date = lc(shift) || return(); $date = int($date) if $date =~ m/^[\d\.]+$/;
447 return $self->{'content'}->{$date};
448 }
449  
450 sub getdbevent {
451 my $self = shift;
452 my $date = shift;
453 my $month = $self->month();
454 my $year = $self->year();
455 my $calendarid = $self->calendarid();
456 my $dbname = $self->dbname();
457 my $dbuser = $self->dbuser();
458 my $dbpass = $self->dbpass();
459 my $dbhost = $self->dbhost();
460 $dbhost = ":host=$dbhost" if (!($dbhost eq ''));
461 my $dbclient = $self->dbclient();
462 my %content;
463 my $dbh = DBI->connect("dbi:Pg:dbname=$dbname$dbhost", $dbuser, $dbpass) || return;
464 my($getContent)=$dbh->prepare("select eventid, eventday, eventmonth, eventyear, eventtime, eventname, eventdesc,eventlink from event where eventday= ? and eventmonth=? and eventyear=? and calendarid=? order by eventtime, eventid");
465  
466 $getContent->execute($date,$month,$year,$calendarid) || return $dbh->errstr();
467 while (my($eventid,$eventday,$eventmonth,$eventyear,$eventtime,$eventname,$eventdesc,$eventlink) = $getContent->fetchrow_array()) {
468 $content{$eventid}{'eventtime'} = $eventtime if $eventtime;
469 $content{$eventid}{'eventday'} = $eventday if $eventday;
470 $content{$eventid}{'eventmonth'} = $eventmonth if $eventmonth;
471 $content{$eventid}{'eventyear'} = $eventyear if $eventyear;
472 $content{$eventid}{'eventname'} = $eventname if $eventname;
473 $content{$eventid}{'eventdesc'} = $eventdesc if $eventdesc;
474 $content{$eventid}{'eventlink'} = $eventlink if $eventlink;
475 }
476  
477 $dbh->disconnect();
478 return %content;
479 }
480  
481 sub getdbcalendar {
482 my $self = shift;
483 my $dbname = $self->dbname();
484 my $dbuser = $self->dbuser();
485 my $dbpass = $self->dbpass();
486 my $dbhost = $self->dbhost();
487 $dbhost = ":host=$dbhost" if (!($dbhost eq ''));
488 my $calendarid = $self->calendarid();
489 my $dbclient = $self->dbclient();
490  
491 my $dbh = DBI->connect("dbi:Pg:dbname=$dbname$dbhost", $dbuser, $dbpass) || return;
492  
493 my($getCalendarInfo)=$dbh->prepare("select border,width,bgcolor,weekdaycolor,weekendcolor,todaycolor,bordercolor,weekdaybordercolor,weekendbordercolor,todaybordercolor,contentcolor,weekdaycontentcolor,weekendcontentcolor,todaycontentcolor,headercolor,weekdayheadercolor,weekendheadercolor,header,cellalignment from calendar where calendarID = ?");
494  
495 $getCalendarInfo->execute($calendarid) ||print $dbh->errstr();
496  
497  
498 # load calendar formatting data from database and set values.
499 while (my($border,$width,$bgcolor,$weekdaycolor,$weekendcolor,$todaycolor, $bordercolor,$weekdaybordercolor,$weekendbordercolor,$todaybordercolor,$contentcolor,$weekdaycontentcolor,$weekendcontentcolor,$todaycontentcolor,$headercolor,$weekdayheadercolor,$weekendheadercolor,$header,$cellalignment) = $getCalendarInfo->fetchrow_array()) {
500 $self->border($border) if $border;
501 $self->width($width) if $width;
502 $self->bgcolor($bgcolor) if $bgcolor;
503 $self->weekdaycolor($weekdaycolor) if $weekdaycolor;
504 $self->weekendcolor($weekendcolor) if $weekendcolor;
505 $self->todaycolor($todaycolor) if $todaycolor;
506 $self->bordercolor($bordercolor) if $bordercolor;
507 $self->weekdaybordercolor($weekdaybordercolor) if $weekdaybordercolor;
508 $self->weekendbordercolor($weekendbordercolor) if $weekendbordercolor;
509 $self->todaybordercolor($todaybordercolor) if $todaybordercolor;
510 $self->contentcolor($contentcolor) if $contentcolor;
511 $self->weekdaycontentcolor($weekdaycontentcolor) if $weekdaycontentcolor;
512 $self->weekendcontentcolor($weekendcontentcolor) if $weekendcontentcolor;
513 $self->todaycontentcolor($todaycontentcolor) if $todaycontentcolor;
514 $self->headercolor($headercolor) if $headercolor;
515 $self->weekdayheadercolor($weekdayheadercolor) if $weekdayheadercolor;
516 $self->weekendheadercolor($weekendheadercolor) if $weekendheadercolor;
517 $self->header($header) if $header;
518 $self->cellalignment($cellalignment) if $cellalignment;
519 }
520  
521 $dbh->disconnect();
522 }
523  
524 sub editdbcalendar {
525  
526 my $self = shift;
527 my $self1 = {}; %$self1 = @_; # Load ourselves up from the args
528 my $dbname = $self->dbname();
529 my $dbuser = $self->dbuser();
530 my $dbpass = $self->dbpass();
531 my $dbhost = $self->dbhost();
532 $dbhost = ":host=$dbhost" if (!($dbhost eq ''));
533 my $calendarid = $self->calendarid();
534  
535 if ($self1->{'border'} && !($self1->{'border'} =~ /\d+/)) {
536 $self1->{'border'} =1;
537 }
538  
539 my $query = "update calendar set calendarid = ?";
540 $query .= ", border = '".$self1->{'border'}."'" if $self1->{'border'};
541 $query .= ", width = '".$self1->{'width'}."'" if $self1->{'width'}; $query .= ", bgcolor = '".$self1->{'bgcolor'}."'" if $self1->{'bgcolor'};
542 $query .= ", weekdaycolor = '".$self1->{'weekdaycolor'}."'" if $self1->{'weekdaycolor'};
543 $query .= ", weekendcolor = '".$self1->{'weekendcolor'}."'" if $self1->{'weekendcolor'};
544 $query .= ", todaycolor = '".$self1->{'todaycolor'}."'" if $self1->{'todaycolor'};
545 $query .= ", bordercolor = '".$self1->{'bordercolor'}."'" if $self1->{'bordercolor'};
546 $query .= ", weekdaybordercolor = '".$self1->{'weekdaybordercolor'}."'" if $self1->{'weekdaybordercolor'};
547 $query .= ", weekendbordercolor = '".$self1->{'weekendbordercolor'}."'" if $self1->{'weekendbordercolor'};
548 $query .= ", todaybordercolor = '".$self1->{'todaybordercolor'}."'" if $self1->{'todaybordercolor'};
549 $query .= ", contentcolor = '".$self1->{'contentcolor'}."'" if $self1->{'contentcolor'};
550 $query .= ", weekdaycontentcolor = '".$self1->{'weekdaycontentcolor'}."'" if $self1->{'weekdaycontentcolor'};
551 $query .= ", weekendcontentcolor = '".$self1->{'weekendcontentcolor'}."'" if $self1->{'weekendcontentcolor'};
552 $query .= ", todaycontentcolor = '".$self1->{'todaycontentcolor'}."'" if $self1->{'todaycontentcolor'};
553 $query .= ", headercolor = '".$self1->{'headercolor'}."'" if $self1->{'headercolor'};
554 $query .= ", weekdayheadercolor = '".$self1->{'weekdayheadercolor'}."'" if $self1->{'weekdayheadercolor'};
555 $query .= ", weekendheadercolor = '".$self1->{'weekendheadercolor'}."'" if $self1->{'weekendheadercolor'};
556 $query .= ", header = '".$self1->{'header'}."'" if $self1->{'header'};
557 $query .= ", cellalignment = '".$self1->{'cellalignment'}."'" if $self1->{'cellalignment'};
558 $query .= " where calendarID = ?";
559  
560 my $dbh = DBI->connect("dbi:Pg:dbname=$dbname$dbhost", $dbuser, $dbpass) || return;
561  
562 my $updateCal = $dbh->prepare($query);
563 $updateCal->execute($calendarid, $calendarid) ||print $dbh->errstr();
564 $dbh->disconnect();
565
566 return(1);
567  
568 }
569 sub getdbcontent {
570 my $self = shift;
571 my $dbname = $self->dbname();
572 my $dbuser = $self->dbuser();
573 my $dbpass = $self->dbpass();
574 my $dbhost = $self->dbhost();
575 $dbhost = ":host=$dbhost" if (!($dbhost eq ''));
576 my $calendarid = $self->calendarid();
577 my $dbclient = $self->dbclient();
578 my $month = $self->month();
579 my $year = $self->year();
580 my $jsDescs='';
581 my $dbh = DBI->connect("dbi:Pg:dbname=$dbname$dbhost", $dbuser, $dbpass) || return;
582  
583 my($getContent)=$dbh->prepare("select eventID, eventTime, eventDay, eventName, eventDesc, eventLink from event where calendarID = ? and eventMonth = ? and eventYear = ? order by eventDay, eventTime");
584
585 $getContent->execute($calendarid, $month, $year) ||print $dbh->errstr();
586  
587 while (my($eventID, $eventTime, $eventDay, $eventName, $eventDesc, $eventLink) = $getContent->fetchrow_array()) {
588 $eventLink = '#' if !$eventLink;
589 $self->{'content'}->{$eventDay} .= "$eventTime:" if $eventTime;
590 $self->{'content'}->{$eventDay} .= "<a href='$eventLink' onMouseOver='popLayer($eventID)' onMouseOut='hideLayer(-50000)'>$eventName</a><br><br>";
591
592 $jsDescs .="if (a==$eventID) desc += \"$eventDesc\";\n";
593 }
594 $getContent->finish();
595 $dbh->disconnect();
596
597 $self->jsDescs($jsDescs);
598  
599 return(1);
600 }
601 sub setcontent {
602 my $self = shift;
603 my $date = lc(shift) || return(); $date = int($date) if $date =~ m/^[\d\.]+$/;
604 my $newcontent = shift || '';
605 return() unless defined($self->{'content'}->{$date});
606 $self->{'content'}->{$date} = $newcontent;
607 return(1);
608 }
609  
610 sub addevent {
611 my $self = shift;
612 my $date = lc(shift) || return(); $date = int($date) if $date =~ m/^[\d+\.]+$/;
613 my $newcontent = shift || return();
614 return() unless defined($self->{'content'}->{$date});
615 $self->{'content'}->{$date} .= $newcontent;
616 return(1);
617 }
618  
619 sub adddbevent {
620 my $self = shift;
621 my $self1 = {}; %$self1 = @_; # Load ourselves up from the args
622 my $dbname = $self->dbname();
623 my $dbuser = $self->dbuser();
624 my $dbpass = $self->dbpass();
625 my $dbhost = $self->dbhost();
626 $dbhost = ":host=$dbhost" if (!($dbhost eq ''));
627 my $dbcalendar = $self->dbcalendar();
628 my $month = $self->month();
629 my $year = $self->year();
630 my $calendarID=$self->calendarid();
631 my $date = $self1->{'date'};
632 my $eventname = $self1->{'eventname'};
633 my $eventdesc = $self1->{'eventdesc'};
634 $eventdesc =~ s/\s+/ /g;
635 my $eventlink = $self1->{'eventlink'};
636 my $eventtime = $self1->{'eventtime'};
637 my $dbh = DBI->connect("dbi:Pg:dbname=$dbname$dbhost", $dbuser, $dbpass) || return;
638 my $addContent= $dbh->prepare("insert into event (calendarid, eventday, eventmonth, eventyear, eventname, eventdesc, eventlink, eventtime) values(?, ?, ?, ?, ?, ?, ?, ?)");
639 $addContent->execute($calendarID, $date, $month, $year, $eventname, $eventdesc, $eventlink, $eventtime)||print $dbh->errstr();
640 $dbh->disconnect();
641 return(1);
642 }
643  
644 sub deldbevent {
645 my $self = shift;
646 my $eventid = shift;
647 my $dbname = $self->dbname();
648 my $dbuser = $self->dbuser();
649 my $dbpass = $self->dbpass();
650 my $dbhost = $self->dbhost();
651 $dbhost = ":host=$dbhost" if (!($dbhost eq ''));
652  
653 my $dbh = DBI->connect("dbi:Pg:dbname=$dbname$dbhost", $dbuser, $dbpass) || return;
654 my $delEvent= $dbh->prepare("delete from event where eventID = ?");
655 $delEvent->execute($eventid)||print $dbh->errstr();
656 $dbh->disconnect();
657 return(1);
658 }
659  
660 sub editdbevent {
661 my $self = shift;
662 my $self1 = {}; %$self1 = @_; # Load ourselves up from the args
663 my $dbname = $self->dbname();
664 my $dbuser = $self->dbuser();
665 my $dbpass = $self->dbpass();
666 my $dbhost = $self->dbhost();
667 $dbhost = ":host=$dbhost" if (!($dbhost eq ''));
668 my $eventid = $self1->{'eventid'};
669 # eventid needed to update specific event
670 $eventid || return;
671
672 # create query from specified args
673 my $query = "update event set eventid = ?";
674 $query .= ", eventlink = '".$self1->{'eventlink'}."' " if $self1->{'eventlink'};
675 if ($self1->{'eventdesc'}) {
676 $self1->{'eventdesc'} =~ s/\s+/ /g;
677 $query .= ", eventdesc = '".$self1->{'eventdesc'}."' ";
678 }
679 $query .= ", eventname = '".$self1->{'eventname'}."' " if $self1->{'eventname'};
680 $query .= ", eventday = '".$self1->{'eventday'}."' " if $self1->{'eventday'};
681 $query .= ", eventmonth = '".$self1->{'eventmonth'}."' " if $self1->{'eventmonth'};
682 $query .= ", eventyear = '".$self1->{'eventyear'}."' " if $self1->{'eventyear'};
683 $query .= ", eventtime = '".$self1->{'eventtime'}."' " if $self1->{'eventtime'};
684 $query .= " where eventid = ?";
685 my $dbh = DBI->connect("dbi:Pg:dbname=$dbname$dbhost", $dbuser, $dbpass) || return;
686 my $editEvent= $dbh->prepare($query);
687 $editEvent->execute($eventid, $eventid) ||print $dbh->errstr();
688 $dbh->disconnect();
689 return(1);
690 }
691  
692 sub calendarid {
693 my $self = shift;
694 my $dbname = $self->dbname();
695 my $dbuser = $self->dbuser();
696 my $dbpass = $self->dbpass();
697 my $dbhost = $self->dbhost();
698 $dbhost = ":host=$dbhost" if (!($dbhost eq ''));
699 my $dbcalendar = $self->dbcalendar();
700 my $dbclient = $self->dbclient();
701  
702 my $dbh = DBI->connect("dbi:Pg:dbname=$dbname$dbhost", $dbuser, $dbpass) || return;
703
704 my($getCalendarID)=$dbh->prepare("select calendar.calendarID from calendar, client where calendar.name= ? and calendar.clientID=client.clientID and client.clientName= ?");
705
706 $getCalendarID->execute($dbcalendar, $dbclient) ||print $dbh->errstr();
707  
708 my $calendarID=$getCalendarID->fetchrow_array();
709
710 $getCalendarID->finish();
711  
712 $dbh->disconnect();
713  
714 $self->{'calendarid'} = $calendarID;
715  
716 return $self->{'calendarid'};
717 }
718  
719 sub border {
720 my $self = shift;
721 my $newvalue = shift;
722 if (defined($newvalue)) { $self->{'border'} = int($newvalue); }
723 return $self->{'border'};
724 }
725  
726 sub jsDescs {
727 my $self = shift;
728 my $newvalue = shift;
729 if (defined($newvalue)) {
730 $self->{'jsDescs'} .= $newvalue;
731 }
732 return $self->{'jsDescs'};
733 }
734  
735 sub width {
736 my $self = shift;
737 my $newvalue = shift;
738 if (defined($newvalue)) { $self->{'width'} = $newvalue; }
739 return $self->{'width'};
740 }
741  
742 sub showdatenumbers {
743 my $self = shift;
744 my $newvalue = shift;
745 if (defined($newvalue)) { $self->{'showdatenumbers'} = $newvalue; }
746 return $self->{'showdatenumbers'};
747 }
748 sub showweekdayheaders {
749 my $self = shift;
750 my $newvalue = shift;
751 if (defined($newvalue)) { $self->{'showweekdayheaders'} = $newvalue; }
752 return $self->{'showweekdayheaders'};
753 }
754  
755 sub cellalignment {
756 my $self = shift;
757 my $newvalue = shift;
758 if (defined($newvalue)) { $self->{'cellalignment'} = $newvalue; }
759 return $self->{'cellalignment'};
760 }
761  
762  
763 sub year {
764 my $self = shift;
765 return $self->{'year'};
766 }
767  
768 sub month {
769 my $self = shift;
770 return $self->{'month'};
771 }
772  
773 sub admin {
774 my $self = shift;
775 return $self->{'admin'};
776 }
777  
778 sub dbname {
779 my $self = shift;
780 return $self->{'dbname'};
781 }
782  
783 sub dbuser {
784 my $self = shift;
785 return $self->{'dbuser'};
786 }
787  
788 sub dbpass {
789 my $self = shift;
790 return $self->{'dbpass'};
791 }
792  
793 sub dbcalendar {
794 my $self = shift;
795 return $self->{'dbcalendar'};
796 }
797  
798 sub dbclient {
799 my $self = shift;
800 return $self->{'dbclient'};
801 }
802  
803 sub dbhost {
804 my $self = shift;
805 return $self->{'dbhost'};
806 }
807  
808 sub monthname {
809 my $self = shift;
810 return $self->{'monthname'};
811 }
812  
813  
814 sub header {
815 my $self = shift;
816 my $newvalue = shift;
817 if (defined($newvalue)) { $self->{'header'} = $newvalue; }
818 return $self->{'header'};
819 }
820  
821
822  
823  
824 __END__;