Annotation of loncom/interface/lonannounce.pm, revision 1.10

1.1       www         1: # The LearningOnline Network
1.2       www         2: # Announce
1.1       www         3: #
1.10    ! www         4: # $Id: lonannounce.pm,v 1.9 2003/05/21 16:26:46 www Exp $
1.1       www         5: #
1.3       www         6: # Copyright Michigan State University Board of Trustees
1.1       www         7: #
1.3       www         8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
1.1       www         9: #
1.3       www        10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
1.1       www        14: #
1.3       www        15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
                     28: 
1.2       www        29: package Apache::lonannounce;
1.1       www        30: 
                     31: use strict;
                     32: use Apache::Constants qw(:common);
1.3       www        33: use Apache::loncommon;
1.8       matthew    34: use Apache::lonhtmlcommon();
1.3       www        35: 
1.10    ! www        36: sub editfield {
        !            37:     my ($r,$start,$end,$text)=@_;
        !            38:     # Deal with date forms
        !            39:     my $startdateform = &Apache::lonhtmlcommon::date_setter('anno',
        !            40:                                                             'startdate',
        !            41:                                                             $start);
        !            42:     my $enddateform = &Apache::lonhtmlcommon::date_setter('anno',
        !            43:                                                           'enddate',
        !            44:                                                           $end);
        !            45: 
        !            46:     $r->print(<<ENDFORM);
        !            47: <form name="anno" method="post">
        !            48: <input type="hidden" value=''          name="action"      >
        !            49: <table><tr><td>Starting date:</td><td>$startdateform</td></tr>
        !            50: <tr><td>Ending date:</td><td>$enddateform</td></tr></table>
        !            51: <textarea name="msg" rows="4" cols="60">$text</textarea>
        !            52: <input type="button" onClick="trysubmit()" value="Post Announcement"><hr>
        !            53: ENDFORM
        !            54: }
        !            55: 
1.3       www        56: sub readcalendar {
                     57:     my $courseid=shift;
                     58:     my $coursenum=$ENV{'course.'.$courseid.'.num'};
                     59:     my $coursedom=$ENV{'course.'.$courseid.'.domain'};
                     60:     my %thiscal=&Apache::lonnet::dump('calendar',$coursedom,$coursenum);
                     61:     my %returnhash=();
                     62:     foreach (keys %thiscal) {
                     63:         unless (($_=~/^error\:/) || ($thiscal{$_}=~/^error\:/)) {
                     64: 	   $returnhash{$courseid.'@'.$_}=$thiscal{$_};
                     65:         }
                     66:     }
                     67:     return %returnhash;
                     68: }
                     69: 
                     70: sub emptycell {
                     71:     return '<td bgcolor="#AAAAAA">&nbsp;</td>';
                     72: }
                     73: 
                     74: sub normalcell {
                     75:     my ($day,$text)=@_;
1.4       www        76:     my $output='';
                     77:     foreach (split(/\_\_\_\&\&\&\_\_\_/,$text)) {
                     78:         if ($_) {
1.5       www        79: 	    my ($courseid,$start,$end,@msg)=split(/\@/,$_);
                     80:             my $msg=join('@',@msg);
1.4       www        81:             my $fullmsg=$ENV{'course.'.$courseid.'.description'}.': '.$msg;
1.5       www        82:             if ($courseid eq $ENV{'request.course.id'}) {
                     83:               if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
                     84:                $output.='<input type="checkbox" name="remove_'.$start.'_'.
                     85: 		   $end.'">';
                     86: 	      }
                     87: 	    }
                     88:             $output.='<a href="javascript:alert('."'$fullmsg'".')">'.
1.4       www        89: 	       substr($msg,0,20).'...</a><br>';
                     90:        }
                     91:     }
                     92:     return '<td><b>'.$day.'</b><br>'.$output.'</td>';
