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