File:  [LON-CAPA] / loncom / interface / lonannounce.pm
Revision 1.3: download - view: text, annotated - select for diffs
Thu Aug 8 13:44:17 2002 UTC (21 years, 9 months ago) by www
Branches: MAIN
CVS tags: HEAD
Routines for chat, explanation of option in parmset, chat function kind of
works

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

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