#!/usr/bin/perl use CGI ':standard'; use Time::Local; # Instruction of calling the calendar: # # To call the monthly calendar (and show the current month): # calendar2.cgi?mode=user&id=XXXXXX [where XXXXXX is the Record ID] # To call the latest event list: # direct : calendar2.cgi?mode=latest&id=XXXXXX # via SSI: # To call the admin interface: # calendar2.cgi?mode=admin # To link to a particular month: # calendar2.cgi?mode=user&id=XXXXXX&month=11&year=103 # Eg. February 2003 = month=1&year=103 # December 2004 = month=11&year=104 ###################################################### # GENERAL CONFIGURATION: ###################################################### # Datafile name in relative to this script's location: # The default setting below assumes the folder "data" and the # this script are in the SAME folder. $calendar_folder="data/"; $data_file="data/data.txt"; $count_file="data/count.txt"; $icon_details="data/icon_details.txt"; # Admin id $admin_id="tfcc"; # Admin Password $admin_password="tgrf2"; # The maximum number of days you can add event to at one time $max_days=10; # The maximum number of characters to show for each event in the main # calendar before the headlines are truncated. $max_letters=80; # Maximum number of days to querry for finding latest events... $max_days_look=365; # Path to this script $path_to_script="calendar2.cgi"; ###################################################### # TEMPLATE SETTINGS: ###################################################### # OPTIONAL: You can format the opening and closing HTML template of your # calendar page in a separate file that can be written in regular HTML and # saved on your server. If you call the calendar on the same window, you # would usually want to use your own template so that the calendar is # inserted inside your own web theme. BUT if you are calling the calendar # in a pop-up window, it would look nicer if the pop-up window contains only # the calendar itself. In this case, leave the variable empty. # TEMPLATE: Create a normal HTML page and place three plusses +++ where you # want the calendar inserted. Note, you are providing a full or relative # server PATH here. A URL will not work. $openinghtml="/hsphere/local/home/taipeif0/taipeifcc.org/calendar2/template.htm"; ###################################################### # ICON SETTINGS: ###################################################### # URL to image folder where you have to keep image files uploaded. $icons="http://taipeifcc.org/calendar2/icons/"; # Image files... # - close $close_image="http://taipeifcc.org/calendar2/images/close.gif"; # - back $back_image="http://taipeifcc.org/calendar2/images/back.gif"; # - delete $delete_image="http://taipeifcc.org/calendar2/images/delete.gif"; # - delte confirm $delete_image_c="http://taipeifcc.org/calendar2/images/delete_c.gif"; # - edit $edit_image="http://taipeifcc.org/calendar2/images/edit.gif"; # - add $add_image="http://taipeifcc.org/calendar2/images/add.gif"; # - login $login_image="http://taipeifcc.org/calendar2/images/login.gif"; # - go $go_image="http://taipeifcc.org/calendar2/images/go.gif"; # - save $save_image="http://taipeifcc.org/calendar2/images/save.gif"; ###################################################### # FONT STYLE: ###################################################### # Font size of Calander $font_size=2; # Font face $font_face="geneva, arial, helvetica"; ###################################################### # DISPLAY SETTINGS: ###################################################### # Number of events to display on delfault page $no_link=3; # Show years between these... $year_start=2004; $year_end=2006; # Name of 12 months @month_name =(January,February,March,April,May,June,July,August,September,October,November,December); # Name of week days @week_name=(Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday); # Current color scheme of calendar. Choose gray, red, brown or brown2. $currentscheme = "brown"; ###################### DO NOT EDIT BELOW THIS LINE ################################## if ($currentscheme eq "gray"){ $co1="#E9E9E9"; # Light $co2="#A2A2A2"; ## Dark $co3="#676767"; ### Darker $co4="#000000"; ##### Darkest } elsif ($currentscheme eq "red"){ $co1="#FFEAEA"; # Light $co2="#FFC4C4"; ## Dark $co3="#FF8C8C"; ### Darker $co4="#FF0000"; ##### Darkest } elsif($currentscheme eq "brown2"){ $co1="#660000"; # Light $co2="#9A654B"; ## Dark $co3="#C9A392"; ### Darker $co4="#F8F3F1"; ##### Darkest } elsif($currentscheme eq "brown"){ $co1="#F8F3F1"; # Light $co2="#E7D7CF"; ## Dark $co3="#A35334"; ### Darker $co4="#660000"; ##### Darkest } else { $co1="#E6E6FF"; # Light $co2="#A4A4FF"; ## Dark $co3="#6666FF"; ### Darker $co4="#0000EC"; ##### Darkest } #======================================================== # Check to see if opening html file is on server if (-e "$openinghtml"){ # If so, open it and write opening and closing text to different strings #to be used throughout the script $problem="Can't open template file. Make sure you are referencing the file and not just a directory."; open(OPENING, "$openinghtml") || &security; @wholefile=; close(OPENING); $fulltemplate=join("\n",@wholefile); ($templatestart,$templateend)=split(/\+\+\+/,$fulltemplate);} else{ #D3. If template file not found, use this for now $templatestart="Calendar Publisher II "; $templateend="";} #======================================================== print "Content-type: text/html\nPragma: no-cache\n\n"; &input; &common; $mode2= "latest"; if ($mode ne $mode2){ print "$templatestart";} &input; &common; if($mode eq admin){ $status=&get_status; print ""; if($status){ if($status eq admin){ if($action eq "Add User"){ if($sub_action eq final){ &do_add_user; &show_admin_index("New user added successfully"); } else{ &show_add_user; } } elsif($action eq "Delete User"){ if($sub_action eq final){ &do_delete_user; &show_admin_index("User\(s\) account deleted successfully"); } elsif($sub_action eq semifinal){ &show_confirm_delete_user; } else{ &show_delete_user; } } elsif($action eq "View Users"){ &show_users; } elsif($action eq "Logout"){ &enter_password("Enter password"); } else{ &show_admin_index("Master Admin Control Panel"); } } else{ if($action eq add){ if($sub_action eq final){ &do_add_event; &show_calender_default("Event added successfully"); } else{ &show_add_event; } } elsif($action eq edit){ if($sub_action eq final){ &do_add_event; &show_calender_default("Event edited Successfully"); } else{ &show_edit_event; } } elsif($action eq "delete"){ if($sub_action eq final){ &do_add_event; &show_calender_default("Event removed from Calendar"); } else{ &show_delete_event; } } else{ &show_calender_default("Welcome $nick_naame"); } } } else{ if(param('password_status') eq On){ &enter_password("Wrong password"); } else{ &enter_password("Enter password"); } } print "
"; } elsif($mode eq user){ &show_calender_user; } elsif($mode eq event){ &show_event; } elsif($mode eq latest){ &show_latest; } $mode2 = "latest"; if ($mode ne $mode2){ print "$templateend";} exit; # EnD~ #~~~~~~~~~~~~~~~~~~~~~~~Functions... # # !!!!!!!!!~~~~~~~~~~~~~~~~~~~~~!!!!!User Functions...!!!!!!!!!!!!!~~~~~~~~~~~~~~~!!!!!!!!!!!!!~~~~~~ sub show_latest{ my($daysecs) = timegm(0,0,0,$day,$month,$year); my @data=&read("$calendar_folder$id.txt"); my(@today) = gmtime(time); my $cutoff=$daysecs+($max_days_look*$day_secs); print "
"; for(my $j=$daysecs;$j<=$cutoff;$j=$j+$day_secs){ foreach $user(@data){ if($count>=$no_link){print "
";return;} $hello=0; my ($day_pointer,$news)=split(/\:\:/,$user); if($day_pointer == $j) { my (@current)=gmtime($j); @fields=split(/\|/,$news); my (@current)=gmtime($j);$current_y=$current[5]+1900;$current_m=$current[4]+1; print "
  • $current[3].$current_m.$current_y

  • \n"; if($count>=$no_link){print "";return;} print "$fields[0]
    "; $count++; last; } } } } sub show_event{ my($todaysecs) = timegm(0,0,0,$day,$month,$year); my @data=&read("$calendar_folder$id.txt"); foreach $user(@data){ ($day_pointer,$news)=split(/\:\:/,$user); if($todaysecs==$day_pointer){ @fields=split(/\|/,$news); if($fields[2]){ $img=""; } last; } } # viijv $year1=$year+1900; ($dayweek) = (gmtime($todaysecs))[6]; $date="$week_name[$dayweek],$month_name[$month] $day, $year1"; $font_size1=$font_size+1; print <$img $date
    $fields[0]
    $fields[1] EOF } sub max_letter{ my($word)=@_; $_=$word; if(!(/img scr/i)){ $first_byte = substr($word, 0, $max_letters); $first_byte="$first_byte..."; return($first_byte); } } sub show_delete_event{ print $table_header; &heading_calander; &show_next("admin"); &show_calander; $year1=$year+1900; my($daysecs) = timegm(0,0,0,$day,$month,$year); ($dayweek) = (gmtime($daysecs))[6]; my @data=&read("$calendar_folder$id.txt"); print < $week_name[$dayweek], $month_name[$month] $day, $year1

    Delete events from: EOF &show_day("day"); &show_month("month"); &show_year("year"); print "
    To
    "; &show_day("day2"); &show_month("month2"); &show_year("year2"); print <
    EOF foreach my $user(@data){ my ($day_pointer,$news)=split(/\:\:/,$user); if($daysecs==$day_pointer){ @fields=split(/\|/,$news); if($fields[2]){ $image="
    "; } print< $print_account
    Are you sure you want to delete this event?
    $image$fields[0]
    EOF return; } } } sub show_edit_event{ print $table_header; &heading_calander; &show_next("admin"); &show_calander; $year1=$year+1900; my($daysecs) = timegm(0,0,0,$day,$month,$year); ($dayweek) = (gmtime($daysecs))[6]; print < $week_name[$dayweek], $month_name[$month] $day, $year1

    EOF my @data1=&read("$calendar_folder$id.txt"); foreach $user(@data1){ ($one,$two)=split(/\:\:/,$user); if($one == $daysecs){ last; } } @items=split(/\|/,$two); my @data=&read($icon_details); foreach $user(@data){ @fields=split(/\|/,$user); if($fields[1] eq $items[2]){ $selected="Selected"; } else{ $selected=""; } push(@icons,""); } $heading=&html_to_text($items[0]); $message=&html_to_text($items[1]); print <
    Post from: EOF &show_day("day"); &show_month("month"); &show_year("year"); print "
    To
    "; &show_day("day2"); &show_month("month2"); &show_year("year2"); print <
    $print_account
    Category:
    Heading:
    Details:
    EOF } sub do_add_event{ my($daysecs1) = timegm(0,0,0,$day,$month,$year); my($daysecs2) = timegm(0,0,0,param('day2'),param('month2'),param('year2')); if($daysecs1 > $daysecs2){ &error("Don't waste time, its precious.
    Go back and select a valid time period"); } elsif((($daysecs2-$daysecs1)/$day_secs)>$max_days){ &error("Sorry,You are only allowed to add/edit/delete $max_days day's events in one go.
    Please go back and decress the time period"); } my @data=&read("$calendar_folder$id.txt"); if(param('category')){ $category=param('category'); } $heading=&text_to_html(param('heading')); $details=&text_to_html(param('details')); if($daysecs1 == $daysecs2){ if((param('action') eq edit)||(param('action') eq "delete")){ foreach $user(@data){ my($one,$two)=split(/\:\:/,$user); if($one == $daysecs1){ $user=""; last; } } } if(param('action') ne "delete"){ push(@data,"$daysecs1\:\:$heading|$details|$category|"); } } else{ for($i=$daysecs1;$i<=$daysecs2;$i=$i+$day_secs){ foreach $user(@data){ my($one,$two)=split(/\:\:/,$user); if($one == $i){ $user=""; last; } } if(param('action') ne "delete"){ push(@data,"$i\:\:$heading|$details|$category|"); } } } @output=sort(@data); &write("$calendar_folder$id.txt",@output); } sub show_add_event{ print $table_header; &heading_calander; &show_next("admin"); &show_calander; $year1=$year+1900; my($daysecs) = timegm(0,0,0,$day,$month,$year); ($dayweek) = (gmtime($daysecs))[6]; print < $week_name[$dayweek], $month_name[$month] $day, $year1

    EOF my @data=&read($icon_details); foreach $user(@data){ @fields=split(/\|/,$user); push(@icons,""); } print <
    Post from: EOF &show_day("day"); &show_month("month"); &show_year("year"); print "
    To
    "; &show_day("day2"); &show_month("month2"); &show_year("year2"); print <
    $print_account
    Category:
    Heading:
    Details:
    EOF } sub show_calender_user{ print $table_header; &heading_calander; &show_next("user"); &show_calander("fdads"); print "\n"; } sub show_calender_default{ ($hlo)=@_; print $table_header; &heading_calander; &show_next("admin"); &show_calander(); &show_right($hlo); print "\n"; } sub heading_calander{ $year_temp=$year+1900; print < $month_name[$month] $year_temp EOF } sub show_next{ my($checker)=@_; print <
    EOF &show_month("month"); &show_year("year"); print < EOF } sub show_day{ my($temp)=@_; print ""; } sub show_month{ my($temp)=@_; print ""; } sub show_year{ my ($temp)=@_; $year_temp=$year+1900; print ""; } sub show_calander{ my($statu)=@_; my($daysecs) = timegm(0,0,0,1,$month,$year); my($dayweek) = (gmtime($daysecs))[6]; my($todaysecs) = timegm(0,0,0,$day,$month,$year); print < Sun Mon Tue Wed Thu Fri Sat EOF print "\n\n"; for($a=0;$a<$dayweek;$a++){ print "\ \;\n"; } $cut_off_value=$daysecs+$day_secs*31; for($daysecs;$daysecs <= $cut_off_value;$daysecs=$daysecs+$day_secs){ $got=$got_day=0; last if ((gmtime($daysecs))[4] != $month); ($daymonth,$dayweek) = (gmtime($daysecs))[3,6]; if($dayweek == 0){ print "\n"; } if($statu){ my @data=&read("$calendar_folder$id.txt"); foreach $user(@data){ ($day_pointer,$news)=split(/\:\:/,$user); if($daysecs==$day_pointer){ $got=1; @fields=split(/\|/,$news); } } if($todaysecs == $daysecs){ $got_day=1; } else{ $got_day=0; } if($got==1){ $fields[0]=&max_letter($fields[0]); if($fields[2]){ $img=""; } else{ $img=""; } if($got_day==1){ print "$daymonth $img $fields[0]\n"; } else{ print "$daymonth $img $fields[0]\n"; } $fields[0]=""; } else{ if($got_day==1){ print "$daymonth\n"; } else{ print "$daymonth\n"; } } } else{ if($todaysecs == $daysecs){ print "$daymonth\n"; } else{ print "$daymonth\n"; } } } for($a=6;$a>$dayweek;$a--){ print "\ \;\n"; } print "\n\n\n\n "; } sub show_right{ my($hello)=@_; $year1=$year+1900; my($daysecs) = timegm(0,0,0,$day,$month,$year); ($dayweek) = (gmtime($daysecs))[6]; my @data=&read("$calendar_folder$id.txt"); print <
  • --> $hello
  • $week_name[$dayweek], $month_name[$month] $day, $year1
    EOF foreach my $user(@data){ my ($day_pointer,$news)=split(/\:\:/,$user); if($daysecs==$day_pointer){ @fields=split(/\|/,$news); if($fields[2]){ $image="
    "; } $fields[0]=&max_letter($fields[0]); print<
    $image$fields[0] Edit event Delete event
    EOF return; } } print <   
    Add event EOF } # # !!!!!!!!!~~~~~~~~~~~~~~~~~~~~~!!!!!END User Functions...!!!!!!!!!!!!!~~~~~~~~~~~~~~~!!!!!!!!!!!!!~~~~~~ # # !!!!!!!!!~~~~~~~~~~~~~~~~~~~~~!!!!!!!!!Common Functions...!!!!!!!!!!!!!~~~~~~~~~~~~~~~!!!!!!!!!!!!!~~~~~~ sub get_status{ if(($id eq $admin_id)&&($password eq $admin_password)){ return("admin"); } else{ my @data=&read($data_file); foreach $user(@data){ @fields=split(/\|/,$user); if(($fields[0] eq $id)&&($fields[2] eq $password)){ $nick_naame=$fields[1]; return($fields[0]); } } } } sub common{ $border="0"; $bordercolor="$co4"; $color4="color=$co4"; $color3="color=$co3"; $color2="color=$co2"; $color1="color=$co1"; $bgcolor4="bgcolor=$co4"; $bgcolor3="bgcolor=$co3"; $bgcolor2="bgcolor=$co2"; $bgcolor1="bgcolor=$co1"; $font_size1=$font_size+1; $day_secs=86400; $print_account=""; if($bgcolor){ $bgcolor="bgColor\=$bgcolor"; } if($bordercolor && $border){ $bordercolor="bordercolor\=$bordercolor"; $border="border\=$border"; } $table_header= "
    \n"; $year=param('year'); $day=param('day'); @today=gmtime(time+gm_time*60); if(!$day){ $day=$today[3]; } #if($month eq a){ # $month=0; #} if(defined param('month')){ $month=param('month'); } else{ $month=$today[4]; } if(!$year){ $year=$today[5]; } } sub input { $mode=param('mode'); $action=param('action'); $sub_action=param('sub_action'); $password=param('password'); $id=param('id'); } sub enter_password { my ($header)=@_; print <
    Calendar Login
    Record ID:
    Password:
    EOF } sub html_to_text{ my ($html)=@_; for($html){ if ($microsoft eq "on"){ s/\"//g; } s/
    /\n/g; s//>\;/g; s/\"/\"\;/g; } return $html; } sub text_to_html{ my ($html)=@_; for($html){ if ($microsoft eq "on"){ s/\"//g; } s/\r\n/
    /g; s/<\;//g; } return $html; } sub read{ my ($open_file)=@_; open(DAT, "$open_file") || die(&error("Cannot open file - \"$open_file\",
    Please make sure the file exists and is readable")); my @data=; close(DAT); return @data; } sub write { my ($writeto_file,@write)=@_; my ($abc,$output); foreach $abc(@write){ $output="$output\n$abc"; for ($output){ s/^\s+//; s/\s+$//; } } flock(DAT, 2); open(DAT,">$writeto_file") || die(&error("Cannot Open File - \"$writeto_file\"
    Please make sure that the file exists and is writable")); print DAT "$output"; close(DAT); flock(DAT, 8); } sub error{ my ($html)=@_; print "
    Error...

    $html
    "; exit; } sub increment_count{ my @data=&read($count_file); &write($count_file,$data[0]+1); return($data[0]+1); } # # !!!!!!!!!~~~~~~~~~~~~~~~~~~~~~!!!!!!!!!END common functions..!!!!!!!!!!!!!~~~~~~~~~~~~~~~!!!!!!!!!!!!!~~~~~~ # # !!!!!!!!!~~~~~~~~~~~~~~~~~~~~~!!!!!Admin functions!!!!!!!!!!!!!!!!~~~~~~~~~~~~~~~!!!!!!!!!!!!!~~~~~~ sub do_delete_user{ my @data=&read($data_file); $i=0; foreach $user(@data){ if(param("user$i") ne On){ push(@new,$user); } else{ @fields=split(/\|/,$user); unlink("$calendar_folder$fields[0]\.txt"); } $i++; } &write($data_file,@new); } sub show_confirm_delete_user{ print"Confirm delete user\(s\):
    Note that this will also delete calendar of this user."; my @data=&read($data_file); $i=0; foreach $user(@data){ if(param("user$i") eq On){ @fields=split(/\|/,$user); print ""; } $i++; } print < EOF } sub show_delete_user{ my @data=&read($data_file); print"
    $fields[1]\[ $fields[0] \]
    $print_account
    Action: Select users to delete
    "; $i=0; foreach $user(@data){ @fields=split(/\|/,$user); print ""; $i++; } print < EOF } sub show_users{ my @data=&read($data_file); print""; foreach $user(@data){ @fields=split(/\|/,$user); print ""; } } sub do_add_user{ if(param('record_password')){ $count=&increment_count; @data=&read($data_file); $nick_name=param('nick_name'); $record_password=param('record_password'); push(@data,"$count|$nick_name|$record_password|"); &write(@empty,"$calendar_folder$count\.txt"); &write($data_file,@data); } else{ &error("Please go back and enter a password"); } } sub show_add_user{ @count=&read($count_file); $count[0]++; print < EOF } sub show_admin_index{ my($header)=@_; print <
    $fields[0] / $fields[1]
    $print_account
    Record IDNick namePassword
    $fields[0]$fields[1]$fields[2]
    Action: Add A New Sub-User

    Nick name:
    Record ID:$count[0]
    Password:
    $print_account
    Action: $header
    $print_account EOF } # # !!!!!!!!!~~~~~~~~~~~~~~~~~~~~~!!!!!!!!!End Admin Functions!!!!!!!!!!!~~~~~~~~~~~~~~~!!!!!!!!!!!!!~~~~~~ # 0 1 2 3 4 5 6 7 8 # ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); # 1 2 3 4 5 6 # $time = timegm($sec,$min,$hours,$mday,$mon,$year); # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Note:
    View Users: View current sub-users each with their own calendar system.
    Add User: Add a new sub-user.
    Delete User: Delete existing sub-users.