"Fossies" - the Fresh Open Source Software Archive

Member "metadot/metadot/Gizmo/AbstractEvent.pm" (1 Jul 2005, 15490 Bytes) of package /linux/www/old/Metadot6.4.5.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "AbstractEvent.pm" see the Fossies "Dox" file reference documentation.

    1 ###########################################################################
    2 # <LICENSEINFO>
    3 # Copyright (C) Daniel Guermeur - 1999-2001
    4 # Copyright (C) Metadot Corporation - 2001-2005
    5 #
    6 # This file is part of Metadot Portal Server software $Name: Release_6_4_5_4 $
    7 #
    8 # Metadot Portal Server software is free software; you can
    9 # redistribute it and/or modify it under the terms of the GNU General Public
   10 # License as published by the Free Software Foundation; either version 2 of
   11 # the License, or (at your option) any later version.
   12 #
   13 # Metadot Portal Server software is distributed in the hope that it
   14 # will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
   15 # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
   16 # Public License for more details.
   17 #
   18 # You should have received a copy of the GNU General Public License along with
   19 # Metadot Portal Server; if not, write to the Free Software
   20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   21 #
   22 # For more information, please contact info@metadot.com.
   23 #</LICENSEINFO>
   24 ############################################################################
   25 package AbstractEvent;
   26 use strict;
   27 
   28 use Metadot qw($USER %FORM $SESSION $HTTP_HEADER_SENT);
   29 
   30 use Carp;
   31 use Gizmo;
   32 use Time::Local;
   33 use Date::Calc qw(check_date);
   34 
   35 use DBAccess;
   36 
   37 # added import of escapeHTML
   38 use CGI qw/escape unescape escapeHTML/;
   39 use vars qw(@ISA);
   40 @ISA=qw(GizmoBuilder);
   41 my $version = "4.5";
   42 
   43 sub get_version {
   44     return $version;
   45 }
   46 
   47 my $DATE_FIELD      = 'i1'; # stores the timestamp
   48 my $TIMED_FIELD     = 'c1'; # stores whether the time-of-day is relevant
   49 my $DURATION_FIELD  = 'i2'; # stores the duration of the event
   50 my $is_visible_in_add_child_lists = 0;
   51 
   52 
   53 sub is_visible_in_add_child_lists {
   54     return $is_visible_in_add_child_lists;
   55 }
   56 
   57 sub customize_permissions {
   58     my $self = shift;
   59     #if set, this text will be displayed at the top of the gizmo edit form.
   60 
   61     my $ac   = shift;
   62     $self->SUPER::customize_permissions($ac);
   63 
   64         #modify the ac here
   65         $ac->add_bundle('DISP', 'View', '0', '0');
   66         $ac->modify_bundle('DISP', 'DEFAULTS_TO', 'on' );
   67         $ac->add_op('DISP','show');
   68 
   69         $ac->add_bundle('MOD', 'Edit', '8', '2');
   70         $ac->add_op('MOD', 'modify');
   71         $ac->add_op('MOD', 'save');
   72         $ac->add_op('MOD', 'up');
   73         $ac->add_op('MOD', 'down');
   74 
   75         $ac->add_bundle('DEL', 'Delete and Cut', '8', '8');
   76         $ac->add_op('DEL', 'delete');
   77         $ac->add_op('DEL', 'delete_ok');
   78     }
   79 
   80 my $MONTHS = {
   81                 0 => 'January',
   82                 1 => 'February',
   83                 2 => 'March',
   84                 3 => 'April',
   85                 4 => 'May',
   86                 5 => 'June',
   87                 6 => 'July',
   88                 7 => 'August',
   89                 8 => 'September',
   90                 9 => 'October',
   91                10 => 'November',
   92                11 => 'December'
   93              };
   94 
   95 #####################################################
   96 ######                                        #######
   97 ######            FRONT-END METHODS           #######
   98 ######                                        #######
   99 #####################################################
  100 
  101 sub www_delete {
  102   my $self = shift;
  103   my $isa = $self->is_a();
  104   my $gizmo_name = $isa->get_gizmo_name();
  105   $self->debug_msg(3, "AbstractEvent::www_delete()");
  106   $self->print_http_header;
  107   $self->two_choices("Do you want to delete this $gizmo_name? <br />",
  108                      "caution",
  109              "Yes please", "index.pl?iid=".$self->id."&isa=$isa&op=delete_ok",
  110              "No!", "$SESSION->{referer}");
  111 }
  112 
  113 sub www_delete_ok {
  114   my $self = shift;
  115   my $url  = $self->_get_url_of_parent();
  116   $self->debug_msg(3, "AbstractEvent::www_delete_ok()");
  117   $self->delete();
  118   $self->md_redirect($url);
  119 }
  120 
  121 ###############
  122 
  123 # returns the url of the AbstractEvent's parent, including the necessary
  124 # op, isa and form variables
  125 sub _get_url_of_parent {
  126     my $self = shift;
  127     my $parent_obj = shift || $self->get_parent_obj();
  128     my $result;
  129 
  130     my $parent_iid = $parent_obj->id();
  131     my $parent_isa = $parent_obj->is_a();
  132     my $op = 'show';
  133     my $dt = $self->date();
  134 
  135     $result = "index.pl?iid=$parent_iid&amp;isa=$parent_isa&amp;op=$op&amp;dt=$dt";
  136     return $result;
  137 }
  138 
  139 sub get_parent_obj {
  140     my $self = shift;
  141     my $result;
  142 
  143     my $parent_iid = shift || $self->parent_id();
  144     $result = Gizmo->restore($parent_iid);
  145     return $result;
  146 }
  147 
  148 sub date_field {
  149     my $self = shift;
  150     my $input = shift;
  151     if (defined $input) {
  152         $DATE_FIELD = $input;
  153     }
  154     return $DATE_FIELD;
  155 }
  156 
  157 sub timed_field {
  158     my $self = shift;
  159     my $input = shift;
  160     if (defined $input) {
  161         $TIMED_FIELD = $input;
  162     }
  163     return $TIMED_FIELD;
  164 }
  165 
  166 sub duration_field {
  167     my $self = shift;
  168     my $input = shift;
  169     if (defined $input) {
  170         $DURATION_FIELD = $input;
  171     }
  172     return $DURATION_FIELD;
  173 }
  174 
  175 sub date {
  176     my $self = shift;
  177     my $input = shift;
  178     my $result;
  179 
  180     my $field_name = $self->date_field();
  181     if (defined $input) {
  182         $result = $self->$field_name($input);
  183     } else {
  184         $result = $self->$field_name();
  185     }
  186     return $result;
  187 }
  188 
  189 sub timed {
  190     my $self = shift;
  191     my $input = shift;
  192     my $result;
  193 
  194     my $field_name = $self->timed_field();
  195     if (defined $input) {
  196         $result = $self->$field_name($input);
  197     } else {
  198         $result = $self->$field_name();
  199     }
  200     return $result;
  201 }
  202 
  203 sub duration {
  204     my $self = shift;
  205     my $input = shift;
  206     my $result;
  207 
  208     my $field_name = $self->duration_field();
  209     if (defined $input) {
  210         $result = $self->$field_name($input);
  211     } else {
  212         $result = $self->$field_name();
  213     }
  214     return $result;
  215 }
  216 
  217 sub months {
  218     my $self = shift;
  219     my $input = shift;
  220 
  221     if (defined $input) {
  222         $MONTHS = $input;
  223     }
  224     return $MONTHS;
  225 }
  226 
  227 ##############
  228 
  229 sub process_edit_form {
  230     my $self = shift;
  231     my $isa = ref $self;
  232 
  233     $self->debug_msg(3, "AbstractEvent::process_edit_form()");
  234 
  235     my $errormsg = $self->_input_form_fields();
  236 
  237     if ($errormsg) {
  238         my $parentid = $self->parent_id();
  239         my $parent = Gizmo->restore($parentid);
  240         $parent->www_add_child("<font color=red>$errormsg</font>", $self->is_a, $self);
  241     } else {
  242         $self->_show_edit_success();
  243     }
  244 }
  245 
  246 # This method will process only the common form fields for AbstractInstance. This method should
  247 # be extended. This method returns an error if any form validation fails
  248 sub _input_form_fields {
  249     my $self = shift;
  250     my $errormsg = '';
  251 
  252     $self->name($FORM{name});
  253     $self->description($FORM{description});
  254 
  255     # input the date if it is defined
  256     my $date_defined = (defined($FORM{day}) && defined($FORM{month}) && defined($FORM{year}));
  257 
  258     if ($date_defined) {
  259         if ($FORM{timed} eq 'yes') {
  260           $self->date(timelocal(0, ($FORM{timed_min}||0), ($FORM{timed_hour}||0), $FORM{day}, $FORM{month}, $FORM{year}));
  261           ## seconds
  262           my $duration = ($FORM{duration_hour} * 60 * 60) + ($FORM{duration_min} * 60);
  263           $self->duration($duration);
  264         } else {
  265           $self->date(timelocal(0, 0, 0, $FORM{day}, $FORM{month}, $FORM{year}));
  266         }
  267         $self->timed($FORM{timed});
  268     }
  269 
  270     # check if everything is ok
  271     $errormsg .= "<br />Title cannot be empty." if $self->name() eq '';
  272     $errormsg .= "<br />Invalid Date: ".$self->months()->{$FORM{month}}." $FORM{day} " . ($FORM{year} + 1900) unless (!$date_defined || Date::Calc::check_date($FORM{year}+1900,$FORM{month}+1,$FORM{day}));
  273 
  274     return $errormsg;
  275 }
  276 
  277 # This method will define the Gizmo's behavior when an edit is successful
  278 sub _show_edit_success {
  279     my $self = shift;
  280 
  281     $self->add();
  282 
  283     my $parent_id   = $self->parent_id();
  284     my $parent      = Gizmo->restore($parent_id);
  285     my $parent_isa  = $parent->is_a();
  286     my $child_isa   = $self->is_a();
  287     my $gizmo_name  = $self->get_gizmo_name();
  288 
  289     $self->two_choices(
  290         "<Big>New $gizmo_name added!</big><br /><br />What do you want to do?",
  291         "confirm",
  292         "Add another $gizmo_name", "index.pl?iid=$parent_id&isa=$parent_isa&op=add_child&child_type=$child_isa&dt=".$self->date(),
  293         "Enough for now!", "index.pl?iid=$parent_id&dt=".$self->date());
  294 }
  295 ##############
  296 
  297 sub www_save {
  298   my $self = shift;
  299   $self->debug_msg(3, "AbstractEvent::www_save()");
  300   my $url = $FORM{target};
  301 
  302   my $iid = $self->defined_or_exit($self->id,"id is missing.");
  303   my $errormsg = $self->_input_form_fields();
  304   if ($errormsg) {
  305     $self->www_modify("<font color=red>$errormsg</font>");
  306   } else {
  307     my $parentid = $self->parent_id();
  308     $self->save();
  309     $self->md_redirect("index.pl?iid=$parentid&dt=".$self->date());
  310   }
  311 }
  312 
  313 #####################################################
  314 ######                                        #######
  315 ######            BACK-END METHODS            #######
  316 ######                                        #######
  317 #####################################################
  318 
  319 #####################################################
  320 ###         WEB DISPLAY BACK-END METHODS          ###
  321 #####################################################
  322 
  323 sub show {
  324   my $self  = shift;
  325   $self->debug_msg(4, "AbstractEvent::show()");
  326 
  327   #my $s = "<p /><b>Title:</b> " . $self->name();
  328   my $s = "<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr><td>\n";
  329   $s .= "<table border=\"0\" width=\"100%\" cellspacing=\"1\" cellpadding=\"5\">\n";
  330   $s .= "<tr><th colspan='2'>" . $self->name(). "</th></td></tr>";
  331   $s .= "<tr><td><b>Date";
  332   if ($self->c1() eq 'yes') {
  333       $s .= " and Time:</b></td><td>";
  334       $s .= $self->format_datetime($self->date(), 'M e, Y T');
  335       $s .= "-" . $self->format_datetime($self->date() + $self->duration(), 'T');
  336       $s .= "</td></tr>\n";
  337   } else {
  338       $s .= ":</b></td><td>";
  339       $s .= $self->format_datetime($self->date(), 'M e, Y') .
  340             "&nbsp;&nbsp;<i>(All Day Event)</i>";
  341       $s .= "</td></tr>\n";
  342   }
  343   my $user = Metadot::UserFactory->get_user( $self->uid() );
  344   my $parent_obj  = $self->get_parent_obj();
  345 
  346   $s .= "<tr><td><b>Details:</b></td><td>" . ($self->description() || '&nbsp') . "</td></tr>\n";
  347   $s .= "<tr><td><b>Author:</b></td><td>" . ($user->fullname() || $user->nickname() || '&nbsp') . "</td></tr>\n";
  348   $s .= "</table>\n</table>\n";
  349   $s .= "<p /><a href=\"".$self->_get_url_of_parent($parent_obj)."\">Back to ".$parent_obj->get_gizmo_name()."</a>\n";
  350 
  351   return $s;
  352 }
  353 
  354 ##############
  355 
  356 sub _generate_form_fields {
  357     my $self  = shift;
  358     my $result = shift || {};
  359 
  360     my $id = $self->id();
  361 
  362     my $dt              = $self->date() || $FORM{dt} || time;
  363     my $duration_hour   = 0;
  364     my $duration_min    = 0;
  365     my $timed           = $self->timed();
  366     my $duration        = $self->duration();
  367 
  368     my ($year, $month, $day, $timed_hour, $timed_min) = (localtime($dt))[5, 4, 3, 2, 1];
  369 
  370     if ($id > 0 || $self->date()) { ## editing or fixing error on add
  371       use integer;
  372       $duration_hour = $duration / 3600;
  373       $duration_min  = ($duration / 60) % 60;
  374     } else { ## adding new
  375       $timed_min = 0;
  376       $timed = 'yes';
  377       $duration_hour = 1;
  378       $duration_min  = 0;
  379     }
  380 
  381     ###
  382     ### BUILD DROP-DOWNS
  383     ###
  384 
  385     ## build day dropdown
  386     my $day_dropdown = "<select name = \"day\">\n";;
  387     for my $d (1..31) {
  388       $day_dropdown .= "    <option value=\"$d\"" .
  389                        ($d == $day ? " selected" : "") . ">$d\n";
  390     }
  391     $day_dropdown .= "</select>";
  392     ##
  393 
  394     ## build month dropdown
  395     my $month_dropdown = "<select name = \"month\">\n";;
  396     for my $m (0..11) {
  397       $month_dropdown .= "    <option value=\"$m\"" .
  398                        ($m == $month ? " selected" : "") . ">".$self->months()->{$m}."\n";
  399     }
  400     $month_dropdown .= "</select>";
  401     ##
  402 
  403     ## build year dropdown
  404     my $year_dropdown = "<select name = \"year\">\n";;
  405     for my $y (($year-1)..($year+5)) {
  406       $year_dropdown .= "    <option value=\"$y\"" .
  407                         ($y == $year ? " selected" : "") . ">" . ($y+1900) . "\n";
  408     }
  409     $year_dropdown .= "</select>";
  410     ##
  411 
  412     ## build hour dropdown
  413     my $hour_dropdown = "<select name = \"timed_hour\">\n";
  414     my $display_hour = '';
  415     my $ampm = '';
  416     for my $h (0..23) {
  417       $ampm = $h > 11 ? 'pm': 'am';
  418       if ($h == 0) {
  419           $display_hour = '12';
  420       } elsif ($h > 12) {
  421           $display_hour = $h - 12;
  422       } else {
  423           $display_hour = $h;
  424       }
  425       $display_hour .= " $ampm";
  426       $hour_dropdown .= "    <option value=\"$h\"" .
  427                         ($h == $timed_hour ? " selected" : "") . ">$display_hour\n";
  428     }
  429     $hour_dropdown .= "</select>";
  430     ##
  431 
  432     my $min_dropdown = "
  433     <select name=timed_min>
  434         <option value=0" . ($timed_min ==  0?' selected':'') . ">:00
  435         <option value=15". ($timed_min == 15?' selected':'') . ">:15
  436         <option value=30". ($timed_min == 30?' selected':'') . ">:30
  437         <option value=45". ($timed_min == 45?' selected':'') . ">:45
  438     </select>
  439     ";
  440 
  441     ## duration hour dropdown
  442     my $dh_dropdown = "<select name = \"duration_hour\">\n";;
  443     #my $dh_value = '';
  444     for my $dh (0..12) {
  445       #$dh_value = $dh < 10 ? "0$dh" : $dh;
  446       $dh_dropdown .= "    <option value=\"$dh\"" .
  447                         ($dh == $duration_hour ? " selected" : "") . ">$dh\n";
  448     }
  449     $dh_dropdown .= "</select>";
  450 
  451     my $dm_dropdown = "
  452     <select name=duration_min>
  453         <option value=0" . ($duration_min ==  0?' selected':'') . ">:00
  454         <option value=15". ($duration_min == 15?' selected':'') . ">:15
  455         <option value=30". ($duration_min == 30?' selected':'') . ">:30
  456         <option value=45". ($duration_min == 45?' selected':'') . ">:45
  457     </select>
  458     ";
  459 
  460     # aju 04-22-02 - escape notes and name HTML
  461     ## build the result hash
  462     $result->{name} = '<input type=text name=name size=55 maxlength=255 value="'.
  463         escapeHTML($self->name()) .'">';
  464     $result->{description} = '<textarea name=description rows=5 cols=60 WRAP=VIRTUAL>'.
  465         escapeHTML($self->description()) . '</textarea>';
  466     $result->{timed_no} = '<input type=radio name=timed value=no' . ($timed eq 'no'?' checked':'') . '>';
  467     $result->{timed_yes} = '<input type=radio name=timed value=yes' . ($timed eq 'yes'?' checked':'') . '>';
  468 
  469     $result->{year}             = $year_dropdown;
  470     $result->{month}            = $month_dropdown;
  471     $result->{day}              = $day_dropdown;
  472     $result->{timed_hour}       = $hour_dropdown;
  473     $result->{timed_min}        = $min_dropdown;
  474 
  475     $result->{duration_hour}    = $dh_dropdown;
  476     $result->{duration_min}     = $dm_dropdown;
  477 
  478     return $result;
  479 }
  480 
  481 
  482 # an alias for Calendar->format_datetime
  483 sub format_datetime {
  484     my $class = shift;
  485     return Calendar->format_datetime(@_);
  486 }
  487 
  488 #####################################################
  489 ###                   THE END                     ###
  490 #####################################################
  491 
  492 
  493 1;
  494 
  495 
  496 __END__
  497 
  498 =head1 NAME
  499 
  500 Gizmo::AbstractEvent -
  501 
  502 =head1 SYNOPSIS
  503 
  504     use Gizmo::AbstractEvent;
  505 
  506     $event = Event->new ($id);
  507 
  508     $AC = $event->get_AC ();
  509     $event->www_show ();
  510     $event->www_delete ();
  511     $event->www_delete_ok ();
  512     $event->process_edit_form ();
  513     $event->www_save ();
  514     $event->show ();
  515     $html = $event->show_edit_form ($title);
  516     $version = Event->get_version();
  517 
  518 =head1 DESCRIPTION
  519 
  520 =cut
  521 
  522