Annotation of loncom/homework/lonhomework.pm, revision 1.354
1.63 albertel 1: # The LearningOnline Network with CAPA
1.52 albertel 2: # The LON-CAPA Homework handler
1.63 albertel 3: #
1.354 ! musolffc 4: # $Id: lonhomework.pm,v 1.353 2015/05/16 23:29:17 droeschl Exp $
1.63 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/
1.159 www 27:
1.1 albertel 28:
29: package Apache::lonhomework;
30: use strict;
1.73 albertel 31: use Apache::style();
32: use Apache::lonxml();
1.204 albertel 33: use Apache::lonnet;
1.73 albertel 34: use Apache::lonplot();
35: use Apache::inputtags();
36: use Apache::structuretags();
37: use Apache::randomlabel();
38: use Apache::response();
39: use Apache::hint();
40: use Apache::outputtags();
1.83 albertel 41: use Apache::caparesponse();
42: use Apache::radiobuttonresponse();
43: use Apache::optionresponse();
44: use Apache::imageresponse();
45: use Apache::essayresponse();
46: use Apache::externalresponse();
1.106 albertel 47: use Apache::rankresponse();
1.107 albertel 48: use Apache::matchresponse();
1.137 albertel 49: use Apache::chemresponse();
1.321 www 50: use Apache::functionplotresponse();
1.169 albertel 51: use Apache::drawimage();
1.26 www 52: use Apache::Constants qw(:common);
1.83 albertel 53: use Apache::loncommon();
1.354 ! musolffc 54: use Apache::lonparmset();
1.146 albertel 55: use Apache::lonlocal;
1.179 albertel 56: use Time::HiRes qw( gettimeofday tv_interval );
1.282 albertel 57: use HTML::Entities();
58: use File::Copy();
1.188 foxr 59:
1.189 albertel 60: # FIXME - improve commenting
1.188 foxr 61:
1.43 albertel 62:
1.69 harris41 63: BEGIN {
1.145 albertel 64: &Apache::lonxml::register_insert();
1.43 albertel 65: }
66:
1.188 foxr 67:
1.276 foxr 68: =pod
69:
70: =item set_bubble_lines()
71:
72: Called at analysis time to set the bubble lines
73: hash for the problem.. This should be called in the
74: end_problemtype tag in analysis mode.
75:
76: We fetch the hash of part id counters from lonxml
77: and push them into analyze:{part_id.bubble_lines}.
78:
79: =cut
80:
81: sub set_bubble_lines {
82: my %bubble_counters = &Apache::lonxml::get_bubble_line_hash();
83:
84: foreach my $key (keys(%bubble_counters)) {
85: $Apache::lonhomework::analyze{"$key.bubble_lines"} =
86: $bubble_counters{"$key"};
87: }
88: }
89:
1.301 jms 90: #
91: # Decides what targets to render for.
92: # Implicit inputs:
93: # Various session environment variables:
94: # request.state - published - is a /res/ resource
95: # uploaded - is a /uploaded/ resource
96: # contruct - is a /priv/ resource
97: # form.grade_target - a form parameter requesting a specific target
1.5 albertel 98: sub get_target {
1.204 albertel 99: &Apache::lonxml::debug("request.state = $env{'request.state'}");
100: if( defined($env{'form.grade_target'})) {
101: &Apache::lonxml::debug("form.grade_target= $env{'form.grade_target'}");
1.188 foxr 102: } else {
1.189 albertel 103: &Apache::lonxml::debug("form.grade_target <undefined>");
1.188 foxr 104: }
1.204 albertel 105: if (($env{'request.state'} eq "published") ||
106: ($env{'request.state'} eq "uploaded")) {
107: if ( defined($env{'form.grade_target'} )
108: && ($env{'form.grade_target'} eq 'tex')) {
109: return ($env{'form.grade_target'});
110: } elsif ( defined($env{'form.grade_target'} )
1.145 albertel 111: && ($Apache::lonhomework::viewgrades eq 'F' )) {
1.207 albertel 112: return ($env{'form.grade_target'});
1.244 albertel 113: } elsif ( $env{'form.grade_target'} eq 'webgrade'
114: && ($Apache::lonhomework::queuegrade eq 'F' )) {
115: return ($env{'form.grade_target'});
1.320 raeburn 116: } elsif ($env{'form.grade_target'} eq 'answer') {
117: if ($env{'form.answer_output_mode'} eq 'tex') {
118: return ($env{'form.grade_target'});
119: }
120: }
1.207 albertel 121: if ($env{'form.webgrade'} &&
1.244 albertel 122: ($Apache::lonhomework::modifygrades eq 'F'
123: || $Apache::lonhomework::queuegrade eq 'F' )) {
1.207 albertel 124: return ('grade','webgrade');
1.145 albertel 125: }
1.204 albertel 126: if ( defined($env{'form.submitted'}) &&
127: ( !defined($env{'form.newrandomization'}))) {
1.217 albertel 128: return ('grade', 'web');
1.145 albertel 129: } else {
1.217 albertel 130: return ('web');
1.145 albertel 131: }
1.204 albertel 132: } elsif ($env{'request.state'} eq "construct") {
1.323 www 133: #
134: # We are in construction space, editing and testing problems
135: #
1.204 albertel 136: if ( defined($env{'form.grade_target'}) ) {
137: return ($env{'form.grade_target'});
1.145 albertel 138: }
1.204 albertel 139: if ( defined($env{'form.preview'})) {
140: if ( defined($env{'form.submitted'})) {
1.323 www 141: #
142: # We are doing a problem preview
143: #
1.145 albertel 144: return ('grade', 'web');
145: } else {
146: return ('web');
147: }
148: } else {
1.267 albertel 149: if ($env{'form.problemstate'} eq 'WEB_GRADE') {
150: return ('grade','webgrade','answer');
1.324 www 151: } elsif ($env{'form.problemmode'} eq 'view') {
152: return ('grade','web','answer');
1.323 www 153: } elsif ($env{'form.problemmode'} eq 'saveview') {
154: return ('modified','web','answer');
155: } elsif ($env{'form.problemmode'} eq 'discard') {
156: return ('web','answer');
157: } elsif (($env{'form.problemmode'} eq 'saveedit') ||
158: ($env{'form.problemmode'} eq 'undo')) {
159: return ('modified','no_output_web','edit');
160: } elsif ($env{'form.problemmode'} eq 'edit') {
161: return ('no_output_web','edit');
1.145 albertel 162: } else {
163: return ('web');
164: }
1.323 www 165: }
166: #
1.338 raeburn 167: # End of Authoring Space
1.323 www 168: #
1.15 albertel 169: }
1.323 www 170: #
171: # Huh? We are nowhere, so do nothing.
172: #
1.145 albertel 173: return ();
1.5 albertel 174: }
175:
1.3 albertel 176: sub setup_vars {
1.145 albertel 177: my ($target) = @_;
178: return ';'
1.11 albertel 179: # return ';$external::target='.$target.';';
1.2 albertel 180: }
181:
1.200 albertel 182: sub proctor_checked_in {
1.226 albertel 183: my ($slot_name,$slot,$type)=@_;
184: my @possible_proctors=split(",",$slot->{'proctor'});
185:
1.248 albertel 186: return 1 if (!@possible_proctors);
187:
1.226 albertel 188: my $key;
189: if ($type eq 'Task') {
1.230 albertel 190: my $version=$Apache::lonhomework::history{'resource.0.version'};
191: $key ="resource.$version.0.checkedin";
1.226 albertel 192: } elsif ($type eq 'problem') {
193: $key ='resource.0.checkedin';
194: }
1.249 albertel 195: # backward compatability, used to be username@domain,
196: # now is username:domain
197: my $who = $Apache::lonhomework::history{$key};
198: if ($who !~ /:/) {
199: $who =~ tr/@/:/;
200: }
1.226 albertel 201: foreach my $possible (@possible_proctors) {
1.249 albertel 202: if ($who eq $possible
1.226 albertel 203: && $Apache::lonhomework::history{$key.'.slot'} eq $slot_name) {
1.202 albertel 204: return 1;
205: }
206: }
1.226 albertel 207:
1.200 albertel 208: return 0;
209: }
210:
1.226 albertel 211: sub check_slot_access {
212: my ($id,$type)=@_;
213:
1.207 albertel 214: # does it pass normal muster
1.226 albertel 215: my ($status,$datemsg)=&check_access($id);
216:
1.252 albertel 217: my $useslots = &Apache::lonnet::EXT("resource.0.useslots");
1.251 albertel 218: if ($useslots ne 'resource' && $useslots ne 'map'
219: && $useslots ne 'map_map') {
1.226 albertel 220: return ($status,$datemsg);
221: }
222:
1.200 albertel 223: if ($status eq 'SHOW_ANSWER' ||
224: $status eq 'CLOSED' ||
225: $status eq 'INVALID_ACCESS' ||
226: $status eq 'UNAVAILABLE') {
227: return ($status,$datemsg);
228: }
1.204 albertel 229: if ($env{'request.state'} eq "construct") {
1.203 albertel 230: return ($status,$datemsg);
231: }
1.226 albertel 232:
233: if ($type eq 'Task') {
234: my $version=$Apache::lonhomework::history{'resource.version'};
1.230 albertel 235: if ($Apache::lonhomework::history{"resource.$version.0.checkedin"} &&
236: $Apache::lonhomework::history{"resource.$version.0.status"} eq 'pass') {
1.226 albertel 237: return ('SHOW_ANSWER');
238: }
1.207 albertel 239: }
1.226 albertel 240:
1.288 raeburn 241: my $availablestudent = &Apache::lonnet::EXT("resource.0.availablestudent");
242: my $available = &Apache::lonnet::EXT("resource.0.available");
243: my @slots= (split(':',$availablestudent),split(':',$available));
1.210 albertel 244:
1.200 albertel 245: # if (!@slots) {
246: # return ($status,$datemsg);
247: # }
248: my $slotstatus='NOT_IN_A_SLOT';
1.206 albertel 249: my ($returned_slot,$slot_name);
1.334 raeburn 250: my $now = time;
251: my $num_usable_slots = 0;
1.210 albertel 252: foreach my $slot (@slots) {
1.241 albertel 253: $slot =~ s/(^\s*|\s*$)//g;
1.201 albertel 254: &Apache::lonxml::debug("getting $slot");
1.200 albertel 255: my %slot=&Apache::lonnet::get_slot($slot);
1.201 albertel 256: &Apache::lonhomework::showhash(%slot);
1.334 raeburn 257: next if ($slot{'endtime'} < $now);
258: $num_usable_slots ++;
259: if ($slot{'starttime'} < $now &&
260: $slot{'endtime'} > $now &&
1.297 raeburn 261: &Apache::loncommon::check_ip_acc($slot{'ip'})) {
1.202 albertel 262: &Apache::lonxml::debug("$slot is good");
263: $slotstatus='NEEDS_CHECKIN';
264: $returned_slot=\%slot;
1.206 albertel 265: $slot_name=$slot;
1.200 albertel 266: last;
1.334 raeburn 267: }
1.200 albertel 268: }
1.202 albertel 269: if ($slotstatus eq 'NEEDS_CHECKIN' &&
1.226 albertel 270: &proctor_checked_in($slot_name,$returned_slot,$type)) {
1.322 raeburn 271: &Apache::lonxml::debug("proctor checked in");
272: $slotstatus=$status;
1.200 albertel 273: }
1.226 albertel 274:
1.235 albertel 275: my ($is_correct,$got_grade,$checkedin);
1.226 albertel 276: if ($type eq 'Task') {
1.230 albertel 277: my $version=$Apache::lonhomework::history{'resource.0.version'};
1.231 albertel 278: $got_grade =
279: ($Apache::lonhomework::history{"resource.$version.0.status"}
280: =~ /^(?:pass|fail)$/);
1.235 albertel 281: $is_correct =
282: ($Apache::lonhomework::history{"resource.$version.0.status"} eq 'pass'
283: || $Apache::lonhomework::history{"resource.0.solved"} =~ /^correct_/ );
1.226 albertel 284: $checkedin =
1.230 albertel 285: $Apache::lonhomework::history{"resource.$version.0.checkedin"};
1.226 albertel 286: } elsif ($type eq 'problem') {
1.252 albertel 287: $got_grade = 1;
288: $checkedin = $Apache::lonhomework::history{"resource.0.checkedin"};
289: $is_correct =
290: ($Apache::lonhomework::history{"resource.0.solved"} =~/^correct_/);
1.226 albertel 291: }
292:
1.235 albertel 293: &Apache::lonxml::debug(" slot is $slotstatus checkedin ($checkedin) got_grade ($got_grade) is_correct ($is_correct)");
294:
1.243 albertel 295: # no slot is currently open, and has been checked in for this version
296: # but hasn't got a grade, therefore must be awaiting a grade
297: if (!defined($slot_name)
298: && $checkedin
1.236 albertel 299: && !$got_grade) {
300: return ('WAITING_FOR_GRADE');
301: }
302:
1.309 raeburn 303: # Previously used slot is no longer open, and has been checked in for this version.
304: # However, the problem is not closed, and potentially, another slot might be
305: # used to gain access to it to work on it, until the due date is reached, and the
306: # problem then becomes CLOSED. Therefore return the slotstatus -
1.334 raeburn 307: # (which will be one of: NOT_IN_A_SLOT, RESERVABLE, RESERVABLE_LATER, or NOTRESERVABLE.
308: if (!defined($slot_name) && $type eq 'problem') {
309: if ($slotstatus eq 'NOT_IN_A_SLOT') {
310: if (!$num_usable_slots) {
311: if ($env{'request.course.id'}) {
312: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
313: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
314: my ($symb)=&Apache::lonnet::whichuser();
315: $slotstatus = 'NOTRESERVABLE';
316: my ($reservable_now_order,$reservable_now,$reservable_future_order,
317: $reservable_future) =
318: &Apache::loncommon::get_future_slots($cnum,$cdom,$now,$symb);
319: if ((ref($reservable_now_order) eq 'ARRAY') && (ref($reservable_now) eq 'HASH')) {
320: if (@{$reservable_now_order} > 0) {
321: $slotstatus = 'RESERVABLE';
322: $datemsg = $reservable_now->{$reservable_now_order->[-1]}{'endreserve'};
323: }
324: }
325: unless ($slotstatus eq 'RESERVABLE') {
326: if ((ref($reservable_future_order) eq 'ARRAY') && (ref($reservable_future) eq 'HASH')) {
327: if (@{$reservable_future_order} > 0) {
328: $slotstatus = 'RESERVABLE_LATER';
329: $datemsg = $reservable_future->{$reservable_future_order->[0]}{'startreserve'};
330: }
331: }
332: }
333: }
334: }
335: }
336: return ($slotstatus,$datemsg);
1.252 albertel 337: }
338:
1.226 albertel 339: if ($slotstatus eq 'NOT_IN_A_SLOT'
340: && $checkedin ) {
341:
1.231 albertel 342: if ($got_grade) {
1.209 albertel 343: return ('SHOW_ANSWER');
344: } else {
345: return ('WAITING_FOR_GRADE');
346: }
1.226 albertel 347:
1.207 albertel 348: }
1.255 albertel 349:
1.235 albertel 350: if ( $is_correct) {
1.255 albertel 351: if ($type eq 'problem') {
352: return ($status);
353: }
1.235 albertel 354: return ('SHOW_ANSWER');
355: }
1.255 albertel 356:
1.225 albertel 357: if ( $status eq 'CANNOT_ANSWER' &&
358: ($slotstatus ne 'NEEDS_CHECKIN' && $slotstatus ne 'NOT_IN_A_SLOT')) {
359: return ($status,$datemsg);
360: }
361:
1.206 albertel 362: return ($slotstatus,$datemsg,$slot_name,$returned_slot);
1.198 albertel 363: }
1.200 albertel 364:
1.301 jms 365: # JB, 9/24/2002: Any changes in this function may require a change
366: # in lonnavmaps::resource::getDateStatus.
1.53 www 367: sub check_access {
1.145 albertel 368: my ($id) = @_;
369: my $date ='';
370: my $status;
371: my $datemsg = '';
372: my $lastdate = '';
373: my $type;
374: my $passed;
375:
1.204 albertel 376: if ($env{'request.state'} eq "construct") {
377: if ($env{'form.problemstate'}) {
378: if ($env{'form.problemstate'} =~ /^CANNOT_ANSWER/) {
1.277 albertel 379: if ( ! ($env{'form.problemstate'} eq 'CANNOT_ANSWER_correct'
380: && &hide_problem_status())) {
1.168 albertel 381: return ('CANNOT_ANSWER',
1.174 www 382: &mt('is in this state due to author settings.'));
1.167 albertel 383: }
1.165 albertel 384: } else {
1.204 albertel 385: return ($env{'form.problemstate'},
1.174 www 386: &mt('is in this state due to author settings.'));
1.165 albertel 387: }
388: }
1.145 albertel 389: &Apache::lonxml::debug("in construction ignoring dates");
390: $status='CAN_ANSWER';
1.146 albertel 391: $datemsg=&mt('is in under construction');
1.163 albertel 392: # return ($status,$datemsg);
1.145 albertel 393: }
394:
395: &Apache::lonxml::debug("checking for part :$id:");
396: &Apache::lonxml::debug("time:".time);
1.152 albertel 397:
1.261 albertel 398: my ($symb)=&Apache::lonnet::whichuser();
1.212 albertel 399: &Apache::lonxml::debug("symb:".$symb);
400: #if ($env{'request.state'} ne "construct" && $symb ne '') {
1.204 albertel 401: if ($env{'request.state'} ne "construct") {
1.288 raeburn 402: my $idacc = &Apache::lonnet::EXT("resource.$id.acc");
1.297 raeburn 403: my $allowed=&Apache::loncommon::check_ip_acc($idacc);
1.163 albertel 404: if (!$allowed && ($Apache::lonhomework::browse ne 'F')) {
405: $status='INVALID_ACCESS';
406: $date=&mt("can not be accessed from your location.");
1.145 albertel 407: return($status,$date);
408: }
1.327 raeburn 409: if ($env{'form.grade_imsexport'}) {
410: if (($env{'request.course.id'}) &&
411: (&Apache::lonnet::allowed('mdc',$env{'request.course.id'}))) {
412: return ('SHOW_ANSWER');
413: }
414: }
1.226 albertel 415: foreach my $temp ("opendate","duedate","answerdate") {
1.163 albertel 416: $lastdate = $date;
1.247 albertel 417: if ($temp eq 'duedate') {
418: $date = &due_date($id);
419: } else {
420: $date = &Apache::lonnet::EXT("resource.$id.$temp");
421: }
422:
1.163 albertel 423: my $thistype = &Apache::lonnet::EXT("resource.$id.$temp.type");
424: if ($thistype =~ /^(con_lost|no_such_host)/ ||
425: $date =~ /^(con_lost|no_such_host)/) {
426: $status='UNAVAILABLE';
427: $date=&mt("may open later.");
428: return($status,$date);
429: }
430: if ($thistype eq 'date_interval') {
431: if ($temp eq 'opendate') {
432: $date=&Apache::lonnet::EXT("resource.$id.duedate")-$date;
433: }
434: if ($temp eq 'answerdate') {
435: $date=&Apache::lonnet::EXT("resource.$id.duedate")+$date;
436: }
1.145 albertel 437: }
1.163 albertel 438: &Apache::lonxml::debug("found :$date: for :$temp:");
439: if ($date eq '') {
440: $date = &mt("an unknown date"); $passed = 0;
441: } elsif ($date eq 'con_lost') {
442: $date = &mt("an indeterminate date"); $passed = 0;
443: } else {
444: if (time < $date) { $passed = 0; } else { $passed = 1; }
1.274 www 445: $date = &Apache::lonlocal::locallocaltime($date);
1.145 albertel 446: }
1.163 albertel 447: if (!$passed) { $type=$temp; last; }
1.145 albertel 448: }
1.163 albertel 449: &Apache::lonxml::debug("have :$type:$passed:");
450: if ($passed) {
451: $status='SHOW_ANSWER';
452: $datemsg=$date;
453: } elsif ($type eq 'opendate') {
454: $status='CLOSED';
1.343 bisitz 455: $datemsg = &mt('will open on [_1]',$date);
1.163 albertel 456: } elsif ($type eq 'duedate') {
457: $status='CAN_ANSWER';
1.343 bisitz 458: $datemsg = &mt('is due at [_1]',$date);
1.163 albertel 459: } elsif ($type eq 'answerdate') {
460: $status='CLOSED';
1.343 bisitz 461: $datemsg = &mt('was due on [_1], and answers will be available on [_2]',
462: $lastdate,$date);
1.145 albertel 463: }
464: }
1.212 albertel 465: if ($status eq 'CAN_ANSWER' ||
466: (($Apache::lonhomework::browse eq 'F') && ($status eq 'CLOSED'))) {
1.145 albertel 467: #check #tries, and if correct.
468: my $tries = $Apache::lonhomework::history{"resource.$id.tries"};
469: my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries");
470: if ( $tries eq '' ) { $tries = '0'; }
1.164 albertel 471: if ( $maxtries eq '' &&
1.204 albertel 472: $env{'request.state'} ne 'construct') { $maxtries = '2'; }
1.164 albertel 473: if ($maxtries && $tries >= $maxtries) { $status = 'CANNOT_ANSWER'; }
1.145 albertel 474: # if (correct and show prob status) or excused then CANNOT_ANSWER
1.331 raeburn 475: if ( ($Apache::lonhomework::history{"resource.$id.solved"}=~/^correct/)
476: && (&show_problem_status()) ) {
1.333 raeburn 477: if (($Apache::lonhomework::history{"resource.$id.awarded"} >= 1) ||
478: (&Apache::lonnet::EXT("resource.$id.retrypartial") !~/^1|on|yes$/i)) {
1.331 raeburn 479: $status = 'CANNOT_ANSWER';
480: }
481: } elsif ($Apache::lonhomework::history{"resource.$id.solved"}=~/^excused/) {
1.145 albertel 482: $status = 'CANNOT_ANSWER';
483: }
1.285 albertel 484: if ($status eq 'CANNOT_ANSWER'
485: && &show_answer_problem_status()) {
486: $status = 'SHOW_ANSWER';
487: }
1.121 albertel 488: }
1.181 albertel 489: if ($status eq 'CAN_ANSWER' || $status eq 'CANNOT_ANSWER') {
1.286 albertel 490: my @interval=&Apache::lonnet::EXT("resource.$id.interval");
491: &Apache::lonxml::debug("looking for interval @interval");
492: if ($interval[0]) {
493: my $first_access=&Apache::lonnet::get_first_access($interval[1]);
1.177 albertel 494: &Apache::lonxml::debug("looking for accesstime $first_access");
495: if (!$first_access) {
496: $status='NOT_YET_VIEWED';
1.247 albertel 497: my $due_date = &due_date($id);
1.256 albertel 498: my $seconds_left = $due_date - time;
1.286 albertel 499: if ($seconds_left > $interval[0] || $due_date eq '') {
500: $seconds_left = $interval[0];
1.256 albertel 501: }
502: $datemsg=&seconds_to_human_length($seconds_left);
1.177 albertel 503: }
504: }
505: }
1.247 albertel 506:
1.133 albertel 507: #if (($status ne 'CLOSED') && ($Apache::lonhomework::type eq 'exam') &&
508: # (!$Apache::lonhomework::history{"resource.0.outtoken"})) {
509: # return ('UNCHECKEDOUT','needs to be checked out');
510: #}
1.54 www 511:
1.145 albertel 512: &Apache::lonxml::debug("sending back :$status:$datemsg:");
513: if (($Apache::lonhomework::browse eq 'F') && ($status eq 'CLOSED')) {
514: &Apache::lonxml::debug("should be allowed to browse a resource when closed");
515: $status='CAN_ANSWER';
1.146 albertel 516: $datemsg=&mt('is closed but you are allowed to view it');
1.145 albertel 517: }
1.106 albertel 518:
1.145 albertel 519: return ($status,$datemsg);
1.20 albertel 520: }
1.301 jms 521: # this should work exactly like the copy in lonnavmaps.pm
1.246 albertel 522: sub due_date {
1.250 albertel 523: my ($part_id,$symb,$udom,$uname)=@_;
1.246 albertel 524: my $date;
1.286 albertel 525: my @interval= &Apache::lonnet::EXT("resource.$part_id.interval",$symb,
1.250 albertel 526: $udom,$uname);
1.286 albertel 527: &Apache::lonxml::debug("looking for interval $part_id $symb @interval");
1.250 albertel 528: my $due_date= &Apache::lonnet::EXT("resource.$part_id.duedate",$symb,
529: $udom,$uname);
1.247 albertel 530: &Apache::lonxml::debug("looking for due_date $part_id $symb $due_date");
1.286 albertel 531: if ($interval[0] =~ /\d+/) {
532: my $first_access=&Apache::lonnet::get_first_access($interval[1],$symb);
533: &Apache::lonxml::debug("looking for first_access $first_access ($interval[1])");
1.247 albertel 534: if (defined($first_access)) {
1.286 albertel 535: my $interval = $first_access+$interval[0];
1.283 albertel 536: $date = (!$due_date || $interval < $due_date) ? $interval
537: : $due_date;
1.247 albertel 538: } else {
539: $date = $due_date;
540: }
541: } else {
542: $date = $due_date;
1.246 albertel 543: }
1.345 musolffc 544: return $date;
1.246 albertel 545: }
546:
1.192 albertel 547: sub seconds_to_human_length {
548: my ($length)=@_;
549:
550: my $seconds=$length%60; $length=int($length/60);
551: my $minutes=$length%60; $length=int($length/60);
552: my $hours=$length%24; $length=int($length/24);
553: my $days=$length;
554:
555: my $timestr;
556: if ($days > 0) { $timestr.=&mt('[quant,_1,day]',$days); }
557: if ($hours > 0) { $timestr.=($timestr?", ":"").
558: &mt('[quant,_1,hour]',$hours); }
559: if ($minutes > 0) { $timestr.=($timestr?", ":"").
560: &mt('[quant,_1,minute]',$minutes); }
561: if ($seconds > 0) { $timestr.=($timestr?", ":"").
562: &mt('[quant,_1,second]',$seconds); }
563: return $timestr;
564: }
565:
1.41 albertel 566: sub showhash {
1.145 albertel 567: my (%hash) = @_;
568: &showhashsubset(\%hash,'.');
569: return '';
1.79 albertel 570: }
571:
1.106 albertel 572: sub showarray {
573: my ($array)=@_;
574: my $string="(";
575: foreach my $elm (@{ $array }) {
1.193 albertel 576: if (ref($elm) eq 'ARRAY') {
577: $string.=&showarray($elm);
578: } elsif (ref($elm) eq 'HASH') {
579: $string.= "HASH --- \n<br />";
580: $string.= &showhashsubset($elm,'.');
1.106 albertel 581: } else {
582: $string.="$elm,"
583: }
584: }
585: chop($string);
586: $string.=")";
587: return $string;
588: }
589:
1.79 albertel 590: sub showhashsubset {
1.145 albertel 591: my ($hash,$keyre) = @_;
592: my $resultkey;
1.346 raeburn 593: foreach $resultkey (sort(keys(%$hash))) {
1.193 albertel 594: if ($resultkey !~ /$keyre/) { next; }
595: if (ref($$hash{$resultkey}) eq 'ARRAY' ) {
596: &Apache::lonxml::debug("$resultkey ---- ".
597: &showarray($$hash{$resultkey}));
598: } elsif (ref($$hash{$resultkey}) eq 'HASH' ) {
599: &Apache::lonxml::debug("$resultkey ---- $$hash{$resultkey}");
600: &showhashsubset($$hash{$resultkey},'.');
601: } else {
602: &Apache::lonxml::debug("$resultkey ---- $$hash{$resultkey}");
1.145 albertel 603: }
604: }
605: &Apache::lonxml::debug("\n<br />restored values^</br>\n");
606: return '';
1.41 albertel 607: }
608:
609: sub setuppermissions {
1.204 albertel 610: $Apache::lonhomework::browse= &Apache::lonnet::allowed('bre',$env{'request.filename'});
1.337 raeburn 611: unless ($Apache::lonhomework::browse eq 'F') {
612: $Apache::lonhomework::browse=&Apache::lonnet::allowed('bro',$env{'request.filename'});
613: }
1.204 albertel 614: my $viewgrades = &Apache::lonnet::allowed('vgr',$env{'request.course.id'});
1.145 albertel 615: if (! $viewgrades &&
1.204 albertel 616: exists($env{'request.course.sec'}) &&
617: $env{'request.course.sec'} !~ /^\s*$/) {
618: $viewgrades = &Apache::lonnet::allowed('vgr',$env{'request.course.id'}.
619: '/'.$env{'request.course.sec'});
1.145 albertel 620: }
1.244 albertel 621: $Apache::lonhomework::viewgrades = $viewgrades;
622:
1.185 albertel 623: if ($Apache::lonhomework::browse eq 'F' &&
1.204 albertel 624: $env{'form.devalidatecourseresdata'} eq 'on') {
1.261 albertel 625: my (undef,$courseid) = &Apache::lonnet::whichuser();
1.204 albertel 626: &Apache::lonnet::devalidatecourseresdata($env{"course.$courseid.num"},
627: $env{"course.$courseid.domain"});
1.185 albertel 628: }
1.244 albertel 629:
1.205 albertel 630: my $modifygrades = &Apache::lonnet::allowed('mgr',$env{'request.course.id'});
631: if (! $modifygrades &&
632: exists($env{'request.course.sec'}) &&
633: $env{'request.course.sec'} !~ /^\s*$/) {
634: $modifygrades =
635: &Apache::lonnet::allowed('mgr',$env{'request.course.id'}.
636: '/'.$env{'request.course.sec'});
637: }
638: $Apache::lonhomework::modifygrades = $modifygrades;
1.244 albertel 639:
640: my $queuegrade = &Apache::lonnet::allowed('mqg',$env{'request.course.id'});
641: if (! $queuegrade &&
642: exists($env{'request.course.sec'}) &&
643: $env{'request.course.sec'} !~ /^\s*$/) {
644: $queuegrade =
645: &Apache::lonnet::allowed('qgr',$env{'request.course.id'}.
646: '/'.$env{'request.course.sec'});
647: }
648: $Apache::lonhomework::queuegrade = $queuegrade;
1.205 albertel 649: return '';
1.41 albertel 650: }
651:
1.253 albertel 652: sub unset_permissions {
653: undef($Apache::lonhomework::queuegrade);
654: undef($Apache::lonhomework::modifygrades);
655: undef($Apache::lonhomework::viewgrades);
656: undef($Apache::lonhomework::browse);
657: }
658:
1.41 albertel 659: sub setupheader {
1.120 albertel 660: my $request=$_[0];
1.197 albertel 661: &Apache::loncommon::content_type($request,'text/html');
1.120 albertel 662: if (!$Apache::lonxml::debug && ($ENV{'REQUEST_METHOD'} eq 'GET')) {
663: &Apache::loncommon::no_cache($request);
664: }
1.196 albertel 665: # $request->set_last_modified(&Apache::lonnet::metadata($request->uri,
666: # 'lastrevisiondate'));
1.120 albertel 667: $request->send_http_header;
668: return OK if $request->header_only;
669: return ''
1.41 albertel 670: }
1.35 albertel 671:
1.47 albertel 672: sub handle_save_or_undo {
1.338 raeburn 673: my ($request,$problem,$result,$getobjref) = @_;
1.323 www 674:
1.145 albertel 675: my $file = &Apache::lonnet::filelocation("",$request->uri);
676: my $filebak =$file.".bak";
677: my $filetmp =$file.".tmp";
678: my $error=0;
1.323 www 679: if (($env{'form.problemmode'} eq 'undo') || ($env{'form.problemmode'} eq 'undoxml')) {
1.145 albertel 680: my $error=0;
1.284 albertel 681: if (!&File::Copy::copy($file,$filetmp)) { $error=1; }
682: if ((!$error) && (!&File::Copy::copy($filebak,$file))) { $error=1; }
683: if ((!$error) && (!&File::Copy::move($filetmp,$filebak))) { $error=1; }
1.145 albertel 684: if (!$error) {
1.266 albertel 685: &Apache::lonxml::info("<p><b>".
686: &mt("Undid changes, Switched [_1] and [_2]",
687: '<span class="LC_filename">'.$filebak.
688: '</span>',
689: '<span class="LC_filename">'.$file.
690: '</span>')."</b></p>");
1.145 albertel 691: } else {
1.266 albertel 692: &Apache::lonxml::info("<p><span class=\"LC_error\">".
693: &mt("Unable to undo, unable to switch [_1] and [_2]",
694: '<span class="LC_filename">'.
695: $filebak.'</span>',
696: '<span class="LC_filename">'.
697: $file.'</span>')."</span></p>");
1.145 albertel 698: $error=1;
699: }
1.52 albertel 700: } else {
1.262 banghart 701: &Apache::lonnet::correct_line_ends($result);
1.323 www 702:
1.145 albertel 703: my $fs=Apache::File->new(">$filebak");
704: if (defined($fs)) {
705: print $fs $$problem;
706: } else {
1.266 albertel 707: &Apache::lonxml::info("<span class=\"LC_error\">".
708: &mt("Unable to make backup [_1]",
709: '<span class="LC_filename">'.
710: $filebak.'</span>')."</span>");
1.145 albertel 711: $error=2;
712: }
713: my $fh=Apache::File->new(">$file");
714: if (defined($fh)) {
715: print $fh $$result;
1.338 raeburn 716: if (ref($getobjref) eq 'SCALAR') {
717: if ($file =~ m{([^/]+)\.(html?)$}) {
718: my $fname = $1;
719: my $ext = $2;
720: my $path = $file;
721: $path =~ s/\Q$fname\E\.\Q$ext\E$//;
722: my (%allfiles,%codebase);
723: &Apache::lonnet::extract_embedded_items($file,\%allfiles,
724: \%codebase,$result);
725: if (keys(%allfiles) > 0) {
726: my $url = $request->uri;
727: my $state = <<STATE;
728: <input type="hidden" name="action" value="upload_embedded" />
729: <input type="hidden" name="url" value="$url" />
730: STATE
731: $$getobjref = "<h3>".&mt("Reference Warning")."</h3>".
732: "<p>".&mt("Completed upload of the file. This file contained references to other files.")."</p>".
733: "<p>".&mt("Please select the locations from which the referenced files are to be uploaded.")."</p>".
734: &Apache::loncommon::ask_for_embedded_content($url,$state,\%allfiles,\%codebase,
735: {'error_on_invalid_names' => 1,
736: 'ignore_remote_references' => 1,});
737: }
738: }
739: }
1.145 albertel 740: } else {
1.266 albertel 741: &Apache::lonxml::info('<span class="LC_error">'.
742: &mt("Unable to write to [_1]",
743: '<span class="LC_filename">'.
744: $file.'</span>').
745: '</span>');
1.145 albertel 746: $error|=4;
747: }
1.52 albertel 748: }
1.145 albertel 749: return $error;
1.64 albertel 750: }
751:
1.101 albertel 752: sub analyze_header {
753: my ($request) = @_;
1.289 raeburn 754: my $js = &Apache::structuretags::setmode_javascript();
1.312 bisitz 755:
756: # Breadcrumbs
1.330 raeburn 757: my $brcrum = [{'href' => &Apache::loncommon::authorspace($request->uri),
1.338 raeburn 758: 'text' => 'Authoring Space'},
1.312 bisitz 759: {'href' => '',
760: 'text' => 'Problem Testing'},
761: {'href' => '',
762: 'text' => 'Analyzing a problem'}];
763:
1.238 albertel 764: my $result =
1.312 bisitz 765: &Apache::loncommon::start_page('Analyzing a problem',
766: $js,
767: {'bread_crumbs' => $brcrum,})
1.311 bisitz 768: .&Apache::loncommon::head_subbox(
769: &Apache::loncommon::CSTR_pageheader());
1.238 albertel 770: $result .=
1.347 golterma 771: '<form name="lonhomework" method="post" action="'.
1.204 albertel 772: &HTML::Entities::encode($env{'request.uri'},'<>&"').'">'.
1.289 raeburn 773: '<input type="hidden" name="problemmode" value="'.
774: $env{'form.problemmode'}.'" />'.
1.179 albertel 775: &Apache::structuretags::remember_problem_state().'
1.278 albertel 776: <div class="LC_edit_problem_analyze_header">
1.289 raeburn 777: <input type="button" name="submitmode" value="'.&mt("EditXML").'" '.
778: 'onclick="javascript:setmode(this.form,'."'editxml'".')" />
779: <input type="button" name="submitmode" value="'.&mt('Edit').'" '.
780: 'onclick="javascript:setmode(this.form,'."'edit'".')" />
1.313 bisitz 781: <hr />
1.289 raeburn 782: <input type="button" name="submitmode" value="'.&mt("View").'" '.
783: 'onclick="javascript:setmode(this.form,'."'view'".')" />
1.313 bisitz 784: <hr />
1.347 golterma 785: </div>'
786: .&Apache::lonxml::message_location().
787: '</form>';
1.171 albertel 788: &Apache::lonxml::add_messages(\$result);
1.101 albertel 789: $request->print($result);
790: $request->rflush();
791: }
792:
1.109 albertel 793: sub analyze_footer {
794: my ($request) = @_;
1.237 albertel 795: $request->print(&Apache::loncommon::end_page());
1.109 albertel 796: $request->rflush();
797: }
798:
1.74 albertel 799: sub analyze {
1.101 albertel 800: my ($request,$file) = @_;
801: &Apache::lonxml::debug("Analyze");
802: my $result;
803: my %overall;
1.219 www 804: my %seedexample;
1.101 albertel 805: my %allparts;
1.204 albertel 806: my $rndseed=$env{'form.rndseed'};
1.101 albertel 807: &analyze_header($request);
1.114 albertel 808: my %prog_state=
1.335 www 809: &Apache::lonhtmlcommon::Create_PrgWin($request,$env{'form.numtoanalyze'});
1.204 albertel 810: for(my $i=1;$i<$env{'form.numtoanalyze'}+1;$i++) {
1.335 www 811: &Apache::lonhtmlcommon::Increment_PrgWin($request,\%prog_state,'last problem');
1.182 albertel 812: if (&Apache::loncommon::connection_aborted($request)) { return; }
1.219 www 813: my $thisseed=$i+$rndseed;
1.101 albertel 814: my $subresult=&Apache::lonnet::ssi($request->uri,
815: ('grade_target' => 'analyze'),
1.219 www 816: ('rndseed' => $thisseed));
1.101 albertel 817: (my $garbage,$subresult)=split(/_HASH_REF__/,$subresult,2);
818: my %analyze=&Apache::lonnet::str2hash($subresult);
1.114 albertel 819: my @parts;
1.336 raeburn 820: if (ref($analyze{'parts'}) eq 'ARRAY') {
1.114 albertel 821: @parts=@{ $analyze{'parts'} };
822: }
1.101 albertel 823: foreach my $part (@parts) {
824: if (!exists($allparts{$part})) {$allparts{$part}=1;};
1.109 albertel 825: if ($analyze{$part.'.type'} eq 'numericalresponse' ||
826: $analyze{$part.'.type'} eq 'stringresponse' ||
827: $analyze{$part.'.type'} eq 'formularesponse' ) {
1.263 albertel 828: foreach my $name (keys(%{ $analyze{$part.'.answer'} })) {
829: my $i=0;
830: foreach my $answer_part (@{ $analyze{$part.'.answer'}{$name} }) {
831: push( @{ $overall{$part.'.answer'}[$i] },
832: $answer_part);
833: my $concatanswer= join("\0",@{ $answer_part });
834: if (($concatanswer eq '') || ($concatanswer=~/^\@/)) {
1.266 albertel 835: $answer_part = ['<span class="LC_error">'.&mt('Error').'</span>'];
1.263 albertel 836: }
837: $seedexample{join("\0",$part,$i,@{$answer_part})}=
838: $thisseed;
839: $i++;
840: }
1.219 www 841: }
1.275 albertel 842: if (!keys(%{ $analyze{$part.'.answer'} })) {
843: my $answer_part =
844: ['<span class="LC_error">'.&mt('Error').'</span>'];
845: $seedexample{join("\0",$part,0,@{$answer_part})}=
846: $thisseed;
847: push( @{ $overall{$part.'.answer'}[0] },
848: $answer_part);
849: }
1.101 albertel 850: }
851: }
852: }
1.335 www 853: &Apache::lonhtmlcommon::Update_PrgWin($request,\%prog_state,&mt('Analyzing Results'));
1.313 bisitz 854: $request->print('<hr />'
1.308 bisitz 855: .'<h3>'
856: .&mt('List of possible answers')
857: .'</h3>'
858: );
1.134 albertel 859: foreach my $part (sort(keys(%allparts))) {
1.336 raeburn 860: if ((ref($overall{$part.'.answer'}) eq 'ARRAY') &&
861: (@{$overall{$part.'.answer'}} > 0)) {
1.263 albertel 862: for (my $i=0;$i<scalar(@{ $overall{$part.'.answer'} });$i++) {
863: my $num_cols=scalar(@{ $overall{$part.'.answer'}[$i][0] });
1.308 bisitz 864: $request->print(&Apache::loncommon::start_data_table()
865: .&Apache::loncommon::start_data_table_header_row()
866: .'<th colspan="'.($num_cols+1).'">'
867: .&mt('Part').' '.$part
868: );
1.263 albertel 869: if (scalar(@{ $overall{$part.'.answer'} }) > 1) {
1.308 bisitz 870: $request->print(' '.&mt('Answer [_1]',$i+1));
1.263 albertel 871: }
1.308 bisitz 872: $request->print('</th>'
873: .&Apache::loncommon::end_data_table_header_row()
874: );
1.263 albertel 875: my %frequency;
876: foreach my $answer (sort {$a->[0] <=> $b->[0]} (@{ $overall{$part.'.answer'}[$i] })) {
877: $frequency{join("\0",@{ $answer })}++;
878: }
1.308 bisitz 879: $request->print(&Apache::loncommon::start_data_table_header_row()
880: .'<th colspan="'.($num_cols).'">'.&mt('Answer').'</th>'
881: .'<th>'.&mt('Frequency').'<br />'
882: .'('.&mt('click for example').')</th>'
883: .&Apache::loncommon::end_data_table_header_row()
884: );
1.263 albertel 885: foreach my $answer (sort {(split("\0",$a))[0] <=> (split("\0",$b))[0]} (keys(%frequency))) {
1.308 bisitz 886: $request->print(&Apache::loncommon::start_data_table_row()
887: .'<td>'
888: .join('</td><td>',split("\0",$answer))
889: .'</td>'
890: .'<td>'
891: .'<a href="'.$request->uri.'?rndseed='.$seedexample{join("\0",$part,$i,$answer)}.'">'.$frequency{$answer}.'</a>'
892: .'</td>'
893: .&Apache::loncommon::end_data_table_row()
894: );
1.263 albertel 895: }
1.308 bisitz 896: $request->print(&Apache::loncommon::end_data_table());
1.109 albertel 897: }
898: } else {
1.307 bisitz 899: $request->print('<p class="LC_warning">'
900: .&mt('Response [_1] is not analyzable at this time.',$part)
901: .'</p>'
902: );
1.101 albertel 903: }
904: }
1.130 albertel 905: if (scalar(keys(%allparts)) == 0 ) {
1.307 bisitz 906: $request->print('<p class="LC_warning">'
907: .&mt('Found no analyzable responses in this problem.'
908: .' Currently only Numerical, Formula and String response styles are supported.')
909: .'</p>'
910: );
1.130 albertel 911: }
1.114 albertel 912: &Apache::lonhtmlcommon::Close_PrgWin($request,\%prog_state);
1.109 albertel 913: &analyze_footer($request);
1.101 albertel 914: &Apache::lonhomework::showhash(%overall);
915: return $result;
1.74 albertel 916: }
917:
1.277 albertel 918: {
919: my $show_problem_status;
920: sub reset_show_problem_status {
921: undef($show_problem_status);
922: }
923:
924: sub set_show_problem_status {
925: my ($new_status) = @_;
926: $show_problem_status = lc($new_status);
927: }
928:
929: sub hide_problem_status {
930: return ($show_problem_status eq 'no'
931: || $show_problem_status eq 'no_feedback_ever');
932: }
933:
934: sub show_problem_status {
935: return ($show_problem_status eq 'yes'
1.285 albertel 936: || $show_problem_status eq 'answer'
1.277 albertel 937: || $show_problem_status eq '');
938: }
939:
940: sub show_some_problem_status {
941: return ($show_problem_status eq 'no');
942: }
943:
944: sub show_no_problem_status {
945: return ($show_problem_status eq 'no_feedback_ever');
946: }
1.285 albertel 947:
948: sub show_answer_problem_status {
949: return ($show_problem_status eq 'answer');
950: }
1.277 albertel 951: }
952:
1.64 albertel 953: sub editxmlmode {
1.145 albertel 954: my ($request,$file) = @_;
955: my $result;
956: my $problem=&Apache::lonnet::getfile($file);
957: if ($problem eq -1) {
1.305 bisitz 958: &Apache::lonxml::error(
1.328 bisitz 959: '<p class="LC_error">'
1.305 bisitz 960: .&mt('Unable to find [_1]',
961: '<span class="LC_filename">'.$file.'</span>')
1.328 bisitz 962: .'</p>');
1.305 bisitz 963:
1.145 albertel 964: $problem='';
965: }
1.323 www 966: if (($env{'form.problemmode'} eq 'saveeditxml') ||
1.347 golterma 967: ($env{'form.problemmode'} eq 'saveviewxml') ||
1.323 www 968: ($env{'form.problemmode'} eq 'undoxml')) {
1.145 albertel 969: my $error=&handle_save_or_undo($request,\$problem,
1.204 albertel 970: \$env{'form.editxmltext'});
1.145 albertel 971: if (!$error) { $problem=&Apache::lonnet::getfile($file); }
972: }
1.204 albertel 973: &Apache::lonhomework::showhashsubset(\%env,'^form');
1.323 www 974: if ($env{'form.problemmode'} eq 'saveviewxml') {
1.204 albertel 975: &Apache::lonhomework::showhashsubset(\%env,'^form');
1.289 raeburn 976: $env{'form.problemmode'}='view';
1.145 albertel 977: &renderpage($request,$file);
978: } else {
979: my ($rows,$cols) = &Apache::edit::textarea_sizes(\$problem);
980: if ($cols > 80) { $cols = 80; }
981: if ($cols < 70) { $cols = 70; }
982: if ($rows < 20) { $rows = 20; }
1.269 albertel 983: my $js =
984: &Apache::edit::js_change_detection().
1.289 raeburn 985: &Apache::loncommon::resize_textarea_js().
1.296 raeburn 986: &Apache::structuretags::setmode_javascript().
1.298 foxr 987: &Apache::lonhtmlcommon::dragmath_js("EditMathPopup");
1.312 bisitz 988:
989: # Breadcrumbs
1.330 raeburn 990: my $brcrum = [{'href' => &Apache::loncommon::authorspace($request->uri),
1.338 raeburn 991: 'text' => 'Authoring Space'},
1.312 bisitz 992: {'href' => '',
993: 'text' => 'Problem Editing'}];
994:
1.238 albertel 995: my $start_page =
1.269 albertel 996: &Apache::loncommon::start_page(&mt("EditXML [_1]",$file),$js,
997: {'no_auto_mt_title' => 1,
1.318 droeschl 998: 'only_body' => 0,
1.269 albertel 999: 'add_entries' => {
1000: 'onresize' => q[resize_textarea('LC_editxmltext','LC_aftertextarea')],
1001: 'onload' => q[resize_textarea('LC_editxmltext','LC_aftertextarea')],
1.323 www 1002: },
1.312 bisitz 1003: 'bread_crumbs' => $brcrum,
1.323 www 1004: });
1.311 bisitz 1005:
1006: $result=$start_page
1007: .&Apache::loncommon::head_subbox(
1008: &Apache::loncommon::CSTR_pageheader());
1009: $result.=&renderpage($request,$file,['no_output_web'],1).
1.310 bisitz 1010: '<form '.&Apache::edit::form_change_detection().' name="lonhomework" method="post" action="'.
1.204 albertel 1011: &HTML::Entities::encode($env{'request.uri'},'<>&"').'">'.
1.179 albertel 1012: &Apache::structuretags::remember_problem_state().'
1.347 golterma 1013: <div class="LC_edit_problem_header">
1014: <div class="LC_edit_problem_header_title">'.
1015: &mt('Problem Editing').' '.&Apache::loncommon::help_open_topic('Problem_Editor_XML_Index').
1016: '</div><div class="LC_edit_actionbar" id="actionbar">';
1017:
1.352 droeschl 1018: $result.='<input type="hidden" name="problemmode" value="saveedit" />'.
1.348 droeschl 1019: &Apache::structuretags::problem_edit_buttons('editxml');
1.352 droeschl 1020: $result.='<div>';
1.347 golterma 1021:
1.352 droeschl 1022: $result .= '<ol class="LC_primary_menu" style="display:inline-block;font-size:90%;vertical-align:middle;">';
1023:
1024: unless ($env{'environment.nocodemirror'}) {
1025: # dropdown menus
1026: $result .= Apache::lonmenu::create_submenu("#", "",
1027: &mt("Problem Templates"), template_dropdown_datastructure());
1028:
1029: $result .= Apache::lonmenu::create_submenu("#", "",
1030: &mt("Response Types"), responseblock_dropdown_datastructure());
1031:
1032: $result .= Apache::lonmenu::create_submenu("#", "",
1033: &mt("Conditional Blocks"), conditional_scripting_datastructure());
1034:
1035: $result .= Apache::lonmenu::create_submenu("#", "",
1036: &mt("Miscellaneous"), misc_datastructure());
1037: }
1.351 droeschl 1038:
1039: $result .= Apache::lonmenu::create_submenu("#", "",
1040: &mt("Help") . ' <img src="/adm/help/help.png" alt="' . &mt("Help") .
1041: '" style="vertical-align:text-bottom; height: auto; margin:0; "/>',
1.352 droeschl 1042: helpmenu_datastructure(),"");
1.351 droeschl 1043:
1044: $result.="</ol></div>";
1.323 www 1045:
1.352 droeschl 1046: $result .= '</div></div>' .
1047: &Apache::lonxml::message_location() .
1048: &Apache::loncommon::xmleditor_js() .
1049: '<textarea ' . &Apache::edit::element_change_detection() .
1050: ' rows="'.$rows.'" cols="'.$cols.'" style="width:100%" ' .
1051: ' name="editxmltext" id="LC_editxmltext">' .
1052: &HTML::Entities::encode($problem,'<>&"') .
1053: '</textarea> <div id="LC_aftertextarea"> </div> </form>';
1054:
1055: my $resource = $env{'request.ambiguous'};
1056: unless($env{'environment.nocodemirror'}){
1057: $result .= '<link rel="stylesheet" href="/adm/codemirror/codemirror-combined-xml.css">
1058: <script src="/adm/codemirror/codemirror-compressed-xml.js"></script>
1059: <script>
1060: CodeMirror.defineMode("mixedmode", function(config) {
1061: return CodeMirror.multiplexingMode(
1062: CodeMirror.getMode(config, "xml"),
1063: {
1064: open: "\<script type=\"loncapa/perl\"\>", close: "\</script\>",
1065: mode: CodeMirror.getMode(config, "perl"),
1066: delimStyle: "tag",
1067: }
1068: );
1069: });
1070: var cm = CodeMirror.fromTextArea(document.getElementById("LC_editxmltext"),
1071: {
1072: mode: "mixedmode",
1073: lineWrapping: true,
1074: lineNumbers: true,
1075: tabSize: 4,
1076: indentUnit: 4,
1077:
1078: autoCloseTags: true,
1079: autoCloseBrackets: true,
1080: height: "auto",
1081: styleActiveLine: true,
1082:
1083: extraKeys: {
1084: "Tab": "indentMore",
1085: "Shift-Tab": "indentLess",
1086: }
1087: });
1088: restoreScrollPosition("'.$resource.'");
1089: </script>';
1090: }
1091:
1092: $result .= &Apache::loncommon::end_page();
1093: &Apache::lonxml::add_messages(\$result);
1094: $request->print($result);
1.145 albertel 1095: }
1096: return '';
1.47 albertel 1097: }
1.189 albertel 1098:
1.301 jms 1099: #
1100: # Render the page in whatever target desired.
1101: #
1.41 albertel 1102: sub renderpage {
1.213 albertel 1103: my ($request,$file,$targets,$return_string) = @_;
1.52 albertel 1104:
1.211 albertel 1105: my @targets = @{$targets || [&get_target()]};
1.204 albertel 1106: &Apache::lonhomework::showhashsubset(\%env,'form.');
1.145 albertel 1107: &Apache::lonxml::debug("Running targets ".join(':',@targets));
1.268 albertel 1108:
1.171 albertel 1109: my $overall_result;
1.145 albertel 1110: foreach my $target (@targets) {
1.183 albertel 1111: # FIXME need to do something intelligent when a problem goes
1112: # from viewable to not viewable due to map conditions
1113: #&setuppermissions();
1114: #if ( $Apache::lonhomework::browse ne '2'
1115: # && $Apache::lonhomework::browse ne 'F' ) {
1116: # $request->print(" You most likely shouldn't see me.");
1117: #}
1.145 albertel 1118: #my $t0 = [&gettimeofday()];
1.211 albertel 1119: my $output=1;
1120: if ($target eq 'no_output_web') {
1121: $target = 'web'; $output=0;
1122: }
1.145 albertel 1123: my $problem=&Apache::lonnet::getfile($file);
1.222 albertel 1124: my $result;
1.145 albertel 1125: if ($problem eq -1) {
1.260 albertel 1126: $problem='';
1.222 albertel 1127: my $filename=(split('/',$file))[-1];
1.260 albertel 1128: my $error =
1.347 golterma 1129: '<p class="LC_error">'
1130: .&mt('Unable to find [_1]',
1131: '<span class="LC_filename">'.$filename.'</span>')
1132: ."</p>";
1.260 albertel 1133: $result.=
1134: &Apache::loncommon::simple_error_page($request,'Not available',
1.340 bisitz 1135: $error,{'no_auto_mt_msg' => 1});
1.260 albertel 1136: return;
1.145 albertel 1137: }
1.52 albertel 1138:
1.145 albertel 1139: my %mystyle;
1140: if ($target eq 'analyze') { %Apache::lonhomework::analyze=(); }
1141: if ($target eq 'answer') { &showhash(%Apache::lonhomework::history); }
1.204 albertel 1142: if ($target eq 'web') {&Apache::lonhomework::showhashsubset(\%env,'^form');}
1.145 albertel 1143:
1144: &Apache::lonxml::debug("Should be parsing now");
1.222 albertel 1145: $result .= &Apache::lonxml::xmlparse($request, $target, $problem,
1146: &setup_vars($target),%mystyle);
1.273 albertel 1147: &finished_parsing();
1.214 albertel 1148: if (!$output) { $result = ''; }
1.145 albertel 1149: #$request->print("Result follows:");
1150: if ($target eq 'modified') {
1151: &handle_save_or_undo($request,\$problem,\$result);
1152: } else {
1153: if ($target eq 'analyze') {
1154: $result=&Apache::lonnet::hashref2str(\%Apache::lonhomework::analyze);
1155: undef(%Apache::lonhomework::analyze);
1156: }
1157: #my $td=&tv_interval($t0);
1158: #if ( $Apache::lonxml::debug) {
1159: #$result =~ s:</body>::;
1160: #$result.="<br />Spent $td seconds processing target $target\n</body>";
1161: #}
1.171 albertel 1162: # $request->print($result);
1163: $overall_result.=$result;
1164: # $request->rflush();
1.145 albertel 1165: }
1166: #$request->print(":Result ends");
1167: #my $td=&tv_interval($t0);
1.52 albertel 1168: }
1.213 albertel 1169: if (!$return_string) {
1170: &Apache::lonxml::add_messages(\$overall_result);
1171: $request->print($overall_result);
1172: $request->rflush();
1173: } else {
1174: return $overall_result;
1175: }
1.41 albertel 1176: }
1177:
1.273 albertel 1178: sub finished_parsing {
1179: undef($Apache::lonhomework::parsing_a_problem);
1180: undef($Apache::lonhomework::parsing_a_task);
1181: }
1182:
1.347 golterma 1183: # function extracted from get_template_html
1184: # returns "key" -> list
1185: # key: path of template
1186: # value 1: title
1187: # value 2: category
1188: # value 3: name of help topic ???
1189: sub get_template_list{
1190: my ($extension) = @_;
1191:
1192: my @files = glob($Apache::lonnet::perlvar{'lonIncludes'}.
1193: '/templates/*.'.$extension);
1194: @files = map {[$_,&mt(&Apache::lonnet::metadata($_, 'title')),
1195: (&Apache::lonnet::metadata($_, 'category')?&mt(&Apache::lonnet::metadata($_, 'category')):&mt('Miscellaneous')),
1196: &mt(&Apache::lonnet::metadata($_, 'help'))]} (@files);
1197: @files = sort {$a->[2].$a->[1] cmp $b->[2].$b->[1]} (@files);
1198: return @files;
1199: }
1200:
1201: sub get_template_html {
1.282 albertel 1202: my ($extension) = @_;
1.145 albertel 1203: my $result;
1204: my @allnames;
1205: &Apache::lonxml::debug("Looking for :$extension:");
1.282 albertel 1206: my $glob_extension = $extension;
1207: if ($extension eq 'survey' || $extension eq 'exam') {
1208: $glob_extension = 'problem';
1209: }
1.347 golterma 1210: my @files = &get_template_list($extension);
1.287 raeburn 1211: my ($midpoint,$seconddiv,$numfiles);
1.341 bisitz 1212: my @noexamplelink = ('blank.problem','blank.library','script.library');
1.287 raeburn 1213: $numfiles = 0;
1214: foreach my $file (@files) {
1215: next if ($file->[1] !~ /\S/);
1216: $numfiles ++;
1217: }
1218: if ($numfiles > 0) {
1219: $result = '<div class="LC_left_float">';
1220: $midpoint = int($numfiles/2);
1221: if ($numfiles%2) {
1222: $midpoint ++;
1223: }
1224: }
1225: my $count = 0;
1.292 www 1226: my $currentcategory='';
1.314 bisitz 1227: my $first = 1;
1.329 raeburn 1228: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.282 albertel 1229: foreach my $file (@files) {
1230: next if ($file->[1] !~ /\S/);
1.292 www 1231: if ($file->[2] ne $currentcategory) {
1232: $currentcategory=$file->[2];
1233: if ((!$seconddiv) && ($count >= $midpoint)) {
1.314 bisitz 1234: $result .= '</div></div>'."\n".'<div class="LC_left_float">'."\n";
1.292 www 1235: $seconddiv = 1;
1.314 bisitz 1236: } elsif (!$first) {
1237: $result.='</div>'."\n";
1238: } else {
1239: $first = 0;
1.292 www 1240: }
1.314 bisitz 1241: $result.= '<div class="LC_Box">'."\n"
1242: .'<h3 class="LC_hcell">'.$currentcategory.'</h3>'."\n";
1.293 www 1243: $count++;
1.292 www 1244: }
1.282 albertel 1245: $result .=
1246: '<label><input type="radio" name="template" value="'.$file->[0].'" />'.
1.292 www 1247: $file->[1].'</label>';
1248: if ($file->[3]) {
1249: $result.=&Apache::loncommon::help_open_topic($file->[3]);
1250: }
1.341 bisitz 1251: # Provide example link
1.292 www 1252: my $filename=$file->[0];
1.329 raeburn 1253: $filename=~s{^\Q$londocroot\E}{};
1.344 raeburn 1254: if (!(grep($filename =~ /\Q$_\E$/,@noexamplelink))) {
1255: $result .= ' <span class="LC_fontsize_small">'
1256: .&Apache::loncommon::modal_link(
1257: $filename.'?inhibitmenu=yes',&mt('Example'),600,420,'sample')
1258: .'</span>';
1259: }
1.341 bisitz 1260: $result .= '<br />'."\n";
1.287 raeburn 1261: $count ++;
1262: }
1263: if ($numfiles > 0) {
1.314 bisitz 1264: $result .= '</div></div>'."\n".'<div class="LC_clear_float_footer"></div>'."\n";
1.42 albertel 1265: }
1.145 albertel 1266: return $result;
1.42 albertel 1267: }
1268:
1269: sub newproblem {
1.65 matthew 1270: my ($request) = @_;
1.282 albertel 1271:
1.347 golterma 1272: if ($env{'form.mode'} eq 'blank'){
1273: my $dest = &Apache::lonnet::filelocation("",$request->uri);
1274: &File::Copy::copy('/home/httpd/html/res/adm/includes/templates/blank.problem',$dest);
1275: &renderpage($request,$dest);
1276: return;
1277: }
1.282 albertel 1278: if ($env{'form.template'}) {
1279: my $file = $env{'form.template'};
1.65 matthew 1280: my $dest = &Apache::lonnet::filelocation("",$request->uri);
1.282 albertel 1281: &File::Copy::copy($file,$dest);
1.65 matthew 1282: &renderpage($request,$dest);
1.282 albertel 1283: return;
1284: }
1285:
1286: my ($extension) = ($request->uri =~ m/\.(\w+)$/);
1287: &Apache::lonxml::debug("Looking for :$extension:");
1.347 golterma 1288: my $templatelist=&get_template_html($extension);
1.282 albertel 1289: if ($env{'form.newfile'} && !$templatelist) {
1290: # no templates found
1.131 albertel 1291: my $templatefilename =
1.258 albertel 1292: $request->dir_config('lonIncludes').'/templates/blank.'.$extension;
1.131 albertel 1293: &Apache::lonxml::debug("$templatefilename");
1294: my $dest = &Apache::lonnet::filelocation("",$request->uri);
1.282 albertel 1295: &File::Copy::copy($templatefilename,$dest);
1.131 albertel 1296: &renderpage($request,$dest);
1.85 albertel 1297: } else {
1.176 albertel 1298: my $url=&HTML::Entities::encode($request->uri,'<>&"');
1.65 matthew 1299: my $dest = &Apache::lonnet::filelocation("",$request->uri);
1.128 albertel 1300: my $errormsg;
1.85 albertel 1301: my $instructions;
1.330 raeburn 1302: my $brcrum = [{'href' => &Apache::loncommon::authorspace($request->uri),
1.338 raeburn 1303: 'text' => 'Authoring Space'},
1.312 bisitz 1304: {'href' => '',
1305: 'text' => "Create New $extension"}];
1.240 albertel 1306: my $start_page =
1.312 bisitz 1307: &Apache::loncommon::start_page("Create New $extension",
1308: undef,
1309: {'bread_crumbs' => $brcrum,});
1.311 bisitz 1310: $request->print(
1311: $start_page
1312: .&Apache::loncommon::head_subbox(
1313: &Apache::loncommon::CSTR_pageheader())
1314: .'<h1>'.&mt("Creating a new $extension resource.")."</h1>
1.128 albertel 1315: $errormsg
1.258 albertel 1316: ".&mt("The requested file [_1] currently does not exist.",
1.329 raeburn 1317: '<span class="LC_filename">'.$url.'</span>').'
1.314 bisitz 1318: <p class="LC_info">
1319: '.&mt("To create a new $extension, select a template from the".
1320: " list below. Then click on the \"Create $extension\" button.").'
1321: </p><div><form action="'.$url.'" method="post">');
1.258 albertel 1322:
1.85 albertel 1323: if (defined($templatelist)) {
1.282 albertel 1324: $request->print($templatelist);
1.85 albertel 1325: }
1.282 albertel 1326: $request->print('<br /><input type="submit" name="newfile" value="'.
1327: &mt("Create $extension").'" />');
1.314 bisitz 1328: $request->print('</form></div>'.&Apache::loncommon::end_page());
1.65 matthew 1329: }
1.282 albertel 1330: return;
1.42 albertel 1331: }
1332:
1.268 albertel 1333: sub update_construct_style {
1334: if ($env{'request.state'} eq "construct"
1.289 raeburn 1335: && $env{'form.problemmode'} eq 'view'
1.268 albertel 1336: && defined($env{'form.submitted'})
1337: && !defined($env{'form.resetdata'})
1338: && !defined($env{'form.newrandomization'})) {
1339: if ((!$env{'form.style_file'} && $env{'construct.style'})
1340: ||$env{'form.clear_style_file'}) {
1.303 raeburn 1341: &Apache::lonnet::delenv('construct.style');
1.268 albertel 1342: } elsif ($env{'form.style_file'}
1343: && $env{'construct.style'} ne $env{'form.style_file'}) {
1.291 raeburn 1344: &Apache::lonnet::appenv({'construct.style' =>
1345: $env{'form.style_file'}});
1.268 albertel 1346: }
1347: }
1348: }
1349:
1.354 ! musolffc 1350: #
! 1351: # Sets interval for current user so time left will be zero, either for the entire folder
! 1352: # containing the current resource, or just the resource, depending on value of first item
! 1353: # in interval array retrieved from EXT("resource.0.interval");
! 1354: #
! 1355: sub zero_timer {
! 1356: my ($symb) = @_;
! 1357: my ($hastimeleft,$first_access,$now);
! 1358: my @interval=&Apache::lonnet::EXT("resource.0.interval");
! 1359: if (@interval > 1) {
! 1360: if ($interval[1] eq 'course') {
! 1361: return;
! 1362: } else {
! 1363: my $now = time;
! 1364: my $first_access=&Apache::lonnet::get_first_access($interval[1],$symb);
! 1365: if ($first_access > 0) {
! 1366: if ($first_access+$interval[0] > $now) {
! 1367: my $done_time = $now - $first_access;
! 1368: my $snum = 1;
! 1369: if ($interval[1] eq 'map') {
! 1370: $snum = 2;
! 1371: }
! 1372: my $result =
! 1373: &Apache::lonparmset::storeparm_by_symb_inner($symb,'0_interval',
! 1374: $snum,$done_time,
! 1375: 'date_interval',
! 1376: $env{'user.name'},
! 1377: $env{'user.domain'});
! 1378: return $result;
! 1379: }
! 1380: }
! 1381: }
! 1382: }
! 1383: return;
! 1384: }
1.268 albertel 1385:
1.41 albertel 1386: sub handler {
1.145 albertel 1387: #my $t0 = [&gettimeofday()];
1388: my $request=$_[0];
1.354 ! musolffc 1389:
1.223 albertel 1390: $Apache::lonxml::request=$request;
1.204 albertel 1391: $Apache::lonxml::debug=$env{'user.debug'};
1392: $env{'request.uri'}=$request->uri;
1.180 albertel 1393: &setuppermissions();
1.193 albertel 1394:
1.145 albertel 1395: my $file=&Apache::lonnet::filelocation("",$request->uri);
1396:
1397: #check if we know where we are
1.350 raeburn 1398: if ($env{'request.course.fn'} && !&Apache::lonnet::symbread('','',1,1)) {
1.145 albertel 1399: # if we are browsing we might not be able to know where we are
1.173 albertel 1400: if ($Apache::lonhomework::browse ne 'F' &&
1.204 albertel 1401: $env{'request.state'} ne "construct") {
1.145 albertel 1402: #should know where we are, so ask
1.253 albertel 1403: &unset_permissions();
1404: $request->internal_redirect('/adm/ambiguous');
1405: return OK;
1.145 albertel 1406: }
1407: }
1.253 albertel 1408: if (&setupheader($request)) {
1409: &unset_permissions();
1410: return OK;
1411: }
1.354 ! musolffc 1412:
1.244 albertel 1413: &Apache::lonxml::debug("Permissions:$Apache::lonhomework::browse:$Apache::lonhomework::viewgrades:$Apache::lonhomework::modifygrades:$Apache::lonhomework::queuegrade");
1.204 albertel 1414: &Apache::lonxml::debug("Problem Mode ".$env{'form.problemmode'});
1.261 albertel 1415: my ($symb) = &Apache::lonnet::whichuser();
1.145 albertel 1416: &Apache::lonxml::debug('symb is '.$symb);
1.204 albertel 1417: if ($env{'request.state'} eq "construct") {
1.145 albertel 1418: if ( -e $file ) {
1419: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1420: ['problemmode']);
1.204 albertel 1421: if (!(defined $env{'form.problemmode'})) {
1.145 albertel 1422: #first visit to problem in construction space
1.289 raeburn 1423: $env{'form.problemmode'}= 'view';
1.145 albertel 1424: &renderpage($request,$file);
1.323 www 1425: } elsif (($env{'form.problemmode'} eq 'editxml') ||
1426: ($env{'form.problemmode'} eq 'saveeditxml') ||
1427: ($env{'form.problemmode'} eq 'saveviewxml') ||
1428: ($env{'form.problemmode'} eq 'undoxml')) {
1.145 albertel 1429: &editxmlmode($request,$file);
1.289 raeburn 1430: } elsif ($env{'form.problemmode'} eq 'calcanswers') {
1.145 albertel 1431: &analyze($request,$file);
1432: } else {
1.268 albertel 1433: &update_construct_style();
1.145 albertel 1434: &renderpage($request,$file);
1435: }
1436: } else {
1.347 golterma 1437: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1438: ['mode']);
1.145 albertel 1439: # requested file doesn't exist in contruction space
1440: &newproblem($request);
1441: }
1442: } else {
1.354 ! musolffc 1443: # Set the event timer to zero if the "done button" was clicked. The button is
! 1444: # part of the doneButton form created in lonmenu.pm
! 1445: if ($symb && $env{'form.LC_interval_done'} eq 'true') {
! 1446: &zero_timer($symb);
! 1447: undef($env{'form.LC_interval_done'});
! 1448: }
1.145 albertel 1449: # just render the page normally outside of construction space
1450: &Apache::lonxml::debug("not construct");
1.52 albertel 1451: &renderpage($request,$file);
1.41 albertel 1452: }
1.145 albertel 1453: #my $td=&tv_interval($t0);
1454: #&Apache::lonxml::debug("Spent $td seconds processing");
1455: # always turn off debug messages
1456: $Apache::lonxml::debug=0;
1.253 albertel 1457: &unset_permissions();
1.145 albertel 1458: return OK;
1.52 albertel 1459:
1.1 albertel 1460: }
1461:
1.352 droeschl 1462: sub template_dropdown_datastructure {
1463: # gathering the all templates and their path, title, category and help topic
1464: my @templates = get_template_list('problem');
1465: # template category => title
1466: my %tmplthash = ();
1467: # template title => path
1468: my %tmpltcontent = ();
1469:
1470: foreach my $template (@templates){
1471: # put in hash if the template is not empty
1472: unless ($template->[1] eq ''){
1473: push(@{$tmplthash{$template->[2]}}, $template->[1]);
1474: push(@{$tmpltcontent{$template->[1]}},$template->[0]);
1475: }
1476: }
1477:
1478: my $catList = [];
1479: foreach my $cat (sort keys %tmplthash) {
1480: my $catItems = [];
1481: foreach my $title (sort @{$tmplthash{$cat}}) {
1482: my $path = $tmpltcontent{$title}->[0];
1483: my $code;
1484: open(FH, "<$path");
1485: while(<FH>){
1486: $code.= $_ unless $_ =~ /(<problem>)|(<\/problem>)/;
1487: }
1488: close(FH);
1489:
1490: if ($code ne '') {
1491: my $href = 'javascript:insertText(\'' . &convert_for_js(&HTML::Entities::encode($code,'<>&"')) . '\')';
1492: my $currItem = [$href, $title, undef];
1493: push @{$catItems}, $currItem;
1494: }
1495: }
1496: push @{$catList}, [$catItems, $cat, undef];
1497: }
1498:
1499: return $catList;
1500: }
1501:
1502: sub responseblock_dropdown_datastructure {
1503:
1504: my $mathCat = [
1505: [
1506: ["javascript:insertText(\'" . &convert_for_js(&HTML::Entities::encode(&Apache::edit::insert_formularesponse())) . "\')", &mt("Formula Response"), undef],
1507: ["javascript:insertText(\'" . &convert_for_js(&HTML::Entities::encode(&Apache::edit::insert_functionplotresponse())) . "\')", &mt("Function Plot Response"), undef],
1508: ["javascript:insertText(\'" . &convert_for_js(&HTML::Entities::encode(&Apache::edit::insert_mathresponse())) . "\')", &mt("Math Response"), undef],
1509: ["javascript:insertText(\'" . &convert_for_js(&HTML::Entities::encode(&Apache::edit::insert_numericalresponse())) . "\')", &mt("Numerical Response"), undef]
1510: ],
1511: &mt("Math"),
1512: undef
1513: ];
1514:
1515: my $miscCat = [
1516: [
1517: ["javascript:insertText(\'" . &convert_for_js(&HTML::Entities::encode(&Apache::edit::insert_imageresponse())) . "\')", &mt("Click on Image"), undef],
1518: ["javascript:insertText(\'" . &convert_for_js(&HTML::Entities::encode(&Apache::edit::insert_customresponse())) . "\')", &mt("Custom Response"), undef],
1519: ["javascript:insertText(\'" . &convert_for_js(&HTML::Entities::encode(&Apache::edit::insert_externalresponse())) . "\')", &mt("External Response"), undef],
1520: ["javascript:insertText(\'" . &convert_for_js(&HTML::Entities::encode(&Apache::edit::insert_matchresponse())) . "\')", &mt("Match Two Lists"), undef],
1521: ["javascript:insertText(\'" . &convert_for_js(&HTML::Entities::encode(&Apache::edit::insert_radiobuttonresponse())) . "\')", &mt("One out of N statements"), undef],
1522: ["javascript:insertText(\'" . &convert_for_js(&HTML::Entities::encode(&Apache::edit::insert_optionresponse())) . "\')", &mt("Select from Options"), undef],
1523: ["javascript:insertText(\'" . &convert_for_js(&HTML::Entities::encode(&Apache::edit::insert_rankresponse())) . "\')", &mt("Rank Values"), undef]
1524: ],
1525: &mt("Miscellaneous"),
1526: undef
1527: ];
1528:
1529: my $chemCat = [
1530: [
1531: ["javascript:insertText(\'" . &convert_for_js(&HTML::Entities::encode(&Apache::edit::insert_reactionresponse())) . "\')", &mt("Chemical Reaction"), undef],
1532: ["javascript:insertText(\'" . &convert_for_js(&HTML::Entities::encode(&Apache::edit::insert_organicresponse())) . "\')", &mt("Organic Chemical Structure"), undef]
1533: ],
1534: &mt("Chemistry"),
1535: undef
1536: ];
1537:
1538: my $textCat = [
1539: [
1540: ["javascript:insertText(\'" . &convert_for_js(&HTML::Entities::encode(&Apache::edit::insert_stringresponse())) . "\')", &mt("String Response"), undef],
1541: ["javascript:insertText(\'" . &convert_for_js(&HTML::Entities::encode(&Apache::edit::insert_essayresponse())) . "\')", &mt("Essay"), undef]
1542: ],
1543: &mt("Text"),
1544: undef
1545: ];
1546:
1547: return [$mathCat, $miscCat, $chemCat, $textCat];
1548: }
1549:
1550:
1551: sub conditional_scripting_datastructure {
1552: # TODO: corresponding routines should be used for the javascript:insertText parts
1553: # instead of the placeholder routine default_xml_tag with the tags
1554: # e.g. &default_xml_tag("postanswerdate") should be replaced with a routine which
1555: # returns the corresponding content for this case
1556:
1557: #TODO translated is currently temporarily here, another solution should be found where the
1558: # needed string can be retrieved
1559:
1560: my $translatedTag = '
1561: <translated>
1562: <lang which="en"></lang>
1563: <lang which="default"></lang>
1564: </translated>';
1565: return [
1566: ["javascript:insertText(\'" . &convert_for_js(&HTML::Entities::encode($translatedTag)) . "\')", &mt("Translated Block"), undef],
1567: ["javascript:insertText(\'" . &convert_for_js(&HTML::Entities::encode(&default_xml_tag("block"))) . "\')", &mt("Conditional Block"), undef],
1568: ["javascript:insertText(\'" . &convert_for_js(&HTML::Entities::encode(&default_xml_tag("postanswerdate"))) . "\')", &mt("After Answer Date Block"), undef],
1569: ["javascript:insertText(\'" . &convert_for_js(&HTML::Entities::encode(&default_xml_tag("preduedate"))) . "\')", &mt("Before Due Date Block"), undef],
1570: ["javascript:insertText(\'" . &convert_for_js(&HTML::Entities::encode(&default_xml_tag("solved"))) . "\')", &mt("Block For After Solved"), undef],
1571: ["javascript:insertText(\'" . &convert_for_js(&HTML::Entities::encode(&default_xml_tag("notsolved"))) . "\')", &mt("Block For When Not Solved"), undef]
1572: ];
1573: }
1574:
1575: sub misc_datastructure {
1576: return [
1577: ["javascript:insertText(\'" . &convert_for_js(&HTML::Entities::encode(&Apache::edit::insert_img())) . "\')", &mt("Image"), undef],
1578: ["javascript:insertText(\'" . &convert_for_js(&HTML::Entities::encode(&Apache::lonplot::insert_gnuplot())) . "\')", &mt("GNU Plot"), undef],
1579: ["javascript:insertText(\'" . &convert_for_js(&HTML::Entities::encode(&Apache::edit::insert_organicstructure())) . "\')", &mt("Organic Structure"), undef],
1580: ["javascript:insertText(\'" . &convert_for_js(&HTML::Entities::encode(&Apache::edit::insert_script())) . "\')", &mt("Script Block"), undef],
1581: ["javascript:insertText(\'" . &convert_for_js(&HTML::Entities::encode(&default_xml_tag("allow"))) . "\')", &mt("File Dependencies"), undef],
1582: ["javascript:insertText(\'" . &convert_for_js(&HTML::Entities::encode(&default_xml_tag("import"))) . "\')", &mt("Import a File"), undef],
1.353 droeschl 1583: ["javascript:insertText(\'" . &convert_for_js(&HTML::Entities::encode(&Apache::londefdef::insert_meta())) . "\')", &mt("Custom Metadata"), undef],
1584: ["javascript:insertText(\'" . &convert_for_js(&HTML::Entities::encode(&default_xml_tag("part"))) . "\')", &mt("Problem Part"), undef]
1.352 droeschl 1585: ];
1586: }
1587:
1588: # helper routine for the datastructure building subroutines
1589: sub default_xml_tag {
1590: my ($tag) = @_;
1591: return "\n<$tag></$tag>";
1592: }
1593:
1594:
1595: sub helpmenu_datastructure {
1596:
1597: my $width = 500;
1598: my $height = 600;
1599:
1600: my $helpers = [
1601: ['Problem_LON-CAPA_Functions', &mt('Script Functions')],
1602: ['Greek_Symbols', &mt('Greek Symbols')],
1603: ['Other_Symbols', &mt('Other Symbols')],
1604: ['Authoring_Output_Tags', &mt('Output Tags')],
1605: ['Authoring_Multilingual_Problems',
1606: &mt('How to create problems in different languages')]
1607: ];
1608:
1609: my $help_structure = [];
1610:
1611: foreach my $count (0..(scalar(@{$helpers})-1)) {
1612: my $filename = $helpers->[$count]->[0];
1613: my $title = $helpers->[$count]->[1];
1614: my $href = &HTML::Entities::encode("javascript:openMyModal('/adm/help/$filename.hlp',$width,$height,'yes');");
1615: push @{$help_structure}, [$href, $title, undef];
1616: }
1617:
1618: return $help_structure;
1619: }
1620:
1621: # we need substitution to not break javascript code
1622: sub convert_for_js {
1623: my $return = shift;
1624: $return =~ s|script|ESCAPEDSCRIPT|g;
1625: $return =~ s|\\|\\\\|g;
1626: $return =~ s|\n|\\r\\n|g;
1627: $return =~ s|'|\\'|g;
1628: $return =~ s|'|\\'|g;
1629: return $return;
1630: }
1631:
1.1 albertel 1632: 1;
1633: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>