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

1.1       www         1: # The LearningOnline Network
1.2       www         2: # Announce
1.1       www         3: #
1.8     ! matthew     4: # $Id: lonannounce.pm,v 1.7 2002/09/11 15:01:43 matthew 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: 
                     36: sub readcalendar {
                     37:     my $courseid=shift;
                     38:     my $coursenum=$ENV{'course.'.$courseid.'.num'};
                     39:     my $coursedom=$ENV{'course.'.$courseid.'.domain'};
                     40:     my %thiscal=&Apache::lonnet::dump('calendar',$coursedom,$coursenum);
                     41:     my %returnhash=();
                     42:     foreach (keys %thiscal) {
                     43:         unless (($_=~/^error\:/) || ($thiscal{$_}=~/^error\:/)) {
                     44: 	   $returnhash{$courseid.'@'.$_}=$thiscal{$_};
                     45:         }
                     46:     }
                     47:     return %returnhash;
                     48: }
                     49: 
                     50: sub emptycell {
                     51:     return '<td bgcolor="#AAAAAA">&nbsp;</td>';
                     52: }
                     53: 
                     54: sub normalcell {
                     55:     my ($day,$text)=@_;
1.4       www        56:     my $output='';
                     57:     foreach (split(/\_\_\_\&\&\&\_\_\_/,$text)) {
                     58:         if ($_) {
1.5       www        59: 	    my ($courseid,$start,$end,@msg)=split(/\@/,$_);
                     60:             my $msg=join('@',@msg);
1.4       www        61:             my $fullmsg=$ENV{'course.'.$courseid.'.description'}.': '.$msg;
1.5       www        62:             if ($courseid eq $ENV{'request.course.id'}) {
                     63:               if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
                     64:                $output.='<input type="checkbox" name="remove_'.$start.'_'.
                     65: 		   $end.'">';
                     66: 	      }
                     67: 	    }
                     68:             $output.='<a href="javascript:alert('."'$fullmsg'".')">'.
1.4       www        69: 	       substr($msg,0,20).'...</a><br>';
                     70:        }
                     71:     }
                     72:     return '<td><b>'.$day.'</b><br>'.$output.'</td>';
1.3       www        73: }
                     74: 
                     75: sub nextday {
                     76:     my %th=@_;
                     77:     $th{'day'}++;
                     78:     return (&Apache::loncommon::maketime(%th),$th{'month'});
                     79: }
                     80: 
                     81: sub showday {
                     82:     my ($tk,%allcal)=@_;
                     83:     my %th=&Apache::loncommon::timehash($tk);
                     84:     my ($nextday,$nextmonth)=&nextday(%th);
                     85:     my $outp='';
1.4       www        86:     my $oneday=24*3600;
1.3       www        87:     foreach (keys %allcal) {
                     88: 	my ($course,$startdate,$enddate)=($_=~/^(\w+)\@(\d+)\_(\d+)$/);
1.4       www        89:         if (($startdate<$nextday) && ($enddate>$tk))  {
1.5       www        90: 	    $outp.='___&&&___'.$course.'@'.$startdate.'@'.$enddate.'@'.
                     91:             $allcal{$_};
1.3       www        92:         }
                     93:     }
                     94:     return ($nextday,$nextmonth,&normalcell($th{'day'},$outp));
                     95: }
1.1       www        96: 
                     97: sub handler {
                     98:     my $r = shift;
                     99:     $r->content_type('text/html');
                    100:     $r->send_http_header;
                    101:     return OK if $r->header_only;
                    102: 
1.3       www       103: # ---------------------------------------------------------- Get time right now
                    104:     my $today=time;
                    105:     my %todayhash=&Apache::loncommon::timehash($today);
                    106: 
                    107: # ---------------------------------------------------------- Get month and year
                    108:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                    109:                                             ['month','year']);
                    110: # --------------------------------------------------- Decide what month to show
                    111:     my $year=$todayhash{'year'};
                    112:     if ($ENV{'form.year'}) { $year=$ENV{'form.year'}; }
                    113:     my $month=$todayhash{'month'};
                    114:     if ($ENV{'form.month'}) { $month=$ENV{'form.month'}; }
                    115: # --------------------------------------------- Find out first day of the month
                    116: 
                    117:     my %firstday=&Apache::loncommon::timehash(
                    118:        &Apache::loncommon::maketime( 'day' => 1, 'month'=> $month,
                    119:                                      'year' => $year, 'hours' => 0,
                    120: 				     'minutes' => 0, 'seconds' => 0,
                    121:                                      'dlsav' => $todayhash{'dlsav'} ));
                    122:     my $weekday=$firstday{'weekday'};
                    123: # ------------------------------------------------------------ Print the screen
1.8     ! matthew   124:     my $pjump_function = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.1       www       125:     $r->print(<<ENDDOCUMENT);
                    126: <html>
                    127: <head>
                    128: <title>The LearningOnline Network with CAPA</title>
1.3       www       129: <script>
                    130:     function pclose() {
                    131:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
                    132:                  "height=350,width=350,scrollbars=no,menubar=no");
                    133:         parmwin.close();
                    134:     }
                    135: 
