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