Annotation of loncom/interface/lonwhatsnew.pm, revision 1.17
1.2 albertel 1: #
1.17 ! albertel 2: # $Id: lonwhatsnew.pm,v 1.16 2005/06/03 19:33:37 raeburn Exp $
1.2 albertel 3: #
4: # Copyright Michigan State University Board of Trustees
5: #
6: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
7: #
8: # LON-CAPA is free software; you can redistribute it and/or modify
9: # it under the terms of the GNU General Public License as published by
10: # the Free Software Foundation; either version 2 of the License, or
11: # (at your option) any later version.
12: #
13: # LON-CAPA is distributed in the hope that it will be useful,
14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: # GNU General Public License for more details.
17: #
18: # You should have received a copy of the GNU General Public License
19: # along with LON-CAPA; if not, write to the Free Software
20: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21: #
22: # /home/httpd/html/adm/gpl.txt
23: #
24: # http://www.lon-capa.org/
25: #
26:
27:
1.1 raeburn 28: package Apache::lonwhatsnew;
29:
30: use strict;
31: use lib qw(/home/httpd/lib/perl);
32: use Apache::lonnet;
1.3 albertel 33: use Apache::loncommon();
34: use Apache::lonhtmlcommon();
1.1 raeburn 35: use Apache::lonlocal;
1.3 albertel 36: use Apache::loncoursedata();
37: use Apache::lonnavmaps();
1.1 raeburn 38: use Apache::Constants qw(:common :http);
39: use Time::Local;
40:
41: #----------------------------
42: # handler
43: #
44: #----------------------------
45:
46: sub handler {
47: my $r = shift;
1.7 raeburn 48: if ($r->header_only) {
49: &Apache::loncommon::content_type($r,'text/html');
50: $r->send_http_header;
51: return OK;
52: }
1.1 raeburn 53: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['command']);
54:
1.13 raeburn 55: my $command;
56: if ($env{'form.action'} eq 'reset') {
57: $command = 'reset';
58: } elsif ($env{'form.action'} eq 'update') {
59: $command = 'update';
60: } else {
61: $command = $env{'form.command'};
1.1 raeburn 62: }
63:
1.7 raeburn 64: &Apache::loncommon::content_type($r,'text/html');
65: $r->send_http_header;
1.1 raeburn 66: $r->print(&display_header());
1.5 albertel 67: if (! (($env{'request.course.fn'}) && (&Apache::lonnet::allowed('vsa',$env{'request.course.id'})))) {
1.1 raeburn 68: # Not in a course, or not allowed to modify parms
1.5 albertel 69: $env{'user.error.msg'}="/adm/whatsnew:vsa:0:0:Cannot display student activity";
1.1 raeburn 70: return HTTP_NOT_ACCEPTABLE;
71: }
72:
1.7 raeburn 73: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.13 raeburn 74: if ($command eq 'chgthreshold') {
1.7 raeburn 75: &Apache::lonhtmlcommon::add_breadcrumb
1.13 raeburn 76: ({href=>'/adm/whatsnew?command=threshold',
77: text=>"Change thresholds"});
1.7 raeburn 78: $r->print(&Apache::lonhtmlcommon::breadcrumbs
1.13 raeburn 79: (undef,'Course Action Items','Course_Action_Items_Thresholds'));
1.7 raeburn 80: } else {
81: &Apache::lonhtmlcommon::add_breadcrumb
1.13 raeburn 82: ({href=>'/adm/whatsnew',
1.7 raeburn 83: text=>"Display Action Items"});
84: $r->print(&Apache::lonhtmlcommon::breadcrumbs
85: (undef,'Course Action Items','Course_Action_Items_Display'));
86: }
1.1 raeburn 87: &display_main_box($r,$command);
1.14 albertel 88: return OK;
1.1 raeburn 89: }
90:
91: #------------------------------
92: # display_main_box
93: #
94: # Display all the elements within the main box
95: #------------------------------
96:
97: sub display_main_box {
98: my ($r,$command) = @_;
99: my $domain=&Apache::loncommon::determinedomain();
100: my $tabbg=&Apache::loncommon::designparm('coordinator.tabbg',$domain);
1.7 raeburn 101: $r->print('<table width="100%" border="0" cellpadding="5" cellspacing="0"><tr><td width="100%">');
1.13 raeburn 102:
103: my %threshold_titles = (
104: av_attempts => 'Average number of attempts',
105: degdiff => 'Degree of difficulty',
106: numstudents => 'Total number of students with submissions',
107: );
1.15 raeburn 108: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
109: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
110:
1.13 raeburn 111: if ($command eq 'chgthreshold') {
1.15 raeburn 112: &display_config_box($r,$command,$tabbg,\%threshold_titles,$cdom,$crs);
1.1 raeburn 113: } else {
1.15 raeburn 114: &display_actions_box($r,$command,\%threshold_titles,$cdom,$crs);
1.1 raeburn 115: }
116: $r->print(<<END_OF_BLOCK);
117: </td>
118: </tr>
119: </table><br />
120: </body>
121: </html>
122: END_OF_BLOCK
123: }
124:
125: #-------------------------------
126: # display_header
127: #
128: # Display the header information and set
129: # up the HTML
130: #-------------------------------
131:
132: sub display_header{
1.3 albertel 133: my $html=&Apache::lonxml::xmlbegin();
1.1 raeburn 134: my $bodytag=&Apache::loncommon::bodytag('Course Action Items');
135: return(<<ENDHEAD);
1.3 albertel 136: $html
1.1 raeburn 137: <head>
138: <title>Course Action Items</title>
139: </head>
140: $bodytag
141: ENDHEAD
142: }
143:
144: #-------------------------------
145: # display_actions_box
146: #
147: # Display the action items
148: #
149: #-------------------------------
150:
151: sub display_actions_box() {
1.15 raeburn 152: my ($r,$command,$threshold_titles,$cdom,$crs) = @_;
1.1 raeburn 153:
154: my $rowColor1 = "#ffffff";
155: my $rowColor2 = "#eeeeee";
156: my $rowColor;
157:
158: my %unread = ();
159: my %ungraded = ();
160: my %bombed = ();
1.11 raeburn 161: my %triggered = ();
1.1 raeburn 162: my @newmsgs = ();
163: my @critmsgs = ();
164: my @newdiscussions = ();
165: my @tograde = ();
166: my @bombs = ();
1.11 raeburn 167: my @warnings = ();
1.16 raeburn 168: my %res_title = ();
1.1 raeburn 169:
170: my $domain=&Apache::loncommon::determinedomain();
171: my $function;
1.5 albertel 172: if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.1 raeburn 173: $function='coordinator';
174: }
1.5 albertel 175: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.1 raeburn 176: $function='admin';
177: }
178:
1.13 raeburn 179: my %threshold = (
180: av_attempts => 0,
181: degdiff => 0.01,
182: numstudents => 0,
183: );
184:
1.1 raeburn 185: my $pgbg=&Apache::loncommon::designparm($function.'.pgbg',$domain);
186: my $tabbg=&Apache::loncommon::designparm($function.'.tabbg',$domain);
187:
1.5 albertel 188: unless ($env{'request.course.id'}) {
1.1 raeburn 189: $r->print('<br /><b><center>You are accessing an invalid course</center></b><br /><br />');
190: return;
191: }
192:
1.13 raeburn 193: my $result;
194:
195: if ($command eq 'reset') {
196: $result = &process_reset($cdom,$crs);
197: } elsif ($command eq 'update') {
198: $result = &process_update($cdom,$crs,$threshold_titles);
199: }
200: if ($result) {
201: $r->print($result.'<hr width="100%" />');
202: }
203:
204: &get_curr_thresholds(\%threshold,$cdom,$crs);
1.16 raeburn 205: &getitems(\%unread,\%ungraded,\%bombed,\%triggered,\@newdiscussions,\@tograde,\@bombs,\@warnings,$rowColor1,$rowColor2,\%threshold,$cdom,$crs,%res_title);
1.13 raeburn 206: my ($msgcount,$critmsgcount) = &getmail(\@newmsgs,\@critmsgs);
207:
208: $r->print('<br /><table border="0" width="100%" cellpadding="2" cellspacing="4"><tr><td align="left" valign="top" width="45%">');
1.1 raeburn 209:
210: ## UNGRADED ITEMS ##
211: $r->print(<<END);
212: <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
213: <tr><td>
214: <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
215: <tr>
1.11 raeburn 216: <td bgcolor="$tabbg"><b>Problems requiring handgrading</b></td></tr>
1.1 raeburn 217: <tr>
218: <td bgcolor="#ffffff">
219: <table cellpadding="2" cellspacing="0" border="0" width="100%">
220: END
221:
222: if (@tograde > 0) {
1.7 raeburn 223: $r->print('<tr bgcolor="#cccccc"><td><b><small>Problem Name</small></b></td><td align="right"><b><small>Number ungraded</small></b></td></tr>');
1.1 raeburn 224: my $rowNum = 0;
225: foreach my $res (@tograde) {
226: if ($rowNum %2 == 1) {
227: $rowColor = $rowColor1;
228: } else {
229: $rowColor = $rowColor2;
230: }
1.7 raeburn 231: my ($map,$id,$url)=&Apache::lonnet::decode_symb($res);
232: my $linkurl=&Apache::lonnet::clutter($url);
233: $linkurl .= '?symb='.&Apache::lonnet::escape($res);
234:
235: $r->print('<tr bgcolor="'.$rowColor.'"><td><a href="'.$linkurl.'"><small>'.$ungraded{$res}{title}.'</small></a></td><td align="right"><small>'.$ungraded{$res}{count}.'</small></td></tr>');
1.1 raeburn 236: $rowNum ++;
237: }
238: } else {
239: $r->print('<tr><td bgcolor="#ffffff"><br><center><i><b><small> No problems require handgrading </small><br><br></b></i></td></tr>');
240: }
241: $r->print('</table></td></tr></table></td></tr></table><br />');
1.7 raeburn 242:
243: ## BOMBS ##
244: $r->print(<<"END");
245: <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
246: <tr>
247: <td>
248: <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
249: <tr>
250: <td bgcolor="$tabbg"><b>Problems with errors</b></td>
251: </tr>
252: <tr>
253: <td bgcolor="#ffffff">
254: <table width="100%" cellspacing="0" cellpadding="0" border="0">
255: END
256: my $bombnum = 0;
257: if (@bombs > 0) {
1.13 raeburn 258: $r->print('<tr bgcolor="#cccccc"><td><b><small>Resource</small></b></td><td align="right"><b><small>Number of errors</small></b></td></tr>');
1.16 raeburn 259: @bombs = sort { &cmp_title($a,$b,\%res_title) } @bombs;
1.7 raeburn 260: foreach my $bomb (@bombs) {
261: if ($bombnum %2 == 1) {
262: $rowColor = $rowColor1;
263: } else {
264: $rowColor = $rowColor2;
265: }
1.13 raeburn 266: $r->print('<tr bgcolor="'.$rowColor.'"><td><small>'.$bombed{$bomb}{errorlink}.'</small></td><td align="right"><small>'.$bombed{$bomb}{errorcount}.'</small></td></tr>');
1.7 raeburn 267: $bombnum ++;
268: }
269: } else {
270: $r->print('<tr><td bgcolor="#ffffff"><br /><center><b><i><small>No problems with errors</small></i></b></center><br /></td></tr>');
271: }
272: $r->print('</table></td></tr></table></td></tr></table><br />');
273:
1.11 raeburn 274: # DEGDIFF AND AV. TRIES TRIGGERS
1.13 raeburn 275: $r->print(<<"END");
1.11 raeburn 276: <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
277: <tr>
278: <td>
279: <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
280: <tr>
1.13 raeburn 281: <td bgcolor="$tabbg"><b>Problems with av. attempts ≥ $threshold{'av_attempts'} or deg. difficulty ≥ $threshold{'degdiff'}<br /> and total number of students with submissions ≥ $threshold{'numstudents'}</b></td>
282: </tr>
283: <tr>
284: <td bgcolor="$tabbg" align="right"><a href="/adm/whatsnew?command=chgthreshold"><b><small>Change thresholds?</small></b></a></td>
1.11 raeburn 285: </tr>
286: <tr>
287: <td bgcolor="#ffffff">
1.16 raeburn 288: <table width="100%" cellspacing="2" cellpadding="2" border="0">
1.11 raeburn 289: END
1.13 raeburn 290: my $warningnum = 0;
291: if (@warnings > 0) {
1.16 raeburn 292: @warnings = sort { &cmp_title($a,$b,\%res_title) } @warnings;
1.13 raeburn 293: $r->print('<form name="reset_tracking" method="post">'.
1.14 albertel 294: ' <input type="hidden" name="action" value="reset" />'."\n");
1.13 raeburn 295: $r->print('<tr bgcolor="#cccccc"><td><b><small>Resource</small></b></td><td align="right"><b><small>Part</small></b></td><td align="right"><b><small>Num. students</small></b></td><td align="right"><b><small>Av. Attempts</small></b></td><td align="right"><b><small>Deg. Diff</small></b></td><td align="right"><b><small>Last Reset</small></b></td><td align="right"><b><small>Reset Count?</small></b></td></tr>');
1.11 raeburn 296: foreach my $res (@warnings) {
297: if ($warningnum %2 == 1) {
1.13 raeburn 298: $rowColor = $rowColor1;
1.11 raeburn 299: } else {
300: $rowColor = $rowColor2;
301: }
302: my ($map,$id,$url)=&Apache::lonnet::decode_symb($res);
303: my $linkurl=&Apache::lonnet::clutter($url);
304: my $rowspan;
305: if ($triggered{$res}{numparts} > 1) {
306: $rowspan = 'rowspan="'.$triggered{$res}{numparts}.'"';
307: }
308: $linkurl .= '?symb='.&Apache::lonnet::escape($res);
309: $r->print('<tr bgcolor="'.$rowColor.'"><td '.$rowspan.'><a href="'.$linkurl.'"><small>'.$triggered{$res}{title}.'</small></a></td>'.$triggered{$res}{text});
310: $warningnum ++;
311: }
1.13 raeburn 312: $r->print('<tr bgcolor="#cccccc"><td colspan="7" align="right"><br /><b><small><input type="submit" name="counters" value="Reset counters to 0" /></form>');
1.11 raeburn 313: } else {
1.13 raeburn 314: $r->print('<tr><td bgcolor="#ffffff"><br /><center><b><i><small>No problems satisfy threshold criteria.</small></i></b></center><br /></td></tr>');
1.11 raeburn 315: }
316: $r->print('</table></td></tr></table></td></tr></table><br />');
317:
1.1 raeburn 318: $r->print('</td><td width="5%"> </td><td align="left" valign="top" width-"50%">');
319:
1.11 raeburn 320: ## UNREAD COURSE DISCUSSION POSTS ##
321: $r->print(<<"END");
322: <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
323: <tr><td>
324: <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
325: <tr>
326: <td bgcolor="$tabbg"><b>Unread course discussion posts</b></td>
327: </tr>
328: <tr>
329: <td bgcolor="#ffffff">
330: <table cellpadding="2" cellspacing="0" border="0" width="100%">
331: END
332:
333: if (@newdiscussions > 0) {
334: $r->print('<tr bgcolor="#cccccc"><td><b><small>Location</small></b></td><td><b><small>Type</small></b><td align="right"><b><small>Number of new posts</small></b></td></tr>');
1.16 raeburn 335: @newdiscussions = sort { &cmp_title($a,$b,\%res_title) } @newdiscussions;
1.11 raeburn 336: my $rowNum = 0;
337: foreach my $ressymb (@newdiscussions) {
338: my $forum_title = $unread{$ressymb}{'title'};
339: my $type = 'Resource';
340: my $feedurl=&Apache::lonfeedback::get_feedurl($ressymb);
341: if ($feedurl =~ /bulletinboard/) {
342: $type = 'Bulletin Board';
343: }
344: my $unreadnum = keys(%{$unread{$ressymb}});
345: $unreadnum = $unreadnum - 2;
346: if ($unreadnum > 0) {
347: if ($rowNum %2 == 1) {
348: $rowColor = $rowColor1;
349: } else {
350: $rowColor = $rowColor2;
351: }
352: $r->print('<tr bgcolor="'.$rowColor.'"><td><small><a href="'.$feedurl.'?symb='.$unread{$ressymb}{symb}.'">'.$forum_title.'</a> </td><td><small>'.$type.'</small></td><td align="right">'.$unreadnum.' </td></tr>');
353: $rowNum ++;
354: }
355: }
356: } else {
357: $r->print('<tr><td bgcolor="#ffffff"><br><center> <i><b><small>No unread posts in course discussions</small></b></i><br><br></td></tr>');
358: }
359: $r->print('</table></td></tr></table></td></tr></table><br />');
360:
1.1 raeburn 361: ## MESSAGES ##
362: $r->print(<<END);
363: <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
364: <tr>
365: <td>
366: <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
367: <tr>
368: <td bgcolor="$tabbg"><b>New course messages</b></td>
369: </tr>
370: <tr>
371: <td bgcolor="#ffffff">
372: <table width="100%" cellspacing="0" cellpadding="0" border="0">
373: END
374: if ($msgcount > 0) {
1.7 raeburn 375: $r->print('<tr bgcolor="#cccccc"><td><b><small>'.&mt('Number').'</small></b></td><td><b><small>'.&mt('Subject').'</small></b></td><td><b><small>'.&mt('Sender').'</small></b></td><td><b><small>'.&mt('Date/Time').'</small></b></td></tr>');
1.1 raeburn 376: my $rowNum = 0;
377: my $mailcount = 1;
378: foreach my $msg (@newmsgs) {
379: if ($rowNum %2 == 1) {
380: $rowColor = $rowColor1;
381: } else {
382: $rowColor = $rowColor2;
383: }
1.7 raeburn 384: $r->print('<tr bgcolor="'.$rowColor.'"><td valign="top"><small>'.$mailcount.'. <small></td><td valign="top"><small><a href="/adm/mail?">'.$msg->{'shortsub'}.'</a> </small></td><td valign="top"><small> '.$msg->{'from'}.'@'.$msg->{'fromdom'}.' </small></td><td valign="top"><small>'.$msg->{'sendtime'}.'</small></td></tr>');
1.1 raeburn 385: $rowNum ++;
386: $mailcount ++;
387: }
388: } else {
389: $r->print('<tr><td bgcolor="#ffffff" width="100%"><center><br /><b><i><small>No new course messages</small></i></b><br /><br /></center></td></tr>');
390: }
391:
392: $r->print('</table></td></tr></table></td></tr></table><br />');
393:
394: $r->print(<<END);
395: <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
396: <tr>
397: <td>
398: <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
399: <tr>
400: <td bgcolor="$tabbg"><b>New critical messages in course</b></td>
401: </tr>
402: <tr> <td bgcolor="#ffffff">
403: <table width="100%" cellspacing="0" cellpadding="0" border="0">
404: END
405:
406: if ($critmsgcount > 0) {
1.7 raeburn 407: $r->print('<tr bgcolor="#cccccc"><td><b><small>Number</small></b></td><td><b><small>Subject</small></b></td><td><b><small>Sender</small></b></td><td><b><small>Date/Time</small></b></td></tr>');
1.1 raeburn 408: my $rowNum = 0;
409: my $mailcount = 1;
410: foreach my $msg (@critmsgs) {
411: if ($rowNum %2 == 1) {
412: $rowColor = $rowColor1;
413: } else {
414: $rowColor = $rowColor2;
415: }
1.7 raeburn 416: $r->print('<tr bgcolor="'.$rowColor.'"><td valign="top"><small>'.$mailcount.'. <small></td><td valign="top"><small><a href="/adm/mail?">'.$msg->{'shortsub'}.'</a> </small></td><td valign="top"><small> '.$msg->{'from'}.'@'.$msg->{'fromdom'}.' </small></td><td valign="top"><small>'.$msg->{'sendtime'}.'</small></td></tr>');
1.1 raeburn 417: $rowNum ++;
418: $mailcount ++;
419: }
420: } else {
421: $r->print('<tr><td bgcolor="#ffffff" width="100%"><center><br /><b><i><small>No unread critical messages in course</small></i></b><br /><br /></center></td></tr>');
422: }
423:
424: $r->print('</table></td></tr></table></td></tr></table><br />');
425:
426: $r->print('
427: </table>
428: </td>
429: </tr>
430: </table>');
431: $r->print('</td></tr></table>');
432: }
433:
1.11 raeburn 434: #-------------------------------
435: # display_config_box
436: #
1.13 raeburn 437: # Display the threshold setting screen
1.11 raeburn 438: #
439: #-------------------------------
440:
441: sub display_config_box() {
1.15 raeburn 442: my ($r,$command,$tabbg,$threshold_titles,$cdom,$crs) = @_;
1.13 raeburn 443: my %threshold = ();
444: my $rowColor1 = "#ffffff";
445: my $rowColor2 = "#eeeeee";
446: my $rowColor;
447:
448: my @thresholditems = ("av_attempts","degdiff","numstudents");
449: my %threshold_titles = (
450: av_attempts => 'Average number of attempts',
451: degdiff => 'Degree of difficulty',
452: numstudents => 'Total number of students with submissions',
453: );
1.15 raeburn 454: &get_curr_thresholds(\%threshold,$cdom,$crs);
1.13 raeburn 455:
456: $r->print('<br /><form name="thresholdform" method="post"><table border="0" cellpadding="2" cellspacing="4"><tr><td align="left" valign="top" width="45%">
457: <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
458: <tr>
459: <td>
460: <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000">
461: <tr>
462: <td bgcolor="#ffffff">
463: <table cellspacing="0" cellpadding="4" border="0">
464: <tr bgcolor="'.$tabbg.'">
465: <th>Threshold Name</th>
466: <th>Current value</th>
467: <th>Change?</th>
468: </tr>');
469: my $rowNum =0;
470: foreach my $type (@thresholditems) {
471: my $parameter = 'internal.threshold_'.$type;
472: # onchange is javascript to automatically check the 'Set' button.
473: my $onchange = 'onFocus="javascript:window.document.forms'.
474: "['thresholdform'].elements['".$parameter."_setparmval']".
475: '.checked=true;"';
476: if ($rowNum %2 == 1) {
477: $rowColor = $rowColor1;
478: } else {
479: $rowColor = $rowColor2;
480: }
481: $r->print('
482: <tr bgcolor="'.$rowColor.'">
483: <td>'.$threshold_titles{$type}.'</td>
484: <td>'.&Apache::lonhtmlcommon::textbox($parameter.'_value',
485: $threshold{$type},
486: 10,$onchange).'</td>
487: <td>'
488: .&Apache::lonhtmlcommon::checkbox($parameter.'_setparmval').
489: '</td>
490: </tr>');
491: $rowNum ++;
492: }
493: $r->print('</table></td></tr></table></td></tr></table>
494: <br /><input type="submit" name="threshold" value="Make changes" />
495: <input type="hidden" name="action" value="update" />
496: </form>');
1.11 raeburn 497: }
498:
1.1 raeburn 499: sub getitems {
1.16 raeburn 500: my ($unread,$ungraded,$bombed,$triggered,$newdiscussions,$tograde,$bombs,$warnings,$rowColor1,$rowColor2,$threshold,$cdom,$crs,$res_title) = @_;
1.1 raeburn 501: my $navmap = Apache::lonnavmaps::navmap->new();
502: my @allres=$navmap->retrieveResources();
1.13 raeburn 503: my %discussiontime = &Apache::lonnet::dump('discussiontimes',$cdom,$crs);
504: my %lastread = &Apache::lonnet::dump('nohist_'.$env{'request.course.id'}.
505: '_discuss',$env{'user.domain'},$env{'user.name'},'lastread');
1.1 raeburn 506: my %lastreadtime = ();
507: my @discussions = ();
508: my ($classlist,$keylist) = &Apache::loncoursedata::get_classlist();
509:
1.11 raeburn 510: my %resourcetracker = &Apache::lonnet::dump('nohist_resourcetracker',
1.13 raeburn 511: $cdom,$crs);
1.11 raeburn 512: my $warningnum = 0;
1.3 albertel 513: foreach my $key (keys(%lastread)) {
514: my $newkey = $key;
515: $newkey =~ s/_lastread$//;
516: $lastreadtime{$newkey} = $lastread{$key};
1.1 raeburn 517: }
518: foreach my $resource (@allres) {
519: my $result = '';
520: my $applies = 0;
521: my $symb = $resource->symb();
1.13 raeburn 522: # %{$$bombed{$symb}} = ();
1.1 raeburn 523: %{$$ungraded{$symb}} = ();
1.11 raeburn 524: %{$$triggered{$symb}} = ();
525: $$triggered{$symb}{numparts} = 0;
1.1 raeburn 526: my $title = $resource->compTitle();
1.16 raeburn 527: $$res_title{$symb} = $title;
1.8 albertel 528: my $ressymb = $resource->wrap_symb();
1.1 raeburn 529: # Check for unread discussion postings
530: if (defined($discussiontime{$ressymb})) {
531: push(@discussions,$ressymb);
532: my $prevread = 0;
533: my $unreadcount = 0;
534: %{$$unread{$ressymb}} = ();
535: $$unread{$ressymb}{'title'} = $title;
536: $$unread{$ressymb}{'symb'} = $symb;
537: if (defined($lastreadtime{$ressymb})) {
538: $prevread = $lastreadtime{$ressymb};
539: }
1.13 raeburn 540: my %contrib = &Apache::lonnet::restore($ressymb,
541: $env{'request.course.id'},$cdom,$crs);
1.1 raeburn 542: if ($contrib{'version'}) {
543: for (my $id=1;$id<=$contrib{'version'};$id++) {
544: unless (($contrib{'hidden'}=~/\.$id\./) || ($contrib{'deleted'}=~/\.$id\./)) {
545: if ($prevread <$contrib{$id.':timestamp'}) {
546: $$unread{$ressymb}{$unreadcount} = $id.': '.$contrib{$id.':subject'};
547: $unreadcount ++;
548: }
549: }
550: }
551: }
1.9 albertel 552: if ($unreadcount) { push(@{$newdiscussions}, $ressymb); }
553: }
1.1 raeburn 554:
555: # Check for ungraded problems
556: if ($resource->is_problem()) {
557: my $ctr = 0;
558: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
559: my ($partlist,$handgrade,$responseType) = &Apache::grades::response_type($url,$symb);
560: foreach my $student (keys(%$classlist)) {
1.3 albertel 561: my ($uname,$udom) = split(/:/,$student);
1.1 raeburn 562: my %status=&Apache::grades::student_gradeStatus($url,$symb,$udom,$uname,$partlist);
563: my $submitted = 0;
1.10 raeburn 564: my $ungraded = 0;
1.1 raeburn 565: foreach (keys(%status)) {
566: $submitted = 1 if ($status{$_} ne 'nothing');
1.10 raeburn 567: $ungraded = 1 if ($status{$_} =~ /^ungraded/);
1.1 raeburn 568: my ($foo,$partid,$foo1) = split(/\./,$_);
569: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
570: $submitted = 0;
571: }
572: }
1.10 raeburn 573: next if (!$submitted || !$ungraded);
1.1 raeburn 574: $ctr ++;
575: }
576: if ($ctr) {
577: $$ungraded{$symb}{count} = $ctr;
578: $$ungraded{$symb}{title} = $title;
579: push(@{$tograde}, $symb);
580: }
581: }
582:
583: # Check for bombs
584: if ($resource->getErrors()) {
585: my $errors = $resource->getErrors();
1.13 raeburn 586: $errors =~ s/^,//;
1.1 raeburn 587: my @bombs = split(/,/, $errors);
588: my $errorcount = scalar(@bombs);
589: my $errorlink = '<a href="/adm/email?display='.
1.13 raeburn 590: &Apache::lonnet::escape($bombs[0]).'">'.
591: $title.'</a>';
1.1 raeburn 592: $$bombed{$symb}{errorcount} = $errorcount;
593: $$bombed{$symb}{errorlink} = $errorlink;
594: push(@{$bombs}, $symb);
595: }
1.11 raeburn 596: # Compile maxtries and degree of difficulty for problem parts
597: my @parts = @{$resource->parts()};
1.12 raeburn 598: my %stats;
1.13 raeburn 599: my %lastreset = ();
1.11 raeburn 600: my $warning = 0;
601: my $rowColor;
1.12 raeburn 602: foreach my $part (@parts) {
603: %{$stats{$part}} = ();
1.11 raeburn 604: my ($attempts,$users,$corrects,$degdiff,$av_attempts);
1.12 raeburn 605: if (exists($resourcetracker{$symb."\0".$part."\0attempts"})) {
606: $attempts = $resourcetracker{$symb."\0".$part."\0attempts"};
1.11 raeburn 607: }
1.12 raeburn 608: if (exists($resourcetracker{$symb."\0".$part."\0users"})) {
609: $users = $resourcetracker{$symb."\0".$part."\0users"};
1.11 raeburn 610: }
1.12 raeburn 611: if (exists($resourcetracker{$symb."\0".$part."\0correct"})) {
612: $corrects = $resourcetracker{$symb."\0".$part."\0correct"};
1.11 raeburn 613: }
614: if ($attempts > 0) {
615: $degdiff = 1 - ($corrects/$attempts);
616: $degdiff = sprintf("%.2f",$degdiff);
617: }
618: if ($users > 0) {
619: $av_attempts = $attempts/$users;
1.16 raeburn 620: $av_attempts = sprintf("%.2f",$av_attempts);
1.11 raeburn 621: }
1.13 raeburn 622: if ((($degdiff ne '' && $degdiff >= $$threshold{'degdiff'}) || ($av_attempts ne '' && $av_attempts >= $$threshold{'av_attempts'})) && ($users >= $$threshold{'numstudents'})) {
1.12 raeburn 623: $stats{$part}{degdiff} = $degdiff;
624: $stats{$part}{attempts} = $av_attempts;
625: $stats{$part}{users} = $users;
1.17 ! albertel 626: $lastreset{$part} = $resourcetracker{$symb."\0".$part."\0resettime"};
1.11 raeburn 627: $warning = 1;
628: }
629: }
630: if ($warning) {
631: if ($warningnum %2 == 1) {
632: $rowColor = $rowColor1;
633: } else {
634: $rowColor = $rowColor2;
635: }
636: $$triggered{$symb}{title} = $resource->title;
1.12 raeburn 637: foreach my $part (@parts) {
638: if (exists($stats{$part}{users})) {
1.13 raeburn 639: my $resetname = 'reset_'.&Apache::lonnet::escape($symb."\0".$part);
640: my $resettitle = 'title_'.&Apache::lonnet::escape($symb."\0".$part);
1.11 raeburn 641: if ($$triggered{$symb}{numparts}) {
642: $$triggered{$symb}{text} .= '<tr bgcolor="'.$rowColor.'">'."\n";
643: }
644: if (@parts > 1) {
645: $$triggered{$symb}{text} .= '
1.12 raeburn 646: <td align="right"><small>part - '.$part.'<small></td>';
1.11 raeburn 647: } else {
648: $$triggered{$symb}{text} .= '
649: <td align="right"><small>single part</small></td>';
650: }
651: $$triggered{$symb}{text} .= '
1.12 raeburn 652: <td align="right"><small>'.$stats{$part}{users}.'</small></td>
653: <td align="right"><small>'.$stats{$part}{attempts}.'</small></td>
654: <td align="right"><small>'.$stats{$part}{degdiff}.'</small></td>
1.13 raeburn 655: <td align="right"><small>'.$lastreset{$part}.'</small></td>
656: <td align="right"><small><input type="checkbox" name="'.$resetname.'" /><input type="hidden" name="'.$resettitle.'" value="'.&Apache::lonnet::escape($$triggered{$symb}{title}).'" /></td>
1.11 raeburn 657: </tr>';
658: $$triggered{$symb}{numparts} ++;
659: }
660: }
661: push(@{$warnings},$symb);
662: $warningnum ++;
663: }
1.1 raeburn 664: }
665: }
666:
1.13 raeburn 667: sub get_curr_thresholds {
668: my ($threshold,$cdom,$crs) = @_;
669: my %coursesettings = &Apache::lonnet::dump('environment',
670: $cdom,$crs,'internal.threshold');
671: if (exists($coursesettings{'internal.threshold_av_attempts'})) {
672: $$threshold{'av_attempts'} = $coursesettings{'internal.threshold_av_attempts'};
673: }
674: if (exists($coursesettings{'internal.threshold_degdiff'})) {
675: $$threshold{'degdiff'} = $coursesettings{'internal.threshold_degdiff'};
676: }
677: if (exists($coursesettings{'internal.threshold_numstudents'})) {
678: $$threshold{'numstudents'} = $coursesettings{'internal.threshold_numstudents'};
679: }
680: }
681:
682: sub process_reset {
683: my ($dom,$crs) = @_;
684: my $result = '<b>Counters reset for following problems (and parts):</b><br />';
685: my @agg_types = ('attempts','users','correct');
686: my %agg_titles = (
687: attempts => 'Number of submissions',
688: users => 'Students with submissions',
689: correct => 'Number of correct submissions',
690: );
691: my @resets = ();
692: my %titles = ();
1.17 ! albertel 693: foreach my $key (keys(%env)) {
1.13 raeburn 694: next if ($key !~ /^form\.reset_(.+)$/);
695: my $title = &Apache::lonnet::unescape($env{'form.title_'.$1});
696: my $reset_item = &Apache::lonnet::unescape($1);
697: my %curr_aggregates = &Apache::lonnet::dump('nohist_resourcetracker',$dom,$crs,$reset_item);
698: my %aggregates = ();
1.17 ! albertel 699: my ($symb,$part) = split(/\0/,$reset_item);
1.13 raeburn 700: foreach my $type (@agg_types) {
701: $aggregates{$reset_item."\0".$type} = 0;
702: }
1.17 ! albertel 703: $aggregates{$reset_item."\0".'resettime'} = time;
1.13 raeburn 704: my $putresult = &Apache::lonnet::put('nohist_resourcetracker',\%aggregates,
705: $dom,$crs);
706: if ($putresult eq 'ok') {
707: $result .= $title.' -part '.$part.': ';
708: my %new_aggregates = &Apache::lonnet::dump('nohist_resourcetracker',$dom,$crs,$reset_item);
709: foreach my $type (@agg_types) {
710: $result .= $agg_titles{$type}.' = '.$new_aggregates{$reset_item."\0".$type}.'; ';
711: }
712: $result =~ s/; $//;
713: $result .= '<br />';
714: } else {
1.14 albertel 715: $result = $title.' -part '.$part.': '.&mt('Unable to reset counters to zero due to [_1]',$putresult).'.<br />'."\n";
1.13 raeburn 716: }
717: }
718: return $result;
719: }
720:
721: sub process_update {
722: my ($dom,$crs,$threshold_titles) = @_;
1.15 raeburn 723: my $setoutput = '<b>Changes to threshold(s) for problem tracking:</b><br />';
1.13 raeburn 724: foreach (keys %env) {
725: next if ($_!~/^form\.(.+)\_setparmval$/);
726: my $name = $1;
727: my $value = $env{'form.'.$name.'_value'};
728: if ($name && defined($value)) {
729: my $put_result = &Apache::lonnet::put('environment',
730: {$name=>$value},$dom,$crs);
731:
732: my ($shortname) = ($name =~ /^internal\.threshold_(.+)$/);
733: if ($put_result eq 'ok') {
1.14 albertel 734: $setoutput.=&mt('Set threshold for [_1] to [_2]',
735: '<b>'.$$threshold_titles{$shortname}.'</b>',
736: '<b>'.$value.'</b>').'<br />';
737: } else {
738: $setoutput.=&mt('Unable to set threshold for [_1] to [_2] due to [_3].',
739: '<b>'.$name.'</b>','<b>'.$value.'</b>',
740: '<tt>'.$put_result.'</tt>').'<br />';
1.13 raeburn 741: }
742: }
743: }
744: return $setoutput;
745: }
746:
1.1 raeburn 747: sub getmail {
748: my ($newmsgs,$critmsgs) = @_;
749: # Check for unread mail in course
750: my $msgcount = 0;
1.3 albertel 751:
1.10 raeburn 752: my @messages = sort(&Apache::lonnet::getkeys('nohist_email'));
1.3 albertel 753: foreach my $message (@messages) {
754: my $msgid=&Apache::lonnet::escape($message);
1.10 raeburn 755: my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
1.1 raeburn 756: &Apache::lonmsg::unpackmsgid($msgid);
1.10 raeburn 757: if (($fromcid) && ($fromcid eq $env{'request.course.id'})) {
1.1 raeburn 758: if (defined($sendtime) && $sendtime!~/error/) {
759: my $numsendtime = $sendtime;
760: $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
761: if ($status eq 'new') {
1.10 raeburn 762: $msgcount ++;
763: if ($shortsubj eq '') {
764: $shortsubj = &mt('No subject');
765: }
766: $shortsubj = &Apache::lonnet::unescape($shortsubj);
1.1 raeburn 767: push(@{$newmsgs}, {
768: msgid => $msgid,
769: sendtime => $sendtime,
1.10 raeburn 770: shortsub => $shortsubj,
1.1 raeburn 771: from => $fromname,
772: fromdom => $fromdom
773: });
774: }
775: }
776: }
777: }
778:
779: # Check for critical messages in course
780: my %what=&Apache::lonnet::dump('critical');
781: my $result = '';
782: my $critmsgcount = 0;
1.3 albertel 783: foreach my $msgid (sort(keys(%what))) {
1.10 raeburn 784: my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
785: &Apache::lonmsg::unpackmsgid($msgid);
786: if (($fromcid) && ($fromcid eq $env{'request.course.id'})) {
1.1 raeburn 787: if (defined($sendtime) && $sendtime!~/error/) {
788: my $numsendtime = $sendtime;
789: $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
790: $critmsgcount ++;
1.10 raeburn 791: if ($shortsubj eq '') {
792: $shortsubj = &mt('No subject');
793: }
794: $shortsubj = &Apache::lonnet::unescape($shortsubj);
1.1 raeburn 795: push(@{$critmsgs}, {
796: msgid => $msgid,
797: sendtime => $sendtime,
1.10 raeburn 798: shortsub => $shortsubj,
1.1 raeburn 799: from => $fromname,
800: fromdom => $fromdom
801: });
802: }
803: }
804: }
805: return ($msgcount,$critmsgcount);
806: }
807:
808: sub cmp_title {
1.16 raeburn 809: my ($a,$b,$res_title) = @_;
810: my ($atitle,$btitle) = (lc($$res_title{$a}),lc($$res_title{$b}));
1.1 raeburn 811: $atitle=~s/^\s*//;
812: $btitle=~s/^\s*//;
813: return $atitle cmp $btitle;
814: }
815:
1.7 raeburn 816: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>