Annotation of loncom/interface/lonparmset.pm, revision 1.500
1.1 www 1: # The LearningOnline Network with CAPA
2: # Handler to set parameters for assessments
3: #
1.500 ! raeburn 4: # $Id: lonparmset.pm,v 1.499 2010/07/01 00:08:28 raeburn Exp $
1.40 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: #
1.59 matthew 28: ###################################################################
29: ###################################################################
30:
31: =pod
32:
33: =head1 NAME
34:
35: lonparmset - Handler to set parameters for assessments and course
36:
37: =head1 SYNOPSIS
38:
39: lonparmset provides an interface to setting course parameters.
40:
41: =head1 DESCRIPTION
42:
43: This module sets coursewide and assessment parameters.
44:
45: =head1 INTERNAL SUBROUTINES
46:
1.416 jms 47: =over
1.59 matthew 48:
49: =pod
50:
1.416 jms 51: =item parmval()
1.59 matthew 52:
53: Figure out a cascading parameter.
54:
1.71 albertel 55: Inputs: $what - a parameter spec (incluse part info and name I.E. 0.weight)
1.162 albertel 56: $id - a bighash Id number
1.71 albertel 57: $def - the resource's default value 'stupid emacs
58:
1.269 raeburn 59: Returns: A list, the first item is the index into the remaining list of items of parm valuse that is the active one, the list consists of parm values at the 14 possible levels
1.71 albertel 60:
1.306 albertel 61: 14- General Course
62: 13- Map or Folder level in course
1.269 raeburn 63: 12- resource default
64: 11- map default
1.306 albertel 65: 10- resource level in course
1.269 raeburn 66: 9 - General for section
67: 8 - Map or Folder level for section
68: 7 - resource level in section
69: 6 - General for group
70: 5 - Map or Folder level for group
71: 4 - resource level in group
1.71 albertel 72: 3 - General for specific student
1.82 www 73: 2 - Map or Folder level for specific student
1.71 albertel 74: 1 - resource level for specific student
1.2 www 75:
1.416 jms 76: =item parmval_by_symb()
77:
78: =item reset_caches()
79:
80: =item cacheparmhash()
81:
82: =item parmhash()
83:
84: =item symbcache()
85:
86: =item preset_defaults()
87:
88: =item date_sanity_info()
89:
90: =item storeparm()
91:
92: Store a parameter by symb
93:
94: Takes
95: - symb
96: - name of parameter
97: - level
98: - new value
99: - new type
100: - username
101: - userdomain
102:
103: =item log_parmset()
104:
105: =item storeparm_by_symb_inner()
106:
107: =item valout()
108:
109: Format a value for output.
110:
111: Inputs: $value, $type, $editable
112:
113: Returns: $value, formatted for output. If $type indicates it is a date,
114: localtime($value) is returned.
115: $editable will return an icon to click on
116:
117: =item plink()
118:
119: Produces a link anchor.
120:
121: Inputs: $type,$dis,$value,$marker,$return,$call
122:
123: Returns: scalar with html code for a link which will envoke the
124: javascript function 'pjump'.
125:
126: =item page_js()
127:
128: =item startpage()
129:
130: =item print_row()
131:
132: =item print_td()
133:
134: =item print_usergroups()
135:
136: =item parm_control_group()
137:
138: =item extractResourceInformation() :
139:
140: Given the course data hash, extractResourceInformation extracts lots of information about the course's resources into a variety of hashes.
141:
142: Input: See list below:
143:
144: =item * B<ids> : An array that will contain all of the ids in the course.
145:
146: =item * B<typep> : hash, id->type, where "type" contains the extension of the file, thus, I<problem exam quiz assess survey form>.
147:
148: =item * B<keyp> : hash, id->key list, will contain a comma separated list of the meta-data keys available for the given id
149:
150: =item * B<allparms> : hash, name of parameter->display value (what is the display value?)
151:
152: =item * B<allparts> : hash, part identification->text representation of part, where the text representation is "[Part $part]"
153:
154: =item * B<allkeys> : hash, full key to part->display value (what's display value?)
155:
156: =item * B<allmaps> : hash, ???
157:
158: =item * B<fcat> : ???
159:
160: =item * B<defp> : hash, ???
161:
162: =item * B<mapp> : ??
163:
164: =item * B<symbp> : hash, id->full sym?
165:
166:
167:
168: =item isdateparm()
169:
170: =item parmmenu()
171:
172: =item partmenu()
173:
174: =item usermenu()
175:
176: =item displaymenu()
177:
178: =item mapmenu()
179:
180: =item levelmenu()
181:
182: =item sectionmenu()
183:
184: =item keysplit()
185:
186: =item keysinorder()
187:
188: =item keysinorder_bytype()
189:
190: =item keysindisplayorder()
191:
192: =item standardkeyorder()
193:
194: =item assessparms() :
195:
196: Show assessment data and parameters. This is a large routine that should
197: be simplified and shortened... someday.
198:
199: Inputs: $r
200:
201: Returns: nothing
202:
203: Variables used (guessed by Jeremy):
204:
205: =item * B<pscat>: ParameterS CATegories? ends up a list of the types of parameters that exist, e.g., tol, weight, acc, opendate, duedate, answerdate, sig, maxtries, type.
206:
207: =item * B<psprt>: ParameterS PaRTs? a list of the parts of a problem that we are displaying? Used to display only selected parts?
208:
209: =item * B<@catmarker> contains list of all possible parameters including part #s
210:
211: =item * B<$fullkeyp> contains the full part/id # for the extraction of proper parameters
212:
213: =item * B<$tempkeyp> contains part 0 only (no ids - ie, subparts)
214: When storing information, store as part 0
215: When requesting information, request from full part
216:
217: =item tablestart()
218:
219: =item tableend()
220:
221: =item extractuser()
222:
223: =item parse_listdata_key()
224:
225: =item listdata()
226:
227: =item date_interval_selector()
228:
229: =item get_date_interval_from_form()
230:
231: =item default_selector()
232:
233: =item string_selector()
234:
235: =item dateshift()
236:
237: =item newoverview()
238:
239: =item secgroup_lister()
240:
241: =item overview()
242:
243: =item clean_parameters()
244:
245: =item date_shift_one()
246:
247: =item date_shift_two()
248:
249: =item parse_key()
250:
251: =item header()
252:
253: Output html header for page
254:
255: =item print_main_menu()
256:
257: =item output_row()
258:
259: Set portfolio metadata
260:
261: =item order_meta_fields()
262:
263: =item addmetafield()
264:
265: =item setrestrictmeta()
266:
267: =item get_added_meta_fieldnames()
268:
269: =item get_deleted_meta_fieldnames()
270:
271: =item defaultsetter()
272:
273: =item components()
274:
275: =item load_parameter_names()
276:
277: =item parm_change_log()
278:
279: =item handler() :
280:
1.450 raeburn 281: Main handler. Calls &assessparms subroutine.
1.416 jms 282:
283:
284: =back
285:
1.59 matthew 286: =cut
287:
1.416 jms 288: ###################################################################
289: ###################################################################
290:
291: package Apache::lonparmset;
292:
293: use strict;
294: use Apache::lonnet;
295: use Apache::Constants qw(:common :http REDIRECT);
296: use Apache::lonhtmlcommon();
297: use Apache::loncommon;
298: use GDBM_File;
299: use Apache::lonhomework;
300: use Apache::lonxml;
301: use Apache::lonlocal;
302: use Apache::lonnavmaps;
303: use Apache::longroup;
304: use Apache::lonrss;
305: use LONCAPA qw(:DEFAULT :match);
306:
307:
1.2 www 308: sub parmval {
1.275 raeburn 309: my ($what,$id,$def,$uname,$udom,$csec,$cgroup,$courseopt)=@_;
310: return &parmval_by_symb($what,&symbcache($id),$def,$uname,$udom,$csec,
311: $cgroup,$courseopt);
1.201 www 312: }
313:
314: sub parmval_by_symb {
1.275 raeburn 315: my ($what,$symb,$def,$uname,$udom,$csec,$cgroup,$courseopt)=@_;
1.200 www 316:
1.352 albertel 317: my $useropt;
318: if ($uname ne '' && $udom ne '') {
1.473 amueller 319: $useropt = &Apache::lonnet::get_userresdata($uname,$udom);
1.352 albertel 320: }
1.200 www 321:
1.8 www 322: my $result='';
1.44 albertel 323: my @outpar=();
1.2 www 324: # ----------------------------------------------------- Cascading lookup scheme
1.446 bisitz 325: my $map=(&Apache::lonnet::decode_symb($symb))[0];
1.305 albertel 326: $map = &Apache::lonnet::deversion($map);
1.10 www 327:
1.201 www 328: my $symbparm=$symb.'.'.$what;
329: my $mapparm=$map.'___(all).'.$what;
1.10 www 330:
1.269 raeburn 331: my $grplevel=$env{'request.course.id'}.'.['.$cgroup.'].'.$what;
332: my $grplevelr=$env{'request.course.id'}.'.['.$cgroup.'].'.$symbparm;
333: my $grplevelm=$env{'request.course.id'}.'.['.$cgroup.'].'.$mapparm;
334:
1.190 albertel 335: my $seclevel=$env{'request.course.id'}.'.['.$csec.'].'.$what;
336: my $seclevelr=$env{'request.course.id'}.'.['.$csec.'].'.$symbparm;
337: my $seclevelm=$env{'request.course.id'}.'.['.$csec.'].'.$mapparm;
338:
339: my $courselevel=$env{'request.course.id'}.'.'.$what;
340: my $courselevelr=$env{'request.course.id'}.'.'.$symbparm;
341: my $courselevelm=$env{'request.course.id'}.'.'.$mapparm;
1.2 www 342:
1.11 www 343:
1.182 albertel 344: # --------------------------------------------------------- first, check course
1.11 www 345:
1.200 www 346: if (defined($$courseopt{$courselevel})) {
1.473 amueller 347: $outpar[14]=$$courseopt{$courselevel};
348: $result=14;
1.43 albertel 349: }
1.11 www 350:
1.200 www 351: if (defined($$courseopt{$courselevelm})) {
1.473 amueller 352: $outpar[13]=$$courseopt{$courselevelm};
353: $result=13;
1.43 albertel 354: }
1.11 www 355:
1.182 albertel 356: # ------------------------------------------------------- second, check default
357:
1.269 raeburn 358: if (defined($def)) { $outpar[12]=$def; $result=12; }
1.182 albertel 359:
360: # ------------------------------------------------------ third, check map parms
361:
1.376 albertel 362: my $thisparm=&parmhash($symbparm);
1.269 raeburn 363: if (defined($thisparm)) { $outpar[11]=$thisparm; $result=11; }
1.182 albertel 364:
1.200 www 365: if (defined($$courseopt{$courselevelr})) {
1.473 amueller 366: $outpar[10]=$$courseopt{$courselevelr};
367: $result=10;
1.43 albertel 368: }
1.11 www 369:
1.182 albertel 370: # ------------------------------------------------------ fourth, back to course
1.352 albertel 371: if ($csec ne '') {
1.200 www 372: if (defined($$courseopt{$seclevel})) {
1.473 amueller 373: $outpar[9]=$$courseopt{$seclevel};
374: $result=9;
375: }
1.200 www 376: if (defined($$courseopt{$seclevelm})) {
1.473 amueller 377: $outpar[8]=$$courseopt{$seclevelm};
378: $result=8;
379: }
1.43 albertel 380:
1.200 www 381: if (defined($$courseopt{$seclevelr})) {
1.473 amueller 382: $outpar[7]=$$courseopt{$seclevelr};
383: $result=7;
384: }
1.43 albertel 385: }
1.275 raeburn 386: # ------------------------------------------------------ fifth, check course group
1.352 albertel 387: if ($cgroup ne '') {
1.269 raeburn 388: if (defined($$courseopt{$grplevel})) {
389: $outpar[6]=$$courseopt{$grplevel};
390: $result=6;
391: }
392: if (defined($$courseopt{$grplevelm})) {
393: $outpar[5]=$$courseopt{$grplevelm};
394: $result=5;
395: }
396: if (defined($$courseopt{$grplevelr})) {
397: $outpar[4]=$$courseopt{$grplevelr};
398: $result=4;
399: }
400: }
1.11 www 401:
1.182 albertel 402: # ---------------------------------------------------------- fifth, check user
1.11 www 403:
1.352 albertel 404: if ($uname ne '') {
1.473 amueller 405: if (defined($$useropt{$courselevel})) {
406: $outpar[3]=$$useropt{$courselevel};
407: $result=3;
408: }
409:
410: if (defined($$useropt{$courselevelm})) {
411: $outpar[2]=$$useropt{$courselevelm};
412: $result=2;
413: }
414:
415: if (defined($$useropt{$courselevelr})) {
416: $outpar[1]=$$useropt{$courselevelr};
417: $result=1;
418: }
1.43 albertel 419: }
1.44 albertel 420: return ($result,@outpar);
1.2 www 421: }
422:
1.198 www 423:
424:
1.376 albertel 425: # --- Caches local to lonparmset
426:
1.446 bisitz 427:
1.376 albertel 428: sub reset_caches {
429: &resetparmhash();
430: &resetsymbcache();
431: &resetrulescache();
1.203 www 432: }
433:
1.376 albertel 434: {
435: my $parmhashid;
436: my %parmhash;
437: sub resetparmhash {
1.473 amueller 438: undef($parmhashid);
439: undef(%parmhash);
1.376 albertel 440: }
1.446 bisitz 441:
1.376 albertel 442: sub cacheparmhash {
1.473 amueller 443: if ($parmhashid eq $env{'request.course.fn'}) { return; }
444: my %parmhashfile;
445: if (tie(%parmhashfile,'GDBM_File',
446: $env{'request.course.fn'}.'_parms.db',&GDBM_READER(),0640)) {
447: %parmhash=%parmhashfile;
448: untie(%parmhashfile);
449: $parmhashid=$env{'request.course.fn'};
450: }
1.201 www 451: }
1.446 bisitz 452:
1.376 albertel 453: sub parmhash {
1.473 amueller 454: my ($id) = @_;
455: &cacheparmhash();
456: return $parmhash{$id};
1.376 albertel 457: }
458: }
459:
1.446 bisitz 460: {
1.376 albertel 461: my $symbsid;
462: my %symbs;
463: sub resetsymbcache {
1.473 amueller 464: undef($symbsid);
465: undef(%symbs);
1.376 albertel 466: }
1.446 bisitz 467:
1.376 albertel 468: sub symbcache {
1.473 amueller 469: my $id=shift;
470: if ($symbsid ne $env{'request.course.id'}) {
471: undef(%symbs);
472: }
473: if (!$symbs{$id}) {
474: my $navmap = Apache::lonnavmaps::navmap->new();
475: if ($id=~/\./) {
476: my $resource=$navmap->getById($id);
477: $symbs{$id}=$resource->symb();
478: } else {
479: my $resource=$navmap->getByMapPc($id);
480: $symbs{$id}=&Apache::lonnet::declutter($resource->src());
481: }
482: $symbsid=$env{'request.course.id'};
483: }
484: return $symbs{$id};
1.201 www 485: }
1.376 albertel 486: }
1.201 www 487:
1.446 bisitz 488: {
1.376 albertel 489: my $rulesid;
490: my %rules;
491: sub resetrulescache {
1.473 amueller 492: undef($rulesid);
493: undef(%rules);
1.376 albertel 494: }
1.446 bisitz 495:
1.376 albertel 496: sub rulescache {
1.473 amueller 497: my $id=shift;
498: if ($rulesid ne $env{'request.course.id'}
499: && !defined($rules{$id})) {
500: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
501: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
502: %rules=&Apache::lonnet::dump('parmdefactions',$dom,$crs);
503: $rulesid=$env{'request.course.id'};
504: }
505: return $rules{$id};
1.221 www 506: }
507: }
508:
1.416 jms 509:
510:
1.229 www 511: sub preset_defaults {
512: my $type=shift;
513: if (&rulescache($type.'_action') eq 'default') {
514: # yes, there is something
1.473 amueller 515: return (&rulescache($type.'_hours'),
516: &rulescache($type.'_min'),
517: &rulescache($type.'_sec'),
518: &rulescache($type.'_value'));
1.229 www 519: } else {
520: # nothing there or something else
1.473 amueller 521: return ('','','','','');
1.229 www 522: }
523: }
524:
1.416 jms 525:
526:
1.277 www 527:
528: sub date_sanity_info {
529: my $checkdate=shift;
530: unless ($checkdate) { return ''; }
531: my $result='';
532: my $crsprefix='course.'.$env{'request.course.id'}.'.';
533: if ($env{$crsprefix.'default_enrollment_end_date'}) {
534: if ($checkdate>$env{$crsprefix.'default_enrollment_end_date'}) {
1.413 bisitz 535: $result.='<div class="LC_warning">'
536: .&mt('After course enrollment end!')
537: .'</div>';
1.277 www 538: }
539: }
540: if ($env{$crsprefix.'default_enrollment_start_date'}) {
541: if ($checkdate<$env{$crsprefix.'default_enrollment_start_date'}) {
1.413 bisitz 542: $result.='<div class="LC_warning">'
543: .&mt('Before course enrollment start!')
544: .'</div>';
1.277 www 545: }
546: }
1.413 bisitz 547: # Preparation for additional warnings about dates in the past/future.
548: # An improved, more context sensitive version is recommended,
549: # e.g. warn for due and answer dates which are defined before the corresponding open date, etc.
550: # if ($checkdate<time) {
551: # $result.='<div class="LC_info">'
552: # .'('.&mt('in the past').')'
553: # .'</div>';
554: # }
555: # if ($checkdate>time) {
556: # $result.='<div class="LC_info">'
557: # .'('.&mt('in the future').')'
558: # .'</div>';
559: # }
1.277 www 560: return $result;
561: }
562: ##################################################
1.186 www 563: ##################################################
564: #
1.197 www 565: # Store a parameter by ID
1.186 www 566: #
567: # Takes
568: # - resource id
569: # - name of parameter
570: # - level
571: # - new value
572: # - new type
1.187 www 573: # - username
574: # - userdomain
575:
1.186 www 576: sub storeparm {
1.269 raeburn 577: my ($sresid,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$cgroup)=@_;
1.275 raeburn 578: &storeparm_by_symb(&symbcache($sresid),$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,'',$cgroup);
1.197 www 579: }
580:
1.226 www 581: my %recstack;
1.197 www 582: sub storeparm_by_symb {
1.275 raeburn 583: my ($symb,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$recflag,$cgroup)=@_;
1.226 www 584: unless ($recflag) {
585: # first time call
1.473 amueller 586: %recstack=();
587: $recflag=1;
1.226 www 588: }
589: # store parameter
590: &storeparm_by_symb_inner
1.473 amueller 591: ($symb,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$cgroup);
1.266 www 592: # don't do anything if parameter was reset
593: unless ($nval) { return; }
1.226 www 594: my ($prefix,$parm)=($spnam=~/^(.*[\_\.])([^\_\.]+)$/);
595: # remember that this was set
596: $recstack{$parm}=1;
597: # what does this trigger?
598: foreach my $triggered (split(/\:/,&rulescache($parm.'_triggers'))) {
599: # don't backfire
600: unless ((!$triggered) || ($recstack{$triggered})) {
1.473 amueller 601: my $action=&rulescache($triggered.'_action');
602: my ($whichaction,$whichparm)=($action=~/^(.*\_)([^\_]+)$/);
1.226 www 603: # set triggered parameter on same level
1.473 amueller 604: my $newspnam=$prefix.$triggered;
605: my $newvalue='';
606: my $active=1;
607: if ($action=~/^when\_setting/) {
1.228 www 608: # are there restrictions?
1.473 amueller 609: if (&rulescache($triggered.'_triggervalue')=~/\w/) {
610: $active=0;
611: foreach my $possiblevalue (split(/\s*\,\s*/,&rulescache($triggered.'_triggervalue'))) {
612: if (lc($possiblevalue) eq lc($nval)) { $active=1; }
613: }
614: }
615: $newvalue=&rulescache($triggered.'_value');
616: } else {
617: my $totalsecs=((&rulescache($triggered.'_days')*24+&rulescache($triggered.'_hours'))*60+&rulescache($triggered.'_min'))*60+&rulescache($triggered.'_sec');
618: if ($action=~/^later\_than/) {
619: $newvalue=$nval+$totalsecs;
620: } else {
621: $newvalue=$nval-$totalsecs;
622: }
623: }
624: if ($active) {
625: &storeparm_by_symb($symb,$newspnam,$snum,$newvalue,&rulescache($triggered.'_type'),
626: $uname,$udom,$csec,$recflag,$cgroup);
627: }
1.226 www 628: }
629: }
630: return '';
631: }
632:
1.293 www 633: sub log_parmset {
634: return &Apache::lonnet::instructor_log('parameterlog',@_);
1.284 www 635: }
636:
1.226 www 637: sub storeparm_by_symb_inner {
1.197 www 638: # ---------------------------------------------------------- Get symb, map, etc
1.269 raeburn 639: my ($symb,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$cgroup)=@_;
1.197 www 640: # ---------------------------------------------------------- Construct prefixes
1.186 www 641: $spnam=~s/\_([^\_]+)$/\.$1/;
1.446 bisitz 642: my $map=(&Apache::lonnet::decode_symb($symb))[0];
1.305 albertel 643: $map = &Apache::lonnet::deversion($map);
644:
1.197 www 645: my $symbparm=$symb.'.'.$spnam;
646: my $mapparm=$map.'___(all).'.$spnam;
647:
1.269 raeburn 648: my $grplevel=$env{'request.course.id'}.'.['.$cgroup.'].'.$spnam;
649: my $grplevelr=$env{'request.course.id'}.'.['.$cgroup.'].'.$symbparm;
650: my $grplevelm=$env{'request.course.id'}.'.['.$cgroup.'].'.$mapparm;
651:
1.190 albertel 652: my $seclevel=$env{'request.course.id'}.'.['.$csec.'].'.$spnam;
653: my $seclevelr=$env{'request.course.id'}.'.['.$csec.'].'.$symbparm;
654: my $seclevelm=$env{'request.course.id'}.'.['.$csec.'].'.$mapparm;
1.446 bisitz 655:
1.190 albertel 656: my $courselevel=$env{'request.course.id'}.'.'.$spnam;
657: my $courselevelr=$env{'request.course.id'}.'.'.$symbparm;
658: my $courselevelm=$env{'request.course.id'}.'.'.$mapparm;
1.446 bisitz 659:
1.186 www 660: my $storeunder='';
1.269 raeburn 661: if (($snum==14) || ($snum==3)) { $storeunder=$courselevel; }
662: if (($snum==13) || ($snum==2)) { $storeunder=$courselevelm; }
663: if (($snum==10) || ($snum==1)) { $storeunder=$courselevelr; }
664: if ($snum==9) { $storeunder=$seclevel; }
665: if ($snum==8) { $storeunder=$seclevelm; }
666: if ($snum==7) { $storeunder=$seclevelr; }
667: if ($snum==6) { $storeunder=$grplevel; }
668: if ($snum==5) { $storeunder=$grplevelm; }
669: if ($snum==4) { $storeunder=$grplevelr; }
670:
1.446 bisitz 671:
1.186 www 672: my $delete;
673: if ($nval eq '') { $delete=1;}
674: my %storecontent = ($storeunder => $nval,
1.473 amueller 675: $storeunder.'.type' => $ntype);
1.186 www 676: my $reply='';
677: if ($snum>3) {
678: # ---------------------------------------------------------------- Store Course
679: #
1.473 amueller 680: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
681: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.186 www 682: # Expire sheets
1.473 amueller 683: &Apache::lonnet::expirespread('','','studentcalc');
684: if (($snum==10) || ($snum==7) || ($snum==4)) {
685: &Apache::lonnet::expirespread('','','assesscalc',$symb);
686: } elsif (($snum==11) || ($snum==8) || ($snum==5)) {
687: &Apache::lonnet::expirespread('','','assesscalc',$map);
688: } else {
689: &Apache::lonnet::expirespread('','','assesscalc');
690: }
1.186 www 691: # Store parameter
1.473 amueller 692: if ($delete) {
693: $reply=&Apache::lonnet::del
694: ('resourcedata',[keys(%storecontent)],$cdom,$cnum);
1.290 www 695: &log_parmset(\%storecontent,1);
1.473 amueller 696: } else {
697: $reply=&Apache::lonnet::cput
698: ('resourcedata',\%storecontent,$cdom,$cnum);
699: &log_parmset(\%storecontent);
700: }
701: &Apache::lonnet::devalidatecourseresdata($cnum,$cdom);
1.186 www 702: } else {
703: # ------------------------------------------------------------------ Store User
704: #
705: # Expire sheets
1.473 amueller 706: &Apache::lonnet::expirespread($uname,$udom,'studentcalc');
707: if ($snum==1) {
708: &Apache::lonnet::expirespread
709: ($uname,$udom,'assesscalc',$symb);
710: } elsif ($snum==2) {
711: &Apache::lonnet::expirespread
712: ($uname,$udom,'assesscalc',$map);
713: } else {
714: &Apache::lonnet::expirespread($uname,$udom,'assesscalc');
715: }
1.186 www 716: # Store parameter
1.473 amueller 717: if ($delete) {
718: $reply=&Apache::lonnet::del
719: ('resourcedata',[keys(%storecontent)],$udom,$uname);
720: &log_parmset(\%storecontent,1,$uname,$udom);
721: } else {
722: $reply=&Apache::lonnet::cput
723: ('resourcedata',\%storecontent,$udom,$uname);
724: &log_parmset(\%storecontent,0,$uname,$udom);
725: }
726: &Apache::lonnet::devalidateuserresdata($uname,$udom);
1.186 www 727: }
1.446 bisitz 728:
1.186 www 729: if ($reply=~/^error\:(.*)/) {
1.473 amueller 730: return "<span class=\"LC_error\">Write Error: $1</span>";
1.186 www 731: }
732: return '';
733: }
734:
1.9 www 735:
736: sub valout {
1.320 www 737: my ($value,$type,$editable)=@_;
1.59 matthew 738: my $result = '';
739: # Values of zero are valid.
740: if (! $value && $value ne '0') {
1.473 amueller 741: if ($editable) {
742: $result = '<span class="LC_clickhere">*</span>';
743: } else {
744: $result=' ';
745: }
1.59 matthew 746: } else {
1.66 www 747: if ($type eq 'date_interval') {
748: my ($sec,$min,$hour,$mday,$mon,$year)=gmtime($value);
1.413 bisitz 749: my @timer;
1.66 www 750: $year=$year-70;
751: $mday--;
752: if ($year) {
1.413 bisitz 753: # $result.=&mt('[quant,_1,yr]',$year).' ';
754: push(@timer,&mt('[quant,_1,yr]',$year));
1.66 www 755: }
756: if ($mon) {
1.413 bisitz 757: # $result.=&mt('[quant,_1,mth]',$mon).' ';
758: push(@timer,&mt('[quant,_1,mth]',$mon));
1.66 www 759: }
760: if ($mday) {
1.413 bisitz 761: # $result.=&mt('[quant,_1,day]',$mday).' ';
762: push(@timer,&mt('[quant,_1,day]',$mday));
1.66 www 763: }
764: if ($hour) {
1.413 bisitz 765: # $result.=&mt('[quant,_1,hr]',$hour).' ';
766: push(@timer,&mt('[quant,_1,hr]',$hour));
1.66 www 767: }
768: if ($min) {
1.413 bisitz 769: # $result.=&mt('[quant,_1,min]',$min).' ';
770: push(@timer,&mt('[quant,_1,min]',$min));
1.66 www 771: }
772: if ($sec) {
1.413 bisitz 773: # $result.=&mt('[quant,_1,sec]',$sec).' ';
774: push(@timer,&mt('[quant,_1,sec]',$sec));
1.66 www 775: }
1.413 bisitz 776: # $result=~s/\s+$//;
777: if (!@timer) { # Special case: all entries 0 -> display "0 secs" intead of empty field to keep this field editable
778: push(@timer,&mt('[quant,_1,sec]',0));
779: }
780: $result.=join(", ",@timer);
1.213 www 781: } elsif (&isdateparm($type)) {
1.361 albertel 782: $result = &Apache::lonlocal::locallocaltime($value).
1.473 amueller 783: &date_sanity_info($value);
1.59 matthew 784: } else {
785: $result = $value;
1.473 amueller 786: $result = &HTML::Entities::encode($result,'"<>&');
1.59 matthew 787: }
788: }
789: return $result;
1.9 www 790: }
791:
1.59 matthew 792:
1.5 www 793: sub plink {
794: my ($type,$dis,$value,$marker,$return,$call)=@_;
1.23 www 795: my $winvalue=$value;
796: unless ($winvalue) {
1.473 amueller 797: if (&isdateparm($type)) {
1.190 albertel 798: $winvalue=$env{'form.recent_'.$type};
1.23 www 799: } else {
1.190 albertel 800: $winvalue=$env{'form.recent_'.(split(/\_/,$type))[0]};
1.23 www 801: }
802: }
1.229 www 803: my ($parmname)=((split(/\&/,$marker))[1]=~/\_([^\_]+)$/);
804: my ($hour,$min,$sec,$val)=&preset_defaults($parmname);
805: unless (defined($winvalue)) { $winvalue=$val; }
1.378 albertel 806: my $valout = &valout($value,$type,1);
1.429 raeburn 807: my $unencmarker = $marker;
1.378 albertel 808: foreach my $item (\$type, \$dis, \$winvalue, \$marker, \$return, \$call,
1.473 amueller 809: \$hour, \$min, \$sec) {
810: $$item = &HTML::Entities::encode($$item,'"<>&');
811: $$item =~ s/\'/\\\'/g;
1.378 albertel 812: }
1.429 raeburn 813: return '<table width="100%"><tr valign="top" align="right"><td><a name="'.$unencmarker.'" /></td></tr><tr><td align="center">'.
1.473 amueller 814: '<a href="javascript:pjump('."'".$type."','".$dis."','".$winvalue."','"
815: .$marker."','".$return."','".$call."','".$hour."','".$min."','".$sec."'".');">'.
816: $valout.'</a></td></tr></table>';
1.5 www 817: }
818:
1.280 albertel 819: sub page_js {
820:
1.81 www 821: my $selscript=&Apache::loncommon::studentbrowser_javascript();
1.88 matthew 822: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.280 albertel 823:
824: return(<<ENDJS);
825: <script type="text/javascript">
1.454 bisitz 826: // <![CDATA[
1.44 albertel 827: function pclose() {
828: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
829: "height=350,width=350,scrollbars=no,menubar=no");
830: parmwin.close();
831: }
832:
1.88 matthew 833: $pjump_def
1.44 albertel 834:
835: function psub() {
836: pclose();
837: if (document.parmform.pres_marker.value!='') {
838: document.parmform.action+='#'+document.parmform.pres_marker.value;
839: var typedef=new Array();
840: typedef=document.parmform.pres_type.value.split('_');
841: if (document.parmform.pres_type.value!='') {
842: if (typedef[0]=='date') {
843: eval('document.parmform.recent_'+
844: document.parmform.pres_type.value+
1.473 amueller 845: '.value=document.parmform.pres_value.value;');
1.44 albertel 846: } else {
847: eval('document.parmform.recent_'+typedef[0]+
1.473 amueller 848: '.value=document.parmform.pres_value.value;');
1.44 albertel 849: }
1.473 amueller 850: }
1.44 albertel 851: document.parmform.submit();
852: } else {
853: document.parmform.pres_value.value='';
854: document.parmform.pres_marker.value='';
855: }
856: }
857:
1.57 albertel 858: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
859: var options = "width=" + w + ",height=" + h + ",";
860: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
861: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
862: var newWin = window.open(url, wdwName, options);
863: newWin.focus();
864: }
1.454 bisitz 865: // ]]>
1.44 albertel 866: </script>
1.81 www 867: $selscript
1.280 albertel 868: ENDJS
869:
870: }
871: sub startpage {
872: my ($r) = @_;
1.281 albertel 873:
1.282 albertel 874: my %loaditems = ('onunload' => "pclose()",
1.485 amueller 875: 'onload' => "showHide_courseContent(); group_or_section('cgroup')",
1.474 amueller 876: );
1.280 albertel 877:
1.414 droeschl 878: if ((($env{'form.command'} eq 'set') && ($env{'form.url'})
1.473 amueller 879: && (!$env{'form.dis'})) || ($env{'form.symb'})) {
880: &Apache::lonhtmlcommon::add_breadcrumb({help=>'Problem_Parameters',
881: text=>"Problem Parameters"});
1.414 droeschl 882: } else {
1.473 amueller 883: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=settable',
884: text=>"Table Mode",
885: help => 'Course_Setting_Parameters'});
1.414 droeschl 886: }
1.446 bisitz 887: my $start_page =
1.473 amueller 888: &Apache::loncommon::start_page('Set/Modify Course Parameters',
889: &page_js(),
890: {'add_entries' => \%loaditems,});
1.446 bisitz 891: my $breadcrumbs =
1.473 amueller 892: &Apache::lonhtmlcommon::breadcrumbs('Table Mode Parameter Setting','Table_Mode');
1.280 albertel 893: $r->print(<<ENDHEAD);
1.281 albertel 894: $start_page
1.193 albertel 895: $breadcrumbs
896: <form method="post" action="/adm/parmset?action=settable" name="parmform">
1.419 bisitz 897: <input type="hidden" value="" name="pres_value" />
898: <input type="hidden" value="" name="pres_type" />
899: <input type="hidden" value="" name="pres_marker" />
900: <input type="hidden" value="1" name="prevvisit" />
1.44 albertel 901: ENDHEAD
902: }
903:
1.209 www 904:
1.44 albertel 905: sub print_row {
1.201 www 906: my ($r,$which,$part,$name,$symbp,$rid,$default,$defaulttype,$display,$defbgone,
1.473 amueller 907: $defbgtwo,$defbgthree,$parmlev,$uname,$udom,$csec,$cgroup,$usersgroups)=@_;
1.275 raeburn 908: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
909: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
910: my $courseopt=&Apache::lonnet::get_courseresdata($cnum,$cdom);
1.66 www 911: # get the values for the parameter in cascading order
912: # empty levels will remain empty
1.44 albertel 913: my ($result,@outpar)=&parmval($$part{$which}.'.'.$$name{$which},
1.473 amueller 914: $rid,$$default{$which},$uname,$udom,$csec,$cgroup,$courseopt);
1.66 www 915: # get the type for the parameters
916: # problem: these may not be set for all levels
917: my ($typeresult,@typeoutpar)=&parmval($$part{$which}.'.'.
1.275 raeburn 918: $$name{$which}.'.type',$rid,
1.473 amueller 919: $$defaulttype{$which},$uname,$udom,$csec,$cgroup,$courseopt);
1.66 www 920: # cascade down manually
1.182 albertel 921: my $cascadetype=$$defaulttype{$which};
1.269 raeburn 922: for (my $i=14;$i>0;$i--) {
1.473 amueller 923: if ($typeoutpar[$i]) {
1.66 www 924: $cascadetype=$typeoutpar[$i];
1.473 amueller 925: } else {
1.66 www 926: $typeoutpar[$i]=$cascadetype;
927: }
928: }
1.57 albertel 929: my $parm=$$display{$which};
930:
1.203 www 931: if ($parmlev eq 'full') {
1.419 bisitz 932: $r->print('<td style="background-color:'.$defbgtwo.';" align="center">'
1.57 albertel 933: .$$part{$which}.'</td>');
1.433 raeburn 934: } else {
1.57 albertel 935: $parm=~s|\[.*\]\s||g;
936: }
1.231 www 937: my $automatic=&rulescache(($which=~/\_([^\_]+)$/)[0].'_triggers');
938: if ($automatic) {
1.473 amueller 939: $parm.='<span class="LC_warning"><br />'.&mt('Automatically sets').' '.join(', ',split(/\:/,$automatic)).'</span>';
1.231 www 940: }
1.427 bisitz 941: $r->print('<td>'.$parm.'</td>');
1.446 bisitz 942:
1.44 albertel 943: my $thismarker=$which;
944: $thismarker=~s/^parameter\_//;
945: my $mprefix=$rid.'&'.$thismarker.'&';
1.275 raeburn 946: my $effective_parm = &valout($outpar[$result],$typeoutpar[$result]);
947: my ($othergrp,$grp_parm,$controlgrp);
1.44 albertel 948:
1.57 albertel 949: if ($parmlev eq 'general') {
950:
951: if ($uname) {
1.66 www 952: &print_td($r,3,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
1.269 raeburn 953: } elsif ($cgroup) {
954: &print_td($r,6,$defbgthree,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
1.57 albertel 955: } elsif ($csec) {
1.446 bisitz 956: &print_td($r,9,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
1.57 albertel 957: } else {
1.446 bisitz 958: &print_td($r,14,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
1.57 albertel 959: }
960: } elsif ($parmlev eq 'map') {
961:
962: if ($uname) {
1.66 www 963: &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
1.269 raeburn 964: } elsif ($cgroup) {
965: &print_td($r,5,$defbgthree,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
1.57 albertel 966: } elsif ($csec) {
1.269 raeburn 967: &print_td($r,8,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
1.57 albertel 968: } else {
1.269 raeburn 969: &print_td($r,13,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
1.57 albertel 970: }
971: } else {
1.275 raeburn 972: if ($uname) {
973: if (@{$usersgroups} > 1) {
974: my ($coursereply,$grp_parm,$controlgrp);
975: ($coursereply,$othergrp,$grp_parm,$controlgrp) =
976: &print_usergroups($r,$$part{$which}.'.'.$$name{$which},
977: $rid,$cgroup,$defbgone,$usersgroups,$result,$courseopt);
978: if ($coursereply && $result > 3) {
979: if (defined($controlgrp)) {
980: if ($cgroup ne $controlgrp) {
981: $effective_parm = $grp_parm;
982: $result = 0;
983: }
984: }
985: }
986: }
987: }
1.57 albertel 988:
1.269 raeburn 989: &print_td($r,14,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
1.57 albertel 990:
1.473 amueller 991: &print_td($r,13,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
992: &print_td($r,12,'#FFDDDD',$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
993: &print_td($r,11,'#FFDDDD',$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
994: &print_td($r,10,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
995:
996: if ($csec) {
997: &print_td($r,9,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
998: &print_td($r,8,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
999: &print_td($r,7,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
1000: }
1.269 raeburn 1001:
1002: if ($cgroup) {
1003: &print_td($r,6,$defbgthree,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
1004: &print_td($r,5,$defbgthree,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
1005: &print_td($r,4,$defbgthree,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
1006: }
1.446 bisitz 1007:
1.473 amueller 1008: if ($uname) {
1.275 raeburn 1009: if ($othergrp) {
1010: $r->print($othergrp);
1011: }
1.473 amueller 1012: &print_td($r,3,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
1013: &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
1014: &print_td($r,1,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
1015: }
1.57 albertel 1016:
1017: } # end of $parmlev if/else
1.419 bisitz 1018: $r->print('<td style="background-color:#CCCCFF;" align="center">'.$effective_parm.'</td>');
1.136 albertel 1019:
1.203 www 1020: if ($parmlev eq 'full') {
1.136 albertel 1021: my $sessionval=&Apache::lonnet::EXT('resource.'.$$part{$which}.
1.201 www 1022: '.'.$$name{$which},$$symbp{$rid});
1.136 albertel 1023: my $sessionvaltype=$typeoutpar[$result];
1024: if (!defined($sessionvaltype)) { $sessionvaltype=$$defaulttype{$which}; }
1.419 bisitz 1025: $r->print('<td style="background-color:#999999;" align="center"><font color="#FFFFFF">'.
1.66 www 1026: &valout($sessionval,$sessionvaltype).' '.
1.57 albertel 1027: '</font></td>');
1.136 albertel 1028: }
1.44 albertel 1029: $r->print('</tr>');
1.57 albertel 1030: $r->print("\n");
1.44 albertel 1031: }
1.59 matthew 1032:
1.44 albertel 1033: sub print_td {
1.66 www 1034: my ($r,$which,$defbg,$result,$outpar,$mprefix,$value,$typeoutpar,$display)=@_;
1.419 bisitz 1035: $r->print('<td style="background-color:'.(($result==$which)?'#AAFFAA':$defbg).
1036: ';" align="center">');
1.437 raeburn 1037: my $nolink = 0;
1038: if ($which == 11 || $which == 12) {
1039: $nolink = 1;
1040: } elsif ($mprefix =~ /availablestudent\&$/) {
1041: if ($which > 3) {
1042: $nolink = 1;
1043: }
1044: }
1045: if ($nolink) {
1046: $r->print(&valout($$outpar[$which],$$typeoutpar[$which]));
1.114 www 1047: } else {
1.437 raeburn 1048: $r->print(&plink($$typeoutpar[$which],
1049: $$display{$value},$$outpar[$which],
1050: $mprefix."$which",'parmform.pres','psub'));
1.114 www 1051: }
1052: $r->print('</td>'."\n");
1.57 albertel 1053: }
1054:
1.275 raeburn 1055: sub print_usergroups {
1056: my ($r,$what,$rid,$cgroup,$defbg,$usersgroups,$result,$courseopt) = @_;
1057: my $courseid = $env{'request.course.id'};
1058: my $output;
1059: my $symb = &symbcache($rid);
1060: my $symbparm=$symb.'.'.$what;
1061: my $map=(&Apache::lonnet::decode_symb($symb))[0];
1062: my $mapparm=$map.'___(all).'.$what;
1063: my ($coursereply,$resultitem,$resultgroup,$resultlevel,$resulttype) =
1064: &parm_control_group($courseid,$usersgroups,$symbparm,$mapparm,$what,
1065: $courseopt);
1066: my $bgcolor = $defbg;
1067: my $grp_parm;
1.446 bisitz 1068: if (($coursereply) && ($cgroup ne $resultgroup)) {
1.275 raeburn 1069: if ($result > 3) {
1.419 bisitz 1070: $bgcolor = '#AAFFAA';
1.275 raeburn 1071: $grp_parm = &valout($coursereply,$resulttype);
1072: }
1073: $grp_parm = &valout($coursereply,$resulttype);
1.419 bisitz 1074: $output = '<td style="background-color:'.$bgcolor.';" align="center">';
1.275 raeburn 1075: if ($resultgroup && $resultlevel) {
1076: $output .= '<small><b>'.$resultgroup.'</b> ('.$resultlevel.'): </small>'.$grp_parm;
1077: } else {
1078: $output .= ' ';
1079: }
1080: $output .= '</td>';
1081: } else {
1.419 bisitz 1082: $output .= '<td style="background-color:'.$bgcolor.';"> </td>';
1.275 raeburn 1083: }
1084: return ($coursereply,$output,$grp_parm,$resultgroup);
1085: }
1086:
1087: sub parm_control_group {
1088: my ($courseid,$usersgroups,$symbparm,$mapparm,$what,$courseopt) = @_;
1089: my ($coursereply,$resultitem,$resultgroup,$resultlevel,$resulttype);
1090: my $grpfound = 0;
1091: my @levels = ($symbparm,$mapparm,$what);
1092: my @levelnames = ('resource','map/folder','general');
1093: foreach my $group (@{$usersgroups}) {
1094: if ($grpfound) { last; }
1095: for (my $i=0; $i<@levels; $i++) {
1096: my $item = $courseid.'.['.$group.'].'.$levels[$i];
1097: if (defined($$courseopt{$item})) {
1098: $coursereply = $$courseopt{$item};
1099: $resultitem = $item;
1100: $resultgroup = $group;
1101: $resultlevel = $levelnames[$i];
1102: $resulttype = $$courseopt{$item.'.type'};
1103: $grpfound = 1;
1104: last;
1105: }
1106: }
1107: }
1108: return($coursereply,$resultitem,$resultgroup,$resultlevel,$resulttype);
1109: }
1.201 www 1110:
1.63 bowersj2 1111:
1112:
1113: sub extractResourceInformation {
1114: my $ids = shift;
1115: my $typep = shift;
1116: my $keyp = shift;
1117: my $allparms = shift;
1118: my $allparts = shift;
1119: my $allmaps = shift;
1120: my $mapp = shift;
1121: my $symbp = shift;
1.82 www 1122: my $maptitles=shift;
1.196 www 1123: my $uris=shift;
1.210 www 1124: my $keyorder=shift;
1.211 www 1125: my $defkeytype=shift;
1.196 www 1126:
1.210 www 1127: my $keyordercnt=100;
1.63 bowersj2 1128:
1.196 www 1129: my $navmap = Apache::lonnavmaps::navmap->new();
1130: my @allres=$navmap->retrieveResources(undef,undef,1,undef,1);
1131: foreach my $resource (@allres) {
1.480 amueller 1132: my $id=$resource->id();
1.196 www 1133: my ($mapid,$resid)=split(/\./,$id);
1.480 amueller 1134: if ($mapid eq '0') { next; }
1135: $$ids[$#$ids+1]=$id;
1136: my $srcf=$resource->src();
1137: $srcf=~/\.(\w+)$/;
1138: $$typep{$id}=$1;
1139: $$keyp{$id}='';
1.196 www 1140: $$uris{$id}=$srcf;
1.480 amueller 1141: foreach my $key (split(/\,/,&Apache::lonnet::metadata($srcf,'allpossiblekeys'))) {
1142: next if ($key!~/^parameter_/);
1.363 albertel 1143:
1.209 www 1144: # Hidden parameters
1.480 amueller 1145: next if (&Apache::lonnet::metadata($srcf,$key.'.hidden') eq 'parm');
1.209 www 1146: #
1147: # allparms is a hash of parameter names
1148: #
1.480 amueller 1149: my $name=&Apache::lonnet::metadata($srcf,$key.'.name');
1150: if (!exists($$allparms{$name}) || $$allparms{$name} =~ m/^\s*$/ ) {
1151: my ($display,$parmdis);
1152: $display = &standard_parameter_names($name);
1153: if ($display eq '') {
1154: $display= &Apache::lonnet::metadata($srcf,$key.'.display');
1155: $parmdis = $display;
1156: $parmdis =~ s/\s*\[Part.*$//g;
1157: } else {
1158: $parmdis = &mt($display);
1159: }
1160: $$allparms{$name}=$parmdis;
1161: if (ref($defkeytype)) {
1162: $$defkeytype{$name}=
1163: &Apache::lonnet::metadata($srcf,$key.'.type');
1164: }
1165: }
1.363 albertel 1166:
1.209 www 1167: #
1168: # allparts is a hash of all parts
1169: #
1.480 amueller 1170: my $part= &Apache::lonnet::metadata($srcf,$key.'.part');
1171: $$allparts{$part} = &mt('Part: [_1]',$part);
1.209 www 1172: #
1173: # Remember all keys going with this resource
1174: #
1.480 amueller 1175: if ($$keyp{$id}) {
1176: $$keyp{$id}.=','.$key;
1177: } else {
1178: $$keyp{$id}=$key;
1179: }
1.210 www 1180: #
1181: # Put in order
1.446 bisitz 1182: #
1.480 amueller 1183: unless ($$keyorder{$key}) {
1184: $$keyorder{$key}=$keyordercnt;
1185: $keyordercnt++;
1186: }
1.473 amueller 1187: }
1188:
1189:
1.480 amueller 1190: if (!exists($$mapp{$mapid})) {
1191: $$mapp{$id}=
1192: &Apache::lonnet::declutter($resource->enclosing_map_src());
1193: $$mapp{$mapid}=$$mapp{$id};
1194: $$allmaps{$mapid}=$$mapp{$id};
1195: if ($mapid eq '1') {
1196: $$maptitles{$mapid}=&mt('Main Course Documents');
1197: } else {
1198: $$maptitles{$mapid}=&Apache::lonnet::gettitle($$mapp{$id});
1199: }
1200: $$maptitles{$$mapp{$id}}=$$maptitles{$mapid};
1201: $$symbp{$mapid}=$$mapp{$id}.'___(all)';
1.473 amueller 1202: } else {
1.480 amueller 1203: $$mapp{$id} = $$mapp{$mapid};
1.473 amueller 1204: }
1.480 amueller 1205: $$symbp{$id}=&Apache::lonnet::encode_symb($$mapp{$id},$resid,$srcf);
1.63 bowersj2 1206: }
1207: }
1208:
1.208 www 1209:
1210:
1.213 www 1211: sub isdateparm {
1212: my $type=shift;
1213: return (($type=~/^date/) && (!($type eq 'date_interval')));
1214: }
1215:
1.468 amueller 1216: #
1217: # This function prints a list of parameters, which were selected. It also display a link from which you can
1218: # hide or show the complete parameter list, from which you can choose your parameters.
1219: #
1.208 www 1220: sub parmmenu {
1.211 www 1221: my ($r,$allparms,$pscat,$keyorder)=@_;
1.208 www 1222: my $tempkey;
1223: $r->print(<<ENDSCRIPT);
1224: <script type="text/javascript">
1.454 bisitz 1225: // <![CDATA[
1.208 www 1226: function checkall(value, checkName) {
1.453 schualex 1227:
1228: var li = "_li";
1229: var displayOverview = "";
1230:
1231: if (value == false) {
1232: displayOverview = "none"
1233: }
1234:
1.473 amueller 1235: for (i=0; i<document.forms.parmform.elements.length; i++) {
1.208 www 1236: ele = document.forms.parmform.elements[i];
1237: if (ele.name == checkName) {
1238: document.forms.parmform.elements[i].checked=value;
1.453 schualex 1239: document.getElementById(document.forms.parmform.elements[i].value.concat(li)).style.display = displayOverview;
1.208 www 1240: }
1241: }
1242: }
1.210 www 1243:
1244: function checkthis(thisvalue, checkName) {
1.458 schualex 1245:
1246: document.getElementById(thisvalue.concat("_li")).style.display = "";
1247:
1.473 amueller 1248: for (i=0; i<document.forms.parmform.elements.length; i++) {
1.210 www 1249: ele = document.forms.parmform.elements[i];
1250: if (ele.name == checkName) {
1.473 amueller 1251: if (ele.value == thisvalue) {
1252: document.forms.parmform.elements[i].checked=true;
1253: }
1.210 www 1254: }
1255: }
1256: }
1257:
1258: function checkdates() {
1.473 amueller 1259: checkthis('duedate','pscat');
1260: checkthis('opendate','pscat');
1261: checkthis('answerdate','pscat');
1.218 www 1262: }
1263:
1264: function checkdisset() {
1.473 amueller 1265: checkthis('discussend','pscat');
1266: checkthis('discusshide','pscat');
1.218 www 1267: }
1268:
1269: function checkcontdates() {
1.473 amueller 1270: checkthis('contentopen','pscat');
1271: checkthis('contentclose','pscat');
1.218 www 1272: }
1.446 bisitz 1273:
1.210 www 1274: function checkvisi() {
1.473 amueller 1275: checkthis('hiddenresource','pscat');
1276: checkthis('encrypturl','pscat');
1277: checkthis('problemstatus','pscat');
1278: checkthis('contentopen','pscat');
1279: checkthis('opendate','pscat');
1.210 www 1280: }
1281:
1282: function checkparts() {
1.473 amueller 1283: checkthis('hiddenparts','pscat');
1284: checkthis('display','pscat');
1285: checkthis('ordered','pscat');
1.210 www 1286: }
1287:
1288: function checkstandard() {
1289: checkall(false,'pscat');
1.473 amueller 1290: checkdates();
1291: checkthis('weight','pscat');
1292: checkthis('maxtries','pscat');
1.210 www 1293: }
1294:
1.453 schualex 1295: function hideParms() {
1296: document.getElementById('LC_parm_overview_parm_menu').style.display = "none";
1297: }
1298:
1299: function showParms() {
1300: document.getElementById('LC_parm_overview_parm_menu').style.display = "";
1301: }
1302:
1303: function checkboxChecked(id) {
1304: var li = "_li";
1305: var id_li = id.concat(li);
1306: if (document.getElementById(id_li).style.display == "none") {
1307: document.getElementById(id_li).style.display = "";
1308: }
1309: else {
1310: document.getElementById(id_li).style.display = "none";
1311: }
1312: }
1.454 bisitz 1313: // ]]>
1.208 www 1314: </script>
1315: ENDSCRIPT
1.445 neumanie 1316: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Select Parameters to View')));
1.453 schualex 1317:
1318: #part to print selected parms overview
1.454 bisitz 1319: $r->print(&mt('Selected Parameters:').'<br />');
1320:
1321: #print out all possible parms and hide them by default
1322: $r->print('<ul>');
1.453 schualex 1323: foreach $tempkey (&keysindisplayorder($allparms,$keyorder)) {
1324: $r->print('<li id="'.$tempkey.'_li" value="'.$tempkey.'_li" name="pscat_li"');
1325: if (!($$pscat[0] eq "all" || grep $_ eq $tempkey, @{$pscat})) {
1.454 bisitz 1326: $r->print(' style="display:none"');
1.453 schualex 1327: }
1.460 bisitz 1328: $r->print('>'
1.457 schualex 1329: .($$allparms{$tempkey}=~/\S/ ? $$allparms{$tempkey} : $tempkey)
1.454 bisitz 1330: .'</li>'
1331: );
1332: }
1.491 bisitz 1333: $r->print('</ul>');
1.453 schualex 1334:
1.491 bisitz 1335: $r->print('<hr />');
1.453 schualex 1336: &shortCuts($r,$allparms,$pscat,$keyorder);
1.491 bisitz 1337: $r->print('<hr />');
1338:
1339: $r->print(
1340: '<p><a href="javascript:showParms()">'
1341: .&mt('Show detailed Parameter Selection')
1342: .'</a></p>'
1343: );
1.453 schualex 1344:
1.454 bisitz 1345: $r->print(&Apache::lonhtmlcommon::row_closure(1));
1.453 schualex 1346: }
1.465 amueller 1347: # return a hash
1348: sub categories {
1349: return ('time_settings' => 'Time Settings',
1350: 'grading' => 'Grading',
1351: 'tries' => 'Tries',
1352: 'problem_appearance' => 'Problem Appearance',
1353: 'behaviour_of_input_fields' => 'Behaviour of Input Fields',
1354: 'hiding' => 'Hiding',
1355: 'high_level_randomization' => 'High Level Randomization',
1356: 'slots' => 'Slots',
1357: 'file_submission' => 'File Submission',
1358: 'misc' => 'Miscellaneous' );
1359: }
1360:
1361: # return a hash. Like a look-up table
1362: sub lookUpTableParameter {
1363:
1364: return (
1365: 'opendate' => 'time_settings',
1366: 'duedate' => 'time_settings',
1367: 'answerdate' => 'time_settings',
1368: 'interval' => 'time_settings',
1369: 'contentopen' => 'time_settings',
1370: 'contentclose' => 'time_settings',
1371: 'discussend' => 'time_settings',
1372: 'weight' => 'grading',
1373: 'handgrade' => 'grading',
1374: 'maxtries' => 'tries',
1375: 'hinttries' => 'tries',
1376: 'type' => 'problem_appearance',
1377: 'problemstatus' => 'problem_appearance',
1378: 'display' => 'problem_appearance',
1379: 'ordered' => 'problem_appearance',
1380: 'numbubbles' => 'problem_appearance',
1381: 'tol' => 'behaviour_of_input_fields',
1382: 'sig' => 'behaviour_of_input_fields',
1383: 'turnoffunit' => 'behaviour_of_input_fields',
1384: 'hiddenresource' => 'hiding',
1385: 'hiddenparts' => 'hiding',
1386: 'discusshide' => 'hiding',
1387: 'buttonshide' => 'hiding',
1388: 'turnoffeditor' => 'hiding',
1389: 'encrypturl' => 'hiding',
1390: 'randomorder' => 'high_level_randomization',
1391: 'randompick' => 'high_level_randomization',
1392: 'available' => 'slots',
1393: 'useslots' => 'slots',
1394: 'availablestudent' => 'slots',
1395: 'uploadedfiletypes' => 'file_submission',
1396: 'maxfilesize' => 'file_submission',
1397: 'cssfile' => 'misc',
1398: 'mapalias' => 'misc',
1399: 'acc' => 'misc',
1400: 'maxcollaborators' => 'misc',
1401: 'scoreformat' => 'misc',
1402:
1403: );
1404: }
1405:
1406: sub whatIsMyCategory {
1407: my $name = shift;
1408: my $catList = shift;
1409: my @list;
1410: my %lookUpList = &lookUpTableParameter; #Initilize the lookupList
1411: my $cat = $lookUpList{$name};
1412: if (defined($cat)) {
1413: if (!defined($$catList{$cat})){
1414: push @list, ($name);
1415: $$catList{$cat} = \@list;
1416: } else {
1417: push @{${$catList}{$cat}}, ($name);
1418: }
1419: } else {
1420: if (!defined($$catList{'misc'})){
1421: push @list, ($name);
1422: $$catList{'misc'} = \@list;
1423: } else {
1424: push @{${$catList}{'misc'}}, ($name);
1425: }
1426: }
1427: }
1428:
1429: sub keysindisplayorderCategory {
1430: my ($name,$keyorder)=@_;
1431: return sort {
1.473 amueller 1432: $$keyorder{'parameter_0_'.$a} <=> $$keyorder{'parameter_0_'.$b};
1.465 amueller 1433: } ( @{$name});
1434: }
1435:
1.467 amueller 1436: sub category_order {
1437: return (
1438: 'time_settings' => 1,
1439: 'grading' => 2,
1440: 'tries' => 3,
1441: 'problem_appearance' => 4,
1442: 'hiding' => 5,
1443: 'behaviour_of_input_fields' => 6,
1444: 'high_level_randomization' => 7,
1445: 'slots' => 8,
1446: 'file_submission' => 9,
1447: 'misc' => 10
1448: );
1449:
1450: }
1.453 schualex 1451:
1452: sub parmboxes {
1453: my ($r,$allparms,$pscat,$keyorder)=@_;
1454: my $tempkey;
1.465 amueller 1455: my $tempparameter;
1456: my %categories = &categories;
1.467 amueller 1457: my %category_order = &category_order();
1.465 amueller 1458: my %categoryList = (
1459: 'time_settings' => [],
1460: 'grading' => [],
1461: 'tries' => [],
1462: 'problem_appearance' => [],
1463: 'behaviour_of_input_fields' => [],
1464: 'hiding' => [],
1465: 'high_level_randomization' => [],
1466: 'slots' => [],
1467: 'file_submission' => [],
1468: 'misc' => [],
1.489 bisitz 1469: );
1470: my $hidelink =
1471: '<p>'
1472: .'<a href="javascript:hideParms()">'
1473: .&mt('Hide detailed Parameter Selection')
1474: .'</a>'
1475: .'</p>'
1476: ."\n";
1477: ;
1.465 amueller 1478: foreach $tempparameter (keys %$allparms) {
1479: &whatIsMyCategory($tempparameter, \%categoryList);
1480: }
1.453 schualex 1481: #part to print the parm-list
1.489 bisitz 1482: $r->print(
1483: '<div id="LC_parm_overview_parm_menu" class="LC_Box" style="display:none">'."\n"
1484: .'<h3>'.&mt('Parameter').'</h3>'."\n"
1485: .$hidelink
1486: .'<div class="LC_columnSection">'."\n"
1.454 bisitz 1487: );
1.453 schualex 1488:
1.465 amueller 1489: #Print parameters
1.467 amueller 1490: for my $key (sort { $category_order{$a} <=> $category_order{$b} } keys %categoryList) {
1491: if(@{$categoryList{$key}} == 0) {
1.465 amueller 1492: next;
1493: } else {
1.489 bisitz 1494: $r->print('<div class="LC_Box LC_400Box">'
1495: .'<h4 class="LC_hcell">'
1.467 amueller 1496: .&mt($categories{$key})
1.489 bisitz 1497: .'</h4>'."\n");
1.467 amueller 1498: foreach $tempkey (&keysindisplayorderCategory($categoryList{$key},$keyorder)) {
1.466 bisitz 1499: $r->print('<span class="LC_nobreak">'
1500: .'<label><input type="checkbox" name="pscat" ');
1.473 amueller 1501: $r->print('value="'.$tempkey.'" ');
1.465 amueller 1502: $r->print('onclick="checkboxChecked(\''.$tempkey.'\')"');
1.473 amueller 1503: if ($$pscat[0] eq "all" || grep $_ eq $tempkey, @{$pscat}) {
1504: $r->print(' checked="checked"');
1505: }
1.465 amueller 1506: $r->print(' />'.($$allparms{$tempkey}=~/\S/ ? $$allparms{$tempkey}
1507: : $tempkey)
1.489 bisitz 1508: .'</label></span><br />'."\n");
1.465 amueller 1509: }
1.489 bisitz 1510: $r->print("</div>\n");
1.465 amueller 1511: }
1512: }
1.453 schualex 1513:
1514: #&shortCuts($r,$allparms,$pscat,$keyorder);
1.489 bisitz 1515: $r->print(
1516: "</div>\n"
1517: .$hidelink
1518: ."</div>\n"
1519: );
1.453 schualex 1520: }
1.468 amueller 1521: #
1522: # This function offers some links on the parameter section to get with one click a group a parameters
1523: #
1.453 schualex 1524: sub shortCuts {
1525: my ($r,$allparms,$pscat,$keyorder)=@_;
1526:
1.491 bisitz 1527: # Parameter Selection
1528: $r->print(
1529: &Apache::lonhtmlcommon::start_funclist(&mt('Parameter Selection'))
1530: .&Apache::lonhtmlcommon::add_item_funclist(
1531: '<a href="javascript:checkall(true, \'pscat\')">'.&mt('Select All').'</a>')
1532: .&Apache::lonhtmlcommon::add_item_funclist(
1533: '<a href="javascript:checkstandard()">'.&mt('Select Common Only').'</a>')
1534: .&Apache::lonhtmlcommon::add_item_funclist(
1535: '<a href="javascript:checkall(false, \'pscat\')">'.&mt('Unselect All').'</a>')
1536: .&Apache::lonhtmlcommon::end_funclist()
1537: );
1538:
1539: # Add Selection for...
1540: $r->print(
1541: &Apache::lonhtmlcommon::start_funclist(&mt('Add Selection for...'))
1542: .&Apache::lonhtmlcommon::add_item_funclist(
1543: '<a href="javascript:checkdates()">'.&mt('Problem Dates').'</a>')
1544: .&Apache::lonhtmlcommon::add_item_funclist(
1545: '<a href="javascript:checkcontdates()">'.&mt('Content Dates').'</a>')
1546: .&Apache::lonhtmlcommon::add_item_funclist(
1547: '<a href="javascript:checkdisset()">'.&mt('Discussion Settings').'</a>')
1548: .&Apache::lonhtmlcommon::add_item_funclist(
1549: '<a href="javascript:checkvisi()">'.&mt('Visibilities').'</a>')
1550: .&Apache::lonhtmlcommon::add_item_funclist(
1551: '<a href="javascript:checkparts()">'.&mt('Part Parameters').'</a>')
1552: .&Apache::lonhtmlcommon::end_funclist()
1553: );
1.208 www 1554: }
1555:
1.209 www 1556: sub partmenu {
1.446 bisitz 1557: my ($r,$allparts,$psprt)=@_;
1558:
1.421 bisitz 1559: $r->print('<select multiple="multiple" name="psprt" size="8">');
1.208 www 1560: $r->print('<option value="all"');
1.401 bisitz 1561: $r->print(' selected="selected"') unless (@{$psprt});
1.208 www 1562: $r->print('>'.&mt('All Parts').'</option>');
1563: my %temphash=();
1564: foreach (@{$psprt}) { $temphash{$_}=1; }
1.234 albertel 1565: foreach my $tempkey (sort {
1.473 amueller 1566: if ($a==$b) { return ($a cmp $b) } else { return ($a <=> $b); }
1.234 albertel 1567: } keys(%{$allparts})) {
1.473 amueller 1568: unless ($tempkey =~ /\./) {
1569: $r->print('<option value="'.$tempkey.'"');
1570: if ($$psprt[0] eq "all" || $temphash{$tempkey}) {
1571: $r->print(' selected="selected"');
1572: }
1573: $r->print('>'.$$allparts{$tempkey}.'</option>');
1574: }
1.208 www 1575: }
1.446 bisitz 1576: $r->print('</select>');
1.209 www 1577: }
1578:
1579: sub usermenu {
1.275 raeburn 1580: my ($r,$uname,$id,$udom,$csec,$cgroup,$parmlev,$usersgroups)=@_;
1.209 www 1581: my $chooseopt=&Apache::loncommon::select_dom_form($udom,'udom').' '.
1582: &Apache::loncommon::selectstudent_link('parmform','uname','udom');
1583: my $selscript=&Apache::loncommon::studentbrowser_javascript();
1.412 bisitz 1584:
1.209 www 1585: my $sections='';
1.300 albertel 1586: my %sectionhash = &Apache::loncommon::get_sections();
1587:
1.269 raeburn 1588: my $groups;
1.307 raeburn 1589: my %grouphash = &Apache::longroup::coursegroups();
1.299 albertel 1590:
1.412 bisitz 1591: my $g_s_header='';
1592: my $g_s_footer='';
1.446 bisitz 1593:
1.300 albertel 1594: if (%sectionhash) {
1.412 bisitz 1595: $sections=&mt('Section:').' <select name="csec"';
1.299 albertel 1596: if (%grouphash && $parmlev ne 'full') {
1.269 raeburn 1597: $sections .= qq| onchange="group_or_section('csec')" |;
1598: }
1599: $sections .= '>';
1.473 amueller 1600: foreach my $section ('',sort keys %sectionhash) {
1601: $sections.='<option value="'.$section.'" '.
1602: ($section eq $csec?'selected="selected"':'').'>'.$section.
1.275 raeburn 1603: '</option>';
1.209 www 1604: }
1605: $sections.='</select>';
1.269 raeburn 1606: }
1.412 bisitz 1607:
1.300 albertel 1608: if (%sectionhash && %grouphash && $parmlev ne 'full') {
1.412 bisitz 1609: $sections .= ' '.&mt('or').' ';
1.269 raeburn 1610: $sections .= qq|
1611: <script type="text/javascript">
1.454 bisitz 1612: // <![CDATA[
1.269 raeburn 1613: function group_or_section(caller) {
1614: if (caller == "cgroup") {
1615: if (document.parmform.cgroup.selectedIndex != 0) {
1616: document.parmform.csec.selectedIndex = 0;
1617: }
1618: } else {
1619: if (document.parmform.csec.selectedIndex != 0) {
1620: document.parmform.cgroup.selectedIndex = 0;
1621: }
1622: }
1623: }
1.454 bisitz 1624: // ]]>
1.269 raeburn 1625: </script>
1626: |;
1627: } else {
1628: $sections .= qq|
1629: <script type="text/javascript">
1.454 bisitz 1630: // <![CDATA[
1.269 raeburn 1631: function group_or_section(caller) {
1632: return;
1633: }
1.454 bisitz 1634: // ]]>
1.269 raeburn 1635: </script>
1636: |;
1.446 bisitz 1637: }
1.299 albertel 1638:
1639: if (%grouphash) {
1.412 bisitz 1640: $groups=&mt('Group:').' <select name="cgroup"';
1.300 albertel 1641: if (%sectionhash && $env{'form.action'} eq 'settable') {
1.269 raeburn 1642: $groups .= qq| onchange="group_or_section('cgroup')" |;
1643: }
1644: $groups .= '>';
1.275 raeburn 1645: foreach my $grp ('',sort keys %grouphash) {
1646: $groups.='<option value="'.$grp.'" ';
1647: if ($grp eq $cgroup) {
1648: unless ((defined($uname)) && ($grp eq '')) {
1649: $groups .= 'selected="selected" ';
1650: }
1651: } elsif (!defined($cgroup)) {
1652: if (@{$usersgroups} == 1) {
1653: if ($grp eq $$usersgroups[0]) {
1654: $groups .= 'selected="selected" ';
1655: }
1656: }
1657: }
1658: $groups .= '>'.$grp.'</option>';
1.269 raeburn 1659: }
1660: $groups.='</select>';
1661: }
1.412 bisitz 1662:
1.445 neumanie 1663: if (%sectionhash || %grouphash) {
1.446 bisitz 1664: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Group/Section')));
1665: $r->print($sections.$groups);
1.448 bisitz 1666: $r->print(&Apache::lonhtmlcommon::row_closure());
1.445 neumanie 1667: }
1.446 bisitz 1668:
1669: $r->print(&Apache::lonhtmlcommon::row_title(&mt('User')));
1.443 neumanie 1670: $r->print(&mt('For User [_1] or Student/Employee ID [_2] at Domain [_3]'
1.412 bisitz 1671: ,'<input type="text" value="'.$uname.'" size="12" name="uname" />'
1672: ,'<input type="text" value="'.$id.'" size="12" name="id" /> '
1.446 bisitz 1673: ,$chooseopt));
1.209 www 1674: }
1675:
1.468 amueller 1676: #
1677: # This function shows on table Mode the available Parameters for the selected Resources
1678: #
1.209 www 1679: sub displaymenu {
1.211 www 1680: my ($r,$allparms,$allparts,$pscat,$psprt,$keyorder)=@_;
1.445 neumanie 1681: $r->print(&Apache::lonhtmlcommon::start_pick_box());
1.448 bisitz 1682: &parmmenu($r,$allparms,$pscat,$keyorder);
1.453 schualex 1683: $r->print(&Apache::lonhtmlcommon::end_pick_box());
1684: &parmboxes($r,$allparms,$pscat,$keyorder);
1.209 www 1685: }
1686:
1.445 neumanie 1687: sub mapmenu {
1.499 raeburn 1688: my ($r,$allmaps,$pschp,$maptitles,$symbp)=@_;
1.468 amueller 1689: my %allmaps_inverted = reverse %$allmaps;
1.461 neumanie 1690: my $navmap = Apache::lonnavmaps::navmap->new();
1691: my $tree=[];
1692: my $treeinfo={};
1693: if (defined($navmap)) {
1.499 raeburn 1694: my $it=$navmap->getIterator(undef,undef,undef,1,1,undef);
1.461 neumanie 1695: my $curRes;
1696: my $depth = 0;
1.468 amueller 1697: my %parent = ();
1698: my $startcount = 5;
1699: my $lastcontainer = $startcount;
1700: # preparing what is to show ...
1.461 neumanie 1701: while ($curRes = $it->next()) {
1702: if ($curRes == $it->BEGIN_MAP()) {
1703: $depth++;
1.468 amueller 1704: $parent{$depth}= $lastcontainer;
1.461 neumanie 1705: }
1706: if ($curRes == $it->END_MAP()) {
1707: $depth--;
1.468 amueller 1708: $lastcontainer = $parent{$depth};
1.461 neumanie 1709: }
1710: if (ref($curRes)) {
1.468 amueller 1711: my $symb = $curRes->symb();
1712: my $ressymb = $symb;
1.461 neumanie 1713: if (($curRes->is_sequence()) || ($curRes->is_page())) {
1714: my $type = 'sequence';
1715: if ($curRes->is_page()) {
1716: $type = 'page';
1717: }
1718: my $id= $curRes->id();
1.468 amueller 1719: my $srcf = $curRes->src();
1720: my $resource_name = &Apache::lonnet::gettitle($srcf);
1721: if(!exists($treeinfo->{$id})) {
1722: push(@$tree,$id);
1.473 amueller 1723: my $enclosing_map_folder = &Apache::lonnet::declutter($curRes->enclosing_map_src());
1.468 amueller 1724: $treeinfo->{$id} = {
1.461 neumanie 1725: depth => $depth,
1726: type => $type,
1.468 amueller 1727: name => $resource_name,
1728: enclosing_map_folder => $enclosing_map_folder,
1.461 neumanie 1729: };
1.462 neumanie 1730: }
1.461 neumanie 1731: }
1732: }
1733: }
1.462 neumanie 1734: }
1.473 amueller 1735: # Show it ...
1.484 amueller 1736: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Select Enclosing Map or Folder'),'','',' id="mapmenu"'));
1.461 neumanie 1737: if ((ref($tree) eq 'ARRAY') && (ref($treeinfo) eq 'HASH')) {
1738: my $icon = '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" />';
1.497 bisitz 1739: my $whitespace =
1740: '<img src="'
1741: .&Apache::loncommon::lonhttpdurl('/adm/lonIcons/whitespace_21.gif')
1742: .'" alt="" />';
1743:
1.498 bisitz 1744: # Info about selectable folders/maps
1745: $r->print(
1746: '<div class="LC_info">'
1747: .&mt('You can only select those maps and folders which can be currently parameterized.')
1748: # .' '.&Apache::loncommon::help_open_topic('...') # Later: Add further help
1749: .'</div>'
1750: );
1751:
1752:
1.497 bisitz 1753: $r->print(&Apache::loncommon::start_data_table());
1754:
1.498 bisitz 1755: # Display row: "All Maps or Folders"
1756: $r->print(
1757: &Apache::loncommon::start_data_table_row()
1758: .'<td>'
1759: .'<label>'
1760: .'<input type="radio" name="pschp"'
1.497 bisitz 1761: );
1762: $r->print(' checked="checked"') if ($pschp eq 'all' || !$pschp);
1.498 bisitz 1763: $r->print(
1764: ' value="all" /> '.$icon.' '
1765: .&mt('All Maps or Folders')
1766: .'</label>'
1767: .'<hr /></td>'
1768: .&Apache::loncommon::end_data_table_row()
1.463 bisitz 1769: );
1.497 bisitz 1770:
1771: # Display row: "Main Course Documents"
1.468 amueller 1772: if (exists($$allmaps{1})) {
1.498 bisitz 1773: $r->print(
1774: &Apache::loncommon::start_data_table_row()
1775: .'<td>'
1776: .'<label>'
1777: .'<input type="radio" name="pschp" value="1"'
1.468 amueller 1778: );
1.497 bisitz 1779: $r->print(' checked="checked"') if ($pschp eq '1');
1.498 bisitz 1780: $r->print(
1781: '/> '.$icon.' '
1782: .$$maptitles{1}
1783: .($$allmaps{1} !~/^uploaded/?' ['.$$allmaps{1}.']':'')
1784: .'</label>'
1785: .'</td>'
1786: .&Apache::loncommon::end_data_table_row()
1.468 amueller 1787: );
1788: }
1.497 bisitz 1789:
1790: # Display rows for all course maps and folders
1.468 amueller 1791: foreach my $id (@{$tree}) {
1792: my ($mapid,$resid)=split(/\./,$id);
1.464 bisitz 1793: # Indentation
1.468 amueller 1794: my $depth = $treeinfo->{$id}->{'depth'};
1.464 bisitz 1795: my $indent;
1796: for (my $i = 0; $i < $depth; $i++) {
1797: $indent.= $whitespace;
1798: }
1.461 neumanie 1799: $icon = '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" />';
1.468 amueller 1800: if ($treeinfo->{$id}->{'type'} eq 'page') {
1.461 neumanie 1801: $icon = '<img src="/adm/lonIcons/navmap.page.open.gif" alt="" />';
1802: }
1.468 amueller 1803: my $symb_name = $$symbp{$id};
1804: my ($front, $tail) = split (/___${resid}___/, $symb_name);
1805: $symb_name = $tail;
1.498 bisitz 1806: $r->print(
1807: &Apache::loncommon::start_data_table_row()
1808: .'<td>'
1809: .'<label>'
1.463 bisitz 1810: );
1.498 bisitz 1811: # Only offer radio button for folders/maps which can be parameterized
1812: if ($allmaps_inverted{$symb_name}) {
1813: $r->print(
1814: '<input type ="radio" name="pschp"'
1815: .' value="'.$allmaps_inverted{$symb_name}.'"'
1816: );
1817: $r->print(' checked="checked"') if ($allmaps_inverted{$symb_name} eq $pschp);
1818: $r->print('/>');
1819: } else {
1820: $r->print($whitespace);
1.461 neumanie 1821: }
1.498 bisitz 1822: $r->print(
1823: $indent.$icon.' '
1824: .$treeinfo->{$id}->{name}
1825: .($$allmaps{$mapid}!~/^uploaded/?' ['.$$allmaps{$mapid}.']':'')
1826: .'</label>'
1827: .'</td>'
1828: .&Apache::loncommon::end_data_table_row()
1.463 bisitz 1829: );
1.461 neumanie 1830: }
1.497 bisitz 1831:
1.462 neumanie 1832: $r->print(&Apache::loncommon::end_data_table());
1.209 www 1833: }
1834: }
1835:
1.482 amueller 1836: # Build up the select Box to choose if your parameter specification should work for the resource, map/folder or the course level
1837: # The value of default selection in the select box is set by the value that is given by the argument in $parmlev.
1.209 www 1838: sub levelmenu {
1.446 bisitz 1839: my ($r,$alllevs,$parmlev)=@_;
1840:
1.445 neumanie 1841: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Select Parameter Level').&Apache::loncommon::help_open_topic('Course_Parameter_Levels')));
1.474 amueller 1842: $r->print('<select id="parmlev" name="parmlev" onchange="showHide_courseContent()">');
1.209 www 1843: foreach (reverse sort keys %{$alllevs}) {
1.473 amueller 1844: $r->print('<option value="'.$$alllevs{$_}.'"');
1845: if ($parmlev eq $$alllevs{$_}) {
1846: $r->print(' selected="selected"');
1847: }
1848: $r->print('>'.&mt($_).'</option>');
1.208 www 1849: }
1.446 bisitz 1850: $r->print("</select>");
1.208 www 1851: }
1852:
1.211 www 1853:
1854: sub sectionmenu {
1855: my ($r,$selectedsections)=@_;
1.300 albertel 1856: my %sectionhash = &Apache::loncommon::get_sections();
1857: return if (!%sectionhash);
1858:
1.421 bisitz 1859: $r->print('<select name="Section" multiple="multiple" size="8">');
1.300 albertel 1860: foreach my $s ('all',sort keys %sectionhash) {
1.473 amueller 1861: $r->print(' <option value="'.$s.'"');
1862: foreach (@{$selectedsections}) {
1863: if ($s eq $_) {
1864: $r->print(' selected="selected"');
1865: last;
1866: }
1867: }
1868: $r->print('>'.$s."</option>\n");
1.300 albertel 1869: }
1870: $r->print("</select>\n");
1.269 raeburn 1871: }
1872:
1873: sub groupmenu {
1874: my ($r,$selectedgroups)=@_;
1.307 raeburn 1875: my %grouphash = &Apache::longroup::coursegroups();
1.299 albertel 1876: return if (!%grouphash);
1877:
1.421 bisitz 1878: $r->print('<select name="Group" multiple="multiple" size="8">');
1.299 albertel 1879: foreach my $group (sort(keys(%grouphash))) {
1.473 amueller 1880: $r->print(' <option value="'.$group.'"');
1881: foreach (@{$selectedgroups}) {
1882: if ($group eq $_) {
1883: $r->print(' selected="selected"');
1884: last;
1885: }
1886: }
1887: $r->print('>'.$group."</option>\n");
1.211 www 1888: }
1.299 albertel 1889: $r->print("</select>\n");
1.211 www 1890: }
1891:
1.269 raeburn 1892:
1.210 www 1893: sub keysplit {
1894: my $keyp=shift;
1895: return (split(/\,/,$keyp));
1896: }
1897:
1898: sub keysinorder {
1899: my ($name,$keyorder)=@_;
1900: return sort {
1.473 amueller 1901: $$keyorder{$a} <=> $$keyorder{$b};
1.210 www 1902: } (keys %{$name});
1903: }
1904:
1.236 albertel 1905: sub keysinorder_bytype {
1906: my ($name,$keyorder)=@_;
1907: return sort {
1.473 amueller 1908: my $ta=(split('_',$a))[-1];
1909: my $tb=(split('_',$b))[-1];
1910: if ($$keyorder{'parameter_0_'.$ta} == $$keyorder{'parameter_0_'.$tb}) {
1911: return ($a cmp $b);
1912: }
1913: $$keyorder{'parameter_0_'.$ta} <=> $$keyorder{'parameter_0_'.$tb};
1.236 albertel 1914: } (keys %{$name});
1915: }
1916:
1.211 www 1917: sub keysindisplayorder {
1918: my ($name,$keyorder)=@_;
1919: return sort {
1.473 amueller 1920: $$keyorder{'parameter_0_'.$a} <=> $$keyorder{'parameter_0_'.$b};
1.211 www 1921: } (keys %{$name});
1922: }
1923:
1.214 www 1924: sub sortmenu {
1925: my ($r,$sortorder)=@_;
1.236 albertel 1926: $r->print('<br /><label><input type="radio" name="sortorder" value="realmstudent"');
1.214 www 1927: if ($sortorder eq 'realmstudent') {
1.422 bisitz 1928: $r->print(' checked="checked"');
1.214 www 1929: }
1930: $r->print(' />'.&mt('Sort by realm first, then student (group/section)'));
1.236 albertel 1931: $r->print('</label><br /><label><input type="radio" name="sortorder" value="studentrealm"');
1.214 www 1932: if ($sortorder eq 'studentrealm') {
1.422 bisitz 1933: $r->print(' checked="checked"');
1.214 www 1934: }
1.236 albertel 1935: $r->print(' />'.&mt('Sort by student (group/section) first, then realm').
1.473 amueller 1936: '</label>');
1.214 www 1937: }
1938:
1.211 www 1939: sub standardkeyorder {
1940: return ('parameter_0_opendate' => 1,
1.473 amueller 1941: 'parameter_0_duedate' => 2,
1942: 'parameter_0_answerdate' => 3,
1943: 'parameter_0_interval' => 4,
1944: 'parameter_0_weight' => 5,
1945: 'parameter_0_maxtries' => 6,
1946: 'parameter_0_hinttries' => 7,
1947: 'parameter_0_contentopen' => 8,
1948: 'parameter_0_contentclose' => 9,
1949: 'parameter_0_type' => 10,
1950: 'parameter_0_problemstatus' => 11,
1951: 'parameter_0_hiddenresource' => 12,
1952: 'parameter_0_hiddenparts' => 13,
1953: 'parameter_0_display' => 14,
1954: 'parameter_0_ordered' => 15,
1955: 'parameter_0_tol' => 16,
1956: 'parameter_0_sig' => 17,
1957: 'parameter_0_turnoffunit' => 18,
1.218 www 1958: 'parameter_0_discussend' => 19,
1959: 'parameter_0_discusshide' => 20);
1.211 www 1960: }
1961:
1.59 matthew 1962:
1.30 www 1963: sub assessparms {
1.1 www 1964:
1.43 albertel 1965: my $r=shift;
1.201 www 1966:
1967: my @ids=();
1968: my %symbp=();
1969: my %mapp=();
1970: my %typep=();
1971: my %keyp=();
1972: my %uris=();
1973: my %maptitles=();
1974:
1.2 www 1975: # -------------------------------------------------------- Variable declaration
1.209 www 1976:
1.129 www 1977: my %allmaps=();
1978: my %alllevs=();
1.57 albertel 1979:
1.187 www 1980: my $uname;
1981: my $udom;
1982: my $uhome;
1983: my $csec;
1.269 raeburn 1984: my $cgroup;
1.275 raeburn 1985: my @usersgroups = ();
1.446 bisitz 1986:
1.190 albertel 1987: my $coursename=$env{'course.'.$env{'request.course.id'}.'.description'};
1.187 www 1988:
1.57 albertel 1989: $alllevs{'Resource Level'}='full';
1.215 www 1990: $alllevs{'Map/Folder Level'}='map';
1.57 albertel 1991: $alllevs{'Course Level'}='general';
1992:
1993: my %allparms;
1994: my %allparts;
1.210 www 1995: #
1996: # Order in which these parameters will be displayed
1997: #
1.211 www 1998: my %keyorder=&standardkeyorder();
1999:
1.43 albertel 2000: @ids=();
2001: %symbp=();
2002: %typep=();
2003:
2004: my $message='';
2005:
1.190 albertel 2006: $csec=$env{'form.csec'};
1.269 raeburn 2007: $cgroup=$env{'form.cgroup'};
1.188 www 2008:
1.190 albertel 2009: if ($udom=$env{'form.udom'}) {
2010: } elsif ($udom=$env{'request.role.domain'}) {
2011: } elsif ($udom=$env{'user.domain'}) {
1.172 albertel 2012: } else {
1.473 amueller 2013: $udom=$r->dir_config('lonDefDomain');
1.172 albertel 2014: }
1.468 amueller 2015:
1.43 albertel 2016:
1.134 albertel 2017: my @pscat=&Apache::loncommon::get_env_multiple('form.pscat');
1.190 albertel 2018: my $pschp=$env{'form.pschp'};
1.134 albertel 2019: my @psprt=&Apache::loncommon::get_env_multiple('form.psprt');
1.76 www 2020: if (!@psprt) { $psprt[0]='0'; }
1.57 albertel 2021:
1.43 albertel 2022: my $pssymb='';
1.57 albertel 2023: my $parmlev='';
1.446 bisitz 2024:
1.190 albertel 2025: unless ($env{'form.parmlev'}) {
1.57 albertel 2026: $parmlev = 'map';
2027: } else {
1.190 albertel 2028: $parmlev = $env{'form.parmlev'};
1.57 albertel 2029: }
1.26 www 2030:
1.29 www 2031: # ----------------------------------------------- Was this started from grades?
2032:
1.190 albertel 2033: if (($env{'form.command'} eq 'set') && ($env{'form.url'})
1.473 amueller 2034: && (!$env{'form.dis'})) {
2035: my $url=$env{'form.url'};
2036: $url=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
2037: $pssymb=&Apache::lonnet::symbread($url);
2038: if (!@pscat) { @pscat=('all'); }
2039: $pschp='';
1.57 albertel 2040: $parmlev = 'full';
1.190 albertel 2041: } elsif ($env{'form.symb'}) {
1.473 amueller 2042: $pssymb=$env{'form.symb'};
2043: if (!@pscat) { @pscat=('all'); }
2044: $pschp='';
1.57 albertel 2045: $parmlev = 'full';
1.43 albertel 2046: } else {
1.473 amueller 2047: $env{'form.url'}='';
1.43 albertel 2048: }
2049:
1.190 albertel 2050: my $id=$env{'form.id'};
1.43 albertel 2051: if (($id) && ($udom)) {
1.473 amueller 2052: $uname=(&Apache::lonnet::idget($udom,$id))[1];
2053: if ($uname) {
2054: $id='';
2055: } else {
2056: $message=
2057: '<span class="LC_error">'.&mt("Unknown ID")." '$id' ".
2058: &mt('at domain')." '$udom'</span>";
2059: }
1.43 albertel 2060: } else {
1.473 amueller 2061: $uname=$env{'form.uname'};
1.43 albertel 2062: }
2063: unless ($udom) { $uname=''; }
2064: $uhome='';
2065: if ($uname) {
1.473 amueller 2066: $uhome=&Apache::lonnet::homeserver($uname,$udom);
1.43 albertel 2067: if ($uhome eq 'no_host') {
1.473 amueller 2068: $message=
2069: '<span class="LC_error">'.&mt("Unknown user")." '$uname' ".
2070: &mt("at domain")." '$udom'</span>";
2071: $uname='';
1.12 www 2072: } else {
1.473 amueller 2073: $csec=&Apache::lonnet::getsection($udom,$uname,
2074: $env{'request.course.id'});
2075: if ($csec eq '-1') {
2076: $message='<span class="LC_error">'.
2077: &mt("User")." '$uname' ".&mt("at domain")." '$udom' ".
2078: &mt("not in this course")."</span>";
2079: $uname='';
2080: $csec=$env{'form.csec'};
1.269 raeburn 2081: $cgroup=$env{'form.cgroup'};
1.473 amueller 2082: } else {
2083: my %name=&Apache::lonnet::userenvironment($udom,$uname,
2084: ('firstname','middlename','lastname','generation','id'));
2085: $message="\n<p>\n".&mt("Full Name").": ".
2086: $name{'firstname'}.' '.$name{'middlename'}.' '
2087: .$name{'lastname'}.' '.$name{'generation'}.
2088: "<br />\n".&mt('ID').": ".$name{'id'}.'<p>';
2089: }
1.297 raeburn 2090: @usersgroups = &Apache::lonnet::get_users_groups(
1.275 raeburn 2091: $udom,$uname,$env{'request.course.id'});
1.297 raeburn 2092: if (@usersgroups > 0) {
1.306 albertel 2093: unless (grep(/^\Q$cgroup\E$/,@usersgroups)) {
1.275 raeburn 2094: $cgroup = $usersgroups[0];
1.297 raeburn 2095: }
1.269 raeburn 2096: }
1.12 www 2097: }
1.43 albertel 2098: }
1.2 www 2099:
1.43 albertel 2100: unless ($csec) { $csec=''; }
1.269 raeburn 2101: unless ($cgroup) { $cgroup=''; }
1.12 www 2102:
1.14 www 2103: # --------------------------------------------------------- Get all assessments
1.446 bisitz 2104: &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allmaps,
1.473 amueller 2105: \%mapp, \%symbp,\%maptitles,\%uris,
2106: \%keyorder);
1.63 bowersj2 2107:
1.57 albertel 2108: $mapp{'0.0'} = '';
2109: $symbp{'0.0'} = '';
1.99 albertel 2110:
1.14 www 2111: # ---------------------------------------------------------- Anything to store?
1.190 albertel 2112: if ($env{'form.pres_marker'}) {
1.205 www 2113: my @markers=split(/\&\&\&/,$env{'form.pres_marker'});
2114: my @values=split(/\&\&\&/,$env{'form.pres_value'});
2115: my @types=split(/\&\&\&/,$env{'form.pres_type'});
1.500 ! raeburn 2116: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
! 2117: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.473 amueller 2118: for (my $i=0;$i<=$#markers;$i++) {
1.437 raeburn 2119: if ($markers[$i] =~ /^[\d.]+\&0_availablestudent\&(1|2|3)$/) {
2120: my (@ok_slots,@fail_slots,@del_slots);
2121: my $courseopt=&Apache::lonnet::get_courseresdata($cnum,$cdom);
2122: my ($level,@all) =
2123: &parmval_by_symb('0.availablestudent',$pssymb,'',$uname,$udom,
2124: $csec,$cgroup,$courseopt);
2125: foreach my $slot_name (split(/:/,$values[$i])) {
2126: next if ($slot_name eq '');
2127: if (&update_slots($slot_name,$cdom,$cnum,$pssymb,$uname,$udom) eq 'ok') {
2128: push(@ok_slots,$slot_name);
2129:
2130: } else {
2131: push(@fail_slots,$slot_name);
2132: }
2133: }
2134: if (@ok_slots) {
2135: $values[$i] = join(':',@ok_slots);
2136: } else {
2137: $values[$i] = '';
2138: }
2139: if ($all[$level] ne '') {
2140: my @existing = split(/:/,$all[$level]);
2141: foreach my $slot_name (@existing) {
2142: if (!grep(/^\Q$slot_name\E$/,split(/:/,$values[$i]))) {
2143: if (&delete_slots($slot_name,$cdom,$cnum,$uname,$udom,$pssymb) eq 'ok') {
2144: push(@del_slots,$slot_name);
2145: }
2146: }
2147: }
2148: }
1.500 ! raeburn 2149: } elsif ($markers[$i] =~ /_type\&\d+$/) {
! 2150: if (($values[$i] eq 'anonsurvey') || ($values[$i] eq 'anonsurveycred')) {
! 2151: &Apache::lonnet::update_released_required($Apache::lonnet::needsrelease{'parameter:type:'.$values[$i]});
! 2152: }
1.437 raeburn 2153: }
1.473 amueller 2154: $message.=&storeparm(split(/\&/,$markers[$i]),
2155: $values[$i],
2156: $types[$i],
2157: $uname,$udom,$csec,$cgroup);
2158: }
1.68 www 2159: # ---------------------------------------------------------------- Done storing
1.473 amueller 2160: $message.='<p class="LC_warning">'
1.459 bisitz 2161: .&mt('Changes can take up to 10 minutes before being active for all students.')
2162: .&Apache::loncommon::help_open_topic('Caching')
2163: .'</p>';
1.68 www 2164: }
1.57 albertel 2165: #----------------------------------------------- if all selected, fill in array
1.209 www 2166: if ($pscat[0] eq "all") {@pscat = (keys %allparms);}
1.446 bisitz 2167: if (!@pscat) { @pscat=('duedate','opendate','answerdate','weight','maxtries') };
1.57 albertel 2168: if ($psprt[0] eq "all" || !@psprt) {@psprt = (keys %allparts);}
1.2 www 2169: # ------------------------------------------------------------------ Start page
1.63 bowersj2 2170:
1.209 www 2171: &startpage($r);
1.57 albertel 2172:
1.44 albertel 2173: foreach ('tolerance','date_default','date_start','date_end',
1.473 amueller 2174: 'date_interval','int','float','string') {
2175: $r->print('<input type="hidden" value="'.
2176: &HTML::Entities::encode($env{'form.recent_'.$_},'"&<>').
2177: '" name="recent_'.$_.'" />');
1.44 albertel 2178: }
1.446 bisitz 2179:
1.459 bisitz 2180: # ----- Start Parameter Selection
2181:
2182: # Hide parm selection?
2183: $r->print(<<ENDPARMSELSCRIPT);
2184: <script type="text/javascript">
2185: // <![CDATA[
2186: function parmsel_show() {
2187: document.getElementById('parmsel').style.display = "";
2188: document.getElementById('parmsellink').style.display = "none";
2189: }
2190: // ]]>
2191: </script>
2192: ENDPARMSELSCRIPT
1.474 amueller 2193:
1.445 neumanie 2194: if (!$pssymb) {
1.486 www 2195: my $parmselhiddenstyle=' style="display:none"';
2196: if($env{'form.hideparmsel'} eq 'hidden') {
2197: $r->print('<div id="parmsel"'.$parmselhiddenstyle.'>');
2198: } else {
2199: $r->print('<div id="parmsel">');
2200: }
2201:
1.491 bisitz 2202: # Step 1
1.479 raeburn 2203: $r->print(&Apache::lonhtmlcommon::topic_bar(1,&mt('Resource Specification')));
1.474 amueller 2204: $r->print(<<COURSECONTENTSCRIPT);
2205: <script type="text/javascript">
2206: // <![CDATA[
2207: function showHide_courseContent(){
2208: var parmlevValue=document.getElementById("parmlev").value;
2209: if (parmlevValue == 'general') {
2210: document.getElementById('mapmenu').style.display="none";
2211: } else {
2212: if ((parmlevValue == "full") || (parmlevValue == "map")) {
2213: document.getElementById('mapmenu').style.display ="";
2214: } else {
2215: document.getElementById('mapmenu').style.display="none";
2216: }
2217: }
2218: }
2219: // ]]>
2220: </script>
2221: COURSECONTENTSCRIPT
2222:
1.445 neumanie 2223: $r->print(&Apache::lonhtmlcommon::start_pick_box());
1.209 www 2224: &levelmenu($r,\%alllevs,$parmlev);
1.491 bisitz 2225: $r->print(&Apache::lonhtmlcommon::row_closure());
1.474 amueller 2226: &mapmenu($r,\%allmaps,$pschp,\%maptitles, \%symbp);
1.491 bisitz 2227: $r->print(&Apache::lonhtmlcommon::row_closure());
2228: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Select Parts to View')));
2229: &partmenu($r,\%allparts,\@psprt);
1.474 amueller 2230: $r->print(&Apache::lonhtmlcommon::row_closure(1));
2231: $r->print(&Apache::lonhtmlcommon::end_pick_box());
1.491 bisitz 2232:
2233: # Step 2
1.479 raeburn 2234: $r->print(&Apache::lonhtmlcommon::topic_bar(2,&mt('Parameter Specification')));
1.473 amueller 2235: &displaymenu($r,\%allparms,\%allparts,\@pscat,\@psprt,\%keyorder);
1.491 bisitz 2236:
2237: # Step 3
1.479 raeburn 2238: $r->print(&Apache::lonhtmlcommon::topic_bar(3,&mt('User Specification (optional)')));
1.486 www 2239: $r->print(&Apache::lonhtmlcommon::start_pick_box());
2240: &usermenu($r,$uname,$id,$udom,$csec,$cgroup,$parmlev,\@usersgroups);
2241: $r->print(&Apache::lonhtmlcommon::row_closure(1));
2242: $r->print(&Apache::lonhtmlcommon::end_pick_box());
1.491 bisitz 2243:
2244: # Update Display Button
1.486 www 2245: $r->print('<p>'
2246: .'<input type="submit" name="dis"'
2247: .' value="'.&mt('Update Parameter Display').'" />'
2248: .'<input type="hidden" name="hideparmsel" value="hidden" />'
2249: .'</p>');
2250: $r->print('</div>');
1.491 bisitz 2251:
1.486 www 2252: # Offer link to display parameter selection again
2253: $r->print('<p id="parmsellink"');
2254: if ($env{'form.hideparmsel'} ne 'hidden') {
2255: $r->print($parmselhiddenstyle);
2256: }
2257: $r->print('>'
2258: .'<a href="javascript:parmsel_show()">'
2259: .&mt('Change Parameter Selection')
2260: .'</a>'
2261: .'</p>');
1.44 albertel 2262: } else {
1.478 amueller 2263: # parameter screen for a single resource.
1.486 www 2264: my ($map,$iid,$resource)=&Apache::lonnet::decode_symb($pssymb);
1.473 amueller 2265: my $title = &Apache::lonnet::gettitle($pssymb);
1.312 albertel 2266: $r->print(&mt('Specific Resource: [_1] ([_2])',$title,$resource).
1.472 amueller 2267: '<input type="hidden" value="'.$pssymb.'" name="symb" />'.
1.486 www 2268: '<br />');
2269: $r->print(&Apache::lonhtmlcommon::topic_bar('',&mt('Additional Display Specification (optional)')));
2270: $r->print(&Apache::lonhtmlcommon::start_pick_box());
2271: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Select Parts to View')).
2272: '<label>'.&mt('Show all parts').': <input type="checkbox" name="psprt" value="all"'.
2273: ($env{'form.psprt'}?' checked="checked"':'').' /></label></td></tr>');
2274: &usermenu($r,$uname,$id,$udom,$csec,$cgroup,$parmlev,\@usersgroups);
2275: $r->print(&Apache::lonhtmlcommon::row_closure(1));
2276: $r->print(&Apache::lonhtmlcommon::end_pick_box());
2277: $r->print('<p>'
1.459 bisitz 2278: .'<input type="submit" name="dis"'
2279: .' value="'.&mt('Update Parameter Display').'" />'
2280: .'<input type="hidden" name="hideparmsel" value="hidden" />'
1.486 www 2281: .'</p>');
1.459 bisitz 2282: }
1.478 amueller 2283:
1.486 www 2284: # ----- End Parameter Selection
1.57 albertel 2285:
1.459 bisitz 2286: # Display Messages
2287: $r->print('<div>'.$message.'</div>');
1.210 www 2288:
1.57 albertel 2289:
2290: my @temp_pscat;
2291: map {
2292: my $cat = $_;
2293: push(@temp_pscat, map { $_.'.'.$cat } @psprt);
2294: } @pscat;
2295:
2296: @pscat = @temp_pscat;
2297:
1.209 www 2298: if (($env{'form.prevvisit'}) || ($pschp) || ($pssymb)) {
1.10 www 2299: # ----------------------------------------------------------------- Start Table
1.57 albertel 2300: my @catmarker=map { tr|.|_|; 'parameter_'.$_; } @pscat;
1.190 albertel 2301: my $csuname=$env{'user.name'};
2302: my $csudom=$env{'user.domain'};
1.57 albertel 2303:
1.203 www 2304: if ($parmlev eq 'full') {
1.473 amueller 2305: my $coursespan=$csec?8:5;
2306: my $userspan=3;
2307: if ($cgroup ne '') {
2308: $coursespan += 3;
2309: }
2310:
2311: $r->print('<p><table border="2">');
2312: $r->print('<tr><td colspan="5"></td>');
2313: $r->print('<th colspan="'.($coursespan).'">'.&mt('Any User').'</th>');
2314: if ($uname) {
2315: if (@usersgroups > 1) {
2316: $userspan ++;
2317: }
2318: $r->print('<th colspan="'.$userspan.'" rowspan="2">');
2319: $r->print(&mt("User")." $uname ".&mt('at Domain')." $udom</th>");
2320: }
2321: my %lt=&Apache::lonlocal::texthash(
2322: 'pie' => "Parameter in Effect",
2323: 'csv' => "Current Session Value",
1.472 amueller 2324: 'at' => 'at',
2325: 'rl' => "Resource Level",
1.473 amueller 2326: 'ic' => 'in Course',
2327: 'aut' => "Assessment URL and Title",
2328: 'type' => 'Type',
2329: 'emof' => "Enclosing Map or Folder",
2330: 'part' => 'Part',
1.472 amueller 2331: 'pn' => 'Parameter Name',
1.473 amueller 2332: 'def' => 'default',
2333: 'femof' => 'from Enclosing Map or Folder',
2334: 'gen' => 'general',
2335: 'foremf' => 'for Enclosing Map or Folder',
2336: 'fr' => 'for Resource'
2337: );
2338: $r->print(<<ENDTABLETWO);
1.419 bisitz 2339: <th rowspan="3">$lt{'pie'}</th>
2340: <th rowspan="3">$lt{'csv'}<br />($csuname $lt{'at'} $csudom)</th>
2341: </tr><tr><td colspan="5"></td><th colspan="2">$lt{'ic'}</th><th colspan="2">$lt{'rl'}</th>
2342: <th colspan="1">$lt{'ic'}</th>
1.182 albertel 2343:
1.10 www 2344: ENDTABLETWO
1.473 amueller 2345: if ($csec) {
2346: $r->print('<th colspan="3">'.
2347: &mt("in Section")." $csec</th>");
2348: }
2349: if ($cgroup) {
1.419 bisitz 2350: $r->print('<th colspan="3">'.
1.472 amueller 2351: &mt("in Group")." $cgroup</th>");
1.473 amueller 2352: }
2353: $r->print(<<ENDTABLEHEADFOUR);
1.133 www 2354: </tr><tr><th>$lt{'aut'}</th><th>$lt{'type'}</th>
2355: <th>$lt{'emof'}</th><th>$lt{'part'}</th><th>$lt{'pn'}</th>
1.192 albertel 2356: <th>$lt{'gen'}</th><th>$lt{'foremf'}</th>
2357: <th>$lt{'def'}</th><th>$lt{'femof'}</th><th>$lt{'fr'}</th>
1.10 www 2358: ENDTABLEHEADFOUR
1.57 albertel 2359:
1.473 amueller 2360: if ($csec) {
2361: $r->print('<th>'.&mt('general').'</th><th>'.&mt('for Enclosing Map or Folder').'</th><th>'.&mt('for Resource').'</th>');
2362: }
2363:
2364: if ($cgroup) {
2365: $r->print('<th>'.&mt('general').'</th><th>'.&mt('for Enclosing Map or Folder').'</th><th>'.&mt('for Resource').'</th>');
2366: }
2367:
2368: if ($uname) {
2369: if (@usersgroups > 1) {
2370: $r->print('<th>'.&mt('Control by other group?').'</th>');
2371: }
2372: $r->print('<th>'.&mt('general').'</th><th>'.&mt('for Enclosing Map or Folder').'</th><th>'.&mt('for Resource').'</th>');
2373: }
2374:
2375: $r->print('</tr>');
2376:
2377: my $defbgone='';
2378: my $defbgtwo='';
2379: my $defbgthree = '';
1.57 albertel 2380:
1.473 amueller 2381: foreach (@ids) {
1.57 albertel 2382:
1.473 amueller 2383: my $rid=$_;
1.57 albertel 2384: my ($inmapid)=($rid=~/\.(\d+)$/);
2385:
1.446 bisitz 2386: if ((!$pssymb &&
1.473 amueller 2387: (($pschp eq 'all') || ($allmaps{$pschp} eq $mapp{$rid})))
2388: ||
2389: ($pssymb && $pssymb eq $symbp{$rid})) {
1.4 www 2390: # ------------------------------------------------------ Entry for one resource
1.473 amueller 2391: if ($defbgone eq '#E0E099') {
2392: $defbgone='#E0E0DD';
1.57 albertel 2393: } else {
1.419 bisitz 2394: $defbgone='#E0E099';
1.57 albertel 2395: }
1.419 bisitz 2396: if ($defbgtwo eq '#FFFF99') {
1.473 amueller 2397: $defbgtwo='#FFFFDD';
1.57 albertel 2398: } else {
1.473 amueller 2399: $defbgtwo='#FFFF99';
1.57 albertel 2400: }
1.419 bisitz 2401: if ($defbgthree eq '#FFBB99') {
2402: $defbgthree='#FFBBDD';
1.269 raeburn 2403: } else {
1.419 bisitz 2404: $defbgthree='#FFBB99';
1.269 raeburn 2405: }
2406:
1.57 albertel 2407: my $thistitle='';
2408: my %name= ();
2409: undef %name;
2410: my %part= ();
2411: my %display=();
2412: my %type= ();
2413: my %default=();
1.196 www 2414: my $uri=&Apache::lonnet::declutter($uris{$rid});
1.57 albertel 2415:
1.210 www 2416: foreach (&keysplit($keyp{$rid})) {
1.57 albertel 2417: my $tempkeyp = $_;
2418: if (grep $_ eq $tempkeyp, @catmarker) {
2419: $part{$_}=&Apache::lonnet::metadata($uri,$_.'.part');
2420: $name{$_}=&Apache::lonnet::metadata($uri,$_.'.name');
1.433 raeburn 2421: my $parmdis=&Apache::lonnet::metadata($uri,$_.'.display');
2422: if ($allparms{$name{$_}} ne '') {
2423: my $identifier;
2424: if ($parmdis =~ /(\s*\[Part.*)$/) {
2425: $identifier = $1;
2426: }
2427: $display{$_} = $allparms{$name{$_}}.$identifier;
2428: } else {
2429: $display{$_} = $parmdis;
2430: }
1.57 albertel 2431: unless ($display{$_}) { $display{$_}=''; }
2432: $display{$_}.=' ('.$name{$_}.')';
2433: $default{$_}=&Apache::lonnet::metadata($uri,$_);
2434: $type{$_}=&Apache::lonnet::metadata($uri,$_.'.type');
2435: $thistitle=&Apache::lonnet::metadata($uri,$_.'.title');
2436: }
2437: }
2438: my $totalparms=scalar keys %name;
2439: if ($totalparms>0) {
1.473 amueller 2440: my $firstrow=1;
2441: my $title=&Apache::lonnet::gettitle($symbp{$rid});
1.419 bisitz 2442: $r->print('<tr><td style="background-color:'.$defbgone.';"'.
1.57 albertel 2443: ' rowspan='.$totalparms.
1.419 bisitz 2444: '><tt><font size="-1">'.
1.57 albertel 2445: join(' / ',split(/\//,$uri)).
2446: '</font></tt><p><b>'.
1.154 albertel 2447: "<a href=\"javascript:openWindow('".
1.473 amueller 2448: &Apache::lonnet::clutter($uri).'?symb='.
2449: &escape($symbp{$rid}).
1.336 albertel 2450: "', 'metadatafile', '450', '500', 'no', 'yes');\"".
2451: " target=\"_self\">$title");
1.57 albertel 2452:
2453: if ($thistitle) {
1.473 amueller 2454: $r->print(' ('.$thistitle.')');
1.57 albertel 2455: }
2456: $r->print('</a></b></td>');
1.419 bisitz 2457: $r->print('<td style="background-color:'.$defbgtwo.';"'.
1.57 albertel 2458: ' rowspan='.$totalparms.'>'.$typep{$rid}.
2459: '</td>');
2460:
1.419 bisitz 2461: $r->print('<td style="background-color:'.$defbgone.';"'.
1.57 albertel 2462: ' rowspan='.$totalparms.
1.238 www 2463: '>'.$maptitles{$mapp{$rid}}.'</td>');
1.57 albertel 2464:
1.236 albertel 2465: foreach (&keysinorder_bytype(\%name,\%keyorder)) {
1.57 albertel 2466: unless ($firstrow) {
2467: $r->print('<tr>');
2468: } else {
2469: undef $firstrow;
2470: }
1.201 www 2471: &print_row($r,$_,\%part,\%name,\%symbp,$rid,\%default,
1.57 albertel 2472: \%type,\%display,$defbgone,$defbgtwo,
1.269 raeburn 2473: $defbgthree,$parmlev,$uname,$udom,$csec,
1.275 raeburn 2474: $cgroup,\@usersgroups);
1.57 albertel 2475: }
2476: }
2477: }
2478: } # end foreach ids
1.43 albertel 2479: # -------------------------------------------------- End entry for one resource
1.57 albertel 2480: $r->print('</table>');
1.203 www 2481: } # end of full
1.57 albertel 2482: #--------------------------------------------------- Entry for parm level map
2483: if ($parmlev eq 'map') {
1.419 bisitz 2484: my $defbgone = '#E0E099';
2485: my $defbgtwo = '#FFFF99';
2486: my $defbgthree = '#FFBB99';
1.57 albertel 2487:
2488: my %maplist;
2489:
2490: if ($pschp eq 'all') {
1.446 bisitz 2491: %maplist = %allmaps;
1.57 albertel 2492: } else {
2493: %maplist = ($pschp => $mapp{$pschp});
2494: }
2495:
2496: #-------------------------------------------- for each map, gather information
2497: my $mapid;
1.473 amueller 2498: foreach $mapid (sort {$maplist{$a} cmp $maplist{$b}} keys %maplist) {
1.60 albertel 2499: my $maptitle = $maplist{$mapid};
1.57 albertel 2500:
2501: #----------------------- loop through ids and get all parameter types for map
2502: #----------------------------------------- and associated information
2503: my %name = ();
2504: my %part = ();
2505: my %display = ();
2506: my %type = ();
2507: my %default = ();
2508: my $map = 0;
2509:
1.473 amueller 2510: # $r->print("Catmarker: @catmarker<br />\n");
1.446 bisitz 2511:
1.57 albertel 2512: foreach (@ids) {
1.473 amueller 2513: ($map)=(/([\d]*?)\./);
2514: my $rid = $_;
1.446 bisitz 2515:
1.57 albertel 2516: # $r->print("$mapid:$map: $rid <br /> \n");
2517:
1.473 amueller 2518: if ($map eq $mapid) {
2519: my $uri=&Apache::lonnet::declutter($uris{$rid});
1.57 albertel 2520: # $r->print("Keys: $keyp{$rid} <br />\n");
2521:
2522: #--------------------------------------------------------------------
2523: # @catmarker contains list of all possible parameters including part #s
2524: # $fullkeyp contains the full part/id # for the extraction of proper parameters
2525: # $tempkeyp contains part 0 only (no ids - ie, subparts)
2526: # When storing information, store as part 0
2527: # When requesting information, request from full part
2528: #-------------------------------------------------------------------
1.473 amueller 2529: foreach (&keysplit($keyp{$rid})) {
2530: my $tempkeyp = $_;
2531: my $fullkeyp = $tempkeyp;
2532: $tempkeyp =~ s/_\w+_/_0_/;
2533:
2534: if ((grep $_ eq $fullkeyp, @catmarker) &&(!$name{$tempkeyp})) {
2535: $part{$tempkeyp}="0";
2536: $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name');
2537: my $parmdis=&Apache::lonnet::metadata($uri,$fullkeyp.'.display');
2538: if ($allparms{$name{$tempkeyp}} ne '') {
2539: my $identifier;
2540: if ($parmdis =~ /(\s*\[Part.*)$/) {
2541: $identifier = $1;
2542: }
2543: $display{$tempkeyp} = $allparms{$name{$tempkeyp}}.$identifier;
2544: } else {
2545: $display{$tempkeyp} = $parmdis;
2546: }
2547: unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
2548: $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
2549: $display{$tempkeyp} =~ s/_\w+_/_0_/;
2550: $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp);
2551: $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type');
2552: }
2553: } # end loop through keys
2554: }
1.57 albertel 2555: } # end loop through ids
1.446 bisitz 2556:
1.57 albertel 2557: #---------------------------------------------------- print header information
1.133 www 2558: my $foldermap=&mt($maptitle=~/^uploaded/?'Folder':'Map');
1.82 www 2559: my $showtitle=$maptitles{$maptitle}.($maptitle!~/^uploaded/?' ['.$maptitle.']':'');
1.401 bisitz 2560: my $tmp="";
1.57 albertel 2561: if ($uname) {
1.473 amueller 2562: my $person=&Apache::loncommon::plainname($uname,$udom);
1.401 bisitz 2563: $tmp.=&mt("User")." <font color=\"red\"><i>$uname \($person\) </i></font> ".
2564: &mt('in')." \n";
1.57 albertel 2565: } else {
1.401 bisitz 2566: $tmp.="<font color=\"red\"><i>".&mt('all').'</i></font> '.&mt('users in')." \n";
1.57 albertel 2567: }
1.269 raeburn 2568: if ($cgroup) {
1.401 bisitz 2569: $tmp.=&mt("Group")." <font color=\"red\"><i>$cgroup".
2570: "</i></font> ".&mt('of')." \n";
1.269 raeburn 2571: $csec = '';
2572: } elsif ($csec) {
1.401 bisitz 2573: $tmp.=&mt("Section")." <font color=\"red\"><i>$csec".
2574: "</i></font> ".&mt('of')." \n";
1.269 raeburn 2575: }
1.401 bisitz 2576: $r->print('<div align="center"><h4>'
2577: .&mt('Set Defaults for All Resources in [_1]Specifically for [_2][_3]'
1.404 bisitz 2578: ,$foldermap.'<br /><font color="red"><i>'.$showtitle.'</i></font><br />'
1.401 bisitz 2579: ,$tmp
2580: ,'<font color="red"><i>'.$coursename.'</i></font>'
2581: )
2582: ."<br /></h4>\n"
1.422 bisitz 2583: );
1.57 albertel 2584: #---------------------------------------------------------------- print table
1.419 bisitz 2585: $r->print('<p>'.&Apache::loncommon::start_data_table()
2586: .&Apache::loncommon::start_data_table_header_row()
2587: .'<th>'.&mt('Parameter Name').'</th>'
2588: .'<th>'.&mt('Default Value').'</th>'
2589: .'<th>'.&mt('Parameter in Effect').'</th>'
2590: .&Apache::loncommon::end_data_table_header_row()
2591: );
1.57 albertel 2592:
1.473 amueller 2593: foreach (&keysinorder(\%name,\%keyorder)) {
2594: $r->print(&Apache::loncommon::start_data_table_row());
1.201 www 2595: &print_row($r,$_,\%part,\%name,\%symbp,$mapid,\%default,
1.269 raeburn 2596: \%type,\%display,$defbgone,$defbgtwo,$defbgthree,
2597: $parmlev,$uname,$udom,$csec,$cgroup);
1.57 albertel 2598: }
1.422 bisitz 2599: $r->print(&Apache::loncommon::end_data_table().'</p>'
2600: .'</div>'
2601: );
1.57 albertel 2602: } # end each map
2603: } # end of $parmlev eq map
2604: #--------------------------------- Entry for parm level general (Course level)
2605: if ($parmlev eq 'general') {
1.473 amueller 2606: my $defbgone = '#E0E099';
1.419 bisitz 2607: my $defbgtwo = '#FFFF99';
2608: my $defbgthree = '#FFBB99';
1.57 albertel 2609:
2610: #-------------------------------------------- for each map, gather information
2611: my $mapid="0.0";
2612: #----------------------- loop through ids and get all parameter types for map
2613: #----------------------------------------- and associated information
2614: my %name = ();
2615: my %part = ();
2616: my %display = ();
2617: my %type = ();
2618: my %default = ();
1.446 bisitz 2619:
1.57 albertel 2620: foreach (@ids) {
2621: my $rid = $_;
1.446 bisitz 2622:
1.196 www 2623: my $uri=&Apache::lonnet::declutter($uris{$rid});
1.57 albertel 2624:
2625: #--------------------------------------------------------------------
2626: # @catmarker contains list of all possible parameters including part #s
2627: # $fullkeyp contains the full part/id # for the extraction of proper parameters
2628: # $tempkeyp contains part 0 only (no ids - ie, subparts)
2629: # When storing information, store as part 0
2630: # When requesting information, request from full part
2631: #-------------------------------------------------------------------
1.473 amueller 2632: foreach (&keysplit($keyp{$rid})) {
2633: my $tempkeyp = $_;
2634: my $fullkeyp = $tempkeyp;
2635: $tempkeyp =~ s/_\w+_/_0_/;
2636: if ((grep $_ eq $fullkeyp, @catmarker) &&(!$name{$tempkeyp})) {
2637: $part{$tempkeyp}="0";
2638: $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name');
2639: my $parmdis=&Apache::lonnet::metadata($uri,$fullkeyp.'.display');
2640: if ($allparms{$name{$tempkeyp}} ne '') {
2641: my $identifier;
2642: if ($parmdis =~ /(\s*\[Part.*)$/) {
2643: $identifier = $1;
2644: }
2645: $display{$tempkeyp} = $allparms{$name{$tempkeyp}}.$identifier;
2646: } else {
2647: $display{$tempkeyp} = $parmdis;
2648: }
2649: unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
2650: $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
2651: $display{$tempkeyp} =~ s/_\w+_/_0_/;
2652: $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp);
2653: $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type');
2654: }
1.57 albertel 2655: } # end loop through keys
2656: } # end loop through ids
1.446 bisitz 2657:
1.57 albertel 2658: #---------------------------------------------------- print header information
1.473 amueller 2659: my $setdef=&mt("Set Defaults for All Resources in Course");
1.57 albertel 2660: $r->print(<<ENDMAPONE);
1.419 bisitz 2661: <center>
2662: <h4>$setdef
1.135 albertel 2663: <font color="red"><i>$coursename</i></font><br />
1.57 albertel 2664: ENDMAPONE
2665: if ($uname) {
1.473 amueller 2666: my $person=&Apache::loncommon::plainname($uname,$udom);
1.135 albertel 2667: $r->print(" ".&mt("User")."<font color=\"red\"> <i>$uname \($person\) </i></font> \n");
1.57 albertel 2668: } else {
1.135 albertel 2669: $r->print("<i><font color=\"red\"> ".&mt("ALL")."</i> ".&mt("USERS")."</font> \n");
1.57 albertel 2670: }
1.446 bisitz 2671:
1.135 albertel 2672: if ($csec) {$r->print(&mt("Section")."<font color=\"red\"> <i>$csec</i></font>\n")};
1.306 albertel 2673: if ($cgroup) {$r->print(&mt("Group")."<font color=\"red\"> <i>$cgroup</i></font>\n")};
1.135 albertel 2674: $r->print("</h4>\n");
1.57 albertel 2675: #---------------------------------------------------------------- print table
1.419 bisitz 2676: $r->print('<p>'.&Apache::loncommon::start_data_table()
2677: .&Apache::loncommon::start_data_table_header_row()
2678: .'<th>'.&mt('Parameter Name').'</th>'
2679: .'<th>'.&mt('Default Value').'</th>'
2680: .'<th>'.&mt('Parameter in Effect').'</th>'
2681: .&Apache::loncommon::end_data_table_header_row()
2682: );
1.57 albertel 2683:
1.473 amueller 2684: foreach (&keysinorder(\%name,\%keyorder)) {
1.419 bisitz 2685: $r->print(&Apache::loncommon::start_data_table_row());
1.201 www 2686: &print_row($r,$_,\%part,\%name,\%symbp,$mapid,\%default,
1.269 raeburn 2687: \%type,\%display,$defbgone,$defbgtwo,$defbgthree,
2688: $parmlev,$uname,$udom,$csec,$cgroup);
1.57 albertel 2689: }
1.419 bisitz 2690: $r->print(&Apache::loncommon::end_data_table()
2691: .'</p>'
2692: .'</center>'
2693: );
1.57 albertel 2694: } # end of $parmlev eq general
1.43 albertel 2695: }
1.280 albertel 2696: $r->print('</form>'.&Apache::loncommon::end_page());
1.57 albertel 2697: } # end sub assessparms
1.30 www 2698:
1.120 www 2699: ##################################################
1.207 www 2700: # Overview mode
2701: ##################################################
1.124 www 2702: my $tableopen;
2703:
2704: sub tablestart {
2705: if ($tableopen) {
1.473 amueller 2706: return '';
1.124 www 2707: } else {
1.473 amueller 2708: $tableopen=1;
2709: return &Apache::loncommon::start_data_table().'<tr><th>'.&mt('Parameter').'</th><th>'.
2710: &mt('Delete').'</th><th>'.&mt('Set to ...').'</th></tr>';
1.124 www 2711: }
2712: }
2713:
2714: sub tableend {
2715: if ($tableopen) {
1.473 amueller 2716: $tableopen=0;
2717: return &Apache::loncommon::end_data_table();
1.124 www 2718: } else {
1.473 amueller 2719: return'';
1.124 www 2720: }
2721: }
2722:
1.207 www 2723: sub readdata {
2724: my ($crs,$dom)=@_;
2725: # Read coursedata
2726: my $resourcedata=&Apache::lonnet::get_courseresdata($crs,$dom);
2727: # Read userdata
2728:
2729: my $classlist=&Apache::loncoursedata::get_classlist();
2730: foreach (keys %$classlist) {
1.350 albertel 2731: if ($_=~/^($match_username)\:($match_domain)$/) {
1.473 amueller 2732: my ($tuname,$tudom)=($1,$2);
2733: my $useropt=&Apache::lonnet::get_userresdata($tuname,$tudom);
1.207 www 2734: foreach my $userkey (keys %{$useropt}) {
1.473 amueller 2735: if ($userkey=~/^$env{'request.course.id'}/) {
1.207 www 2736: my $newkey=$userkey;
1.473 amueller 2737: $newkey=~s/^($env{'request.course.id'}\.)/$1\[useropt\:$tuname\:$tudom\]\./;
2738: $$resourcedata{$newkey}=$$useropt{$userkey};
2739: }
2740: }
2741: }
1.207 www 2742: }
2743: return $resourcedata;
2744: }
2745:
2746:
1.124 www 2747: # Setting
1.208 www 2748:
2749: sub storedata {
2750: my ($r,$crs,$dom)=@_;
1.207 www 2751: # Set userlevel immediately
2752: # Do an intermediate store of course level
2753: my $olddata=&readdata($crs,$dom);
1.124 www 2754: my %newdata=();
2755: undef %newdata;
2756: my @deldata=();
2757: undef @deldata;
1.190 albertel 2758: foreach (keys %env) {
1.473 amueller 2759: if ($_=~/^form\.([a-z]+)\_(.+)$/) {
2760: my $cmd=$1;
2761: my $thiskey=$2;
2762: my ($tuname,$tudom)=&extractuser($thiskey);
2763: my $tkey=$thiskey;
2764: if ($tuname) {
2765: $tkey=~s/\.\[useropt\:$tuname\:$tudom\]\./\./;
2766: }
2767: if ($cmd eq 'set' || $cmd eq 'datepointer' || $cmd eq 'dateinterval') {
2768: my ($data, $typeof, $text);
2769: if ($cmd eq 'set') {
2770: $data=$env{$_};
2771: $typeof=$env{'form.typeof_'.$thiskey};
2772: $text = &mt('Saved modified parameter for');
2773: } elsif ($cmd eq 'datepointer') {
2774: $data=&Apache::lonhtmlcommon::get_date_from_form($env{$_});
2775: $typeof=$env{'form.typeof_'.$thiskey};
2776: $text = &mt('Saved modified date for');
2777: } elsif ($cmd eq 'dateinterval') {
2778: $data=&get_date_interval_from_form($thiskey);
2779: $typeof=$env{'form.typeof_'.$thiskey};
2780: $text = &mt('Saved modified date for');
2781: }
2782: if (defined($data) and $$olddata{$thiskey} ne $data) {
1.207 www 2783: if ($tuname) {
1.473 amueller 2784: if (&Apache::lonnet::put('resourcedata',{$tkey=>$data,
2785: $tkey.'.type' => $typeof},
2786: $tudom,$tuname) eq 'ok') {
2787: &log_parmset({$tkey=>$data,$tkey.'.type' => $typeof},0,$tuname,$tudom);
2788: $r->print('<br />'.$text.' '.
2789: &Apache::loncommon::plainname($tuname,$tudom));
2790: } else {
2791: $r->print('<div class="LC_error">'.
2792: &mt('Error saving parameters').'</div>');
2793: }
2794: &Apache::lonnet::devalidateuserresdata($tuname,$tudom);
2795: } else {
2796: $newdata{$thiskey}=$data;
2797: $newdata{$thiskey.'.type'}=$typeof;
1.446 bisitz 2798: }
1.473 amueller 2799: }
2800: } elsif ($cmd eq 'del') {
2801: if ($tuname) {
2802: if (&Apache::lonnet::del('resourcedata',[$tkey],$tudom,$tuname) eq 'ok') {
2803: &log_parmset({$tkey=>''},1,$tuname,$tudom);
2804: $r->print('<br />'.&mt('Deleted parameter for').' '.&Apache::loncommon::plainname($tuname,$tudom));
2805: } else {
2806: $r->print('<div class="LC_error">'.
2807: &mt('Error deleting parameters').'</div>');
2808: }
2809: &Apache::lonnet::devalidateuserresdata($tuname,$tudom);
2810: } else {
2811: push (@deldata,$thiskey,$thiskey.'.type');
2812: }
2813: }
2814: }
1.124 www 2815: }
1.207 www 2816: # Store all course level
1.144 www 2817: my $delentries=$#deldata+1;
2818: my @newdatakeys=keys %newdata;
2819: my $putentries=$#newdatakeys+1;
2820: if ($delentries) {
1.473 amueller 2821: if (&Apache::lonnet::del('resourcedata',\@deldata,$dom,$crs) eq 'ok') {
2822: my %loghash=map { $_ => '' } @deldata;
2823: &log_parmset(\%loghash,1);
2824: $r->print('<h2>'.&mt('Deleted [_1] parameter(s)</h2>',$delentries));
2825: } else {
2826: $r->print('<div class="LC_error">'.
2827: &mt('Error deleting parameters').'</div>');
2828: }
2829: &Apache::lonnet::devalidatecourseresdata($crs,$dom);
1.144 www 2830: }
2831: if ($putentries) {
1.473 amueller 2832: if (&Apache::lonnet::put('resourcedata',\%newdata,$dom,$crs) eq 'ok') {
2833: &log_parmset(\%newdata,0);
2834: $r->print('<h3>'.&mt('Saved [_1] parameter(s)',$putentries/2).'</h3>');
2835: } else {
2836: $r->print('<div class="LC_error">'.
2837: &mt('Error saving parameters').'</div>');
2838: }
2839: &Apache::lonnet::devalidatecourseresdata($crs,$dom);
1.144 www 2840: }
1.208 www 2841: }
1.207 www 2842:
1.208 www 2843: sub extractuser {
2844: my $key=shift;
1.350 albertel 2845: return ($key=~/^$env{'request.course.id'}.\[useropt\:($match_username)\:($match_domain)\]\./);
1.208 www 2846: }
1.206 www 2847:
1.381 albertel 2848: sub parse_listdata_key {
2849: my ($key,$listdata) = @_;
2850: # split into student/section affected, and
2851: # the realm (folder/resource part and parameter
1.446 bisitz 2852: my ($student,$realm) =
1.473 amueller 2853: ($key=~/^\Q$env{'request.course.id'}\E\.\[([^\.]+)\]\.(.+)$/);
1.381 albertel 2854: # if course wide student would be undefined
2855: if (!defined($student)) {
1.473 amueller 2856: ($realm)=($key=~/^\Q$env{'request.course.id'}\E\.(.+)$/);
1.381 albertel 2857: }
2858: # strip off the .type if it's not the Question type parameter
2859: if ($realm=~/\.type$/ && !exists($listdata->{$key.'.type'})) {
1.473 amueller 2860: $realm=~s/\.type//;
1.381 albertel 2861: }
2862: # split into resource+part and parameter name
1.388 albertel 2863: my ($res, $parm) = ($realm=~/^(.*)\.(.*)$/);
2864: ($res, my $part) = ($res =~/^(.*)\.(.*)$/);
1.381 albertel 2865: return ($student,$res,$part,$parm);
2866: }
2867:
1.208 www 2868: sub listdata {
1.214 www 2869: my ($r,$resourcedata,$listdata,$sortorder)=@_;
1.207 www 2870: # Start list output
1.206 www 2871:
1.122 www 2872: my $oldsection='';
2873: my $oldrealm='';
2874: my $oldpart='';
1.123 www 2875: my $pointer=0;
1.124 www 2876: $tableopen=0;
1.145 www 2877: my $foundkeys=0;
1.248 albertel 2878: my %keyorder=&standardkeyorder();
1.381 albertel 2879:
1.214 www 2880: foreach my $thiskey (sort {
1.473 amueller 2881: my ($astudent,$ares,$apart,$aparm) = &parse_listdata_key($a,$listdata);
2882: my ($bstudent,$bres,$bpart,$bparm) = &parse_listdata_key($b,$listdata);
1.381 albertel 2883:
1.473 amueller 2884: # get the numerical order for the param
2885: $aparm=$keyorder{'parameter_0_'.$aparm};
2886: $bparm=$keyorder{'parameter_0_'.$bparm};
1.381 albertel 2887:
1.473 amueller 2888: my $result=0;
1.381 albertel 2889:
1.473 amueller 2890: if ($sortorder eq 'realmstudent') {
1.381 albertel 2891: if ($ares ne $bres ) {
1.473 amueller 2892: $result = ($ares cmp $bres);
1.446 bisitz 2893: } elsif ($astudent ne $bstudent) {
1.473 amueller 2894: $result = ($astudent cmp $bstudent);
2895: } elsif ($apart ne $bpart ) {
2896: $result = ($apart cmp $bpart);
2897: }
2898: } else {
2899: if ($astudent ne $bstudent) {
2900: $result = ($astudent cmp $bstudent);
2901: } elsif ($ares ne $bres ) {
2902: $result = ($ares cmp $bres);
2903: } elsif ($apart ne $bpart ) {
2904: $result = ($apart cmp $bpart);
2905: }
2906: }
1.446 bisitz 2907:
1.473 amueller 2908: if (!$result) {
1.381 albertel 2909: if (defined($aparm) && defined($bparm)) {
1.473 amueller 2910: $result = ($aparm <=> $bparm);
1.381 albertel 2911: } elsif (defined($aparm)) {
1.473 amueller 2912: $result = -1;
1.381 albertel 2913: } elsif (defined($bparm)) {
1.473 amueller 2914: $result = 1;
2915: }
2916: }
1.381 albertel 2917:
1.473 amueller 2918: $result;
1.214 www 2919: } keys %{$listdata}) {
1.381 albertel 2920:
1.473 amueller 2921: if ($$listdata{$thiskey.'.type'}) {
1.211 www 2922: my $thistype=$$listdata{$thiskey.'.type'};
2923: if ($$resourcedata{$thiskey.'.type'}) {
1.473 amueller 2924: $thistype=$$resourcedata{$thiskey.'.type'};
2925: }
2926: my ($middle,$part,$name)=
2927: ($thiskey=~/^$env{'request.course.id'}\.(?:(.+)\.)*([\w\s]+)\.(\w+)$/);
2928: my $section=&mt('All Students');
2929: if ($middle=~/^\[(.*)\]/) {
2930: my $issection=$1;
2931: if ($issection=~/^useropt\:($match_username)\:($match_domain)/) {
2932: $section=&mt('User').": ".&Apache::loncommon::plainname($1,$2);
2933: } else {
2934: $section=&mt('Group/Section').': '.$issection;
2935: }
2936: $middle=~s/^\[(.*)\]//;
2937: }
2938: $middle=~s/\.+$//;
2939: $middle=~s/^\.+//;
2940: my $realm='<span class="LC_parm_scope_all">'.&mt('All Resources').'</span>';
2941: if ($middle=~/^(.+)\_\_\_\(all\)$/) {
2942: $realm='<span class="LC_parm_scope_folder">'.&mt('Folder/Map').': '.&Apache::lonnet::gettitle($1).' <br /><span class="LC_parm_folder">('.$1.')</span></span>';
2943: } elsif ($middle) {
2944: my ($map,$id,$url)=&Apache::lonnet::decode_symb($middle);
2945: $realm='<span class="LC_parm_scope_resource">'.&mt('Resource').': '.&Apache::lonnet::gettitle($middle).' <br /><span class="LC_parm_symb">('.$url.' in '.$map.' id: '.$id.')</span></span>';
2946: }
2947: if ($sortorder eq 'realmstudent') {
2948: if ($realm ne $oldrealm) {
2949: $r->print(&tableend()."\n<hr /><h1>$realm</h1>");
2950: $oldrealm=$realm;
2951: $oldsection='';
2952: }
2953: if ($section ne $oldsection) {
2954: $r->print(&tableend()."\n<h2>$section</h2>");
2955: $oldsection=$section;
2956: $oldpart='';
2957: }
2958: } else {
2959: if ($section ne $oldsection) {
2960: $r->print(&tableend()."\n<hr /><h1>$section</h1>");
2961: $oldsection=$section;
2962: $oldrealm='';
2963: }
2964: if ($realm ne $oldrealm) {
2965: $r->print(&tableend()."\n<h2>$realm</h2>");
2966: $oldrealm=$realm;
2967: $oldpart='';
2968: }
2969: }
2970: if ($part ne $oldpart) {
2971: $r->print(&tableend().
2972: "\n".'<span class="LC_parm_part">'.&mt('Part').": $part</span>");
2973: $oldpart=$part;
2974: }
1.123 www 2975: #
2976: # Ready to print
2977: #
1.470 raeburn 2978: my $parmitem = &standard_parameter_names($name);
1.473 amueller 2979: $r->print(&tablestart().
2980: &Apache::loncommon::start_data_table_row().
2981: '<td><b>'.&mt($parmitem).
2982: '</b></td><td><input type="checkbox" name="del_'.
2983: $thiskey.'" /></td><td>');
2984: $foundkeys++;
2985: if (&isdateparm($thistype)) {
2986: my $jskey='key_'.$pointer;
2987: $pointer++;
2988: $r->print(
2989: &Apache::lonhtmlcommon::date_setter('parmform',
2990: $jskey,
2991: $$resourcedata{$thiskey},
2992: '',1,'','').
1.277 www 2993: '<input type="hidden" name="datepointer_'.$thiskey.'" value="'.$jskey.'" />'.
1.413 bisitz 2994: (($$resourcedata{$thiskey}!=0)?'<span class="LC_nobreak"><a href="/adm/parmset?&action=dateshift1&timebase='.$$resourcedata{$thiskey}.'">'.
2995: &mt('Shift all dates based on this date').'</a></span>':'').
1.277 www 2996: &date_sanity_info($$resourcedata{$thiskey})
1.473 amueller 2997: );
2998: } elsif ($thistype eq 'date_interval') {
2999: $r->print(&date_interval_selector($thiskey,
3000: $$resourcedata{$thiskey}));
3001: } elsif ($thistype =~ m/^string/) {
3002: $r->print(&string_selector($thistype,$thiskey,
3003: $$resourcedata{$thiskey}));
3004: } else {
3005: $r->print(&default_selector($thiskey,$$resourcedata{$thiskey}));
3006: }
3007: $r->print('<input type="hidden" name="typeof_'.$thiskey.'" value="'.
3008: $thistype.'" />');
3009: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
3010: }
1.121 www 3011: }
1.208 www 3012: return $foundkeys;
3013: }
3014:
1.385 albertel 3015:
3016: sub date_interval_selector {
3017: my ($thiskey, $showval) = @_;
3018: my $result;
3019: foreach my $which (['days', 86400, 31],
1.473 amueller 3020: ['hours', 3600, 23],
3021: ['minutes', 60, 59],
3022: ['seconds', 1, 59]) {
3023: my ($name, $factor, $max) = @{ $which };
3024: my $amount = int($showval/$factor);
3025: $showval %= $factor;
3026: my %select = ((map {$_ => $_} (0..$max)),
3027: 'select_form_order' => [0..$max]);
3028: $result .= &Apache::loncommon::select_form($amount,$name.'_'.$thiskey,
1.496 raeburn 3029: \%select);
1.473 amueller 3030: $result .= ' '.&mt($name);
1.385 albertel 3031: }
3032: $result .= '<input type="hidden" name="dateinterval_'.$thiskey.'" />';
3033: return $result;
3034:
3035: }
3036:
3037: sub get_date_interval_from_form {
3038: my ($key) = @_;
3039: my $seconds = 0;
3040: foreach my $which (['days', 86400],
1.473 amueller 3041: ['hours', 3600],
3042: ['minutes', 60],
3043: ['seconds', 1]) {
3044: my ($name, $factor) = @{ $which };
3045: if (defined($env{'form.'.$name.'_'.$key})) {
3046: $seconds += $env{'form.'.$name.'_'.$key} * $factor;
3047: }
1.385 albertel 3048: }
3049: return $seconds;
3050: }
3051:
3052:
1.383 albertel 3053: sub default_selector {
3054: my ($thiskey, $showval) = @_;
1.385 albertel 3055: return '<input type="text" name="set_'.$thiskey.'" value="'.$showval.'" />';
1.383 albertel 3056: }
3057:
1.446 bisitz 3058: my %strings =
1.383 albertel 3059: (
3060: 'string_yesno'
3061: => [[ 'yes', 'Yes' ],
1.473 amueller 3062: [ 'no', 'No' ]],
1.383 albertel 3063: 'string_problemstatus'
3064: => [[ 'yes', 'Yes' ],
1.473 amueller 3065: [ 'answer', 'Yes, and show correct answer if they exceed the maximum number of tries.' ],
3066: [ 'no', 'No, don\'t show correct/incorrect feedback.' ],
3067: [ 'no_feedback_ever', 'No, show no feedback at all.' ]],
1.383 albertel 3068: );
3069:
3070:
3071: sub string_selector {
3072: my ($thistype, $thiskey, $showval) = @_;
1.446 bisitz 3073:
1.383 albertel 3074: if (!exists($strings{$thistype})) {
1.473 amueller 3075: return &default_selector($thiskey,$showval);
1.383 albertel 3076: }
3077:
3078: my $result;
3079: foreach my $possibilities (@{ $strings{$thistype} }) {
1.473 amueller 3080: my ($name, $description) = @{ $possibilities };
3081: $result .= '<label><input type="radio" name="set_'.$thiskey.
3082: '" value="'.$name.'"';
3083: if ($showval eq $name) {
3084: $result .= ' checked="checked"';
3085: }
3086: $result .= ' />'.&mt($description).'</label> ';
1.383 albertel 3087: }
3088: return $result;
3089: }
3090:
1.389 www 3091: #
3092: # Shift all start and end dates by $shift
3093: #
3094:
3095: sub dateshift {
3096: my ($shift)=@_;
3097: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3098: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
3099: my %data=&Apache::lonnet::dump('resourcedata',$dom,$crs);
3100: # ugly retro fix for broken version of types
3101: foreach my $key (keys %data) {
3102: if ($key=~/\wtype$/) {
3103: my $newkey=$key;
3104: $newkey=~s/type$/\.type/;
3105: $data{$newkey}=$data{$key};
3106: delete $data{$key};
3107: }
3108: }
1.391 www 3109: my %storecontent=();
1.389 www 3110: # go through all parameters and look for dates
3111: foreach my $key (keys %data) {
3112: if ($data{$key.'.type'}=~/^date_(start|end)$/) {
3113: my $newdate=$data{$key}+$shift;
1.391 www 3114: $storecontent{$key}=$newdate;
1.389 www 3115: }
3116: }
1.391 www 3117: my $reply=&Apache::lonnet::cput
3118: ('resourcedata',\%storecontent,$dom,$crs);
3119: if ($reply eq 'ok') {
3120: &log_parmset(\%storecontent);
3121: }
3122: &Apache::lonnet::devalidatecourseresdata($crs,$dom);
3123: return $reply;
1.389 www 3124: }
3125:
1.208 www 3126: sub newoverview {
1.280 albertel 3127: my ($r) = @_;
3128:
1.208 www 3129: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3130: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
1.414 droeschl 3131: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setoverview',
1.473 amueller 3132: text=>"Overview Mode"});
1.280 albertel 3133: my $start_page = &Apache::loncommon::start_page('Set Parameters');
1.298 albertel 3134: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Overview');
1.208 www 3135: $r->print(<<ENDOVER);
1.280 albertel 3136: $start_page
1.208 www 3137: $breadcrumbs
1.232 albertel 3138: <form method="post" action="/adm/parmset?action=newoverview" name="parmform">
1.208 www 3139: ENDOVER
1.211 www 3140: my @ids=();
3141: my %typep=();
3142: my %keyp=();
3143: my %allparms=();
3144: my %allparts=();
3145: my %allmaps=();
3146: my %mapp=();
3147: my %symbp=();
3148: my %maptitles=();
3149: my %uris=();
3150: my %keyorder=&standardkeyorder();
3151: my %defkeytype=();
3152:
3153: my %alllevs=();
3154: $alllevs{'Resource Level'}='full';
1.215 www 3155: $alllevs{'Map/Folder Level'}='map';
1.211 www 3156: $alllevs{'Course Level'}='general';
3157:
3158: my $csec=$env{'form.csec'};
1.269 raeburn 3159: my $cgroup=$env{'form.cgroup'};
1.211 www 3160:
3161: my @pscat=&Apache::loncommon::get_env_multiple('form.pscat');
3162: my $pschp=$env{'form.pschp'};
3163: my @psprt=&Apache::loncommon::get_env_multiple('form.psprt');
3164: if (!@psprt) { $psprt[0]='0'; }
3165:
1.446 bisitz 3166: my @selected_sections =
1.473 amueller 3167: &Apache::loncommon::get_env_multiple('form.Section');
1.211 www 3168: @selected_sections = ('all') if (! @selected_sections);
1.374 albertel 3169: foreach my $sec (@selected_sections) {
3170: if ($sec eq 'all') {
1.211 www 3171: @selected_sections = ('all');
3172: }
3173: }
1.269 raeburn 3174: my @selected_groups =
3175: &Apache::loncommon::get_env_multiple('form.Group');
1.211 www 3176:
3177: my $pssymb='';
3178: my $parmlev='';
1.446 bisitz 3179:
1.211 www 3180: unless ($env{'form.parmlev'}) {
3181: $parmlev = 'map';
3182: } else {
3183: $parmlev = $env{'form.parmlev'};
3184: }
3185:
1.446 bisitz 3186: &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allmaps,
1.473 amueller 3187: \%mapp, \%symbp,\%maptitles,\%uris,
3188: \%keyorder,\%defkeytype);
1.211 www 3189:
1.374 albertel 3190: if (grep {$_ eq 'all'} (@psprt)) {
1.481 amueller 3191: @psprt = keys(%allparts);
1.374 albertel 3192: }
1.211 www 3193: # Menu to select levels, etc
3194:
1.456 bisitz 3195: $r->print('<div class="LC_Box">');
1.445 neumanie 3196: #$r->print('<h2 class="LC_hcell">Step 1</h2>');
1.452 bisitz 3197: $r->print('<div>');
1.445 neumanie 3198: $r->print(&Apache::lonhtmlcommon::start_pick_box());
1.211 www 3199: &levelmenu($r,\%alllevs,$parmlev);
3200: if ($parmlev ne 'general') {
1.447 bisitz 3201: $r->print(&Apache::lonhtmlcommon::row_closure());
1.483 amueller 3202: &mapmenu($r,\%allmaps,$pschp,\%maptitles,\%symbp);
1.211 www 3203: }
1.447 bisitz 3204: $r->print(&Apache::lonhtmlcommon::row_closure(1));
1.445 neumanie 3205: $r->print(&Apache::lonhtmlcommon::end_pick_box());
3206: $r->print('</div></div>');
1.446 bisitz 3207:
1.456 bisitz 3208: $r->print('<div class="LC_Box">');
1.452 bisitz 3209: $r->print('<div>');
1.446 bisitz 3210: $r->print(&Apache::lonhtmlcommon::start_pick_box());
1.445 neumanie 3211: &parmmenu($r,\%allparms,\@pscat,\%keyorder);
1.453 schualex 3212: $r->print(&Apache::lonhtmlcommon::end_pick_box());
3213: &parmboxes($r,\%allparms,\@pscat,\%keyorder);
3214: $r->print(&Apache::lonhtmlcommon::start_pick_box());
1.446 bisitz 3215: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Select Parts to View')));
1.481 amueller 3216: $r->print('<table>'.
1.317 albertel 3217: '<tr><th>'.&mt('Parts').'</th><th>'.&mt('Section(s)').
3218: '</th><th>'.&mt('Group(s)').'</th></tr><tr><td>');
1.211 www 3219: &partmenu($r,\%allparts,\@psprt);
1.317 albertel 3220: $r->print('</td><td>');
1.211 www 3221: §ionmenu($r,\@selected_sections);
1.317 albertel 3222: $r->print('</td><td>');
1.269 raeburn 3223: &groupmenu($r,\@selected_groups);
3224: $r->print('</td></tr></table>');
1.445 neumanie 3225: #$r->print('</td></tr></table>');
1.447 bisitz 3226: $r->print(&Apache::lonhtmlcommon::row_closure(1));
1.445 neumanie 3227: $r->print(&Apache::lonhtmlcommon::end_pick_box());
3228: $r->print('</div></div>');
3229:
1.456 bisitz 3230: $r->print('<div class="LC_Box">');
1.452 bisitz 3231: $r->print('<div>');
1.214 www 3232: my $sortorder=$env{'form.sortorder'};
3233: unless ($sortorder) { $sortorder='realmstudent'; }
3234: &sortmenu($r,$sortorder);
1.445 neumanie 3235: $r->print('</div></div>');
1.446 bisitz 3236:
1.214 www 3237: $r->print('<p><input type="submit" name="dis" value="'.&mt('Display').'" /></p>');
1.446 bisitz 3238:
1.211 www 3239: # Build the list data hash from the specified parms
3240:
3241: my $listdata;
3242: %{$listdata}=();
3243:
3244: foreach my $cat (@pscat) {
1.269 raeburn 3245: &secgroup_lister($cat,$pschp,$parmlev,$listdata,\@psprt,\@selected_sections,\%defkeytype,\%allmaps,\@ids,\%symbp);
3246: &secgroup_lister($cat,$pschp,$parmlev,$listdata,\@psprt,\@selected_groups,\%defkeytype,\%allmaps,\@ids,\%symbp);
1.211 www 3247: }
3248:
1.212 www 3249: if (($env{'form.store'}) || ($env{'form.dis'})) {
1.211 www 3250:
1.481 amueller 3251: if ($env{'form.store'}) { &storedata($r,$crs,$dom); }
1.211 www 3252:
3253: # Read modified data
3254:
1.481 amueller 3255: my $resourcedata=&readdata($crs,$dom);
1.211 www 3256:
3257: # List data
3258:
1.481 amueller 3259: &listdata($r,$resourcedata,$listdata,$sortorder);
1.211 www 3260: }
3261: $r->print(&tableend().
1.473 amueller 3262: ((($env{'form.store'}) || ($env{'form.dis'}))?'<p><input type="submit" name="store" value="'.&mt('Save').'" /></p>':'').
3263: '</form>'.&Apache::loncommon::end_page());
1.208 www 3264: }
3265:
1.269 raeburn 3266: sub secgroup_lister {
3267: my ($cat,$pschp,$parmlev,$listdata,$psprt,$selections,$defkeytype,$allmaps,$ids,$symbp) = @_;
3268: foreach my $item (@{$selections}) {
3269: foreach my $part (@{$psprt}) {
3270: my $rootparmkey=$env{'request.course.id'};
3271: if (($item ne 'all') && ($item ne 'none') && ($item)) {
3272: $rootparmkey.='.['.$item.']';
3273: }
3274: if ($parmlev eq 'general') {
3275: # course-level parameter
3276: my $newparmkey=$rootparmkey.'.'.$part.'.'.$cat;
3277: $$listdata{$newparmkey}=1;
3278: $$listdata{$newparmkey.'.type'}=$$defkeytype{$cat};
3279: } elsif ($parmlev eq 'map') {
3280: # map-level parameter
3281: foreach my $mapid (keys %{$allmaps}) {
3282: if (($pschp ne 'all') && ($pschp ne $mapid)) { next; }
3283: my $newparmkey=$rootparmkey.'.'.$$allmaps{$mapid}.'___(all).'.$part.'.'.$cat;
3284: $$listdata{$newparmkey}=1;
3285: $$listdata{$newparmkey.'.type'}=$$defkeytype{$cat};
3286: }
3287: } else {
3288: # resource-level parameter
3289: foreach my $rid (@{$ids}) {
3290: my ($map,$resid,$url)=&Apache::lonnet::decode_symb($$symbp{$rid});
3291: if (($pschp ne 'all') && ($$allmaps{$pschp} ne $map)) { next; }
3292: my $newparmkey=$rootparmkey.'.'.$$symbp{$rid}.'.'.$part.'.'.$cat;
3293: $$listdata{$newparmkey}=1;
3294: $$listdata{$newparmkey.'.type'}=$$defkeytype{$cat};
3295: }
3296: }
3297: }
3298: }
3299: }
3300:
1.208 www 3301: sub overview {
1.280 albertel 3302: my ($r) = @_;
1.208 www 3303: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3304: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
1.280 albertel 3305:
1.414 droeschl 3306: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setoverview',
1.473 amueller 3307: text=>"Overview Mode"});
1.280 albertel 3308: my $start_page=&Apache::loncommon::start_page('Modify Parameters');
1.298 albertel 3309: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Overview');
1.208 www 3310: $r->print(<<ENDOVER);
1.280 albertel 3311: $start_page
1.208 www 3312: $breadcrumbs
1.232 albertel 3313: <form method="post" action="/adm/parmset?action=setoverview" name="parmform">
1.208 www 3314: ENDOVER
3315: # Store modified
3316:
3317: &storedata($r,$crs,$dom);
3318:
3319: # Read modified data
3320:
3321: my $resourcedata=&readdata($crs,$dom);
3322:
1.214 www 3323:
3324: my $sortorder=$env{'form.sortorder'};
3325: unless ($sortorder) { $sortorder='realmstudent'; }
3326: &sortmenu($r,$sortorder);
3327:
1.208 www 3328: # List data
3329:
1.214 www 3330: my $foundkeys=&listdata($r,$resourcedata,$resourcedata,$sortorder);
1.208 www 3331:
1.145 www 3332: $r->print(&tableend().'<p>'.
1.473 amueller 3333: ($foundkeys?'<input type="submit" value="'.&mt('Save').'" />':&mt('There are no parameters.')).'</p></form>'.
3334: &Apache::loncommon::end_page());
1.120 www 3335: }
1.121 www 3336:
1.333 albertel 3337: sub clean_parameters {
3338: my ($r) = @_;
3339: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3340: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
3341:
1.414 droeschl 3342: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=cleanparameters',
1.473 amueller 3343: text=>"Clean Parameters"});
1.333 albertel 3344: my $start_page=&Apache::loncommon::start_page('Clean Parameters');
3345: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Clean');
3346: $r->print(<<ENDOVER);
3347: $start_page
3348: $breadcrumbs
3349: <form method="post" action="/adm/parmset?action=cleanparameters" name="parmform">
3350: ENDOVER
3351: # Store modified
3352:
3353: &storedata($r,$crs,$dom);
3354:
3355: # Read modified data
3356:
3357: my $resourcedata=&readdata($crs,$dom);
3358:
3359: # List data
3360:
3361: $r->print('<h3>'.
1.473 amueller 3362: &mt('These parameters refer to resources that do not exist.').
3363: '</h3>'.
3364: '<input type="submit" value="'.&mt('Delete Selected').'" />'.'<br />'.
3365: '<br />');
1.333 albertel 3366: $r->print(&Apache::loncommon::start_data_table().
1.473 amueller 3367: '<tr>'.
3368: '<th>'.&mt('Delete').'</th>'.
3369: '<th>'.&mt('Parameter').'</th>'.
3370: '</tr>');
1.333 albertel 3371: foreach my $thiskey (sort(keys(%{$resourcedata}))) {
1.473 amueller 3372: next if (!exists($resourcedata->{$thiskey.'.type'})
3373: && $thiskey=~/\.type$/);
3374: my %data = &parse_key($thiskey);
3375: if (1) { #exists($data{'realm_exists'})
3376: #&& !$data{'realm_exists'}) {
3377: $r->print(&Apache::loncommon::start_data_table_row().
3378: '<tr>'.
3379: '<td><input type="checkbox" name="del_'.$thiskey.'" /></td>' );
3380:
3381: $r->print('<td>');
3382: my $display_value = $resourcedata->{$thiskey};
3383: if (&isdateparm($resourcedata->{$thiskey.'.type'})) {
3384: $display_value =
3385: &Apache::lonlocal::locallocaltime($display_value);
3386: }
1.470 raeburn 3387: my $parmitem = &standard_parameter_names($data{'parameter_name'});
3388: $parmitem = &mt($parmitem);
1.473 amueller 3389: $r->print(&mt('Parameter: "[_1]" with value: "[_2]"',
3390: $parmitem,$resourcedata->{$thiskey}));
3391: $r->print('<br />');
3392: if ($data{'scope_type'} eq 'all') {
3393: $r->print(&mt('All users'));
3394: } elsif ($data{'scope_type'} eq 'user') {
3395: $r->print(&mt('User: [_1]',join(':',@{$data{'scope'}})));
3396: } elsif ($data{'scope_type'} eq 'section') {
3397: $r->print(&mt('Section: [_1]',$data{'scope'}));
3398: } elsif ($data{'scope_type'} eq 'group') {
3399: $r->print(&mt('Group: [_1]',$data{'scope'}));
3400: }
3401: $r->print('<br />');
3402: if ($data{'realm_type'} eq 'all') {
3403: $r->print(&mt('All Resources'));
3404: } elsif ($data{'realm_type'} eq 'folder') {
3405: $r->print(&mt('Folder: [_1]'),$data{'realm'});
3406: } elsif ($data{'realm_type'} eq 'symb') {
3407: my ($map,$resid,$url) =
3408: &Apache::lonnet::decode_symb($data{'realm'});
3409: $r->print(&mt('Resource: [_1] <br /> with ID: [_2] <br /> in folder [_3]',
3410: $url,$resid,$map));
3411: }
3412: $r->print(' <br /> '.&mt('Part: [_1]',$data{'parameter_part'}));
3413: $r->print('</td></tr>');
1.446 bisitz 3414:
1.473 amueller 3415: }
1.333 albertel 3416: }
3417: $r->print(&Apache::loncommon::end_data_table().'<p>'.
1.473 amueller 3418: '<input type="submit" value="'.&mt('Delete Selected').'" />'.
3419: '</p></form>'.
3420: &Apache::loncommon::end_page());
1.333 albertel 3421: }
3422:
1.390 www 3423: sub date_shift_one {
3424: my ($r) = @_;
3425: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3426: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
3427:
1.414 droeschl 3428: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=dateshift1&timebase='.$env{'form.timebase'},
1.473 amueller 3429: text=>"Shifting Dates"});
1.390 www 3430: my $start_page=&Apache::loncommon::start_page('Shift Dates');
3431: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Shift');
3432: $r->print(<<ENDOVER);
3433: $start_page
3434: $breadcrumbs
3435: ENDOVER
3436: $r->print('<form name="shiftform" method="post">'.
3437: '<table><tr><td>'.&mt('Currently set date:').'</td><td>'.
3438: &Apache::lonlocal::locallocaltime($env{'form.timebase'}).'</td></tr>'.
3439: '<tr><td>'.&mt('Shifted date:').'</td><td>'.
3440: &Apache::lonhtmlcommon::date_setter('shiftform',
3441: 'timeshifted',
3442: $env{'form.timebase'},,
3443: '').
3444: '</td></tr></table>'.
3445: '<input type="hidden" name="action" value="dateshift2" />'.
3446: '<input type="hidden" name="timebase" value="'.$env{'form.timebase'}.'" />'.
3447: '<input type="submit" value="'.&mt('Shift all dates accordingly').'" /></form>');
3448: $r->print(&Apache::loncommon::end_page());
3449: }
3450:
3451: sub date_shift_two {
3452: my ($r) = @_;
3453: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3454: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
1.414 droeschl 3455: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=dateshift1&timebase='.$env{'form.timebase'},
1.473 amueller 3456: text=>"Shifting Dates"});
1.390 www 3457: my $start_page=&Apache::loncommon::start_page('Shift Dates');
3458: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Shift');
3459: $r->print(<<ENDOVER);
3460: $start_page
3461: $breadcrumbs
3462: ENDOVER
3463: my $timeshifted=&Apache::lonhtmlcommon::get_date_from_form('timeshifted');
3464: $r->print(&mt('Shifting all dates such that [_1] becomes [_2]',
3465: &Apache::lonlocal::locallocaltime($env{'form.timebase'}),
3466: &Apache::lonlocal::locallocaltime($timeshifted)));
3467: my $delta=$timeshifted-$env{'form.timebase'};
3468: &dateshift($delta);
3469: $r->print(&Apache::loncommon::end_page());
3470: }
3471:
1.333 albertel 3472: sub parse_key {
3473: my ($key) = @_;
3474: my %data;
3475: my ($middle,$part,$name)=
1.473 amueller 3476: ($key=~/^$env{'request.course.id'}\.(?:(.+)\.)*([\w\s]+)\.(\w+)$/);
1.333 albertel 3477: $data{'scope_type'} = 'all';
3478: if ($middle=~/^\[(.*)\]/) {
1.473 amueller 3479: $data{'scope'} = $1;
3480: if ($data{'scope'}=~/^useropt\:($match_username)\:($match_domain)/) {
3481: $data{'scope_type'} = 'user';
3482: $data{'scope'} = [$1,$2];
3483: } else {
3484: #FIXME check for group scope
3485: $data{'scope_type'} = 'section';
3486: }
3487: $middle=~s/^\[(.*)\]//;
1.333 albertel 3488: }
3489: $middle=~s/\.+$//;
3490: $middle=~s/^\.+//;
3491: $data{'realm_type'}='all';
3492: if ($middle=~/^(.+)\_\_\_\(all\)$/) {
1.473 amueller 3493: $data{'realm'} = $1;
3494: $data{'realm_type'} = 'folder';
3495: $data{'realm_title'} = &Apache::lonnet::gettitle($data{'realm'});
3496: ($data{'realm_exists'}) = &Apache::lonnet::is_on_map($data{'realm'});
1.333 albertel 3497: } elsif ($middle) {
1.473 amueller 3498: $data{'realm'} = $middle;
3499: $data{'realm_type'} = 'symb';
3500: $data{'realm_title'} = &Apache::lonnet::gettitle($data{'realm'});
3501: my ($map,$resid,$url) = &Apache::lonnet::decode_symb($data{'realm'});
3502: $data{'realm_exists'} = &Apache::lonnet::symbverify($data{'realm'},$url);
1.333 albertel 3503: }
1.446 bisitz 3504:
1.333 albertel 3505: $data{'parameter_part'} = $part;
3506: $data{'parameter_name'} = $name;
3507:
3508: return %data;
3509: }
3510:
1.239 raeburn 3511:
1.416 jms 3512: sub header {
3513: return &Apache::loncommon::start_page('Parameter Manager');
3514: }
1.193 albertel 3515:
3516:
3517:
3518: sub print_main_menu {
3519: my ($r,$parm_permission)=@_;
3520: #
1.414 droeschl 3521: $r->print(&header());
3522: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Parameter Manager'));
1.193 albertel 3523: $r->print(<<ENDMAINFORMHEAD);
3524: <form method="post" enctype="multipart/form-data"
3525: action="/adm/parmset" name="studentform">
3526: ENDMAINFORMHEAD
3527: #
1.195 albertel 3528: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3529: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.268 albertel 3530: my $vgr = &Apache::lonnet::allowed('vgr',$env{'request.course.id'});
1.366 albertel 3531: my $mgr = &Apache::lonnet::allowed('mgr',$env{'request.course.id'});
1.268 albertel 3532:
1.477 raeburn 3533: my $crstype = &Apache::loncommon::course_type();
3534: my $lc_crstype = lc($crstype);
1.417 droeschl 3535:
1.193 albertel 3536: my @menu =
1.477 raeburn 3537: ( { categorytitle=>"Settings for this $crstype",
1.473 amueller 3538: items => [
3539: { linktext => 'Portfolio Metadata',
3540: url => '/adm/parmset?action=setrestrictmeta',
3541: permission => $parm_permission,
1.477 raeburn 3542: linktitle => "Restrict metadata for this $lc_crstype." ,
1.473 amueller 3543: icon =>'contact-new.png' ,
3544: },
3545: { linktext => 'Reset Student Access Times',
3546: url => '/adm/helper/resettimes.helper',
3547: permission => $mgr,
1.477 raeburn 3548: linktitle => "Reset access times for folders/maps, resources or the $lc_crstype." ,
1.473 amueller 3549: icon => 'start-here.png' ,
3550: },
3551:
3552: { linktext => 'Set Parameter Setting Default Actions',
3553: url => '/adm/parmset?action=setdefaults',
3554: permission => $parm_permission,
3555: linktitle =>'Set default actions for parameters.' ,
3556: icon => 'folder-new.png' ,
3557: }]},
3558: { categorytitle => 'New and Existing Parameter Settings for Resources',
3559: items => [
3560: { linktext => 'Edit Resource Parameters - Helper Mode',
3561: url => '/adm/helper/parameter.helper',
3562: permission => $parm_permission,
3563: linktitle =>'Set/Modify resource parameters in helper mode.' ,
3564: icon => 'dialog-information.png' ,
3565: #help => 'Parameter_Helper',
3566: },
3567: { linktext => 'Edit Resource Parameters - Overview Mode',
3568: url => '/adm/parmset?action=newoverview',
3569: permission => $parm_permission,
3570: linktitle =>'Set/Modify resource parameters in overview mode.' ,
3571: icon => 'edit-find.png' ,
3572: #help => 'Parameter_Overview',
3573: },
3574: { linktext => 'Edit Resource Parameters - Table Mode',
3575: url => '/adm/parmset?action=settable',
3576: permission => $parm_permission,
3577: linktitle =>'Set/Modify resource parameters in table mode.' ,
3578: icon => 'edit-copy.png' ,
3579: #help => 'Table_Mode',
3580: }]},
1.417 droeschl 3581: { categorytitle => 'Existing Parameter Settings for Resources',
1.473 amueller 3582: items => [
3583: { linktext => 'Modify Resource Parameters - Overview Mode',
3584: url => '/adm/parmset?action=setoverview',
3585: permission => $parm_permission,
3586: linktitle =>'Set/Modify existing resource parameters in overview mode.' ,
3587: icon => 'preferences-desktop-wallpaper.png' ,
3588: #help => 'Parameter_Overview',
3589: },
3590: { linktext => 'Change Log',
3591: url => '/adm/parmset?action=parameterchangelog',
3592: permission => $parm_permission,
1.477 raeburn 3593: linktitle =>"View parameter and $lc_crstype blog posting/user notification change log." ,
1.487 wenzelju 3594: icon => 'document-properties.png',
1.473 amueller 3595: }]}
1.193 albertel 3596: );
1.414 droeschl 3597: $r->print(&Apache::lonhtmlcommon::generate_menu(@menu));
1.193 albertel 3598: return;
3599: }
1.414 droeschl 3600:
1.416 jms 3601:
3602:
1.252 banghart 3603: sub output_row {
1.347 banghart 3604: my ($r, $field_name, $field_text, $added_flag) = @_;
1.252 banghart 3605: my $output;
1.263 banghart 3606: my $options=$env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.options'};
3607: my $values=$env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.values'};
1.337 banghart 3608: if (!defined($options)) {
1.254 banghart 3609: $options = 'active,stuadd';
1.261 banghart 3610: $values = '';
1.252 banghart 3611: }
1.337 banghart 3612: if (!($options =~ /deleted/)) {
3613: my @options= ( ['active', 'Show to student'],
1.418 schafran 3614: ['stuadd', 'Provide text area for students to type metadata'],
1.351 banghart 3615: ['choices','Provide choices for students to select from']);
1.473 amueller 3616: # ['onlyone','Student may select only one choice']);
1.337 banghart 3617: if ($added_flag) {
3618: push @options,['deleted', 'Delete Metadata Field'];
3619: }
1.351 banghart 3620: $output = &Apache::loncommon::start_data_table_row();
1.451 bisitz 3621: $output .= '<td><strong>'.$field_text.':</strong></td>';
1.351 banghart 3622: $output .= &Apache::loncommon::end_data_table_row();
1.337 banghart 3623: foreach my $opt (@options) {
1.473 amueller 3624: my $checked = ($options =~ m/$opt->[0]/) ? ' checked="checked" ' : '' ;
3625: $output .= &Apache::loncommon::continue_data_table_row();
3626: $output .= '<td>'.(' ' x 5).'<label>
3627: <input type="checkbox" name="'.
3628: $field_name.'_'.$opt->[0].'" value="yes"'.$checked.' />'.
3629: &mt($opt->[1]).'</label></td>';
3630: $output .= &Apache::loncommon::end_data_table_row();
3631: }
1.351 banghart 3632: $output .= &Apache::loncommon::continue_data_table_row();
1.451 bisitz 3633: $output .= '<td>'.(' ' x 10).'<input name="'.$field_name.'_values" type="text" value="'.$values.'" size="80" /></td>';
1.351 banghart 3634: $output .= &Apache::loncommon::end_data_table_row();
3635: my $multiple_checked;
3636: my $single_checked;
3637: if ($options =~ m/onlyone/) {
1.422 bisitz 3638: $multiple_checked = '';
1.423 bisitz 3639: $single_checked = ' checked="checked"';
1.351 banghart 3640: } else {
1.423 bisitz 3641: $multiple_checked = ' checked="checked"';
1.422 bisitz 3642: $single_checked = '';
1.351 banghart 3643: }
1.473 amueller 3644: $output .= &Apache::loncommon::continue_data_table_row();
3645: $output .= '<td>'.(' ' x 10).'
3646: <input type="radio" name="'.$field_name.'_onlyone" value="multiple"'.$multiple_checked .' />
3647: '.&mt('Student may select multiple choices from list').'</td>';
3648: $output .= &Apache::loncommon::end_data_table_row();
3649: $output .= &Apache::loncommon::continue_data_table_row();
3650: $output .= '<td>'.(' ' x 10).'
3651: <input type="radio" name="'.$field_name.'_onlyone" value="single"'.$single_checked.' />
3652: '.&mt('Student may select only one choice from list').'</td>';
3653: $output .= &Apache::loncommon::end_data_table_row();
1.252 banghart 3654: }
3655: return ($output);
3656: }
1.416 jms 3657:
3658:
3659:
1.340 banghart 3660: sub order_meta_fields {
3661: my ($r)=@_;
3662: my $idx = 1;
3663: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3664: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
1.341 banghart 3665: $r->print(&Apache::loncommon::start_page('Order Metadata Fields'));
1.414 droeschl 3666: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=addmetadata',
1.473 amueller 3667: text=>"Add Metadata Field"});
1.345 banghart 3668: &Apache::lonhtmlcommon::add_breadcrumb
3669: ({href=>"/adm/parmset?action=setrestrictmeta",
3670: text=>"Restrict Metadata"},
3671: {text=>"Order Metadata"});
3672: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Order Metadata'));
1.340 banghart 3673: if ($env{'form.storeorder'}) {
3674: my $newpos = $env{'form.newpos'} - 1;
3675: my $currentpos = $env{'form.currentpos'} - 1;
3676: my @neworder = ();
3677: my @oldorder = split /,/,$env{'course.'.$env{'request.course.id'}.'.metadata.addedorder'};
3678: my $i;
1.341 banghart 3679: if ($newpos > $currentpos) {
1.340 banghart 3680: # moving stuff up
3681: for ($i=0;$i<$currentpos;$i++) {
1.473 amueller 3682: $neworder[$i]=$oldorder[$i];
1.340 banghart 3683: }
3684: for ($i=$currentpos;$i<$newpos;$i++) {
1.473 amueller 3685: $neworder[$i]=$oldorder[$i+1];
1.340 banghart 3686: }
3687: $neworder[$newpos]=$oldorder[$currentpos];
3688: for ($i=$newpos+1;$i<=$#oldorder;$i++) {
1.473 amueller 3689: $neworder[$i]=$oldorder[$i];
1.340 banghart 3690: }
3691: } else {
3692: # moving stuff down
1.473 amueller 3693: for ($i=0;$i<$newpos;$i++) {
3694: $neworder[$i]=$oldorder[$i];
3695: }
3696: $neworder[$newpos]=$oldorder[$currentpos];
3697: for ($i=$newpos+1;$i<$currentpos+1;$i++) {
3698: $neworder[$i]=$oldorder[$i-1];
3699: }
3700: for ($i=$currentpos+1;$i<=$#oldorder;$i++) {
3701: $neworder[$i]=$oldorder[$i];
3702: }
1.340 banghart 3703: }
1.473 amueller 3704: my $ordered_fields = join ",", @neworder;
1.343 banghart 3705: my $put_result = &Apache::lonnet::put('environment',
1.446 bisitz 3706: {'metadata.addedorder'=>$ordered_fields},$dom,$crs);
1.473 amueller 3707: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.metadata.addedorder' => $ordered_fields});
1.340 banghart 3708: }
1.357 raeburn 3709: my $fields = &get_added_meta_fieldnames($env{'request.course.id'});
1.341 banghart 3710: my $ordered_fields;
1.340 banghart 3711: my @fields_in_order = split /,/,$env{'course.'.$env{'request.course.id'}.'.metadata.addedorder'};
3712: if (!@fields_in_order) {
3713: # no order found, pick sorted order then create metadata.addedorder key.
3714: foreach my $key (sort keys %$fields) {
3715: push @fields_in_order, $key;
1.341 banghart 3716: $ordered_fields = join ",", @fields_in_order;
1.340 banghart 3717: }
1.341 banghart 3718: my $put_result = &Apache::lonnet::put('environment',
1.446 bisitz 3719: {'metadata.addedorder'=>$ordered_fields},$dom,$crs);
3720: }
1.340 banghart 3721: $r->print('<table>');
3722: my $num_fields = scalar(@fields_in_order);
3723: foreach my $key (@fields_in_order) {
3724: $r->print('<tr><td>');
3725: $r->print('<form method="post" action="">');
3726: $r->print('<select name="newpos" onChange="this.form.submit()">');
3727: for (my $i = 1;$i le $num_fields;$i ++) {
3728: if ($i eq $idx) {
3729: $r->print('<option value="'.$i.'" SELECTED>('.$i.')</option>');
3730: } else {
3731: $r->print('<option value="'.$i.'">'.$i.'</option>');
3732: }
3733: }
3734: $r->print('</select></td><td>');
3735: $r->print('<input type="hidden" name="currentpos" value="'.$idx.'" />');
3736: $r->print('<input type="hidden" name="storeorder" value="true" />');
3737: $r->print('</form>');
3738: $r->print($$fields{$key}.'</td></tr>');
3739: $idx ++;
3740: }
3741: $r->print('</table>');
3742: return 'ok';
3743: }
1.416 jms 3744:
3745:
1.359 banghart 3746: sub continue {
3747: my $output;
3748: $output .= '<form action="" method="post">';
3749: $output .= '<input type="hidden" name="action" value="setrestrictmeta" />';
3750: $output .= '<input type="submit" value="Continue" />';
3751: return ($output);
3752: }
1.416 jms 3753:
3754:
1.334 banghart 3755: sub addmetafield {
3756: my ($r)=@_;
1.414 droeschl 3757: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=addmetadata',
1.473 amueller 3758: text=>"Add Metadata Field"});
1.334 banghart 3759: $r->print(&Apache::loncommon::start_page('Add Metadata Field'));
3760: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Add Metadata Field'));
1.335 banghart 3761: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3762: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
1.339 banghart 3763: if (exists($env{'form.undelete'})) {
1.358 banghart 3764: my @meta_fields = &Apache::loncommon::get_env_multiple('form.undeletefield');
1.339 banghart 3765: foreach my $meta_field(@meta_fields) {
3766: my $options = $env{'course.'.$env{'request.course.id'}.'.metadata.'.$meta_field.'.options'};
3767: $options =~ s/deleted//;
3768: $options =~ s/,,/,/;
3769: my $put_result = &Apache::lonnet::put('environment',
3770: {'metadata.'.$meta_field.'.options'=>$options},$dom,$crs);
1.446 bisitz 3771:
1.339 banghart 3772: $r->print('Undeleted Metadata Field <strong>'.$env{'course.'.$env{'request.course.id'}.'.metadata.'.$meta_field.'.added'}."</strong> with result ".$put_result.'<br />');
3773: }
1.359 banghart 3774: $r->print(&continue());
1.339 banghart 3775: } elsif (exists($env{'form.fieldname'})) {
1.335 banghart 3776: my $meta_field = $env{'form.fieldname'};
3777: my $display_field = $env{'form.fieldname'};
3778: $meta_field =~ s/\W/_/g;
1.338 banghart 3779: $meta_field =~ tr/A-Z/a-z/;
1.335 banghart 3780: my $put_result = &Apache::lonnet::put('environment',
3781: {'metadata.'.$meta_field.'.values'=>"",
3782: 'metadata.'.$meta_field.'.added'=>"$display_field",
3783: 'metadata.'.$meta_field.'.options'=>""},$dom,$crs);
1.359 banghart 3784: $r->print('Added new Metadata Field <strong>'.$env{'form.fieldname'}."</strong> with result ".$put_result.'<br />');
3785: $r->print(&continue());
1.335 banghart 3786: } else {
1.357 raeburn 3787: my $fields = &get_deleted_meta_fieldnames($env{'request.course.id'});
1.339 banghart 3788: if ($fields) {
3789: $r->print('You may undelete previously deleted fields.<br />Check those you wish to undelete and click Undelete.<br />');
3790: $r->print('<form method="post" action="">');
3791: foreach my $key(keys(%$fields)) {
1.358 banghart 3792: $r->print('<input type="checkbox" name="undeletefield" value="'.$key.'" />'.$$fields{$key}.'<br /');
1.339 banghart 3793: }
3794: $r->print('<input type="submit" name="undelete" value="Undelete" />');
3795: $r->print('</form>');
3796: }
3797: $r->print('<hr /><strong>Or</strong> you may enter a new metadata field name.<form method="post" action="/adm/parmset?action=addmetadata"');
1.335 banghart 3798: $r->print('<input type="text" name="fieldname" /><br />');
3799: $r->print('<input type="submit" value="Add Metadata Field" />');
1.334 banghart 3800: }
1.361 albertel 3801: $r->print('</form>');
1.334 banghart 3802: }
1.416 jms 3803:
3804:
3805:
1.259 banghart 3806: sub setrestrictmeta {
1.240 banghart 3807: my ($r)=@_;
1.242 banghart 3808: my $next_meta;
1.244 banghart 3809: my $output;
1.245 banghart 3810: my $item_num;
1.246 banghart 3811: my $put_result;
1.414 droeschl 3812: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setrestrictmeta',
1.473 amueller 3813: text=>"Restrict Metadata"});
1.280 albertel 3814: $r->print(&Apache::loncommon::start_page('Restrict Metadata'));
1.298 albertel 3815: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Restrict Metadata'));
1.240 banghart 3816: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3817: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
1.259 banghart 3818: my $key_base = $env{'course.'.$env{'request.course.id'}.'.'};
1.252 banghart 3819: my $save_field = '';
1.259 banghart 3820: if ($env{'form.restrictmeta'}) {
1.254 banghart 3821: foreach my $field (sort(keys(%env))) {
1.252 banghart 3822: if ($field=~m/^form.(.+)_(.+)$/) {
1.254 banghart 3823: my $options;
1.252 banghart 3824: my $meta_field = $1;
3825: my $meta_key = $2;
1.253 banghart 3826: if ($save_field ne $meta_field) {
1.252 banghart 3827: $save_field = $meta_field;
1.473 amueller 3828: if ($env{'form.'.$meta_field.'_stuadd'}) {
3829: $options.='stuadd,';
3830: }
3831: if ($env{'form.'.$meta_field.'_choices'}) {
3832: $options.='choices,';
3833: }
3834: if ($env{'form.'.$meta_field.'_onlyone'} eq 'single') {
3835: $options.='onlyone,';
3836: }
3837: if ($env{'form.'.$meta_field.'_active'}) {
3838: $options.='active,';
3839: }
3840: if ($env{'form.'.$meta_field.'_deleted'}) {
3841: $options.='deleted,';
3842: }
1.259 banghart 3843: my $name = $save_field;
1.253 banghart 3844: $put_result = &Apache::lonnet::put('environment',
1.262 banghart 3845: {'metadata.'.$meta_field.'.options'=>$options,
3846: 'metadata.'.$meta_field.'.values'=>$env{'form.'.$meta_field.'_values'},
1.253 banghart 3847: },$dom,$crs);
1.252 banghart 3848: }
3849: }
3850: }
3851: }
1.296 albertel 3852: &Apache::lonnet::coursedescription($env{'request.course.id'},
1.473 amueller 3853: {'freshen_cache' => 1});
1.335 banghart 3854: # Get the default metadata fields
1.258 albertel 3855: my %metadata_fields = &Apache::lonmeta::fieldnames('portfolio');
1.335 banghart 3856: # Now get possible added metadata fields
1.357 raeburn 3857: my $added_metadata_fields = &get_added_meta_fieldnames($env{'request.course.id'});
1.346 banghart 3858: my $row_alt = 1;
1.347 banghart 3859: $output .= &Apache::loncommon::start_data_table();
1.258 albertel 3860: foreach my $field (sort(keys(%metadata_fields))) {
1.265 banghart 3861: if ($field ne 'courserestricted') {
1.346 banghart 3862: $row_alt = $row_alt ? 0 : 1;
1.473 amueller 3863: $output.= &output_row($r, $field, $metadata_fields{$field});
3864: }
1.255 banghart 3865: }
1.351 banghart 3866: my $buttons = (<<ENDButtons);
3867: <input type="submit" name="restrictmeta" value="Save" />
3868: </form><br />
3869: <form method="post" action="/adm/parmset?action=addmetadata" name="form1">
3870: <input type="submit" name="restrictmeta" value="Add a Metadata Field" />
3871: </form>
3872: <br />
3873: <form method="post" action="/adm/parmset?action=ordermetadata" name="form2">
3874: <input type="submit" name="restrictmeta" value="Order Metadata Fields" />
3875: ENDButtons
1.337 banghart 3876: my $added_flag = 1;
1.335 banghart 3877: foreach my $field (sort(keys(%$added_metadata_fields))) {
1.346 banghart 3878: $row_alt = $row_alt ? 0 : 1;
3879: $output.= &output_row($r, $field, $$added_metadata_fields{$field},$added_flag, $row_alt);
1.335 banghart 3880: }
1.347 banghart 3881: $output .= &Apache::loncommon::end_data_table();
1.446 bisitz 3882: $r->print(<<ENDenv);
1.259 banghart 3883: <form method="post" action="/adm/parmset?action=setrestrictmeta" name="form">
1.244 banghart 3884: $output
1.351 banghart 3885: $buttons
1.340 banghart 3886: </form>
1.244 banghart 3887: ENDenv
1.280 albertel 3888: $r->print(&Apache::loncommon::end_page());
1.240 banghart 3889: return 'ok';
3890: }
1.416 jms 3891:
3892:
3893:
1.335 banghart 3894: sub get_added_meta_fieldnames {
1.357 raeburn 3895: my ($cid) = @_;
1.335 banghart 3896: my %fields;
3897: foreach my $key(%env) {
1.357 raeburn 3898: if ($key =~ m/\Q$cid\E\.metadata\.(.+)\.added$/) {
1.335 banghart 3899: my $field_name = $1;
3900: my ($display_field_name) = $env{$key};
3901: $fields{$field_name} = $display_field_name;
3902: }
3903: }
3904: return \%fields;
3905: }
1.416 jms 3906:
3907:
3908:
1.339 banghart 3909: sub get_deleted_meta_fieldnames {
1.357 raeburn 3910: my ($cid) = @_;
1.339 banghart 3911: my %fields;
3912: foreach my $key(%env) {
1.357 raeburn 3913: if ($key =~ m/\Q$cid\E\.metadata\.(.+)\.added$/) {
1.339 banghart 3914: my $field_name = $1;
3915: if ($env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.options'} =~ m/deleted/) {
3916: my ($display_field_name) = $env{$key};
3917: $fields{$field_name} = $display_field_name;
3918: }
3919: }
3920: }
3921: return \%fields;
3922: }
1.220 www 3923: sub defaultsetter {
1.280 albertel 3924: my ($r) = @_;
3925:
1.414 droeschl 3926: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setdefaults',
1.473 amueller 3927: text=>"Set Defaults"});
1.446 bisitz 3928: my $start_page =
1.473 amueller 3929: &Apache::loncommon::start_page('Parameter Setting Default Actions');
1.298 albertel 3930: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Defaults');
1.220 www 3931: $r->print(<<ENDDEFHEAD);
1.280 albertel 3932: $start_page
1.220 www 3933: $breadcrumbs
3934: <form method="post" action="/adm/parmset?action=setdefaults" name="defaultform">
3935: ENDDEFHEAD
1.280 albertel 3936:
3937: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3938: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
1.221 www 3939: my @ids=();
3940: my %typep=();
3941: my %keyp=();
3942: my %allparms=();
3943: my %allparts=();
3944: my %allmaps=();
3945: my %mapp=();
3946: my %symbp=();
3947: my %maptitles=();
3948: my %uris=();
3949: my %keyorder=&standardkeyorder();
3950: my %defkeytype=();
3951:
1.446 bisitz 3952: &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allmaps,
1.473 amueller 3953: \%mapp, \%symbp,\%maptitles,\%uris,
3954: \%keyorder,\%defkeytype);
1.224 www 3955: if ($env{'form.storerules'}) {
1.473 amueller 3956: my %newrules=();
3957: my @delrules=();
3958: my %triggers=();
3959: foreach my $key (keys(%env)) {
1.225 albertel 3960: if ($key=~/^form\.(\w+)\_action$/) {
1.473 amueller 3961: my $tempkey=$1;
3962: my $action=$env{$key};
1.226 www 3963: if ($action) {
1.473 amueller 3964: $newrules{$tempkey.'_action'}=$action;
3965: if ($action ne 'default') {
3966: my ($whichaction,$whichparm)=($action=~/^(.*\_)([^\_]+)$/);
3967: $triggers{$whichparm}.=$tempkey.':';
3968: }
3969: $newrules{$tempkey.'_type'}=$defkeytype{$tempkey};
3970: if (&isdateparm($defkeytype{$tempkey})) {
3971: $newrules{$tempkey.'_days'}=$env{'form.'.$tempkey.'_days'};
3972: $newrules{$tempkey.'_hours'}=$env{'form.'.$tempkey.'_hours'};
3973: $newrules{$tempkey.'_min'}=$env{'form.'.$tempkey.'_min'};
3974: $newrules{$tempkey.'_sec'}=$env{'form.'.$tempkey.'_sec'};
3975: } else {
3976: $newrules{$tempkey.'_value'}=$env{'form.'.$tempkey.'_value'};
3977: $newrules{$tempkey.'_triggervalue'}=$env{'form.'.$tempkey.'_triggervalue'};
3978: }
3979: } else {
3980: push(@delrules,$tempkey.'_action');
3981: push(@delrules,$tempkey.'_type');
3982: push(@delrules,$tempkey.'_hours');
3983: push(@delrules,$tempkey.'_min');
3984: push(@delrules,$tempkey.'_sec');
3985: push(@delrules,$tempkey.'_value');
3986: }
3987: }
3988: }
3989: foreach my $key (keys %allparms) {
3990: $newrules{$key.'_triggers'}=$triggers{$key};
3991: }
3992: &Apache::lonnet::put('parmdefactions',\%newrules,$dom,$crs);
3993: &Apache::lonnet::del('parmdefactions',\@delrules,$dom,$crs);
3994: &resetrulescache();
1.224 www 3995: }
1.227 www 3996: my %lt=&Apache::lonlocal::texthash('days' => 'Days',
1.473 amueller 3997: 'hours' => 'Hours',
3998: 'min' => 'Minutes',
3999: 'sec' => 'Seconds',
4000: 'yes' => 'Yes',
4001: 'no' => 'No');
1.222 www 4002: my @standardoptions=('','default');
4003: my @standarddisplay=('',&mt('Default value when manually setting'));
4004: my @dateoptions=('','default');
4005: my @datedisplay=('',&mt('Default value when manually setting'));
4006: foreach my $tempkey (&keysindisplayorder(\%allparms,\%keyorder)) {
1.473 amueller 4007: unless ($tempkey) { next; }
4008: push @standardoptions,'when_setting_'.$tempkey;
4009: push @standarddisplay,&mt('Automatically set when setting ').$tempkey;
4010: if (&isdateparm($defkeytype{$tempkey})) {
4011: push @dateoptions,'later_than_'.$tempkey;
4012: push @datedisplay,&mt('Automatically set later than ').$tempkey;
4013: push @dateoptions,'earlier_than_'.$tempkey;
4014: push @datedisplay,&mt('Automatically set earlier than ').$tempkey;
4015: }
1.222 www 4016: }
1.231 www 4017: $r->print(&mt('Manual setting rules apply to all interfaces.').'<br />'.
1.473 amueller 4018: &mt('Automatic setting rules apply to table mode interfaces only.'));
1.318 albertel 4019: $r->print("\n".&Apache::loncommon::start_data_table().
1.473 amueller 4020: &Apache::loncommon::start_data_table_header_row().
4021: "<th>".&mt('Rule for parameter').'</th><th>'.
4022: &mt('Action').'</th><th>'.&mt('Value').'</th>'.
4023: &Apache::loncommon::end_data_table_header_row());
1.221 www 4024: foreach my $tempkey (&keysindisplayorder(\%allparms,\%keyorder)) {
1.473 amueller 4025: unless ($tempkey) { next; }
4026: $r->print("\n".&Apache::loncommon::start_data_table_row().
4027: "<td>".$allparms{$tempkey}."\n<br />(".$tempkey.')</td><td>');
4028: my $action=&rulescache($tempkey.'_action');
4029: $r->print('<select name="'.$tempkey.'_action">');
4030: if (&isdateparm($defkeytype{$tempkey})) {
4031: for (my $i=0;$i<=$#dateoptions;$i++) {
4032: if ($dateoptions[$i]=~/\_$tempkey$/) { next; }
4033: $r->print("\n<option value='$dateoptions[$i]'".
4034: ($dateoptions[$i] eq $action?' selected="selected"':'').
4035: ">$datedisplay[$i]</option>");
4036: }
4037: } else {
4038: for (my $i=0;$i<=$#standardoptions;$i++) {
4039: if ($standardoptions[$i]=~/\_$tempkey$/) { next; }
4040: $r->print("\n<option value='$standardoptions[$i]'".
4041: ($standardoptions[$i] eq $action?' selected="selected"':'').
4042: ">$standarddisplay[$i]</option>");
4043: }
4044: }
4045: $r->print('</select>');
4046: unless (&isdateparm($defkeytype{$tempkey})) {
4047: $r->print("\n<br />".&mt('Triggering value(s) of other parameter (optional, comma-separated):').
4048: '<input type="text" size="20" name="'.$tempkey.'_triggervalue" value="'.&rulescache($tempkey.'_triggervalue').'" />');
4049: }
4050: $r->print("\n</td><td>\n");
1.222 www 4051:
1.221 www 4052: if (&isdateparm($defkeytype{$tempkey})) {
1.473 amueller 4053: my $days=&rulescache($tempkey.'_days');
4054: my $hours=&rulescache($tempkey.'_hours');
4055: my $min=&rulescache($tempkey.'_min');
4056: my $sec=&rulescache($tempkey.'_sec');
4057: $r->print(<<ENDINPUTDATE);
1.227 www 4058: <input name="$tempkey\_days" type="text" size="4" value="$days" />$lt{'days'}<br />
1.222 www 4059: <input name="$tempkey\_hours" type="text" size="4" value="$hours" />$lt{'hours'}<br />
4060: <input name="$tempkey\_min" type="text" size="4" value="$min" />$lt{'min'}<br />
4061: <input name="$tempkey\_sec" type="text" size="4" value="$sec" />$lt{'sec'}
1.221 www 4062: ENDINPUTDATE
1.473 amueller 4063: } elsif ($defkeytype{$tempkey} eq 'string_yesno') {
1.222 www 4064: my $yeschecked='';
4065: my $nochecked='';
1.444 bisitz 4066: if (&rulescache($tempkey.'_value') eq 'yes') { $yeschecked=' checked="checked"'; }
4067: if (&rulescache($tempkey.'_value') eq 'no') { $nochecked=' checked="checked"'; }
1.222 www 4068:
1.473 amueller 4069: $r->print(<<ENDYESNO);
1.444 bisitz 4070: <label><input type="radio" name="$tempkey\_value" value="yes"$yeschecked /> $lt{'yes'}</label><br />
4071: <label><input type="radio" name="$tempkey\_value" value="no"$nochecked /> $lt{'no'}</label>
1.221 www 4072: ENDYESNO
4073: } else {
1.473 amueller 4074: $r->print('<input type="text" size="20" name="'.$tempkey.'_value" value="'.&rulescache($tempkey.'_value').'" />');
4075: }
1.318 albertel 4076: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1.221 www 4077: }
1.318 albertel 4078: $r->print(&Apache::loncommon::end_data_table().
1.473 amueller 4079: "\n".'<input type="submit" name="storerules" value="'.
4080: &mt('Save').'" /></form>'."\n".
4081: &Apache::loncommon::end_page());
1.220 www 4082: return;
4083: }
1.193 albertel 4084:
1.290 www 4085: sub components {
1.330 albertel 4086: my ($key,$uname,$udom,$exeuser,$exedomain,$typeflag)=@_;
4087:
4088: if ($typeflag) {
1.473 amueller 4089: $key=~s/\.type$//;
1.290 www 4090: }
1.330 albertel 4091:
4092: my ($middle,$part,$name)=
1.473 amueller 4093: ($key=~/^$env{'request.course.id'}\.(?:(.+)\.)*([\w\s]+)\.(\w+)$/);
1.291 www 4094: my $issection;
1.330 albertel 4095:
1.290 www 4096: my $section=&mt('All Students');
4097: if ($middle=~/^\[(.*)\]/) {
1.473 amueller 4098: $issection=$1;
4099: $section=&mt('Group/Section').': '.$issection;
4100: $middle=~s/^\[(.*)\]//;
1.290 www 4101: }
4102: $middle=~s/\.+$//;
4103: $middle=~s/^\.+//;
1.291 www 4104: if ($uname) {
1.473 amueller 4105: $section=&mt('User').": ".&Apache::loncommon::plainname($uname,$udom);
4106: $issection='';
1.291 www 4107: }
1.316 albertel 4108: my $realm='<span class="LC_parm_scope_all">'.&mt('All Resources').'</span>';
1.446 bisitz 4109: my $realmdescription=&mt('all resources');
1.290 www 4110: if ($middle=~/^(.+)\_\_\_\(all\)$/) {
1.473 amueller 4111: $realm='<span class="LC_parm_scope_folder">'.&mt('Folder/Map').': '.&Apache::lonnet::gettitle($1).' <span class="LC_parm_folder"><br />('.$1.')</span></span>';
4112: $realmdescription=&mt('folder').' '.&Apache::lonnet::gettitle($1);
1.304 www 4113: } elsif ($middle) {
1.473 amueller 4114: my ($map,$id,$url)=&Apache::lonnet::decode_symb($middle);
4115: $realm='<span class="LC_parm_scope_resource">'.&mt('Resource').': '.&Apache::lonnet::gettitle($middle).' <br /><span class="LC_parm_symb">('.$url.' in '.$map.' id: '.$id.')</span></span>';
4116: $realmdescription=&mt('resource').' '.&Apache::lonnet::gettitle($middle);
1.290 www 4117: }
1.291 www 4118: my $what=$part.'.'.$name;
1.330 albertel 4119: return ($realm,$section,$name,$part,
1.473 amueller 4120: $what,$middle,$uname,$udom,$issection,$realmdescription);
1.290 www 4121: }
1.293 www 4122:
1.328 albertel 4123: my %standard_parms;
1.469 raeburn 4124: my %standard_parms_types;
1.416 jms 4125:
1.328 albertel 4126: sub load_parameter_names {
4127: open(my $config,"<$Apache::lonnet::perlvar{'lonTabDir'}/packages.tab");
4128: while (my $configline=<$config>) {
1.473 amueller 4129: if ($configline !~ /\S/ || $configline=~/^\#/) { next; }
4130: chomp($configline);
4131: my ($short,$plain)=split(/:/,$configline);
4132: my (undef,$name,$type)=split(/\&/,$short,3);
4133: if ($type eq 'display') {
4134: $standard_parms{$name} = $plain;
1.469 raeburn 4135: } elsif ($type eq 'type') {
4136: $standard_parms_types{$name} = $plain;
4137: }
1.328 albertel 4138: }
4139: close($config);
4140: $standard_parms{'int_pos'} = 'Positive Integer';
4141: $standard_parms{'int_zero_pos'} = 'Positive Integer or Zero';
4142: }
4143:
1.292 www 4144: sub standard_parameter_names {
4145: my ($name)=@_;
1.328 albertel 4146: if (!%standard_parms) {
1.473 amueller 4147: &load_parameter_names();
1.328 albertel 4148: }
1.292 www 4149: if ($standard_parms{$name}) {
1.473 amueller 4150: return $standard_parms{$name};
1.446 bisitz 4151: } else {
1.473 amueller 4152: return $name;
1.292 www 4153: }
4154: }
1.290 www 4155:
1.469 raeburn 4156: sub standard_parameter_types {
4157: my ($name)=@_;
4158: if (!%standard_parms_types) {
4159: &load_parameter_names();
4160: }
4161: if ($standard_parms_types{$name}) {
4162: return $standard_parms_types{$name};
4163: }
4164: return;
4165: }
1.309 www 4166:
1.285 albertel 4167: sub parm_change_log {
1.284 www 4168: my ($r)=@_;
1.414 droeschl 4169: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=settable',
1.473 amueller 4170: text=>"Parameter Change Log"});
1.327 albertel 4171: $r->print(&Apache::loncommon::start_page('Parameter Change Log'));
4172: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Parameter Change Log'));
4173:
1.286 www 4174: my %parmlog=&Apache::lonnet::dump('nohist_parameterlog',
1.473 amueller 4175: $env{'course.'.$env{'request.course.id'}.'.domain'},
4176: $env{'course.'.$env{'request.course.id'}.'.num'});
1.311 albertel 4177:
1.301 www 4178: if ((keys(%parmlog))[0]=~/^error\:/) { undef(%parmlog); }
1.311 albertel 4179:
1.327 albertel 4180: $r->print('<form action="/adm/parmset?action=parameterchangelog"
4181: method="post" name="parameterlog">');
1.446 bisitz 4182:
1.311 albertel 4183: my %saveable_parameters = ('show' => 'scalar',);
4184: &Apache::loncommon::store_course_settings('parameter_log',
4185: \%saveable_parameters);
4186: &Apache::loncommon::restore_course_settings('parameter_log',
4187: \%saveable_parameters);
1.348 www 4188: $r->print(&Apache::loncommon::display_filter().
1.326 www 4189: '<label>'.&Apache::lonhtmlcommon::checkbox('includetypes',$env{'form.includetypes'},'1').
1.473 amueller 4190: ' '.&mt('Include parameter types').'</label>'.
4191: '<input type="submit" value="'.&mt('Display').'" /></form>');
1.301 www 4192:
1.291 www 4193: my $courseopt=&Apache::lonnet::get_courseresdata($env{'course.'.$env{'request.course.id'}.'.num'},
1.473 amueller 4194: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.301 www 4195: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1.473 amueller 4196: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Extent').'</th><th>'.&mt('Users').'</th><th>'.
4197: &mt('Parameter').'</th><th>'.&mt('Part').'</th><th>'.&mt('New Value').'</th><th>'.&mt('Announce').'</th>'.
4198: &Apache::loncommon::end_data_table_header_row());
1.309 www 4199: my $shown=0;
1.349 www 4200: my $folder='';
4201: if ($env{'form.displayfilter'} eq 'currentfolder') {
1.473 amueller 4202: my $last='';
4203: if (tie(my %hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
4204: &GDBM_READER(),0640)) {
4205: $last=$hash{'last_known'};
4206: untie(%hash);
4207: }
4208: if ($last) { ($folder) = &Apache::lonnet::decode_symb($last); }
1.349 www 4209: }
1.446 bisitz 4210: foreach my $id (sort
1.473 amueller 4211: {
4212: if ($parmlog{$b}{'exe_time'} ne $parmlog{$a}{'exe_time'}) {
4213: return $parmlog{$b}{'exe_time'} <=>$parmlog{$a}{'exe_time'}
4214: }
4215: my $aid = (split('00000',$a))[-1];
4216: my $bid = (split('00000',$b))[-1];
4217: return $bid<=>$aid;
4218: } (keys(%parmlog))) {
1.294 www 4219: my @changes=keys(%{$parmlog{$id}{'logentry'}});
1.473 amueller 4220: my $count = 0;
4221: my $time =
4222: &Apache::lonlocal::locallocaltime($parmlog{$id}{'exe_time'});
4223: my $plainname =
4224: &Apache::loncommon::plainname($parmlog{$id}{'exe_uname'},
4225: $parmlog{$id}{'exe_udom'});
4226: my $about_me_link =
4227: &Apache::loncommon::aboutmewrapper($plainname,
4228: $parmlog{$id}{'exe_uname'},
4229: $parmlog{$id}{'exe_udom'});
4230: my $send_msg_link='';
4231: if ((($parmlog{$id}{'exe_uname'} ne $env{'user.name'})
4232: || ($parmlog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
4233: $send_msg_link ='<br />'.
4234: &Apache::loncommon::messagewrapper(&mt('Send message'),
4235: $parmlog{$id}{'exe_uname'},
4236: $parmlog{$id}{'exe_udom'});
4237: }
4238: my $row_start=&Apache::loncommon::start_data_table_row();
4239: my $makenewrow=0;
4240: my %istype=();
4241: my $output;
4242: foreach my $changed (reverse(sort(@changes))) {
1.330 albertel 4243: my $value=$parmlog{$id}{'logentry'}{$changed};
1.473 amueller 4244: my $typeflag = ($changed =~/\.type$/ &&
4245: !exists($parmlog{$id}{'logentry'}{$changed.'.type'}));
1.330 albertel 4246: my ($realm,$section,$parmname,$part,$what,$middle,$uname,$udom,$issection,$realmdescription)=
1.473 amueller 4247: &components($changed,$parmlog{$id}{'uname'},$parmlog{$id}{'udom'},undef,undef,$typeflag);
4248: if ($env{'form.displayfilter'} eq 'currentfolder') {
4249: if ($folder) {
4250: if ($middle!~/^\Q$folder\E/) { next; }
4251: }
4252: }
4253: if ($typeflag) {
4254: $istype{$parmname}=$value;
4255: if (!$env{'form.includetypes'}) { next; }
4256: }
4257: $count++;
4258: if ($makenewrow) {
4259: $output .= $row_start;
4260: } else {
4261: $makenewrow=1;
4262: }
1.470 raeburn 4263: my $parmitem = &standard_parameter_names($parmname);
1.473 amueller 4264: $output .='<td>'.$realm.'</td><td>'.$section.'</td><td>'.
4265: &mt($parmitem).'</td><td>'.
4266: ($part?&mt('Part: [_1]',$part):&mt('All Parts')).'</td><td>';
4267: my $stillactive=0;
4268: if ($parmlog{$id}{'delflag'}) {
4269: $output .= &mt('Deleted');
4270: } else {
4271: if ($typeflag) {
1.470 raeburn 4272: my $parmitem = &standard_parameter_names($value);
4273: $parmitem = &mt($parmitem);
1.473 amueller 4274: $output .= &mt('Type: [_1]',$parmitem);
4275: } else {
4276: my ($level,@all)=&parmval_by_symb($what,$middle,&Apache::lonnet::metadata($middle,$what),
4277: $uname,$udom,$issection,$issection,$courseopt);
1.469 raeburn 4278: my $showvalue = $value;
4279: if ($istype{$parmname} eq '') {
4280: my $type = &standard_parameter_types($parmname);
4281: if ($type ne '') {
4282: if (&isdateparm($type)) {
4283: $showvalue =
4284: &Apache::lonlocal::locallocaltime($value);
4285: }
4286: }
4287: } else {
1.473 amueller 4288: if (&isdateparm($istype{$parmname})) {
4289: $showvalue =
1.469 raeburn 4290: &Apache::lonlocal::locallocaltime($value);
1.473 amueller 4291: }
1.469 raeburn 4292: }
4293: $output .= $showvalue;
1.473 amueller 4294: if ($value ne $all[$level]) {
4295: $output .= '<br /><span class="LC_warning">'.&mt('Not active anymore').'</span>';
4296: } else {
4297: $stillactive=1;
4298: }
4299: }
4300: }
4301: $output .= '</td><td>';
1.470 raeburn 4302:
1.473 amueller 4303: if ($stillactive) {
1.470 raeburn 4304: my $parmitem = &standard_parameter_names($parmname);
4305: $parmitem = &mt($parmitem);
1.473 amueller 4306: my $title=&mt('Changed [_1]',$parmitem);
1.471 raeburn 4307: my $description=&mt('Changed [_1] for [_2] to [_3]',
4308: $parmitem,$realmdescription,
1.473 amueller 4309: (&isdateparm($istype{$parmname})?&Apache::lonlocal::locallocaltime($value):$value));
4310: if (($uname) && ($udom)) {
4311: $output .=
4312: &Apache::loncommon::messagewrapper('Notify User',
4313: $uname,$udom,$title,
4314: $description);
4315: } else {
4316: $output .=
4317: &Apache::lonrss::course_blog_link($id,$title,
4318: $description);
4319: }
4320: }
4321: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
4322: }
1.349 www 4323: if ($env{'form.displayfilter'} eq 'containing') {
1.473 amueller 4324: my $wholeentry=$about_me_link.':'.
4325: $parmlog{$id}{'exe_uname'}.':'.$parmlog{$id}{'exe_udom'}.':'.
4326: $output;
4327: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
4328: }
1.349 www 4329: if ($count) {
1.473 amueller 4330: $r->print($row_start.'<td rowspan="'.$count.'">'.$time.'</td>
1.332 albertel 4331: <td rowspan="'.$count.'">'.$about_me_link.
1.473 amueller 4332: '<br /><tt>'.$parmlog{$id}{'exe_uname'}.
4333: ':'.$parmlog{$id}{'exe_udom'}.'</tt>'.
4334: $send_msg_link.'</td>'.$output);
4335: $shown++;
4336: }
4337: if (!($env{'form.show'} eq &mt('all')
4338: || $shown<=$env{'form.show'})) { last; }
1.286 www 4339: }
1.301 www 4340: $r->print(&Apache::loncommon::end_data_table());
1.284 www 4341: $r->print(&Apache::loncommon::end_page());
4342: }
4343:
1.437 raeburn 4344: sub update_slots {
4345: my ($slot_name,$cdom,$cnum,$symb,$uname,$udom) = @_;
4346: my %slot=&Apache::lonnet::get_slot($slot_name);
4347: if (!keys(%slot)) {
4348: return 'error: slot does not exist';
4349: }
4350: my $max=$slot{'maxspace'};
4351: if (!defined($max)) { $max=99999; }
4352:
4353: my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
4354: "^$slot_name\0");
4355: my ($tmp)=%consumed;
4356: if ($tmp=~/^error: 2 / ) {
4357: return 'error: unable to determine current slot status';
4358: }
4359: my $last=0;
4360: foreach my $key (keys(%consumed)) {
4361: my $num=(split('\0',$key))[1];
4362: if ($num > $last) { $last=$num; }
4363: if ($consumed{$key}->{'name'} eq $uname.':'.$udom) {
4364: return 'ok';
4365: }
4366: }
4367:
4368: if (scalar(keys(%consumed)) >= $max) {
4369: return 'error: no space left in slot';
4370: }
4371: my $wanted=$last+1;
4372:
4373: my %reservation=('name' => $uname.':'.$udom,
4374: 'timestamp' => time,
4375: 'symb' => $symb);
4376:
4377: my $success=&Apache::lonnet::newput('slot_reservations',
4378: {"$slot_name\0$wanted" =>
4379: \%reservation},
4380: $cdom, $cnum);
1.438 raeburn 4381: if ($success eq 'ok') {
4382: my %storehash = (
4383: symb => $symb,
4384: slot => $slot_name,
4385: action => 'reserve',
4386: context => 'parameter',
4387: );
4388: &Apache::lonnet::instructor_log('slotreservationslog',\%storehash,
4389: '',$uname,$udom,$cnum,$cdom);
4390:
4391: &Apache::lonnet::instructor_log($cdom.'_'.$cnum.'_slotlog',\%storehash,
4392: '',$uname,$udom,$uname,$udom);
4393: }
1.437 raeburn 4394: return $success;
4395: }
4396:
4397: sub delete_slots {
4398: my ($slot_name,$cdom,$cnum,$uname,$udom,$symb) = @_;
4399: my $delresult;
4400: my %consumed = &Apache::lonnet::dump('slot_reservations',$cdom,
4401: $cnum, "^$slot_name\0");
4402: if (&Apache::lonnet::error(%consumed)) {
4403: return 'error: unable to determine current slot status';
4404: }
4405: my ($tmp)=%consumed;
4406: if ($tmp=~/^error: 2 /) {
4407: return 'error: unable to determine current slot status';
4408: }
4409: foreach my $key (keys(%consumed)) {
4410: if ($consumed{$key}->{'name'} eq $uname.':'.$udom) {
4411: my $num=(split('\0',$key))[1];
4412: my $entry = $slot_name.'\0'.$num;
4413: $delresult = &Apache::lonnet::del('slot_reservations',[$entry],
4414: $cdom,$cnum);
4415: if ($delresult eq 'ok') {
4416: my %storehash = (
4417: symb => $symb,
4418: slot => $slot_name,
4419: action => 'release',
4420: context => 'parameter',
4421: );
4422: &Apache::lonnet::instructor_log('slotreservationslog',\%storehash,
4423: 1,$uname,$udom,$cnum,$cdom);
1.438 raeburn 4424: &Apache::lonnet::instructor_log($cdom.'_'.$cnum.'_slotlog',\%storehash,
4425: 1,$uname,$udom,$uname,$udom);
1.437 raeburn 4426: }
4427: }
4428: }
4429: return $delresult;
4430: }
4431:
1.355 albertel 4432: sub check_for_course_info {
4433: my $navmap = Apache::lonnavmaps::navmap->new();
4434: return 1 if ($navmap);
4435: return 0;
4436: }
4437:
1.259 banghart 4438:
1.30 www 4439: sub handler {
1.43 albertel 4440: my $r=shift;
1.30 www 4441:
1.376 albertel 4442: &reset_caches();
4443:
1.414 droeschl 4444: &Apache::loncommon::content_type($r,'text/html');
4445: $r->send_http_header;
4446: return OK if $r->header_only;
4447:
1.193 albertel 4448: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.473 amueller 4449: ['action','state',
1.205 www 4450: 'pres_marker',
4451: 'pres_value',
1.206 www 4452: 'pres_type',
1.390 www 4453: 'udom','uname','symb','serial','timebase']);
1.131 www 4454:
1.83 bowersj2 4455:
1.193 albertel 4456: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.194 albertel 4457: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/parmset",
1.473 amueller 4458: text=>"Parameter Manager",
4459: faq=>10,
4460: bug=>'Instructor Interface',
1.442 droeschl 4461: help =>
4462: 'Parameter_Manager,Course_Environment,Parameter_Helper,Parameter_Overview,Table_Mode'});
1.203 www 4463:
1.30 www 4464: # ----------------------------------------------------- Needs to be in a course
1.194 albertel 4465: my $parm_permission =
1.473 amueller 4466: (&Apache::lonnet::allowed('opa',$env{'request.course.id'}) ||
4467: &Apache::lonnet::allowed('opa',$env{'request.course.id'}.'/'.
4468: $env{'request.course.sec'}));
1.355 albertel 4469: my $exists = &check_for_course_info();
4470:
4471: if ($env{'request.course.id'} && $parm_permission && $exists) {
1.193 albertel 4472: #
4473: # Main switch on form.action and form.state, as appropriate
4474: #
4475: # Check first if coming from someone else headed directly for
4476: # the table mode
4477: if ((($env{'form.command'} eq 'set') && ($env{'form.url'})
1.473 amueller 4478: && (!$env{'form.dis'})) || ($env{'form.symb'})) {
4479: &assessparms($r);
1.193 albertel 4480: } elsif (! exists($env{'form.action'})) {
4481: &print_main_menu($r,$parm_permission);
1.414 droeschl 4482: } elsif ($env{'form.action'} eq 'setoverview') {
1.473 amueller 4483: &overview($r);
4484: } elsif ($env{'form.action'} eq 'addmetadata') {
4485: &addmetafield($r);
4486: } elsif ($env{'form.action'} eq 'ordermetadata') {
4487: &order_meta_fields($r);
1.414 droeschl 4488: } elsif ($env{'form.action'} eq 'setrestrictmeta') {
1.473 amueller 4489: &setrestrictmeta($r);
1.414 droeschl 4490: } elsif ($env{'form.action'} eq 'newoverview') {
1.473 amueller 4491: &newoverview($r);
1.414 droeschl 4492: } elsif ($env{'form.action'} eq 'setdefaults') {
1.473 amueller 4493: &defaultsetter($r);
4494: } elsif ($env{'form.action'} eq 'settable') {
4495: &assessparms($r);
1.414 droeschl 4496: } elsif ($env{'form.action'} eq 'parameterchangelog') {
1.473 amueller 4497: &parm_change_log($r);
1.414 droeschl 4498: } elsif ($env{'form.action'} eq 'cleanparameters') {
1.473 amueller 4499: &clean_parameters($r);
1.414 droeschl 4500: } elsif ($env{'form.action'} eq 'dateshift1') {
1.390 www 4501: &date_shift_one($r);
1.414 droeschl 4502: } elsif ($env{'form.action'} eq 'dateshift2') {
1.390 www 4503: &date_shift_two($r);
1.446 bisitz 4504: }
1.43 albertel 4505: } else {
1.1 www 4506: # ----------------------------- Not in a course, or not allowed to modify parms
1.473 amueller 4507: if ($exists) {
4508: $env{'user.error.msg'}=
4509: "/adm/parmset:opa:0:0:Cannot modify assessment parameters";
4510: } else {
4511: $env{'user.error.msg'}=
4512: "/adm/parmset::0:1:Course environment gone, reinitialize the course";
4513: }
4514: return HTTP_NOT_ACCEPTABLE;
1.43 albertel 4515: }
1.376 albertel 4516: &reset_caches();
4517:
1.43 albertel 4518: return OK;
1.1 www 4519: }
4520:
4521: 1;
4522: __END__
4523:
4524:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>