Annotation of loncom/homework/bridgetask.pm, revision 1.177
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # definition of tags that give a structure to a document
3: #
1.177 ! albertel 4: # $Id: bridgetask.pm,v 1.176 2006/06/20 03:56:30 albertel Exp $
1.1 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: ###
29:
30:
31: package Apache::bridgetask;
32:
33: use strict;
34: use Apache::lonnet;
35: use Apache::File();
36: use Apache::lonmenu;
37: use Apache::lonlocal;
38: use Apache::lonxml;
1.37 albertel 39: use Apache::slotrequest();
1.1 albertel 40: use Time::HiRes qw( gettimeofday tv_interval );
1.158 www 41: use lib '/home/httpd/lib/perl/';
42: use LONCAPA;
43:
1.9 albertel 44:
1.1 albertel 45: BEGIN {
1.162 albertel 46: &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Question','QuestionText','Setup','Instance','InstanceText','Criteria','ClosingParagraph'));
1.1 albertel 47: }
48:
1.169 albertel 49: my %dimension;
1.9 albertel 50: sub initialize_bridgetask {
51: # id of current Dimension, 0 means that no dimension is current
52: # (inside <Task> only)
1.168 albertel 53: %Apache::bridgetask::dimension=();
1.9 albertel 54: # list of all Dimension ids seen
1.168 albertel 55: %Apache::bridgetask::top_dimensionlist=();
1.9 albertel 56: # list of all current Instance ids
1.168 albertel 57: %Apache::bridgetask::instance=();
1.9 albertel 58: # list of all Instance ids seen in this problem
59: @Apache::bridgetask::instancelist=();
1.15 albertel 60: # key of queud user data that we are currently grading
61: $Apache::bridgetask::queue_key='';
1.169 albertel 62: undef(%dimension);
1.9 albertel 63: }
64:
1.4 albertel 65: sub proctor_check_auth {
1.81 albertel 66: my ($slot_name,$slot,$type)=@_;
1.11 albertel 67: my $user=$env{'form.proctorname'};
68: my $domain=$env{'form.proctordomain'};
1.4 albertel 69:
70: my @allowed=split(",",$slot->{'proctor'});
71: foreach my $possible (@allowed) {
1.138 albertel 72: my ($puser,$pdom)=(split(':',$possible));
1.4 albertel 73: if ($puser eq $user && $pdom eq $domain) {
1.72 albertel 74: my $authenticated=0;
75: if ( $slot->{'secret'} =~ /\S/ &&
76: $env{'form.proctorpassword'} eq $slot->{'secret'} ) {
77: $authenticated=1;
78: } else {
79:
80: my $authhost=&Apache::lonnet::authenticate($puser,$env{'form.proctorpassword'},$pdom);
81: if ($authhost ne 'no_host') {
82: $authenticated=1;
83: }
84: }
1.150 albertel 85: if ($authenticated) {
1.176 albertel 86: &check_in($type,$user,$domain,$slot_name);
1.4 albertel 87: return 1;
88: }
89: }
90: }
91: return 0;
92: }
93:
1.174 albertel 94: sub check_in {
95: my ($type,$user,$domain,$slot_name) = @_;
96: my $useslots = &Apache::lonnet::EXT("resource.0.useslots");
97: if ( $useslots eq 'map_map') {
98: &check_in_sequence($user,$domain,$slot_name);
99: } else {
100: &create_new_version($type,$user,$domain,$slot_name);
101: }
102: return 1;
103: }
104:
105: sub check_in_sequence {
106: my ($user,$domain,$slot_name) = @_;
107: my $navmap = Apache::lonnavmaps::navmap->new();
108: my ($symb) = &Apache::lonxml::whichuser();
109: my ($map) = &Apache::lonnet::decode_symb($symb);
1.175 albertel 110: my @resources =
111: $navmap->retrieveResources($map, sub { $_[0]->is_problem() },0,0);
1.174 albertel 112: my %old_history = %Apache::lonhomework::history;
113: my %old_results = %Apache::lonhomework::results;
114:
115: foreach my $res (@resources) {
116: &Apache::lonxml::debug("doing ".$res->src);
117: &Apache::structuretags::initialize_storage($res->symb);
118: my $type = ($res->is_task()) ? 'Task' : 'problem';
119: &create_new_version($type,$user,$domain,$slot_name);
120: &Apache::structuretags::finalize_storage($res->symb);
121: }
122:
123: %Apache::lonhomework::history = %old_history;
124: %Apache::lonhomework::results = %old_results;
125: }
126:
1.150 albertel 127: sub create_new_version {
128: my ($type,$user,$domain,$slot_name) = @_;
1.174 albertel 129:
130: my $id = '0';
1.150 albertel 131: if ($type eq 'Task') {
132: # increment version
133: my $version=
134: $Apache::lonhomework::history{'resource.0.version'};
135: $version++;
1.152 albertel 136: &Apache::lonxml::debug("Making version $version");
1.150 albertel 137: #clean out all current results
138: foreach my $key (keys(%Apache::lonhomework::history)) {
139: if ($key=~/^resource\.0\./) {
140: $Apache::lonhomework::results{$key}='';
141: }
142: }
143:
144: #setup new version and who did it
1.174 albertel 145: $Apache::lonhomework::results{'resource.0.version'}=$version;
146: $id = "$version.0";
147: if (!defined($user) || defined($domain)) {
148: $user = $env{'user.name'};
149: $domain = $env{'user.domain'};
1.150 albertel 150: }
1.174 albertel 151:
1.150 albertel 152: } elsif ($type eq 'problem') {
153: &Apache::lonxml::debug("authed $slot_name");
1.174 albertel 154: }
155:
156: if (defined($user) && defined($domain)) {
157: $Apache::lonhomework::results{"resource.$id.checkedin"}=
158: $user.':'.$domain;
159: }
160: if (defined($slot_name)) {
161: $Apache::lonhomework::results{"resource.$id.checkedin.slot"}=
162: $slot_name;
1.150 albertel 163: }
164: }
165:
1.25 albertel 166: sub get_version {
1.29 albertel 167: my ($version,$previous);
1.25 albertel 168: if ($env{'form.previousversion'} &&
1.36 albertel 169: $env{'form.previousversion'} ne 'current' &&
1.89 albertel 170: defined($Apache::lonhomework::history{'resource.'.$env{'form.previousversion'}.'.0.status'})) {
1.29 albertel 171: $version=$env{'form.previousversion'};
172: $previous=1;
173: } else {
1.150 albertel 174: if (defined($Apache::lonhomework::results{'resource.0.version'})) {
175: $version=$Apache::lonhomework::results{'resource.0.version'};
176: } elsif (defined($Apache::lonhomework::history{'resource.0.version'})) {
177: $version=$Apache::lonhomework::history{'resource.0.version'};
178: }
1.29 albertel 179: $previous=0;
180: }
181: if (wantarray) {
182: return ($version,$previous);
1.25 albertel 183: }
1.29 albertel 184: return $version;
1.25 albertel 185: }
186:
1.8 albertel 187: sub add_previous_version_button {
1.25 albertel 188: my ($status)=@_;
1.8 albertel 189: my $result;
1.89 albertel 190: if ($Apache::lonhomework::history{'resource.0.version'} eq '') {
1.25 albertel 191: return '';
192: }
1.89 albertel 193: if ($Apache::lonhomework::history{'resource.0.version'} < 2 &&
1.29 albertel 194: $status ne 'NEEDS_CHECKIN') {
1.25 albertel 195: return '';
196: }
1.29 albertel 197: my $version=&get_version();
198: if ($env{'form.previousversion'} ne '' &&
199: $env{'form.previousversion'} eq $version) {
200: $result.="<h3>".&mt("Showing previous version [_1]",$version).
201: "</h3>\n";
202: }
203: my @to_show;
1.89 albertel 204: foreach my $test_version (1..$Apache::lonhomework::history{'resource.0.version'}) {
205: if (defined($Apache::lonhomework::history{'resource.'.$test_version.'.0.status'})) {
1.29 albertel 206: push(@to_show,$test_version);
207: }
208: }
209: my $list='<option>'.
210: join("</option>\n<option>",@to_show).
211: "</option>\n";
1.36 albertel 212: $list.='<option value="current">'.&mt('Current').'</option>';
1.115 albertel 213: $result.='<form name="getprevious" method="post" action="';
1.29 albertel 214: my $uri=$env{'request.uri'};
215: if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
216: $result.=$uri.'">'.
217: &mt(' Show a previously done version: [_1]','<select onchange="this.form.submit()" name="previousversion">
218: <option>'.&mt('Pick one').'</option>
219: '.$list.'
220: </select>')."</form>";
1.8 albertel 221: return $result;
222: }
223:
1.13 albertel 224: sub add_grading_button {
1.59 albertel 225: my (undef,$cid)=&Apache::lonxml::whichuser();
226: my $cnum=$env{'course.'.$cid.'.num'};
227: my $cdom=$env{'course.'.$cid.'.domain'};
1.144 albertel 228: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
229:
1.59 albertel 230: my $size=5;
231: if (scalar(keys(%sections)) < 3) {
232: $size=scalar(keys(%sections))+2;
233: }
1.122 albertel 234: my $sec_select = '<select multiple="multiple" name="chosensections" size="'.$size.'">'."\n";
1.59 albertel 235: $sec_select .= "<option value='all' selected='selected'>all</option>\n";
236: foreach my $sec (sort {lc($a) cmp lc($b)} (keys(%sections))) {
1.122 albertel 237: $sec_select .= "<option value=\"$sec\">$sec</option>\n";
1.59 albertel 238: }
239: $sec_select .= "<option value='none'>none</option></select>\n";
240:
1.29 albertel 241: my $result=' <input type="submit" name="gradeasubmission" value="'.
1.13 albertel 242: &mt("Get a submission to grade").'" />';
243: $result.='<input type="hidden" name="grade_target" value="webgrade" />';
1.40 albertel 244: if (&Apache::lonnet::allowed('mgq',$env{'request.course.id'})) {
1.34 albertel 245: my ($entries,$ready,$locks)=&get_queue_counts('gradingqueue');
1.106 albertel 246: $result.='<table><tr>';
247: $result.='<td rowspan="4">Specify a section: </td><td rowspan="4">'.$sec_select.'</td>';
248: $result.='<td>'.' <input type="submit" name="reviewagrading" value="'.
249: &mt("Select an entry from the grading queue:").'" /> ';
1.34 albertel 250:
1.107 albertel 251: $result.= &mt("[_1] entries, [_2] ready, [_3] being graded",$entries,$ready,$locks).' </td></tr>'."\n";
1.34 albertel 252:
253: ($entries,$ready,$locks)=&get_queue_counts('reviewqueue');
1.106 albertel 254: $result.='<tr><td>'.
255: ' <input type="submit" name="reviewasubmission" value="'.
256: &mt("Select an entry from the review queue:").'" /> ';
257: $result.=&mt("[_1] entries, [_2] ready, [_3] being graded",
258: $entries,$ready,$locks).'</td></tr>'."\n";
259: $result.='<tr><td> <input type="submit" name="regradeasubmission" value="'.
260: &mt("List of user's grade status").'" /> </td></tr></table>'."\n";
1.105 albertel 261: $result.='<p> <input type="submit" name="regradeaspecificsubmission" value="'.
1.106 albertel 262: &mt("Regrade specific user:").'" />'."\n";
1.105 albertel 263: $result.='<input type="text" size="12" name="gradinguser" />';
264: $result.=&Apache::loncommon::select_dom_form($env{'user.domain'},
265: 'gradingdomain');
266: $result.=' '.
267: &Apache::loncommon::selectstudent_link('gradesubmission',
268: 'gradinguser',
269: 'gradingdomain');
270: $result.=&Apache::loncommon::studentbrowser_javascript();
1.123 albertel 271: $result.= '</p>';
1.144 albertel 272: }
1.13 albertel 273: return $result;
274: }
275:
1.22 albertel 276: sub add_request_another_attempt_button {
1.38 albertel 277: my ($text)=@_;
278: if (!$text) { $text="Request another attempt"; }
1.25 albertel 279: my $result;
1.36 albertel 280: my $symb=&Apache::lonnet::symbread();
1.149 albertel 281: # not a slot access based resource
282: my $useslots = &Apache::lonnet::EXT("resource.0.useslots",$symb);
283: if ($useslots =~ /^\s*no\s*$/i) {
284: return '';
285: }
286:
1.37 albertel 287: my ($slot_name,$slot)=&Apache::slotrequest::check_for_reservation($symb);
1.38 albertel 288: my $action='get_reservation';
1.37 albertel 289: if ($slot_name) {
1.38 albertel 290: $text="Change reservation.";
291: $action='change_reservation';
1.37 albertel 292: my $description=&Apache::slotrequest::get_description($slot_name,
293: $slot);
294: $result.=(<<STUFF);
295: <p> Will be next available: $description </p>
296: STUFF
297: }
1.38 albertel 298:
299: if ($env{'request.enc'}) { $symb=&Apache::lonenc::encrypted($symb); }
1.158 www 300: $symb=&escape($symb);
1.115 albertel 301: $result.='<form method="post" action="/adm/slotrequest">'.
1.38 albertel 302: '<input type="hidden" name="symb" value="'.$symb.'" />'.
303: '<input type="hidden" name="command" value="'.$action.'" />'.
304: '<input type="submit" name="requestattempt" value="'.
305: &mt($text).'" />'.
306: '</form>';
1.25 albertel 307: return $result;
1.22 albertel 308: }
309:
1.30 albertel 310: sub preserve_grade_info {
311: my $result;
312: # if we are viewing someone else preserve that info
313: if (defined $env{'form.grade_symb'}) {
314: foreach my $field ('symb','courseid','domain','username') {
315: $result .= '<input type="hidden" name="grade_'.$field.
316: '" value="'.$env{"form.grade_$field"}.'" />'."\n";
317: }
318: }
319: return $result;
320: }
321:
1.53 albertel 322: sub style {
1.125 albertel 323: my ($target) = @_;
324: if ($target eq 'web'
325: || $target eq 'webgrade') {
326: return (<<STYLE);
1.126 albertel 327: <link rel="stylesheet" type="text/css" href="/res/adm/includes/task.css" />
1.53 albertel 328: STYLE
1.125 albertel 329: }
330: return;
1.53 albertel 331: }
332:
1.54 albertel 333: sub show_task {
334: my ($status,$previous)=@_;
335: if (!$previous && (
336: ( $status eq 'CLOSED' ) ||
337: ( $status eq 'BANNED') ||
338: ( $status eq 'UNAVAILABLE') ||
339: ( $status eq 'NOT_IN_A_SLOT') ||
340: ( $status eq 'NEEDS_CHECKIN') ||
341: ( $status eq 'WAITING_FOR_GRADE') ||
1.150 albertel 342: ( $status eq 'INVALID_ACCESS') ||
343: ( &get_version() eq ''))) {
1.54 albertel 344: return 0;
345: }
1.64 albertel 346: if ($env{'form.donescreen'}) { return 0; }
1.54 albertel 347: return 1;
348: }
349:
1.173 albertel 350: my @delay;
351: sub nest {
352: if (@delay) {
353: return $delay[-1];
354: } else {
355: return;
356: }
357: }
358:
359: sub nested_parse {
360: my ($str,$env,$args) = @_;
361: my @old_env = @Apache::scripttag::parser_env;
362: @Apache::scripttag::parser_env = @$env;
363: if (exists($args->{'set_dim_id'})) {
364: &enable_dimension_parsing($args->{'set_dim_id'});
365: }
366: push(@delay,(($args->{'delayed_dim_results'})? 1 : 0));
367: my $result = &Apache::scripttag::xmlparse($$str);
368: pop(@delay);
369: if (exists($args->{'set_dim_id'})) {
370: &disable_dimension_parsing();
371: }
372: @Apache::scripttag::parser_env = @old_env;
373: if ($args->{'delayed_dim_results'}) {
374: my $dim = &get_dim_id();
375: return $dimension{$dim}{'result'};
376: }
377: return $result;
378: }
379:
1.54 albertel 380: sub internal_location {
381: my ($id)=@_;
382: return '<!-- LONCAPA_INTERNAL_ADD_TASK_STATUS'.$id.' -->';
383: }
384:
1.60 albertel 385: sub submission_time_stamp {
386: my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser();
387: my $submissiontime;
1.89 albertel 388: my $version=$Apache::lonhomework::history{'resource.0.version'};
1.60 albertel 389: for (my $v=$Apache::lonhomework::history{'version'};$v>0;$v--) {
390: if (defined($Apache::lonhomework::history{$v.':resource.'.$version.'.0.bridgetask.portfiles'})) {
391: $submissiontime=$Apache::lonhomework::history{$v.':timestamp'};
392: }
393: }
394: my $result;
395: if ($submissiontime) {
1.89 albertel 396: my $slot_name=$Apache::lonhomework::history{'resource.'.$version.'.0.checkedin.slot'};
1.60 albertel 397: my %slot=&Apache::lonnet::get_slot($slot_name);
398: my $diff = $slot{'endtime'} - $submissiontime;
1.71 albertel 399: my ($color,$when)=('#FF6666','after');
400: if ($diff > 0) { ($color,$when)=('#336600','before'); }
1.60 albertel 401: my $info;
402: if ($diff%60) { $info=($diff%60).' seconds'; }
403: $diff=int($diff/60);
404: if ($diff%60) { $info=($diff%60).' minutes '.$info; }
405: $diff=int($diff/60);
406: if ($diff) { $info=$diff.' hours '.$info; }
407: $result='<p><font color="'.$color.'">'.
408: &mt('Student submitted [_1] [_2] the deadline.
409: (Submission was at [_3], end of period was [_4].)',
410: $info,$when,scalar(localtime($submissiontime)),
411: scalar(localtime($slot{'endtime'}))).
412: '</font></p>';
413: }
414: return $result;
415: }
416:
1.119 albertel 417: sub file_list {
418: my ($files,$uname,$udom) = @_;
419: if (!defined($uname) || !defined($udom)) {
420: (undef,undef,$udom,$uname) = &Apache::lonxml::whichuser();
421: }
1.70 albertel 422: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio/';
1.119 albertel 423:
1.120 albertel 424: my $file_list="<ul class=\"LC_GRADING_handininfo\">\n";
1.119 albertel 425: foreach my $partial_file (split(',',$files)) {
1.70 albertel 426: my $file=$file_url.$partial_file;
427: $file=~s|/+|/|g;
428: &Apache::lonnet::allowuploaded('/adm/bridgetask',$file);
1.161 albertel 429: $file_list.='<li><span style="white-space: nowrap;"><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.
430: &Apache::loncommon::icon($file).'" alt="file icon" border="0" /> '.$file.
431: '</a></span></li>'."\n";
1.70 albertel 432: }
433: $file_list.="</ul>\n";
1.119 albertel 434: return $file_list;
435: }
436:
1.163 albertel 437: sub grade_mode {
438: if ($env{'form.regrade'} || $env{'form.regradeaspecificsubmission'}) {
439: return 'regrade';
440: }
441: return 'queue_grade';
442: }
443:
1.119 albertel 444: sub webgrade_standard_info {
445: my ($version)=&get_version();
446:
447: my $file_list = &file_list($Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"});
1.70 albertel 448:
1.163 albertel 449: my %lt=('done' => 'Next Item',
450: 'stop' => 'Quit Grading',
451: 'fail' => 'Fail Rest',
452: 'cancel' => 'Cancel',
453: );
1.170 albertel 454: %lt=&Apache::lonlocal::texthash(%lt);
1.163 albertel 455:
1.70 albertel 456: my $result=<<INFO;
1.120 albertel 457: <div class="LC_GRADING_maincontrols">
1.163 albertel 458: INFO
459:
460: if (&grade_mode() eq 'regrade') {
461: $result.=<<INFO;
462: <input type="submit" name="cancel" value="$lt{'cancel'}" />
463: INFO
464: }
465:
466: $result.=<<INFO;
1.111 albertel 467: <input type="submit" name="next" value="$lt{'done'}" />
468: <input type="submit" name="stop" value="$lt{'stop'}" />
1.143 albertel 469: <input type="button" name="fail" value="$lt{'fail'}"
470: onclick="javascript:onFailRest()" />
1.111 albertel 471: </div>
1.70 albertel 472: $file_list
473: INFO
474: return $result;
475: }
476:
1.166 albertel 477: sub done_screen {
478: my ($version) = @_;
479: my $title=&Apache::lonnet::gettitle();
480: my @files=split(',',$Apache::lonhomework::history{'resource.'.$version.'.0.bridgetask.portfiles'});
481: my (undef,undef,$domain,$user)= &Apache::lonxml::whichuser();
482: my $files = '<ul>';
1.167 albertel 483: my $msg;
1.166 albertel 484: foreach my $file (@files) {
485: my $url="/uploaded/$domain/$user/portfolio$file";
486: if (! &Apache::lonnet::stat_file($url)) {
487: $file = &mt('<span class="LC_error"> Nonexistent file:</span> '.
488: '<span class="LC_filename">[_1]</span>',$file);
1.167 albertel 489: $msg .= "<p>Submitted non-existant file $file</p>\n";
1.166 albertel 490: } else {
491: $file = '<span class="LC_filename">'.$file.'</span>';
1.167 albertel 492: $msg .= "<p>Submitted file $file</p>\n";
1.166 albertel 493: }
494: $files .= '<li>'.$file.'</li>';
495: }
496: $files.='</ul>';
1.167 albertel 497: my $subject = "Submission message for $title";
498: my ($message_status,$comment_status);
499: my $setting = $env{'course.'.$env{'request.course.id'}.'.task_messages'};
500: $setting =~ s/^\s*(\S*)\s*$/$1/;
501: $setting = lc($setting);
502: if ($setting eq 'only_student'
503: || $setting eq 'student_and_user_notes_screen') {
504: $message_status =
505: &Apache::lonmsg::user_normal_msg($user,$domain,$subject,$msg);
506: $message_status = '<p>'.&mt('Message sent to user: [_1]',
507: $message_status).' </p>';
508: }
509: if ($setting eq 'student_and_user_notes_screen') {
510: $comment_status =
511: &Apache::lonmsg::store_instructor_comment($subject.'<br />'.
512: $msg,$user,$domain);
513: $comment_status = '<p>'.&mt('Message sent to instructor: [_1]',
514: $comment_status).' </p>';
515: }
1.166 albertel 516: return <<DONESCREEN;
517: <h2>$title</h2>
518: <p> Files submitted: $files </p>
519: <p> You are now done with this Bridge Task </p>
520: <hr />
521: <p> <a href="/adm/logout">Logout</a> </p>
522: <p> <a href="/adm/roles">Change to a different course</a> </p>
1.167 albertel 523: $message_status
524: $comment_status
1.166 albertel 525: DONESCREEN
526:
527: }
528:
1.1 albertel 529: sub start_Task {
1.87 albertel 530: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.1 albertel 531:
1.4 albertel 532: my ($status,$accessmsg,$slot);
1.16 albertel 533: if ($target ne 'webgrade') {
1.70 albertel 534: &Apache::structuretags::init_problem_globals('Task');
1.16 albertel 535: &Apache::structuretags::initialize_storage();
536: &Apache::lonhomework::showhash(%Apache::lonhomework::history);
1.74 albertel 537: if ($env{'request.state'} eq 'construct') {
538: &Apache::structuretags::setup_rndseed($safeeval);
539: }
1.16 albertel 540: }
541:
1.4 albertel 542: $Apache::lonhomework::parsing_a_task=1;
1.141 albertel 543:
544: my $name;
545: if ($target eq 'web' || $target eq 'webgrade') {
546: $name = &Apache::structuretags::get_resource_name($parstack,$safeeval);
547: }
548:
1.145 albertel 549: my ($result,$form_tag_start);
550: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'tex'
551: || $target eq 'edit') {
552: ($result,$form_tag_start) =
553: &Apache::structuretags::page_start($target,$token,$tagstack,
554: $parstack,$parser,$safeeval,
1.146 albertel 555: $name,&style($target));
1.145 albertel 556: $result .= '<div class="LC_task">'."\n";
557: }
1.123 albertel 558:
1.74 albertel 559: if ($target eq 'web' && $env{'request.state'} ne 'construct') {
1.147 albertel 560: if ($Apache::lonhomework::queuegrade
561: || $Apache::lonhomework::modifygrades) {
1.141 albertel 562: $result.='<form name="gradesubmission" method="post" action="';
1.13 albertel 563: my $uri=$env{'request.uri'};
564: if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
1.141 albertel 565: $result.=$uri.'">'.&add_grading_button()."</form>";
1.38 albertel 566: my $symb=&Apache::lonnet::symbread();
1.40 albertel 567: if (&Apache::lonnet::allowed('mgq',$env{'request.course.id'})) {
1.141 albertel 568: $result.='<form method="post" name="slotrequest" action="/adm/slotrequest">'.
1.40 albertel 569: '<input type="hidden" name="symb" value="'.$symb.'" />'.
570: '<input type="hidden" name="command" value="showslots" />'.
571: '<input type="submit" name="requestattempt" value="'.
572: &mt('Show Slot list').'" />'.
573: '</form>';
1.108 albertel 574: my $target_id =
575: &Apache::lonstathelpers::make_target_id({symb => $symb,
576: part => '0'});
1.141 albertel 577: $result.='<form method="post" name="gradingstatus" action="/adm/statistics">'.
1.108 albertel 578: '<input type="hidden" name="problemchoice" value="'.$target_id.'" />'.
579: '<input type="hidden" name="reportSelected" value="grading_analysis" />'.
580: '<input type="submit" name="grading" value="'.
581: &mt('Show Grading Status').'" />'.
582: '</form>';
1.40 albertel 583: }
1.13 albertel 584: }
1.8 albertel 585: }
1.74 albertel 586: if ($target eq 'web' && $env{'request.state'} eq 'construct') {
587: $form_tag_start.=&Apache::structuretags::problem_web_to_edit_header($env{'form.rndseed'});
588: }
1.163 albertel 589: if ($target eq 'web'
590: || ($target eq 'grade' && !$env{'form.webgrade'})
591: || $target eq 'answer'
592: || $target eq 'tex') {
1.29 albertel 593: my ($version,$previous)=&get_version();
1.14 albertel 594: ($status,$accessmsg,my $slot_name,$slot) =
1.81 albertel 595: &Apache::lonhomework::check_slot_access('0','Task');
1.152 albertel 596: if ($status eq 'CAN_ANSWER' && $version eq '') {
1.177 ! albertel 597: # CAN_ANSWER mode, and no current version, unproctored access
1.174 albertel 598: # thus self-checkedin
1.177 ! albertel 599: &check_in('Task',undef,undef,$slot_name);
1.152 albertel 600: &add_to_queue('gradingqueue',{'type' => 'Task',
601: 'time' => time,
602: 'slot' => $slot_name});
1.150 albertel 603: ($version,$previous)=&get_version();
604: }
605:
1.9 albertel 606: push(@Apache::inputtags::status,$status);
1.14 albertel 607: $Apache::inputtags::slot_name=$slot_name;
1.1 albertel 608: my $expression='$external::datestatus="'.$status.'";';
1.89 albertel 609: $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$version.0.solved"}.'";';
1.1 albertel 610: &Apache::run::run($expression,$safeeval);
611: &Apache::lonxml::debug("Got $status");
1.141 albertel 612: $result.=&add_previous_version_button($status);
1.54 albertel 613: if (!&show_task($status,$previous)) {
1.87 albertel 614: my $bodytext=&Apache::lonxml::get_all_text("/task",$parser,$style);
1.1 albertel 615: if ( $target eq "web" ) {
1.74 albertel 616: if ($env{'request.state'} eq 'construct') {
617: $result.=$form_tag_start;
618: }
1.4 albertel 619: my $msg;
1.1 albertel 620: if ($status eq 'UNAVAILABLE') {
621: $msg.='<h1>'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'</h1>';
1.3 albertel 622: } elsif ($status eq 'NOT_IN_A_SLOT') {
623: $msg.='<h1>'.&mt('You are not currently signed up to work at this time and/or place.').'</h1>';
1.38 albertel 624: $msg.=&add_request_another_attempt_button("Sign up for time to work.");
1.4 albertel 625: } elsif ($status eq 'NEEDS_CHECKIN') {
626: $msg.='<h1>'.&mt('You need the Proctor to validate you.').
627: '</h1>'.&proctor_validation_screen($slot);
1.22 albertel 628: } elsif ($status eq 'WAITING_FOR_GRADE') {
629: $msg.='<h1>'.&mt('Your submission is in the grading queue.').'</h1>';
1.64 albertel 630: } elsif ($env{'form.donescreen'}) {
1.167 albertel 631: $result .= &done_screen($version);
1.1 albertel 632: } elsif ($status ne 'NOT_YET_VIEWED') {
633: $msg.='<h1>'.&mt('Not open to be viewed').'</h1>';
634: }
635: if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') {
636: $msg.='The problem '.$accessmsg;
637: }
638: $result.=$msg.'<br />';
639: } elsif ($target eq 'tex') {
640: $result.='\begin{document}\noindent \vskip 1 mm \begin{minipage}{\textwidth}\vskip 0 mm';
641: if ($status eq 'UNAVAILABLE') {
642: $result.=&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'\vskip 0 mm ';
643: } else {
644: $result.=&mt('Problem is not open to be viewed. It')." $accessmsg \\vskip 0 mm ";
645: }
1.22 albertel 646: } elsif ($target eq 'grade' && !$env{'form.webgrade'}) {
1.4 albertel 647: if ($status eq 'NEEDS_CHECKIN') {
1.83 albertel 648: if(&proctor_check_auth($slot_name,$slot,'Task')
649: && defined($Apache::inputtags::slot_name)) {
1.148 albertel 650: my $result=
651: &add_to_queue('gradingqueue',
1.152 albertel 652: {'type' => 'Task',
1.148 albertel 653: 'time' => time,
654: 'slot' =>
655: $Apache::inputtags::slot_name});
1.77 albertel 656: &Apache::lonxml::debug("add_to_queue said $result");
657: }
1.4 albertel 658: }
1.1 albertel 659: }
660: } elsif ($target eq 'web') {
1.141 albertel 661:
1.57 albertel 662: $result.=&preserve_grade_info();
663: $result.=&internal_location();
1.36 albertel 664: $result.=$form_tag_start.
665: '<input type="hidden" name="submitted" value="yes" />';
1.54 albertel 666: &Apache::lonxml::startredirection();
1.1 albertel 667: }
1.21 albertel 668: } elsif ( ($target eq 'grade' && $env{'form.webgrade'}) ||
669: $target eq 'webgrade') {
1.32 albertel 670: my $webgrade='yes';
1.21 albertel 671: if ($target eq 'webgrade') {
1.141 albertel 672: $result.= "\n".'<div class="LC_GRADING_task">'."\n".
1.124 albertel 673: '<script type="text/javascript"
1.126 albertel 674: src="/res/adm/includes/task_grading.js"></script>';
1.49 albertel 675: #$result.='<br />Review'.&show_queue('reviewqueue');
676: #$result.='<br />Grade'.&show_queue('gradingqueue');
1.30 albertel 677: }
1.33 albertel 678: # FIXME Blast! still need to reorg this, need to reshow the
679: # queue being reviewed once done with the grade pass...
680: # Hrrm, vaildation pass should perhaps say 'not_locked'
681: # perhaps do a search if there is a key that is mine and if
682: # there isn't reshow the queue....
1.105 albertel 683: my ($todo,$status_code,$msg)=&get_key_todo($target);
1.33 albertel 684:
685: if ($todo) {
686: &setup_env_for_other_user($todo,$safeeval);
687: my ($symb,$uname,$udom)=&decode_queue_key($todo);
688: $result.="\n".'<table><tr><td>Found '.
689: &Apache::lonnet::gettitle($symb).' for '.$uname.' at '.$udom.'</td></tr></table>';
690: $form_tag_start.=
691: '<input type="hidden" name="gradingkey" value="'.
1.158 www 692: &escape($todo).'" />';
1.33 albertel 693: $Apache::bridgetask::queue_key=$todo;
694: &Apache::structuretags::initialize_storage();
695: &Apache::lonhomework::showhash(%Apache::lonhomework::history);
1.110 albertel 696: if ($target eq 'webgrade' && $status_code eq 'selected') {
697: $form_tag_start.=
698: '<input type="hidden" name="queuemode" value="selected" />';
1.33 albertel 699: }
1.15 albertel 700: } else {
1.33 albertel 701: if ($target eq 'webgrade') {
702: $result.="\n";
1.81 albertel 703: my $back='<p><a href="/adm/flip?postdata=return:">'.
704: &mt('Return to resource').'</a></p>';
1.33 albertel 705: if ($status_code eq 'stop') {
1.81 albertel 706: $result.='<b>'.&mt("Stopped grading.").'</b>'.$back;
1.163 albertel 707: } elsif ($status_code eq 'cancel') {
708: $result.='<b>'.&mt("Cancelled grading.").'</b>'.$back;
1.164 albertel 709: } elsif ($status_code eq 'never_versioned') {
710: $result.='<b>'.
711: &mt("Requested user has never accessed the task.").
712: '</b>'.$back;
1.165 albertel 713: } elsif ($status_code =~ /still_open:(.*)/) {
714: my $date = &Apache::lonlocal::locallocaltime($1);
715: $result.='<b>'.
716: &mt("Task is still open, will close at [_1].",$date).
717: '</b>'.$back;
1.33 albertel 718: } elsif ($status_code eq 'lock_failed') {
1.105 albertel 719: $result.='<b>'.&mt("Failed to lock the requested record.")
1.81 albertel 720: .'</b>'.$back;
1.33 albertel 721: } elsif ($status_code eq 'unlock') {
1.81 albertel 722: $result.='<b>'.&mt("Unlocked the requested record.")
723: .'</b>'.$back;
1.33 albertel 724: $result.=&show_queue($env{'form.queue'},1);
725: } elsif ($status_code eq 'show_list') {
726: $result.=&show_queue($env{'form.queue'},1);
1.49 albertel 727: } elsif ($status_code eq 'select_user') {
728: $result.=&select_user();
1.95 albertel 729: } elsif ($status_code eq 'unable') {
730: $result.='<b>'.&mt("Unable to aqcuire a user to grade.").'</b>'.$back;
1.105 albertel 731: } elsif ($status_code eq 'not_allowed') {
732: $result.='<b>'.&mt('Not allowed to grade the requested user.').' '.$msg.'</b>'.$back;
1.33 albertel 733: } else {
1.81 albertel 734: $result.='<b>'.&mt("No user to be graded.").'</b>'.$back;
1.32 albertel 735: }
1.21 albertel 736: }
1.33 albertel 737: $webgrade='no';
1.163 albertel 738: }
739: if (!$todo || $env{'form.cancel'}) {
1.87 albertel 740: my $bodytext=&Apache::lonxml::get_all_text("/task",$parser,$style);
1.32 albertel 741: }
742: if ($target eq 'webgrade' && defined($env{'form.queue'})) {
1.61 albertel 743: if ($webgrade eq 'yes') {
744: $result.=&submission_time_stamp();
745: }
1.32 albertel 746: $result.=$form_tag_start;
747: $result.='<input type="hidden" name="webgrade" value="'.
748: $webgrade.'" />';
749: $result.='<input type="hidden" name="queue" value="'.
750: $env{'form.queue'}.'" />';
1.52 albertel 751: if ($env{'form.regrade'}) {
752: $result.='<input type="hidden" name="regrade" value="'.
753: $env{'form.regrade'}.'" />';
754: }
1.62 albertel 755: if ($env{'form.chosensections'}) {
756: my @chosen_sections=
757: &Apache::loncommon::get_env_multiple('form.chosensections');
758: foreach my $sec (@chosen_sections) {
759: $result.='<input type="hidden" name="chosensections"
760: value="'.$sec.'" />';
761: }
762: }
1.70 albertel 763: if ($webgrade eq 'yes') { $result.=&webgrade_standard_info(); }
1.15 albertel 764: }
1.110 albertel 765: if ($target eq 'webgrade') {
1.120 albertel 766: $result.="\n".'<div id="LC_GRADING_criterialist">';
1.110 albertel 767: }
1.74 albertel 768: } elsif ($target eq 'edit') {
1.141 albertel 769: $result.=$form_tag_start.
1.74 albertel 770: &Apache::structuretags::problem_edit_header();
771: $Apache::lonxml::warnings_error_header=
772: &mt("Editor Errors - these errors might not effect the running of the problem, but they will likely cause problems with further use of the Edit mode. Please use the EditXML mode to fix these errors.")."<br />";
773: my $temp=&Apache::edit::insertlist($target,$token);
774: $result.=$temp;
1.1 albertel 775: } else {
776: # page_start returned a starting result, delete it if we don't need it
777: $result = '';
778: }
779: return $result;
780: }
781:
1.165 albertel 782: sub get_task_end_time {
783: my ($queue_entry,$symb,$udom,$uname) = @_;
784:
785: my $end_time;
786: if (my $slot = &slotted_access($queue_entry)) {
787: my %slot_data=&Apache::lonnet::get_slot($slot);
788: $end_time = $slot_data{'endtime'};
789: } else {
790: $end_time = &Apache::lonhomework::due_date('0',$symb,
791: $udom,$uname);
792: }
793: return $end_time;
794: }
795:
1.32 albertel 796: sub get_key_todo {
797: my ($target)=@_;
798: my $todo;
1.33 albertel 799:
800: if (defined($env{'form.reviewasubmission'})) {
1.54 albertel 801: &Apache::lonxml::debug("review a submission....");
1.33 albertel 802: $env{'form.queue'}='reviewqueue';
803: return (undef,'show_list');
804: }
805:
806: if (defined($env{'form.reviewagrading'})) {
807: &Apache::lonxml::debug("review a grading....");
808: $env{'form.queue'}='gradingqueue';
809: return (undef,'show_list');
810: }
811:
1.49 albertel 812: if (defined($env{'form.regradeasubmission'})) {
813: &Apache::lonxml::debug("regrade a grading....");
814: $env{'form.queue'}='none';
815: return (undef,'select_user');
816: }
817:
1.105 albertel 818:
1.138 albertel 819: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.105 albertel 820:
821: #need to try both queues..
822: if (defined($env{'form.regradeaspecificsubmission'}) &&
823: defined($env{'form.gradinguser'}) &&
824: defined($env{'form.gradingdomain'}) ) {
825: my ($symb,$cid)=&Apache::lonxml::whichuser();
826: my $cnum = $env{'course.'.$cid.'.num'};
827: my $cdom = $env{'course.'.$cid.'.domain'};
828: my $uname = $env{'form.gradinguser'};
829: my $udom = $env{'form.gradingdomain'};
830:
831: my $gradingkey=&encode_queue_key($symb,$udom,$uname);
832:
833: my $queue;
834:
835: if (&in_queue('gradingqueue',$symb,$cdom,$cnum,$udom,$uname)) {
836: $env{'form.queue'} = $queue = 'gradingqueue';
837: } elsif (&in_queue('reviewqueue' ,$symb,$cdom,$cnum,$udom,$uname)) {
838: $env{'form.queue'} = $queue = 'reviewqueue';
839: }
840:
841: if (!$queue) {
842: $env{'form.queue'} = $queue = 'none';
843: #not queued so doing either a re or pre grade
1.164 albertel 844: my %status = &Apache::lonnet::restore($symb,$cid,$udom,$uname);
845: if ($status{'resource.0.version'} < 1) {
846: return (undef,'never_versioned');
847: }
1.105 albertel 848: return ($gradingkey);
849: }
850:
1.165 albertel 851: if ($queue) {
852: my $queue_entry = &get_queue_data($queue,$udom,$uname);
853:
854: my $end_time = &get_task_end_time($queue_entry,$symb,
855: $udom,$uname);
856: if ($end_time > time) {
857: return (undef,"still_open:$end_time");
858: }
859: }
860:
1.105 albertel 861: my $who=&queue_key_locked($queue,$gradingkey);
862: if ($who eq $me) {
863: #already have the lock
1.158 www 864: $env{'form.gradingkey'}=&escape($gradingkey);
1.163 albertel 865: &Apache::lonxml::debug("already locked");
1.105 albertel 866: return ($gradingkey);
867: }
868:
869: if (!defined($who)) {
870: if (&lock_key($queue,$gradingkey)) {
1.163 albertel 871: &Apache::lonxml::debug("newly locked");
1.105 albertel 872: return ($gradingkey);
873: } else {
874: return (undef,'lock_failed');
875: }
876: }
877:
878: #otherwise (defined($who) && $who ne $me) some else has it...
879: return (undef,'not_allowed',
880: &mt('Another user ([_1]) currently has the record for [_2] locked.',
1.138 albertel 881: $who,$env{'form.gradinguser'}.':'.$env{'form.gradingdomain'}));
1.105 albertel 882: }
883:
884:
1.32 albertel 885: my $queue=$env{'form.queue'};
1.33 albertel 886:
1.32 albertel 887: if (!defined($queue)) {
888: $env{'form.queue'}=$queue='gradingqueue';
889: }
1.33 albertel 890:
1.158 www 891: my $gradingkey=&unescape($env{'form.gradingkey'});
1.33 albertel 892:
1.49 albertel 893: if ($env{'form.queue'} eq 'none') {
894: if (defined($env{'form.gradingkey'})) {
895: if ($target eq 'webgrade') {
896: if ($env{'form.stop'}) {
897: return (undef,'stop');
1.163 albertel 898: } elsif ($env{'form.cancel'}) {
899: return (undef,'cancel');
1.49 albertel 900: } elsif ($env{'form.next'}) {
1.59 albertel 901: return (undef,'select_user');
1.49 albertel 902: }
903: }
904: return ($gradingkey,'selected');
905: } else {
1.59 albertel 906: return (undef,'select_user');
1.49 albertel 907: }
908: }
1.32 albertel 909: if (defined($env{'form.queue'}) && defined($env{'form.gradingkey'})
1.33 albertel 910: && !defined($env{'form.gradingaction'})
911: && $env{'form.queuemode'} eq 'selected') {
912:
913: my $who=&queue_key_locked($queue,$gradingkey);
914: if ($who eq $me) {
915: &Apache::lonxml::debug("Found a key was given to me");
916: return ($gradingkey,'selected');
917: } else {
918: return (undef,'show_list');
919: }
920:
921: }
922:
923: if ($target eq 'webgrade' && $env{'form.queuemode'} eq 'selected') {
924: if ($env{'form.gradingaction'} eq 'resume') {
925: delete($env{'form.gradingaction'});
926: &Apache::lonxml::debug("Resuming a key");
1.32 albertel 927: return ($gradingkey);
1.33 albertel 928: } elsif ($env{'form.gradingaction'} eq 'unlock') {
929: &Apache::lonxml::debug("Unlocking a key ".
930: &check_queue_unlock($queue,$gradingkey,1));
931: return (undef,'unlock');
932: } elsif ($env{'form.gradingaction'} eq 'select') {
933: &Apache::lonxml::debug("Locking a key");
934: if (&lock_key($queue,$gradingkey)) {
935: &Apache::lonxml::debug("Success $queue");
936: return ($gradingkey);
937: }
938: &Apache::lonxml::debug("Failed $queue");
939: return (undef,'lock_failed');
1.32 albertel 940: }
941: }
1.33 albertel 942:
943: if ($env{'form.queuemode'} ne 'selected') {
944: # don't get something new from the queue if they hit the stop button
1.163 albertel 945: if (!(($env{'form.cancel'} || $env{'form.stop'})
946: && $target eq 'webgrade')
1.33 albertel 947: && !$env{'form.gradingaction'}) {
948: &Apache::lonxml::debug("Getting anew $queue");
949: return (&get_from_queue($queue));
950: } else {
951: return (undef,'stop');
952: }
1.32 albertel 953: }
1.33 albertel 954: return (undef,undef)
1.32 albertel 955: }
1.94 albertel 956:
957: sub minimize_storage {
958: foreach my $key (keys(%Apache::lonhomework::results)) {
959: if ($key =~ /regrader$/) { next; }
960: if ($Apache::lonhomework::results{$key} eq
961: $Apache::lonhomework::history{$key}) {
962: delete($Apache::lonhomework::results{$key});
963: }
964: }
965: }
966:
1.1 albertel 967: sub end_Task {
968: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
969: my $result='';
970: my $status=$Apache::inputtags::status['-1'];
1.29 albertel 971: my ($version,$previous)=&get_version();
1.1 albertel 972: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
1.15 albertel 973: $target eq 'tex') {
1.69 albertel 974: if ($target eq 'web' || $target eq 'answer' || $target eq 'tex') {
1.1 albertel 975: if ($target eq 'web') {
1.54 albertel 976: if (&show_task($status,$previous)) {
977: $result.=&Apache::lonxml::endredirection();
978: }
1.64 albertel 979: if ($status eq 'CAN_ANSWER' && !$previous &&
980: !$env{'form.donescreen'}) {
1.15 albertel 981: $result.="\n".'<table border="1">'.
1.28 albertel 982: &Apache::inputtags::file_selector("$version.0",
983: "bridgetask","*",
1.46 albertel 984: 'portfolioonly',
985: '
986: <h2>'.&mt('Submit Portfolio Files for Grading').'</h2>
987: <p>'.&mt('Indicate the files from your portfolio to be evaluated in grading this task.').'</p>').
1.9 albertel 988: "</table>";
1.77 albertel 989: }
1.78 albertel 990: if (!$previous && $status ne 'SHOW_ANSWER' &&
991: &show_task($status,$previous)) {
1.9 albertel 992: $result.=&Apache::inputtags::gradestatus('0');
1.64 albertel 993: $result.='</form>';
1.116 albertel 994: my $action = &Apache::lonenc::check_encrypt($env{'request.uri'});
1.64 albertel 995: $result.=<<DONEBUTTON;
1.115 albertel 996: <form name="done" method="post" action="$action">
1.64 albertel 997: <input type="hidden" name="donescreen" value="1" />
998: <input type="submit" value="Done" />
999: </form>
1000: DONEBUTTON
1.77 albertel 1001: }
1.56 albertel 1002: if (&show_task($status,$previous) &&
1.89 albertel 1003: $Apache::lonhomework::history{"resource.$version.0.status"} =~ /^(pass|fail)$/) {
1004: my $bt_status=$Apache::lonhomework::history{"resource.$version.0.status"};
1.54 albertel 1005: my $title=&Apache::lonnet::gettitle();
1.80 albertel 1006:
1.149 albertel 1007: my $start_time;
1008:
1.80 albertel 1009: my $slot_name=
1.89 albertel 1010: $Apache::lonhomework::history{"resource.$version.0.checkedin.slot"};
1.149 albertel 1011: if ($slot_name) {
1012: my %slot=&Apache::lonnet::get_slot($slot_name);
1013:
1014: $start_time=$slot{'starttime'}
1015: } else {
1016: $start_time=
1017: &Apache::lonnet::EXT('resource.0.opendate');
1018: }
1019: $start_time=&Apache::lonlocal::locallocaltime($start_time);
1.54 albertel 1020:
1.116 albertel 1021: my $status = "\n<div class='LC_$bt_status LC_criteria'>\n";
1.54 albertel 1022:
1023: if ($bt_status eq 'pass') {
1024: $status.='<h2>You passed the '.$title.' given on '.
1.80 albertel 1025: $start_time.'</h2>';
1.54 albertel 1026: }
1027: if ($bt_status eq 'fail') {
1028: $status.='<h2>You did not pass the '.$title.' given on '.
1.80 albertel 1029: $start_time.'</h2>';
1.54 albertel 1030: if (!$previous) {
1031: $status.=&add_request_another_attempt_button();
1032: }
1033: }
1034: my $man_count=0;
1035: my $opt_count=0;
1036: my $opt_passed=0;
1.168 albertel 1037: foreach my $dim (keys(%Apache::bridgetask::top_dimensionlist)) {
1038: if ($Apache::bridgetask::top_dimensionlist{$dim}{'manadatory'}
1.54 albertel 1039: eq 'N') {
1040: $opt_count++;
1.168 albertel 1041: if ($Apache::lonhomework::history{"resource.$version.0.$dim.status"} eq 'pass') {
1.54 albertel 1042: $opt_passed++;
1043: }
1044: } else {
1045: $man_count++;
1046: }
1047: }
1.151 albertel 1048:
1.54 albertel 1049: my $opt_req=&Apache::lonxml::get_param('OptionalRequired',
1050: $parstack,$safeeval);
1051: if ($opt_req !~ /\S/) { $opt_req='0'; }
1.99 albertel 1052: $status.="\n<p>".&mt('You needed to pass all of the [_1] mandatory components and [_2] of the [_3] optional components, of which you passed [_4].',$man_count,$opt_req,$opt_count,$opt_passed)."</p></div>\n";
1.54 albertel 1053:
1054: my $internal_location=&internal_location();
1055: $result=~s/\Q$internal_location\E/$status/;
1056: }
1.142 albertel 1057: $result.="\n</div>\n".
1058: &Apache::loncommon::end_page({'discussion' => 1});
1.1 albertel 1059: }
1060: }
1.29 albertel 1061: if ($target eq 'grade' && !$env{'form.webgrade'} && !$previous) {
1.12 albertel 1062: my $award='SUBMITTED';
1.28 albertel 1063: &Apache::essayresponse::file_submission("$version.0",'bridgetask',
1.20 albertel 1064: 'portfiles',\$award);
1.14 albertel 1065: if ($award eq 'SUBMITTED' &&
1.28 albertel 1066: $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}) {
1067: $Apache::lonhomework::results{"resource.0.tries"}=
1068: $Apache::lonhomework::results{"resource.$version.0.tries"}=
1069: 1+$Apache::lonhomework::history{"resource.$version.0.tries"};
1070:
1071: $Apache::lonhomework::results{"resource.0.award"}=
1072: $Apache::lonhomework::results{"resource.$version.0.award"}=
1073: $award;
1.51 albertel 1074: $Apache::lonhomework::results{"resource.0.submission"}=
1075: $Apache::lonhomework::results{"resource.$version.0.submission"}='';
1.64 albertel 1076: } else {
1077: delete($Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"});
1.77 albertel 1078: $award = '';
1.10 albertel 1079: }
1.4 albertel 1080: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
1081: &Apache::structuretags::finalize_storage();
1.148 albertel 1082: if ($award eq 'SUBMITTED') {
1083: my $useslots = &Apache::lonnet::EXT("resource.0.useslots");
1084: if ($useslots =~ /^\s*no\s*$/i) {
1085: &add_to_queue('gradingqueue',
1.152 albertel 1086: {'type' => 'Task',
1.148 albertel 1087: 'time' => time});
1088: } elsif (defined($Apache::inputtags::slot_name)) {
1089: &add_to_queue('gradingqueue',
1.152 albertel 1090: {'type' => 'Task',
1.148 albertel 1091: 'time' => time,
1092: 'slot' => $Apache::inputtags::slot_name});
1093: }
1.14 albertel 1094: }
1.79 albertel 1095: } elsif ($Apache::lonhomework::results{'INTERNAL_store'}) {
1096: &Apache::structuretags::finalize_storage();
1.1 albertel 1097: }
1.163 albertel 1098: if ($target eq 'grade' && $env{'form.webgrade'} eq 'yes'
1099: && exists($env{'form.cancel'})) {
1100: &check_queue_unlock($env{'form.queue'});
1101: &Apache::lonxml::debug(" cancelled grading .".$env{'form.queue'});
1102: } elsif ($target eq 'grade' && $env{'form.webgrade'} eq 'yes'
1103: && !exists($env{'form.cancel'})) {
1.20 albertel 1104: my $optional_required=
1105: &Apache::lonxml::get_param('OptionalRequired',$parstack,
1106: $safeeval);
1107: my $optional_passed=0;
1108: my $mandatory_failed=0;
1109: my $ungraded=0;
1110: my $review=0;
1.21 albertel 1111: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
1.168 albertel 1112: foreach my $dim (keys(%Apache::bridgetask::top_dimensionlist)) {
1.20 albertel 1113: my $status=
1.168 albertel 1114: $Apache::lonhomework::results{"resource.$version.0.$dim.status"};
1.20 albertel 1115: my $mandatory=
1.168 albertel 1116: ($Apache::bridgetask::top_dimensionlist{$dim}{'manadatory'} ne 'N');
1.20 albertel 1117: if ($status eq 'pass') {
1118: if (!$mandatory) { $optional_passed++; }
1119: } elsif ($status eq 'fail') {
1120: if ($mandatory) { $mandatory_failed++; }
1121: } elsif ($status eq 'ungraded') {
1122: $ungraded++;
1123: } elsif ($status eq 'review') {
1124: $review++;
1.49 albertel 1125: } else {
1126: $ungraded++;
1127: }
1.20 albertel 1128: }
1129: if ($optional_passed < $optional_required) {
1130: $mandatory_failed++;
1131: }
1.168 albertel 1132: &Apache::lonxml::debug("all dim ".join(':',keys(%Apache::bridgetask::top_dimensionlist))."results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
1.89 albertel 1133: $Apache::lonhomework::results{'resource.0.regrader'}=
1.138 albertel 1134: $env{'user.name'}.':'.$env{'user.domain'};
1.20 albertel 1135: if ($review) {
1.89 albertel 1136: $Apache::lonhomework::results{"resource.$version.0.status"}='review';
1.33 albertel 1137: if ($env{'form.queue'} eq 'reviewqueue') {
1138: &check_queue_unlock($env{'form.queue'});
1139: &Apache::lonxml::debug(" still needs review not changing status.");
1140: } else {
1.49 albertel 1141: &move_between_queues($env{'form.queue'},'reviewqueue');
1.33 albertel 1142: }
1.20 albertel 1143: } elsif ($ungraded) {
1.89 albertel 1144: $Apache::lonhomework::results{"resource.$version.0.status"}='ungraded';
1.49 albertel 1145: if ($env{'form.queue'} eq 'reviewqueue' ||
1146: $env{'form.queue'} eq 'none' ) {
1.33 albertel 1147: &Apache::lonxml::debug("moving back.");
1.49 albertel 1148: &move_between_queues($env{'form.queue'},'gradingqueue');
1.33 albertel 1149: } else {
1150: &check_queue_unlock($env{'form.queue'});
1151: }
1.20 albertel 1152: } elsif ($mandatory_failed) {
1.89 albertel 1153: $Apache::lonhomework::results{"resource.$version.0.status"}='fail';
1.25 albertel 1154: $Apache::lonhomework::results{"resource.$version.0.solved"}='incorrect_by_override';
1155: $Apache::lonhomework::results{"resource.$version.0.award"}='INCORRECT';
1156: $Apache::lonhomework::results{"resource.$version.0.awarded"}='0';
1.39 albertel 1157: &remove_from_queue($env{'form.queue'});
1158:
1159: my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser();
1.52 albertel 1160:
1161: if ($env{'form.regrade'} ne 'yes') {
1162: $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
1163: $Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
1164: &Apache::grades::version_portfiles(
1165: \%Apache::lonhomework::results,
1166: ["$version.0.bridgetask"],$courseid,
1167: $symb,$udom,$uname,
1168: ["$version.0.bridgetask"]);
1169: }
1.20 albertel 1170: } else {
1.89 albertel 1171: $Apache::lonhomework::results{"resource.$version.0.status"}='pass';
1.25 albertel 1172: $Apache::lonhomework::results{"resource.$version.0.solved"}='correct_by_override';
1173: $Apache::lonhomework::results{"resource.$version.0.award"}='EXACT_ANS';
1174: $Apache::lonhomework::results{"resource.$version.0.awarded"}='1';
1.32 albertel 1175: &remove_from_queue($env{'form.queue'});
1.39 albertel 1176:
1177: my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser();
1.52 albertel 1178: if ($env{'form.regrade'} ne 'yes') {
1179: $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
1180: $Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
1181: &Apache::grades::version_portfiles(
1182: \%Apache::lonhomework::results,
1183: ["$version.0.bridgetask"],$courseid,
1184: $symb,$udom,$uname,
1185: ["$version.0.bridgetask"]);
1186: }
1.20 albertel 1187: }
1.89 albertel 1188: $Apache::lonhomework::results{"resource.0.status"}=
1189: $Apache::lonhomework::results{"resource.$version.0.status"};
1.28 albertel 1190: if (defined($Apache::lonhomework::results{"resource.$version.0.awarded"})) {
1.26 albertel 1191: $Apache::lonhomework::results{"resource.0.award"}=
1.50 albertel 1192: $Apache::lonhomework::results{"resource.$version.0.award"};
1.26 albertel 1193: $Apache::lonhomework::results{"resource.0.awarded"}=
1.50 albertel 1194: $Apache::lonhomework::results{"resource.$version.0.awarded"};
1.26 albertel 1195: $Apache::lonhomework::results{"resource.0.solved"}=
1.50 albertel 1196: $Apache::lonhomework::results{"resource.$version.0.solved"};
1.25 albertel 1197: }
1.94 albertel 1198: &minimize_storage();
1.21 albertel 1199: &Apache::structuretags::finalize_storage();
1.20 albertel 1200: }
1.15 albertel 1201: } elsif ($target eq 'webgrade') {
1.131 albertel 1202: $result.="</div>";
1.20 albertel 1203: #$result.='<input type="submit" name="next" value="'.
1204: # &mt('Save & Next').'" /> ';
1205: #$result.='<input type="submit" name="end" value="'.
1206: # &mt('Save & Stop Grading').'" /> ';
1207: #$result.='<input type="submit" name="throwaway" value="'.
1208: # &mt('Throw Away & Stop Grading').'" /> ';
1209: #$result.='<input type="submit" name="save" value="'.
1210: # &mt('Save Partial Grade and Continue Grading').'" /> ';
1.124 albertel 1211: $result.='</form>'."\n</div>\n</div>\n".
1.140 albertel 1212: &Apache::loncommon::end_page();
1.1 albertel 1213: } elsif ($target eq 'meta') {
1.70 albertel 1214: $result.=&Apache::response::meta_package_write('Task');
1.77 albertel 1215: $result.=&Apache::response::meta_stores_write('solved','string',
1216: 'Problem Status');
1217: $result.=&Apache::response::meta_stores_write('tries','int_zeropos',
1218: 'Number of Attempts');
1219: $result.=&Apache::response::meta_stores_write('awarded','float',
1220: 'Partial Credit Factor');
1221: $result.=&Apache::response::meta_stores_write('status','string',
1222: 'Bridge Task Status');
1.1 albertel 1223: }
1.4 albertel 1224: undef($Apache::lonhomework::parsing_a_task);
1.1 albertel 1225: return $result;
1226: }
1227:
1.31 albertel 1228: sub move_between_queues {
1229: my ($src_queue,$dest_queue)=@_;
1.49 albertel 1230: my $cur_data;
1231: if ($src_queue ne 'none') {
1232: $cur_data=&get_queue_data($src_queue);
1233: if (!$cur_data) { return 'not_exist'; }
1234: } else {
1235: $cur_data = ['none'];
1236: }
1.148 albertel 1237: my $result=&add_to_queue($dest_queue,$cur_data);
1.31 albertel 1238: if ($result ne 'ok') {
1239: return $result;
1240: }
1241: &check_queue_unlock($src_queue);
1242: return &remove_from_queue($src_queue);
1.21 albertel 1243: }
1244:
1245: sub check_queue_unlock {
1.32 albertel 1246: my ($queue,$key,$allow_not_me)=@_;
1.49 albertel 1247: if ($queue eq 'none') { return 'ok'; }
1.30 albertel 1248: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
1.32 albertel 1249: if (!defined($key)) {
1.138 albertel 1250: $key="$symb\0queue\0$uname:$udom";
1.32 albertel 1251: }
1.30 albertel 1252: my $cnum=$env{'course.'.$cid.'.num'};
1253: my $cdom=$env{'course.'.$cid.'.domain'};
1.138 albertel 1254: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.30 albertel 1255: my $who=&queue_key_locked($queue,$key,$cdom,$cnum);
1256: if ($who eq $me) {
1.163 albertel 1257: &Apache::lonxml::debug("unlocking my own $who");
1.32 albertel 1258: return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
1259: } elsif ($allow_not_me) {
1.33 albertel 1260: &Apache::lonxml::debug("unlocking $who by $me");
1.32 albertel 1261: return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
1.30 albertel 1262: }
1.32 albertel 1263: return 'not_owner';
1.21 albertel 1264: }
1265:
1.88 albertel 1266: sub in_queue {
1267: my ($queue,$symb,$cdom,$cnum,$udom,$uname)=@_;
1268: if ($queue eq 'none') { return 0; }
1269: if (!defined($symb) || !defined($cdom) || !defined($cnum)
1270: || !defined($udom) || !defined($uname)) {
1271: ($symb,my $cid,$udom,$uname)=&Apache::lonxml::whichuser();
1272: $cnum=$env{'course.'.$cid.'.num'};
1273: $cdom=$env{'course.'.$cid.'.domain'};
1274: }
1275:
1276: my $key=&encode_queue_key($symb,$udom,$uname);
1277: my %results = &Apache::lonnet::get($queue,[$key],$cdom,$cnum);
1278:
1279: if (defined($results{$key})) {
1280: return 1;
1281: }
1282: return 0;
1283: }
1284:
1.21 albertel 1285: sub remove_from_queue {
1.86 albertel 1286: my ($queue,$symb,$cdom,$cnum,$udom,$uname)=@_;
1.49 albertel 1287: if ($queue eq 'none') { return 'ok'; }
1.86 albertel 1288: if (!defined($symb) || !defined($cdom) || !defined($cnum)
1289: || !defined($udom) || !defined($uname)) {
1290: ($symb,my $cid,$udom,$uname)=&Apache::lonxml::whichuser();
1291: $cnum=$env{'course.'.$cid.'.num'};
1292: $cdom=$env{'course.'.$cid.'.domain'};
1293: }
1.88 albertel 1294: if (!&in_queue($queue,$symb,$cdom,$cnum,$udom,$uname)) {
1295: return 'ok';
1296: }
1.86 albertel 1297: my $key=&encode_queue_key($symb,$udom,$uname);
1.27 albertel 1298: my @keys=($key,"$key\0locked");
1.31 albertel 1299: return &Apache::lonnet::del($queue,\@keys,$cdom,$cnum);
1.21 albertel 1300: }
1301:
1.16 albertel 1302: sub setup_env_for_other_user {
1303: my ($queue_key,$safeeval)=@_;
1304: my ($symb,$uname,$udom)=&decode_queue_key($queue_key);
1.30 albertel 1305: &Apache::lonxml::debug("setup_env for $queue_key");
1.16 albertel 1306: $env{'form.grade_symb'}=$symb;
1307: $env{'form.grade_domain'}=$udom;
1308: $env{'form.grade_username'}=$uname;
1309: $env{'form.grade_courseid'}=$env{'request.course.id'};
1310: &Apache::lonxml::initialize_rndseed($safeeval);
1311: }
1312:
1.31 albertel 1313: sub get_queue_data {
1.165 albertel 1314: my ($queue,$udom,$uname)=@_;
1315: my ($symb,$cid,$other_udom,$other_uname)=&Apache::lonxml::whichuser();
1316: if (!$uname || !$udom) {
1317: $uname=$other_uname;
1318: $udom =$other_udom;
1319: }
1.31 albertel 1320: my $cnum=$env{'course.'.$cid.'.num'};
1321: my $cdom=$env{'course.'.$cid.'.domain'};
1.138 albertel 1322: my $todo="$symb\0queue\0$uname:$udom";
1.31 albertel 1323: my ($key,$value)=&Apache::lonnet::get($queue,[$todo],$cdom,$cnum);
1324: if ($key eq $todo && ref($value)) {
1325: return $value;
1326: }
1327: return undef;
1328: }
1329:
1.84 albertel 1330:
1.49 albertel 1331: sub check_queue_for_key {
1.84 albertel 1332: my ($cdom,$cnum,$queue,$todo)=@_;
1333:
1.49 albertel 1334: my %results=
1335: &Apache::lonnet::get($queue,[$todo,"$todo\0locked"],$cdom,$cnum);
1336:
1337: if (exists($results{$todo}) && ref($results{$todo})) {
1338: if (defined($results{"$todo\0locked"})) {
1339: return 'locked';
1340: }
1.148 albertel 1341: if (my $slot=&slotted_access($results{$todo})) {
1.86 albertel 1342: my %slot_data=&Apache::lonnet::get_slot($slot);
1343: if ($slot_data{'endtime'} > time) {
1344: return 'in_progress';
1345: }
1.148 albertel 1346: } else {
1347: my ($symb) = &decode_queue_key($todo);
1348: my $due_date = &Apache::lonhomework::due_date('0',$symb);
1349: if ($due_date > time) {
1350: return 'in_progress';
1351: }
1.58 albertel 1352: }
1.49 albertel 1353: return 'enqueued';
1354: }
1355: return undef;
1356: }
1357:
1.14 albertel 1358: sub add_to_queue {
1.82 albertel 1359: my ($queue,$user_data)=@_;
1.49 albertel 1360: if ($queue eq 'none') { return 'ok'; }
1.14 albertel 1361: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
1.82 albertel 1362: if (!$cid || $env{'request.state'} eq 'construct') {
1363: return 'no_queue';
1364: }
1.14 albertel 1365: my $cnum=$env{'course.'.$cid.'.num'};
1366: my $cdom=$env{'course.'.$cid.'.domain'};
1367: my %data;
1.138 albertel 1368: $data{"$symb\0queue\0$uname:$udom"}=$user_data;
1.83 albertel 1369: return &Apache::lonnet::cput($queue,\%data,$cdom,$cnum);
1.14 albertel 1370: }
1371:
1.156 albertel 1372: sub get_limited_classlist {
1373: my ($sections) = @_;
1374:
1375: my $classlist = &Apache::loncoursedata::get_classlist();
1.157 albertel 1376: foreach my $student (keys(%$classlist)) {
1377: if ( $classlist->{$student}[&Apache::loncoursedata::CL_STATUS()]
1378: ne 'Active') {
1379: delete($classlist->{$student});
1380: }
1381: }
1.156 albertel 1382:
1.157 albertel 1383: if (ref($sections) && !grep('all',@{ $sections })) {
1.156 albertel 1384: foreach my $student (keys(%$classlist)) {
1385: my $section =
1386: $classlist->{$student}[&Apache::loncoursedata::CL_SECTION()];
1387: if (! grep($section,@{ $sections })) {
1388: delete($classlist->{$student});
1389: }
1390: }
1391: }
1392: return $classlist;
1393: }
1394:
1395:
1.14 albertel 1396: sub show_queue {
1.32 albertel 1397: my ($queue,$with_selects)=@_;
1.14 albertel 1398: my $result;
1399: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
1400: my $cnum=$env{'course.'.$cid.'.num'};
1401: my $cdom=$env{'course.'.$cid.'.domain'};
1.59 albertel 1402:
1403: my @chosen_sections=
1404: &Apache::loncommon::get_env_multiple('form.chosensections');
1.156 albertel 1405:
1406: my $classlist = &get_limited_classlist(\@chosen_sections);
1407:
1.63 albertel 1408: if (!(grep(/^all$/,@chosen_sections))) {
1409: $result.='<p> Showing only sections <tt>'.join(', ',@chosen_sections).
1410: '</tt>.</p> '."\n";
1411: }
1.59 albertel 1412:
1.156 albertel 1413: my ($view,$view_section);
1414: my $scope = $env{'request.course.id'};
1415: if (!($view=&Apache::lonnet::allowed('vgr',$scope))) {
1416: $scope .= '/'.$env{'request.course.sec'};
1417: if ( $view = &Apache::lonnet::allowed('vgr',$scope)) {
1418: $view_section=$env{'request.course.sec'};
1419: } else {
1420: undef($view);
1421: }
1422: }
1423:
1.16 albertel 1424: my $regexp="^$symb\0";
1.30 albertel 1425: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.31 albertel 1426: my ($tmp)=%queue;
1427: if ($tmp=~/^error: 2 /) {
1.159 albertel 1428: return "\n<h3>Current Queue - $queue</h3>".
1429: &Apache::loncommon::start_data_table().
1430: &Apache::loncommon::start_data_table_row().
1431: '<td>'.&mt('Empty').'</td>'.
1432: &Apache::loncommon::end_data_table_row().
1433: &Apache::loncommon::end_data_table();
1.31 albertel 1434: }
1.103 albertel 1435: my $title=&Apache::lonnet::gettitle($symb);
1.159 albertel 1436: $result.="\n<h3>Current Queue - $title $queue </h3>".
1437: &Apache::loncommon::start_data_table().
1438: &Apache::loncommon::start_data_table_header_row();
1.103 albertel 1439: if ($with_selects) { $result.="<th>Status</th><th></th>"; }
1.159 albertel 1440: $result.="<th>user</th><th>data</th>".
1441: &Apache::loncommon::end_data_table_header_row();
1.14 albertel 1442: foreach my $key (sort(keys(%queue))) {
1.59 albertel 1443: my ($symb,$uname,$udom) = &decode_queue_key($key);
1444: if (!defined($classlist->{$uname.':'.$udom})) { next; }
1.156 albertel 1445:
1446: my $section = $classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_SECTION()];
1447:
1448: my $can_view=1;
1449: if (!$view
1450: || ($view_section && !$section)
1451: || ($view_section && $section && ($view_section ne $section))) {
1452: $can_view=0;
1453: }
1454:
1.32 albertel 1455: if ($key=~/locked$/ && !$with_selects) {
1.159 albertel 1456: $result.= &Apache::loncommon::start_data_table_row().
1457: "<td>$uname</td>";
1.103 albertel 1458: $result.='<td>'.$queue{$key}.'</td></tr>';
1.32 albertel 1459: } elsif ($key=~/timestamp$/ && !$with_selects) {
1.159 albertel 1460: $result.=&Apache::loncommon::start_data_table_row()."<td></td>";
1.103 albertel 1461: $result.='<td>'.
1.16 albertel 1462: &Apache::lonlocal::locallocaltime($queue{$key})."</td></tr>";
1.32 albertel 1463: } elsif ($key!~/(timestamp|locked)$/) {
1.159 albertel 1464: $result.= &Apache::loncommon::start_data_table_row();
1.148 albertel 1465: my ($end_time,$slot_text);
1466: if (my $slot=&slotted_access($queue{$key})) {
1467: my %slot_data=&Apache::lonnet::get_slot($slot);
1468: $end_time = $slot_data{'endtime'};
1469: $slot_text = &mt('Slot: [_1]',$slot);
1470: } else {
1471: $end_time = &Apache::lonhomework::due_date('0',$symb);
1472: $slot_text = '';
1473: }
1.32 albertel 1474: if ($with_selects) {
1.158 www 1475: my $ekey=&escape($key);
1.103 albertel 1476: my ($action,$description,$status)=('select',&mt('Select'));
1.32 albertel 1477: if (exists($queue{"$key\0locked"})) {
1.138 albertel 1478: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.103 albertel 1479: $status=&mt('Locked by <tt>[_1]</tt>',$queue{"$key\0locked"});
1.32 albertel 1480: if ($me eq $queue{"$key\0locked"}) {
1481: ($action,$description)=('resume',&mt('Resume'));
1482: } else {
1483: ($action,$description)=('unlock',&mt('Unlock'));
1484: }
1485: }
1.62 albertel 1486: my $seclist;
1487: foreach my $sec (@chosen_sections) {
1488: $seclist.='<input type="hidden" name="chosensections"
1489: value="'.$sec.'" />';
1490: }
1.156 albertel 1491: if ($can_view && ($end_time ne '' && time > $end_time)) {
1.35 albertel 1492: $result.=(<<FORM);
1.103 albertel 1493: <td>$status</td>
1.32 albertel 1494: <td>
1.115 albertel 1495: <form style="display: inline" method="post">
1.32 albertel 1496: <input type="hidden" name="gradingkey" value="$ekey" />
1497: <input type="hidden" name="queue" value="$queue" />
1498: <input type="hidden" name="gradingaction" value="$action" />
1499: <input type="hidden" name="webgrade" value="no" />
1.33 albertel 1500: <input type="hidden" name="queuemode" value="selected" />
1.32 albertel 1501: <input type="submit" name="submit" value="$description" />
1.62 albertel 1502: $seclist
1.32 albertel 1503: </form>
1504: </td>
1505: FORM
1.156 albertel 1506: } elsif (!$can_view && ($end_time ne '' && time > $end_time)) {
1507: $result.='<td>'.&mt("Not gradable").'</td><td> </td>'
1.35 albertel 1508: } else {
1.148 albertel 1509: $result.='<td>'.&mt("In Progress").'</td><td> </td>'
1.35 albertel 1510: }
1.32 albertel 1511: }
1.156 albertel 1512: $result.= "<td>".$classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_FULLNAME()].
1.138 albertel 1513: " <tt>($uname:$udom)</tt> </td>";
1.148 albertel 1514: $result.='<td>'.$slot_text.' End time: '.
1515: &Apache::lonlocal::locallocaltime($end_time).
1.159 albertel 1516: "</td>".&Apache::loncommon::end_data_table_row();
1.16 albertel 1517: }
1.14 albertel 1518: }
1.159 albertel 1519: $result.= &Apache::loncommon::end_data_table()."<hr />\n";
1.14 albertel 1520: return $result;
1521: }
1522:
1.34 albertel 1523: sub get_queue_counts {
1524: my ($queue)=@_;
1525: my $result;
1526: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
1527: my $cnum=$env{'course.'.$cid.'.num'};
1528: my $cdom=$env{'course.'.$cid.'.domain'};
1.156 albertel 1529:
1.157 albertel 1530: my $classlist=&get_limited_classlist();
1.156 albertel 1531:
1.34 albertel 1532: my $regexp="^$symb\0";
1533: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1534: my ($tmp)=%queue;
1535: if ($tmp=~/^error: 2 /) {
1536: return (0,0,0);
1537: }
1538: my ($entries,$ready_to_grade,$locks)=(0,0,0);
1.96 albertel 1539: my %slot_cache;
1.34 albertel 1540: foreach my $key (sort(keys(%queue))) {
1.156 albertel 1541: my ($symb,$uname,$udom) = &decode_queue_key($key);
1542: if (!defined($classlist->{$uname.':'.$udom})) { next; }
1543:
1.34 albertel 1544: if ($key=~/locked$/) {
1545: $locks++;
1546: } elsif ($key=~/timestamp$/) {
1547: #ignore
1548: } elsif ($key!~/(timestamp|locked)$/) {
1549: $entries++;
1.148 albertel 1550: if (my $slot=&slotted_access($queue{$key})) {
1551: if (!exists($slot_cache{$slot})) {
1552: my %slot_data=&Apache::lonnet::get_slot($slot);
1553: $slot_cache{$slot} = \%slot_data;
1554: }
1555: if (time > $slot_cache{$slot}{'endtime'}) {
1556: $ready_to_grade++;
1557: }
1558: } else {
1559: my $due_date = &Apache::lonhomework::due_date('0',$symb);
1560: if ($due_date ne '' && time > $due_date) {
1561: $ready_to_grade++;
1562: }
1.34 albertel 1563: }
1564: }
1565: }
1566: return ($entries,$ready_to_grade,$locks);
1567: }
1568:
1.49 albertel 1569: sub encode_queue_key {
1570: my ($symb,$udom,$uname)=@_;
1.138 albertel 1571: return "$symb\0queue\0$uname:$udom";
1.49 albertel 1572: }
1573:
1.14 albertel 1574: sub decode_queue_key {
1575: my ($key)=@_;
1576: my ($symb,undef,$user) = split("\0",$key);
1.138 albertel 1577: my ($uname,$udom) = split(':',$user);
1.14 albertel 1578: return ($symb,$uname,$udom);
1579: }
1580:
1581: sub queue_key_locked {
1.30 albertel 1582: my ($queue,$key,$cdom,$cnum)=@_;
1.33 albertel 1583: if (!defined($cdom) || !defined($cnum)) {
1584: my (undef,$cid)=&Apache::lonxml::whichuser();
1585: $cnum=$env{'course.'.$cid.'.num'};
1586: $cdom=$env{'course.'.$cid.'.domain'};
1587: }
1.14 albertel 1588: my ($key_locked,$value)=
1.30 albertel 1589: &Apache::lonnet::get($queue,["$key\0locked"],$cdom,$cnum);
1.14 albertel 1590: if ($key_locked eq "$key\0locked") {
1591: return $value;
1592: }
1593: return undef;
1594: }
1595:
1.148 albertel 1596: sub slotted_access {
1597: my ($queue_entry) = @_;
1598: if (ref($queue_entry) eq 'ARRAY') {
1599: if (defined($queue_entry->[0])) {
1600: return $queue_entry->[0];
1601: }
1602: return undef;
1603: } elsif (ref($queue_entry) eq 'HASH') {
1604: if (defined($queue_entry->{'slot'})) {
1605: return $queue_entry->{'slot'};
1606: }
1607: return undef;
1608: }
1609: return undef;
1610: }
1611:
1.14 albertel 1612: sub pick_from_queue_data {
1.156 albertel 1613: my ($queue,$check_section,$queuedata,$cdom,$cnum,$classlist)=@_;
1.98 albertel 1614: my @possible; # will hold queue entries that are valid to be selected
1.30 albertel 1615: foreach my $key (keys(%$queuedata)) {
1.68 albertel 1616: if ($key =~ /\0locked$/) { next; }
1617: if ($key =~ /\0timestamp$/) { next; }
1.156 albertel 1618:
1.14 albertel 1619: my ($symb,$uname,$udom)=&decode_queue_key($key);
1.156 albertel 1620: if (!defined($classlist->{$uname.':'.$udom})) { next; }
1621:
1.14 albertel 1622: if ($check_section) {
1.156 albertel 1623: my $section =
1624: $classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_SECTION()];
1.17 albertel 1625: if ($section eq $check_section) {
1.33 albertel 1626: &Apache::lonxml::debug("my sec");
1.15 albertel 1627: next;
1628: }
1.14 albertel 1629: }
1.148 albertel 1630: my $end_time;
1631: if (my $slot=&slotted_access($queuedata->{$key})) {
1.154 albertel 1632: &Apache::lonxml::debug("looking at slot $slot");
1.148 albertel 1633: my %slot_data=&Apache::lonnet::get_slot($slot);
1634: if ($slot_data{'endtime'} < time) {
1635: $end_time = $slot_data{'endtime'};
1.154 albertel 1636: } else {
1637: &Apache::lonxml::debug("not time ".$slot_data{'endtime'});
1638: next;
1.148 albertel 1639: }
1640: } else {
1641: my $due_date = &Apache::lonhomework::due_date('0',$symb);
1.154 albertel 1642: if ($due_date < time) {
1.148 albertel 1643: $end_time = $due_date;
1.154 albertel 1644: } else {
1645: &Apache::lonxml::debug("not time $due_date");
1646: next;
1.148 albertel 1647: }
1648: }
1649:
1.98 albertel 1650: if (exists($queuedata->{"$key\0locked"})) {
1.33 albertel 1651: &Apache::lonxml::debug("someone already has um.");
1.15 albertel 1652: next;
1653: }
1.148 albertel 1654: push(@possible,[$key,$end_time]);
1.98 albertel 1655: }
1656: if (@possible) {
1657: # sort entries in order by slot end time
1658: @possible = sort { $a->[1] <=> $b->[1] } @possible;
1.137 albertel 1659: # pick one of the entries in the top 10% in small queues and one
1660: # of the first ten entries in large queues
1.139 albertel 1661: #my $ten_percent = int($#possible * 0.1);
1662: #if ($ten_percent < 1 ) { $ten_percent = 1; }
1663: #if ($ten_percent > 10) { $ten_percent = 10; }
1664: #my $max=($#possible < $ten_percent) ? $#possible : $ten_percent;
1.137 albertel 1665:
1.139 albertel 1666: #return $possible[int(rand($max))][0];
1667: return $possible[0][0];
1.14 albertel 1668: }
1669: return undef;
1670: }
1671:
1.15 albertel 1672: sub find_mid_grade {
1.30 albertel 1673: my ($queue,$symb,$cdom,$cnum)=@_;
1.158 www 1674: my $todo=&unescape($env{'form.gradingkey'});
1.138 albertel 1675: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.15 albertel 1676: if ($todo) {
1.30 albertel 1677: my $who=&queue_key_locked($queue,$todo,$cdom,$cnum);
1.15 albertel 1678: if ($who eq $me) { return $todo; }
1679: }
1680: my $regexp="^$symb\0.*\0locked\$";
1.30 albertel 1681: my %locks=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.15 albertel 1682: foreach my $key (keys(%locks)) {
1683: my $who=$locks{$key};
1684: if ($who eq $me) {
1685: $todo=$key;
1686: $todo=~s/\0locked$//;
1687: return $todo;
1688: }
1689: }
1690: return undef;
1691: }
1692:
1.32 albertel 1693: sub lock_key {
1694: my ($queue,$todo)=@_;
1.138 albertel 1695: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.32 albertel 1696: my (undef,$cid)=&Apache::lonxml::whichuser();
1697: my $cnum=$env{'course.'.$cid.'.num'};
1698: my $cdom=$env{'course.'.$cid.'.domain'};
1699: my $success=&Apache::lonnet::newput($queue,{"$todo\0locked"=> $me},
1700: $cdom,$cnum);
1.33 albertel 1701: &Apache::lonxml::debug("success $success $todo");
1.32 albertel 1702: if ($success eq 'ok') {
1703: return 1;
1704: }
1705: return 0;
1706: }
1707:
1.86 albertel 1708: sub get_queue_symb_status {
1.85 albertel 1709: my ($queue,$symb,$cdom,$cnum) = @_;
1710: if (!defined($cdom) || !defined($cnum)) {
1711: my (undef,$cid)=&Apache::lonxml::whichuser();
1712: $cnum=$env{'course.'.$cid.'.num'};
1713: $cdom=$env{'course.'.$cid.'.domain'};
1714: }
1.157 albertel 1715: my $classlist=&get_limited_classlist();
1.156 albertel 1716:
1.85 albertel 1717: my $regexp="^$symb\0";
1718: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1719: my ($tmp)=%queue;
1720: if ($tmp=~/^error: 2 /) { return; }
1721: my @users;
1722: foreach my $key (sort(keys(%queue))) {
1723: next if ($key=~/locked$/);
1724: next if ($key=~/timestamp$/);
1725: my ($symb,$uname,$udom) = &decode_queue_key($key);
1.156 albertel 1726: next if (!defined($classlist->{$uname.':'.$udom}));
1.85 albertel 1727: push(@users,"$uname:$udom");
1728: }
1729: return @users;
1730: }
1731:
1.14 albertel 1732: sub get_from_queue {
1.30 albertel 1733: my ($queue)=@_;
1.14 albertel 1734: my $result;
1735: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
1736: my $cnum=$env{'course.'.$cid.'.num'};
1737: my $cdom=$env{'course.'.$cid.'.domain'};
1.32 albertel 1738: my $todo=&find_mid_grade($queue,$symb,$cdom,$cnum);
1.33 albertel 1739: &Apache::lonxml::debug("found ".join(':',&decode_queue_key($todo)));
1.16 albertel 1740: if ($todo) { return $todo; }
1.95 albertel 1741: my $attempts=0;
1.156 albertel 1742:
1.157 albertel 1743: my $classlist=&get_limited_classlist();
1.156 albertel 1744:
1.14 albertel 1745: while (1) {
1.95 albertel 1746: if ($attempts > 2) {
1747: # tried twice to get a queue entry, giving up
1748: return (undef,'unable');
1749: }
1.14 albertel 1750: my $starttime=time;
1.83 albertel 1751: &Apache::lonnet::cput($queue,{"$symb\0timestamp"=>$starttime},
1752: $cdom,$cnum);
1.33 albertel 1753: &Apache::lonxml::debug("$starttime");
1.14 albertel 1754: my $regexp="^$symb\0queue\0";
1.156 albertel 1755: #my $range= ($attempts < 1 ) ? '0-100' : '0-400';
1.97 albertel 1756:
1.98 albertel 1757: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.33 albertel 1758: #make a pass looking for a user _not_ in my section
1.14 albertel 1759: if ($env{'request.course.sec'}) {
1.33 albertel 1760: &Apache::lonxml::debug("sce");
1.30 albertel 1761: $todo=&pick_from_queue_data($queue,$env{'request.course.sec'},
1.156 albertel 1762: \%queue,$cdom,$cnum,$classlist);
1.33 albertel 1763: &Apache::lonxml::debug("sce $todo");
1.14 albertel 1764: }
1.33 albertel 1765: # no one _not_ in our section so look for any user that is
1766: # ready for grading
1.14 albertel 1767: if (!$todo) {
1.33 albertel 1768: &Apache::lonxml::debug("no sce");
1.156 albertel 1769: $todo=&pick_from_queue_data($queue,undef,\%queue,$cdom,$cnum,
1770: $classlist);
1.33 albertel 1771: &Apache::lonxml::debug("no sce $todo");
1.14 albertel 1772: }
1773: # no user to grade
1774: if (!$todo) { last; }
1.33 albertel 1775: &Apache::lonxml::debug("got $todo");
1.14 albertel 1776: # otherwise found someone so lets try to lock them
1.32 albertel 1777: # unless someone else already picked them
1.95 albertel 1778: if (!&lock_key($queue,$todo)) {
1779: $attempts++;
1780: next;
1781: }
1.14 albertel 1782: my (undef,$endtime)=
1.30 albertel 1783: &Apache::lonnet::get($queue,["$symb\0timestamp"],
1.14 albertel 1784: $cdom,$cnum);
1.33 albertel 1785: &Apache::lonxml::debug("emd $endtime");
1.14 albertel 1786: # someone else already modified the queue,
1787: # perhaps our picked user wass already fully graded between
1788: # when we picked him and when we locked his record? so lets
1789: # double check.
1790: if ($endtime != $starttime) {
1791: my ($key,$value)=
1.30 albertel 1792: &Apache::lonnet::get($queue,["$todo"],
1.14 albertel 1793: $cdom,$cnum);
1.33 albertel 1794: &Apache::lonxml::debug("check $key .. $value");
1.14 albertel 1795: if ($key eq $todo && ref($value)) {
1796: } else {
1.30 albertel 1797: &Apache::lonnet::del($queue,["$todo\0locked"],
1.14 albertel 1798: $cdom,$cnum);
1.33 albertel 1799: &Apache::lonxml::debug("del");
1.95 albertel 1800: $attempts++;
1.14 albertel 1801: next;
1802: }
1803: }
1.33 albertel 1804: &Apache::lonxml::debug("last $todo");
1.14 albertel 1805: last;
1806: }
1807: return $todo;
1808: }
1809:
1.49 albertel 1810: sub select_user {
1811: my ($symb,$cid)=&Apache::lonxml::whichuser();
1812:
1.59 albertel 1813: my @chosen_sections=
1814: &Apache::loncommon::get_env_multiple('form.chosensections');
1.156 albertel 1815:
1816: my $classlist = &get_limited_classlist(\@chosen_sections);
1.63 albertel 1817:
1818: my $result;
1819: if (!(grep(/^all$/,@chosen_sections))) {
1820: $result.='<p> Showing only sections <tt>'.join(', ',@chosen_sections).
1821: '</tt>.</p> '."\n";
1822: }
1.159 albertel 1823: $result.=&Apache::loncommon::start_data_table();
1.49 albertel 1824:
1.156 albertel 1825: foreach my $student (sort {lc($classlist->{$a}[&Apache::loncoursedata::CL_FULLNAME()]) cmp lc($classlist->{$b}[&Apache::loncoursedata::CL_FULLNAME()]) } (keys(%$classlist))) {
1.49 albertel 1826: my ($uname,$udom) = split(/:/,$student);
1.59 albertel 1827:
1.84 albertel 1828: my $cnum=$env{'course.'.$cid.'.num'};
1829: my $cdom=$env{'course.'.$cid.'.domain'};
1.88 albertel 1830: my %status = &get_student_status($symb,$cdom,$cnum,$udom,$uname,
1831: 'Task');
1.49 albertel 1832: my $queue = 'none';
1.58 albertel 1833: my $cannot_grade;
1834: if ($status{'reviewqueue'} =~ /^(in_progress|enqueue)$/) {
1.49 albertel 1835: $queue = 'reviewqueue';
1.58 albertel 1836: if ($status{'reviewqueue'} eq 'in_progress') {
1837: $cannot_grade=1;
1838: }
1839: } elsif ($status{'gradingqueue'} =~ /^(in_progress|enqueue)$/) {
1.49 albertel 1840: $queue = 'gradingqueue';
1.58 albertel 1841: if ($status{'gradingqueue'} eq 'in_progress') {
1842: $cannot_grade=1;
1843: }
1.49 albertel 1844: }
1845: my $todo =
1.158 www 1846: &escape(&encode_queue_key($symb,$udom,$uname));
1.58 albertel 1847: if ($cannot_grade) {
1.159 albertel 1848: $result.=&Apache::loncommon::start_data_table_row().
1849: '<td> </td><td>'.$classlist->{$student}[&Apache::loncoursedata::CL_FULLNAME()].
1.58 albertel 1850: '</td><td>';
1851: } else {
1.62 albertel 1852: my $seclist;
1853: foreach my $sec (@chosen_sections) {
1854: $seclist.='<input type="hidden" name="chosensections"
1855: value="'.$sec.'" />';
1856: }
1.159 albertel 1857: $result.=&Apache::loncommon::start_data_table_row();
1.58 albertel 1858: $result.=<<RESULT;
1.49 albertel 1859: <td>
1.115 albertel 1860: <form style="display: inline" method="post">
1.49 albertel 1861: <input type="hidden" name="gradingkey" value="$todo" />
1862: <input type="hidden" name="queue" value="$queue" />
1863: <input type="hidden" name="webgrade" value="no" />
1.52 albertel 1864: <input type="hidden" name="regrade" value="yes" />
1.62 albertel 1865: <input type="submit" name="submit" value="Regrade" />
1866: $seclist
1.49 albertel 1867: </form>
1.155 albertel 1868: <td>$classlist->{$student}[&Apache::loncoursedata::CL_FULLNAME()] <tt>($student)</tt></td>
1.49 albertel 1869: <td>
1870: RESULT
1.58 albertel 1871: }
1.49 albertel 1872: if ($status{'status'} eq 'pass') {
1873: $result .= '<font color="green">'.&mt('Passed').'</font>';
1874: } elsif ($status{'status'} eq 'fail') {
1875: $result .= '<font color="red">'.&mt('Failed').'</font>';
1876: } elsif ($status{'status'} eq 'review') {
1877: $result .= '<font color="blue">'.&mt('Under Review').'</font>';
1878: } elsif ($status{'status'} eq 'ungraded') {
1879: $result .= &mt('Ungraded');
1880: } elsif ($status{'status'} ne '') {
1881: $result .= '<font color="orange">'.&mt('Unknown Status').'</font>';
1882: } else {
1883: $result.=" ";
1884: }
1885: if ($status{'version'}) {
1886: $result .= ' '.&mt('Version').' '.$status{'version'};
1887: }
1.101 albertel 1888: if ($status{'grader'}) {
1889: $result .= ' '.&mt('(Graded by [_1])',$status{'grader'}).' ';
1890: }
1.49 albertel 1891: $result.= '</td><td>';
1892: if ($status{'reviewqueue'} eq 'enqueued') {
1893: $result .= &mt('Awaiting Review');
1894: } elsif ($status{'reviewqueue'} eq 'locked') {
1895: $result .= &mt('Under Review');
1.58 albertel 1896: } elsif ($status{'reviewqueue'} eq 'in_progress') {
1897: $result .= &mt('Still being worked on.');
1.49 albertel 1898: } elsif ($status{'gradingqueue'} eq 'enqueued') {
1899: $result .= &mt('Awaiting Grading');
1900: } elsif ($status{'gradingqueue'} eq 'locked') {
1901: $result .= &mt('Being Graded');
1.58 albertel 1902: } elsif ($status{'gradingqueue'} eq 'in_progress') {
1903: $result .= &mt('Still being worked on.');
1.49 albertel 1904: } else {
1905: $result.=" ";
1906: }
1.159 albertel 1907: $result.= '</td>'.&Apache::loncommon::end_data_table_row();
1.49 albertel 1908: }
1.159 albertel 1909: $result.=&Apache::loncommon::end_data_table();
1.49 albertel 1910: return $result;
1911: }
1912:
1913: sub get_student_status {
1.86 albertel 1914: my ($symb,$cdom,$cnum,$udom,$uname,$type)=@_;
1915:
1916: my %status;
1917:
1918: if ($type eq 'Task') {
1919: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
1.49 albertel 1920: $udom,$uname);
1.89 albertel 1921: $status{'status'}=$record{'resource.0.status'};
1922: $status{'version'}=$record{'resource.0.version'};
1923: $status{'grader'}=$record{'resource.0.regrader'};
1.86 albertel 1924: }
1925: $status{'reviewqueue'}=
1926: &check_queue_for_key($cdom,$cnum,'reviewqueue',
1927: &encode_queue_key($symb,$udom,$uname));
1928: $status{'gradingqueue'}=
1929: &check_queue_for_key($cdom,$cnum,'gradingqueue',
1930: &encode_queue_key($symb,$udom,$uname));
1.49 albertel 1931: return %status;
1932: }
1933:
1.1 albertel 1934: sub start_ClosingParagraph {
1935: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1936: my $result;
1937: if ($target eq 'web') {
1.13 albertel 1938: } elsif ($target eq 'webgrade') {
1939: &Apache::lonxml::startredirection();
1.1 albertel 1940: }
1941: return $result;
1942: }
1943:
1944: sub end_ClosingParagraph {
1945: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1946: my $result;
1947: if ($target eq 'web') {
1.13 albertel 1948: } elsif ($target eq 'webgrade') {
1949: &Apache::lonxml::endredirection();
1.1 albertel 1950: }
1951: return $result;
1952: }
1953:
1.168 albertel 1954: sub get_dim_id {
1955: return $Apache::bridgetask::dimension[-1];
1956: }
1957:
1.19 albertel 1958: sub get_id {
1959: my ($parstack,$safeeval)=@_;
1960: my $id=&Apache::lonxml::get_param('id',$parstack,$safeeval);
1961: if (!$id) { $id=$Apache::lonxml::curdepth; }
1962: return $id;
1963: }
1964:
1.162 albertel 1965: sub start_Setup {
1966: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.168 albertel 1967: #undef(%dimension);
1968: my $dim = &get_id($parstack,$safeeval);
1969: push(@Apache::bridgetask::dimension,$dim);
1.162 albertel 1970: &Apache::lonxml::startredirection();
1.168 albertel 1971: return &internal_location($dim);
1.162 albertel 1972: }
1.173 albertel 1973:
1974: {
1975: my @allowed;
1976: sub enable_dimension_parsing {
1977: my ($id) = @_;
1978: push(@allowed,$id);
1979: }
1980: sub disable_dimension_parsing {
1981: pop(@allowed);
1982: }
1983: sub skip_dimension_parsing {
1984: my ($check) = @_;
1985: if (!@allowed) { return 0;}
1986: # if unspecified allow any id
1987: if ($allowed[-1] eq undef) { return 0;}
1988:
1989: return ($check ne $allowed[-1]);
1990: }
1991: }
1992:
1.151 albertel 1993: sub start_Question { return &start_Dimension(@_); }
1.1 albertel 1994: sub start_Dimension {
1.173 albertel 1995: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.168 albertel 1996: my $dim = &get_id($parstack,$safeeval);
1997: my $previous_dim;
1998: if (@Apache::bridgetask::dimension) {
1999: $previous_dim = $Apache::bridgetask::dimension[-1];
2000: push(@{$Apache::bridgetask::dimension{$previous_dim}{'contains'}},
2001: $dim);
1.173 albertel 2002: if(&skip_dimension_parsing($dim)) {
2003: $dimension{$previous_dim}{'criteria.'.$dim} =
2004: $token->[4]
2005: .&Apache::lonxml::get_all_text('/'.$tagstack->[-1],$parser,
2006: $style)
2007: .'</'.$tagstack->[-1].'>';
2008: }
1.169 albertel 2009: $dimension{$previous_dim}{'criteria.'.$dim.'.type'}='dimension';
2010: $dimension{$previous_dim}{'criteria.'.$dim.'.mandatory'}=
2011: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
2012: push(@{$dimension{$previous_dim}{'criterias'}},$dim);
1.171 albertel 2013: $dimension{$dim}{'nested'}=$previous_dim;
1.172 albertel 2014: &Apache::lonxml::debug("adding $dim as criteria to $previous_dim");
1.168 albertel 2015: } else {
2016: $Apache::bridgetask::top_dimensionlist{$dim}{'manadatory'}=
2017: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
2018: }
2019: push(@Apache::bridgetask::dimension,$dim);
1.54 albertel 2020: &Apache::lonxml::startredirection();
1.173 albertel 2021: &enable_dimension_parsing($dim);
1.168 albertel 2022: return &internal_location($dim);
1.1 albertel 2023: }
2024:
1.160 albertel 2025: sub start_QuestionText {
2026: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.168 albertel 2027: my $dim = &get_dim_id();
1.160 albertel 2028: my $text=&Apache::lonxml::get_all_text('/questiontext',$parser,$style);
2029: if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
1.169 albertel 2030: $dimension{$dim}{'questiontext'}=$text;
1.160 albertel 2031: }
2032: return '';
2033: }
2034:
2035: sub end_QuestionText {
2036: return '';
2037: }
2038:
1.13 albertel 2039: sub get_instance {
1.75 albertel 2040: my ($dim)=@_;
2041: my $rand_alg=&Apache::lonnet::get_rand_alg();
2042: if (!$rand_alg || $rand_alg eq '32bit' || $rand_alg eq '64bit' ||
2043: $rand_alg eq '64bit2' || $rand_alg eq '64bit3' ||
2044: $rand_alg eq '64bit4' ) {
2045: &Apache::response::pushrandomnumber();
1.169 albertel 2046: my @order=&Math::Random::random_permutation(@{$dimension{$dim}{'instances'}});
1.75 albertel 2047: my $num=@order;
2048: my $version=&get_version();
2049: my $which=($version-1)%$num;
2050: return $order[$which];
2051: } else {
2052: my ($version,$previous) = &get_version();
2053: my $instance =
2054: $Apache::lonhomework::history{"resource.$version.0.$dim.instance"};
2055: if (defined($instance)) { return $instance; }
2056:
2057: &Apache::response::pushrandomnumber();
1.173 albertel 2058: if (ref($dimension{$dim}{'instances'}) eq 'ARRAY') {
2059: my @instances = @{$dimension{$dim}{'instances'}};
2060: # remove disabled instances
2061: for (my $i=0; $i < $#instances; $i++) {
2062: if ($dimension{$dim}{$instances[$i].'.disabled'}) {
2063: splice(@instances,$i,1);
2064: $i--;
2065: }
2066: }
2067: @instances = &Math::Random::random_permutation(@instances);
2068: $instance = $instances[($version-1)%scalar(@instances)];
2069: if ($version =~ /^\d$/) {
2070: $Apache::lonhomework::results{"resource.$version.0.$dim.instance"} =
2071: $instance;
2072: $Apache::lonhomework::results{'INTERNAL_store'} = 1;
1.75 albertel 2073: }
2074: }
2075: &Apache::response::poprandomnumber();
2076: return $instance;
2077: }
1.13 albertel 2078: }
2079:
1.169 albertel 2080: sub get_criteria {
2081: my ($what,$version,$dim,$id) = @_;
2082: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
2083: my $prefix = ($type eq 'criteria') ? "$dim.$id"
2084: : "$id";
2085: my $entry = "resource.$version.0.$prefix.$what";
2086: if (exists($Apache::lonhomework::results{$entry})) {
2087: return $Apache::lonhomework::results{$entry};
2088: }
2089: return $Apache::lonhomework::history{$entry};
2090: }
2091:
1.18 albertel 2092: {
2093: my $last_link;
1.122 albertel 2094: sub link {
1.151 albertel 2095: my ($id) = @_;
2096: $id =~ s/\./_/g;
2097: return 'LC_GRADING_criteria_'.$id;
1.122 albertel 2098: }
1.151 albertel 2099: sub end_Question { return &end_Dimension(@_); }
1.18 albertel 2100: sub end_Dimension {
2101: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.54 albertel 2102: my $result=&Apache::lonxml::endredirection();
1.25 albertel 2103: my $dim=&get_id($parstack,$safeeval);
1.173 albertel 2104: if (&skip_dimension_parsing($dim)) {
2105: &disable_dimension_parsing($dim);
2106: pop(@Apache::bridgetask::dimension);
2107: return;
2108: }
1.75 albertel 2109: my $instance=&get_instance($dim);
1.25 albertel 2110: my $version=&get_version();
1.18 albertel 2111: if ($target eq 'web') {
1.173 albertel 2112: $result .= &nested_parse(\$dimension{$dim}{'intro'},[@_]);
1.76 albertel 2113: my @instances = $instance;
2114: if (&Apache::response::showallfoils()) {
1.169 albertel 2115: @instances = @{$dimension{$dim}{'instances'}};
1.76 albertel 2116: }
1.160 albertel 2117: my $shown_question_text;
1.76 albertel 2118: foreach my $instance (@instances) {
1.173 albertel 2119: $result .= &nested_parse(\$dimension{$dim}{$instance.'.text'},
2120: [@_]);
2121: $result .= &nested_parse(\$dimension{$dim}{'questiontext'},
2122: [@_],{'set_dim_id' => undef});
1.169 albertel 2123: my $task_status =
2124: $Apache::lonhomework::history{"resource.$version.0.status"};
1.173 albertel 2125: if ($task_status ne 'pass' && $task_status ne 'fail') {
1.76 albertel 2126:
1.173 albertel 2127: foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
2128: @{$dimension{$dim}{'criterias'}}) {
2129: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
2130: &Apache::lonxml::debug("$id is $type");
2131: if ($type eq 'dimension') {
2132: $result.=
2133: &nested_parse(\$dimension{$dim}{'criteria.'.$id},
2134: [@_],{'set_dim_id' => $id});
2135: }
2136: }
2137: } else {
1.89 albertel 2138: my $dim_status=$Apache::lonhomework::history{"resource.$version.0.$dim.status"};
1.76 albertel 2139: my $mandatory='Mandatory';
2140: if ($Apache::bridgetask::dimensionmandatory{$dim} eq 'N') {
2141: $mandatory='Optional';
2142: }
1.116 albertel 2143: my $dim_info="<div class='LC_$dim_status LC_question_grade'>\n";
1.76 albertel 2144: if ($dim_status eq 'pass') {
2145: $dim_info.='<h3>Question : you passed this '.$mandatory.' question</h3>';
1.54 albertel 2146: }
1.76 albertel 2147: if ($dim_status eq 'fail') {
2148: $dim_info.='<h3>Question : you did not pass this '.$mandatory.' question</h3>';
1.53 albertel 2149: }
1.76 albertel 2150: my $man_count=0;
2151: my $man_passed=0;
2152: my $opt_count=0;
2153: my $opt_passed=0;
1.169 albertel 2154: foreach my $id ( @{$dimension{$dim}{$instance.'.criterias'}},
2155: @{$dimension{$dim}{'criterias'}} ) {
2156: my $status = &get_criteria('status',$version,$dim,$id);
2157: if ($dimension{$dim}{'criteria.'.$id.'.mandatory'}
1.76 albertel 2158: eq 'N') {
2159: $opt_count++;
1.169 albertel 2160: if ($status eq 'pass') { $opt_passed++; }
1.76 albertel 2161: } else {
2162: $man_count++;
1.169 albertel 2163: if ($status eq 'pass') { $man_passed++; }
1.76 albertel 2164: }
1.22 albertel 2165: }
1.76 albertel 2166: if ($man_passed eq $man_count) { $man_passed='all'; }
1.151 albertel 2167:
1.169 albertel 2168: my $opt_req=$dimension{$dim}{$instance.'.optionalrequired'};
1.151 albertel 2169: if ($opt_req !~ /\S/) {
2170: $opt_req=
2171: &Apache::lonxml::get_param('OptionalRequired',
2172: $parstack,$safeeval);
2173: if ($opt_req !~ /\S/) { $opt_req = 0; }
2174: }
1.76 albertel 2175: $dim_info.="\n<p>".&mt('You passed [_1] of the [_2] mandatory components and [_3] of the [_4] optional components, of which you were required to pass [_5].',$man_passed,$man_count,$opt_passed,$opt_count,$opt_req)."</p>\n</div>";
2176:
2177: my $internal_location=&internal_location($dim);
2178: $result=~s/\Q$internal_location\E/$dim_info/;
2179:
1.169 albertel 2180: foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
2181: @{$dimension{$dim}{'criterias'}}) {
2182: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
1.171 albertel 2183: if ($type eq 'dimension') {
2184: $result.=$dimension{$id}{'result'};
2185: next;
2186: }
1.169 albertel 2187: my $status= &get_criteria('status', $version,$dim,$id);
2188: my $comment=&get_criteria('comment',$version,$dim,$id);
2189: my $mandatory=($dimension{$dim}{'criteria.'.$id.'.mandatory'} ne 'N');
1.76 albertel 2190: if ($mandatory) {
2191: $mandatory='Mandatory';
2192: } else {
2193: $mandatory='Optional';
2194: }
2195: if ($status eq 'fail') {
2196: } elsif ($status eq 'pass') {
2197: } else {
2198: &Apache::lonxml::error("Student viewing a graded bridgetask was shown a status of $status");
2199: }
2200: my $status_display=$status;
2201: $status_display=~s/^([a-z])/uc($1)/e;
1.116 albertel 2202: $result.=
2203: '<div class="LC_'.$status.' LC_criteria"><h4>'
2204: .$mandatory.' Criteria</h4><p>';
1.173 albertel 2205: $result.=
2206: &nested_parse(\$dimension{$dim}{'criteria.'.$id},
2207: [@_],{'set_dim_id' => $id});
1.116 albertel 2208: $result.='</p><p class="LC_grade">'.$status_display.'</p>';
1.169 albertel 2209: if ($comment) {
2210: $result.='<p class="LC_comment">'.
2211: &mt('Comment: [_1]',$comment).'</p>';
1.76 albertel 2212: }
2213: $result.='</div>';
1.22 albertel 2214: }
2215: }
2216: }
1.18 albertel 2217: } elsif ($target eq 'webgrade') {
1.47 albertel 2218: # in case of any side effects that we need
1.173 albertel 2219: &nested_parse(\$dimension{$dim}{'intro'},[@_]);
2220: &nested_parse(\$dimension{$dim}{$instance.'.text'},[@_]);
2221: $result.=
2222: &nested_parse(\$dimension{$dim}{'questiontext'},[@_],
2223: {'set_dim_id' => undef,
2224: 'delay_dim_results' => 1});
1.169 albertel 2225: foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
2226: @{$dimension{$dim}{'criterias'}} ) {
2227: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
1.171 albertel 2228: if ($type eq 'dimension') {
2229: # dimensional 'criteria' don't get assigned grades
1.173 albertel 2230: $result.=
2231: &nested_parse(\$dimension{$dim}{'criteria.'.$id},
2232: [@_],{'set_dim_id' => $id});
1.171 albertel 2233: next;
2234: }
1.169 albertel 2235:
1.151 albertel 2236: my $link=&link($id);
1.169 albertel 2237: my $status= &get_criteria('status',$version,$dim,$id);
1.120 albertel 2238: $result.='<div class="LC_GRADING_criteria" id="'.$link.'">'."\n".
1.136 albertel 2239: '<div class="LC_GRADING_criteriatext" id="next_'.$last_link.'">'."\n";
1.173 albertel 2240: $result.=
2241: &nested_parse(\$dimension{$dim}{'criteria.'.$id},[@_]);
2242:
1.111 albertel 2243: $result.='</div>'."\n".
1.120 albertel 2244: '<div class="LC_GRADING_grade">'."\n".
2245: '<label class="LC_GRADING_ungraded"><input type="radio" name="HWVAL_'.$link.'" value="ungraded" '.($status eq 'ungraded' || !$status ? 'checked="checked"':'').' />'.&mt('Ungraded').'</label>'."\n".
2246: '<label class="LC_GRADING_fail"><input type="radio" name="HWVAL_'.$link.'" value="fail" '.($status eq 'fail' ? 'checked="checked"':'').' />'.&mt('Fail').'</label>'."\n".
2247: '<label class="LC_GRADING_pass"><input type="radio" name="HWVAL_'.$link.'" value="pass" '.($status eq 'pass' ? 'checked="checked"':'').' />'.&mt('Pass').'</label>'."\n".
2248: '<label class="LC_GRADING_review"><input type="radio" name="HWVAL_'.$link.'" value="review" '.($status eq 'review' ? 'checked="checked"':'').' />'.&mt('Review').'</label>'."\n".
1.111 albertel 2249: '</div>'."\n".
1.120 albertel 2250: '<label class="LC_GRADING_comment">'.&mt('Additional Comment for Student')."\n".
1.169 albertel 2251: '<textarea class="LC_GRADING_comment_area" name="HWVAL_comment_'.$link.'">'.&HTML::Entities::encode(&get_criteria('comment',$version,$dim,$id),'<>"&').'</textarea>'."\n".
1.111 albertel 2252: '</label>'."\n".
1.120 albertel 2253: '<ul class="LC_GRADING_navbuttons">'."\n".
1.111 albertel 2254: '<li><a href="#'.$last_link.'">Prev</a></li>'."\n".
2255: '<li><a href="#next_'.$link.'">Next</a></li>'."\n".
2256: '</ul>'."\n".
2257: '</div>'."\n";
1.151 albertel 2258: $result.=&grading_history($version,$dim,$id);
1.18 albertel 2259: $last_link=$link;
2260: }
1.173 albertel 2261: if (&delay_result()) {
2262: &Apache::lonxml::debug(" for $dim stashing results into ".$dimension{$dim}{'nested'});
2263: $dimension{$dimension{$dim}{'nested'}}{'result'}.=$result;
1.171 albertel 2264: undef($result);
2265: }
1.22 albertel 2266: } elsif ($target eq 'grade' && $env{'form.webgrade'}) {
1.19 albertel 2267: my $optional_passed=0;
1.20 albertel 2268: my $mandatory_failed=0;
2269: my $ungraded=0;
2270: my $review=0;
1.153 albertel 2271:
1.173 albertel 2272: $result .= &nested_parse(\$dimension{$dim}{'intro'},[@_]);
2273: $result .= &nested_parse(\$dimension{$dim}{$instance.'.text'},
2274: [@_]);
2275: $result .= &nested_parse(\$dimension{$dim}{'questiontext'},
2276: [@_],{'set_dim_id' => undef});
1.160 albertel 2277:
1.169 albertel 2278: foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
2279: @{$dimension{$dim}{'criterias'}}) {
1.151 albertel 2280: my $link=&link($id);
1.169 albertel 2281:
2282: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
2283: if ($type eq 'criteria') {
2284: # dimensional 'criteria' don't get assigned grades
2285: $Apache::lonhomework::results{"resource.$version.0.$dim.$id.status"}=$env{'form.HWVAL_'.$link};
2286: $Apache::lonhomework::results{"resource.$version.0.$dim.$id.comment"}=$env{'form.HWVAL_comment_'.$link};
1.173 albertel 2287: } else {
2288: $result .=
2289: &nested_parse(\$dimension{$dim}{'criteria.'.$id},
2290: [@_],{'set_dim_id' => $id});
1.169 albertel 2291: }
2292: my $status= &get_criteria('status',$version,$dim,$id);
2293:
2294: my $mandatory=($dimension{$dim}{'criteria.'.$id.'.mandatory'} ne 'N');
1.20 albertel 2295: if ($status eq 'pass') {
2296: if (!$mandatory) { $optional_passed++; }
2297: } elsif ($status eq 'fail') {
2298: if ($mandatory) { $mandatory_failed++; }
1.21 albertel 2299: } elsif ($status eq 'review') {
2300: $review++;
1.20 albertel 2301: } elsif ($status eq 'ungraded') {
2302: $ungraded++;
1.21 albertel 2303: } else {
1.47 albertel 2304: $ungraded++;
1.19 albertel 2305: }
2306: }
1.151 albertel 2307: # FIXME optional required can apply to only <instance> right now...
1.169 albertel 2308: my $opt_req=$dimension{$dim}{$instance.'.optionalrequired'};
1.151 albertel 2309: if ($opt_req !~ /\S/) {
2310: $opt_req=
2311: &Apache::lonxml::get_param('OptionalRequired',
2312: $parstack,$safeeval);
2313: if ($opt_req !~ /\S/) { $opt_req = 0; }
2314: }
2315: if ($optional_passed < $opt_req) {
1.20 albertel 2316: $mandatory_failed++;
2317: }
1.169 albertel 2318: &Apache::lonxml::debug("all instance ".join(':',@{$dimension{$dim}{$instance.'.criterias'}})." results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
1.20 albertel 2319: if ($review) {
1.89 albertel 2320: $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
1.22 albertel 2321: 'review';
1.20 albertel 2322: } elsif ($ungraded) {
1.89 albertel 2323: $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
1.22 albertel 2324: 'ungraded';
1.20 albertel 2325: } elsif ($mandatory_failed) {
1.89 albertel 2326: $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
1.22 albertel 2327: 'fail';
1.20 albertel 2328: } else {
1.91 albertel 2329: $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
1.22 albertel 2330: 'pass';
1.20 albertel 2331: }
1.69 albertel 2332: } else {
2333: # any other targets no output
2334: undef($result);
1.13 albertel 2335: }
1.173 albertel 2336: &disable_dimension_parsing();
1.169 albertel 2337: pop(@Apache::bridgetask::dimension);
1.18 albertel 2338: return $result;
1.1 albertel 2339: }
1.162 albertel 2340:
2341: sub end_Setup {
2342: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
2343: my $result=&Apache::lonxml::endredirection();
2344: my $dim=&get_id($parstack,$safeeval);
2345: my $instance=&get_instance($dim);
2346: my $version=&get_version();
2347: if ($target eq 'web') {
2348: @Apache::scripttag::parser_env = @_;
1.169 albertel 2349: $result.=&Apache::scripttag::xmlparse($dimension{$dim}{'intro'});
1.162 albertel 2350: my @instances = $instance;
2351: if (&Apache::response::showallfoils()) {
1.169 albertel 2352: @instances = @{$dimension{$dim}{'instances'}};
1.162 albertel 2353: }
2354: foreach my $instance (@instances) {
2355: @Apache::scripttag::parser_env = @_;
1.169 albertel 2356: $result.=&Apache::scripttag::xmlparse($dimension{$dim}{$instance.'.text'});
1.162 albertel 2357: @Apache::scripttag::parser_env = @_;
1.169 albertel 2358: $result.=&Apache::scripttag::xmlparse($dimension{$dim}{'questiontext'});
1.162 albertel 2359: }
2360: } elsif ($target eq 'webgrade'
2361: || $target eq 'grade' && $env{'form.webgrade'}) {
2362: # in case of any side effects that we need
2363: @Apache::scripttag::parser_env = @_;
1.169 albertel 2364: &Apache::scripttag::xmlparse($dimension{$dim}{'intro'});
1.162 albertel 2365: @Apache::scripttag::parser_env = @_;
1.169 albertel 2366: &Apache::scripttag::xmlparse($dimension{$dim}{$instance.'.text'});
1.162 albertel 2367: @Apache::scripttag::parser_env = @_;
1.169 albertel 2368: &Apache::scripttag::xmlparse($dimension{$dim}{'questiontext'});
1.162 albertel 2369: } else {
2370: # any other targets no output
2371: undef($result);
2372: }
1.169 albertel 2373: pop(@Apache::bridgetask::dimension);
1.162 albertel 2374: return $result;
2375: }
1.1 albertel 2376: }
2377:
1.113 albertel 2378: sub grading_history {
1.151 albertel 2379: my ($version,$dim,$id) = @_;
1.113 albertel 2380: if (!&Apache::lonnet::allowed('mgq',$env{'request.course.id'})) {
2381: return '';
2382: }
2383: my ($result,$grader);
1.151 albertel 2384: my $scope="resource.$version.0.$dim.$id";
1.113 albertel 2385: foreach my $t (1..$Apache::lonhomework::history{'version'}) {
2386: if (exists($Apache::lonhomework::history{$t.':resource.0.regrader'})) {
2387: my ($gname,$gdom) =
1.138 albertel 2388: split(':',$Apache::lonhomework::history{$t.':resource.0.regrader'});
1.113 albertel 2389: my $fullname = &Apache::loncommon::plainname($gname,$gdom);
2390: $grader = &Apache::loncommon::aboutmewrapper($fullname,
2391: $gname,$gdom);
2392: }
2393: my $entry;
2394: if (exists($Apache::lonhomework::history{"$t:$scope.status"})) {
2395: $entry.="<tt>".$Apache::lonhomework::history{"$t:$scope.status"}.'</tt>';
2396: }
2397: if (exists($Apache::lonhomework::history{"$t:$scope.comment"})) {
2398: $entry.=' comment: "'.$Apache::lonhomework::history{"$t:$scope.comment"}.'"';
2399: }
2400: if ($entry) {
2401: $result.= "<li>$grader : $entry </li>";
2402: }
2403: }
2404: if ($result) {
1.120 albertel 2405: return '<ul class="LC_GRADING_pastgrading">'.$result.'</ul>';
1.113 albertel 2406: }
2407: return '';
2408: }
2409:
1.1 albertel 2410: sub start_IntroParagraph {
1.87 albertel 2411: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.1 albertel 2412: my $result;
1.168 albertel 2413: my $dim = &get_dim_id();
1.153 albertel 2414: if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
1.151 albertel 2415: if ($tagstack->[-2] eq 'Dimension' || $tagstack->[-2] eq 'Question' ) {
1.169 albertel 2416: $dimension{$dim}{'intro'}=
1.151 albertel 2417: &Apache::lonxml::get_all_text('/introparagraph',
2418: $parser,$style);
2419: } elsif ($tagstack->[-2] eq 'Task' && $target eq 'webgrade') {
1.127 albertel 2420: &Apache::lonxml::startredirection();
1.1 albertel 2421: }
1.47 albertel 2422:
1.1 albertel 2423: }
2424: return $result;
2425: }
2426:
2427: sub end_IntroParagraph {
1.127 albertel 2428: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.128 albertel 2429: if ($tagstack->[-2] eq 'Task' && $target eq 'webgrade') {
1.127 albertel 2430: my $result = &Apache::lonxml::endredirection();
2431: }
1.1 albertel 2432: }
2433:
2434: sub start_Instance {
2435: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.168 albertel 2436: my $dim = &get_dim_id();
2437: my $id = &get_id($parstack,$safeeval);
1.169 albertel 2438: push(@{$dimension{$dim}{'instances'}},$id);
1.168 albertel 2439: push(@{$Apache::bridgetask::instance{$dim}},$id);
1.19 albertel 2440: push(@Apache::bridgetask::instancelist,$id);
1.169 albertel 2441: $dimension{$dim}{$id.'.optionalrequired'}=
1.19 albertel 2442: &Apache::lonxml::get_param('OptionalRequired',$parstack,$safeeval);
1.75 albertel 2443: my $disabled = &Apache::lonxml::get_param('Disabled',$parstack,$safeeval);
2444: if (lc($disabled) eq 'yes') {
1.169 albertel 2445: $dimension{$dim}{$id.'.disabled'}='1';
1.75 albertel 2446: }
1.1 albertel 2447: return '';
2448: }
2449:
2450: sub end_Instance {
2451: }
2452:
2453: sub start_InstanceText {
1.87 albertel 2454: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.168 albertel 2455: my $dim = &get_dim_id();
2456: my $instance_id=$Apache::bridgetask::instance{$dim}[-1];
1.87 albertel 2457: my $text=&Apache::lonxml::get_all_text('/instancetext',$parser,$style);
1.153 albertel 2458: if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
1.169 albertel 2459: $dimension{$dim}{$instance_id.'.text'}=$text;
1.1 albertel 2460: }
2461: return '';
2462: }
2463:
2464: sub end_InstanceText {
2465: return '';
2466: }
2467:
2468: sub start_Criteria {
1.87 albertel 2469: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
2470: my $criteria=&Apache::lonxml::get_all_text('/criteria',$parser,$style);
1.21 albertel 2471: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
1.168 albertel 2472: my $dim = &get_dim_id();
1.19 albertel 2473: my $id=&get_id($parstack,$safeeval);
1.169 albertel 2474: &Apache::lonxml::debug("Criteria $id with $dim");
1.151 albertel 2475: if (&Apache::londefdef::is_inside_of($tagstack,'Instance')) {
1.168 albertel 2476: my $instance_id=$Apache::bridgetask::instance{$dim}[-1];
1.169 albertel 2477: $dimension{$dim}{"criteria.$instance_id.$id"}=$criteria;
2478: $dimension{$dim}{"criteria.$instance_id.$id.type"}='criteria';
2479: $dimension{$dim}{"criteria.$instance_id.$id.mandatory"}=
1.151 albertel 2480: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.169 albertel 2481: push(@{$dimension{$dim}{$instance_id.'.criterias'}},"$instance_id.$id");
1.151 albertel 2482: } else {
1.169 albertel 2483: $dimension{$dim}{'criteria.'.$id}=$criteria;
2484: $dimension{$dim}{'criteria.'.$id.'.type'}='criteria';
2485: $dimension{$dim}{'criteria.'.$id.'.mandatory'}=
1.151 albertel 2486: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.169 albertel 2487: push(@{$dimension{$dim}{'criterias'}},$id);
1.151 albertel 2488: }
1.1 albertel 2489: }
2490: return '';
2491: }
2492:
1.47 albertel 2493: sub end_Criteria {
2494: }
2495:
1.4 albertel 2496: sub proctor_validation_screen {
2497: my ($slot) = @_;
2498: my (undef,undef,$domain,$user) = &Apache::lonxml::whichuser();
1.5 albertel 2499: my $url=&Apache::lonnet::studentphoto($domain,$user,'jpg');
1.44 albertel 2500: my $name=&Apache::loncommon::plainname($user,$domain);
2501:
1.4 albertel 2502: my $msg;
1.11 albertel 2503: if ($env{'form.proctorpassword'}) {
1.4 albertel 2504: $msg='<p><font color="red">'.&mt("Failed to authenticate the proctor.")
2505: .'</font></p>';
2506: }
1.47 albertel 2507: if (!$env{'form.proctordomain'}) { $env{'form.proctordomain'}=$domain; }
1.4 albertel 2508: my $result= (<<ENDCHECKOUT);
2509: <h2>Proctor Validation</h2>
2510: <p>Your room's proctor needs to validate your access to this resource.</p>
2511: $msg
1.115 albertel 2512: <form name="checkout" method="post" action="$env{'request.uri'}">
1.4 albertel 2513: <input type="hidden" name="validate" value="yes" />
2514: <input type="hidden" name="submitted" value="yes" />
2515: <table>
1.44 albertel 2516: <tr><td>Proctor's Username:</td><td><input type="string" name="proctorname" value="$env{'form.proctorname'}" /></td></tr>
1.4 albertel 2517: <tr><td>Password:</td><td><input type="password" name="proctorpassword" value="" /></td></tr>
1.46 albertel 2518: <tr><td>Proctor's Domain:</td><td><input type="string" name="proctordomain" value="$env{'form.proctordomain'}" /></td></tr>
1.4 albertel 2519: </table>
2520: <input type="submit" name="checkoutbutton" value="Validate" /><br />
1.44 albertel 2521: <table border="1">
2522: <tr><td>
2523: <table>
2524: <tr><td colspan="2">Student who should be logged in is:</td></tr>
2525: <tr><td>Name:</td><td>$name</td></tr>
1.45 albertel 2526: <tr><td>Student ID:</td><td>$env{'environment.id'}</td></tr>
1.138 albertel 2527: <tr><td>Usename</td><td>$user:$domain</td></tr>
1.44 albertel 2528: <tr><td colspan="2"><img src="$url" /></td></tr>
2529: </table>
2530: </tr></td>
2531: </table>
1.4 albertel 2532: </form>
2533: ENDCHECKOUT
2534: return $result;
2535: }
2536:
1.1 albertel 2537: 1;
2538: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>