Annotation of loncom/interface/lonwhatsnew.pm, revision 1.16
1.2 albertel 1: #
1.16 ! raeburn 2: # $Id: lonwhatsnew.pm,v 1.15 2005/06/01 19:24:50 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.13 raeburn 626: my %resethash = &Apache::lonnet::restore($symb,'nohist_resourcetracker',$cdom,$crs);
627: $lastreset{$part} = &get_counter_resets(\%resethash,$part);
1.11 raeburn 628: $warning = 1;
629: }
630: }
631: if ($warning) {
632: if ($warningnum %2 == 1) {
633: $rowColor = $rowColor1;
634: } else {
635: $rowColor = $rowColor2;
636: }
637: $$triggered{$symb}{title} = $resource->title;
1.12 raeburn 638: foreach my $part (@parts) {
639: if (exists($stats{$part}{users})) {
1.13 raeburn 640: my $resetname = 'reset_'.&Apache::lonnet::escape($symb."\0".$part);
641: my $resettitle = 'title_'.&Apache::lonnet::escape($symb."\0".$part);
1.11 raeburn 642: if ($$triggered{$symb}{numparts}) {
643: $$triggered{$symb}{text} .= '<tr bgcolor="'.$rowColor.'">'."\n";
644: }
645: if (@parts > 1) {
646: $$triggered{$symb}{text} .= '
1.12 raeburn 647: <td align="right"><small>part - '.$part.'<small></td>';
1.11 raeburn 648: } else {
649: $$triggered{$symb}{text} .= '
650: <td align="right"><small>single part</small></td>';
651: }
652: $$triggered{$symb}{text} .= '
1.12 raeburn 653: <td align="right"><small>'.$stats{$part}{users}.'</small></td>
654: <td align="right"><small>'.$stats{$part}{attempts}.'</small></td>
655: <td align="right"><small>'.$stats{$part}{degdiff}.'</small></td>
1.13 raeburn 656: <td align="right"><small>'.$lastreset{$part}.'</small></td>
657: <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 658: </tr>';
659: $$triggered{$symb}{numparts} ++;
660: }
661: }
662: push(@{$warnings},$symb);
663: $warningnum ++;
664: }
1.1 raeburn 665: }
666: }
667:
1.13 raeburn 668: sub get_counter_resets {
669: my ($resethash,$part) = @_;
670: my $lastreset = 'None';
671: if ($$resethash{'version'}) {
672: for (my $version=1;$version<=$$resethash{'version'};$version++) {
1.15 raeburn 673: if (exists($$resethash{$version.':'.$part."\0".'prev_attempts'})) {
674: $lastreset = $$resethash{$version.':timestamp'};
1.13 raeburn 675: }
676: }
677: }
678: unless ($lastreset eq 'None') {
679: $lastreset = localtime($lastreset);
680: }
681: return $lastreset;
682: }
683:
684: sub get_curr_thresholds {
685: my ($threshold,$cdom,$crs) = @_;
686: my %coursesettings = &Apache::lonnet::dump('environment',
687: $cdom,$crs,'internal.threshold');
688: if (exists($coursesettings{'internal.threshold_av_attempts'})) {
689: $$threshold{'av_attempts'} = $coursesettings{'internal.threshold_av_attempts'};
690: }
691: if (exists($coursesettings{'internal.threshold_degdiff'})) {
692: $$threshold{'degdiff'} = $coursesettings{'internal.threshold_degdiff'};
693: }
694: if (exists($coursesettings{'internal.threshold_numstudents'})) {
695: $$threshold{'numstudents'} = $coursesettings{'internal.threshold_numstudents'};
696: }
697: }
698:
699: sub process_reset {
700: my ($dom,$crs) = @_;
701: my $result = '<b>Counters reset for following problems (and parts):</b><br />';
702: my @agg_types = ('attempts','users','correct');
703: my %agg_titles = (
704: attempts => 'Number of submissions',
705: users => 'Students with submissions',
706: correct => 'Number of correct submissions',
707: );
708: my @resets = ();
709: my %titles = ();
710: foreach my $key (keys %env) {
711: next if ($key !~ /^form\.reset_(.+)$/);
712: my $title = &Apache::lonnet::unescape($env{'form.title_'.$1});
713: my $reset_item = &Apache::lonnet::unescape($1);
714: my %curr_aggregates = &Apache::lonnet::dump('nohist_resourcetracker',$dom,$crs,$reset_item);
715: my %resethash = ();
716: my %aggregates = ();
717: my ($symb,$part) = split/\0/,$reset_item;
718: foreach my $type (@agg_types) {
719: $aggregates{$reset_item."\0".$type} = 0;
720: $resethash{$part."\0".'prev_'.$type} = $curr_aggregates{$reset_item."\0".$type};
721: }
722: my $putresult = &Apache::lonnet::put('nohist_resourcetracker',\%aggregates,
723: $dom,$crs);
724: if ($putresult eq 'ok') {
725: my $storeresult = &Apache::lonnet::cstore(\%resethash,$symb,'nohist_resourcetracker',$dom,$crs);
726: $result .= $title.' -part '.$part.': ';
727: my %new_aggregates = &Apache::lonnet::dump('nohist_resourcetracker',$dom,$crs,$reset_item);
728: foreach my $type (@agg_types) {
729: $result .= $agg_titles{$type}.' = '.$new_aggregates{$reset_item."\0".$type}.'; ';
730: }
731: $result =~ s/; $//;
732: $result .= '<br />';
733: } else {
1.14 albertel 734: $result = $title.' -part '.$part.': '.&mt('Unable to reset counters to zero due to [_1]',$putresult).'.<br />'."\n";
1.13 raeburn 735: }
736: }
737: return $result;
738: }
739:
740: sub process_update {
741: my ($dom,$crs,$threshold_titles) = @_;
1.15 raeburn 742: my $setoutput = '<b>Changes to threshold(s) for problem tracking:</b><br />';
1.13 raeburn 743: foreach (keys %env) {
744: next if ($_!~/^form\.(.+)\_setparmval$/);
745: my $name = $1;
746: my $value = $env{'form.'.$name.'_value'};
747: if ($name && defined($value)) {
748: my $put_result = &Apache::lonnet::put('environment',
749: {$name=>$value},$dom,$crs);
750:
751: my ($shortname) = ($name =~ /^internal\.threshold_(.+)$/);
752: if ($put_result eq 'ok') {
1.14 albertel 753: $setoutput.=&mt('Set threshold for [_1] to [_2]',
754: '<b>'.$$threshold_titles{$shortname}.'</b>',
755: '<b>'.$value.'</b>').'<br />';
756: } else {
757: $setoutput.=&mt('Unable to set threshold for [_1] to [_2] due to [_3].',
758: '<b>'.$name.'</b>','<b>'.$value.'</b>',
759: '<tt>'.$put_result.'</tt>').'<br />';
1.13 raeburn 760: }
761: }
762: }
763: return $setoutput;
764: }
765:
1.1 raeburn 766: sub getmail {
767: my ($newmsgs,$critmsgs) = @_;
768: # Check for unread mail in course
769: my $msgcount = 0;
1.3 albertel 770:
1.10 raeburn 771: my @messages = sort(&Apache::lonnet::getkeys('nohist_email'));
1.3 albertel 772: foreach my $message (@messages) {
773: my $msgid=&Apache::lonnet::escape($message);
1.10 raeburn 774: my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
1.1 raeburn 775: &Apache::lonmsg::unpackmsgid($msgid);
1.10 raeburn 776: if (($fromcid) && ($fromcid eq $env{'request.course.id'})) {
1.1 raeburn 777: if (defined($sendtime) && $sendtime!~/error/) {
778: my $numsendtime = $sendtime;
779: $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
780: if ($status eq 'new') {
1.10 raeburn 781: $msgcount ++;
782: if ($shortsubj eq '') {
783: $shortsubj = &mt('No subject');
784: }
785: $shortsubj = &Apache::lonnet::unescape($shortsubj);
1.1 raeburn 786: push(@{$newmsgs}, {
787: msgid => $msgid,
788: sendtime => $sendtime,
1.10 raeburn 789: shortsub => $shortsubj,
1.1 raeburn 790: from => $fromname,
791: fromdom => $fromdom
792: });
793: }
794: }
795: }
796: }
797:
798: # Check for critical messages in course
799: my %what=&Apache::lonnet::dump('critical');
800: my $result = '';
801: my $critmsgcount = 0;
1.3 albertel 802: foreach my $msgid (sort(keys(%what))) {
1.10 raeburn 803: my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
804: &Apache::lonmsg::unpackmsgid($msgid);
805: if (($fromcid) && ($fromcid eq $env{'request.course.id'})) {
1.1 raeburn 806: if (defined($sendtime) && $sendtime!~/error/) {
807: my $numsendtime = $sendtime;
808: $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
809: $critmsgcount ++;
1.10 raeburn 810: if ($shortsubj eq '') {
811: $shortsubj = &mt('No subject');
812: }
813: $shortsubj = &Apache::lonnet::unescape($shortsubj);
1.1 raeburn 814: push(@{$critmsgs}, {
815: msgid => $msgid,
816: sendtime => $sendtime,
1.10 raeburn 817: shortsub => $shortsubj,
1.1 raeburn 818: from => $fromname,
819: fromdom => $fromdom
820: });
821: }
822: }
823: }
824: return ($msgcount,$critmsgcount);
825: }
826:
827: sub cmp_title {
1.16 ! raeburn 828: my ($a,$b,$res_title) = @_;
! 829: my ($atitle,$btitle) = (lc($$res_title{$a}),lc($$res_title{$b}));
1.1 raeburn 830: $atitle=~s/^\s*//;
831: $btitle=~s/^\s*//;
832: return $atitle cmp $btitle;
833: }
834:
1.7 raeburn 835: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>