Annotation of loncom/interface/lonwhatsnew.pm, revision 1.25
1.2 albertel 1: #
1.25 ! albertel 2: # $Id: lonwhatsnew.pm,v 1.24 2005/07/14 21:30:25 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();
510: my @allres=$navmap->retrieveResources();
1.13 raeburn 511: my %discussiontime = &Apache::lonnet::dump('discussiontimes',$cdom,$crs);
512: my %lastread = &Apache::lonnet::dump('nohist_'.$env{'request.course.id'}.
513: '_discuss',$env{'user.domain'},$env{'user.name'},'lastread');
1.1 raeburn 514: my %lastreadtime = ();
515: my @discussions = ();
516: my ($classlist,$keylist) = &Apache::loncoursedata::get_classlist();
517:
1.11 raeburn 518: my %resourcetracker = &Apache::lonnet::dump('nohist_resourcetracker',
1.13 raeburn 519: $cdom,$crs);
1.11 raeburn 520: my $warningnum = 0;
1.3 albertel 521: foreach my $key (keys(%lastread)) {
522: my $newkey = $key;
523: $newkey =~ s/_lastread$//;
524: $lastreadtime{$newkey} = $lastread{$key};
1.1 raeburn 525: }
526: foreach my $resource (@allres) {
527: my $result = '';
528: my $applies = 0;
529: my $symb = $resource->symb();
1.13 raeburn 530: # %{$$bombed{$symb}} = ();
1.1 raeburn 531: %{$$ungraded{$symb}} = ();
1.11 raeburn 532: %{$$triggered{$symb}} = ();
533: $$triggered{$symb}{numparts} = 0;
1.1 raeburn 534: my $title = $resource->compTitle();
1.16 raeburn 535: $$res_title{$symb} = $title;
1.8 albertel 536: my $ressymb = $resource->wrap_symb();
1.1 raeburn 537: # Check for unread discussion postings
1.21 albertel 538: if ($resource->hasDiscussion()) {
1.1 raeburn 539: push(@discussions,$ressymb);
540: my $prevread = 0;
541: my $unreadcount = 0;
542: %{$$unread{$ressymb}} = ();
543: $$unread{$ressymb}{'title'} = $title;
544: $$unread{$ressymb}{'symb'} = $symb;
545: if (defined($lastreadtime{$ressymb})) {
546: $prevread = $lastreadtime{$ressymb};
547: }
1.13 raeburn 548: my %contrib = &Apache::lonnet::restore($ressymb,
549: $env{'request.course.id'},$cdom,$crs);
1.1 raeburn 550: if ($contrib{'version'}) {
551: for (my $id=1;$id<=$contrib{'version'};$id++) {
552: unless (($contrib{'hidden'}=~/\.$id\./) || ($contrib{'deleted'}=~/\.$id\./)) {
553: if ($prevread <$contrib{$id.':timestamp'}) {
554: $$unread{$ressymb}{$unreadcount} = $id.': '.$contrib{$id.':subject'};
555: $unreadcount ++;
556: }
557: }
558: }
559: }
1.9 albertel 560: if ($unreadcount) { push(@{$newdiscussions}, $ressymb); }
561: }
1.1 raeburn 562:
563: # Check for ungraded problems
564: if ($resource->is_problem()) {
565: my $ctr = 0;
566: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1.25 ! albertel 567: my $partlist=$resource->parts();
1.19 albertel 568: my $handgradeable;
1.25 ! albertel 569: foreach my $part (@$partlist) {
! 570: if ($resource->handgrade($part) eq 'yes') {
! 571: $handgradeable=1; last;
! 572: }
1.19 albertel 573: }
1.23 albertel 574: if ($handgradeable) {
575: foreach my $student (keys(%$classlist)) {
576: my ($uname,$udom) = split(/:/,$student);
577: my %status=&Apache::grades::student_gradeStatus($url,$symb,$udom,$uname,$partlist);
578: my $submitted = 0;
579: my $ungraded = 0;
580: foreach (keys(%status)) {
581: $submitted = 1 if ($status{$_} ne 'nothing');
582: $ungraded = 1 if ($status{$_} =~ /^ungraded/);
583: my ($foo,$partid,$foo1) = split(/\./,$_);
584: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
585: $submitted = 0;
586: }
587: }
588: next if (!$submitted || !$ungraded);
589: $ctr ++;
590: }
591: if ($ctr) {
592: $$ungraded{$symb}{count} = $ctr;
593: $$ungraded{$symb}{title} = $title;
594: push(@{$tograde}, $symb);
595: }
596: }
1.1 raeburn 597: }
598:
599: # Check for bombs
600: if ($resource->getErrors()) {
601: my $errors = $resource->getErrors();
1.23 albertel 602: $errors =~ s/^,//;
1.1 raeburn 603: my @bombs = split(/,/, $errors);
604: my $errorcount = scalar(@bombs);
605: my $errorlink = '<a href="/adm/email?display='.
1.13 raeburn 606: &Apache::lonnet::escape($bombs[0]).'">'.
607: $title.'</a>';
1.1 raeburn 608: $$bombed{$symb}{errorcount} = $errorcount;
609: $$bombed{$symb}{errorlink} = $errorlink;
610: push(@{$bombs}, $symb);
611: }
1.11 raeburn 612: # Compile maxtries and degree of difficulty for problem parts
613: my @parts = @{$resource->parts()};
1.12 raeburn 614: my %stats;
1.13 raeburn 615: my %lastreset = ();
1.11 raeburn 616: my $warning = 0;
617: my $rowColor;
1.12 raeburn 618: foreach my $part (@parts) {
619: %{$stats{$part}} = ();
1.11 raeburn 620: my ($attempts,$users,$corrects,$degdiff,$av_attempts);
1.12 raeburn 621: if (exists($resourcetracker{$symb."\0".$part."\0attempts"})) {
622: $attempts = $resourcetracker{$symb."\0".$part."\0attempts"};
1.11 raeburn 623: }
1.12 raeburn 624: if (exists($resourcetracker{$symb."\0".$part."\0users"})) {
625: $users = $resourcetracker{$symb."\0".$part."\0users"};
1.11 raeburn 626: }
1.12 raeburn 627: if (exists($resourcetracker{$symb."\0".$part."\0correct"})) {
628: $corrects = $resourcetracker{$symb."\0".$part."\0correct"};
1.11 raeburn 629: }
630: if ($attempts > 0) {
631: $degdiff = 1 - ($corrects/$attempts);
632: $degdiff = sprintf("%.2f",$degdiff);
633: }
634: if ($users > 0) {
635: $av_attempts = $attempts/$users;
1.16 raeburn 636: $av_attempts = sprintf("%.2f",$av_attempts);
1.11 raeburn 637: }
1.13 raeburn 638: if ((($degdiff ne '' && $degdiff >= $$threshold{'degdiff'}) || ($av_attempts ne '' && $av_attempts >= $$threshold{'av_attempts'})) && ($users >= $$threshold{'numstudents'})) {
1.12 raeburn 639: $stats{$part}{degdiff} = $degdiff;
640: $stats{$part}{attempts} = $av_attempts;
641: $stats{$part}{users} = $users;
1.17 albertel 642: $lastreset{$part} = $resourcetracker{$symb."\0".$part."\0resettime"};
1.11 raeburn 643: $warning = 1;
644: }
645: }
646: if ($warning) {
647: if ($warningnum %2 == 1) {
648: $rowColor = $rowColor1;
649: } else {
650: $rowColor = $rowColor2;
651: }
652: $$triggered{$symb}{title} = $resource->title;
1.12 raeburn 653: foreach my $part (@parts) {
654: if (exists($stats{$part}{users})) {
1.13 raeburn 655: my $resetname = 'reset_'.&Apache::lonnet::escape($symb."\0".$part);
656: my $resettitle = 'title_'.&Apache::lonnet::escape($symb."\0".$part);
1.11 raeburn 657: if ($$triggered{$symb}{numparts}) {
658: $$triggered{$symb}{text} .= '<tr bgcolor="'.$rowColor.'">'."\n";
659: }
660: if (@parts > 1) {
661: $$triggered{$symb}{text} .= '
1.12 raeburn 662: <td align="right"><small>part - '.$part.'<small></td>';
1.11 raeburn 663: } else {
664: $$triggered{$symb}{text} .= '
665: <td align="right"><small>single part</small></td>';
666: }
667: $$triggered{$symb}{text} .= '
1.12 raeburn 668: <td align="right"><small>'.$stats{$part}{users}.'</small></td>
669: <td align="right"><small>'.$stats{$part}{attempts}.'</small></td>
670: <td align="right"><small>'.$stats{$part}{degdiff}.'</small></td>
1.13 raeburn 671: <td align="right"><small>'.$lastreset{$part}.'</small></td>
672: <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 673: </tr>';
674: $$triggered{$symb}{numparts} ++;
675: }
676: }
677: push(@{$warnings},$symb);
678: $warningnum ++;
679: }
1.1 raeburn 680: }
681: }
682:
1.13 raeburn 683: sub get_curr_thresholds {
684: my ($threshold,$cdom,$crs) = @_;
685: my %coursesettings = &Apache::lonnet::dump('environment',
686: $cdom,$crs,'internal.threshold');
687: if (exists($coursesettings{'internal.threshold_av_attempts'})) {
688: $$threshold{'av_attempts'} = $coursesettings{'internal.threshold_av_attempts'};
689: }
690: if (exists($coursesettings{'internal.threshold_degdiff'})) {
691: $$threshold{'degdiff'} = $coursesettings{'internal.threshold_degdiff'};
692: }
693: if (exists($coursesettings{'internal.threshold_numstudents'})) {
694: $$threshold{'numstudents'} = $coursesettings{'internal.threshold_numstudents'};
695: }
696: }
697:
698: sub process_reset {
699: my ($dom,$crs) = @_;
700: my $result = '<b>Counters reset for following problems (and parts):</b><br />';
701: my @agg_types = ('attempts','users','correct');
702: my %agg_titles = (
703: attempts => 'Number of submissions',
704: users => 'Students with submissions',
705: correct => 'Number of correct submissions',
706: );
707: my @resets = ();
708: my %titles = ();
1.17 albertel 709: foreach my $key (keys(%env)) {
1.13 raeburn 710: next if ($key !~ /^form\.reset_(.+)$/);
711: my $title = &Apache::lonnet::unescape($env{'form.title_'.$1});
712: my $reset_item = &Apache::lonnet::unescape($1);
713: my %curr_aggregates = &Apache::lonnet::dump('nohist_resourcetracker',$dom,$crs,$reset_item);
714: my %aggregates = ();
1.17 albertel 715: my ($symb,$part) = split(/\0/,$reset_item);
1.13 raeburn 716: foreach my $type (@agg_types) {
717: $aggregates{$reset_item."\0".$type} = 0;
718: }
1.17 albertel 719: $aggregates{$reset_item."\0".'resettime'} = time;
1.13 raeburn 720: my $putresult = &Apache::lonnet::put('nohist_resourcetracker',\%aggregates,
721: $dom,$crs);
722: if ($putresult eq 'ok') {
723: $result .= $title.' -part '.$part.': ';
724: my %new_aggregates = &Apache::lonnet::dump('nohist_resourcetracker',$dom,$crs,$reset_item);
725: foreach my $type (@agg_types) {
726: $result .= $agg_titles{$type}.' = '.$new_aggregates{$reset_item."\0".$type}.'; ';
727: }
728: $result =~ s/; $//;
729: $result .= '<br />';
730: } else {
1.14 albertel 731: $result = $title.' -part '.$part.': '.&mt('Unable to reset counters to zero due to [_1]',$putresult).'.<br />'."\n";
1.13 raeburn 732: }
733: }
734: return $result;
735: }
736:
737: sub process_update {
738: my ($dom,$crs,$threshold_titles) = @_;
1.15 raeburn 739: my $setoutput = '<b>Changes to threshold(s) for problem tracking:</b><br />';
1.13 raeburn 740: foreach (keys %env) {
741: next if ($_!~/^form\.(.+)\_setparmval$/);
742: my $name = $1;
743: my $value = $env{'form.'.$name.'_value'};
744: if ($name && defined($value)) {
745: my $put_result = &Apache::lonnet::put('environment',
746: {$name=>$value},$dom,$crs);
747:
748: my ($shortname) = ($name =~ /^internal\.threshold_(.+)$/);
749: if ($put_result eq 'ok') {
1.14 albertel 750: $setoutput.=&mt('Set threshold for [_1] to [_2]',
751: '<b>'.$$threshold_titles{$shortname}.'</b>',
752: '<b>'.$value.'</b>').'<br />';
753: } else {
754: $setoutput.=&mt('Unable to set threshold for [_1] to [_2] due to [_3].',
755: '<b>'.$name.'</b>','<b>'.$value.'</b>',
756: '<tt>'.$put_result.'</tt>').'<br />';
1.13 raeburn 757: }
758: }
759: }
760: return $setoutput;
761: }
762:
1.1 raeburn 763: sub getmail {
764: my ($newmsgs,$critmsgs) = @_;
765: # Check for unread mail in course
766: my $msgcount = 0;
1.3 albertel 767:
1.10 raeburn 768: my @messages = sort(&Apache::lonnet::getkeys('nohist_email'));
1.3 albertel 769: foreach my $message (@messages) {
770: my $msgid=&Apache::lonnet::escape($message);
1.10 raeburn 771: my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
1.1 raeburn 772: &Apache::lonmsg::unpackmsgid($msgid);
1.10 raeburn 773: if (($fromcid) && ($fromcid eq $env{'request.course.id'})) {
1.1 raeburn 774: if (defined($sendtime) && $sendtime!~/error/) {
775: my $numsendtime = $sendtime;
776: $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
777: if ($status eq 'new') {
1.10 raeburn 778: $msgcount ++;
779: if ($shortsubj eq '') {
780: $shortsubj = &mt('No subject');
781: }
782: $shortsubj = &Apache::lonnet::unescape($shortsubj);
1.1 raeburn 783: push(@{$newmsgs}, {
784: msgid => $msgid,
785: sendtime => $sendtime,
1.10 raeburn 786: shortsub => $shortsubj,
1.1 raeburn 787: from => $fromname,
788: fromdom => $fromdom
789: });
790: }
791: }
792: }
793: }
794:
795: # Check for critical messages in course
796: my %what=&Apache::lonnet::dump('critical');
797: my $result = '';
798: my $critmsgcount = 0;
1.3 albertel 799: foreach my $msgid (sort(keys(%what))) {
1.10 raeburn 800: my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
801: &Apache::lonmsg::unpackmsgid($msgid);
802: if (($fromcid) && ($fromcid eq $env{'request.course.id'})) {
1.1 raeburn 803: if (defined($sendtime) && $sendtime!~/error/) {
804: my $numsendtime = $sendtime;
805: $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
806: $critmsgcount ++;
1.10 raeburn 807: if ($shortsubj eq '') {
808: $shortsubj = &mt('No subject');
809: }
810: $shortsubj = &Apache::lonnet::unescape($shortsubj);
1.1 raeburn 811: push(@{$critmsgs}, {
812: msgid => $msgid,
813: sendtime => $sendtime,
1.10 raeburn 814: shortsub => $shortsubj,
1.1 raeburn 815: from => $fromname,
816: fromdom => $fromdom
817: });
818: }
819: }
820: }
821: return ($msgcount,$critmsgcount);
822: }
823:
824: sub cmp_title {
1.16 raeburn 825: my ($a,$b,$res_title) = @_;
826: my ($atitle,$btitle) = (lc($$res_title{$a}),lc($$res_title{$b}));
1.1 raeburn 827: $atitle=~s/^\s*//;
828: $btitle=~s/^\s*//;
829: return $atitle cmp $btitle;
830: }
831:
1.7 raeburn 832: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>