Annotation of loncom/homework/bridgetask.pm, revision 1.179
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # definition of tags that give a structure to a document
3: #
1.179 ! albertel 4: # $Id: bridgetask.pm,v 1.178 2006/06/23 22:32:39 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.178 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";
1.178 albertel 147: if (!defined($user) || !defined($domain)) {
1.174 albertel 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.179 ! albertel 533: &Apache::structuretags::init_problem_globals('Task');
1.16 albertel 534: if ($target ne 'webgrade') {
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.179 ! albertel 1224: &Apache::structuretags::reset_problem_globals('Task');
1.4 albertel 1225: undef($Apache::lonhomework::parsing_a_task);
1.1 albertel 1226: return $result;
1227: }
1228:
1.31 albertel 1229: sub move_between_queues {
1230: my ($src_queue,$dest_queue)=@_;
1.49 albertel 1231: my $cur_data;
1232: if ($src_queue ne 'none') {
1233: $cur_data=&get_queue_data($src_queue);
1234: if (!$cur_data) { return 'not_exist'; }
1235: } else {
1236: $cur_data = ['none'];
1237: }
1.148 albertel 1238: my $result=&add_to_queue($dest_queue,$cur_data);
1.31 albertel 1239: if ($result ne 'ok') {
1240: return $result;
1241: }
1242: &check_queue_unlock($src_queue);
1243: return &remove_from_queue($src_queue);
1.21 albertel 1244: }
1245:
1246: sub check_queue_unlock {
1.32 albertel 1247: my ($queue,$key,$allow_not_me)=@_;
1.49 albertel 1248: if ($queue eq 'none') { return 'ok'; }
1.30 albertel 1249: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
1.32 albertel 1250: if (!defined($key)) {
1.138 albertel 1251: $key="$symb\0queue\0$uname:$udom";
1.32 albertel 1252: }
1.30 albertel 1253: my $cnum=$env{'course.'.$cid.'.num'};
1254: my $cdom=$env{'course.'.$cid.'.domain'};
1.138 albertel 1255: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.30 albertel 1256: my $who=&queue_key_locked($queue,$key,$cdom,$cnum);
1257: if ($who eq $me) {
1.163 albertel 1258: &Apache::lonxml::debug("unlocking my own $who");
1.32 albertel 1259: return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
1260: } elsif ($allow_not_me) {
1.33 albertel 1261: &Apache::lonxml::debug("unlocking $who by $me");
1.32 albertel 1262: return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
1.30 albertel 1263: }
1.32 albertel 1264: return 'not_owner';
1.21 albertel 1265: }
1266:
1.88 albertel 1267: sub in_queue {
1268: my ($queue,$symb,$cdom,$cnum,$udom,$uname)=@_;
1269: if ($queue eq 'none') { return 0; }
1270: if (!defined($symb) || !defined($cdom) || !defined($cnum)
1271: || !defined($udom) || !defined($uname)) {
1272: ($symb,my $cid,$udom,$uname)=&Apache::lonxml::whichuser();
1273: $cnum=$env{'course.'.$cid.'.num'};
1274: $cdom=$env{'course.'.$cid.'.domain'};
1275: }
1276:
1277: my $key=&encode_queue_key($symb,$udom,$uname);
1278: my %results = &Apache::lonnet::get($queue,[$key],$cdom,$cnum);
1279:
1280: if (defined($results{$key})) {
1281: return 1;
1282: }
1283: return 0;
1284: }
1285:
1.21 albertel 1286: sub remove_from_queue {
1.86 albertel 1287: my ($queue,$symb,$cdom,$cnum,$udom,$uname)=@_;
1.49 albertel 1288: if ($queue eq 'none') { return 'ok'; }
1.86 albertel 1289: if (!defined($symb) || !defined($cdom) || !defined($cnum)
1290: || !defined($udom) || !defined($uname)) {
1291: ($symb,my $cid,$udom,$uname)=&Apache::lonxml::whichuser();
1292: $cnum=$env{'course.'.$cid.'.num'};
1293: $cdom=$env{'course.'.$cid.'.domain'};
1294: }
1.88 albertel 1295: if (!&in_queue($queue,$symb,$cdom,$cnum,$udom,$uname)) {
1296: return 'ok';
1297: }
1.86 albertel 1298: my $key=&encode_queue_key($symb,$udom,$uname);
1.27 albertel 1299: my @keys=($key,"$key\0locked");
1.31 albertel 1300: return &Apache::lonnet::del($queue,\@keys,$cdom,$cnum);
1.21 albertel 1301: }
1302:
1.16 albertel 1303: sub setup_env_for_other_user {
1304: my ($queue_key,$safeeval)=@_;
1305: my ($symb,$uname,$udom)=&decode_queue_key($queue_key);
1.30 albertel 1306: &Apache::lonxml::debug("setup_env for $queue_key");
1.16 albertel 1307: $env{'form.grade_symb'}=$symb;
1308: $env{'form.grade_domain'}=$udom;
1309: $env{'form.grade_username'}=$uname;
1310: $env{'form.grade_courseid'}=$env{'request.course.id'};
1311: &Apache::lonxml::initialize_rndseed($safeeval);
1312: }
1313:
1.31 albertel 1314: sub get_queue_data {
1.165 albertel 1315: my ($queue,$udom,$uname)=@_;
1316: my ($symb,$cid,$other_udom,$other_uname)=&Apache::lonxml::whichuser();
1317: if (!$uname || !$udom) {
1318: $uname=$other_uname;
1319: $udom =$other_udom;
1320: }
1.31 albertel 1321: my $cnum=$env{'course.'.$cid.'.num'};
1322: my $cdom=$env{'course.'.$cid.'.domain'};
1.138 albertel 1323: my $todo="$symb\0queue\0$uname:$udom";
1.31 albertel 1324: my ($key,$value)=&Apache::lonnet::get($queue,[$todo],$cdom,$cnum);
1325: if ($key eq $todo && ref($value)) {
1326: return $value;
1327: }
1328: return undef;
1329: }
1330:
1.84 albertel 1331:
1.49 albertel 1332: sub check_queue_for_key {
1.84 albertel 1333: my ($cdom,$cnum,$queue,$todo)=@_;
1334:
1.49 albertel 1335: my %results=
1336: &Apache::lonnet::get($queue,[$todo,"$todo\0locked"],$cdom,$cnum);
1337:
1338: if (exists($results{$todo}) && ref($results{$todo})) {
1339: if (defined($results{"$todo\0locked"})) {
1340: return 'locked';
1341: }
1.148 albertel 1342: if (my $slot=&slotted_access($results{$todo})) {
1.86 albertel 1343: my %slot_data=&Apache::lonnet::get_slot($slot);
1344: if ($slot_data{'endtime'} > time) {
1345: return 'in_progress';
1346: }
1.148 albertel 1347: } else {
1348: my ($symb) = &decode_queue_key($todo);
1349: my $due_date = &Apache::lonhomework::due_date('0',$symb);
1350: if ($due_date > time) {
1351: return 'in_progress';
1352: }
1.58 albertel 1353: }
1.49 albertel 1354: return 'enqueued';
1355: }
1356: return undef;
1357: }
1358:
1.14 albertel 1359: sub add_to_queue {
1.82 albertel 1360: my ($queue,$user_data)=@_;
1.49 albertel 1361: if ($queue eq 'none') { return 'ok'; }
1.14 albertel 1362: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
1.82 albertel 1363: if (!$cid || $env{'request.state'} eq 'construct') {
1364: return 'no_queue';
1365: }
1.14 albertel 1366: my $cnum=$env{'course.'.$cid.'.num'};
1367: my $cdom=$env{'course.'.$cid.'.domain'};
1368: my %data;
1.138 albertel 1369: $data{"$symb\0queue\0$uname:$udom"}=$user_data;
1.83 albertel 1370: return &Apache::lonnet::cput($queue,\%data,$cdom,$cnum);
1.14 albertel 1371: }
1372:
1.156 albertel 1373: sub get_limited_classlist {
1374: my ($sections) = @_;
1375:
1376: my $classlist = &Apache::loncoursedata::get_classlist();
1.157 albertel 1377: foreach my $student (keys(%$classlist)) {
1378: if ( $classlist->{$student}[&Apache::loncoursedata::CL_STATUS()]
1379: ne 'Active') {
1380: delete($classlist->{$student});
1381: }
1382: }
1.156 albertel 1383:
1.157 albertel 1384: if (ref($sections) && !grep('all',@{ $sections })) {
1.156 albertel 1385: foreach my $student (keys(%$classlist)) {
1386: my $section =
1387: $classlist->{$student}[&Apache::loncoursedata::CL_SECTION()];
1388: if (! grep($section,@{ $sections })) {
1389: delete($classlist->{$student});
1390: }
1391: }
1392: }
1393: return $classlist;
1394: }
1395:
1396:
1.14 albertel 1397: sub show_queue {
1.32 albertel 1398: my ($queue,$with_selects)=@_;
1.14 albertel 1399: my $result;
1400: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
1401: my $cnum=$env{'course.'.$cid.'.num'};
1402: my $cdom=$env{'course.'.$cid.'.domain'};
1.59 albertel 1403:
1404: my @chosen_sections=
1405: &Apache::loncommon::get_env_multiple('form.chosensections');
1.156 albertel 1406:
1407: my $classlist = &get_limited_classlist(\@chosen_sections);
1408:
1.63 albertel 1409: if (!(grep(/^all$/,@chosen_sections))) {
1410: $result.='<p> Showing only sections <tt>'.join(', ',@chosen_sections).
1411: '</tt>.</p> '."\n";
1412: }
1.59 albertel 1413:
1.156 albertel 1414: my ($view,$view_section);
1415: my $scope = $env{'request.course.id'};
1416: if (!($view=&Apache::lonnet::allowed('vgr',$scope))) {
1417: $scope .= '/'.$env{'request.course.sec'};
1418: if ( $view = &Apache::lonnet::allowed('vgr',$scope)) {
1419: $view_section=$env{'request.course.sec'};
1420: } else {
1421: undef($view);
1422: }
1423: }
1424:
1.16 albertel 1425: my $regexp="^$symb\0";
1.30 albertel 1426: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.31 albertel 1427: my ($tmp)=%queue;
1428: if ($tmp=~/^error: 2 /) {
1.159 albertel 1429: return "\n<h3>Current Queue - $queue</h3>".
1430: &Apache::loncommon::start_data_table().
1431: &Apache::loncommon::start_data_table_row().
1432: '<td>'.&mt('Empty').'</td>'.
1433: &Apache::loncommon::end_data_table_row().
1434: &Apache::loncommon::end_data_table();
1.31 albertel 1435: }
1.103 albertel 1436: my $title=&Apache::lonnet::gettitle($symb);
1.159 albertel 1437: $result.="\n<h3>Current Queue - $title $queue </h3>".
1438: &Apache::loncommon::start_data_table().
1439: &Apache::loncommon::start_data_table_header_row();
1.103 albertel 1440: if ($with_selects) { $result.="<th>Status</th><th></th>"; }
1.159 albertel 1441: $result.="<th>user</th><th>data</th>".
1442: &Apache::loncommon::end_data_table_header_row();
1.14 albertel 1443: foreach my $key (sort(keys(%queue))) {
1.59 albertel 1444: my ($symb,$uname,$udom) = &decode_queue_key($key);
1445: if (!defined($classlist->{$uname.':'.$udom})) { next; }
1.156 albertel 1446:
1447: my $section = $classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_SECTION()];
1448:
1449: my $can_view=1;
1450: if (!$view
1451: || ($view_section && !$section)
1452: || ($view_section && $section && ($view_section ne $section))) {
1453: $can_view=0;
1454: }
1455:
1.32 albertel 1456: if ($key=~/locked$/ && !$with_selects) {
1.159 albertel 1457: $result.= &Apache::loncommon::start_data_table_row().
1458: "<td>$uname</td>";
1.103 albertel 1459: $result.='<td>'.$queue{$key}.'</td></tr>';
1.32 albertel 1460: } elsif ($key=~/timestamp$/ && !$with_selects) {
1.159 albertel 1461: $result.=&Apache::loncommon::start_data_table_row()."<td></td>";
1.103 albertel 1462: $result.='<td>'.
1.16 albertel 1463: &Apache::lonlocal::locallocaltime($queue{$key})."</td></tr>";
1.32 albertel 1464: } elsif ($key!~/(timestamp|locked)$/) {
1.159 albertel 1465: $result.= &Apache::loncommon::start_data_table_row();
1.148 albertel 1466: my ($end_time,$slot_text);
1467: if (my $slot=&slotted_access($queue{$key})) {
1468: my %slot_data=&Apache::lonnet::get_slot($slot);
1469: $end_time = $slot_data{'endtime'};
1470: $slot_text = &mt('Slot: [_1]',$slot);
1471: } else {
1472: $end_time = &Apache::lonhomework::due_date('0',$symb);
1473: $slot_text = '';
1474: }
1.32 albertel 1475: if ($with_selects) {
1.158 www 1476: my $ekey=&escape($key);
1.103 albertel 1477: my ($action,$description,$status)=('select',&mt('Select'));
1.32 albertel 1478: if (exists($queue{"$key\0locked"})) {
1.138 albertel 1479: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.103 albertel 1480: $status=&mt('Locked by <tt>[_1]</tt>',$queue{"$key\0locked"});
1.32 albertel 1481: if ($me eq $queue{"$key\0locked"}) {
1482: ($action,$description)=('resume',&mt('Resume'));
1483: } else {
1484: ($action,$description)=('unlock',&mt('Unlock'));
1485: }
1486: }
1.62 albertel 1487: my $seclist;
1488: foreach my $sec (@chosen_sections) {
1489: $seclist.='<input type="hidden" name="chosensections"
1490: value="'.$sec.'" />';
1491: }
1.156 albertel 1492: if ($can_view && ($end_time ne '' && time > $end_time)) {
1.35 albertel 1493: $result.=(<<FORM);
1.103 albertel 1494: <td>$status</td>
1.32 albertel 1495: <td>
1.115 albertel 1496: <form style="display: inline" method="post">
1.32 albertel 1497: <input type="hidden" name="gradingkey" value="$ekey" />
1498: <input type="hidden" name="queue" value="$queue" />
1499: <input type="hidden" name="gradingaction" value="$action" />
1500: <input type="hidden" name="webgrade" value="no" />
1.33 albertel 1501: <input type="hidden" name="queuemode" value="selected" />
1.32 albertel 1502: <input type="submit" name="submit" value="$description" />
1.62 albertel 1503: $seclist
1.32 albertel 1504: </form>
1505: </td>
1506: FORM
1.156 albertel 1507: } elsif (!$can_view && ($end_time ne '' && time > $end_time)) {
1508: $result.='<td>'.&mt("Not gradable").'</td><td> </td>'
1.35 albertel 1509: } else {
1.148 albertel 1510: $result.='<td>'.&mt("In Progress").'</td><td> </td>'
1.35 albertel 1511: }
1.32 albertel 1512: }
1.156 albertel 1513: $result.= "<td>".$classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_FULLNAME()].
1.138 albertel 1514: " <tt>($uname:$udom)</tt> </td>";
1.148 albertel 1515: $result.='<td>'.$slot_text.' End time: '.
1516: &Apache::lonlocal::locallocaltime($end_time).
1.159 albertel 1517: "</td>".&Apache::loncommon::end_data_table_row();
1.16 albertel 1518: }
1.14 albertel 1519: }
1.159 albertel 1520: $result.= &Apache::loncommon::end_data_table()."<hr />\n";
1.14 albertel 1521: return $result;
1522: }
1523:
1.34 albertel 1524: sub get_queue_counts {
1525: my ($queue)=@_;
1526: my $result;
1527: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
1528: my $cnum=$env{'course.'.$cid.'.num'};
1529: my $cdom=$env{'course.'.$cid.'.domain'};
1.156 albertel 1530:
1.157 albertel 1531: my $classlist=&get_limited_classlist();
1.156 albertel 1532:
1.34 albertel 1533: my $regexp="^$symb\0";
1534: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1535: my ($tmp)=%queue;
1536: if ($tmp=~/^error: 2 /) {
1537: return (0,0,0);
1538: }
1539: my ($entries,$ready_to_grade,$locks)=(0,0,0);
1.96 albertel 1540: my %slot_cache;
1.34 albertel 1541: foreach my $key (sort(keys(%queue))) {
1.156 albertel 1542: my ($symb,$uname,$udom) = &decode_queue_key($key);
1543: if (!defined($classlist->{$uname.':'.$udom})) { next; }
1544:
1.34 albertel 1545: if ($key=~/locked$/) {
1546: $locks++;
1547: } elsif ($key=~/timestamp$/) {
1548: #ignore
1549: } elsif ($key!~/(timestamp|locked)$/) {
1550: $entries++;
1.148 albertel 1551: if (my $slot=&slotted_access($queue{$key})) {
1552: if (!exists($slot_cache{$slot})) {
1553: my %slot_data=&Apache::lonnet::get_slot($slot);
1554: $slot_cache{$slot} = \%slot_data;
1555: }
1556: if (time > $slot_cache{$slot}{'endtime'}) {
1557: $ready_to_grade++;
1558: }
1559: } else {
1560: my $due_date = &Apache::lonhomework::due_date('0',$symb);
1561: if ($due_date ne '' && time > $due_date) {
1562: $ready_to_grade++;
1563: }
1.34 albertel 1564: }
1565: }
1566: }
1567: return ($entries,$ready_to_grade,$locks);
1568: }
1569:
1.49 albertel 1570: sub encode_queue_key {
1571: my ($symb,$udom,$uname)=@_;
1.138 albertel 1572: return "$symb\0queue\0$uname:$udom";
1.49 albertel 1573: }
1574:
1.14 albertel 1575: sub decode_queue_key {
1576: my ($key)=@_;
1577: my ($symb,undef,$user) = split("\0",$key);
1.138 albertel 1578: my ($uname,$udom) = split(':',$user);
1.14 albertel 1579: return ($symb,$uname,$udom);
1580: }
1581:
1582: sub queue_key_locked {
1.30 albertel 1583: my ($queue,$key,$cdom,$cnum)=@_;
1.33 albertel 1584: if (!defined($cdom) || !defined($cnum)) {
1585: my (undef,$cid)=&Apache::lonxml::whichuser();
1586: $cnum=$env{'course.'.$cid.'.num'};
1587: $cdom=$env{'course.'.$cid.'.domain'};
1588: }
1.14 albertel 1589: my ($key_locked,$value)=
1.30 albertel 1590: &Apache::lonnet::get($queue,["$key\0locked"],$cdom,$cnum);
1.14 albertel 1591: if ($key_locked eq "$key\0locked") {
1592: return $value;
1593: }
1594: return undef;
1595: }
1596:
1.148 albertel 1597: sub slotted_access {
1598: my ($queue_entry) = @_;
1599: if (ref($queue_entry) eq 'ARRAY') {
1600: if (defined($queue_entry->[0])) {
1601: return $queue_entry->[0];
1602: }
1603: return undef;
1604: } elsif (ref($queue_entry) eq 'HASH') {
1605: if (defined($queue_entry->{'slot'})) {
1606: return $queue_entry->{'slot'};
1607: }
1608: return undef;
1609: }
1610: return undef;
1611: }
1612:
1.14 albertel 1613: sub pick_from_queue_data {
1.156 albertel 1614: my ($queue,$check_section,$queuedata,$cdom,$cnum,$classlist)=@_;
1.98 albertel 1615: my @possible; # will hold queue entries that are valid to be selected
1.30 albertel 1616: foreach my $key (keys(%$queuedata)) {
1.68 albertel 1617: if ($key =~ /\0locked$/) { next; }
1618: if ($key =~ /\0timestamp$/) { next; }
1.156 albertel 1619:
1.14 albertel 1620: my ($symb,$uname,$udom)=&decode_queue_key($key);
1.156 albertel 1621: if (!defined($classlist->{$uname.':'.$udom})) { next; }
1622:
1.14 albertel 1623: if ($check_section) {
1.156 albertel 1624: my $section =
1625: $classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_SECTION()];
1.17 albertel 1626: if ($section eq $check_section) {
1.33 albertel 1627: &Apache::lonxml::debug("my sec");
1.15 albertel 1628: next;
1629: }
1.14 albertel 1630: }
1.148 albertel 1631: my $end_time;
1632: if (my $slot=&slotted_access($queuedata->{$key})) {
1.154 albertel 1633: &Apache::lonxml::debug("looking at slot $slot");
1.148 albertel 1634: my %slot_data=&Apache::lonnet::get_slot($slot);
1635: if ($slot_data{'endtime'} < time) {
1636: $end_time = $slot_data{'endtime'};
1.154 albertel 1637: } else {
1638: &Apache::lonxml::debug("not time ".$slot_data{'endtime'});
1639: next;
1.148 albertel 1640: }
1641: } else {
1642: my $due_date = &Apache::lonhomework::due_date('0',$symb);
1.154 albertel 1643: if ($due_date < time) {
1.148 albertel 1644: $end_time = $due_date;
1.154 albertel 1645: } else {
1646: &Apache::lonxml::debug("not time $due_date");
1647: next;
1.148 albertel 1648: }
1649: }
1650:
1.98 albertel 1651: if (exists($queuedata->{"$key\0locked"})) {
1.33 albertel 1652: &Apache::lonxml::debug("someone already has um.");
1.15 albertel 1653: next;
1654: }
1.148 albertel 1655: push(@possible,[$key,$end_time]);
1.98 albertel 1656: }
1657: if (@possible) {
1658: # sort entries in order by slot end time
1659: @possible = sort { $a->[1] <=> $b->[1] } @possible;
1.137 albertel 1660: # pick one of the entries in the top 10% in small queues and one
1661: # of the first ten entries in large queues
1.139 albertel 1662: #my $ten_percent = int($#possible * 0.1);
1663: #if ($ten_percent < 1 ) { $ten_percent = 1; }
1664: #if ($ten_percent > 10) { $ten_percent = 10; }
1665: #my $max=($#possible < $ten_percent) ? $#possible : $ten_percent;
1.137 albertel 1666:
1.139 albertel 1667: #return $possible[int(rand($max))][0];
1668: return $possible[0][0];
1.14 albertel 1669: }
1670: return undef;
1671: }
1672:
1.15 albertel 1673: sub find_mid_grade {
1.30 albertel 1674: my ($queue,$symb,$cdom,$cnum)=@_;
1.158 www 1675: my $todo=&unescape($env{'form.gradingkey'});
1.138 albertel 1676: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.15 albertel 1677: if ($todo) {
1.30 albertel 1678: my $who=&queue_key_locked($queue,$todo,$cdom,$cnum);
1.15 albertel 1679: if ($who eq $me) { return $todo; }
1680: }
1681: my $regexp="^$symb\0.*\0locked\$";
1.30 albertel 1682: my %locks=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.15 albertel 1683: foreach my $key (keys(%locks)) {
1684: my $who=$locks{$key};
1685: if ($who eq $me) {
1686: $todo=$key;
1687: $todo=~s/\0locked$//;
1688: return $todo;
1689: }
1690: }
1691: return undef;
1692: }
1693:
1.32 albertel 1694: sub lock_key {
1695: my ($queue,$todo)=@_;
1.138 albertel 1696: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.32 albertel 1697: my (undef,$cid)=&Apache::lonxml::whichuser();
1698: my $cnum=$env{'course.'.$cid.'.num'};
1699: my $cdom=$env{'course.'.$cid.'.domain'};
1700: my $success=&Apache::lonnet::newput($queue,{"$todo\0locked"=> $me},
1701: $cdom,$cnum);
1.33 albertel 1702: &Apache::lonxml::debug("success $success $todo");
1.32 albertel 1703: if ($success eq 'ok') {
1704: return 1;
1705: }
1706: return 0;
1707: }
1708:
1.86 albertel 1709: sub get_queue_symb_status {
1.85 albertel 1710: my ($queue,$symb,$cdom,$cnum) = @_;
1711: if (!defined($cdom) || !defined($cnum)) {
1712: my (undef,$cid)=&Apache::lonxml::whichuser();
1713: $cnum=$env{'course.'.$cid.'.num'};
1714: $cdom=$env{'course.'.$cid.'.domain'};
1715: }
1.157 albertel 1716: my $classlist=&get_limited_classlist();
1.156 albertel 1717:
1.85 albertel 1718: my $regexp="^$symb\0";
1719: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1720: my ($tmp)=%queue;
1721: if ($tmp=~/^error: 2 /) { return; }
1722: my @users;
1723: foreach my $key (sort(keys(%queue))) {
1724: next if ($key=~/locked$/);
1725: next if ($key=~/timestamp$/);
1726: my ($symb,$uname,$udom) = &decode_queue_key($key);
1.156 albertel 1727: next if (!defined($classlist->{$uname.':'.$udom}));
1.85 albertel 1728: push(@users,"$uname:$udom");
1729: }
1730: return @users;
1731: }
1732:
1.14 albertel 1733: sub get_from_queue {
1.30 albertel 1734: my ($queue)=@_;
1.14 albertel 1735: my $result;
1736: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
1737: my $cnum=$env{'course.'.$cid.'.num'};
1738: my $cdom=$env{'course.'.$cid.'.domain'};
1.32 albertel 1739: my $todo=&find_mid_grade($queue,$symb,$cdom,$cnum);
1.33 albertel 1740: &Apache::lonxml::debug("found ".join(':',&decode_queue_key($todo)));
1.16 albertel 1741: if ($todo) { return $todo; }
1.95 albertel 1742: my $attempts=0;
1.156 albertel 1743:
1.157 albertel 1744: my $classlist=&get_limited_classlist();
1.156 albertel 1745:
1.14 albertel 1746: while (1) {
1.95 albertel 1747: if ($attempts > 2) {
1748: # tried twice to get a queue entry, giving up
1749: return (undef,'unable');
1750: }
1.14 albertel 1751: my $starttime=time;
1.83 albertel 1752: &Apache::lonnet::cput($queue,{"$symb\0timestamp"=>$starttime},
1753: $cdom,$cnum);
1.33 albertel 1754: &Apache::lonxml::debug("$starttime");
1.14 albertel 1755: my $regexp="^$symb\0queue\0";
1.156 albertel 1756: #my $range= ($attempts < 1 ) ? '0-100' : '0-400';
1.97 albertel 1757:
1.98 albertel 1758: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.33 albertel 1759: #make a pass looking for a user _not_ in my section
1.14 albertel 1760: if ($env{'request.course.sec'}) {
1.33 albertel 1761: &Apache::lonxml::debug("sce");
1.30 albertel 1762: $todo=&pick_from_queue_data($queue,$env{'request.course.sec'},
1.156 albertel 1763: \%queue,$cdom,$cnum,$classlist);
1.33 albertel 1764: &Apache::lonxml::debug("sce $todo");
1.14 albertel 1765: }
1.33 albertel 1766: # no one _not_ in our section so look for any user that is
1767: # ready for grading
1.14 albertel 1768: if (!$todo) {
1.33 albertel 1769: &Apache::lonxml::debug("no sce");
1.156 albertel 1770: $todo=&pick_from_queue_data($queue,undef,\%queue,$cdom,$cnum,
1771: $classlist);
1.33 albertel 1772: &Apache::lonxml::debug("no sce $todo");
1.14 albertel 1773: }
1774: # no user to grade
1775: if (!$todo) { last; }
1.33 albertel 1776: &Apache::lonxml::debug("got $todo");
1.14 albertel 1777: # otherwise found someone so lets try to lock them
1.32 albertel 1778: # unless someone else already picked them
1.95 albertel 1779: if (!&lock_key($queue,$todo)) {
1780: $attempts++;
1781: next;
1782: }
1.14 albertel 1783: my (undef,$endtime)=
1.30 albertel 1784: &Apache::lonnet::get($queue,["$symb\0timestamp"],
1.14 albertel 1785: $cdom,$cnum);
1.33 albertel 1786: &Apache::lonxml::debug("emd $endtime");
1.14 albertel 1787: # someone else already modified the queue,
1788: # perhaps our picked user wass already fully graded between
1789: # when we picked him and when we locked his record? so lets
1790: # double check.
1791: if ($endtime != $starttime) {
1792: my ($key,$value)=
1.30 albertel 1793: &Apache::lonnet::get($queue,["$todo"],
1.14 albertel 1794: $cdom,$cnum);
1.33 albertel 1795: &Apache::lonxml::debug("check $key .. $value");
1.14 albertel 1796: if ($key eq $todo && ref($value)) {
1797: } else {
1.30 albertel 1798: &Apache::lonnet::del($queue,["$todo\0locked"],
1.14 albertel 1799: $cdom,$cnum);
1.33 albertel 1800: &Apache::lonxml::debug("del");
1.95 albertel 1801: $attempts++;
1.14 albertel 1802: next;
1803: }
1804: }
1.33 albertel 1805: &Apache::lonxml::debug("last $todo");
1.14 albertel 1806: last;
1807: }
1808: return $todo;
1809: }
1810:
1.49 albertel 1811: sub select_user {
1812: my ($symb,$cid)=&Apache::lonxml::whichuser();
1813:
1.59 albertel 1814: my @chosen_sections=
1815: &Apache::loncommon::get_env_multiple('form.chosensections');
1.156 albertel 1816:
1817: my $classlist = &get_limited_classlist(\@chosen_sections);
1.63 albertel 1818:
1819: my $result;
1820: if (!(grep(/^all$/,@chosen_sections))) {
1821: $result.='<p> Showing only sections <tt>'.join(', ',@chosen_sections).
1822: '</tt>.</p> '."\n";
1823: }
1.159 albertel 1824: $result.=&Apache::loncommon::start_data_table();
1.49 albertel 1825:
1.156 albertel 1826: foreach my $student (sort {lc($classlist->{$a}[&Apache::loncoursedata::CL_FULLNAME()]) cmp lc($classlist->{$b}[&Apache::loncoursedata::CL_FULLNAME()]) } (keys(%$classlist))) {
1.49 albertel 1827: my ($uname,$udom) = split(/:/,$student);
1.59 albertel 1828:
1.84 albertel 1829: my $cnum=$env{'course.'.$cid.'.num'};
1830: my $cdom=$env{'course.'.$cid.'.domain'};
1.88 albertel 1831: my %status = &get_student_status($symb,$cdom,$cnum,$udom,$uname,
1832: 'Task');
1.49 albertel 1833: my $queue = 'none';
1.58 albertel 1834: my $cannot_grade;
1835: if ($status{'reviewqueue'} =~ /^(in_progress|enqueue)$/) {
1.49 albertel 1836: $queue = 'reviewqueue';
1.58 albertel 1837: if ($status{'reviewqueue'} eq 'in_progress') {
1838: $cannot_grade=1;
1839: }
1840: } elsif ($status{'gradingqueue'} =~ /^(in_progress|enqueue)$/) {
1.49 albertel 1841: $queue = 'gradingqueue';
1.58 albertel 1842: if ($status{'gradingqueue'} eq 'in_progress') {
1843: $cannot_grade=1;
1844: }
1.49 albertel 1845: }
1846: my $todo =
1.158 www 1847: &escape(&encode_queue_key($symb,$udom,$uname));
1.58 albertel 1848: if ($cannot_grade) {
1.159 albertel 1849: $result.=&Apache::loncommon::start_data_table_row().
1850: '<td> </td><td>'.$classlist->{$student}[&Apache::loncoursedata::CL_FULLNAME()].
1.58 albertel 1851: '</td><td>';
1852: } else {
1.62 albertel 1853: my $seclist;
1854: foreach my $sec (@chosen_sections) {
1855: $seclist.='<input type="hidden" name="chosensections"
1856: value="'.$sec.'" />';
1857: }
1.159 albertel 1858: $result.=&Apache::loncommon::start_data_table_row();
1.58 albertel 1859: $result.=<<RESULT;
1.49 albertel 1860: <td>
1.115 albertel 1861: <form style="display: inline" method="post">
1.49 albertel 1862: <input type="hidden" name="gradingkey" value="$todo" />
1863: <input type="hidden" name="queue" value="$queue" />
1864: <input type="hidden" name="webgrade" value="no" />
1.52 albertel 1865: <input type="hidden" name="regrade" value="yes" />
1.62 albertel 1866: <input type="submit" name="submit" value="Regrade" />
1867: $seclist
1.49 albertel 1868: </form>
1.155 albertel 1869: <td>$classlist->{$student}[&Apache::loncoursedata::CL_FULLNAME()] <tt>($student)</tt></td>
1.49 albertel 1870: <td>
1871: RESULT
1.58 albertel 1872: }
1.49 albertel 1873: if ($status{'status'} eq 'pass') {
1874: $result .= '<font color="green">'.&mt('Passed').'</font>';
1875: } elsif ($status{'status'} eq 'fail') {
1876: $result .= '<font color="red">'.&mt('Failed').'</font>';
1877: } elsif ($status{'status'} eq 'review') {
1878: $result .= '<font color="blue">'.&mt('Under Review').'</font>';
1879: } elsif ($status{'status'} eq 'ungraded') {
1880: $result .= &mt('Ungraded');
1881: } elsif ($status{'status'} ne '') {
1882: $result .= '<font color="orange">'.&mt('Unknown Status').'</font>';
1883: } else {
1884: $result.=" ";
1885: }
1886: if ($status{'version'}) {
1887: $result .= ' '.&mt('Version').' '.$status{'version'};
1888: }
1.101 albertel 1889: if ($status{'grader'}) {
1890: $result .= ' '.&mt('(Graded by [_1])',$status{'grader'}).' ';
1891: }
1.49 albertel 1892: $result.= '</td><td>';
1893: if ($status{'reviewqueue'} eq 'enqueued') {
1894: $result .= &mt('Awaiting Review');
1895: } elsif ($status{'reviewqueue'} eq 'locked') {
1896: $result .= &mt('Under Review');
1.58 albertel 1897: } elsif ($status{'reviewqueue'} eq 'in_progress') {
1898: $result .= &mt('Still being worked on.');
1.49 albertel 1899: } elsif ($status{'gradingqueue'} eq 'enqueued') {
1900: $result .= &mt('Awaiting Grading');
1901: } elsif ($status{'gradingqueue'} eq 'locked') {
1902: $result .= &mt('Being Graded');
1.58 albertel 1903: } elsif ($status{'gradingqueue'} eq 'in_progress') {
1904: $result .= &mt('Still being worked on.');
1.49 albertel 1905: } else {
1906: $result.=" ";
1907: }
1.159 albertel 1908: $result.= '</td>'.&Apache::loncommon::end_data_table_row();
1.49 albertel 1909: }
1.159 albertel 1910: $result.=&Apache::loncommon::end_data_table();
1.49 albertel 1911: return $result;
1912: }
1913:
1914: sub get_student_status {
1.86 albertel 1915: my ($symb,$cdom,$cnum,$udom,$uname,$type)=@_;
1916:
1917: my %status;
1918:
1919: if ($type eq 'Task') {
1920: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
1.49 albertel 1921: $udom,$uname);
1.89 albertel 1922: $status{'status'}=$record{'resource.0.status'};
1923: $status{'version'}=$record{'resource.0.version'};
1924: $status{'grader'}=$record{'resource.0.regrader'};
1.86 albertel 1925: }
1926: $status{'reviewqueue'}=
1927: &check_queue_for_key($cdom,$cnum,'reviewqueue',
1928: &encode_queue_key($symb,$udom,$uname));
1929: $status{'gradingqueue'}=
1930: &check_queue_for_key($cdom,$cnum,'gradingqueue',
1931: &encode_queue_key($symb,$udom,$uname));
1.49 albertel 1932: return %status;
1933: }
1934:
1.1 albertel 1935: sub start_ClosingParagraph {
1936: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1937: my $result;
1938: if ($target eq 'web') {
1.13 albertel 1939: } elsif ($target eq 'webgrade') {
1940: &Apache::lonxml::startredirection();
1.1 albertel 1941: }
1942: return $result;
1943: }
1944:
1945: sub end_ClosingParagraph {
1946: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1947: my $result;
1948: if ($target eq 'web') {
1.13 albertel 1949: } elsif ($target eq 'webgrade') {
1950: &Apache::lonxml::endredirection();
1.1 albertel 1951: }
1952: return $result;
1953: }
1954:
1.168 albertel 1955: sub get_dim_id {
1956: return $Apache::bridgetask::dimension[-1];
1957: }
1958:
1.19 albertel 1959: sub get_id {
1960: my ($parstack,$safeeval)=@_;
1961: my $id=&Apache::lonxml::get_param('id',$parstack,$safeeval);
1962: if (!$id) { $id=$Apache::lonxml::curdepth; }
1963: return $id;
1964: }
1965:
1.162 albertel 1966: sub start_Setup {
1967: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.168 albertel 1968: #undef(%dimension);
1969: my $dim = &get_id($parstack,$safeeval);
1970: push(@Apache::bridgetask::dimension,$dim);
1.162 albertel 1971: &Apache::lonxml::startredirection();
1.168 albertel 1972: return &internal_location($dim);
1.162 albertel 1973: }
1.173 albertel 1974:
1975: {
1976: my @allowed;
1977: sub enable_dimension_parsing {
1978: my ($id) = @_;
1979: push(@allowed,$id);
1980: }
1981: sub disable_dimension_parsing {
1982: pop(@allowed);
1983: }
1984: sub skip_dimension_parsing {
1985: my ($check) = @_;
1986: if (!@allowed) { return 0;}
1987: # if unspecified allow any id
1988: if ($allowed[-1] eq undef) { return 0;}
1989:
1990: return ($check ne $allowed[-1]);
1991: }
1992: }
1993:
1.151 albertel 1994: sub start_Question { return &start_Dimension(@_); }
1.1 albertel 1995: sub start_Dimension {
1.173 albertel 1996: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.168 albertel 1997: my $dim = &get_id($parstack,$safeeval);
1998: my $previous_dim;
1999: if (@Apache::bridgetask::dimension) {
2000: $previous_dim = $Apache::bridgetask::dimension[-1];
2001: push(@{$Apache::bridgetask::dimension{$previous_dim}{'contains'}},
2002: $dim);
1.173 albertel 2003: if(&skip_dimension_parsing($dim)) {
2004: $dimension{$previous_dim}{'criteria.'.$dim} =
2005: $token->[4]
2006: .&Apache::lonxml::get_all_text('/'.$tagstack->[-1],$parser,
2007: $style)
2008: .'</'.$tagstack->[-1].'>';
2009: }
1.169 albertel 2010: $dimension{$previous_dim}{'criteria.'.$dim.'.type'}='dimension';
2011: $dimension{$previous_dim}{'criteria.'.$dim.'.mandatory'}=
2012: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
2013: push(@{$dimension{$previous_dim}{'criterias'}},$dim);
1.171 albertel 2014: $dimension{$dim}{'nested'}=$previous_dim;
1.172 albertel 2015: &Apache::lonxml::debug("adding $dim as criteria to $previous_dim");
1.168 albertel 2016: } else {
2017: $Apache::bridgetask::top_dimensionlist{$dim}{'manadatory'}=
2018: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
2019: }
2020: push(@Apache::bridgetask::dimension,$dim);
1.54 albertel 2021: &Apache::lonxml::startredirection();
1.173 albertel 2022: &enable_dimension_parsing($dim);
1.168 albertel 2023: return &internal_location($dim);
1.1 albertel 2024: }
2025:
1.160 albertel 2026: sub start_QuestionText {
2027: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.168 albertel 2028: my $dim = &get_dim_id();
1.160 albertel 2029: my $text=&Apache::lonxml::get_all_text('/questiontext',$parser,$style);
2030: if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
1.169 albertel 2031: $dimension{$dim}{'questiontext'}=$text;
1.160 albertel 2032: }
2033: return '';
2034: }
2035:
2036: sub end_QuestionText {
2037: return '';
2038: }
2039:
1.13 albertel 2040: sub get_instance {
1.75 albertel 2041: my ($dim)=@_;
2042: my $rand_alg=&Apache::lonnet::get_rand_alg();
2043: if (!$rand_alg || $rand_alg eq '32bit' || $rand_alg eq '64bit' ||
2044: $rand_alg eq '64bit2' || $rand_alg eq '64bit3' ||
2045: $rand_alg eq '64bit4' ) {
2046: &Apache::response::pushrandomnumber();
1.169 albertel 2047: my @order=&Math::Random::random_permutation(@{$dimension{$dim}{'instances'}});
1.75 albertel 2048: my $num=@order;
2049: my $version=&get_version();
2050: my $which=($version-1)%$num;
2051: return $order[$which];
2052: } else {
2053: my ($version,$previous) = &get_version();
2054: my $instance =
2055: $Apache::lonhomework::history{"resource.$version.0.$dim.instance"};
2056: if (defined($instance)) { return $instance; }
2057:
2058: &Apache::response::pushrandomnumber();
1.173 albertel 2059: if (ref($dimension{$dim}{'instances'}) eq 'ARRAY') {
2060: my @instances = @{$dimension{$dim}{'instances'}};
2061: # remove disabled instances
2062: for (my $i=0; $i < $#instances; $i++) {
2063: if ($dimension{$dim}{$instances[$i].'.disabled'}) {
2064: splice(@instances,$i,1);
2065: $i--;
2066: }
2067: }
2068: @instances = &Math::Random::random_permutation(@instances);
2069: $instance = $instances[($version-1)%scalar(@instances)];
2070: if ($version =~ /^\d$/) {
2071: $Apache::lonhomework::results{"resource.$version.0.$dim.instance"} =
2072: $instance;
2073: $Apache::lonhomework::results{'INTERNAL_store'} = 1;
1.75 albertel 2074: }
2075: }
2076: &Apache::response::poprandomnumber();
2077: return $instance;
2078: }
1.13 albertel 2079: }
2080:
1.169 albertel 2081: sub get_criteria {
2082: my ($what,$version,$dim,$id) = @_;
2083: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
2084: my $prefix = ($type eq 'criteria') ? "$dim.$id"
2085: : "$id";
2086: my $entry = "resource.$version.0.$prefix.$what";
2087: if (exists($Apache::lonhomework::results{$entry})) {
2088: return $Apache::lonhomework::results{$entry};
2089: }
2090: return $Apache::lonhomework::history{$entry};
2091: }
2092:
1.18 albertel 2093: {
2094: my $last_link;
1.122 albertel 2095: sub link {
1.151 albertel 2096: my ($id) = @_;
2097: $id =~ s/\./_/g;
2098: return 'LC_GRADING_criteria_'.$id;
1.122 albertel 2099: }
1.151 albertel 2100: sub end_Question { return &end_Dimension(@_); }
1.18 albertel 2101: sub end_Dimension {
2102: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.54 albertel 2103: my $result=&Apache::lonxml::endredirection();
1.25 albertel 2104: my $dim=&get_id($parstack,$safeeval);
1.173 albertel 2105: if (&skip_dimension_parsing($dim)) {
2106: &disable_dimension_parsing($dim);
2107: pop(@Apache::bridgetask::dimension);
2108: return;
2109: }
1.75 albertel 2110: my $instance=&get_instance($dim);
1.25 albertel 2111: my $version=&get_version();
1.18 albertel 2112: if ($target eq 'web') {
1.173 albertel 2113: $result .= &nested_parse(\$dimension{$dim}{'intro'},[@_]);
1.76 albertel 2114: my @instances = $instance;
2115: if (&Apache::response::showallfoils()) {
1.169 albertel 2116: @instances = @{$dimension{$dim}{'instances'}};
1.76 albertel 2117: }
1.160 albertel 2118: my $shown_question_text;
1.76 albertel 2119: foreach my $instance (@instances) {
1.173 albertel 2120: $result .= &nested_parse(\$dimension{$dim}{$instance.'.text'},
2121: [@_]);
2122: $result .= &nested_parse(\$dimension{$dim}{'questiontext'},
2123: [@_],{'set_dim_id' => undef});
1.169 albertel 2124: my $task_status =
2125: $Apache::lonhomework::history{"resource.$version.0.status"};
1.173 albertel 2126: if ($task_status ne 'pass' && $task_status ne 'fail') {
1.76 albertel 2127:
1.173 albertel 2128: foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
2129: @{$dimension{$dim}{'criterias'}}) {
2130: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
2131: &Apache::lonxml::debug("$id is $type");
2132: if ($type eq 'dimension') {
2133: $result.=
2134: &nested_parse(\$dimension{$dim}{'criteria.'.$id},
2135: [@_],{'set_dim_id' => $id});
2136: }
2137: }
2138: } else {
1.89 albertel 2139: my $dim_status=$Apache::lonhomework::history{"resource.$version.0.$dim.status"};
1.76 albertel 2140: my $mandatory='Mandatory';
2141: if ($Apache::bridgetask::dimensionmandatory{$dim} eq 'N') {
2142: $mandatory='Optional';
2143: }
1.116 albertel 2144: my $dim_info="<div class='LC_$dim_status LC_question_grade'>\n";
1.76 albertel 2145: if ($dim_status eq 'pass') {
2146: $dim_info.='<h3>Question : you passed this '.$mandatory.' question</h3>';
1.54 albertel 2147: }
1.76 albertel 2148: if ($dim_status eq 'fail') {
2149: $dim_info.='<h3>Question : you did not pass this '.$mandatory.' question</h3>';
1.53 albertel 2150: }
1.76 albertel 2151: my $man_count=0;
2152: my $man_passed=0;
2153: my $opt_count=0;
2154: my $opt_passed=0;
1.169 albertel 2155: foreach my $id ( @{$dimension{$dim}{$instance.'.criterias'}},
2156: @{$dimension{$dim}{'criterias'}} ) {
2157: my $status = &get_criteria('status',$version,$dim,$id);
2158: if ($dimension{$dim}{'criteria.'.$id.'.mandatory'}
1.76 albertel 2159: eq 'N') {
2160: $opt_count++;
1.169 albertel 2161: if ($status eq 'pass') { $opt_passed++; }
1.76 albertel 2162: } else {
2163: $man_count++;
1.169 albertel 2164: if ($status eq 'pass') { $man_passed++; }
1.76 albertel 2165: }
1.22 albertel 2166: }
1.76 albertel 2167: if ($man_passed eq $man_count) { $man_passed='all'; }
1.151 albertel 2168:
1.169 albertel 2169: my $opt_req=$dimension{$dim}{$instance.'.optionalrequired'};
1.151 albertel 2170: if ($opt_req !~ /\S/) {
2171: $opt_req=
2172: &Apache::lonxml::get_param('OptionalRequired',
2173: $parstack,$safeeval);
2174: if ($opt_req !~ /\S/) { $opt_req = 0; }
2175: }
1.76 albertel 2176: $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>";
2177:
2178: my $internal_location=&internal_location($dim);
2179: $result=~s/\Q$internal_location\E/$dim_info/;
2180:
1.169 albertel 2181: foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
2182: @{$dimension{$dim}{'criterias'}}) {
2183: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
1.171 albertel 2184: if ($type eq 'dimension') {
2185: $result.=$dimension{$id}{'result'};
2186: next;
2187: }
1.169 albertel 2188: my $status= &get_criteria('status', $version,$dim,$id);
2189: my $comment=&get_criteria('comment',$version,$dim,$id);
2190: my $mandatory=($dimension{$dim}{'criteria.'.$id.'.mandatory'} ne 'N');
1.76 albertel 2191: if ($mandatory) {
2192: $mandatory='Mandatory';
2193: } else {
2194: $mandatory='Optional';
2195: }
2196: if ($status eq 'fail') {
2197: } elsif ($status eq 'pass') {
2198: } else {
2199: &Apache::lonxml::error("Student viewing a graded bridgetask was shown a status of $status");
2200: }
2201: my $status_display=$status;
2202: $status_display=~s/^([a-z])/uc($1)/e;
1.116 albertel 2203: $result.=
2204: '<div class="LC_'.$status.' LC_criteria"><h4>'
2205: .$mandatory.' Criteria</h4><p>';
1.173 albertel 2206: $result.=
2207: &nested_parse(\$dimension{$dim}{'criteria.'.$id},
2208: [@_],{'set_dim_id' => $id});
1.116 albertel 2209: $result.='</p><p class="LC_grade">'.$status_display.'</p>';
1.169 albertel 2210: if ($comment) {
2211: $result.='<p class="LC_comment">'.
2212: &mt('Comment: [_1]',$comment).'</p>';
1.76 albertel 2213: }
2214: $result.='</div>';
1.22 albertel 2215: }
2216: }
2217: }
1.18 albertel 2218: } elsif ($target eq 'webgrade') {
1.47 albertel 2219: # in case of any side effects that we need
1.173 albertel 2220: &nested_parse(\$dimension{$dim}{'intro'},[@_]);
2221: &nested_parse(\$dimension{$dim}{$instance.'.text'},[@_]);
2222: $result.=
2223: &nested_parse(\$dimension{$dim}{'questiontext'},[@_],
2224: {'set_dim_id' => undef,
2225: 'delay_dim_results' => 1});
1.169 albertel 2226: foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
2227: @{$dimension{$dim}{'criterias'}} ) {
2228: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
1.171 albertel 2229: if ($type eq 'dimension') {
2230: # dimensional 'criteria' don't get assigned grades
1.173 albertel 2231: $result.=
2232: &nested_parse(\$dimension{$dim}{'criteria.'.$id},
2233: [@_],{'set_dim_id' => $id});
1.171 albertel 2234: next;
2235: }
1.169 albertel 2236:
1.151 albertel 2237: my $link=&link($id);
1.169 albertel 2238: my $status= &get_criteria('status',$version,$dim,$id);
1.120 albertel 2239: $result.='<div class="LC_GRADING_criteria" id="'.$link.'">'."\n".
1.136 albertel 2240: '<div class="LC_GRADING_criteriatext" id="next_'.$last_link.'">'."\n";
1.173 albertel 2241: $result.=
2242: &nested_parse(\$dimension{$dim}{'criteria.'.$id},[@_]);
2243:
1.111 albertel 2244: $result.='</div>'."\n".
1.120 albertel 2245: '<div class="LC_GRADING_grade">'."\n".
2246: '<label class="LC_GRADING_ungraded"><input type="radio" name="HWVAL_'.$link.'" value="ungraded" '.($status eq 'ungraded' || !$status ? 'checked="checked"':'').' />'.&mt('Ungraded').'</label>'."\n".
2247: '<label class="LC_GRADING_fail"><input type="radio" name="HWVAL_'.$link.'" value="fail" '.($status eq 'fail' ? 'checked="checked"':'').' />'.&mt('Fail').'</label>'."\n".
2248: '<label class="LC_GRADING_pass"><input type="radio" name="HWVAL_'.$link.'" value="pass" '.($status eq 'pass' ? 'checked="checked"':'').' />'.&mt('Pass').'</label>'."\n".
2249: '<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 2250: '</div>'."\n".
1.120 albertel 2251: '<label class="LC_GRADING_comment">'.&mt('Additional Comment for Student')."\n".
1.169 albertel 2252: '<textarea class="LC_GRADING_comment_area" name="HWVAL_comment_'.$link.'">'.&HTML::Entities::encode(&get_criteria('comment',$version,$dim,$id),'<>"&').'</textarea>'."\n".
1.111 albertel 2253: '</label>'."\n".
1.120 albertel 2254: '<ul class="LC_GRADING_navbuttons">'."\n".
1.111 albertel 2255: '<li><a href="#'.$last_link.'">Prev</a></li>'."\n".
2256: '<li><a href="#next_'.$link.'">Next</a></li>'."\n".
2257: '</ul>'."\n".
2258: '</div>'."\n";
1.151 albertel 2259: $result.=&grading_history($version,$dim,$id);
1.18 albertel 2260: $last_link=$link;
2261: }
1.173 albertel 2262: if (&delay_result()) {
2263: &Apache::lonxml::debug(" for $dim stashing results into ".$dimension{$dim}{'nested'});
2264: $dimension{$dimension{$dim}{'nested'}}{'result'}.=$result;
1.171 albertel 2265: undef($result);
2266: }
1.22 albertel 2267: } elsif ($target eq 'grade' && $env{'form.webgrade'}) {
1.19 albertel 2268: my $optional_passed=0;
1.20 albertel 2269: my $mandatory_failed=0;
2270: my $ungraded=0;
2271: my $review=0;
1.153 albertel 2272:
1.173 albertel 2273: $result .= &nested_parse(\$dimension{$dim}{'intro'},[@_]);
2274: $result .= &nested_parse(\$dimension{$dim}{$instance.'.text'},
2275: [@_]);
2276: $result .= &nested_parse(\$dimension{$dim}{'questiontext'},
2277: [@_],{'set_dim_id' => undef});
1.160 albertel 2278:
1.169 albertel 2279: foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
2280: @{$dimension{$dim}{'criterias'}}) {
1.151 albertel 2281: my $link=&link($id);
1.169 albertel 2282:
2283: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
2284: if ($type eq 'criteria') {
2285: # dimensional 'criteria' don't get assigned grades
2286: $Apache::lonhomework::results{"resource.$version.0.$dim.$id.status"}=$env{'form.HWVAL_'.$link};
2287: $Apache::lonhomework::results{"resource.$version.0.$dim.$id.comment"}=$env{'form.HWVAL_comment_'.$link};
1.173 albertel 2288: } else {
2289: $result .=
2290: &nested_parse(\$dimension{$dim}{'criteria.'.$id},
2291: [@_],{'set_dim_id' => $id});
1.169 albertel 2292: }
2293: my $status= &get_criteria('status',$version,$dim,$id);
2294:
2295: my $mandatory=($dimension{$dim}{'criteria.'.$id.'.mandatory'} ne 'N');
1.20 albertel 2296: if ($status eq 'pass') {
2297: if (!$mandatory) { $optional_passed++; }
2298: } elsif ($status eq 'fail') {
2299: if ($mandatory) { $mandatory_failed++; }
1.21 albertel 2300: } elsif ($status eq 'review') {
2301: $review++;
1.20 albertel 2302: } elsif ($status eq 'ungraded') {
2303: $ungraded++;
1.21 albertel 2304: } else {
1.47 albertel 2305: $ungraded++;
1.19 albertel 2306: }
2307: }
1.151 albertel 2308: # FIXME optional required can apply to only <instance> right now...
1.169 albertel 2309: my $opt_req=$dimension{$dim}{$instance.'.optionalrequired'};
1.151 albertel 2310: if ($opt_req !~ /\S/) {
2311: $opt_req=
2312: &Apache::lonxml::get_param('OptionalRequired',
2313: $parstack,$safeeval);
2314: if ($opt_req !~ /\S/) { $opt_req = 0; }
2315: }
2316: if ($optional_passed < $opt_req) {
1.20 albertel 2317: $mandatory_failed++;
2318: }
1.169 albertel 2319: &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 2320: if ($review) {
1.89 albertel 2321: $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
1.22 albertel 2322: 'review';
1.20 albertel 2323: } elsif ($ungraded) {
1.89 albertel 2324: $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
1.22 albertel 2325: 'ungraded';
1.20 albertel 2326: } elsif ($mandatory_failed) {
1.89 albertel 2327: $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
1.22 albertel 2328: 'fail';
1.20 albertel 2329: } else {
1.91 albertel 2330: $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
1.22 albertel 2331: 'pass';
1.20 albertel 2332: }
1.69 albertel 2333: } else {
2334: # any other targets no output
2335: undef($result);
1.13 albertel 2336: }
1.173 albertel 2337: &disable_dimension_parsing();
1.169 albertel 2338: pop(@Apache::bridgetask::dimension);
1.18 albertel 2339: return $result;
1.1 albertel 2340: }
1.162 albertel 2341:
2342: sub end_Setup {
2343: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
2344: my $result=&Apache::lonxml::endredirection();
2345: my $dim=&get_id($parstack,$safeeval);
2346: my $instance=&get_instance($dim);
2347: my $version=&get_version();
2348: if ($target eq 'web') {
2349: @Apache::scripttag::parser_env = @_;
1.169 albertel 2350: $result.=&Apache::scripttag::xmlparse($dimension{$dim}{'intro'});
1.162 albertel 2351: my @instances = $instance;
2352: if (&Apache::response::showallfoils()) {
1.169 albertel 2353: @instances = @{$dimension{$dim}{'instances'}};
1.162 albertel 2354: }
2355: foreach my $instance (@instances) {
2356: @Apache::scripttag::parser_env = @_;
1.169 albertel 2357: $result.=&Apache::scripttag::xmlparse($dimension{$dim}{$instance.'.text'});
1.162 albertel 2358: @Apache::scripttag::parser_env = @_;
1.169 albertel 2359: $result.=&Apache::scripttag::xmlparse($dimension{$dim}{'questiontext'});
1.162 albertel 2360: }
2361: } elsif ($target eq 'webgrade'
2362: || $target eq 'grade' && $env{'form.webgrade'}) {
2363: # in case of any side effects that we need
2364: @Apache::scripttag::parser_env = @_;
1.169 albertel 2365: &Apache::scripttag::xmlparse($dimension{$dim}{'intro'});
1.162 albertel 2366: @Apache::scripttag::parser_env = @_;
1.169 albertel 2367: &Apache::scripttag::xmlparse($dimension{$dim}{$instance.'.text'});
1.162 albertel 2368: @Apache::scripttag::parser_env = @_;
1.169 albertel 2369: &Apache::scripttag::xmlparse($dimension{$dim}{'questiontext'});
1.162 albertel 2370: } else {
2371: # any other targets no output
2372: undef($result);
2373: }
1.169 albertel 2374: pop(@Apache::bridgetask::dimension);
1.162 albertel 2375: return $result;
2376: }
1.1 albertel 2377: }
2378:
1.113 albertel 2379: sub grading_history {
1.151 albertel 2380: my ($version,$dim,$id) = @_;
1.113 albertel 2381: if (!&Apache::lonnet::allowed('mgq',$env{'request.course.id'})) {
2382: return '';
2383: }
2384: my ($result,$grader);
1.151 albertel 2385: my $scope="resource.$version.0.$dim.$id";
1.113 albertel 2386: foreach my $t (1..$Apache::lonhomework::history{'version'}) {
2387: if (exists($Apache::lonhomework::history{$t.':resource.0.regrader'})) {
2388: my ($gname,$gdom) =
1.138 albertel 2389: split(':',$Apache::lonhomework::history{$t.':resource.0.regrader'});
1.113 albertel 2390: my $fullname = &Apache::loncommon::plainname($gname,$gdom);
2391: $grader = &Apache::loncommon::aboutmewrapper($fullname,
2392: $gname,$gdom);
2393: }
2394: my $entry;
2395: if (exists($Apache::lonhomework::history{"$t:$scope.status"})) {
2396: $entry.="<tt>".$Apache::lonhomework::history{"$t:$scope.status"}.'</tt>';
2397: }
2398: if (exists($Apache::lonhomework::history{"$t:$scope.comment"})) {
2399: $entry.=' comment: "'.$Apache::lonhomework::history{"$t:$scope.comment"}.'"';
2400: }
2401: if ($entry) {
2402: $result.= "<li>$grader : $entry </li>";
2403: }
2404: }
2405: if ($result) {
1.120 albertel 2406: return '<ul class="LC_GRADING_pastgrading">'.$result.'</ul>';
1.113 albertel 2407: }
2408: return '';
2409: }
2410:
1.1 albertel 2411: sub start_IntroParagraph {
1.87 albertel 2412: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.1 albertel 2413: my $result;
1.168 albertel 2414: my $dim = &get_dim_id();
1.153 albertel 2415: if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
1.151 albertel 2416: if ($tagstack->[-2] eq 'Dimension' || $tagstack->[-2] eq 'Question' ) {
1.169 albertel 2417: $dimension{$dim}{'intro'}=
1.151 albertel 2418: &Apache::lonxml::get_all_text('/introparagraph',
2419: $parser,$style);
2420: } elsif ($tagstack->[-2] eq 'Task' && $target eq 'webgrade') {
1.127 albertel 2421: &Apache::lonxml::startredirection();
1.1 albertel 2422: }
1.47 albertel 2423:
1.1 albertel 2424: }
2425: return $result;
2426: }
2427:
2428: sub end_IntroParagraph {
1.127 albertel 2429: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.128 albertel 2430: if ($tagstack->[-2] eq 'Task' && $target eq 'webgrade') {
1.127 albertel 2431: my $result = &Apache::lonxml::endredirection();
2432: }
1.1 albertel 2433: }
2434:
2435: sub start_Instance {
2436: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.168 albertel 2437: my $dim = &get_dim_id();
2438: my $id = &get_id($parstack,$safeeval);
1.169 albertel 2439: push(@{$dimension{$dim}{'instances'}},$id);
1.168 albertel 2440: push(@{$Apache::bridgetask::instance{$dim}},$id);
1.19 albertel 2441: push(@Apache::bridgetask::instancelist,$id);
1.169 albertel 2442: $dimension{$dim}{$id.'.optionalrequired'}=
1.19 albertel 2443: &Apache::lonxml::get_param('OptionalRequired',$parstack,$safeeval);
1.75 albertel 2444: my $disabled = &Apache::lonxml::get_param('Disabled',$parstack,$safeeval);
2445: if (lc($disabled) eq 'yes') {
1.169 albertel 2446: $dimension{$dim}{$id.'.disabled'}='1';
1.75 albertel 2447: }
1.1 albertel 2448: return '';
2449: }
2450:
2451: sub end_Instance {
2452: }
2453:
2454: sub start_InstanceText {
1.87 albertel 2455: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.168 albertel 2456: my $dim = &get_dim_id();
2457: my $instance_id=$Apache::bridgetask::instance{$dim}[-1];
1.87 albertel 2458: my $text=&Apache::lonxml::get_all_text('/instancetext',$parser,$style);
1.153 albertel 2459: if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
1.169 albertel 2460: $dimension{$dim}{$instance_id.'.text'}=$text;
1.1 albertel 2461: }
2462: return '';
2463: }
2464:
2465: sub end_InstanceText {
2466: return '';
2467: }
2468:
2469: sub start_Criteria {
1.87 albertel 2470: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
2471: my $criteria=&Apache::lonxml::get_all_text('/criteria',$parser,$style);
1.21 albertel 2472: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
1.168 albertel 2473: my $dim = &get_dim_id();
1.19 albertel 2474: my $id=&get_id($parstack,$safeeval);
1.169 albertel 2475: &Apache::lonxml::debug("Criteria $id with $dim");
1.151 albertel 2476: if (&Apache::londefdef::is_inside_of($tagstack,'Instance')) {
1.168 albertel 2477: my $instance_id=$Apache::bridgetask::instance{$dim}[-1];
1.169 albertel 2478: $dimension{$dim}{"criteria.$instance_id.$id"}=$criteria;
2479: $dimension{$dim}{"criteria.$instance_id.$id.type"}='criteria';
2480: $dimension{$dim}{"criteria.$instance_id.$id.mandatory"}=
1.151 albertel 2481: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.169 albertel 2482: push(@{$dimension{$dim}{$instance_id.'.criterias'}},"$instance_id.$id");
1.151 albertel 2483: } else {
1.169 albertel 2484: $dimension{$dim}{'criteria.'.$id}=$criteria;
2485: $dimension{$dim}{'criteria.'.$id.'.type'}='criteria';
2486: $dimension{$dim}{'criteria.'.$id.'.mandatory'}=
1.151 albertel 2487: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.169 albertel 2488: push(@{$dimension{$dim}{'criterias'}},$id);
1.151 albertel 2489: }
1.1 albertel 2490: }
2491: return '';
2492: }
2493:
1.47 albertel 2494: sub end_Criteria {
2495: }
2496:
1.4 albertel 2497: sub proctor_validation_screen {
2498: my ($slot) = @_;
2499: my (undef,undef,$domain,$user) = &Apache::lonxml::whichuser();
1.5 albertel 2500: my $url=&Apache::lonnet::studentphoto($domain,$user,'jpg');
1.44 albertel 2501: my $name=&Apache::loncommon::plainname($user,$domain);
2502:
1.4 albertel 2503: my $msg;
1.11 albertel 2504: if ($env{'form.proctorpassword'}) {
1.4 albertel 2505: $msg='<p><font color="red">'.&mt("Failed to authenticate the proctor.")
2506: .'</font></p>';
2507: }
1.47 albertel 2508: if (!$env{'form.proctordomain'}) { $env{'form.proctordomain'}=$domain; }
1.4 albertel 2509: my $result= (<<ENDCHECKOUT);
2510: <h2>Proctor Validation</h2>
2511: <p>Your room's proctor needs to validate your access to this resource.</p>
2512: $msg
1.115 albertel 2513: <form name="checkout" method="post" action="$env{'request.uri'}">
1.4 albertel 2514: <input type="hidden" name="validate" value="yes" />
2515: <input type="hidden" name="submitted" value="yes" />
2516: <table>
1.44 albertel 2517: <tr><td>Proctor's Username:</td><td><input type="string" name="proctorname" value="$env{'form.proctorname'}" /></td></tr>
1.4 albertel 2518: <tr><td>Password:</td><td><input type="password" name="proctorpassword" value="" /></td></tr>
1.46 albertel 2519: <tr><td>Proctor's Domain:</td><td><input type="string" name="proctordomain" value="$env{'form.proctordomain'}" /></td></tr>
1.4 albertel 2520: </table>
2521: <input type="submit" name="checkoutbutton" value="Validate" /><br />
1.44 albertel 2522: <table border="1">
2523: <tr><td>
2524: <table>
2525: <tr><td colspan="2">Student who should be logged in is:</td></tr>
2526: <tr><td>Name:</td><td>$name</td></tr>
1.45 albertel 2527: <tr><td>Student ID:</td><td>$env{'environment.id'}</td></tr>
1.138 albertel 2528: <tr><td>Usename</td><td>$user:$domain</td></tr>
1.44 albertel 2529: <tr><td colspan="2"><img src="$url" /></td></tr>
2530: </table>
2531: </tr></td>
2532: </table>
1.4 albertel 2533: </form>
2534: ENDCHECKOUT
2535: return $result;
2536: }
2537:
1.1 albertel 2538: 1;
2539: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>