#! /usr/bin/perl -w
# **** calander_calc.pl ******
# **** program to give calander and to return date picked *****
use CGI qw/:all/;
use Date::Calc qw(:all);
use DBD::Pg;
use DBI;
#$month = 2;
#$year = 2001;
#$days = Days_in_Month($year, $month);
print "days in month: $days \n";
$j = 1;
$today = localtime(time);
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);
$year = (1900 + $year);
$year_this = $year;
$month_this = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec) [$mon];
$month = ($mon + 1);
$query_params = new CGI;
if ($query_params->param('month')) { $month = $query_params->param('month') }
if ($query_params->param('year')) { $year = $query_params->param('year') }
if ($query_params->param('day')) { $day = $query_params->param('day') }
$days = Days_in_Month($year, $month);
# ****** Web Interface ******
print header, start_html(-title=>"Date::Calc Calander - Maintenance", -BGCOLOR=>'white');
print $query_params->Dump;
if (($query_params->param('performaction')) eq "Add Record") { add_row() };
if (($query_params->param('performaction')) eq "Edit Record") { edit_row() };
if (($query_params->param('performaction')) eq "Remove Records")
{ remove_row() };
if (($query_params->param('performaction')) eq "Save_Edit") { edit_row_db() };
print ("
");
#print system("date");
$this_month = Month_to_Text($month);
$day_name = Day_of_Week_to_Text($wday);
#print ("");
print ("
today is $day_name - $month_this / $mday / $year_this
calander for $this_month $year
Sun Mon Tue Wed
Thr Fri Sat
");
for ($i = 1 ; $i <= $days; $i++) {
$weekday = Day_of_Week($year,$month,$i);
if ($weekday ne 7){
if ($weekday >= 1 and $i eq 1) {
for ($j = 1; $j lt $weekday + 1; $j++) {
print ("   ");
}
}
}
#$day_name = Day_of_Week_to_Text($weekday);
print (" ");
if ($weekday eq '6') {
print (" ");
}
}
print ("
");
print ("");
print ("");
print ("
");
if ($query_params->param('day')) {
# $selected_day = $query_params->param('day');
specified_date();
} else {
current_date();
}
print end_html;
# ****** Subroutines below ******************
sub specified_date() {
$date_wanted = $month."/".$day."/".$year;
print ("");
}
sub current_date {
$date_wanted = $month."/".$mday."/".$year;
print ("
The listings for : $date_wanted
Below are the things on the calender for this date
");
open_info_db();
print ("
");
}
sub day_planner_input {
}
# ********** DataBase Routines **************
sub open_info_db {
$dbname = "info_manager";
$dbtable = "day_planner";
# $date_wanted = "9/16/2000";
$select_used = "select oid,* from $dbtable where planner_date = '$date_wanted' order by planner_catagory";
$dbh = DBI->connect("DBI:Pg:dbname = $dbname", "postgres");
$sth = $dbh->prepare("$select_used");
$sth->execute || die print ("Failure in execute");
$sth->bind_columns(undef, \$planner_oid, \$planner_date,
\$planner_catagory, \$planner_message);
while ($sth->fetch) {
chomp($planner_message);
print ("
  $planner_date    :: $planner_catagory
");
}
}
sub add_row_db {
$dbname = "info_manager";
$dbtable = "day_planner";
$catagory_wanted = $query_params->param("catagory");
$message = $query_params->param("message");
chomp($message);
$date_wanted = $month."/".$day."/".$year;
$select_used = "insert into $dbtable values ('$date_wanted', '$catagory_wanted', '$message')";
$dbh = DBI->connect("DBI:Pg:dbname = $dbname", "postgres");
$sth = $dbh->prepare("$select_used");
$sth->execute || die print ("DB Insert Failure to execute");
}
sub edit_row_db {
$dbname = "info_manager";
$dbtable = "day_planner";
$message = $query_params->param("message");
chomp($message);
$planner_iod = $query_params->param("record_id");
$select_used = "update $dbtable set planner_message='$message' where oid ='$planner_iod'";
$dbh = DBI->connect("DBI:Pg:dbname = $dbname", "postgres");
$sth = $dbh->prepare("$select_used");
$sth->execute || die print ("DB row Update failure");
}
sub delete_row_db {
$dbname = "info_manager";
$dbtable = "day_planner";
$planner_oid = $query_params->param("record_id");
$dbh = DBI->connect("DBI:Pg:dbname = $dbname", "postgres");
$sth = $dbh->prepare("delete from $dbtable where oid='$planner_oid'");
$sth->execute || die print ("DELETE FAILURE");
}
sub get_row_db {
$dbname = "info_manager";
$dbtable = "day_planner";
$planner_oid = $query_params->param('record_id');
$dbh = DBI->connect("DBI:Pg:dbname = $dbname", "postgres");
$sth = $dbh->prepare("select * from $dbtable where oid = '$planner_oid'");
$sth->execute ||die print ("Selecting record for update failure");
$sth->bind_columns(undef, \$planner_date, \$planner_catagory, \$planner_message);
$sth->fetch;
}
# ********** PreformAction routines **************
sub add_row {
$row_input_title = "Add NEW Row to Day Planner";
$row_input_performaction = "Add Record";
$row_input_submit = "Add Record";
if (($query_params->param("message")) &&
($query_params->param("catagory"))) {
add_row_db();
} else { print ("You did not enter enough data
");
}
row_input_form();
}
sub edit_row {
print ("Edit Row routine");
$row_input_title = "Edit THIS Row";
$row_input_performaction = "Save_Edit";
$row_input_submit = "Save EDITS";
if ($query_params->param('record_id')) {
get_row_db();
row_input_form();
} else {
print ("ACTION NOT PERFORMED
You need to check the item you want to edit ");
}
}
sub remove_row {
print ("Remove Row");
delete_row_db();
print ("Row Removed");
}
# ******* Misc Routines ***************
# ******* can be called by any routine ************
sub row_input_form {
print ("");
}