Annotation of loncom/interface/lonwhatsnew.pm, revision 1.26
1.2 albertel 1: #
1.26 ! albertel 2: # $Id: lonwhatsnew.pm,v 1.25 2005/07/15 05:30:06 albertel 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: }
211:
212: &get_curr_thresholds(\%threshold,$cdom,$crs);
1.16 raeburn 213: &getitems(\%unread,\%ungraded,\%bombed,\%triggered,\@newdiscussions,\@tograde,\@bombs,\@warnings,$rowColor1,$rowColor2,\%threshold,$cdom,$crs,%res_title);
1.13 raeburn 214: my ($msgcount,$critmsgcount) = &getmail(\@newmsgs,\@critmsgs);
215:
216: $r->print('<br /><table border="0" width="100%" cellpadding="2" cellspacing="4"><tr><td align="left" valign="top" width="45%">');
1.1 raeburn 217:
218: ## UNGRADED ITEMS ##
219: $r->print(<<END);
220: <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
221: <tr><td>
222: <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
223: <tr>
1.11 raeburn 224: <td bgcolor="$tabbg"><b>Problems requiring handgrading</b></td></tr>
1.1 raeburn 225: <tr>
226: <td bgcolor="#ffffff">
227: <table cellpadding="2" cellspacing="0" border="0" width="100%">
228: END
229:
230: if (@tograde > 0) {
1.7 raeburn 231: $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 232: my $rowNum = 0;
233: foreach my $res (@tograde) {
234: if ($rowNum %2 == 1) {
235: $rowColor = $rowColor1;
236: } else {
237: $rowColor = $rowColor2;
238: }
1.7 raeburn 239: my ($map,$id,$url)=&Apache::lonnet::decode_symb($res);
240: my $linkurl=&Apache::lonnet::clutter($url);
241: $linkurl .= '?symb='.&Apache::lonnet::escape($res);
242:
243: $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 244: $rowNum ++;
245: }
246: } else {
247: $r->print('<tr><td bgcolor="#ffffff"><br><center><i><b><small> No problems require handgrading </small><br><br></b></i></td></tr>');
248: }
249: $r->print('</table></td></tr></table></td></tr></table><br />');
1.7 raeburn 250:
251: ## BOMBS ##
252: $r->print(<<"END");
253: <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
254: <tr>
255: <td>
256: <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
257: <tr>
258: <td bgcolor="$tabbg"><b>Problems with errors</b></td>
259: </tr>
260: <tr>
261: <td bgcolor="#ffffff">
262: <table width="100%" cellspacing="0" cellpadding="0" border="0">
263: END
264: my $bombnum = 0;
265: if (@bombs > 0) {
1.13 raeburn 266: $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 267: @bombs = sort { &cmp_title($a,$b,\%res_title) } @bombs;
1.7 raeburn 268: foreach my $bomb (@bombs) {
269: if ($bombnum %2 == 1) {
1.23 albertel 270: $rowColor = $rowColor1;
1.7 raeburn 271: } else {
272: $rowColor = $rowColor2;
273: }
1.13 raeburn 274: $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 275: $bombnum ++;
276: }
277: } else {
278: $r->print('<tr><td bgcolor="#ffffff"><br /><center><b><i><small>No problems with errors</small></i></b></center><br /></td></tr>');
279: }
280: $r->print('</table></td></tr></table></td></tr></table><br />');
281:
1.11 raeburn 282: # DEGDIFF AND AV. TRIES TRIGGERS
1.13 raeburn 283: $r->print(<<"END");
1.11 raeburn 284: <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
285: <tr>
286: <td>
287: <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
288: <tr>
1.13 raeburn 289: <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>
290: </tr>
291: <tr>
292: <td bgcolor="$tabbg" align="right"><a href="/adm/whatsnew?command=chgthreshold"><b><small>Change thresholds?</small></b></a></td>
1.11 raeburn 293: </tr>
294: <tr>
295: <td bgcolor="#ffffff">
1.16 raeburn 296: <table width="100%" cellspacing="2" cellpadding="2" border="0">
1.11 raeburn 297: END
1.13 raeburn 298: my $warningnum = 0;
299: if (@warnings > 0) {
1.16 raeburn 300: @warnings = sort { &cmp_title($a,$b,\%res_title) } @warnings;
1.13 raeburn 301: $r->print('<form name="reset_tracking" method="post">'.
1.14 albertel 302: ' <input type="hidden" name="action" value="reset" />'."\n");
1.13 raeburn 303: $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 304: foreach my $res (@warnings) {
305: if ($warningnum %2 == 1) {
1.13 raeburn 306: $rowColor = $rowColor1;
1.11 raeburn 307: } else {
308: $rowColor = $rowColor2;
309: }
310: my ($map,$id,$url)=&Apache::lonnet::decode_symb($res);
311: my $linkurl=&Apache::lonnet::clutter($url);
312: my $rowspan;
313: if ($triggered{$res}{numparts} > 1) {
314: $rowspan = 'rowspan="'.$triggered{$res}{numparts}.'"';
315: }
316: $linkurl .= '?symb='.&Apache::lonnet::escape($res);
317: $r->print('<tr bgcolor="'.$rowColor.'"><td '.$rowspan.'><a href="'.$linkurl.'"><small>'.$triggered{$res}{title}.'</small></a></td>'.$triggered{$res}{text});
318: $warningnum ++;
319: }
1.13 raeburn 320: $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 321: } else {
1.13 raeburn 322: $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 323: }
324: $r->print('</table></td></tr></table></td></tr></table><br />');
325:
1.1 raeburn 326: $r->print('</td><td width="5%"> </td><td align="left" valign="top" width-"50%">');
327:
1.11 raeburn 328: ## UNREAD COURSE DISCUSSION POSTS ##
329: $r->print(<<"END");
330: <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
331: <tr><td>
332: <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
333: <tr>
334: <td bgcolor="$tabbg"><b>Unread course discussion posts</b></td>
335: </tr>
336: <tr>
337: <td bgcolor="#ffffff">
338: <table cellpadding="2" cellspacing="0" border="0" width="100%">
339: END
340:
341: if (@newdiscussions > 0) {
342: $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 343: @newdiscussions = sort { &cmp_title($a,$b,\%res_title) } @newdiscussions;
1.11 raeburn 344: my $rowNum = 0;
345: foreach my $ressymb (@newdiscussions) {
346: my $forum_title = $unread{$ressymb}{'title'};
347: my $type = 'Resource';
348: my $feedurl=&Apache::lonfeedback::get_feedurl($ressymb);
349: if ($feedurl =~ /bulletinboard/) {
350: $type = 'Bulletin Board';
351: }
352: my $unreadnum = keys(%{$unread{$ressymb}});
353: $unreadnum = $unreadnum - 2;
354: if ($unreadnum > 0) {
355: if ($rowNum %2 == 1) {
356: $rowColor = $rowColor1;
357: } else {
358: $rowColor = $rowColor2;
359: }
360: $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>');
361: $rowNum ++;
362: }
363: }
364: } else {
365: $r->print('<tr><td bgcolor="#ffffff"><br><center> <i><b><small>No unread posts in course discussions</small></b></i><br><br></td></tr>');
366: }
367: $r->print('</table></td></tr></table></td></tr></table><br />');
368:
1.1 raeburn 369: ## MESSAGES ##
370: $r->print(<<END);
371: <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
372: <tr>
373: <td>
374: <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
375: <tr>
376: <td bgcolor="$tabbg"><b>New course messages</b></td>
377: </tr>
378: <tr>
379: <td bgcolor="#ffffff">
380: <table width="100%" cellspacing="0" cellpadding="0" border="0">
381: END
382: if ($msgcount > 0) {
1.7 raeburn 383: $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 384: my $rowNum = 0;
385: my $mailcount = 1;
386: foreach my $msg (@newmsgs) {
387: if ($rowNum %2 == 1) {
388: $rowColor = $rowColor1;
389: } else {
390: $rowColor = $rowColor2;
391: }
1.20 www 392: $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 393: $rowNum ++;
394: $mailcount ++;
395: }
396: } else {
397: $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>');
398: }
399:
400: $r->print('</table></td></tr></table></td></tr></table><br />');
401:
402: $r->print(<<END);
403: <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
404: <tr>
405: <td>
406: <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
407: <tr>
408: <td bgcolor="$tabbg"><b>New critical messages in course</b></td>
409: </tr>
410: <tr> <td bgcolor="#ffffff">
411: <table width="100%" cellspacing="0" cellpadding="0" border="0">
412: END
413:
414: if ($critmsgcount > 0) {
1.7 raeburn 415: $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 416: my $rowNum = 0;
417: my $mailcount = 1;
418: foreach my $msg (@critmsgs) {
419: if ($rowNum %2 == 1) {
420: $rowColor = $rowColor1;
421: } else {
422: $rowColor = $rowColor2;
423: }
1.7 raeburn 424: $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 425: $rowNum ++;
426: $mailcount ++;
427: }
428: } else {
429: $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>');
430: }
431:
432: $r->print('</table></td></tr></table></td></tr></table><br />');
433:
434: $r->print('
435: </table>
436: </td>
437: </tr>
438: </table>');
439: $r->print('</td></tr></table>');
440: }
441:
1.11 raeburn 442: #-------------------------------
443: # display_config_box
444: #
1.13 raeburn 445: # Display the threshold setting screen
1.11 raeburn 446: #
447: #-------------------------------
448:
449: sub display_config_box() {
1.15 raeburn 450: my ($r,$command,$tabbg,$threshold_titles,$cdom,$crs) = @_;
1.13 raeburn 451: my %threshold = ();
452: my $rowColor1 = "#ffffff";
453: my $rowColor2 = "#eeeeee";
454: my $rowColor;
455:
456: my @thresholditems = ("av_attempts","degdiff","numstudents");
457: my %threshold_titles = (
458: av_attempts => 'Average number of attempts',
459: degdiff => 'Degree of difficulty',
460: numstudents => 'Total number of students with submissions',
461: );
1.15 raeburn 462: &get_curr_thresholds(\%threshold,$cdom,$crs);
1.13 raeburn 463:
464: $r->print('<br /><form name="thresholdform" method="post"><table border="0" cellpadding="2" cellspacing="4"><tr><td align="left" valign="top" width="45%">
465: <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
466: <tr>
467: <td>
468: <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000">
469: <tr>
470: <td bgcolor="#ffffff">
471: <table cellspacing="0" cellpadding="4" border="0">
472: <tr bgcolor="'.$tabbg.'">
473: <th>Threshold Name</th>
474: <th>Current value</th>
475: <th>Change?</th>
476: </tr>');
477: my $rowNum =0;
478: foreach my $type (@thresholditems) {
479: my $parameter = 'internal.threshold_'.$type;
480: # onchange is javascript to automatically check the 'Set' button.
481: my $onchange = 'onFocus="javascript:window.document.forms'.
482: "['thresholdform'].elements['".$parameter."_setparmval']".
483: '.checked=true;"';
484: if ($rowNum %2 == 1) {
485: $rowColor = $rowColor1;
486: } else {
487: $rowColor = $rowColor2;
488: }
489: $r->print('
490: <tr bgcolor="'.$rowColor.'">
491: <td>'.$threshold_titles{$type}.'</td>
492: <td>'.&Apache::lonhtmlcommon::textbox($parameter.'_value',
493: $threshold{$type},
494: 10,$onchange).'</td>
495: <td>'
496: .&Apache::lonhtmlcommon::checkbox($parameter.'_setparmval').
497: '</td>
498: </tr>');
499: $rowNum ++;
500: }
501: $r->print('</table></td></tr></table></td></tr></table>
502: <br /><input type="submit" name="threshold" value="Make changes" />
503: <input type="hidden" name="action" value="update" />
504: </form>');
1.11 raeburn 505: }
506:
1.1 raeburn 507: sub getitems {
1.16 raeburn 508: my ($unread,$ungraded,$bombed,$triggered,$newdiscussions,$tograde,$bombs,$warnings,$rowColor1,$rowColor2,$threshold,$cdom,$crs,$res_title) = @_;
1.1 raeburn 509: my $navmap = Apache::lonnavmaps::navmap->new();
1.26 ! albertel 510: # force retrieve Resource to seed the part id cache we'll need it later
! 511: my @allres=$navmap->retrieveResources(undef,sub {if ($_[0]->is_problem) { $_[0]->parts();} return 1;});
1.13 raeburn 512: my %discussiontime = &Apache::lonnet::dump('discussiontimes',$cdom,$crs);
513: my %lastread = &Apache::lonnet::dump('nohist_'.$env{'request.course.id'}.
514: '_discuss',$env{'user.domain'},$env{'user.name'},'lastread');
1.1 raeburn 515: my %lastreadtime = ();
516: my @discussions = ();
517: my ($classlist,$keylist) = &Apache::loncoursedata::get_classlist();
518:
1.11 raeburn 519: my %resourcetracker = &Apache::lonnet::dump('nohist_resourcetracker',
1.13 raeburn 520: $cdom,$crs);
1.11 raeburn 521: my $warningnum = 0;
1.3 albertel 522: foreach my $key (keys(%lastread)) {
523: my $newkey = $key;
524: $newkey =~ s/_lastread$//;
525: $lastreadtime{$newkey} = $lastread{$key};
1.1 raeburn 526: }
527: foreach my $resource (@allres) {
528: my $result = '';
529: my $applies = 0;
530: my $symb = $resource->symb();
1.13 raeburn 531: # %{$$bombed{$symb}} = ();
1.1 raeburn 532: %{$$ungraded{$symb}} = ();
1.11 raeburn 533: %{$$triggered{$symb}} = ();
534: $$triggered{$symb}{numparts} = 0;
1.1 raeburn 535: my $title = $resource->compTitle();
1.16 raeburn 536: $$res_title{$symb} = $title;
1.8 albertel 537: my $ressymb = $resource->wrap_symb();
1.1 raeburn 538: # Check for unread discussion postings
1.21 albertel 539: if ($resource->hasDiscussion()) {
1.1 raeburn 540: push(@discussions,$ressymb);
541: my $prevread = 0;
542: my $unreadcount = 0;
543: %{$$unread{$ressymb}} = ();
544: $$unread{$ressymb}{'title'} = $title;
545: $$unread{$ressymb}{'symb'} = $symb;
546: if (defined($lastreadtime{$ressymb})) {
547: $prevread = $lastreadtime{$ressymb};
548: }
1.13 raeburn 549: my %contrib = &Apache::lonnet::restore($ressymb,
550: $env{'request.course.id'},$cdom,$crs);
1.1 raeburn 551: if ($contrib{'version'}) {
552: for (my $id=1;$id<=$contrib{'version'};$id++) {
553: unless (($contrib{'hidden'}=~/\.$id\./) || ($contrib{'deleted'}=~/\.$id\./)) {
554: if ($prevread <$contrib{$id.':timestamp'}) {
555: $$unread{$ressymb}{$unreadcount} = $id.': '.$contrib{$id.':subject'};
556: $unreadcount ++;
557: }
558: }
559: }
560: }
1.9 albertel 561: if ($unreadcount) { push(@{$newdiscussions}, $ressymb); }
562: }
1.1 raeburn 563:
564: # Check for ungraded problems
565: if ($resource->is_problem()) {
566: my $ctr = 0;
567: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1.25 albertel 568: my $partlist=$resource->parts();
1.19 albertel 569: my $handgradeable;
1.25 albertel 570: foreach my $part (@$partlist) {
571: if ($resource->handgrade($part) eq 'yes') {
572: $handgradeable=1; last;
573: }
1.19 albertel 574: }
1.23 albertel 575: if ($handgradeable) {
576: foreach my $student (keys(%$classlist)) {
577: my ($uname,$udom) = split(/:/,$student);
578: my %status=&Apache::grades::student_gradeStatus($url,$symb,$udom,$uname,$partlist);
579: my $submitted = 0;
580: my $ungraded = 0;
581: foreach (keys(%status)) {
582: $submitted = 1 if ($status{$_} ne 'nothing');
583: $ungraded = 1 if ($status{$_} =~ /^ungraded/);
584: my ($foo,$partid,$foo1) = split(/\./,$_);
585: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
586: $submitted = 0;
587: }
588: }
589: next if (!$submitted || !$ungraded);
590: $ctr ++;
591: }
592: if ($ctr) {
593: $$ungraded{$symb}{count} = $ctr;
594: $$ungraded{$symb}{title} = $title;
595: push(@{$tograde}, $symb);
596: }
597: }
1.1 raeburn 598: }
599:
600: # Check for bombs
601: if ($resource->getErrors()) {
602: my $errors = $resource->getErrors();
1.23 albertel 603: $errors =~ s/^,//;
1.1 raeburn 604: my @bombs = split(/,/, $errors);
605: my $errorcount = scalar(@bombs);
606: my $errorlink = '<a href="/adm/email?display='.
1.13 raeburn 607: &Apache::lonnet::escape($bombs[0]).'">'.
608: $title.'</a>';
1.1 raeburn 609: $$bombed{$symb}{errorcount} = $errorcount;
610: $$bombed{$symb}{errorlink} = $errorlink;
611: push(@{$bombs}, $symb);
612: }
1.11 raeburn 613: # Compile maxtries and degree of difficulty for problem parts
614: my @parts = @{$resource->parts()};
1.12 raeburn 615: my %stats;
1.13 raeburn 616: my %lastreset = ();
1.11 raeburn 617: my $warning = 0;
618: my $rowColor;
1.12 raeburn 619: foreach my $part (@parts) {
620: %{$stats{$part}} = ();
1.11 raeburn 621: my ($attempts,$users,$corrects,$degdiff,$av_attempts);
1.12 raeburn 622: if (exists($resourcetracker{$symb."\0".$part."\0attempts"})) {
623: $attempts = $resourcetracker{$symb."\0".$part."\0attempts"};
1.11 raeburn 624: }
1.12 raeburn 625: if (exists($resourcetracker{$symb."\0".$part."\0users"})) {
626: $users = $resourcetracker{$symb."\0".$part."\0users"};
1.11 raeburn 627: }
1.12 raeburn 628: if (exists($resourcetracker{$symb."\0".$part."\0correct"})) {
629: $corrects = $resourcetracker{$symb."\0".$part."\0correct"};
1.11 raeburn 630: }
631: if ($attempts > 0) {
632: $degdiff = 1 - ($corrects/$attempts);
633: $degdiff = sprintf("%.2f",$degdiff);
634: }
635: if ($users > 0) {
636: $av_attempts = $attempts/$users;
1.16 raeburn 637: $av_attempts = sprintf("%.2f",$av_attempts);
1.11 raeburn 638: }
1.13 raeburn 639: if ((($degdiff ne '' && $degdiff >= $$threshold{'degdiff'}) || ($av_attempts ne '' && $av_attempts >= $$threshold{'av_attempts'})) && ($users >= $$threshold{'numstudents'})) {
1.12 raeburn 640: $stats{$part}{degdiff} = $degdiff;
641: $stats{$part}{attempts} = $av_attempts;
642: $stats{$part}{users} = $users;
1.17 albertel 643: $lastreset{$part} = $resourcetracker{$symb."\0".$part."\0resettime"};
1.11 raeburn 644: $warning = 1;
645: }
646: }
647: if ($warning) {
648: if ($warningnum %2 == 1) {
649: $rowColor = $rowColor1;
650: } else {
651: $rowColor = $rowColor2;
652: }
653: $$triggered{$symb}{title} = $resource->title;
1.12 raeburn 654: foreach my $part (@parts) {
655: if (exists($stats{$part}{users})) {
1.13 raeburn 656: my $resetname = 'reset_'.&Apache::lonnet::escape($symb."\0".$part);
657: my $resettitle = 'title_'.&Apache::lonnet::escape($symb."\0".$part);
1.11 raeburn 658: if ($$triggered{$symb}{numparts}) {
659: $$triggered{$symb}{text} .= '<tr bgcolor="'.$rowColor.'">'."\n";
660: }
661: if (@parts > 1) {
662: $$triggered{$symb}{text} .= '
1.12 raeburn 663: <td align="right"><small>part - '.$part.'<small></td>';
1.11 raeburn 664: } else {
665: $$triggered{$symb}{text} .= '
666: <td align="right"><small>single part</small></td>';
667: }
668: $$triggered{$symb}{text} .= '
1.12 raeburn 669: <td align="right"><small>'.$stats{$part}{users}.'</small></td>
670: <td align="right"><small>'.$stats{$part}{attempts}.'</small></td>
671: <td align="right"><small>'.$stats{$part}{degdiff}.'</small></td>
1.13 raeburn 672: <td align="right"><small>'.$lastreset{$part}.'</small></td>
673: <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 674: </tr>';
675: $$triggered{$symb}{numparts} ++;
676: }
677: }
678: push(@{$warnings},$symb);
679: $warningnum ++;
680: }
1.1 raeburn 681: }
682: }
683:
1.13 raeburn 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 = ();
1.17 albertel 710: foreach my $key (keys(%env)) {
1.13 raeburn 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 %aggregates = ();
1.17 albertel 716: my ($symb,$part) = split(/\0/,$reset_item);
1.13 raeburn 717: foreach my $type (@agg_types) {
718: $aggregates{$reset_item."\0".$type} = 0;
719: }
1.17 albertel 720: $aggregates{$reset_item."\0".'resettime'} = time;
1.13 raeburn 721: my $putresult = &Apache::lonnet::put('nohist_resourcetracker',\%aggregates,
722: $dom,$crs);
723: if ($putresult eq 'ok') {
724: $result .= $title.' -part '.$part.': ';
725: my %new_aggregates = &Apache::lonnet::dump('nohist_resourcetracker',$dom,$crs,$reset_item);
726: foreach my $type (@agg_types) {
727: $result .= $agg_titles{$type}.' = '.$new_aggregates{$reset_item."\0".$type}.'; ';
728: }
729: $result =~ s/; $//;
730: $result .= '<br />';
731: } else {
1.14 albertel 732: $result = $title.' -part '.$part.': '.&mt('Unable to reset counters to zero due to [_1]',$putresult).'.<br />'."\n";
1.13 raeburn 733: }
734: }
735: return $result;
736: }
737:
738: sub process_update {
739: my ($dom,$crs,$threshold_titles) = @_;
1.15 raeburn 740: my $setoutput = '<b>Changes to threshold(s) for problem tracking:</b><br />';
1.13 raeburn 741: foreach (keys %env) {
742: next if ($_!~/^form\.(.+)\_setparmval$/);
743: my $name = $1;
744: my $value = $env{'form.'.$name.'_value'};
745: if ($name && defined($value)) {
746: my $put_result = &Apache::lonnet::put('environment',
747: {$name=>$value},$dom,$crs);
748:
749: my ($shortname) = ($name =~ /^internal\.threshold_(.+)$/);
750: if ($put_result eq 'ok') {
1.14 albertel 751: $setoutput.=&mt('Set threshold for [_1] to [_2]',
752: '<b>'.$$threshold_titles{$shortname}.'</b>',
753: '<b>'.$value.'</b>').'<br />';
754: } else {
755: $setoutput.=&mt('Unable to set threshold for [_1] to [_2] due to [_3].',
756: '<b>'.$name.'</b>','<b>'.$value.'</b>',
757: '<tt>'.$put_result.'</tt>').'<br />';
1.13 raeburn 758: }
759: }
760: }
761: return $setoutput;
762: }
763:
1.1 raeburn 764: sub getmail {
765: my ($newmsgs,$critmsgs) = @_;
766: # Check for unread mail in course
767: my $msgcount = 0;
1.3 albertel 768:
1.10 raeburn 769: my @messages = sort(&Apache::lonnet::getkeys('nohist_email'));
1.3 albertel 770: foreach my $message (@messages) {
771: my $msgid=&Apache::lonnet::escape($message);
1.10 raeburn 772: my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
1.1 raeburn 773: &Apache::lonmsg::unpackmsgid($msgid);
1.10 raeburn 774: if (($fromcid) && ($fromcid eq $env{'request.course.id'})) {
1.1 raeburn 775: if (defined($sendtime) && $sendtime!~/error/) {
776: my $numsendtime = $sendtime;
777: $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
778: if ($status eq 'new') {
1.10 raeburn 779: $msgcount ++;
780: if ($shortsubj eq '') {
781: $shortsubj = &mt('No subject');
782: }
783: $shortsubj = &Apache::lonnet::unescape($shortsubj);
1.1 raeburn 784: push(@{$newmsgs}, {
785: msgid => $msgid,
786: sendtime => $sendtime,
1.10 raeburn 787: shortsub => $shortsubj,
1.1 raeburn 788: from => $fromname,
789: fromdom => $fromdom
790: });
791: }
792: }
793: }
794: }
795:
796: # Check for critical messages in course
797: my %what=&Apache::lonnet::dump('critical');
798: my $result = '';
799: my $critmsgcount = 0;
1.3 albertel 800: foreach my $msgid (sort(keys(%what))) {
1.10 raeburn 801: my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
802: &Apache::lonmsg::unpackmsgid($msgid);
803: if (($fromcid) && ($fromcid eq $env{'request.course.id'})) {
1.1 raeburn 804: if (defined($sendtime) && $sendtime!~/error/) {
805: my $numsendtime = $sendtime;
806: $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
807: $critmsgcount ++;
1.10 raeburn 808: if ($shortsubj eq '') {
809: $shortsubj = &mt('No subject');
810: }
811: $shortsubj = &Apache::lonnet::unescape($shortsubj);
1.1 raeburn 812: push(@{$critmsgs}, {
813: msgid => $msgid,
814: sendtime => $sendtime,
1.10 raeburn 815: shortsub => $shortsubj,
1.1 raeburn 816: from => $fromname,
817: fromdom => $fromdom
818: });
819: }
820: }
821: }
822: return ($msgcount,$critmsgcount);
823: }
824:
825: sub cmp_title {
1.16 raeburn 826: my ($a,$b,$res_title) = @_;
827: my ($atitle,$btitle) = (lc($$res_title{$a}),lc($$res_title{$b}));
1.1 raeburn 828: $atitle=~s/^\s*//;
829: $btitle=~s/^\s*//;
830: return $atitle cmp $btitle;
831: }
832:
1.7 raeburn 833: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>