1.3       www        93: }
                     94: 
                     95: sub nextday {
                     96:     my %th=@_;
                     97:     $th{'day'}++;
                     98:     return (&Apache::loncommon::maketime(%th),$th{'month'});
                     99: }
                    100: 
                    101: sub showday {
                    102:     my ($tk,%allcal)=@_;
                    103:     my %th=&Apache::loncommon::timehash($tk);
                    104:     my ($nextday,$nextmonth)=&nextday(%th);
                    105:     my $outp='';
1.4       www       106:     my $oneday=24*3600;
1.3       www       107:     foreach (keys %allcal) {
                    108: 	my ($course,$startdate,$enddate)=($_=~/^(\w+)\@(\d+)\_(\d+)$/);
1.4       www       109:         if (($startdate<$nextday) && ($enddate>$tk))  {
1.5       www       110: 	    $outp.='___&&&___'.$course.'@'.$startdate.'@'.$enddate.'@'.
                    111:             $allcal{$_};
1.3       www       112:         }
                    113:     }
                    114:     return ($nextday,$nextmonth,&normalcell($th{'day'},$outp));
                    115: }
1.1       www       116: 
                    117: sub handler {
                    118:     my $r = shift;
                    119:     $r->content_type('text/html');
                    120:     $r->send_http_header;
                    121:     return OK if $r->header_only;
                    122: 
1.3       www       123: # ---------------------------------------------------------- Get time right now
                    124:     my $today=time;
                    125:     my %todayhash=&Apache::loncommon::timehash($today);
                    126: 
                    127: # ---------------------------------------------------------- Get month and year
                    128:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                    129:                                             ['month','year']);
                    130: # --------------------------------------------------- Decide what month to show
                    131:     my $year=$todayhash{'year'};
                    132:     if ($ENV{'form.year'}) { $year=$ENV{'form.year'}; }
                    133:     my $month=$todayhash{'month'};
                    134:     if ($ENV{'form.month'}) { $month=$ENV{'form.month'}; }
                    135: # --------------------------------------------- Find out first day of the month
                    136: 
                    137:     my %firstday=&Apache::loncommon::timehash(
                    138:        &Apache::loncommon::maketime( 'day' => 1, 'month'=> $month,
                    139:                                      'year' => $year, 'hours' => 0,
                    140: 				     'minutes' => 0, 'seconds' => 0,
                    141:                                      'dlsav' => $todayhash{'dlsav'} ));
                    142:     my $weekday=$firstday{'weekday'};
                    143: # ------------------------------------------------------------ Print the screen
1.9       www       144: 
1.1       www       145:     $r->print(<<ENDDOCUMENT);
                    146: <html>
                    147: <head>
                    148: <title>The LearningOnline Network with CAPA</title>
1.3       www       149: <script>
                    150: 
                    151:     function trysubmit() {
                    152:         document.anno.action.value="new";
                    153: 	document.anno.submit();
                    154:     }
                    155: 
                    156:     function removesub() {
                    157:         document.anno.action.value="del";
                    158: 	document.anno.submit();
                    159:     }
                    160: </script>
1.1       www       161: </head>
                    162: ENDDOCUMENT
