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