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

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

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