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

1.1       www         1: # The LearningOnline Network
1.2       www         2: # Announce
1.1       www         3: #
1.5     ! www         4: # $Id: lonannounce.pm,v 1.4 2002/08/09 20:15:16 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: <body bgcolor="#FFFFFF">
1.3       www       179: <h1>Announcements</h1>
1.1       www       180: ENDDOCUMENT
1.3       www       181: 
                    182: # does this user have privileges to post, etc?
                    183:     my $allowed=0;
                    184:     if ($ENV{'request.course.id'}) {
                    185:        $allowed=&Apache::lonnet::allowed('srm',$ENV{'request.course.id'});
                    186:     }
                    187: 
                    188:     if ($allowed) {
                    189:         my $coursenum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
                    190:         my $coursedom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
                    191: # ----------------------------------------------------- Store new submitted one
                    192:         if ($ENV{'form.action'} eq 'new') {
                    193: 	    &Apache::lonnet::put('calendar',{ 
                    194: 		$ENV{'form.startdate'}.'_'.$ENV{'form.enddate'} => 
                    195: 		    $ENV{'form.msg'} },$coursedom,$coursenum);
                    196:         }
                    197: # ---------------------------------------------------------------- Remove items
                    198:         if ($ENV{'form.action'} eq 'del') {
                    199: 	    my @delwhich=();
                    200:             foreach (keys %ENV) {
                    201: 		if ($_=~/^form\.remove\_(.+)$/) {
                    202: 		    push(@delwhich,$1);
                    203:                 }
                    204:             }
                    205:             &Apache::lonnet::del('calendar',\@delwhich,$coursedom,$coursenum);
                    206:         }
                    207: # -------------------------------------------------------- Form to post new one
                    208:         my %tomorrowhash=%todayhash;
                    209:         $tomorrowhash{'day'}++;
                    210:         my $tomorrow=&Apache::loncommon::maketime(%tomorrowhash);
                    211:         
                    212: 	$r->print(<<ENDFORM);
                    213: <form name="anno" method="post">
                    214: <input type="hidden" value=''          name="action"      >
                    215: <input type="hidden" value=''          name="pres_value"  >
                    216: <input type="hidden" value=''          name="pres_type"   >
                    217: <input type="hidden" value=''          name="pres_marker" >
                    218: <input type="hidden" value='$today'    name="startdate"   >
                    219: <input type="hidden" value='$tomorrow' name="enddate"     >
                    220: <a 
                    221:  href="javascript:pjump('date_start','Starting Date',document.anno.startdate.value,'start','anno.pres','dateset');"
                    222: >Set Starting Date</a>
                    223: <a 
                    224:  href="javascript:pjump('date_end','Ending Date',document.anno.enddate.value,'end','anno.pres','dateset');"
                    225: >Set Ending Date</a><p>
                    226: <textarea name="msg" rows="4" cols="60">
                    227: </textarea>
                    228: <input type="button" onClick="trysubmit()" value="Post Announcement"><hr>
                    229: <input type="button" onClick="removesub()" value="Remove Marked"><hr>
                    230: ENDFORM
                    231:     }
1.5     ! www       232: # ----------------------------------------------------- Summarize all calendars
        !           233:     my %allcal=();
        !           234:     foreach (&Apache::loncommon::findallcourses()) {
        !           235: 	%allcal=(%allcal,&readcalendar($_));
        !           236:     }
        !           237: 
        !           238: # ------------------------------- Initialize table and forward backward buttons
1.3       www       239:     my ($pm,$py,$fm,$fy)=($month-1,$year,$month+1,$year);
                    240:     if ($pm<1) { ($pm,$py)=(12,$year-1); }
                    241:     if ($fm>12){ ($fm,$fy)=(1,$year+1); }
                    242:     $r->print('<h1>'.('','January','February','March','April','May',
                    243: 		      'June','July','August','September','October',
                    244:                       'November','December')[$month].' '.$year.'</h1>'.
                    245:  '<a href="/adm/announcements?month='.$pm.'&year='.$py.'">Previous Month</a> '.
                    246:  '<a href="/adm/announcements?month='.$fm.'&year='.$fy.'">Next Month</a><p>'.
                    247:         '<table border="2" cols="7" rows="5"><tr><th>Sun</th><th>Mon</th>'.
                    248:         '<th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th>');
                    249: 
                    250:     my $tk=&Apache::loncommon::maketime(%firstday);
                    251:     my $outp;
                    252:     my $nm;
                    253: 
                    254: # ---------------------------------------------------------------- Actual table
                    255:     $r->print('<tr>');
                    256:     for (my $i=0;$i<$weekday;$i++) { $r->print(&emptycell); }
                    257:     for (my $i=$weekday;$i<=6;$i++) { 
                    258:         ($tk,$nm,$outp)=&showday($tk,%allcal);
                    259:         $r->print($outp);
                    260:     }
                    261:     $r->print('</tr>');
                    262: 
                    263:     for (my $k=0;$k<=3;$k++) {
                    264:         $r->print('<tr>');
                    265:         for (my $i=0;$i<=6;$i++) {
                    266:             ($tk,$nm,$outp)=&showday($tk,%allcal);
                    267:             if ($month!=$nm) { $outp=&emptycell; }
                    268:             $r->print($outp);
                    269:         }
                    270:         $r->print('</tr>');
                    271:     }
                    272: # ------------------------------------------------------------------- End table
                    273:     if ($allowed) { $r->print('</form>'); }
                    274:     $r->print('</table><p>'.
                    275:  '<a href="/adm/announcements?month='.$pm.'&year='.$py.'">Previous Month</a> '.
                    276:  '<a href="/adm/announcements?month='.$fm.'&year='.$fy.'">Next Month</a><p>'.
                    277:  '</body></html>');
1.1       www       278:     return OK;
                    279: } 
                    280: 
                    281: 1;
                    282: __END__

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