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