267 # Sets up HTML tables to graph a calendar 268 sub graph_calendar { 269 # Form options 270 my (%form) = @_; 271 272 # Setup the return variable 273 my $tms = ""; 274 275 # If a range is not specified ($form{'pdays'} - today - $form{'ndays'}) then 276 # find the epoch of the first day of the requested month and the epoch 277 # of the last day of the requested month (for the requested year) 278 my($pday,$nday); 279 if(!$form{'pdays'} || !$form{'ndays'}) { 280 $pday = timelocal(0,0,0,1,$form{'gmonth'},$form{'gyear'}); 281 $nday = timelocal(0,0,0,month_days($form{'gmonth'},$form{'gyear'}),$form{'gmonth'},$form{'gyear'}); 282 } 283 else{ 284 #else: a range is specifed 285 $pday = ($form{'pdays'} * 2) - $form{'pdays'}; #make pdays negative 286 $pday = ($pday * 86400) + time(); # pdays ago 287 $nday = ($form{'ndays'} * 86400)+ time(); # ndays from now 288 289 } 290 291 # Table headers 292 my $tsetup = "trans_image(); 307 $tsetup .= " cellspacing=\"$form{'cellspacing'}\" cellpadding=\"$form{'cellpadding'}\" border=\"$form{'border'}\" width=\"98%\">\n"; 308 309 310 # Problem lurking in here somewhere 311 312 # Get the day/month/year for $pday 313 my @local = localtime($pday); 314 315 # Make sure $pday is set to midnight 316 my $tepoch = timelocal(0,0,0,1,$local[4],($local[5] + 1900)); 317 318 # Counters for days/months/years 319 my $daycounter = 1; 320 my $monthcounter = $local[4]; 321 my $yearcounter = $local[5] + 1900; 322 323 # Number of seconds in a day 324 my $add = 86400; 325 326 # Slots 0-6 = days of week Sun-Sat 327 my $slot = 0; 328 329 # HTML for days of the week 330 my $day_name_string = ""; 331 foreach my $dayname(qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday)) { 332 $day_name_string .= "\n"; 333 $day_name_string .= "

\n"; 334 $day_name_string .= "$dayname\n"; 335 $day_name_string .= "\n"; 336 } 337 $day_name_string .= "\n"; 338 339 # Loop while epoch range gets smaller 340 while($tepoch <= $nday) { 341 if($daycounter == 1) { # If the beginning of the month 342 my @local2 = localtime($tepoch); 343 $slot = $local[6]; # Find what day of the week this month begins on 344 $tms .= $tsetup; # Start a new table 345 $tms .= "\n"; 346 $tms .= "\n"; 347 $tms .= "

\n"; 348 $tms .= get_monthname($monthcounter) . " $yearcounter\n"; 349 $tms .= "

\n"; 350 $tms .= "$day_name_string\n"; 351 352 if($slot) { # If slot > 0 print empty up until day before begining day of week 353 foreach my $z(0 .. ($slot - 1)) { 354 $tms .= "\ \n"; 355 } 356 } 357 } 358 # Insert this day of the week 359 $tms .= "\n"; 360 $tms .= "\n"; 361 $tms .= "\n"; 362 $tms .= "$daycounter
\n"; # Day number 363 $tms .= "\n"; # epoch time, used in adding descriptions later 364 $tms .= "\n"; 365 $tepoch = $tepoch + $add; # Add the next day 366 $daycounter++; # Count the action day number up 367 368 # If the last day of the month has been printed 369 if($daycounter > month_days($monthcounter,$yearcounter)) { 370 $daycounter = 1; # Reset day counter to 1 371 $monthcounter++; # Increment Month counter 372 foreach my $q($slot .. 5) { # Insert blank slots until the TR row is filled 373 $tms .= "\ \n"; 374 } 375 # End the HTML table 376 $tms .= "\n"; 377 $tms .= "\n"; 378 if($monthcounter > 11) { # If December 379 $monthcounter = 0; # Set month January 380 $yearcounter ++; # Increment the year 381 } 382 } 383 else { 384 # else: 385 $slot++; # Increment the slot (day of week) 386 if($slot > 6) { # If > sat 387 $tms .="\n"; # End the row. 388 $slot = 0; # Set to Sunday 389 } 390 } 391 } 392 return $tms; # Return the Tables 393 }