1.6       www       163:     $r->print(&Apache::loncommon::bodytag("Announcements and Calendar"));
1.3       www       164: # does this user have privileges to post, etc?
                    165:     my $allowed=0;
                    166:     if ($ENV{'request.course.id'}) {
                    167:        $allowed=&Apache::lonnet::allowed('srm',$ENV{'request.course.id'});
                    168:     }
                    169: 
                    170:     if ($allowed) {
                    171:         my $coursenum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
                    172:         my $coursedom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
                    173: # ----------------------------------------------------- Store new submitted one
                    174:         if ($ENV{'form.action'} eq 'new') {
1.9       www       175: 	    my $startdate = 
                    176: 		&Apache::lonhtmlcommon::get_date_from_form('startdate');
                    177: 	    my $enddate   = 
                    178: 		&Apache::lonhtmlcommon::get_date_from_form('enddate');
                    179: 	    unless ($startdate=~/^\d+$/) { $startdate=time; }
                    180:             unless ($enddate=~/^\d+$/) { $enddate=$startdate+1; }
                    181:             if ($startdate>$enddate) {
                    182: 		my $buffer=$startdate;
                    183: 		$startdate=$enddate;
                    184: 		$enddate=$buffer;
                    185:             }
1.3       www       186: 	    &Apache::lonnet::put('calendar',{ 
1.9       www       187: 		$startdate.'_'.$enddate => 
1.3       www       188: 		    $ENV{'form.msg'} },$coursedom,$coursenum);
                    189:         }
                    190: # ---------------------------------------------------------------- Remove items
                    191:         if ($ENV{'form.action'} eq 'del') {
                    192: 	    my @delwhich=();
                    193:             foreach (keys %ENV) {
                    194: 		if ($_=~/^form\.remove\_(.+)$/) {
                    195: 		    push(@delwhich,$1);
                    196:                 }
                    197:             }
                    198:             &Apache::lonnet::del('calendar',\@delwhich,$coursedom,$coursenum);
                    199:         }
                    200: # -------------------------------------------------------- Form to post new one
                    201:         my %tomorrowhash=%todayhash;
                    202:         $tomorrowhash{'day'}++;
                    203:         my $tomorrow=&Apache::loncommon::maketime(%tomorrowhash);
                    204:         
1.10    ! www       205:         &editfield($r,$today,$tomorrow,'');
1.3       www       206:     }
1.5       www       207: # ----------------------------------------------------- Summarize all calendars
                    208:     my %allcal=();
                    209:     foreach (&Apache::loncommon::findallcourses()) {
                    210: 	%allcal=(%allcal,&readcalendar($_));
                    211:     }
                    212: 
                    213: # ------------------------------- Initialize table and forward backward buttons
1.3       www       214:     my ($pm,$py,$fm,$fy)=($month-1,$year,$month+1,$year);
                    215:     if ($pm<1) { ($pm,$py)=(12,$year-1); }
                    216:     if ($fm>12){ ($fm,$fy)=(1,$year+1); }
                    217:     $r->print('<h1>'.('','January','February','March','April','May',
                    218: 		      'June','July','August','September','October',
                    219:                       'November','December')[$month].' '.$year.'</h1>'.
                    220:  '<a href="/adm/announcements?month='.$pm.'&year='.$py.'">Previous Month</a> '.
                    221:  '<a href="/adm/announcements?month='.$fm.'&year='.$fy.'">Next Month</a><p>'.
                    222:         '<table border="2" cols="7" rows="5"><tr><th>Sun</th><th>Mon</th>'.
1.7       matthew   223:         '<th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th></tr>');
1.3       www       224: 
                    225:     my $tk=&Apache::loncommon::maketime(%firstday);
                    226:     my $outp;
                    227:     my $nm;
                    228: 
                    229: # ---------------------------------------------------------------- Actual table
                    230:     $r->print('<tr>');
                    231:     for (my $i=0;$i<$weekday;$i++) { $r->print(&emptycell); }
                    232:     for (my $i=$weekday;$i<=6;$i++) { 
                    233:         ($tk,$nm,$outp)=&showday($tk,%allcal);
                    234:         $r->print($outp);
                    235:     }
                    236:     $r->print('</tr>');
                    237: 
                    238:     for (my $k=0;$k<=3;$k++) {
                    239:         $r->print('<tr>');
                    240:         for (my $i=0;$i<=6;$i++) {
                    241:             ($tk,$nm,$outp)=&showday($tk,%allcal);
                    242:             if ($month!=$nm) { $outp=&emptycell; }
                    243:             $r->print($outp);
                    244:         }
                    245:         $r->print('</tr>');
                    246:     }
                    247: # ------------------------------------------------------------------- End table
1.7       matthew   248:     $r->print('</table>');
1.9       www       249:     if ($allowed) { $r->print('<input type="button" onClick="removesub()" value="Remove Checked Entries"></form>'); }
1.7       matthew   250:     $r->print('<p>'.
1.3       www       251:  '<a href="/adm/announcements?month='.$pm.'&year='.$py.'">Previous Month</a> '.
                    252:  '<a href="/adm/announcements?month='.$fm.'&year='.$fy.'">Next Month</a><p>'.
                    253:  '</body></html>');
1.1       www       254:     return OK;
                    255: } 
                    256: 
                    257: 1;
                    258: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>