1.8     ! matthew   136:     $pjump_function
1.3       www       137: 
                    138:     function dateset() {
                    139:         if (document.anno.pres_marker.value=='end') {
                    140:            document.anno.enddate.value=
                    141: 	       document.anno.pres_value.value;
                    142:         }
                    143:         if (document.anno.pres_marker.value=='start') {
                    144:            document.anno.startdate.value=
                    145: 	       document.anno.pres_value.value;
                    146:         }
                    147:         pclose();
                    148:     }
                    149: 
                    150:     function trysubmit() {
                    151:         if (document.anno.startdate.value=='') {
                    152: 	    alert("Announcements must have a starting date");
                    153:             return '';
                    154:         }
                    155:         if (document.anno.enddate.value=='') {
                    156: 	    alert("Announcements must have a starting date");
                    157:             return '';
                    158:         }
                    159:         if (document.anno.startdate.value>document.anno.enddate.value) {
                    160: 	    alert("Starting date is later than ending date");
                    161:             return '';
                    162:         }
                    163:         document.anno.action.value="new";
                    164: 	document.anno.submit();
                    165:     }
                    166: 
                    167:     function removesub() {
                    168:         document.anno.action.value="del";
                    169: 	document.anno.submit();
                    170:     }
                    171: </script>
1.1       www       172: </head>
                    173: ENDDOCUMENT
1.6       www       174:     $r->print(&Apache::loncommon::bodytag("Announcements and Calendar"));
1.3       www       175: # does this user have privileges to post, etc?
                    176:     my $allowed=0;
                    177:     if ($ENV{'request.course.id'}) {
                    178:        $allowed=&Apache::lonnet::allowed('srm',$ENV{'request.course.id'});
                    179:     }
                    180: 
                    181:     if ($allowed) {
                    182:         my $coursenum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
                    183:         my $coursedom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
                    184: # ----------------------------------------------------- Store new submitted one
                    185:         if ($ENV{'form.action'} eq 'new') {
                    186: 	    &Apache::lonnet::put('calendar',{ 
                    187: 		$ENV{'form.startdate'}.'_'.$ENV{'form.enddate'} => 
                    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:         
                    205: 	$r->print(<<ENDFORM);
                    206: <form name="anno" method="post">
                    207: <input type="hidden" value=''          name="action"      >
                    208: <input type="hidden" value=''          name="pres_value"  >
                    209: <input type="hidden" value=''          name="pres_type"   >
                    210: <input type="hidden" value=''          name="pres_marker" >
                    211: <input type="hidden" value='$today'    name="startdate"   >
                    212: <input type="hidden" value='$tomorrow' name="enddate"     >
                    213: <a 
                    214:  href="javascript:pjump('date_start','Starting Date',document.anno.startdate.value,'start','anno.pres','dateset');"
                    215: >Set Starting Date</a>
                    216: <a 
                    217:  href="javascript:pjump('date_end','Ending Date',document.anno.enddate.value,'end','anno.pres','dateset');"
                    218: >Set Ending Date</a><p>
                    219: <textarea name="msg" rows="4" cols="60">
                    220: </textarea>
                    221: <input type="button" onClick="trysubmit()" value="Post Announcement"><hr>
                    222: <input type="button" onClick="removesub()" value="Remove Marked"><hr>
                    223: ENDFORM
                    224:     }
1.5       www       225: # ----------------------------------------------------- Summarize all calendars
                    226:     my %allcal=();
                    227:     foreach (&Apache::loncommon::findallcourses()) {
                    228: 	%allcal=(%allcal,&readcalendar($_));
                    229:     }
                    230: 
                    231: # ------------------------------- Initialize table and forward backward buttons
1.3       www       232:     my ($pm,$py,$fm,$fy)=($month-1,$year,$month+1,$year);
                    233:     if ($pm<1) { ($pm,$py)=(12,$year-1); }
                    234:     if ($fm>12){ ($fm,$fy)=(1,$year+1); }
                    235:     $r->print('<h1>'.('','January','February','March','April','May',
                    236: 		      'June','July','August','September','October',
                    237:                       'November','December')[$month].' '.$year.'</h1>'.
                    238:  '<a href="/adm/announcements?month='.$pm.'&year='.$py.'">Previous Month</a> '.
                    239:  '<a href="/adm/announcements?month='.$fm.'&year='.$fy.'">Next Month</a><p>'.
                    240:         '<table border="2" cols="7" rows="5"><tr><th>Sun</th><th>Mon</th>'.
1.7       matthew   241:         '<th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th></tr>');
1.3       www       242: 
                    243:     my $tk=&Apache::loncommon::maketime(%firstday);
                    244:     my $outp;
                    245:     my $nm;
                    246: 
                    247: # ---------------------------------------------------------------- Actual table
                    248:     $r->print('<tr>');
                    249:     for (my $i=0;$i<$weekday;$i++) { $r->print(&emptycell); }
                    250:     for (my $i=$weekday;$i<=6;$i++) { 
                    251:         ($tk,$nm,$outp)=&showday($tk,%allcal);
                    252:         $r->print($outp);
                    253:     }
                    254:     $r->print('</tr>');
                    255: 
                    256:     for (my $k=0;$k<=3;$k++) {
                    257:         $r->print('<tr>');
                    258:         for (my $i=0;$i<=6;$i++) {
                    259:             ($tk,$nm,$outp)=&showday($tk,%allcal);
                    260:             if ($month!=$nm) { $outp=&emptycell; }
                    261:             $r->print($outp);
                    262:         }
                    263:         $r->print('</tr>');
                    264:     }
                    265: # ------------------------------------------------------------------- End table
1.7       matthew   266:     $r->print('</table>');
1.3       www       267:     if ($allowed) { $r->print('</form>'); }
1.7       matthew   268:     $r->print('<p>'.
1.3       www       269:  '<a href="/adm/announcements?month='.$pm.'&year='.$py.'">Previous Month</a> '.
                    270:  '<a href="/adm/announcements?month='.$fm.'&year='.$fy.'">Next Month</a><p>'.
                    271:  '</body></html>');
1.1       www       272:     return OK;
                    273: } 
                    274: 
                    275: 1;
                    276: __END__

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