File:  [LON-CAPA] / loncom / interface / lonparmset.pm
Revision 1.605: download - view: text, annotated - select for diffs
Wed Mar 23 16:39:47 2022 UTC (2 years, 1 month ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Bug 6969
  Don't call &storeparm() for a user-specific parameter if $uname is null.

    1: # The LearningOnline Network with CAPA
    2: # Handler to set parameters for assessments
    3: #
    4: # $Id: lonparmset.pm,v 1.605 2022/03/23 16:39:47 raeburn Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: ###################################################################
   29: ###################################################################
   30: 
   31: =pod
   32: 
   33: =head1 NAME
   34: 
   35: lonparmset - Handler to set parameters for assessments and course
   36: 
   37: =head1 SYNOPSIS
   38: 
   39: lonparmset provides an interface to setting content parameters in a 
   40: course.
   41: 
   42: It contains all the code for the "Content and Problem Settings" UI, except
   43: for the helpers parameter.helper and resettimes.helper, and lonhelper.pm,
   44: and lonblockingmenu.pm.
   45: 
   46: =head1 DESCRIPTION
   47: 
   48: This module sets coursewide and assessment parameters.
   49: 
   50: =head1 INTERNAL SUBROUTINES
   51: 
   52: =over
   53: 
   54: =item parmval()
   55: 
   56: Figure out a cascading parameter.
   57: 
   58: Inputs:  $what - a parameter spec (incluse part info and name I.E. 0.weight)
   59:          $id   - a bighash Id number
   60:          $def  - the resource's default value   'stupid emacs
   61: 
   62: Returns:  A list, the first item is the index into the remaining list of items of parm values that is the active one, the list consists of parm values at the 18 possible levels
   63: 
   64: 18 - General Course
   65: 17 - Map or Folder level in course (recursive) 
   66: 16 - Map or Folder level in course (non-recursive)
   67: 15 - resource default
   68: 14 - map default
   69: 13 - resource level in course
   70: 12 - General for section
   71: 11 - Map or Folder level for section (recursive)
   72: 10 - Map or Folder level for section (non-recursive)
   73: 9 - resource level in section
   74: 8 - General for group
   75: 7 - Map or Folder level for group (recursive)
   76: 6 - Map or Folder level for group (non-recursive)
   77: 5 - resource level in group
   78: 4 - General for specific student
   79: 3 - Map or Folder level for specific student (recursive)
   80: 2 - Map or Folder level for specific student (non-recursive)
   81: 1 - resource level for specific student
   82: 
   83: =item parmval_by_symb()
   84: 
   85: =item reset_caches()
   86: 
   87: =item cacheparmhash() 
   88: 
   89: =item parmhash()
   90: 
   91: =item symbcache()
   92: 
   93: =item preset_defaults()
   94: 
   95: =item date_sanity_info()
   96: 
   97: =item storeparm()
   98: 
   99: Store a parameter by symb
  100: 
  101:     Takes
  102:     - symb
  103:     - name of parameter
  104:     - level
  105:     - new value
  106:     - new type
  107:     - username
  108:     - userdomain
  109: 
  110: =item log_parmset()
  111: 
  112: =item storeparm_by_symb_inner()
  113: 
  114: =item valout()
  115: 
  116: Format a value for output.
  117: 
  118: Inputs:  $value, $type, $editable
  119: 
  120: Returns: $value, formatted for output.  If $type indicates it is a date,
  121: localtime($value) is returned.
  122: $editable will return an icon to click on
  123: 
  124: =item plink()
  125: 
  126: Produces a link anchor.
  127: 
  128: Inputs: $type,$dis,$value,$marker,$return,$call
  129: 
  130: Returns: scalar with html code for a link which will envoke the 
  131: javascript function 'pjump'.
  132: 
  133: =item page_js()
  134: 
  135: =item startpage()
  136: 
  137: =item print_row()
  138: 
  139: =item print_td()
  140: 
  141: =item check_other_groups()
  142: 
  143: =item parm_control_group()
  144: 
  145: =item extractResourceInformation() : 
  146: 
  147:  extractResourceInformation extracts lots of information about all of the the course's resources into a variety of hashes.
  148: 
  149: Input: See list below
  150: 
  151: =over 4
  152: 
  153: =item * B<env{'user.name'}> : Current username
  154: 
  155: =item * B<env{'user.domain'}> : Domain of current user.
  156: 
  157: =item * B<env{"request.course.fn"}> : Course
  158: 
  159: =back
  160: 
  161: Outputs: See list below:
  162: 
  163: =over 4
  164: 
  165: =item * B<ids> (out) : An array that will contain all of the ids in the course.
  166: 
  167: =item * B<typep>(out) : hash, id->type, where "type" contains the extension of the file, thus, I<problem exam quiz assess survey form>.
  168: 
  169: =item * B<keyp> (out) : hash, id->key list, will contain a comma separated list of the meta-data keys available for the given id
  170: 
  171: =item * B<allparms> (out) : hash, name of parameter->display value (what is the display value?)
  172: 
  173: =item * B<allparts> (out) : hash, part identification->text representation of part, where the text representation is "[Part $part]"
  174: 
  175: =item * B<allmaps> (out) : hash, ???
  176: 
  177: =item * B<mapp> : ??
  178: 
  179: =item * B<symbp> : hash, id->full sym?
  180: 
  181: =item * B<maptitles>
  182: 
  183: =item * B<uris>
  184: 
  185: =item * B<keyorder>
  186: 
  187: =item * B<defkeytype>
  188: 
  189: =back
  190: 
  191: =item isdateparm()
  192: 
  193: =item parmmenu()
  194: 
  195: =item partmenu()
  196: 
  197: =item usermenu()
  198: 
  199: =item displaymenu()
  200: 
  201: =item mapmenu()
  202: 
  203: =item levelmenu()
  204: 
  205: =item sectionmenu()
  206: 
  207: =item keysplit()
  208: 
  209: =item keysinorder()
  210: 
  211: =item keysinorder_bytype()
  212: 
  213: =item keysindisplayorder()
  214: 
  215: =item standardkeyorder()
  216: 
  217: =item assessparms() : 
  218: 
  219: Show assessment data and parameters.  This is a large routine that should
  220: be simplified and shortened... someday.
  221: 
  222: Inputs: $r - the Apache request object.
  223:   
  224: Returns: nothing
  225: 
  226: Variables used (guessed by Jeremy):
  227: 
  228: =over
  229: 
  230: =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.
  231: 
  232: =item * B<psprt>: ParameterS PaRTs? a list of the parts of a problem that we are displaying? Used to display only selected parts?
  233: 
  234: =item * B<@catmarker> contains list of all possible parameters including part #s
  235: 
  236: =item * B<$fullkeyp> contains the full part/id # for the extraction of proper parameters
  237: 
  238: =item * B<$tempkeyp> contains part 0 only (no ids - ie, subparts)
  239:         When storing information, store as part 0
  240:         When requesting information, request from full part
  241: 
  242: =back
  243: 
  244: =item tablestart()
  245: 
  246: =item tableend()
  247: 
  248: =item extractuser()
  249: 
  250: =item parse_listdata_key()
  251: 
  252: =item listdata()
  253: 
  254: =item date_interval_selector()
  255: 
  256: =item get_date_interval_from_form()
  257: 
  258: =item default_selector()
  259: 
  260: =item string_selector()
  261: 
  262: =item dateshift()
  263: 
  264: =item newoverview()
  265: 
  266: =item secgroup_lister()
  267: 
  268: =item overview()
  269: 
  270: =item clean_parameters()
  271: 
  272: =item date_shift_one()
  273: 
  274: =item date_shift_two()
  275: 
  276: =item parse_key()
  277: 
  278: =item header()
  279: 
  280: Output html header for page
  281: 
  282: =item print_main_menu()
  283: 
  284: =item output_row()
  285: 
  286: Set portfolio metadata
  287: 
  288: =item order_meta_fields()
  289: 
  290: =item addmetafield()
  291: 
  292: =item setrestrictmeta()
  293: 
  294: =item get_added_meta_fieldnames()
  295: 
  296: =item get_deleted_meta_fieldnames()
  297: 
  298: =item defaultsetter()
  299: 
  300: =item components()
  301: 
  302: =item load_parameter_names()
  303: 
  304: =item parm_change_log()
  305: 
  306: =item handler() : 
  307: 
  308: Main handler.  Calls &assessparms subroutine.
  309: 
  310: =back
  311: 
  312: =cut
  313: 
  314: ###################################################################
  315: ###################################################################
  316: 
  317: package Apache::lonparmset;
  318: 
  319: use strict;
  320: use Apache::lonnet;
  321: use Apache::Constants qw(:common :http REDIRECT);
  322: use Apache::lonhtmlcommon();
  323: use Apache::loncommon;
  324: use GDBM_File;
  325: use Apache::lonhomework;
  326: use Apache::lonxml;
  327: use Apache::lonlocal;
  328: use Apache::lonnavmaps;
  329: use Apache::longroup;
  330: use Apache::lonrss;
  331: use HTML::Entities;
  332: use LONCAPA qw(:DEFAULT :match);
  333: 
  334: 
  335: ##################################################
  336: # CONTENT AND PROBLEM SETTINGS HTML PAGE HEADER/FOOTER
  337: ##################################################
  338: 
  339: # Page header
  340: #
  341: # @param {Apache2::RequestRec} $r - Apache request object
  342: # @param {string} $mode - selected tab, 'parmset' for course and problem settings, or 'coursepref' for course settings
  343: # @param {string} $crstype - course type ('Community' for community settings)
  344: sub startSettingsScreen {
  345:     my ($r,$mode,$crstype)=@_;
  346: 
  347:     my $tabtext = &mt('Course Settings');
  348:     if ($crstype eq 'Community') {
  349:         $tabtext = &mt('Community Settings');
  350:     } 
  351:     $r->print("\n".'<ul class="LC_TabContentBigger" id="main">');
  352:     $r->print("\n".'<li'.($mode eq 'coursepref'?' class="active"':'').'><a href="/adm/courseprefs"><b>&nbsp;&nbsp;&nbsp;&nbsp;'.
  353:                                           $tabtext.
  354:                                           '&nbsp;&nbsp;&nbsp;&nbsp;</b></a></li>');
  355: 
  356:     $r->print("\n".'<li'.($mode eq 'parmset'?' class="active"':'').' id="tabbededitor"><a href="/adm/parmset"><b>'.
  357:                                                                  &mt('Content and Problem Settings').'</b></a></li>');
  358:     $r->print("\n".'</ul>'."\n");
  359:     $r->print('<div class="LC_Box" style="clear:both;margin:0;" id="parameditor"><div id="maincoursedoc" style="margin:0 0;padding:0 0;"><div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">');
  360: }
  361: 
  362: # Page footer
  363: sub endSettingsScreen {
  364:    my ($r)=@_;
  365:    $r->print('</div></div></div>');
  366: }
  367: 
  368: 
  369: 
  370: ##################################################
  371: # (mostly) TABLE MODE
  372: # (parmval is also used for the log of parameter changes)
  373: ##################################################
  374: 
  375: # Calls parmval_by_symb, getting the symb from $id with &symbcache.
  376: #
  377: # @param {string} $what - part info and parameter name separated by a dot, e.g. '0.weight'
  378: # @param {string} $id - resource id or map pc
  379: # @param {string} $def - the resource's default value for this parameter
  380: # @param {string} $uname - user name
  381: # @param {string} $udom - user domain
  382: # @param {string} $csec - section name
  383: # @param {string} $cgroup - group name
  384: # @param {hash reference} $courseopt - course parameters hash (result of lonnet::get_courseresdata, dump of course's resourcedata.db)
  385: # @returns {Array}
  386: sub parmval {
  387:     my ($what,$id,$def,$uname,$udom,$csec,$cgroup,$courseopt)=@_;
  388:     return &parmval_by_symb($what,&symbcache($id),$def,$uname,$udom,$csec,
  389:                                                            $cgroup,$courseopt);
  390: }
  391: 
  392: # Returns an array containing
  393: # - the most specific level that is defined for that parameter (integer)
  394: # - an array with the level as index and the parameter value as value (when defined)
  395: #   (level 1 is the most specific and will have precedence)
  396: #
  397: # @param {string} $what - part info and parameter name separated by a dot, e.g. '0.weight'
  398: # @param {string} $symb - resource symb or map src
  399: # @param {string} $def - the resource's default value for this parameter
  400: # @param {string} $uname - user name
  401: # @param {string} $udom - user domain
  402: # @param {string} $csec - section name
  403: # @param {string} $cgroup - group name
  404: # @param {hash reference} $courseopt - course parameters hash (result of lonnet::get_courseresdata, dump of course's resourcedata.db)
  405: # @returns {Array}
  406: sub parmval_by_symb {
  407:     my ($what,$symb,$def,$uname,$udom,$csec,$cgroup,$courseopt)=@_;
  408: 
  409:     my $useropt;
  410:     if ($uname ne '' && $udom ne '') {
  411:         $useropt = &Apache::lonnet::get_userresdata($uname,$udom);
  412:     }
  413: 
  414:     my $result='';
  415:     my @outpar=();
  416: # ----------------------------------------------------- Cascading lookup scheme
  417:     my $map=(&Apache::lonnet::decode_symb($symb))[0];
  418:     $map = &Apache::lonnet::deversion($map);
  419:     
  420:     # NOTE: some of that code looks redondant with code in lonnavmaps::parmval_real,
  421:     # any change should be reflected there.
  422:     
  423:     my $symbparm=$symb.'.'.$what;
  424:     my $recurseparm=$map.'___(rec).'.$what; 
  425:     my $mapparm=$map.'___(all).'.$what;
  426: 
  427:     my $grplevel=$env{'request.course.id'}.'.['.$cgroup.'].'.$what;
  428:     my $grplevelr=$env{'request.course.id'}.'.['.$cgroup.'].'.$symbparm;
  429:     my $grpleveli=$env{'request.course.id'}.'.['.$cgroup.'].'.$recurseparm;
  430:     my $grplevelm=$env{'request.course.id'}.'.['.$cgroup.'].'.$mapparm;
  431: 
  432:     my $seclevel=$env{'request.course.id'}.'.['.$csec.'].'.$what;
  433:     my $seclevelr=$env{'request.course.id'}.'.['.$csec.'].'.$symbparm;
  434:     my $secleveli=$env{'request.course.id'}.'.['.$csec.'].'.$recurseparm;
  435:     my $seclevelm=$env{'request.course.id'}.'.['.$csec.'].'.$mapparm;
  436: 
  437:     my $courselevel=$env{'request.course.id'}.'.'.$what;
  438:     my $courselevelr=$env{'request.course.id'}.'.'.$symbparm;
  439:     my $courseleveli=$env{'request.course.id'}.'.'.$recurseparm;
  440:     my $courselevelm=$env{'request.course.id'}.'.'.$mapparm;
  441: 
  442: 
  443: # --------------------------------------------------------- first, check course
  444: 
  445: # 18 - General Course
  446:     if (defined($$courseopt{$courselevel})) {
  447:         $outpar[18]=$$courseopt{$courselevel};
  448:         $result=18;
  449:     }
  450: 
  451: # 17 - Map or Folder level in course (recursive) 
  452:     if (defined($$courseopt{$courseleveli})) {
  453:         $outpar[17]=$$courseopt{$courseleveli};
  454:         $result=17;
  455:     }
  456: 
  457: # 16 - Map or Folder level in course (non-recursive)
  458:     if (defined($$courseopt{$courselevelm})) {
  459:         $outpar[16]=$$courseopt{$courselevelm};
  460:         $result=16;
  461:     }
  462: 
  463: # ------------------------------------------------------- second, check default
  464: 
  465: # 15 - resource default
  466:     if (defined($def)) { $outpar[15]=$def; $result=15; }
  467: 
  468: # ------------------------------------------------------ third, check map parms
  469: 
  470:     
  471: # 14 - map default
  472:     my $thisparm=&parmhash($symbparm);
  473:     if (defined($thisparm)) { $outpar[14]=$thisparm; $result=14; }
  474: 
  475: # 13 - resource level in course
  476:     if (defined($$courseopt{$courselevelr})) {
  477:         $outpar[13]=$$courseopt{$courselevelr};
  478:         $result=13;
  479:     }
  480: 
  481: # ------------------------------------------------------ fourth, back to course
  482:     if ($csec ne '') {
  483: # 12 - General for section
  484:         if (defined($$courseopt{$seclevel})) {
  485:             $outpar[12]=$$courseopt{$seclevel};
  486:             $result=12;
  487:         }
  488: # 11 - Map or Folder level for section (recursive)
  489:         if (defined($$courseopt{$secleveli})) {
  490:             $outpar[11]=$$courseopt{$secleveli};
  491:             $result=11;
  492:         }
  493: # 10 - Map or Folder level for section (non-recursive)
  494:         if (defined($$courseopt{$seclevelm})) {
  495:             $outpar[10]=$$courseopt{$seclevelm};
  496:             $result=10;
  497:         }
  498: # 9 - resource level in section
  499:         if (defined($$courseopt{$seclevelr})) {
  500:             $outpar[9]=$$courseopt{$seclevelr};
  501:             $result=9;
  502:         }
  503:     }
  504: # ------------------------------------------------------ fifth, check course group
  505:     if ($cgroup ne '') {
  506: # 8 - General for group
  507:         if (defined($$courseopt{$grplevel})) {
  508:             $outpar[8]=$$courseopt{$grplevel};
  509:             $result=8;
  510:         }
  511: # 7 - Map or Folder level for group (recursive)
  512:         if (defined($$courseopt{$grpleveli})) {
  513:             $outpar[7]=$$courseopt{$grpleveli};
  514:             $result=7;
  515:         }
  516: # 6 - Map or Folder level for group (non-recursive)
  517:         if (defined($$courseopt{$grplevelm})) {
  518:             $outpar[6]=$$courseopt{$grplevelm};
  519:             $result=6;
  520:         }
  521: # 5 - resource level in group
  522:         if (defined($$courseopt{$grplevelr})) {
  523:             $outpar[5]=$$courseopt{$grplevelr};
  524:             $result=5;
  525:         }
  526:     }
  527: 
  528: # ---------------------------------------------------------- sixth, check user
  529: 
  530:     if ($uname ne '') {
  531: # 4 - General for specific student
  532:         if (defined($$useropt{$courselevel})) {
  533:             $outpar[4]=$$useropt{$courselevel};
  534:             $result=4;
  535:         }
  536: 
  537: # 3 - Map or Folder level for specific student (recursive)
  538:         if (defined($$useropt{$courseleveli})) {
  539:             $outpar[3]=$$useropt{$courseleveli};
  540:             $result=3;
  541:         }
  542: 
  543: # 2 - Map or Folder level for specific student (non-recursive)
  544:         if (defined($$useropt{$courselevelm})) {
  545:             $outpar[2]=$$useropt{$courselevelm};
  546:             $result=2;
  547:         }
  548: 
  549: # 1 - resource level for specific student
  550:         if (defined($$useropt{$courselevelr})) {
  551:             $outpar[1]=$$useropt{$courselevelr};
  552:             $result=1;
  553:         }
  554:     }
  555:     return ($result,@outpar);
  556: }
  557: 
  558: 
  559: 
  560: # --- Caches local to lonparmset
  561: 
  562: 
  563: # Reset lonparmset caches (called at the beginning and end of the handler).
  564: sub reset_caches {
  565:     &resetparmhash();
  566:     &resetsymbcache();
  567:     &resetrulescache();
  568: }
  569: 
  570: # cache for map parameters, stored temporarily in $env{'request.course.fn'}_parms.db
  571: # (these parameters come from param elements in .sequence files created with the advanced RAT)
  572: {
  573:     my $parmhashid; # course identifier, to initialize the cache only once for a course
  574:     my %parmhash; # the parameter cache
  575:     # reset map parameter hash
  576:     sub resetparmhash {
  577:         undef($parmhashid);
  578:         undef(%parmhash);
  579:     }
  580: 
  581:     # dump the _parms.db database into %parmhash
  582:     sub cacheparmhash {
  583:         if ($parmhashid eq  $env{'request.course.fn'}) { return; }
  584:         my %parmhashfile;
  585:         if (tie(%parmhashfile,'GDBM_File',
  586:             $env{'request.course.fn'}.'_parms.db',&GDBM_READER(),0640)) {
  587:             %parmhash=%parmhashfile;
  588:             untie(%parmhashfile);
  589:             $parmhashid=$env{'request.course.fn'};
  590:         }
  591:     }
  592: 
  593:     # returns a parameter value for an identifier symb.parts.parameter, using the map parameter cache
  594:     sub parmhash {
  595:         my ($id) = @_;
  596:         &cacheparmhash();
  597:         return $parmhash{$id};
  598:     }
  599: }
  600: 
  601: # cache resource id or map pc -> resource symb or map src, using lonnavmaps to find association
  602: {
  603:     my $symbsid; # course identifier, to initialize the cache only once for a course
  604:     my %symbs; # hash id->symb
  605:     # reset the id->symb cache
  606:     sub resetsymbcache {
  607:         undef($symbsid);
  608:         undef(%symbs);
  609:     }
  610: 
  611:     # returns the resource symb or map src corresponding to a resource id or map pc
  612:     # (using lonnavmaps and a cache)
  613:     sub symbcache {
  614:         my $id=shift;
  615:         if ($symbsid ne $env{'request.course.id'}) {
  616:             undef(%symbs);
  617:         }
  618:         if (!$symbs{$id}) {
  619:             my $navmap = Apache::lonnavmaps::navmap->new();
  620:             if ($id=~/\./) {
  621:                 my $resource=$navmap->getById($id);
  622:                 $symbs{$id}=$resource->symb();
  623:             } else {
  624:                 my $resource=$navmap->getByMapPc($id);
  625:                 $symbs{$id}=&Apache::lonnet::declutter($resource->src());
  626:             }
  627:             $symbsid=$env{'request.course.id'};
  628:         }
  629:         return $symbs{$id};
  630:     }
  631: }
  632: 
  633: # cache for parameter default actions (stored in parmdefactions.db)
  634: {
  635:     my $rulesid; # course identifier, to initialize the cache only once for a course
  636:     my %rules; # parameter default actions hash
  637:     sub resetrulescache {
  638:         undef($rulesid);
  639:         undef(%rules);
  640:     }
  641: 
  642:     # returns the value for a given key in the parameter default action hash
  643:     sub rulescache {
  644:         my $id=shift;
  645:         if ($rulesid ne $env{'request.course.id'}
  646:             && !defined($rules{$id})) {
  647:             my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  648:             my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
  649:             %rules=&Apache::lonnet::dump('parmdefactions',$dom,$crs);
  650:             $rulesid=$env{'request.course.id'};
  651:         }
  652:         return $rules{$id};
  653:     }
  654: }
  655: 
  656: 
  657: # Returns the values of the parameter type default action
  658: # "default value when manually setting".
  659: # If none is defined, ('','','','','') is returned.
  660: #
  661: # @param {string} $type - parameter type
  662: # @returns {Array<string>} - (hours, min, sec, value)
  663: sub preset_defaults {
  664:     my $type=shift;
  665:     if (&rulescache($type.'_action') eq 'default') {
  666:         # yes, there is something
  667:         return (&rulescache($type.'_hours'),
  668:             &rulescache($type.'_min'),
  669:             &rulescache($type.'_sec'),
  670:             &rulescache($type.'_value'));
  671:     } else {
  672:         # nothing there or something else
  673:         return ('','','','','');
  674:     }
  675: }
  676: 
  677: 
  678: # Checks that a date is after enrollment start date and before
  679: # enrollment end date.
  680: # Returns HTML with a warning if it is not, or the empty string otherwise.
  681: # This is used by both overview and table modes.
  682: #
  683: # @param {integer} $checkdate - the date to check.
  684: # @returns {string} - HTML possibly containing a localized warning message.
  685: sub date_sanity_info {
  686:    my $checkdate=shift;
  687:    unless ($checkdate) { return ''; }
  688:    my $result='';
  689:    my $crsprefix='course.'.$env{'request.course.id'}.'.';
  690:    if ($env{$crsprefix.'default_enrollment_end_date'}) {
  691:       if ($checkdate>$env{$crsprefix.'default_enrollment_end_date'}) {
  692:          $result.='<div class="LC_warning">'
  693:                  .&mt('After course enrollment end!')
  694:                  .'</div>';
  695:       }
  696:    }
  697:    if ($env{$crsprefix.'default_enrollment_start_date'}) {
  698:       if ($checkdate<$env{$crsprefix.'default_enrollment_start_date'}) {
  699:          $result.='<div class="LC_warning">'
  700:                  .&mt('Before course enrollment start!')
  701:                  .'</div>';
  702:       }
  703:    }
  704: # Preparation for additional warnings about dates in the past/future.
  705: # An improved, more context sensitive version is recommended,
  706: # e.g. warn for due and answer dates which are defined before the corresponding open date, etc.
  707: #   if ($checkdate<time) {
  708: #      $result.='<div class="LC_info">'
  709: #              .'('.&mt('in the past').')'
  710: #              .'</div>';
  711: #      }
  712: #   if ($checkdate>time) {
  713: #      $result.='<div class="LC_info">'
  714: #              .'('.&mt('in the future').')'
  715: #              .'</div>';
  716: #      }
  717:    return $result;
  718: }
  719: 
  720: 
  721: # Store a parameter value and type by ID, also triggering more parameter changes based on parameter default actions.
  722: #
  723: # @param {string} $sresid - resource id or map pc
  724: # @param {string} $spnam - part info and parameter name separated by a dot or underscore, e.g. '0.weight'
  725: # @param {integer} $snum - level
  726: # @param {string} $nval - new value
  727: # @param {string} $ntype - new type
  728: # @param {string} $uname - username
  729: # @param {string} $udom - userdomain
  730: # @param {string} $csec - section name
  731: # @param {string} $cgroup - group name
  732: sub storeparm {
  733:     my ($sresid,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$cgroup)=@_;
  734:     &storeparm_by_symb(&symbcache($sresid),$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,'',$cgroup);
  735: }
  736: 
  737: my %recstack; # hash parameter name -> 1 when a parameter was used before in a recursive call to storeparm_by_symb
  738: 
  739: # Store a parameter value and type by symb, also triggering more parameter changes based on parameter default actions.
  740: # Uses storeparm_by_symb_inner to actually store the parameter, ignoring any returned error.
  741: #
  742: # @param {string} $symb - resource symb or map src
  743: # @param {string} $spnam - part info and parameter name separated by a dot or underscore, e.g. '0.weight'
  744: # @param {integer} $snum - level
  745: # @param {string} $nval - new value
  746: # @param {string} $ntype - new type
  747: # @param {string} $uname - username
  748: # @param {string} $udom - userdomain
  749: # @param {string} $csec - section name
  750: # @param {boolean} $recflag - should be true for recursive calls to storeparm_by_symb, false otherwise
  751: # @param {string} $cgroup - group name
  752: sub storeparm_by_symb {
  753:     my ($symb,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$recflag,$cgroup)=@_;
  754:     unless ($recflag) {
  755:         # first time call
  756:         %recstack=();
  757:         $recflag=1;
  758:     }
  759:     # store parameter
  760:     &storeparm_by_symb_inner
  761:     ($symb,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$cgroup);
  762:     # don't do anything if parameter was reset
  763:     unless ($nval) { return; }
  764:     my ($prefix,$parm)=($spnam=~/^(.*[\_\.])([^\_\.]+)$/);
  765:     # remember that this was set
  766:     $recstack{$parm}=1;
  767:     # what does this trigger?
  768:     foreach my $triggered (split(/\:/,&rulescache($parm.'_triggers'))) {
  769:         # don't backfire
  770:         unless ((!$triggered) || ($recstack{$triggered})) {
  771:             my $action=&rulescache($triggered.'_action');
  772:             my ($whichaction,$whichparm)=($action=~/^(.*\_)([^\_]+)$/);
  773:             # set triggered parameter on same level
  774:             my $newspnam=$prefix.$triggered;
  775:             my $newvalue='';
  776:             my $active=1;
  777:             if ($action=~/^when\_setting/) {
  778:             # are there restrictions?
  779:                 if (&rulescache($triggered.'_triggervalue')=~/\w/) {
  780:                     $active=0;
  781:                     foreach my $possiblevalue (split(/\s*\,\s*/,&rulescache($triggered.'_triggervalue'))) {
  782:                         if (lc($possiblevalue) eq lc($nval)) { $active=1; }
  783:                     }
  784:                 }
  785:                 $newvalue=&rulescache($triggered.'_value');
  786:             } else {
  787:                 my $totalsecs=((&rulescache($triggered.'_days')*24+&rulescache($triggered.'_hours'))*60+&rulescache($triggered.'_min'))*60+&rulescache($triggered.'_sec');
  788:                 if ($action=~/^later\_than/) {
  789:                     $newvalue=$nval+$totalsecs;
  790:                 } else {
  791:                     $newvalue=$nval-$totalsecs;
  792:                 }
  793:             }
  794:             if ($active) {
  795:                 &storeparm_by_symb($symb,$newspnam,$snum,$newvalue,&rulescache($triggered.'_type'),
  796:                         $uname,$udom,$csec,$recflag,$cgroup);
  797:             }
  798:         }
  799:     }
  800:     return '';
  801: }
  802: 
  803: # Adds all given arguments to the course parameter log.
  804: # @returns {string} - the answer to the lonnet query.
  805: sub log_parmset {
  806:     return &Apache::lonnet::write_log('course','parameterlog',@_);
  807: }
  808: 
  809: # Store a parameter value and type by symb, without using the parameter default actions.
  810: # Expire related sheets.
  811: #
  812: # @param {string} $symb - resource symb or map src
  813: # @param {string} $spnam - part info and parameter name separated by a dot, e.g. '0.weight'
  814: # @param {integer} $snum - level
  815: # @param {string} $nval - new value
  816: # @param {string} $ntype - new type
  817: # @param {string} $uname - username
  818: # @param {string} $udom - userdomain
  819: # @param {string} $csec - section name
  820: # @param {string} $cgroup - group name
  821: # @returns {string} - HTML code with an error message if the parameter could not be stored.
  822: sub storeparm_by_symb_inner {
  823: # ---------------------------------------------------------- Get symb, map, etc
  824:     my ($symb,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$cgroup)=@_;
  825: # ---------------------------------------------------------- Construct prefixes
  826:     $spnam=~s/\_([^\_]+)$/\.$1/;
  827:     my $map=(&Apache::lonnet::decode_symb($symb))[0];
  828:     $map = &Apache::lonnet::deversion($map);
  829: 
  830:     my $symbparm=$symb.'.'.$spnam;
  831:     my $recurseparm=$map.'___(rec).'.$spnam;
  832:     my $mapparm=$map.'___(all).'.$spnam;
  833: 
  834:     my $grplevel=$env{'request.course.id'}.'.['.$cgroup.'].'.$spnam;
  835:     my $grplevelr=$env{'request.course.id'}.'.['.$cgroup.'].'.$symbparm;
  836:     my $grpleveli=$env{'request.course.id'}.'.['.$cgroup.'].'.$recurseparm;
  837:     my $grplevelm=$env{'request.course.id'}.'.['.$cgroup.'].'.$mapparm;
  838: 
  839:     my $seclevel=$env{'request.course.id'}.'.['.$csec.'].'.$spnam;
  840:     my $seclevelr=$env{'request.course.id'}.'.['.$csec.'].'.$symbparm;
  841:     my $secleveli=$env{'request.course.id'}.'.['.$csec.'].'.$recurseparm;
  842:     my $seclevelm=$env{'request.course.id'}.'.['.$csec.'].'.$mapparm;
  843: 
  844:     my $courselevel=$env{'request.course.id'}.'.'.$spnam;
  845:     my $courselevelr=$env{'request.course.id'}.'.'.$symbparm;
  846:     my $courseleveli=$env{'request.course.id'}.'.'.$recurseparm;
  847:     my $courselevelm=$env{'request.course.id'}.'.'.$mapparm;
  848: 
  849:     my $storeunder='';
  850:     my $possreplace='';
  851:     if (($snum==18) || ($snum==4)) { $storeunder=$courselevel; }
  852:     if (($snum==17) || ($snum==3)) { 
  853:         $storeunder=$courseleveli;
  854:         $possreplace=$courselevelm; 
  855:     } 
  856:     if (($snum==16) || ($snum==2)) { 
  857:         $storeunder=$courselevelm;
  858:         $possreplace=$courseleveli;
  859:     }
  860:     if (($snum==13) || ($snum==1)) { $storeunder=$courselevelr; }
  861:     if ($snum==12) { $storeunder=$seclevel; }
  862:     if ($snum==11) { 
  863:         $storeunder=$secleveli;
  864:         $possreplace=$seclevelm; 
  865:     }
  866:     if ($snum==10) { 
  867:         $storeunder=$seclevelm;
  868:         $possreplace=$secleveli;
  869:     }
  870:     if ($snum==9) { $storeunder=$seclevelr; }
  871:     if ($snum==8) { $storeunder=$grplevel; }
  872:     if ($snum==7) { 
  873:         $storeunder=$grpleveli;
  874:         $possreplace=$grplevelm;
  875:     }
  876:     if ($snum==6) {
  877:         $storeunder=$grplevelm;
  878:         $possreplace=$grpleveli;
  879:     }
  880:     if ($snum==5) { $storeunder=$grplevelr; }
  881: 
  882: 
  883:     my $delete;
  884:     if ($nval eq '') { $delete=1;}
  885:     my %storecontent = ($storeunder         => $nval,
  886:             $storeunder.'.type' => $ntype);
  887:     my $reply='';
  888:     
  889:     if ($snum>4) {
  890: # ---------------------------------------------------------------- Store Course
  891: #
  892:         my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  893:         my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  894:         # Expire sheets
  895:         &Apache::lonnet::expirespread('','','studentcalc');
  896:         if (($snum==13) || ($snum==9) || ($snum==5)) {
  897:             &Apache::lonnet::expirespread('','','assesscalc',$symb);
  898:         } elsif (($snum==17) || ($snum==16) || ($snum==11) || ($snum==10) || ($snum==7) || ($snum==6)) {
  899:             &Apache::lonnet::expirespread('','','assesscalc',$map);
  900:         } else {
  901:             &Apache::lonnet::expirespread('','','assesscalc');
  902:         }
  903:         # Store parameter
  904:         if ($delete) {
  905:             $reply=&Apache::lonnet::del
  906:             ('resourcedata',[keys(%storecontent)],$cdom,$cnum);
  907:                 &log_parmset(\%storecontent,1);
  908:         } else {
  909:             $reply=&Apache::lonnet::cput
  910:             ('resourcedata',\%storecontent,$cdom,$cnum);
  911:             &log_parmset(\%storecontent);
  912:             if ($possreplace) {
  913:                 my $resdata = &Apache::lonnet::get_courseresdata($cnum,$cdom);
  914:                 if (ref($resdata) eq 'HASH') {
  915:                     if (exists($resdata->{$possreplace})) {
  916:                         if (&Apache::lonnet::del
  917:                             ('resourcedata',[$possreplace,$possreplace.'.type'],$cdom,$cnum) eq 'ok') {
  918:                             &log_parmset({$possreplace => '', $possreplace.'.type' => $ntype},1);   
  919:                         }
  920:                     }
  921:                 }
  922:             }
  923:         }
  924:         &Apache::lonnet::devalidatecourseresdata($cnum,$cdom);
  925:     } else {
  926: # ------------------------------------------------------------------ Store User
  927: #
  928:         # Expire sheets
  929:         &Apache::lonnet::expirespread($uname,$udom,'studentcalc');
  930:         if ($snum==1) {
  931:             &Apache::lonnet::expirespread
  932:             ($uname,$udom,'assesscalc',$symb);
  933:         } elsif (($snum==2) || ($snum==3)) {
  934:             &Apache::lonnet::expirespread
  935:             ($uname,$udom,'assesscalc',$map);
  936:         } else {
  937:             &Apache::lonnet::expirespread($uname,$udom,'assesscalc');
  938:         }
  939:         # Store parameter
  940:         if ($delete) {
  941:             $reply=&Apache::lonnet::del
  942:             ('resourcedata',[keys(%storecontent)],$udom,$uname);
  943:             &log_parmset(\%storecontent,1,$uname,$udom);
  944:         } else {
  945:             $reply=&Apache::lonnet::cput
  946:             ('resourcedata',\%storecontent,$udom,$uname);
  947:             &log_parmset(\%storecontent,0,$uname,$udom);
  948:             if ($possreplace) {
  949:                 my $resdata = &Apache::lonnet::get_userresdata($uname,$udom);
  950:                 if (ref($resdata) eq 'HASH') {
  951:                     if (exists($resdata->{$possreplace})) {
  952:                         if (&Apache::lonnet::del
  953:                             ('resourcedata',[$possreplace,$possreplace.'.type'],$udom,$uname) eq 'ok') {
  954:                             &log_parmset({$possreplace => '',$possreplace.'.type' => $ntype},1,
  955:                                           $uname,$udom);
  956:                         }
  957:                     }
  958:                 }
  959:             }
  960:         }
  961:         &Apache::lonnet::devalidateuserresdata($uname,$udom);
  962:     }
  963: 
  964:     if ($reply=~/^error\:(.*)/) {
  965:         return "<span class=\"LC_error\">Write Error: $1</span>";
  966:     }
  967:     return '';
  968: }
  969: 
  970: 
  971: # Returns HTML with the value of the given parameter,
  972: # using a readable format for dates, and
  973: # a warning if there is a problem with a date.
  974: # Used by table mode.
  975: # Returns HTML for the editmap.png image if no value is defined and $editable is true.
  976: #
  977: # @param {string} $value - the parameter value
  978: # @param {string} $type - the parameter type
  979: # @param {boolean} $editable - Set to true to get an icon when no value is defined.
  980: sub valout {
  981:     my ($value,$type,$editable)=@_;
  982:     my $result = '';
  983:     # Values of zero are valid.
  984:     if (! $value && $value ne '0') {
  985:         if ($editable) {
  986:             $result =
  987:                 '<img src="/res/adm/pages/editmap.png"'
  988:                .' alt="'.&mt('Change').'"'
  989:                .' title="'.&mt('Change').'" style="border:0;" />';
  990:         } else {
  991:             $result='&nbsp;';
  992:         }
  993:     } else {
  994:         if ($type eq 'date_interval') {
  995:             my ($totalsecs,$donesuffix) = split(/_/,$value,2);
  996:             my ($usesdone,$donebuttontext,$proctor,$secretkey);
  997:             if ($donesuffix =~ /^done\:([^\:]+)\:(.*)$/) {
  998:                 $donebuttontext = $1;
  999:                 (undef,$proctor,$secretkey) = split(/_/,$2);
 1000:                 $usesdone = 'done';
 1001:             } elsif ($donesuffix =~ /^done(|_.+)$/) {
 1002:                 $donebuttontext = &mt('Done');
 1003:                 ($usesdone,$proctor,$secretkey) = split(/_/,$donesuffix);
 1004:             }
 1005:             my ($sec,$min,$hour,$mday,$mon,$year)=gmtime($totalsecs);
 1006:             my @timer;
 1007:             $year=$year-70;
 1008:             $mday--;
 1009:             if ($year) {
 1010: #               $result.=&mt('[quant,_1,yr]',$year).' ';
 1011:                 push(@timer,&mt('[quant,_1,yr]',$year));
 1012:             }
 1013:             if ($mon) {
 1014: #               $result.=&mt('[quant,_1,mth]',$mon).' ';
 1015:                 push(@timer,&mt('[quant,_1,mth]',$mon));
 1016:             }
 1017:             if ($mday) {
 1018: #               $result.=&mt('[quant,_1,day]',$mday).' ';
 1019:                 push(@timer,&mt('[quant,_1,day]',$mday));
 1020:             }
 1021:             if ($hour) {
 1022: #               $result.=&mt('[quant,_1,hr]',$hour).' ';
 1023:                 push(@timer,&mt('[quant,_1,hr]',$hour));
 1024:             }
 1025:             if ($min) {
 1026: #               $result.=&mt('[quant,_1,min]',$min).' ';
 1027:                 push(@timer,&mt('[quant,_1,min]',$min));
 1028:             }
 1029:             if ($sec) {
 1030: #               $result.=&mt('[quant,_1,sec]',$sec).' ';
 1031:                 push(@timer,&mt('[quant,_1,sec]',$sec));
 1032:             }
 1033: #           $result=~s/\s+$//;
 1034:             if (!@timer) { # Special case: all entries 0 -> display "0 secs" intead of empty field to keep this field editable
 1035:                 push(@timer,&mt('[quant,_1,sec]',0));
 1036:             }
 1037:             $result.=join(", ",@timer);
 1038:             if ($usesdone eq 'done') {
 1039:                 if ($secretkey) {
 1040:                     $result .= ' '.&mt('+ "[_1]" with proctor key: [_2]',$donebuttontext,$secretkey);  
 1041:                 } else {
 1042:                     $result .= ' + "'.$donebuttontext.'"';
 1043:                 }
 1044:             }
 1045:         } elsif (&isdateparm($type)) {
 1046:             $result = &Apache::lonlocal::locallocaltime($value).
 1047:                 &date_sanity_info($value);
 1048:         } else {
 1049:             $result = $value;
 1050:             $result=~s/\,/\, /gs;
 1051:             $result = &HTML::Entities::encode($result,'"<>&');
 1052:         }
 1053:     }
 1054:     return $result;
 1055: }
 1056: 
 1057: 
 1058: # Returns HTML containing a link on a parameter value, for table mode.
 1059: # The link uses the javascript function 'pjump'.
 1060: #
 1061: # @param {string} $type - parameter type
 1062: # @param {string} $dis - dialog title for editing the parameter value and type
 1063: # @param {string} $value - parameter value
 1064: # @param {string} $marker - identifier for the parameter, "resource id&part_parameter name&level", will be passed as pres_marker when the user submits a change.
 1065: # @param {string} $return - prefix for the name of the form and field names that will be used to submit the form ('parmform.pres')
 1066: # @param {string} $call - javascript function to call to submit the form ('psub')
 1067: # @param {boolean} $recursive - true if link is for a map/folder where parameter is currently set to be recursive.
 1068: # @param {string} $extra - optional additional information to send as tenth arg in call to javascript pjump function.
 1069: sub plink {
 1070:     my ($type,$dis,$value,$marker,$return,$call,$recursive,$extra)=@_;
 1071:     my $winvalue=$value;
 1072:     unless ($winvalue) {
 1073:         if (&isdateparm($type) || (&is_specialstring($type))) {
 1074:             $winvalue=$env{'form.recent_'.$type};
 1075:         } elsif ($type eq 'string_yesno') {
 1076:             if ($env{'form.recent_string'} =~ /^(yes|no)$/i) {
 1077:                 $winvalue=$env{'form.recent_string'};
 1078:             }
 1079:         } else {
 1080:             $winvalue=$env{'form.recent_'.(split(/\_/,$type))[0]};
 1081:         }
 1082:     }
 1083:     my ($parmname)=((split(/\&/,$marker))[1]=~/\_([^\_]+)$/);
 1084:     my ($hour,$min,$sec,$val)=&preset_defaults($parmname);
 1085:     unless (defined($winvalue)) { $winvalue=$val; }
 1086:     my $valout = &valout($value,$type,1);
 1087:     my $unencmarker = $marker;
 1088:     foreach my $item (\$type, \$dis, \$winvalue, \$marker, \$return, \$call,
 1089:               \$hour, \$min, \$sec, \$extra) {
 1090:         $$item = &HTML::Entities::encode($$item,'"<>&');
 1091:         $$item =~ s/\'/\\\'/g;
 1092:     }
 1093:     return '<table width="100%"><tr valign="top" align="right"><td><a name="'.$unencmarker.'" /></td></tr><tr><td align="center">'.
 1094:     '<a href="javascript:pjump('."'".$type."','".$dis."','".$winvalue."','"
 1095:         .$marker."','".$return."','".$call."','".$hour."','".$min."','".$sec."','".$extra."'".');">'.
 1096:         $valout.'</a></td></tr>'.($recursive?'<tr><td align="center" class="LC_parm_recursive">'.
 1097:                                               &mt('recursive').'</td></tr>' : '').'</table>';
 1098: 
 1099: }
 1100: 
 1101: # Javascript for table mode.
 1102: sub page_js {
 1103: 
 1104:     my $selscript=&Apache::loncommon::studentbrowser_javascript();
 1105:     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
 1106: 
 1107:     return(<<ENDJS);
 1108: <script type="text/javascript">
 1109: // <![CDATA[
 1110: 
 1111:     $pjump_def
 1112: 
 1113:     function psub() {
 1114:         var specstring = /^string_!(yesno|any)/i;
 1115:         if (document.parmform.pres_marker.value!='') {
 1116:             document.parmform.action+='#'+document.parmform.pres_marker.value;
 1117:             var typedef=new Array();
 1118:             typedef=document.parmform.pres_type.value.split('_');
 1119:             if (document.parmform.pres_type.value!='') {
 1120:                 if ((typedef[0]=='date') || 
 1121:                     (specstring.test(document.parmform.pres_type.value)))  {
 1122:                     eval('document.parmform.recent_'+
 1123:                         document.parmform.pres_type.value+
 1124:                         '.value=document.parmform.pres_value.value;');
 1125:                 } else {
 1126:                     eval('document.parmform.recent_'+typedef[0]+
 1127:                         '.value=document.parmform.pres_value.value;');
 1128:                 }
 1129:             }
 1130:             document.parmform.submit();
 1131:         } else {
 1132:             document.parmform.pres_value.value='';
 1133:             document.parmform.pres_marker.value='';
 1134:         }
 1135:     }
 1136: 
 1137:     function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
 1138:         var options = "width=" + w + ",height=" + h + ",";
 1139:         options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
 1140:         options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
 1141:         var newWin = window.open(url, wdwName, options);
 1142:         newWin.focus();
 1143:     }
 1144: 
 1145: // ]]>
 1146: 
 1147: </script>
 1148: $selscript
 1149: ENDJS
 1150: 
 1151: }
 1152: 
 1153: # Javascript to show or hide the map selection (function showHide_courseContent),
 1154: # for table and overview modes.
 1155: sub showhide_js {
 1156:     return <<"COURSECONTENTSCRIPT";
 1157: 
 1158: function showHide_courseContent() {
 1159:     var parmlevValue=document.getElementById("parmlev").value;
 1160:     if (parmlevValue == 'general') {
 1161:         document.getElementById('mapmenu').style.display="none";
 1162:     } else {
 1163:         if ((parmlevValue == "full") || (parmlevValue == "map")) {
 1164:             document.getElementById('mapmenu').style.display ="";
 1165:         } else {
 1166:             document.getElementById('mapmenu').style.display="none";
 1167:         }
 1168:     }
 1169:     return;
 1170: }
 1171: 
 1172: COURSECONTENTSCRIPT
 1173: }
 1174: 
 1175: # Javascript functions showHideLenient and toggleParmTextbox, for overview mode
 1176: sub toggleparmtextbox_js {
 1177:     return <<"ENDSCRIPT";
 1178: 
 1179: if (!document.getElementsByClassName) {
 1180:     function getElementsByClassName(node, classname) {
 1181:         var a = [];
 1182:         var re = new RegExp('(^| )'+classname+'( |$)');
 1183:         var els = node.getElementsByTagName("*");
 1184:         for(var i=0,j=els.length; i<j; i++)
 1185:             if(re.test(els[i].className))a.push(els[i]);
 1186:         return a;
 1187:     }
 1188: }
 1189: 
 1190: function showHideLenient() {
 1191:     var lenients;
 1192:     var setRegExp = /^set_/;
 1193:     if (document.getElementsByClassName) {
 1194:         lenients = document.getElementsByClassName('LC_lenient_radio');
 1195:     } else {
 1196:         lenients = getElementsByClassName(document.body,'LC_lenient_radio');
 1197:     }
 1198:     if (lenients != 'undefined') {
 1199:         for (var i=0; i<lenients.length; i++) {
 1200:             if (lenients[i].checked) {
 1201:                 if (lenients[i].value == 'weighted') {
 1202:                     if (setRegExp.test(lenients[i].name)) {
 1203:                         var identifier = lenients[i].name.replace(setRegExp,'');
 1204:                         toggleParmTextbox(document.parmform,identifier);
 1205:                     }
 1206:                 }
 1207:             }
 1208:         }
 1209:     }
 1210:     return;
 1211: }
 1212: 
 1213: function toggleParmTextbox(form,key) {
 1214:     var divfortext = document.getElementById('LC_parmtext_'+key);
 1215:     if (divfortext) {
 1216:         var caller = form.elements['set_'+key];
 1217:         if (caller.length) {
 1218:             for (i=0; i<caller.length; i++) {
 1219:                 if (caller[i].checked) {
 1220:                     if (caller[i].value == 'weighted') {
 1221:                         divfortext.style.display = 'inline';
 1222:                     } else {
 1223:                         divfortext.style.display = 'none';
 1224:                     }
 1225:                 }
 1226:             }
 1227:         }
 1228:     }
 1229:     return;
 1230: }
 1231: 
 1232: ENDSCRIPT
 1233: }
 1234: 
 1235: # Javascript function validateParms, for overview mode
 1236: sub validateparms_js {
 1237:     return <<'ENDSCRIPT';
 1238: 
 1239: function validateParms() {
 1240:     var textRegExp = /^settext_/;
 1241:     var tailLenient = /\.lenient$/;
 1242:     var patternRelWeight = /^\-?[\d.]+$/;
 1243:     var patternLenientStd = /^(yes|no|default)$/;
 1244:     var ipRegExp = /^setip/;
 1245:     var ipallowRegExp = /^setipallow_/;
 1246:     var ipdenyRegExp = /^setipdeny_/; 
 1247:     var deeplinkRegExp = /^deeplink_/;
 1248:     var dlListScopeRegExp = /^deeplink_(state|others|listing|scope)_/; 
 1249:     var dlLinkProtectRegExp = /^deeplink_protect_/;
 1250:     var dlLtidRegExp = /^deeplink_ltid_/;
 1251:     var dlLticRegExp = /^deeplink_ltic_/;
 1252:     var dlKeyRegExp = /^deeplink_key_/;
 1253:     var dlMenusRegExp = /^deeplink_menus_/;
 1254:     var dlCollsRegExp = /^deeplink_colls_/;
 1255:     var patternIP = /[\[\]\*\.a-zA-Z\d\-]+/;
 1256:     if ((document.parmform.elements.length != 'undefined')  && (document.parmform.elements.length) != 'null') {
 1257:         if (document.parmform.elements.length) {
 1258:             for (i=0; i<document.parmform.elements.length; i++) {
 1259:                 var name=document.parmform.elements[i].name;
 1260:                 if (textRegExp.test(name)) {
 1261:                     var identifier = name.replace(textRegExp,'');
 1262:                     if (tailLenient.test(identifier)) {
 1263:                         if (document.parmform.elements['set_'+identifier].length) {
 1264:                             for (var j=0; j<document.parmform.elements['set_'+identifier].length; j++) {
 1265:                                 if (document.parmform.elements['set_'+identifier][j].checked) {
 1266:                                     if (!(patternLenientStd.test(document.parmform.elements['set_'+identifier][j].value))) {
 1267:                                         var relweight = document.parmform.elements[i].value;
 1268:                                         relweight = relweight.replace(/^\s+|\s+$/g,'');
 1269:                                         if (!patternRelWeight.test(relweight)) {
 1270:                                             relweight = '0.0';
 1271:                                         }
 1272:                                         if (document.parmform.elements['set_'+identifier][j].value == 'weighted') {
 1273:                                             document.parmform.elements['set_'+identifier][j].value = relweight;
 1274:                                         } else {
 1275:                                             document.parmform.elements['set_'+identifier][j].value += ','+relweight;
 1276:                                         }
 1277:                                     }
 1278:                                     break;
 1279:                                 }
 1280:                             }
 1281:                         }
 1282:                     }
 1283:                 } else if (ipRegExp.test(name)) {
 1284:                     if (ipallowRegExp.test(name)) {
 1285:                         var identifier = name.replace(ipallowRegExp,'');
 1286:                         var possallow = document.parmform.elements[i].value;
 1287:                         possallow = possallow.replace(/^\s+|\s+$/g,'');
 1288:                         if (patternIP.test(possallow)) {
 1289:                             if (document.parmform.elements['set_'+identifier].value) {
 1290:                                 possallow = ','+possallow;
 1291:                             }
 1292:                             document.parmform.elements['set_'+identifier].value += possallow;
 1293:                         }
 1294:                     } else if (ipdenyRegExp.test(name)) {
 1295:                         var identifier = name.replace(ipdenyRegExp,'');
 1296:                         var possdeny = document.parmform.elements[i].value;
 1297:                         possdeny = possdeny.replace(/^\s+|\s+$/g,'');
 1298:                         if (patternIP.test(possdeny)) {
 1299:                             possdeny = '!'+possdeny;
 1300:                             if (document.parmform.elements['set_'+identifier].value) {
 1301:                                 possdeny = ','+possdeny;
 1302:                             }
 1303:                             document.parmform.elements['set_'+identifier].value += possdeny;
 1304:                         }
 1305:                     }
 1306:                 } else if (deeplinkRegExp.test(name)) {
 1307:                     if (dlListScopeRegExp.test(name)) {
 1308:                         var identifier =  name.replace(dlListScopeRegExp,'');
 1309:                         var idx = document.parmform.elements[i].selectedIndex;
 1310:                         if (idx > 0) { 
 1311:                             var possdeeplink = document.parmform.elements[i].options[idx].value
 1312:                             possdeeplink = possdeeplink.replace(/^\s+|\s+$/g,'');
 1313:                             if (document.parmform.elements['set_'+identifier].value) {
 1314:                                 possdeeplink = ','+possdeeplink;
 1315:                             }
 1316:                             document.parmform.elements['set_'+identifier].value += possdeeplink;
 1317:                         }
 1318:                     } else if (dlLinkProtectRegExp.test(name)) {
 1319:                         if (document.parmform.elements[i].checked) {
 1320:                             var identifier =  name.replace(dlLinkProtectRegExp,'');
 1321:                             var posslinkurl = document.parmform.elements[i].value;
 1322:                             posslinkurl = posslinkurl.replace(/^\s+|\s+$/g,'');
 1323:                             if (document.parmform.elements['set_'+identifier].value) {
 1324:                                 posslinkurl = ','+posslinkurl;
 1325:                             }
 1326:                             document.parmform.elements['set_'+identifier].value += posslinkurl;
 1327:                         }
 1328:                     } else if (dlLtidRegExp.test(name)) {
 1329:                         var identifier = name.replace(dlLtidRegExp,'');
 1330:                         if (isRadioSet('deeplink_protect_'+identifier,'ltid')) {
 1331:                             var possltid = document.parmform.elements[i].value;
 1332:                             possltid = possltid.replace(/\D+/g,'');
 1333:                             if (possltid.length) {
 1334:                                 if (document.parmform.elements['set_'+identifier].value) {
 1335:                                     possltid = ':'+possltid;
 1336:                                 }
 1337:                                 document.parmform.elements['set_'+identifier].value += possltid;
 1338:                             } else {
 1339:                                 document.parmform.elements['set_'+identifier].value = '';
 1340:                                 alert("A link type of 'domain LTI launch' was selected but no domain LTI launcher was selected.\nPlease select one, or choose a different supported link type.");
 1341:                                 return false;  
 1342:                             }
 1343:                         }
 1344:                     } else if (dlLticRegExp.test(name)) {
 1345:                         var identifier = name.replace(dlLticRegExp,'');
 1346:                         if (isRadioSet('deeplink_protect_'+identifier,'ltic')) {
 1347:                             var possltic = document.parmform.elements[i].value;
 1348:                             possltic = possltic.replace(/\D+/g,'');
 1349:                             if (possltic.length) {
 1350:                                 if (document.parmform.elements['set_'+identifier].value) {
 1351:                                     possltic = ':'+possltic;
 1352:                                 }
 1353:                                 document.parmform.elements['set_'+identifier].value += possltic;
 1354:                             } else {
 1355:                                 document.parmform.elements['set_'+identifier].value = '';
 1356:                                 alert("A link type of 'course LTI launch' was selected but no course LTI launcher was selected.\nPlease select one, or choose a different supported link type.");
 1357:                                 return false;
 1358:                             }
 1359:                         }
 1360:                     } else if (dlKeyRegExp.test(name)) {
 1361:                         var identifier = name.replace(dlKeyRegExp,'');
 1362:                         if (isRadioSet('deeplink_protect_'+identifier,'key')) {
 1363:                             var posskey = document.parmform.elements[i].value;
 1364:                             posskey = posskey.replace(/^\s+|\s+$/g,'');
 1365:                             var origlength = posskey.length;
 1366:                             posskey = posskey.replace(/[^a-zA-Z\d_.!@#$%^&*()+=-]/g,'');
 1367:                             var newlength = posskey.length;
 1368:                             if (newlength > 0) {
 1369:                                 var change = origlength - newlength;
 1370:                                 if (change) {
 1371:                                     alert(change+' disallowed character(s) removed from deeplink key'); 
 1372:                                 }
 1373:                                 if (document.parmform.elements['set_'+identifier].value) {
 1374:                                     posskey = ':'+posskey;
 1375:                                 }
 1376:                                 document.parmform.elements['set_'+identifier].value += posskey;
 1377:                             } else {
 1378:                                 document.parmform.elements['set_'+identifier].value = '';
 1379:                                 if (newlength < origlength) {
 1380:                                     alert("A link type of 'deep with key' was selected but the key value was blank, after removing disallowed characters.\nPlease enter a key using one or more of: a-zA-Z0-9_.!@#$%^&*()+=-");
 1381:                                 } else {
 1382:                                     alert("A link type of 'deep with key' was selected but the key value was blank.\nPlease enter a key.");
 1383:                                 }
 1384:                                 return false;
 1385:                             }
 1386:                         }
 1387:                     } else if (dlMenusRegExp.test(name)) {
 1388:                         if (document.parmform.elements[i].checked) {
 1389:                             var identifier =  name.replace(dlMenusRegExp,'');
 1390:                             var posslinkmenu = document.parmform.elements[i].value;
 1391:                             posslinkmenu = posslinkmenu.replace(/^\s+|\s+$/g,'');
 1392:                             if (posslinkmenu == 'std') {
 1393:                                 posslinkmenu = '0';
 1394:                                 if (document.parmform.elements['set_'+identifier].value) {
 1395:                                     posslinkmenu = ','+posslinkmenu;
 1396:                                 }
 1397:                                 document.parmform.elements['set_'+identifier].value += posslinkmenu;
 1398:                             }
 1399:                         }
 1400:                     } else if (dlCollsRegExp.test(name)) {
 1401:                         var identifier =  name.replace(dlCollsRegExp,'');
 1402:                         if (isRadioSet('deeplink_menus_'+identifier,'colls')) {
 1403:                             var posslinkmenu = document.parmform.elements[i].value;
 1404:                             if (document.parmform.elements['set_'+identifier].value) {
 1405:                                 posslinkmenu = ','+posslinkmenu;
 1406:                             }
 1407:                             document.parmform.elements['set_'+identifier].value += posslinkmenu;
 1408:                         }
 1409:                     }
 1410:                 }
 1411:             }
 1412:         }
 1413:     }
 1414:     return true;
 1415: }
 1416: 
 1417: function isRadioSet(name,expected) {
 1418:     var menuitems = document.getElementsByName(name);
 1419:     var radioLength = menuitems.length;
 1420:     result = false;
 1421:     if (radioLength  > 1) {
 1422:         for (var j=0; j<radioLength; j++) {
 1423:             if (menuitems[j].checked) {
 1424:                 if (menuitems[j].value == expected) {
 1425:                     result = true;
 1426:                     break;
 1427:                 }
 1428:             }
 1429:         }
 1430:     }
 1431:     return result;
 1432: }
 1433: 
 1434: ENDSCRIPT
 1435: }
 1436: 
 1437: # Javascript initialization, for overview mode
 1438: sub ipacc_boxes_js  {
 1439:     my $remove = &mt('Remove');
 1440:     return <<"END";
 1441: \$(document).ready(function() {
 1442:     var wrapper         = \$(".LC_string_ipacc_wrap");
 1443:     var add_button      = \$(".LC_add_ipacc_button");
 1444:     var ipaccRegExp     = /^LC_string_ipacc_/;
 1445: 
 1446:     \$(add_button).click(function(e){
 1447:         e.preventDefault();
 1448:         var identifier = \$(this).closest("div").attr("id");
 1449:         identifier = identifier.replace(ipaccRegExp,'');
 1450:         \$(this).closest('div').find('.LC_string_ipacc_inner').append('<div><input type="text" name="setip'+identifier+'" /><a href="#" class="LC_remove_ipacc">$remove</a></div>');
 1451:     });
 1452: 
 1453:     \$(wrapper).delegate(".LC_remove_ipacc","click", function(e){
 1454:         e.preventDefault(); \$(this).closest("div").remove();
 1455:     })
 1456: });
 1457: 
 1458: 
 1459: END
 1460: }
 1461: 
 1462: # Javascript function toggleSecret, for overview mode.
 1463: sub done_proctor_js {
 1464:     return <<"END";
 1465: function toggleSecret(form,radio,key) {
 1466:     var radios = form[radio+key];
 1467:     if (radios.length) {
 1468:         for (var i=0; i<radios.length; i++) {
 1469:             if (radios[i].checked) {
 1470:                 if (radios[i].value == '_done_proctor') {
 1471:                     if (document.getElementById('done_'+key+'_proctorkey')) {
 1472:                         document.getElementById('done_'+key+'_proctorkey').type='text';
 1473:                     }
 1474:                 } else {
 1475:                     if (document.getElementById('done_'+key+'_proctorkey')) {
 1476:                         document.getElementById('done_'+key+'_proctorkey').type='hidden';
 1477:                         document.getElementById('done_'+key+'_proctorkey').value='';
 1478:                     }
 1479:                 }
 1480:             }
 1481:         }
 1482:     }
 1483: }
 1484: END
 1485: 
 1486: }
 1487: 
 1488: # Javascript function toggle
 1489: sub deeplink_js {
 1490:     return <<"END";
 1491: function toggleDeepLink(form,item,key) {
 1492:     var radios = form['deeplink_'+item+'_'+key];
 1493:     if (radios.length) {
 1494:         var keybox;
 1495:         if (document.getElementById('deeplink_key_'+item+'_'+key)) {
 1496:             keybox = document.getElementById('deeplink_key_'+item+'_'+key);
 1497:         }
 1498:         var divoptions = new Array();
 1499:         if (item == 'protect') {
 1500:             divoptions = ['ltic','ltid'];
 1501:         } else {
 1502:             if (item == 'menus') {
 1503:                 divoptions = ['colls'];
 1504:             }
 1505:         }
 1506:         var seldivs = new Array();
 1507:         if ((item == 'protect') || (item == 'menus')) {
 1508:             for (var i=0; i<divoptions.length; i++) {
 1509:                 if (document.getElementById('deeplinkdiv_'+divoptions[i]+'_'+item+'_'+key)) {
 1510:                     seldivs[i] = document.getElementById('deeplinkdiv_'+divoptions[i]+'_'+item+'_'+key);
 1511:                 } else {
 1512:                     seldivs[i] = '';
 1513:                 }
 1514:             }
 1515:         }
 1516:         for (var i=0; i<radios.length; i++) {
 1517:             if (radios[i].checked) {
 1518:                 if ((item == 'protect') || (item == 'menus')) {
 1519:                     for (var j=0; j<seldivs.length; j++) {
 1520:                         if (radios[i].value == divoptions[j]) {
 1521:                             if (seldivs[j] != '') {
 1522:                                 seldivs[j].style.display = 'inline-block';
 1523:                             }
 1524:                             if (item == 'protect') {
 1525:                                 keybox.type = 'hidden';
 1526:                                 keybox.value = '';
 1527:                             }
 1528:                         } else {
 1529:                             if (seldivs[j] != '') {
 1530:                                 seldivs[j].style.display = 'none';
 1531:                                 form['deeplink_'+divoptions[j]+'_'+key].selectedIndex = 0;
 1532:                             }
 1533:                         }
 1534:                     }
 1535:                     if (item == 'protect') {
 1536:                         if (radios[i].value == 'key') {
 1537:                             keybox.type = 'text';
 1538:                         } else {
 1539:                             keybox.type = 'hidden';
 1540:                         }
 1541:                     }
 1542:                 }
 1543:             }
 1544:         }
 1545:     }
 1546: }
 1547: END
 1548: 
 1549: }
 1550: 
 1551: # Prints HTML page start for table mode.
 1552: # @param {Apache2::RequestRec} $r - the Apache request
 1553: # @param {string} $psymb - resource symb
 1554: # @param {string} $crstype - course type (Community / Course / Placement Test)
 1555: sub startpage {
 1556:     my ($r,$psymb,$crstype) = @_;
 1557: 
 1558:     my %loaditems = (
 1559:                       'onload'   => "group_or_section('cgroup')",
 1560:                     );
 1561:     if (!$psymb) {
 1562:         $loaditems{'onload'} = "showHide_courseContent(); group_or_section('cgroup'); resize_scrollbox('mapmenuscroll','1','1');";
 1563:     }
 1564: 
 1565:     if ((($env{'form.command'} eq 'set') && ($env{'form.url'}) &&
 1566:             (!$env{'form.dis'})) || ($env{'form.symb'})) {
 1567:         &Apache::lonhtmlcommon::add_breadcrumb({help=>'Problem_Parameters',
 1568:             text=>"Problem Parameters"});
 1569:     } else {
 1570:         &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=settable',
 1571:             text=>"Table Mode",
 1572:             help => 'Course_Setting_Parameters'});
 1573:     }
 1574:     my $js = &page_js().'
 1575: <script type="text/javascript">
 1576: // <![CDATA[
 1577: '.
 1578:             &Apache::lonhtmlcommon::resize_scrollbox_js('params').'
 1579: // ]]>
 1580: </script>
 1581: ';
 1582:     my $start_page =
 1583:         &Apache::loncommon::start_page('Set/Modify Course Parameters',$js,
 1584:                                        {'add_entries' => \%loaditems,});
 1585:     my $breadcrumbs =
 1586:     &Apache::lonhtmlcommon::breadcrumbs('Table Mode Parameter Setting','Table_Mode');
 1587:     my $escfilter=&Apache::lonhtmlcommon::entity_encode($env{'form.filter'});
 1588:     my $escpart=&Apache::lonhtmlcommon::entity_encode($env{'form.part'});
 1589:     $r->print($start_page.$breadcrumbs);
 1590:     &startSettingsScreen($r,'parmset',$crstype);
 1591:     $r->print(<<ENDHEAD);
 1592: <form method="post" action="/adm/parmset?action=settable" name="parmform">
 1593: <input type="hidden" value="" name="pres_value" />
 1594: <input type="hidden" value="" name="pres_type" />
 1595: <input type="hidden" value="" name="pres_marker" />
 1596: <input type="hidden" value="1" name="prevvisit" />
 1597: <input type="hidden" value="$escfilter" name="filter" />
 1598: <input type="hidden" value="$escpart" name="part" />
 1599: ENDHEAD
 1600: }
 1601: 
 1602: 
 1603: # Prints a row for table mode (except for the tr start).
 1604: # Every time a hash reference is passed, a single entry is used, so print_row
 1605: # could just use these values, but why make it simple when it can be complicated ?
 1606: #
 1607: # @param {Apache2::RequestRec} $r - the Apache request
 1608: # @param {string} $which - parameter key ('parameter_'.part.'_'.name)
 1609: # @param {hash reference} $part - parameter key -> parameter part (can be problem part.'_'.response id for response parameters)
 1610: # @param {hash reference} $name - parameter key -> parameter name
 1611: # @param {hash reference} $symbp - map pc or resource/map id -> map src.'___(all)' or resource symb
 1612: # @param {string} $rid - resource id
 1613: # @param {hash reference} $default - parameter key -> resource parameter default value
 1614: # @param {hash reference} $defaulttype - parameter key -> resource parameter default type
 1615: # @param {hash reference} $display - parameter key -> full title for the parameter
 1616: # @param {string} $defbgone - user level and other levels background color
 1617: # @param {string} $defbgtwo - section level background color, also used for part number
 1618: # @param {string} $defbgthree - group level background color
 1619: # @param {string} $parmlev - parameter level (Resource:'full', Map:'map', Course:'general')
 1620: # @param {string} $uname - user name
 1621: # @param {string} $udom - user domain
 1622: # @param {string} $csec - section name
 1623: # @param {string} $cgroup - group name
 1624: # @param {array reference} $usersgroups - list of groups the user belongs to, if any
 1625: # @param {boolean} $noeditgrp - true if no edit is allowed for group level parameters
 1626: # @param {boolean} $readonly - true if no editing allowed.
 1627: # @param {array reference} - $recurseup - list of maps containing current one, ending at top-level.
 1628: # @param {hash reference} - $maptitles - - hash map id or src -> map title 
 1629: # @param {hash reference} - $allmaps_inverted - hash map src -> map pc
 1630: # @param {scalar reference} - $reclinks - number of "parameter in effect" cells with link to map where recursive param was set 
 1631: sub print_row {
 1632:     my ($r,$which,$part,$name,$symbp,$rid,$default,$defaulttype,$display,$defbgone,
 1633:     $defbgtwo,$defbgthree,$parmlev,$uname,$udom,$csec,$cgroup,$usersgroups,$noeditgrp,
 1634:     $readonly,$recurseup,$maptitles,$allmaps_inverted,$reclinks)=@_;
 1635:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 1636:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 1637:     my $courseopt=&Apache::lonnet::get_courseresdata($cnum,$cdom);
 1638:     my $numlinks = 0;
 1639: 
 1640:     # get the values for the parameter in cascading order
 1641:     # empty levels will remain empty
 1642:     my ($result,@outpar)=&parmval($$part{$which}.'.'.$$name{$which},
 1643:       $rid,$$default{$which},$uname,$udom,$csec,$cgroup,$courseopt);
 1644:     # get the type for the parameters
 1645:     # problem: these may not be set for all levels
 1646:     my ($typeresult,@typeoutpar)=&parmval($$part{$which}.'.'.
 1647:                                           $$name{$which}.'.type',$rid,
 1648:          $$defaulttype{$which},$uname,$udom,$csec,$cgroup,$courseopt);
 1649:     # cascade down manually
 1650:     my $cascadetype=$$defaulttype{$which};
 1651:     for (my $i=18;$i>0;$i--) {
 1652:         if ($typeoutpar[$i]) {
 1653:             $cascadetype=$typeoutpar[$i];
 1654:         } else {
 1655:             $typeoutpar[$i]=$cascadetype;
 1656:         }
 1657:     }
 1658:     my $parm=$$display{$which};
 1659: 
 1660:     if ($parmlev eq 'full') {
 1661:         $r->print('<td style="background-color:'.$defbgtwo.';" align="center">'
 1662:                   .($$part{$which} eq '0'?'0 ('.&mt('default').')':$$part{$which}).'</td>');
 1663:     } else {
 1664:         $parm=~s|\[.*\]\s||g;
 1665:     }
 1666:     my $automatic=&rulescache(($which=~/\_([^\_]+)$/)[0].'_triggers');
 1667:     if ($automatic) {
 1668:         $parm.='<span class="LC_warning"><br />'.&mt('Automatically sets').' '.join(', ',split(/\:/,$automatic)).'</span>';
 1669:     }
 1670:     $r->print('<td>'.$parm.'</td>');
 1671: 
 1672:     my $thismarker=$which;
 1673:     $thismarker=~s/^parameter\_//;
 1674:     my $mprefix=$rid.'&'.$thismarker.'&';
 1675:     my ($parmname)=($thismarker=~/\_([^\_]+)$/);
 1676:     my ($othergrp,$grp_parm,$controlgrp,$effective_parm,$effparm_rec,$effparm_level,
 1677:         $eff_groupparm,$recurse_check,$recursinfo,$extra);
 1678:     if ((ref($recurseup) eq 'ARRAY') && (@{$recurseup} > 0)) {
 1679:         if ($result eq '') {
 1680:             $recurse_check = 1;
 1681:         } elsif (($uname ne '') && ($result > 3)) {
 1682:             $recurse_check = 1;
 1683:         } elsif (($cgroup ne '') && ($result > 7)) {
 1684:             $recurse_check = 1;
 1685:         } elsif (($csec ne '') && ($result > 11)) {
 1686:             $recurse_check = 1;
 1687:         } elsif ($result > 17) {
 1688:             $recurse_check = 1;
 1689:         }
 1690:         if ($recurse_check) {
 1691:             my $what = $$part{$which}.'.'.$$name{$which};
 1692:             my $prefix;
 1693:             if (($uname ne '') && ($udom ne '')) {
 1694:                 my $useropt = &Apache::lonnet::get_userresdata($uname,$udom);
 1695:                 $prefix = $env{'request.course.id'};
 1696:                 $recursinfo = &get_recursive($recurseup,$useropt,$what,$prefix);
 1697:                 if (ref($recursinfo) eq 'ARRAY') {
 1698:                     $effparm_rec = 1;
 1699:                     $effparm_level = &mt('user: [_1]',$uname);
 1700:                 }
 1701:             }
 1702:             if (($cgroup ne '') && (!$effparm_rec)) {
 1703:                 $prefix = $env{'request.course.id'}.'.['.$cgroup.']';
 1704:                 $recursinfo = &get_recursive($recurseup,$courseopt,$what,$prefix);
 1705:                 if (ref($recursinfo) eq 'ARRAY') {
 1706:                     $effparm_rec = 1;
 1707:                     $effparm_level = &mt('group: [_1]',$cgroup);
 1708:                 }
 1709:             }
 1710:             if (($csec ne '') && (!$effparm_rec)) {
 1711:                 $prefix = $env{'request.course.id'}.'.['.$csec.']';
 1712:                 $recursinfo = &get_recursive($recurseup,$courseopt,$what,$prefix);
 1713:                 if (ref($recursinfo) eq 'ARRAY') {
 1714:                     $effparm_rec = 1;
 1715:                     $effparm_level = &mt('section: [_1]',$csec);
 1716:                 }
 1717:             }
 1718:             if (!$effparm_rec) {
 1719:                 $prefix = $env{'request.course.id'};
 1720:                 $recursinfo = &get_recursive($recurseup,$courseopt,$what,$prefix); 
 1721:                 if (ref($recursinfo) eq 'ARRAY') {
 1722:                     $effparm_rec = 1;
 1723:                 }
 1724:             }
 1725:         }
 1726:     }
 1727:     if ((!$effparm_rec) && ($result == 17 || $result == 11 || $result == 7 || $result == 3)) {
 1728:         $effparm_rec = 1;
 1729:     }
 1730:     if ((!$effparm_rec) && 
 1731:         (($$name{$which} eq 'encrypturl') || ($$name{$which} eq 'hiddenresource')) && 
 1732:         ($result == 16 || $result == 10 || $result == 6 || $result == 2)) {
 1733:         $effparm_rec = 1;
 1734:     }
 1735:     if ($parmname eq 'deeplink') {
 1736:         my ($domltistr,$crsltistr);
 1737:         my %lti =
 1738:             &Apache::lonnet::get_domain_lti($env{'course.'.$env{'request.course.id'}.'.domain'},
 1739:                                             'linkprot');
 1740:         if (keys(%lti)) {
 1741:             foreach my $item (sort { $a <=> $b }  (keys(%lti))) {
 1742:                 if (($item =~ /^\d+$/) && (ref($lti{$item}) eq 'HASH')) {
 1743:                     $domltistr .= $item.':'.&escape(&escape($lti{$item}{'name'})).',';
 1744:                 }
 1745:             }
 1746:             $domltistr =~ s/,$//;
 1747:             if ($domltistr) {
 1748:                 $extra = 'ltid_'.$domltistr;
 1749:             }
 1750:         }
 1751:         my %courselti = &Apache::lonnet::get_course_lti($cnum,$cdom);
 1752:         if (keys(%courselti)) {
 1753:             foreach my $item (sort { $a <=> $b } keys(%courselti)) {
 1754:                 if (($item =~ /^\d+$/) && (ref($courselti{$item}) eq 'HASH')) {
 1755:                     $crsltistr .= $item.':'.&escape(&escape($courselti{$item}{'name'})).',';
 1756:                 }
 1757:             }
 1758:             $crsltistr =~ s/,$//;
 1759:             if ($crsltistr) {
 1760:                 if ($extra) {
 1761:                     $extra .= '&';
 1762:                 }
 1763:                 $extra .= 'ltic_'.$crsltistr;
 1764:             }
 1765:         }
 1766:         if ($env{'course.'.$env{'request.course.id'}.'.menucollections'}) {
 1767:             my @colls;
 1768:             foreach my $item (split(/;/,$env{'course.'.$env{'request.course.id'}.'.menucollections'})) {
 1769:                 my ($num,$value) = split(/\%/,$item);
 1770:                 if ($num =~ /^\d+$/) {
 1771:                     push(@colls,$num);
 1772:                 }
 1773:             }
 1774:             if (@colls) {
 1775:                 if ($extra) {
 1776:                     $extra .= '&';
 1777:                 }
 1778:                 $extra .= 'menus_'.join(',',@colls);
 1779:             }
 1780:         }
 1781:     }
 1782:     if ($parmlev eq 'general') {
 1783:         if ($uname) {
 1784:             &print_td($r,4,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra);
 1785:         } elsif ($cgroup) {
 1786:             &print_td($r,8,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp,$readonly,'',$extra);
 1787:         } elsif ($csec) {
 1788:             &print_td($r,12,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra);
 1789:         } else {
 1790:             &print_td($r,18,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra);
 1791:         }
 1792:     } elsif ($parmlev eq 'map') {
 1793:         if ($uname) {
 1794:             &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,1,$extra);
 1795:         } elsif ($cgroup) {
 1796:             &print_td($r,6,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp,$readonly,1,$extra);
 1797:         } elsif ($csec) {
 1798:             &print_td($r,10,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,1,$extra);
 1799:         } else {
 1800:             &print_td($r,16,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,1,$extra);
 1801:         }
 1802:     } else {
 1803:         if ($uname) {
 1804:             if (@{$usersgroups} > 1) {
 1805:                 (my $coursereply,$othergrp,$grp_parm,$controlgrp,my $grp_is_rec) =
 1806:                     &check_other_groups($$part{$which}.'.'.$$name{$which},
 1807:                        $rid,$cgroup,$defbgone,$usersgroups,$result,$courseopt);
 1808:                 if (($coursereply) && ($result > 4)) {
 1809:                     if (defined($controlgrp)) {
 1810:                         if ($cgroup ne $controlgrp) {
 1811:                             $eff_groupparm = $grp_parm;
 1812:                             undef($result);
 1813:                             undef($effparm_rec);
 1814:                             if ($grp_is_rec) {
 1815:                                  $effparm_rec = 1;
 1816:                             }
 1817:                         }
 1818:                     }
 1819:                 }
 1820:             }
 1821:         }
 1822: 
 1823:         &print_td($r,18,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra);
 1824:         &print_td($r,16,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,1,$extra);
 1825:         &print_td($r,15,'#FFDDDD',$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra);
 1826:         &print_td($r,14,'#FFDDDD',$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra);
 1827:         &print_td($r,13,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra);
 1828: 
 1829:         if ($csec) {
 1830:             &print_td($r,12,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra);
 1831:             &print_td($r,10,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,1,$extra);
 1832:             &print_td($r,9,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra);
 1833:         }
 1834: 
 1835:         if ($cgroup) {
 1836:             &print_td($r,8,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp,$readonly,'',$extra);
 1837:             &print_td($r,6,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp,$readonly,1,$extra);
 1838:             &print_td($r,5,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp.$readonly,'',$extra);
 1839:         }
 1840: 
 1841:         if ($uname) {
 1842:             if ($othergrp) {
 1843:                 $r->print($othergrp);
 1844:             }
 1845:             &print_td($r,4,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra);
 1846:             &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,1,$extra);
 1847:             &print_td($r,1,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra);
 1848:         }
 1849:     } # end of $parmlev if/else
 1850:     if (ref($recursinfo) eq 'ARRAY') {
 1851:         my $rectitle = &mt('recursive');
 1852:         if ((ref($maptitles) eq 'HASH') && (exists($maptitles->{$recursinfo->[2]}))) {
 1853:             if ((ref($allmaps_inverted) eq 'HASH') && (exists($allmaps_inverted->{$recursinfo->[2]}))) {
 1854:                 $rectitle = &mt('set in: [_1]','"'.
 1855:                                 '<a href="javascript:pjumprec('."'".$allmaps_inverted->{$recursinfo->[2]}."',".
 1856:                                                               "'$parmname','$$part{$which}'".');">'.
 1857:                                 $maptitles->{$recursinfo->[2]}.'</a>"');
 1858:               
 1859:                 $numlinks ++;
 1860:             }
 1861:         }
 1862:         my ($parmname)=($thismarker=~/\_([^\_]+)$/);
 1863:         $effective_parm = &valout($recursinfo->[0],$recursinfo->[1]);
 1864:         $r->print('<td style="background-color:#CCCCFF;" align="center">'.$effective_parm.
 1865:                   '<br /><span class="LC_parm_recursive">'.$rectitle.'&nbsp;'.
 1866:                   $effparm_level.'</span></td>');
 1867:     } else {
 1868:         if ($result) {
 1869:             $effective_parm = &valout($outpar[$result],$typeoutpar[$result]);
 1870:         }
 1871:         if ($eff_groupparm) {
 1872:             $effective_parm = $eff_groupparm;
 1873:         }
 1874:         $r->print('<td style="background-color:#CCCCFF;" align="center">'.$effective_parm.
 1875:                   ($effparm_rec?'<br /><span class="LC_parm_recursive">'.&mt('recursive').
 1876:                                 '</span>':'').'</td>');
 1877:     }
 1878:     if ($parmlev eq 'full') {
 1879:         my $sessionval=&Apache::lonnet::EXT('resource.'.$$part{$which}.
 1880:                                         '.'.$$name{$which},$$symbp{$rid});
 1881:         my $sessionvaltype=$typeoutpar[$result];
 1882:         if (!defined($sessionvaltype)) {
 1883:             $sessionvaltype=$$defaulttype{$which};
 1884:         }
 1885:         $r->print('<td style="background-color:#999999;" align="center"><font color="#FFFFFF">'.
 1886:                   &valout($sessionval,$sessionvaltype).'&nbsp;'.
 1887:                   '</font></td>');
 1888:     }
 1889:     $r->print('</tr>');
 1890:     $r->print("\n");
 1891:     if (($numlinks) && (ref($reclinks))) {
 1892:         $$reclinks = $numlinks;
 1893:     }
 1894: }
 1895: 
 1896: # Prints a cell for table mode.
 1897: #
 1898: # FIXME: some of these parameter names are uninspired ($which and $value)
 1899: # Also, it would make more sense to pass the display for this cell rather
 1900: # than the full display hash and the key to use.
 1901: #
 1902: # @param {Apache2::RequestRec} $r - the Apache request
 1903: # @param {integer} $which - level
 1904: # @param {string} $defbg - cell background color
 1905: # @param {integer} $result - the most specific level that is defined for that parameter
 1906: # @param {array reference} $outpar - array level -> parameter value (when defined)
 1907: # @param {string} $mprefix - resource id.'&'.part.'_'.parameter name.'&'
 1908: # @param {string} $value - parameter key ('parameter_'.part.'_'.name)
 1909: # @param {array reference} $typeoutpar - array level -> parameter type (when defined)
 1910: # @param {hash reference} $display - parameter key -> full title for the parameter
 1911: # @param {boolean} $noeditgrp - true if no edit is allowed for group level parameters
 1912: # @param {boolean} $readonly -true if editing not allowed.
 1913: # @param {boolean} $ismaplevel - true if level is for a map.
 1914: # @param {string} $extra - extra information to pass to plink.
 1915: sub print_td {
 1916:     my ($r,$which,$defbg,$result,$outpar,$mprefix,$value,$typeoutpar,$display,
 1917:         $noeditgrp,$readonly,$ismaplevel,$extra)=@_;
 1918:     my ($ineffect,$recursive,$currval,$currtype,$currlevel);
 1919:     $ineffect = 0;
 1920:     $currval = $$outpar[$which];
 1921:     $currtype = $$typeoutpar[$which];
 1922:     $currlevel = $which;
 1923:     if (($result) && ($result == $which)) {
 1924:         $ineffect = 1;
 1925:     } 
 1926:     if ($ismaplevel) {
 1927:         if ($mprefix =~ /(hiddenresource|encrypturl)\&/) {
 1928:             if (($result) && ($result == $which)) {
 1929:                 $recursive = 1;
 1930:             }
 1931:         } elsif ($$outpar[$which+1] ne '') {
 1932:             $recursive = 1;
 1933:             $currlevel = $which+1;
 1934:             $currval = $$outpar[$currlevel];
 1935:             $currtype = $$typeoutpar[$currlevel];
 1936:             if (($result) && ($result == $currlevel)) {
 1937:                 $ineffect = 1;
 1938:             }
 1939:         }
 1940:     }
 1941:     $r->print('<td style="background-color:'.($ineffect?'#AAFFAA':$defbg).
 1942:               ';" align="center">');
 1943:     my $nolink = 0;
 1944:     if ($readonly) {
 1945:         $nolink = 1;
 1946:     } else { 
 1947:         if ($which == 14 || $which == 15 || $mprefix =~ /mapalias\&$/) {
 1948:             $nolink = 1;
 1949:         } elsif (($env{'request.course.sec'} ne '') && ($which > 12)) {
 1950:             $nolink = 1;
 1951:         } elsif ($which == 5 || $which ==  6 || $which == 7 || $which == 8) {
 1952:             if ($noeditgrp) {
 1953:                 $nolink = 1;
 1954:             }
 1955:         } elsif ($mprefix =~ /availablestudent\&$/) {
 1956:             $nolink = 1;
 1957:         } elsif ($mprefix =~ /examcode\&$/) {
 1958:             unless ($which == 2) {
 1959:                 $nolink = 1;
 1960:             }
 1961:         }
 1962:     }
 1963:     if ($nolink) {
 1964:         my ($parmname)=((split(/\&/,$mprefix))[1]=~/\_([^\_]+)$/);
 1965:         $r->print(&valout($currval,$currtype));
 1966:     } else {
 1967:         $r->print(&plink($currtype,
 1968:                          $$display{$value},$currval,
 1969:                          $mprefix.$currlevel,'parmform.pres','psub',$recursive,
 1970:                          $extra));
 1971:     }
 1972:     $r->print('</td>'."\n");
 1973: }
 1974: 
 1975: # Returns HTML and other info for the cell added when a user is selected
 1976: # and that user is in several groups. This is the cell with the title "Control by other group".
 1977: #
 1978: # @param {string} $what - parameter part.'.'.parameter name
 1979: # @param {string} $rid - resource id
 1980: # @param {string} $cgroup - group name
 1981: # @param {string} $defbg - cell background color
 1982: # @param {array reference} $usersgroups - list of groups the user belongs to, if any
 1983: # @param {integer} $result - level
 1984: # @param {hash reference} $courseopt - course parameters hash (result of lonnet::get_courseresdata, dump of course's resourcedata.db)
 1985: # @returns {Array} - array (parameter value for the other group, HTML for the cell, HTML with the value, name of the other group, true if recursive)
 1986: sub check_other_groups {
 1987:     my ($what,$rid,$cgroup,$defbg,$usersgroups,$result,$courseopt) = @_;
 1988:     my $courseid = $env{'request.course.id'};
 1989:     my $output;
 1990:     my $symb = &symbcache($rid);
 1991:     my $symbparm=$symb.'.'.$what;
 1992:     my $map=(&Apache::lonnet::decode_symb($symb))[0];
 1993:     my $recurseparm=$map.'___(rec).'.$what; 
 1994:     my $mapparm=$map.'___(all).'.$what;
 1995:     my ($coursereply,$resultitem,$resultgroup,$resultlevel,$resulttype) =
 1996:           &parm_control_group($courseid,$usersgroups,$symbparm,$mapparm,
 1997:                               $recurseparm,$what,$courseopt);
 1998:     my $bgcolor = $defbg;
 1999:     my ($grp_parm,$grp_is_rec);
 2000:     if (($coursereply) && ($cgroup ne $resultgroup)) {
 2001:         my ($parmname) = ($what =~ /\.([^.]+)$/);
 2002:         if ($result > 3) {
 2003:             $bgcolor = '#AAFFAA';
 2004:         }
 2005:         $grp_parm = &valout($coursereply,$resulttype);
 2006:         $output = '<td style="background-color:'.$bgcolor.';" align="center">';
 2007:         if ($resultgroup && $resultlevel) {
 2008:             if ($resultlevel eq 'recursive') {
 2009:                 $resultlevel = 'map/folder';
 2010:                 $grp_is_rec = 1;
 2011:             }
 2012:             $output .= '<small><b>'.$resultgroup.'</b> ('.$resultlevel.'): </small>'.$grp_parm.
 2013:                        ($grp_is_rec?'<span class="LC_parm_recursive">'.&mt('recursive').'</span>':'');
 2014:              
 2015:         } else {
 2016:             $output .= '&nbsp;';
 2017:         }
 2018:         $output .= '</td>';
 2019:     } else {
 2020:         $output .= '<td style="background-color:'.$bgcolor.';">&nbsp;</td>';
 2021:     }
 2022:     return ($coursereply,$output,$grp_parm,$resultgroup,$grp_is_rec);
 2023: }
 2024: 
 2025: # Looks for a group with a defined parameter for given user and parameter.
 2026: # Used by check_other_groups.
 2027: #
 2028: # @param {string} $courseid - the course id
 2029: # @param {array reference} $usersgroups - list of groups the user belongs to, if any
 2030: # @param {string} $symbparm - end of the course parameter hash key for the group resource level
 2031: # @param {string} $mapparm - end of the course parameter hash key for the group map/folder level
 2032: # @param {string} $recurseparm - end of the course parameter hash key for the group recursive level
 2033: # @param {string} $what - parameter part.'.'.parameter name
 2034: # @param {hash reference} $courseopt - course parameters hash
 2035: # @returns {Array} - (parameter value for the group, course parameter hash key for the parameter, name of the group, level name, parameter type)
 2036: sub parm_control_group {
 2037:     my ($courseid,$usersgroups,$symbparm,$mapparm,$recurseparm,$what,$courseopt) = @_;
 2038:     my ($coursereply,$resultitem,$resultgroup,$resultlevel,$resulttype);
 2039:     my $grpfound = 0;
 2040:     my @levels = ($symbparm,$mapparm,$recurseparm,$what);
 2041:     my @levelnames = ('resource','map/folder','recursive','general');
 2042:     foreach my $group (@{$usersgroups}) {
 2043:         if ($grpfound) { last; }
 2044:         for (my $i=0; $i<@levels; $i++) {
 2045:             my $item = $courseid.'.['.$group.'].'.$levels[$i];
 2046:             if (defined($$courseopt{$item})) {
 2047:                 $coursereply = $$courseopt{$item};
 2048:                 $resultitem = $item;
 2049:                 $resultgroup = $group;
 2050:                 $resultlevel = $levelnames[$i];
 2051:                 $resulttype = $$courseopt{$item.'.type'};
 2052:                 $grpfound = 1;
 2053:                 last;
 2054:             }
 2055:         }
 2056:     }
 2057:     return($coursereply,$resultitem,$resultgroup,$resultlevel,$resulttype);
 2058: }
 2059: 
 2060: 
 2061: 
 2062: # Extracts lots of information about all of the the course's resources into a variety of hashes, using lonnavmaps and lonnet::metadata.
 2063: # All the parameters are references and are filled by the sub.
 2064: #
 2065: # @param {array reference} $ids - resource and map ids
 2066: # @param {hash reference} $typep - hash resource/map id -> resource type (file extension)
 2067: # @param {hash reference} $keyp - hash resource/map id -> comma-separated list of parameter keys from lonnet::metadata
 2068: # @param {hash reference} $allparms - hash parameter name -> parameter title
 2069: # @param {hash reference} $allparts - hash parameter part -> part title (a parameter part can be problem part.'_'.response id for response parameters)
 2070: # @param {hash reference} $allmaps - hash map pc -> map src
 2071: # @param {hash reference} $mapp - hash map pc or resource/map id -> enclosing map src
 2072: # @param {hash reference} $symbp - hash map pc or resource/map id -> map src.'___(all)' for a map or resource symb for a resource
 2073: # @param {hash reference} $maptitles - hash map pc or src -> map title (this should really be two separate hashes)
 2074: # @param {hash reference} $uris - hash resource/map id -> resource src
 2075: # @param {hash reference} $keyorder - hash parameter key -> appearance rank for this parameter when looking through every resource and every parameter, starting at 100 (integer)
 2076: # @param {hash reference} $defkeytype - hash parameter name -> parameter type
 2077: sub extractResourceInformation {
 2078:     my $ids = shift;
 2079:     my $typep = shift;
 2080:     my $keyp = shift;
 2081:     my $allparms = shift;
 2082:     my $allparts = shift;
 2083:     my $allmaps = shift;
 2084:     my $mapp = shift;
 2085:     my $symbp = shift;
 2086:     my $maptitles=shift;
 2087:     my $uris=shift;
 2088:     my $keyorder=shift;
 2089:     my $defkeytype=shift;
 2090:     my $pssymb=shift;
 2091: 
 2092:     my $keyordercnt=100;
 2093: 
 2094:     my $navmap = Apache::lonnavmaps::navmap->new();
 2095:     return unless(ref($navmap));
 2096:     my @allres;
 2097:     if ($pssymb ne '') {
 2098:         my $res = $navmap->getBySymb($pssymb);
 2099:         if (ref($res)) {
 2100:             @allres = ($res);
 2101:         }
 2102:     }
 2103:     if (!@allres) { 
 2104:         @allres=$navmap->retrieveResources(undef,undef,1,undef,1);
 2105:     }
 2106:     foreach my $resource (@allres) {
 2107:         my $id=$resource->id();
 2108:         my ($mapid,$resid)=split(/\./,$id);
 2109:         if ($mapid eq '0') { next; }
 2110:         $$ids[$#$ids+1]=$id;
 2111:         my $srcf=$resource->src();
 2112:         $srcf=~/\.(\w+)$/;
 2113:         $$typep{$id}=$1;
 2114:         my $toolsymb;
 2115:         if ($srcf =~ /ext\.tool$/) {
 2116:             $toolsymb = $resource->symb();
 2117:         }
 2118:         $$keyp{$id}='';
 2119:         $$uris{$id}=$srcf;
 2120: 
 2121:         foreach my $key (split(/\,/,&Apache::lonnet::metadata($srcf,'allpossiblekeys',$toolsymb))) {
 2122:             next if ($key!~/^parameter_/);
 2123: 
 2124: # Hidden parameters
 2125:             next if (&Apache::lonnet::metadata($srcf,$key.'.hidden',$toolsymb) eq 'parm');
 2126: #
 2127: # allparms is a hash of parameter names
 2128: #
 2129:             my $name=&Apache::lonnet::metadata($srcf,$key.'.name',$toolsymb);
 2130:             if (!exists($$allparms{$name}) || $$allparms{$name} =~ m/^\s*$/ ) {
 2131:                 my ($display,$parmdis);
 2132:                 $display = &standard_parameter_names($name);
 2133:                 if ($display eq '') {
 2134:                     $display= &Apache::lonnet::metadata($srcf,$key.'.display',$toolsymb);
 2135:                     $parmdis = $display;
 2136:                     $parmdis =~ s/\s*\[Part.*$//g;
 2137:                 } else {
 2138:                     $parmdis = &mt($display);
 2139:                 }
 2140:                 $$allparms{$name}=$parmdis;
 2141:                 if (ref($defkeytype)) {
 2142:                     $$defkeytype{$name}=
 2143:                     &Apache::lonnet::metadata($srcf,$key.'.type',$toolsymb);
 2144:                 }
 2145:             }
 2146: 
 2147: #
 2148: # allparts is a hash of all parts
 2149: #
 2150:             my $part= &Apache::lonnet::metadata($srcf,$key.'.part',$toolsymb);
 2151:             $$allparts{$part} = &mt('Part: [_1]',$part);
 2152: #
 2153: # Remember all keys going with this resource
 2154: #
 2155:             if ($$keyp{$id}) {
 2156:                 $$keyp{$id}.=','.$key;
 2157:             } else {
 2158:                 $$keyp{$id}=$key;
 2159:             }   
 2160: #
 2161: # Put in order
 2162: #
 2163:             unless ($$keyorder{$key}) {
 2164:                 $$keyorder{$key}=$keyordercnt;
 2165:                 $keyordercnt++;
 2166:             }
 2167:         }
 2168: 
 2169: 
 2170:         if (!exists($$mapp{$mapid})) {
 2171:             $$mapp{$id}=
 2172:             &Apache::lonnet::declutter($resource->enclosing_map_src());
 2173:             $$mapp{$mapid}=$$mapp{$id};
 2174:             $$allmaps{$mapid}=$$mapp{$id};
 2175:             if ($mapid eq '1') {
 2176:                 $$maptitles{$mapid}=&mt('Main Content');
 2177:             } else {
 2178:                 $$maptitles{$mapid}=&Apache::lonnet::gettitle($$mapp{$id});
 2179:             }
 2180:             $$maptitles{$$mapp{$id}}=$$maptitles{$mapid};
 2181:             $$symbp{$mapid}=$$mapp{$id}.'___(all)';  # Added in rev. 1.57, but seems not to be used.
 2182:                                                      # Lines 1038 and 1114 which use $symbp{$mapid}
 2183:                                                      # are commented out in rev. 1.57
 2184:         } else {
 2185:             $$mapp{$id} = $$mapp{$mapid};
 2186:         }
 2187:         $$symbp{$id}=&Apache::lonnet::encode_symb($$mapp{$id},$resid,$srcf);
 2188:     }
 2189: }
 2190: 
 2191: sub get_recursive {
 2192:     my ($recurseup,$resdata,$what,$prefix) = @_; 
 2193:     if ((ref($resdata) eq 'HASH') && (ref($recurseup) eq 'ARRAY')) {
 2194:         foreach my $item (@{$recurseup}) {
 2195:             my $norecursechk=$prefix.'.'.$item.'___(all).'.$what;
 2196:             if (defined($resdata->{$norecursechk})) {
 2197:                 if ($what =~ /\.(encrypturl|hiddenresource)$/) {
 2198:                     my $type = $resdata->{$norecursechk.'.type'};
 2199:                     return [$resdata->{$norecursechk},$type,$item];
 2200:                 } else {
 2201:                     last;
 2202:                 }
 2203:             }
 2204:             my $recursechk=$prefix.'.'.$item.'___(rec).'.$what;
 2205:             if (defined($resdata->{$recursechk})) {
 2206:                 my $type = $resdata->{$recursechk.'.type'};
 2207:                 return [$resdata->{$recursechk},$type,$item];
 2208:             }
 2209:         }
 2210:     }
 2211:     return;
 2212: }
 2213: 
 2214: 
 2215: # Tells if a parameter type is a date.
 2216: #
 2217: # @param {string} type - parameter type
 2218: # @returns{boolean} - true if it is a date
 2219: sub isdateparm {
 2220:     my $type=shift;
 2221:     return (($type=~/^date/) && (!($type eq 'date_interval')));
 2222: }
 2223: 
 2224: # Determine if parameter type is specialized string type (i.e.,
 2225: # not just string or string_yesno.  
 2226: 
 2227: sub is_specialstring {
 2228:     my $type=shift;
 2229:     return (($type=~/^string_/) && ($type ne 'string_yesno'));
 2230: }
 2231: 
 2232: # Prints the HTML and Javascript to select parameters, with various shortcuts.
 2233: #
 2234: # @param {Apache2::RequestRec} $r - the Apache request
 2235: sub parmmenu {
 2236:     my ($r)=@_;
 2237:     $r->print(<<ENDSCRIPT);
 2238: <script type="text/javascript">
 2239: // <![CDATA[
 2240:     function checkall(value, checkName) {
 2241: 
 2242:         var li = "_li";
 2243:         var displayOverview = "";
 2244:         
 2245:         if (value == false) {
 2246:             displayOverview = "none"
 2247:         }
 2248: 
 2249:         for (i=0; i<document.forms.parmform.elements.length; i++) {
 2250:             ele = document.forms.parmform.elements[i];
 2251:             if (ele.name == checkName) {
 2252:                 document.forms.parmform.elements[i].checked=value;
 2253:             }
 2254:         }
 2255:     }
 2256: 
 2257:     function checkthis(thisvalue, checkName) {
 2258:         for (i=0; i<document.forms.parmform.elements.length; i++) {
 2259:             ele = document.forms.parmform.elements[i];
 2260:             if (ele.name == checkName) {
 2261:                 if (ele.value == thisvalue) {
 2262:                     document.forms.parmform.elements[i].checked=true;
 2263:                 }
 2264:             }
 2265:         }
 2266:     }
 2267: 
 2268:     function checkdates() {
 2269:         checkthis('duedate','pscat');
 2270:         checkthis('opendate','pscat');
 2271:         checkthis('answerdate','pscat');
 2272:     }
 2273: 
 2274:     function checkdisset() {
 2275:         checkthis('discussend','pscat');
 2276:         checkthis('discusshide','pscat');
 2277:         checkthis('discussvote','pscat');
 2278:     }
 2279: 
 2280:     function checkcontdates() {
 2281:         checkthis('contentopen','pscat');
 2282:         checkthis('contentclose','pscat');
 2283:     }
 2284: 
 2285:     function checkvisi() {
 2286:         checkthis('hiddenresource','pscat');
 2287:         checkthis('encrypturl','pscat');
 2288:         checkthis('problemstatus','pscat');
 2289:         checkthis('contentopen','pscat');
 2290:         checkthis('opendate','pscat');
 2291:     }
 2292: 
 2293:     function checkparts() {
 2294:         checkthis('hiddenparts','pscat');
 2295:         checkthis('display','pscat');
 2296:         checkthis('ordered','pscat');
 2297:     }
 2298: 
 2299:     function checkstandard() {
 2300:         checkall(false,'pscat');
 2301:         checkdates();
 2302:         checkthis('weight','pscat');
 2303:         checkthis('maxtries','pscat');
 2304:         checkthis('type','pscat');
 2305:         checkthis('problemstatus','pscat');
 2306:     }
 2307: 
 2308: // ]]>
 2309: </script>
 2310: ENDSCRIPT
 2311: 
 2312:     $r->print('<hr />');
 2313:     &shortCuts($r);
 2314:     $r->print('<hr />');
 2315: }
 2316: 
 2317: # Returns parameter categories.
 2318: #
 2319: # @returns {hash} - category name -> title in English
 2320: sub categories {
 2321:     return ('time_settings' => 'Time Settings',
 2322:     'grading' => 'Grading',
 2323:     'tries' => 'Tries',
 2324:     'problem_appearance' => 'Problem Appearance',
 2325:     'behaviour_of_input_fields' => 'Behaviour of Input Fields',
 2326:     'hiding' => 'Hiding',
 2327:     'high_level_randomization' => 'High Level Randomization',
 2328:     'slots' => 'Slots',
 2329:     'file_submission' => 'File Submission',
 2330:     'misc' => 'Miscellaneous' ); 
 2331: }
 2332: 
 2333: # Returns the category for each parameter.
 2334: #
 2335: # @returns {hash} - parameter name -> category name
 2336: sub lookUpTableParameter {
 2337:  
 2338:     return ( 
 2339:         'opendate' => 'time_settings',
 2340:         'duedate' => 'time_settings',
 2341:         'answerdate' => 'time_settings',
 2342:         'interval' => 'time_settings',
 2343:         'contentopen' => 'time_settings',
 2344:         'contentclose' => 'time_settings',
 2345:         'discussend' => 'time_settings',
 2346:         'printstartdate' => 'time_settings',
 2347:         'printenddate' => 'time_settings',
 2348:         'weight' => 'grading',
 2349:         'handgrade' => 'grading',
 2350:         'maxtries' => 'tries',
 2351:         'hinttries' => 'tries',
 2352:         'randomizeontries' => 'tries',
 2353:         'type' => 'problem_appearance',
 2354:         'problemstatus' => 'problem_appearance',
 2355:         'display' => 'problem_appearance',
 2356:         'ordered' => 'problem_appearance',
 2357:         'numbubbles' => 'problem_appearance',
 2358:         'tol' => 'behaviour_of_input_fields',
 2359:         'sig' => 'behaviour_of_input_fields',
 2360:         'turnoffunit' => 'behaviour_of_input_fields',
 2361:         'hiddenresource' => 'hiding',
 2362:         'hiddenparts' => 'hiding',
 2363:         'discusshide' => 'hiding',
 2364:         'buttonshide' => 'hiding',
 2365:         'turnoffeditor' => 'hiding',
 2366:         'encrypturl' => 'hiding',
 2367:         'deeplink' => 'hiding',
 2368:         'randomorder' => 'high_level_randomization',
 2369:         'randompick' => 'high_level_randomization',
 2370:         'available' => 'slots',
 2371:         'useslots' => 'slots',
 2372:         'availablestudent' => 'slots',
 2373:         'uploadedfiletypes' => 'file_submission',
 2374:         'maxfilesize' => 'file_submission',
 2375:         'cssfile' => 'misc',
 2376:         'mapalias' => 'misc',
 2377:         'acc' => 'misc',
 2378:         'maxcollaborators' => 'misc',
 2379:         'scoreformat' => 'misc',
 2380:         'lenient' => 'grading',
 2381:         'retrypartial' => 'tries',
 2382:         'discussvote'  => 'misc',
 2383:         'examcode' => 'high_level_randomization',
 2384:     );
 2385: }
 2386: 
 2387: # Adds the given parameter name to an array of arrays listing all parameters for each category.
 2388: #
 2389: # @param {string} $name - parameter name
 2390: # @param {array reference} $catList - array reference category name -> array reference of parameter names
 2391: sub whatIsMyCategory {
 2392:     my $name = shift;
 2393:     my $catList = shift;
 2394:     my @list;
 2395:     my %lookUpList = &lookUpTableParameter; #Initilize the lookupList
 2396:     my $cat = $lookUpList{$name};
 2397:     if (defined($cat)) {
 2398:         if (!defined($$catList{$cat})){
 2399:             push @list, ($name);
 2400:             $$catList{$cat} = \@list;
 2401:         } else {
 2402:             push @{${$catList}{$cat}}, ($name);     
 2403:         }
 2404:     } else {
 2405:         if (!defined($$catList{'misc'})){
 2406:             push @list, ($name);
 2407:             $$catList{'misc'} = \@list;
 2408:         } else {
 2409:             push @{${$catList}{'misc'}}, ($name);     
 2410:         }
 2411:     }        
 2412: }
 2413: 
 2414: # Sorts parameter names based on appearance order.
 2415: #
 2416: # @param {array reference} name - array reference of parameter names
 2417: # @param {hash reference} $keyorder - hash parameter key -> appearance rank
 2418: # @returns {Array} - array of parameter names
 2419: sub keysindisplayorderCategory {
 2420:     my ($name,$keyorder)=@_;
 2421:     return sort {
 2422:         $$keyorder{'parameter_0_'.$a} <=> $$keyorder{'parameter_0_'.$b}; 
 2423:     } ( @{$name});
 2424: }
 2425: 
 2426: # Returns a hash category name -> order, starting at 1 (integer)
 2427: #
 2428: # @returns {hash}
 2429: sub category_order {
 2430:     return (
 2431:         'time_settings' => 1,
 2432:         'grading' => 2,
 2433:         'tries' => 3,
 2434:         'problem_appearance' => 4,
 2435:         'hiding' => 5,
 2436:         'behaviour_of_input_fields' => 6,
 2437:         'high_level_randomization'  => 7,
 2438:         'slots' => 8,
 2439:         'file_submission' => 9,
 2440:         'misc' => 10
 2441:     );
 2442: 
 2443: }
 2444: 
 2445: # Prints HTML to let the user select parameters, from a list of all parameters organized by category.
 2446: #
 2447: # @param {Apache2::RequestRec} $r - the Apache request
 2448: # @param {hash reference} $allparms - hash parameter name -> parameter title
 2449: # @param {array reference} $pscat - list of selected parameter names
 2450: # @param {hash reference} $keyorder - hash parameter key -> appearance rank
 2451: sub parmboxes {
 2452:     my ($r,$allparms,$pscat,$keyorder)=@_;
 2453:     my %categories = &categories();
 2454:     my %category_order = &category_order();
 2455:     my %categoryList = (
 2456:         'time_settings' => [],
 2457:         'grading' => [],
 2458:         'tries' => [],
 2459:         'problem_appearance' => [],
 2460:         'behaviour_of_input_fields' => [],
 2461:         'hiding' => [],
 2462:         'high_level_randomization' => [],
 2463:         'slots' => [],
 2464:         'file_submission' => [],
 2465:         'misc' => [],
 2466:     );
 2467: 
 2468:     foreach my $tempparameter (keys(%$allparms)) {
 2469:         &whatIsMyCategory($tempparameter, \%categoryList);
 2470:     }
 2471:     #part to print the parm-list
 2472:     foreach my $key (sort { $category_order{$a} <=> $category_order{$b} } keys(%categoryList)) {
 2473:         next if (@{$categoryList{$key}} == 0);
 2474:         next if ($key eq '');
 2475:         $r->print('<div class="LC_Box LC_400Box">'
 2476:                  .'<h4 class="LC_hcell">'.&mt($categories{$key}).'</h4>'."\n");
 2477:         foreach my $tempkey (&keysindisplayorderCategory($categoryList{$key},$keyorder)) {
 2478:             next if ($tempkey eq '');
 2479:             $r->print('<span class="LC_nobreak">'
 2480:                      .'<label><input type="checkbox" name="pscat" '
 2481:                      .'value="'.$tempkey.'" ');
 2482:             if ($$pscat[0] eq "all" || grep $_ eq $tempkey, @{$pscat}) {
 2483:                 $r->print( ' checked="checked"');
 2484:             }
 2485:             $r->print(' />'.($$allparms{$tempkey}=~/\S/ ? $$allparms{$tempkey}
 2486:                                                       : $tempkey)
 2487:                      .'</label></span><br />'."\n");
 2488:         }
 2489:         $r->print('</div>');
 2490:     }
 2491:     $r->print("\n");
 2492: }
 2493: 
 2494: # Prints HTML with shortcuts to select groups of parameters in one click, or deselect all.
 2495: #
 2496: # @param {Apache2::RequestRec} $r - the Apache request
 2497: sub shortCuts {
 2498:     my ($r)=@_;
 2499: 
 2500:     # Parameter Selection
 2501:     $r->print(
 2502:         &Apache::lonhtmlcommon::start_funclist(&mt('Parameter Selection'))
 2503:        .&Apache::lonhtmlcommon::add_item_funclist(
 2504:             '<a href="javascript:checkall(true, \'pscat\')">'.&mt('Select All').'</a>')
 2505:        .&Apache::lonhtmlcommon::add_item_funclist(
 2506:             '<a href="javascript:checkstandard()">'.&mt('Select Common Only').'</a>')
 2507:        .&Apache::lonhtmlcommon::add_item_funclist(
 2508:             '<a href="javascript:checkall(false, \'pscat\')">'.&mt('Unselect All').'</a>')
 2509:        .&Apache::lonhtmlcommon::end_funclist()
 2510:     );
 2511: 
 2512:     # Add Selection for...
 2513:     $r->print(
 2514:         &Apache::lonhtmlcommon::start_funclist(&mt('Add Selection for...'))
 2515:        .&Apache::lonhtmlcommon::add_item_funclist(
 2516:             '<a href="javascript:checkdates()">'.&mt('Problem Dates').'</a>')
 2517:        .&Apache::lonhtmlcommon::add_item_funclist(
 2518:             '<a href="javascript:checkcontdates()">'.&mt('Content Dates').'</a>')
 2519:        .&Apache::lonhtmlcommon::add_item_funclist(
 2520:             '<a href="javascript:checkdisset()">'.&mt('Discussion Settings').'</a>')
 2521:        .&Apache::lonhtmlcommon::add_item_funclist(
 2522:             '<a href="javascript:checkvisi()">'.&mt('Visibilities').'</a>')
 2523:        .&Apache::lonhtmlcommon::add_item_funclist(
 2524:             '<a href="javascript:checkparts()">'.&mt('Part Parameters').'</a>')
 2525:        .&Apache::lonhtmlcommon::end_funclist()
 2526:     );
 2527: }
 2528: 
 2529: # Prints HTML to select parts to view (except for the title).
 2530: # Used by table and overview modes.
 2531: #
 2532: # @param {Apache2::RequestRec} $r - the Apache request
 2533: # @param {hash reference} $allparts - hash parameter part -> part title
 2534: # @param {array reference} $psprt - list of selected parameter parts
 2535: sub partmenu {
 2536:     my ($r,$allparts,$psprt)=@_;
 2537:     my $selsize = 1+scalar(keys(%{$allparts}));
 2538:     if ($selsize > 8) {
 2539:         $selsize = 8;
 2540:     }
 2541: 
 2542:     $r->print('<select multiple="multiple" name="psprt" size="'.$selsize.'">');
 2543:     $r->print('<option value="all"');
 2544:     $r->print(' selected="selected"') unless (@{$psprt}); # useless, the array is never empty
 2545:     $r->print('>'.&mt('All Parts').'</option>');
 2546:     my %temphash=();
 2547:     foreach (@{$psprt}) { $temphash{$_}=1; }
 2548:     foreach my $tempkey (sort {
 2549:                 if ($a==$b) { return ($a cmp $b) } else { return ($a <=> $b); }
 2550:             } keys(%{$allparts})) {
 2551:         unless ($tempkey =~ /\./) {
 2552:             $r->print('<option value="'.$tempkey.'"');
 2553:             if ($$psprt[0] eq "all" ||  $temphash{$tempkey}) {
 2554:                 $r->print(' selected="selected"');
 2555:             }
 2556:             $r->print('>'.$$allparts{$tempkey}.'</option>');
 2557:         }
 2558:     }
 2559:     $r->print('</select>');
 2560: }
 2561: 
 2562: # Prints HTML to select a user and/or a group.
 2563: # Used by table mode.
 2564: #
 2565: # @param {Apache2::RequestRec} $r - the Apache request
 2566: # @param {string} $uname - selected user name
 2567: # @param {string} $id - selected Student/Employee ID
 2568: # @param {string} $udom - selected user domain
 2569: # @param {string} $csec - selected section name
 2570: # @param {string} $cgroup - selected group name
 2571: # @param {string} $parmlev - parameter level (Resource:'full', Map:'map', Course:'general')
 2572: # @param {array reference} $usersgroups - list of groups the user belongs to, if any
 2573: # @param {string} $pssymb - resource symb (when a single resource is selected)
 2574: sub usermenu {
 2575:     my ($r,$uname,$id,$udom,$csec,$cgroup,$parmlev,$usersgroups,$pssymb)=@_;
 2576:     my $chooseopt=&Apache::loncommon::select_dom_form($udom,'udom').' '.
 2577:                   &Apache::loncommon::selectstudent_link('parmform','uname','udom','condition').
 2578:                   &Apache::lonhtmlcommon::scripttag(<<ENDJS);
 2579: function setCourseadv(form,caller) {
 2580:     if (caller.value == 'st') {
 2581:         form.courseadv.value = 'none';
 2582:     } else {
 2583:         form.courseadv.value = '';
 2584:     }
 2585:     return;
 2586: }
 2587: ENDJS
 2588: 
 2589:     my (%chkroles,$stuonly,$courseadv);
 2590:     if ($env{'form.userroles'} eq 'any') {
 2591:         $chkroles{'any'} = ' checked="checked"';
 2592:     } else {
 2593:         $chkroles{'st'} = ' checked="checked"';
 2594:         $courseadv = 'none';
 2595:     }
 2596:     my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
 2597:     if ($crstype eq 'Community') {
 2598:         $stuonly = &mt('member only');
 2599:     } else {
 2600:         $stuonly = &mt('student only');
 2601:     }
 2602:     $chooseopt .= '<br /><span class="LC_cusr_subheading">'.
 2603:                   &mt("User's role").':&nbsp;'.
 2604:                   '<label><input type="radio" name="userroles" value="st"'.$chkroles{'st'}.' onclick="setCourseadv(this.form,this);" />'.
 2605:                   $stuonly.'</label>&nbsp;&nbsp;'.
 2606:                   '<label><input type="radio" name="userroles" value="any"'.$chkroles{'any'}.' onclick="setCourseadv(this.form,this);" />'.
 2607:                   &mt('any role').'</label><input type="hidden" id="courseadv" name="courseadv" value="'.$courseadv.'" /></span>';
 2608:     my $sections='';
 2609:     my %sectionhash = &Apache::loncommon::get_sections();
 2610: 
 2611:     my $groups;
 2612:     my %grouphash;
 2613:     if (($pssymb) || &Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
 2614:         %grouphash = &Apache::longroup::coursegroups();
 2615:     } elsif ($env{'request.course.groups'} ne '') {
 2616:         map { $grouphash{$_} = 1; } split(/:/,$env{'request.course.groups'});
 2617:     }
 2618: 
 2619:     my $g_s_header='';
 2620:     my $g_s_footer='';
 2621: 
 2622:     my $currsec = $env{'request.course.sec'};
 2623:     if ($currsec) {
 2624:         $sections=&mt('Section:').' '.$currsec;
 2625:         if (%grouphash) {
 2626:             $sections .= ';'.('&nbsp;' x2);
 2627:         }
 2628:     } elsif (%sectionhash && $currsec eq '') {
 2629:         $sections=&mt('Section:').' <select name="csec"';
 2630:         if (%grouphash && $parmlev ne 'full') {
 2631:             $sections .= qq| onchange="group_or_section('csec')" |;
 2632:         }
 2633:         $sections .= '>';
 2634:     foreach my $section ('',sort(keys(%sectionhash))) {
 2635:         $sections.='<option value="'.$section.'" '.
 2636:         ($section eq $csec?'selected="selected"':'').'>'.$section.
 2637:                                                               '</option>';
 2638:         }
 2639:         $sections.='</select>';
 2640:     }
 2641: 
 2642:     if (%sectionhash && %grouphash && $parmlev ne 'full' && $currsec eq '') {
 2643:         $sections .= '&nbsp;'.&mt('or').'&nbsp;';
 2644:         $sections .= qq|
 2645: <script type="text/javascript">
 2646: // <![CDATA[
 2647: function group_or_section(caller) {
 2648:    if (caller == "cgroup") {
 2649:        if (document.parmform.cgroup.selectedIndex != 0) {
 2650:            document.parmform.csec.selectedIndex = 0;
 2651:        }
 2652:    } else {
 2653:        if (document.parmform.csec.selectedIndex != 0) {
 2654:            document.parmform.cgroup.selectedIndex = 0;
 2655:        }
 2656:    }
 2657: }
 2658: // ]]>
 2659: </script>
 2660: |;
 2661:     } else {
 2662:         $sections .= qq|
 2663: <script type="text/javascript">
 2664: // <![CDATA[
 2665: function group_or_section(caller) {
 2666:     return;
 2667: }
 2668: // ]]>
 2669: </script>
 2670: |;
 2671:     }
 2672: 
 2673:     if (%grouphash) {
 2674:         $groups=&mt('Group').': <select name="cgroup"';
 2675:         if (%sectionhash && $env{'form.action'} eq 'settable' && $currsec eq '') {
 2676:             $groups .= qq| onchange="group_or_section('cgroup')" |;
 2677:         }
 2678:         $groups .= '>';
 2679:         foreach my $grp ('',sort(keys(%grouphash))) {
 2680:             $groups.='<option value="'.$grp.'" ';
 2681:             if ($grp eq $cgroup) {
 2682:                 unless ((defined($uname)) && ($grp eq '')) {
 2683:                     $groups .=  'selected="selected" ';
 2684:                 }
 2685:             } elsif (!defined($cgroup)) {
 2686:                 if (@{$usersgroups} == 1) {
 2687:                     if ($grp eq $$usersgroups[0]) {
 2688:                         $groups .=  'selected="selected" ';
 2689:                     }
 2690:                 }
 2691:             }
 2692:             $groups .= '>'.$grp.'</option>';
 2693:         }
 2694:         $groups.='</select>';
 2695:     }
 2696: 
 2697:     if (%sectionhash || %grouphash) {
 2698:         $r->print(&Apache::lonhtmlcommon::row_title(&mt('Group/Section')));
 2699:         $r->print($sections.$groups);
 2700:         $r->print(&Apache::lonhtmlcommon::row_closure());
 2701:     } else {
 2702:         $r->print($sections); 
 2703:     }
 2704: 
 2705:     $r->print(&Apache::lonhtmlcommon::row_title(&mt('User')));
 2706:     $r->print(&mt('For User [_1] or Student/Employee ID [_2] at Domain [_3]'
 2707:                  ,'<input type="text" value="'.$uname.'" size="12" name="uname" />'
 2708:                  ,'<input type="text" value="'.$id.'" size="12" name="id" /> '
 2709:                  ,$chooseopt));
 2710: }
 2711: 
 2712: # Prints HTML to select parameters from a list of all parameters.
 2713: # Uses parmmenu and parmboxes.
 2714: # Used by table and overview modes.
 2715: #
 2716: # @param {Apache2::RequestRec} $r - the Apache request
 2717: # @param {hash reference} $allparms - hash parameter name -> parameter title
 2718: # @param {array reference} $pscat - list of selected parameter names
 2719: # @param {hash reference} $keyorder - hash parameter key -> appearance rank
 2720: # @param {string} [$divid] - name used to give an id to the HTML element for the scroll box
 2721: sub displaymenu {
 2722:     my ($r,$allparms,$pscat,$keyorder,$divid)=@_;
 2723: 
 2724:     $r->print(&Apache::lonhtmlcommon::start_pick_box());
 2725:     $r->print(&Apache::lonhtmlcommon::row_title(&mt('Select Parameters to View')));
 2726: 
 2727:     &parmmenu($r);
 2728:     $r->print(&Apache::loncommon::start_scrollbox('480px','440px','200px',$divid));
 2729:     &parmboxes($r,$allparms,$pscat,$keyorder);
 2730:     $r->print(&Apache::loncommon::end_scrollbox());
 2731: 
 2732:     $r->print(&Apache::lonhtmlcommon::row_closure(1));
 2733:     $r->print(&Apache::lonhtmlcommon::end_pick_box());
 2734:  
 2735: }
 2736: 
 2737: # Prints HTML to select a map.
 2738: # Used by table mode and overview mode.
 2739: #
 2740: # @param {Apache2::RequestRec} $r - the Apache request
 2741: # @param {hash reference} $allmaps - hash map pc -> map src
 2742: # @param {string} $pschp - selected map pc, or 'all'
 2743: # @param {hash reference} $maptitles - hash map id or src -> map title
 2744: # @param {hash reference} $symbp - hash map pc or resource/map id -> map src.'___(all)' or resource symb
 2745: sub mapmenu {
 2746:     my ($r,$allmaps,$pschp,$maptitles,$symbp)=@_;
 2747:     my %allmaps_inverted = reverse %$allmaps;
 2748:     my $navmap = Apache::lonnavmaps::navmap->new();
 2749:     my $tree=[];
 2750:     my $treeinfo={};
 2751:     if (defined($navmap)) {
 2752:         my $it=$navmap->getIterator(undef,undef,undef,1,1,undef);
 2753:         my $curRes;
 2754:         my $depth = 0;
 2755:         my %parent = ();
 2756:         my $startcount = 5;
 2757:         my $lastcontainer = $startcount;
 2758: # preparing what is to show ...
 2759:         while ($curRes = $it->next()) {
 2760:             if ($curRes == $it->BEGIN_MAP()) {
 2761:                 $depth++;
 2762:                 $parent{$depth}= $lastcontainer;
 2763:             }
 2764:             if ($curRes == $it->END_MAP()) {
 2765:                 $depth--;
 2766:                 $lastcontainer = $parent{$depth};
 2767:             }
 2768:             if (ref($curRes)) {
 2769:                 my $symb = $curRes->symb();
 2770:                 my $ressymb = $symb;
 2771:                 if (($curRes->is_sequence()) || ($curRes->is_page())) {
 2772:                     my $type = 'sequence';
 2773:                     if ($curRes->is_page()) {
 2774:                         $type = 'page';
 2775:                     }
 2776:                     my $id= $curRes->id();
 2777:                     my $srcf = $curRes->src();
 2778:                     my $resource_name = &Apache::lonnet::gettitle($srcf);
 2779:                     if(!exists($treeinfo->{$id})) {
 2780:                         push(@$tree,$id);
 2781:                         my $enclosing_map_folder = &Apache::lonnet::declutter($curRes->enclosing_map_src());        
 2782:                         $treeinfo->{$id} = {
 2783:                                     depth => $depth,
 2784:                                     type  => $type,
 2785:                                     name  => $resource_name,
 2786:                                     enclosing_map_folder => $enclosing_map_folder,
 2787:                                     };
 2788:                     }
 2789:                 }
 2790:             }
 2791:         }
 2792:     }
 2793: # Show it ...    
 2794:     $r->print(&Apache::lonhtmlcommon::row_title(&mt('Select Enclosing Map or Folder'),'','',' id="mapmenu"'));
 2795:     if ((ref($tree) eq 'ARRAY') && (ref($treeinfo) eq 'HASH')) {
 2796:         my $icon = '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" />';
 2797:         my $whitespace =
 2798:             '<img src="'
 2799:            .&Apache::loncommon::lonhttpdurl('/adm/lonIcons/whitespace_21.gif')
 2800:            .'" alt="" />';
 2801: 
 2802:         # Info about selectable folders/maps
 2803:         $r->print(
 2804:             '<div class="LC_info">'
 2805:            .&mt('You can only select maps and folders which have modifiable settings.')
 2806:            .' '.&Apache::loncommon::help_open_topic('Parameter_Set_Folder') 
 2807:            .'</div>'
 2808:         );
 2809: 
 2810:         $r->print(&Apache::loncommon::start_scrollbox('700px','680px','400px','mapmenuscroll'));
 2811:         $r->print(&Apache::loncommon::start_data_table(undef,'mapmenuinner'));
 2812: 
 2813:         # Display row: "All Maps or Folders"
 2814:         $r->print(
 2815:             &Apache::loncommon::start_data_table_row(undef,'picklevel')
 2816:            .'<td>'
 2817:            .'<label>'
 2818:            .'<input type="radio" name="pschp"'
 2819:         );
 2820:         $r->print(' checked="checked"') if ($pschp eq 'all' || !$pschp);
 2821:         $r->print(
 2822:             ' value="all" />&nbsp;'.$icon.'&nbsp;'
 2823:            .&mt('All Maps or Folders')
 2824:            .'</label>'
 2825:            .'<hr /></td>'
 2826:            .&Apache::loncommon::end_data_table_row()
 2827:         );
 2828: 
 2829:         # Display row: "Main Content"
 2830:         if (exists($$allmaps{1})) {
 2831:             $r->print(
 2832:                 &Apache::loncommon::start_data_table_row()
 2833:                .'<td>'
 2834:                .'<label>'
 2835:                .'<input type="radio" name="pschp" value="1"'
 2836:             );
 2837:             $r->print(' checked="checked"') if ($pschp eq '1');
 2838:             $r->print(
 2839:                 '/>&nbsp;'.$icon.'&nbsp;'
 2840:                .$$maptitles{1}
 2841:                .($$allmaps{1} !~/^uploaded/?' ['.$$allmaps{1}.']':'')
 2842:                .'</label>'
 2843:                .'</td>'
 2844:                .&Apache::loncommon::end_data_table_row()
 2845:             );
 2846:         }
 2847: 
 2848:         # Display rows for all course maps and folders
 2849:         foreach my $id (@{$tree}) {
 2850:             my ($mapid,$resid)=split(/\./,$id);
 2851:             # Indentation
 2852:             my $depth = $treeinfo->{$id}->{'depth'};
 2853:             my $indent;
 2854:             for (my $i = 0; $i < $depth; $i++) {
 2855:                 $indent.= $whitespace;
 2856:             }
 2857:             $icon =  '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" />';
 2858:             if ($treeinfo->{$id}->{'type'} eq 'page') {
 2859:                 $icon = '<img src="/adm/lonIcons/navmap.page.open.gif" alt="" />';
 2860:             }
 2861:             my $symb_name = $$symbp{$id};
 2862:             my ($front, $tail) = split (/___${resid}___/, $symb_name);
 2863:             $symb_name = $tail;
 2864:             $r->print(
 2865:                 &Apache::loncommon::start_data_table_row()
 2866:                .'<td>'
 2867:                .'<label>'
 2868:             );
 2869:             # Only offer radio button for folders/maps which can be parameterized
 2870:             if ($allmaps_inverted{$symb_name}) {
 2871:                 $r->print(
 2872:                     '<input type ="radio" name="pschp"'
 2873:                    .' value="'.$allmaps_inverted{$symb_name}.'"'
 2874:                 );
 2875:                 $r->print(' checked="checked"') if ($allmaps_inverted{$symb_name} eq $pschp);
 2876:                 $r->print('/>');
 2877:             } else {
 2878:                 $r->print($whitespace);
 2879:             }
 2880:             $r->print(
 2881:                 $indent.$icon.'&nbsp;'
 2882:                .$treeinfo->{$id}->{name}
 2883:                .($$allmaps{$mapid}!~/^uploaded/?' ['.$$allmaps{$mapid}.']':'')
 2884:                .'</label>'
 2885:                .'</td>'
 2886:                .&Apache::loncommon::end_data_table_row()
 2887:             );
 2888:         }
 2889: 
 2890:         $r->print(&Apache::loncommon::end_data_table().
 2891:                   '<br style="line-height:2px;" />'.
 2892:                   &Apache::loncommon::end_scrollbox());
 2893:     }
 2894: }
 2895: 
 2896: # Prints HTML to select the parameter level (resource, map/folder or course).
 2897: # Used by table and overview modes.
 2898: #
 2899: # @param {Apache2::RequestRec} $r - the Apache request
 2900: # @param {hash reference} $alllevs - all parameter levels, hash English title -> value
 2901: # @param {string} $parmlev - selected level value (full|map|general), or ''
 2902: sub levelmenu {
 2903:     my ($r,$alllevs,$parmlev)=@_;
 2904: 
 2905:     $r->print(&Apache::lonhtmlcommon::row_title(&mt('Select Parameter Level').
 2906:                                                 &Apache::loncommon::help_open_topic('Course_Parameter_Levels')));
 2907:     $r->print('<select id="parmlev" name="parmlev" onchange="showHide_courseContent()">');
 2908:     foreach my $lev (reverse(sort(keys(%{$alllevs})))) {
 2909:         $r->print('<option value="'.$$alllevs{$lev}.'"');
 2910:         if ($parmlev eq $$alllevs{$lev}) {
 2911:             $r->print(' selected="selected"');
 2912:         }
 2913:         $r->print('>'.&mt($lev).'</option>');
 2914:     }
 2915:     $r->print("</select>");
 2916: }
 2917: 
 2918: 
 2919: # Returns HTML to select a section (with a select HTML element).
 2920: # Used by overview mode.
 2921: #
 2922: # @param {array reference} $selectedsections - list of selected section ids
 2923: # @returns {string}
 2924: sub sectionmenu {
 2925:     my ($selectedsections)=@_;
 2926:     my %sectionhash = &Apache::loncommon::get_sections();
 2927:     return '' if (!%sectionhash);
 2928: 
 2929:     my (@possibles,$disabled);
 2930:     if ($env{'request.course.sec'} ne '') {
 2931:         @possibles = ($env{'request.course.sec'});
 2932:         $selectedsections = [$env{'request.course.sec'}];
 2933:         $disabled = ' disabled="disabled"';
 2934:     } else {
 2935:         @possibles = ('all',sort(keys(%sectionhash)));
 2936:     }
 2937:     my $output = '<select name="Section" multiple="multiple" size="8"'.$disabled.'>';
 2938:     foreach my $s (@possibles) {
 2939:         $output .= '    <option value="'.$s.'"';
 2940:         if ((@{$selectedsections}) && (grep(/^\Q$s\E$/,@{$selectedsections}))) {  
 2941:             $output .= ' selected="selected"';
 2942:         }
 2943:         $output .= '>'."$s</option>\n";
 2944:     }
 2945:     $output .= "</select>\n";
 2946:     return $output;
 2947: }
 2948: 
 2949: # Returns HTML to select a group (with a select HTML element).
 2950: # Used by overview mode.
 2951: #
 2952: # @param {array reference} $selectedgroups - list of selected group names
 2953: # @returns {string}
 2954: sub groupmenu {
 2955:     my ($selectedgroups)=@_;
 2956:     my %grouphash;
 2957:     if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
 2958:         %grouphash = &Apache::longroup::coursegroups();
 2959:     } elsif ($env{'request.course.groups'} ne '') {
 2960:          map { $grouphash{$_} = 1; } split(/:/,$env{'request.course.groups'});
 2961:     }
 2962:     return '' if (!%grouphash);
 2963: 
 2964:     my $output = '<select name="Group" multiple="multiple" size="8">';
 2965:     foreach my $group (sort(keys(%grouphash))) {
 2966:         $output .= '    <option value="'.$group.'"';
 2967:         if ((@{$selectedgroups}) && (grep(/^\Q$group\E$/,\@{$selectedgroups}))) {
 2968:             $output .=  ' selected="selected"';
 2969:         }
 2970:         $output .= '>'."$group</option>\n";
 2971:     }
 2972:     $output .= "</select>\n";
 2973:     return $output;
 2974: }
 2975: 
 2976: # Returns an array with the given parameter split by comma.
 2977: # Used by assessparms (table mode).
 2978: #
 2979: # @param {string} $keyp - the string to split
 2980: # @returns {Array<string>}
 2981: sub keysplit {
 2982:     my $keyp=shift;
 2983:     return (split(/\,/,$keyp));
 2984: }
 2985: 
 2986: # Returns the keys in $name, sorted using $keyorder.
 2987: # Parameters are sorted by key, which means they are sorted by part first, then by name.
 2988: # Used by assessparms (table mode) for resource level.
 2989: #
 2990: # @param {hash reference} $name - parameter key -> parameter name
 2991: # @param {hash reference} $keyorder - hash parameter key -> appearance rank
 2992: # @returns {Array<string>}
 2993: sub keysinorder {
 2994:     my ($name,$keyorder)=@_;
 2995:     return sort {
 2996:         $$keyorder{$a} <=> $$keyorder{$b};
 2997:     } (keys(%{$name}));
 2998: }
 2999: 
 3000: # Returns the keys in $name, sorted using $keyorder to sort parameters by name first, then by part.
 3001: # Used by assessparms (table mode) for map and general levels.
 3002: #
 3003: # @param {hash reference} $name - parameter key -> parameter name
 3004: # @param {hash reference} $keyorder - hash parameter key -> appearance rank
 3005: # @returns {Array<string>}
 3006: sub keysinorder_bytype {
 3007:     my ($name,$keyorder)=@_;
 3008:     return sort {
 3009:         my $ta=(split('_',$a))[-1]; # parameter name
 3010:         my $tb=(split('_',$b))[-1];
 3011:         if ($$keyorder{'parameter_0_'.$ta} == $$keyorder{'parameter_0_'.$tb}) {
 3012:             return ($a cmp $b);
 3013:         }
 3014:         $$keyorder{'parameter_0_'.$ta} <=> $$keyorder{'parameter_0_'.$tb};
 3015:     } (keys(%{$name}));
 3016: }
 3017: 
 3018: # Returns the keys in $name, sorted using $keyorder to sort parameters by name.
 3019: # Used by defaultsetter (parameter settings default actions).
 3020: #
 3021: # @param {hash reference} $name - hash parameter name -> parameter title
 3022: # @param {hash reference} $keyorder - hash parameter key -> appearance rank
 3023: # @returns {Array<string>}
 3024: sub keysindisplayorder {
 3025:     my ($name,$keyorder)=@_;
 3026:     return sort {
 3027:         $$keyorder{'parameter_0_'.$a} <=> $$keyorder{'parameter_0_'.$b};
 3028:     } (keys(%{$name}));
 3029: }
 3030: 
 3031: # Prints HTML with a choice to sort results by realm or student first.
 3032: # Used by overview mode.
 3033: #
 3034: # @param {Apache2::RequestRec} $r - the Apache request
 3035: # @param {string} $sortorder - realmstudent|studentrealm
 3036: sub sortmenu {
 3037:     my ($r,$sortorder)=@_;
 3038:     $r->print('<br /><label><input type="radio" name="sortorder" value="realmstudent"');
 3039:     if ($sortorder eq 'realmstudent') {
 3040:        $r->print(' checked="checked"');
 3041:     }
 3042:     $r->print(' />'.&mt('Sort by realm first, then student (group/section)'));
 3043:     $r->print('</label><br /><label><input type="radio" name="sortorder" value="studentrealm"');
 3044:     if ($sortorder eq 'studentrealm') {
 3045:        $r->print(' checked="checked"');
 3046:     }
 3047:     $r->print(' />'.&mt('Sort by student (group/section) first, then realm').
 3048:           '</label>');
 3049: }
 3050: 
 3051: # Returns a hash parameter key -> order (integer) giving the order for some parameters.
 3052: #
 3053: # @returns {hash}
 3054: sub standardkeyorder {
 3055:     return ('parameter_0_opendate' => 1,
 3056:         'parameter_0_duedate' => 2,
 3057:         'parameter_0_answerdate' => 3,
 3058:         'parameter_0_interval' => 4,
 3059:         'parameter_0_weight' => 5,
 3060:         'parameter_0_maxtries' => 6,
 3061:         'parameter_0_hinttries' => 7,
 3062:         'parameter_0_contentopen' => 8,
 3063:         'parameter_0_contentclose' => 9,
 3064:         'parameter_0_type' => 10,
 3065:         'parameter_0_problemstatus' => 11,
 3066:         'parameter_0_hiddenresource' => 12,
 3067:         'parameter_0_hiddenparts' => 13,
 3068:         'parameter_0_display' => 14,
 3069:         'parameter_0_ordered' => 15,
 3070:         'parameter_0_tol' => 16,
 3071:         'parameter_0_sig' => 17,
 3072:         'parameter_0_turnoffunit' => 18,
 3073:         'parameter_0_discussend' => 19,
 3074:         'parameter_0_discusshide' => 20,
 3075:         'parameter_0_discussvote' => 21,
 3076:         'parameter_0_printstartdate'  =>  22,
 3077:         'parameter_0_printenddate' =>  23);
 3078: }
 3079: 
 3080: 
 3081: # Table mode UI.
 3082: # If nothing is selected, prints HTML forms to select resources, parts, parameters, user, group and section.
 3083: # Otherwise, prints the parameter table, with a link to change the selection unless a single resource is selected.
 3084: #
 3085: # Parameters used from the request:
 3086: # action - handler action (see handler), usermenu is checking for value 'settable'
 3087: # cgroup - selected group
 3088: # command - 'set': direct access to table mode for a resource
 3089: # csec - selected section
 3090: # dis - set when the "Update Display" button was used, used only to discard command 'set'
 3091: # hideparmsel - can be 'hidden' to hide the parameter selection div initially and display the "Change Parameter Selection" link instead (which displays the div)
 3092: # id - student/employee ID
 3093: # parmlev - selected level (full|map|general)
 3094: # part - selected part (unused ?)
 3095: # pres_marker - &&&-separated parameter identifiers, "resource id&part_parameter name&level"
 3096: # pres_type - &&&-separated parameter types
 3097: # pres_value - &&&-separated parameter values
 3098: # prevvisit - '1' if the user has submitted the form before
 3099: # pscat (multiple values) - selected parameter names
 3100: # pschp - selected map pc, or 'all'
 3101: # psprt (multiple values) - list of selected parameter parts
 3102: # filter - part of or whole parameter name, to be filtered out when parameters are displayed (unused ?)
 3103: # recent_* (* = parameter type) - recent values entered by the user for parameter types
 3104: # symb - resource symb (when a single resource is selected)
 3105: # udom - selected user domain
 3106: # uname - selected user name
 3107: # url - used only with command 'set', the resource url
 3108: #
 3109: # @param {Apache2::RequestRec} $r - the Apache request
 3110: # @param $parm_permission - ref to hash of permissions
 3111: #                           if $parm_permission->{'edit'} is true, editing is allowed.
 3112: sub assessparms {
 3113: 
 3114:     my ($r,$parm_permission) = @_;
 3115: 
 3116: 
 3117: # -------------------------------------------------------- Variable declaration
 3118:     my @ids=(); # resource and map ids
 3119:     my %symbp=(); # hash map pc or resource/map id -> map src.'___(all)' or resource symb
 3120:     my %mapp=(); # hash map pc or resource/map id -> enclosing map src
 3121:     my %typep=(); # hash resource/map id -> resource type (file extension)
 3122:     my %keyp=(); # hash resource/map id -> comma-separated list of parameter keys
 3123:     my %uris=(); # hash resource/map id -> resource src
 3124:     my %maptitles=(); # hash map pc or src -> map title
 3125:     my %allmaps=(); # hash map pc -> map src
 3126:     my %allmaps_inverted=(); # hash map src -> map pc
 3127:     my %alllevs=(); # hash English level title -> value
 3128: 
 3129:     my $uname; # selected user name
 3130:     my $udom; # selected user domain
 3131:     my $uhome; # server with the user's files, or 'no_host'
 3132:     my $csec; # selected section name
 3133:     my $cgroup; # selected group name
 3134:     my @usersgroups = (); # list of the user groups
 3135:     my $numreclinks = 0;
 3136: 
 3137:     my $coursename=$env{'course.'.$env{'request.course.id'}.'.description'};
 3138: 
 3139:     $alllevs{'Resource Level'}='full';
 3140:     $alllevs{'Map/Folder Level'}='map';
 3141:     $alllevs{'Course Level'}='general';
 3142: 
 3143:     my %allparms; # hash parameter name -> parameter title
 3144:     my %allparts; # hash parameter part -> part title
 3145: # ------------------------------------------------------------------------------
 3146: 
 3147: #
 3148: # Order in which these parameters will be displayed
 3149: #
 3150:     my %keyorder=&standardkeyorder();
 3151: 
 3152: #    @ids=();
 3153: #    %symbp=();       # These seem defined above already.
 3154: #    %typep=();
 3155: 
 3156:     my $message='';
 3157: 
 3158:     $csec=$env{'form.csec'};
 3159:     if ($env{'request.course.sec'} ne '') {
 3160:         $csec = $env{'request.course.sec'};    
 3161:     }
 3162: 
 3163: # Check group privs.
 3164:     $cgroup=$env{'form.cgroup'};
 3165:     my $noeditgrp; 
 3166:     if ($cgroup ne '') {
 3167:         unless (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
 3168:             if (($env{'request.course.groups'} eq '') || 
 3169:                 (!grep(/^\Q$cgroup\E$/,split(/:/,$env{'request.course.groups'})))) {
 3170:                 $noeditgrp = 1;
 3171:             }
 3172:         }
 3173:     }
 3174: 
 3175:     if      ($udom=$env{'form.udom'}) {
 3176:     } elsif ($udom=$env{'request.role.domain'}) {
 3177:     } elsif ($udom=$env{'user.domain'}) {
 3178:     } else {
 3179:         $udom=$r->dir_config('lonDefDomain');
 3180:     }
 3181:     
 3182: 
 3183:     my @pscat=&Apache::loncommon::get_env_multiple('form.pscat');
 3184:     my $pschp=$env{'form.pschp'};
 3185: 
 3186: 
 3187:     my @psprt=&Apache::loncommon::get_env_multiple('form.psprt');
 3188:     if (!@psprt) { $psprt[0]='all'; }
 3189:     if (($env{'form.part'}) && ($psprt[0] ne 'all')) { $psprt[0]=$env{'form.part'}; }
 3190: 
 3191:     my $pssymb='';
 3192:     my $parmlev='';
 3193: 
 3194:     unless ($env{'form.parmlev'}) {
 3195:         $parmlev = 'map';
 3196:     } else {
 3197:         $parmlev = $env{'form.parmlev'};
 3198:     }
 3199: 
 3200: # ----------------------------------------------- Was this started from grades?
 3201: 
 3202:     if (($env{'form.command'} eq 'set') && ($env{'form.url'}) &&
 3203:             (!$env{'form.dis'})) {
 3204:         my $url=$env{'form.url'};
 3205:         $url=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
 3206:         $pssymb=&Apache::lonnet::symbread($url);
 3207:         if (!@pscat) { @pscat=('all'); }
 3208:         $pschp='';
 3209:         $parmlev = 'full';
 3210:     } elsif ($env{'form.symb'}) {
 3211:         $pssymb=$env{'form.symb'};
 3212:         if (!@pscat) { @pscat=('all'); }
 3213:         $pschp='';
 3214:         $parmlev = 'full';
 3215:     } else {
 3216:         $env{'form.url'}='';
 3217:     }
 3218: 
 3219:     my $id=$env{'form.id'};
 3220:     if (($id) && ($udom)) {
 3221:         $uname=(&Apache::lonnet::idget($udom,[$id],'ids'))[1];
 3222:         if ($uname) {
 3223:             $id='';
 3224:         } else {
 3225:             $message=
 3226:                 '<p class="LC_warning">'.
 3227:                 &mt('Unknown ID [_1] at domain [_2]',
 3228:                     "'".$id."'","'".$udom."'").
 3229:                 '</p>';
 3230:         }
 3231:     } else {
 3232:         $uname=$env{'form.uname'};
 3233:     }
 3234:     unless ($udom) { $uname=''; }
 3235:     $uhome='';
 3236:     if ($uname) {
 3237:         $uhome=&Apache::lonnet::homeserver($uname,$udom);
 3238:         if ($uhome eq 'no_host') {
 3239:             $message=
 3240:                 '<p class="LC_warning">'.
 3241:                 &mt('Unknown user [_1] at domain [_2]',
 3242:                     "'".$uname."'","'".$udom."'").
 3243:                 '</p>';
 3244:             $uname='';
 3245:         } else {
 3246:             $csec=&Apache::lonnet::getsection($udom,$uname,
 3247:                           $env{'request.course.id'});
 3248:             if ($csec eq '-1') {
 3249:                 my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
 3250:                 if ($env{'form.userroles'} eq 'any') {
 3251:                     if (($env{'user.name'} eq $uname) && ($env{'user.domain'} eq $udom)) {
 3252:                         $csec = $env{'request.course.sec'};
 3253:                         $message = '<span class="LC_info">';
 3254:                         if ($crstype eq 'Community') {
 3255:                             $message .= &mt('User [_1] at domain [_2] has a non-member role in this community',
 3256:                                             $uname,$udom);
 3257:                         } else {
 3258:                             $message .= &mt('User [_1] at domain [_2] has a non-student role in this course',
 3259:                                             $uname,$udom);
 3260:                         }
 3261:                         $message .= '</span>';
 3262:                     } else {
 3263:                         my @possroles = ('in','ep','ta','cr');
 3264:                         if ($crstype eq 'Community') {
 3265:                             unshift(@possroles,'co');
 3266:                         } else {
 3267:                             unshift(@possroles,'cc');
 3268:                         }
 3269:                         my %not_student_roles =
 3270:                             &Apache::lonnet::get_my_roles($uname,$udom,'userroles',['active'],
 3271:                                                           \@possroles,[$udom],1,1);
 3272:                         my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 3273:                         my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 3274:                         my %sections_by_role;
 3275:                         foreach my $role (keys(%not_student_roles)) {
 3276:                             if ($role =~ /^\Q$cnum:$cdom:\E([^:]+):(|[^:]+)$/) {
 3277:                                 my ($rolename,$sec) = ($1,$2);
 3278:                                 if ($rolename =~ m{^cr/}) {
 3279:                                     $rolename = 'cr';
 3280:                                 }
 3281:                                 push(@{$sections_by_role{$rolename}},$sec);
 3282:                             }
 3283:                         }
 3284:                         my $numroles = scalar(keys(%sections_by_role));
 3285:                         if ($numroles) {
 3286:                             foreach my $role (@possroles) {
 3287:                                 if (ref($sections_by_role{$role}) eq 'ARRAY') {
 3288:                                     my @secs = sort { $a <=> $b } @{$sections_by_role{$role}};
 3289:                                     $csec = $secs[0];
 3290:                                     last;
 3291:                                 }
 3292:                             }
 3293:                         }
 3294:                         if ($csec eq '-1') {
 3295:                             $message = '<span class="LC_warning">';
 3296:                             if ($crstype eq 'Community') {
 3297:                                 $message .= &mt('User [_1] at domain [_2] does not have a role in this community',
 3298:                                                 $uname,$udom);
 3299:                             } else {
 3300:                                 $message .= &mt('User [_1] at domain [_2] does not have a role in this course',
 3301:                                                 $uname,$udom);
 3302:                             }
 3303:                             $message .= '</span>';
 3304:                             $uname='';
 3305:                             if ($env{'request.course.sec'} ne '') {
 3306:                                 $csec=$env{'request.course.sec'};
 3307:                             } else {
 3308:                                 $csec=$env{'form.csec'};
 3309:                             }
 3310:                             $cgroup=$env{'form.cgroup'};
 3311:                         } else {
 3312:                             $message = '<span class="LC_info">';
 3313:                             if ($crstype eq 'Community') {
 3314:                                 $message .= &mt('User [_1] at domain [_2] has a non-member role in this community',
 3315:                                          $uname,$udom);
 3316:                             } else {
 3317:                                 $message .= &mt('User [_1] at domain [_2] has a non-student role in this course',
 3318:                                                 $uname,$udom);
 3319:                             }
 3320:                             $message .= '</span>';
 3321:                         }
 3322:                     }
 3323:                 } else {
 3324:                     $message = '<span class="LC_warning">';
 3325:                     if ($crstype eq 'Community') {
 3326:                         $message .= &mt('User [_1] at domain [_2] does not have a member role in this community',
 3327:                                          $uname,$udom);
 3328:                     } else {
 3329:                          $message .= &mt('User [_1] at domain [_2] does not have a student role in this course',
 3330:                                          $uname,$udom);
 3331:                     }
 3332:                     $message .= '</span>';
 3333:                     $uname='';
 3334:                     if ($env{'request.course.sec'} ne '') {
 3335:                         $csec=$env{'request.course.sec'};
 3336:                     } else {
 3337:                         $csec=$env{'form.csec'};
 3338:                     }
 3339:                     $cgroup=$env{'form.cgroup'};
 3340:                 }
 3341:             } elsif ($env{'request.course.sec'} ne '') {
 3342:                 if ($csec ne $env{'request.course.sec'}) {
 3343:                     $message='<span class="LC_warning">'.
 3344:                               &mt("User '[_1]' at domain '[_2]' not in section '[_3]'",
 3345:                                   $uname,$udom,$env{'request.course.sec'}).
 3346:                               '</span>';
 3347:                     $uname='';
 3348:                     $csec=$env{'request.course.sec'};
 3349:                 }
 3350:                 $cgroup=$env{'form.cgroup'};
 3351:             }
 3352:             if ($uname ne '') {
 3353:                 my %name=&Apache::lonnet::userenvironment($udom,$uname,
 3354:                   ('firstname','middlename','lastname','generation','id'));
 3355:                 $message .= "\n<p>\n".&mt('Full Name').': '
 3356:                             .$name{'firstname'}.' '.$name{'middlename'}.' '
 3357:                             .$name{'lastname'}.' '.$name{'generation'}
 3358:                             ."<br />\n".&mt('Student/Employee ID').': '.$name{'id'}.'</p>';
 3359:                 @usersgroups = &Apache::lonnet::get_users_groups(
 3360:                                    $udom,$uname,$env{'request.course.id'});
 3361:                 if (@usersgroups > 0) {
 3362:                     unless (grep(/^\Q$cgroup\E$/,@usersgroups)) {
 3363:                         $cgroup = $usersgroups[0];
 3364:                     }
 3365:                 } else {
 3366:                     $cgroup = '';
 3367:                 }
 3368:             }
 3369:         }
 3370:     }
 3371: 
 3372:     unless ($csec) { $csec=''; }
 3373:     unless ($cgroup) { $cgroup=''; }
 3374: 
 3375: # --------------------------------------------------------- Get all assessments
 3376:     &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allmaps,
 3377:                 \%mapp, \%symbp,\%maptitles,\%uris,
 3378:                 \%keyorder,undef,$pssymb);
 3379: 
 3380:     %allmaps_inverted = reverse(%allmaps);
 3381: 
 3382:     $mapp{'0.0'} = '';
 3383:     $symbp{'0.0'} = '';
 3384: 
 3385: # ---------------------------------------------------------- Anything to store?
 3386:     if ($env{'form.pres_marker'} && $parm_permission->{'edit'}) {
 3387:         my @markers=split(/\&\&\&/,$env{'form.pres_marker'});
 3388:         my @values=split(/\&\&\&/,$env{'form.pres_value'});
 3389:         my @types=split(/\&\&\&/,$env{'form.pres_type'});
 3390:         my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 3391:         my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 3392:         my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
 3393:         my ($got_chostname,$chostname,$cmajor,$cminor);
 3394:         my $totalstored = 0;
 3395:         my $totalskippeduser = 0;
 3396:         my $now = time;
 3397:         for (my $i=0;$i<=$#markers;$i++) {
 3398:             my ($needsrelease,$needsnewer,$name,$namematch);
 3399:             if (($env{'request.course.sec'} ne '') && ($markers[$i] =~ /\&(9|10|11|12)$/)) {
 3400:                 next if ($csec ne $env{'request.course.sec'});
 3401:             }
 3402:             if ($markers[$i] =~ /\&(8|7|6|5)$/) {
 3403:                 next if ($noeditgrp);
 3404:             } elsif ($markers[$i] =~ /\&(4|3|2|1)$/) {
 3405:                 if ($uname eq '') {
 3406:                     $totalskippeduser ++;
 3407:                     next;
 3408:                 }
 3409:             }
 3410:             if ($markers[$i] =~ /\&(17|11|7|3)$/) {
 3411:                 $namematch = 'maplevelrecurse';
 3412:             }
 3413:             if ($markers[$i] =~ /^[\d.]+\&0_availablestudent\&(1|2|3|4)$/) {
 3414:                 my (@ok_slots,@fail_slots,@del_slots);
 3415:                 my $courseopt=&Apache::lonnet::get_courseresdata($cnum,$cdom);
 3416:                 my ($level,@all) =
 3417:                     &parmval_by_symb('0.availablestudent',$pssymb,'',$uname,$udom,
 3418:                                      $csec,$cgroup,$courseopt);
 3419:                 foreach my $slot_name (split(/:/,$values[$i])) {
 3420:                     next if ($slot_name eq '');
 3421:                     if (&update_slots($slot_name,$cdom,$cnum,$pssymb,$uname,$udom) eq 'ok') {
 3422:                         push(@ok_slots,$slot_name);
 3423: 
 3424:                     } else {
 3425:                         push(@fail_slots,$slot_name);
 3426:                     }
 3427:                 }
 3428:                 if (@ok_slots) {
 3429:                     $values[$i] = join(':',@ok_slots);
 3430:                 } else {
 3431:                     $values[$i] = '';
 3432:                 }
 3433:                 if ($all[$level] ne '') {
 3434:                     my @existing = split(/:/,$all[$level]);
 3435:                     foreach my $slot_name (@existing) {
 3436:                         if (!grep(/^\Q$slot_name\E$/,split(/:/,$values[$i]))) {
 3437:                             if (&delete_slots($slot_name,$cdom,$cnum,$uname,$udom,$pssymb) eq 'ok') {
 3438:                                 push(@del_slots,$slot_name);
 3439:                             }
 3440:                         }
 3441:                     }
 3442:                 }
 3443:             } elsif ($markers[$i] =~ /_(type|lenient|retrypartial|discussvote|examcode|printstartdate|printenddate|acc|interval)\&\d+$/) {
 3444:                 $name = $1;
 3445:                 my $val = $values[$i];
 3446:                 my $valmatch = '';
 3447:                 if ($name eq 'examcode') {
 3448:                     if (&Apache::lonnet::validCODE($values[$i])) {
 3449:                         $val = 'valid';
 3450:                     }
 3451:                 } elsif ($name eq 'printstartdate') {
 3452:                     if ($val =~ /^\d+$/) {
 3453:                         if ($val > $now) {
 3454:                             $val = 'future';
 3455:                         }
 3456:                     } 
 3457:                 } elsif ($name eq 'printenddate') {
 3458:                     if ($val =~ /^\d+$/) {
 3459:                         if ($val < $now) {
 3460:                             $val = 'past';
 3461:                         }
 3462:                     }
 3463:                 } elsif (($name eq 'lenient') || ($name eq 'acc')) {
 3464:                     my $stringtype = &get_stringtype($name);
 3465:                     my $stringmatch = &standard_string_matches($stringtype);
 3466:                     if (ref($stringmatch) eq 'ARRAY') {
 3467:                         foreach my $item (@{$stringmatch}) {
 3468:                             if (ref($item) eq 'ARRAY') {
 3469:                                 my ($regexpname,$pattern) = @{$item};
 3470:                                 if ($pattern ne '') {
 3471:                                     if ($val =~ /$pattern/) {
 3472:                                         $valmatch = $regexpname;
 3473:                                         $val = '';
 3474:                                         last;
 3475:                                     }
 3476:                                 }
 3477:                             }
 3478:                         }
 3479:                     }
 3480:                 } elsif ($name eq 'interval') {
 3481:                     my $intervaltype = &get_intervaltype($name);
 3482:                     my $intervalmatch = &standard_interval_matches($intervaltype);
 3483:                     if (ref($intervalmatch) eq 'ARRAY') {
 3484:                         foreach my $item (@{$intervalmatch}) {
 3485:                             if (ref($item) eq 'ARRAY') {
 3486:                                 my ($regexpname,$pattern) = @{$item};
 3487:                                 if ($pattern ne '') {
 3488:                                     if ($val =~ /$pattern/) {
 3489:                                         $valmatch = $regexpname;
 3490:                                         $val = '';
 3491:                                         last;
 3492:                                     }
 3493:                                 }
 3494:                             }
 3495:                         }
 3496:                     }
 3497:                 }
 3498:                 $needsrelease =
 3499:                     $Apache::lonnet::needsrelease{"parameter:$name:$val:$valmatch:"};
 3500:                 if ($needsrelease) {
 3501:                     unless ($got_chostname) {
 3502:                         ($chostname,$cmajor,$cminor) = &parameter_release_vars();
 3503:                         $got_chostname = 1;
 3504:                     } 
 3505:                     $needsnewer = &parameter_releasecheck($name,$val,$valmatch,undef,
 3506:                                                           $needsrelease,
 3507:                                                           $cmajor,$cminor);
 3508:                 }
 3509:             }
 3510:             if ($needsnewer) {
 3511:                 undef($namematch);
 3512:             } else {
 3513:                 my $currneeded;
 3514:                 if ($needsrelease) {
 3515:                     $currneeded = $needsrelease;
 3516:                 }
 3517:                 if ($namematch) {
 3518:                     $needsrelease =
 3519:                         $Apache::lonnet::needsrelease{"parameter::::$namematch"};
 3520:                     if (($needsrelease) && (($currneeded eq '') || ($needsrelease < $currneeded))) {
 3521:                         unless ($got_chostname) {
 3522:                             ($chostname,$cmajor,$cminor) = &parameter_release_vars();
 3523:                             $got_chostname = 1;
 3524:                         }
 3525:                         $needsnewer = &parameter_releasecheck(undef,undef,undef,$namematch,
 3526:                                                               $needsrelease,
 3527:                                                               $cmajor,$cminor);
 3528:                     } else {
 3529:                         undef($namematch);
 3530:                     }
 3531:                 }
 3532:             }
 3533:             if ($needsnewer) {
 3534:                 $message .= &oldversion_warning($name,$namematch,$values[$i],$chostname,$cmajor,
 3535:                                                 $cminor,$needsrelease);
 3536:             } else {
 3537:                 $message.=&storeparm(split(/\&/,$markers[$i]),
 3538:                                      $values[$i],
 3539:                                      $types[$i],
 3540:                                      $uname,$udom,$csec,$cgroup);
 3541:                 $totalstored ++;
 3542:             }
 3543:         }
 3544: # ---------------------------------------------------------------- Done storing
 3545:         if ($totalstored) {
 3546:             $message.='<p class="LC_warning">'
 3547:                      .&mt('Changes for [quant,_1,parameter] saved.',$totalstored)
 3548:                      .'<br />'
 3549:                      .&mt('Changes can take up to 10 minutes before being active for all students.')
 3550:                      .&Apache::loncommon::help_open_topic('Caching')
 3551:                      .'</p>';
 3552:         } else {
 3553:             $message.='<p class="LC_info">'.&mt('No parameter changes saved.').'</p>';
 3554:         }
 3555:         if ($totalskippeduser) {
 3556:             $message .= '<p class="LC_warning">';
 3557:             if ($uhome eq 'no_host') {
 3558:                 $message .= &mt('Changes for [quant,_1,user-specific parameter] not saved because the username or ID was invalid.',
 3559:                                 $totalskippeduser);
 3560:             } elsif ($env{'form.userroles'} eq 'any') {
 3561:                 $message .= &mt('Changes for [quant,_1,user-specific parameter] not saved because the user does not have a course role.',
 3562:                                 $totalskippeduser);
 3563:             } else {
 3564:                 $message .= &mt('Changes for [quant,_1,user-specific parameter] not saved because the user is not a student.',
 3565:                                 $totalskippeduser);
 3566:             }
 3567:             $message .= '</p>';
 3568:         }
 3569:     }
 3570: 
 3571: #----------------------------------------------- if all selected, fill in array
 3572:     if ($pscat[0] eq "all") {
 3573:         @pscat = (keys(%allparms));
 3574:     }
 3575:     if (!@pscat) {
 3576:         @pscat=('duedate','opendate','answerdate','weight','maxtries','type','problemstatus')
 3577:     };
 3578:     if ($psprt[0] eq "all" || !@psprt) {
 3579:         @psprt = (keys(%allparts));
 3580:     }
 3581: # ------------------------------------------------------------------ Start page
 3582: 
 3583:     my $crstype = &Apache::loncommon::course_type();
 3584:     &startpage($r,$pssymb,$crstype);
 3585: 
 3586:     foreach my $item ('tolerance','date_default','date_start','date_end',
 3587:             'date_interval','int','float','string','string_lenient',
 3588:             'string_examcode','string_deeplink','string_discussvote',
 3589:             'string_useslots','string_problemstatus','string_ip',
 3590:             'string_questiontype') {
 3591:         $r->print('<input type="hidden" value="'.
 3592:             &HTML::Entities::encode($env{'form.recent_'.$item},'"&<>').
 3593:             '" name="recent_'.$item.'" />');
 3594:     }
 3595: 
 3596:     # ----- Start Parameter Selection
 3597: 
 3598:     # Hide parm selection?
 3599:     $r->print(<<ENDPARMSELSCRIPT);
 3600: <script type="text/javascript">
 3601: // <![CDATA[
 3602: function parmsel_show() {
 3603:     document.getElementById('parmsel').style.display = "";
 3604:     document.getElementById('parmsellink').style.display = "none";
 3605: }
 3606: // ]]>
 3607: </script>
 3608: ENDPARMSELSCRIPT
 3609:     
 3610:     if (!$pssymb) {
 3611:         # No single resource selected, print forms to select things (hidden after first selection)
 3612:         my $parmselhiddenstyle=' style="display:none"';
 3613:         if($env{'form.hideparmsel'} eq 'hidden') {
 3614:            $r->print('<div id="parmsel"'.$parmselhiddenstyle.'>');
 3615:         } else  {
 3616:            $r->print('<div id="parmsel">');
 3617:         }
 3618: 
 3619:         # Step 1
 3620:         $r->print(&Apache::lonhtmlcommon::topic_bar(1,&mt('Resource Specification'),'parmstep1'));
 3621:         $r->print('
 3622: <script type="text/javascript">
 3623: // <![CDATA['.
 3624:                  &showhide_js().'
 3625: // ]]>
 3626: </script>
 3627: ');
 3628:         $r->print(&Apache::lonhtmlcommon::start_pick_box(undef,'parmlevel'));
 3629:         &levelmenu($r,\%alllevs,$parmlev);
 3630:         $r->print(&Apache::lonhtmlcommon::row_closure());
 3631:         &mapmenu($r,\%allmaps,$pschp,\%maptitles, \%symbp);
 3632:         $r->print(&Apache::lonhtmlcommon::row_closure());
 3633:         $r->print(&Apache::lonhtmlcommon::row_title(&mt('Select Parts to View')));
 3634:         &partmenu($r,\%allparts,\@psprt);
 3635:         $r->print(&Apache::lonhtmlcommon::row_closure(1));
 3636:         $r->print(&Apache::lonhtmlcommon::end_pick_box());
 3637: 
 3638:         # Step 2
 3639:         $r->print(&Apache::lonhtmlcommon::topic_bar(2,&mt('Parameter Specification'),'parmstep2'));
 3640:         &displaymenu($r,\%allparms,\@pscat,\%keyorder,'parmmenuscroll');
 3641: 
 3642:         # Step 3
 3643:         $r->print(&Apache::lonhtmlcommon::topic_bar(3,&mt('User Specification (optional)'),'parmstep3'));
 3644:         $r->print(&Apache::lonhtmlcommon::start_pick_box());
 3645:         &usermenu($r,$uname,$id,$udom,$csec,$cgroup,$parmlev,\@usersgroups,$pssymb);
 3646:         $r->print(&Apache::lonhtmlcommon::row_closure(1));
 3647:         $r->print(&Apache::lonhtmlcommon::end_pick_box());
 3648: 
 3649:         # Update Display Button
 3650:         $r->print('<p>'
 3651:              .'<input type="submit" name="dis"'
 3652:              .' value="'.&mt('Update Display').'" />'
 3653:              .'<input type="hidden" name="hideparmsel" value="hidden" />'
 3654:              .'</p>');
 3655:         $r->print('</div>');
 3656: 
 3657:         # Offer link to display parameter selection again
 3658:         $r->print('<p id="parmsellink"');
 3659:         if ($env{'form.hideparmsel'} ne 'hidden') {
 3660:            $r->print($parmselhiddenstyle);
 3661:         }
 3662:         $r->print('>'
 3663:              .'<a href="javascript:parmsel_show()">'
 3664:              .&mt('Change Parameter Selection')
 3665:              .'</a>'
 3666:              .'</p>');
 3667:     } else {
 3668:         # parameter screen for a single resource. 
 3669:         my ($map,$iid,$resource)=&Apache::lonnet::decode_symb($pssymb);
 3670:         my $title = &Apache::lonnet::gettitle($pssymb);
 3671:         $r->print(&mt('Specific Resource: [_1] ([_2])',
 3672:                          $title,'<span class="LC_filename">'.$resource.'</span>').
 3673:                 '<input type="hidden" value="'.$pssymb.'" name="symb" />'.
 3674:                   '<br />');
 3675:         $r->print(&Apache::lonhtmlcommon::topic_bar('',&mt('Additional Display Specification (optional)')));
 3676:         $r->print(&Apache::lonhtmlcommon::start_pick_box());
 3677:         &usermenu($r,$uname,$id,$udom,$csec,$cgroup,$parmlev,\@usersgroups,$pssymb);
 3678:         $r->print(&Apache::lonhtmlcommon::row_closure(1));
 3679:         $r->print(&Apache::lonhtmlcommon::end_pick_box());
 3680:         $r->print('<p>'
 3681:              .'<input type="submit" name="dis"'
 3682:              .' value="'.&mt('Update Display').'" />'
 3683:              .'<input type="hidden" name="hideparmsel" value="hidden" />'
 3684:              .'</p>');
 3685:     }
 3686:     
 3687:     # ----- End Parameter Selection
 3688: 
 3689:     # Display Messages
 3690:     $r->print('<div>'.$message.'</div>');
 3691: 
 3692: 
 3693:     my @temp_pscat;
 3694:     map {
 3695:         my $cat = $_;
 3696:         push(@temp_pscat, map { $_.'.'.$cat } @psprt);
 3697:     } @pscat;
 3698: 
 3699:     @pscat = @temp_pscat;
 3700: 
 3701: 
 3702:     if (($env{'form.prevvisit'}) || ($pschp) || ($pssymb)) {
 3703: # ----------------------------------------------------------------- Start Table
 3704:         my @catmarker=map { tr|.|_|; 'parameter_'.$_; } @pscat;
 3705:         my $csuname=$env{'user.name'};
 3706:         my $csudom=$env{'user.domain'};
 3707:         my $readonly = 1;
 3708:         if ($parm_permission->{'edit'}) {
 3709:             undef($readonly); 
 3710:         }
 3711: 
 3712:         if ($parmlev eq 'full') {
 3713: #
 3714: # This produces the cascading table output of parameters
 3715: #
 3716:             my $coursespan=$csec?8:5;
 3717:             my $userspan=3;
 3718:             if ($cgroup ne '') {
 3719:                 $coursespan += 3;
 3720:             }
 3721: 
 3722:             $r->print(&Apache::loncommon::start_data_table());
 3723:             #
 3724:             # This produces the headers
 3725:             #
 3726:             $r->print('<tr><td colspan="5"></td>');
 3727:             $r->print('<th colspan="'.($coursespan).'">'.&mt('Any User').'</th>');
 3728:             if ($uname) {
 3729:                 if (@usersgroups > 1) {
 3730:                     $userspan ++;
 3731:                 }
 3732:                 $r->print('<th colspan="'.$userspan.'" rowspan="2">');
 3733:                 $r->print(&mt('User [_1] at Domain [_2]',"'".$uname."'","'".$udom."'").'</th>');
 3734:             }
 3735:             my %lt=&Apache::lonlocal::texthash(
 3736:                 'pie'    => "Parameter in Effect",
 3737:                 'csv'    => "Current Session Value",
 3738:                 'rl'     => "Resource Level",
 3739:                 'ic'     => 'in Course',
 3740:                 'aut'    => "Assessment URL and Title",
 3741:                 'type'   => 'Type',
 3742:                 'emof'   => "Enclosing Map or Folder",
 3743:                 'part'   => 'Part',
 3744:                 'pn'     => 'Parameter Name',
 3745:                 'def'    => 'default',
 3746:                 'femof'  => 'from Enclosing Map or Folder',
 3747:                 'gen'    => 'general',
 3748:                 'foremf' => 'for Enclosing Map or Folder',
 3749:                 'fr'     => 'for Resource'
 3750:             );
 3751:             $r->print(<<ENDTABLETWO);
 3752: <th rowspan="3">$lt{'pie'}</th>
 3753: <th rowspan="3">$lt{'csv'}<br />($csuname:$csudom)</th>
 3754: </tr><tr><td colspan="5"></td><th colspan="2">$lt{'ic'}</th><th colspan="2">$lt{'rl'}</th>
 3755: <th colspan="1">$lt{'ic'}</th>
 3756: 
 3757: ENDTABLETWO
 3758:             if ($csec) {
 3759:                 $r->print('<th colspan="3">'.
 3760:                 &mt("in Section")." $csec</th>");
 3761:             }
 3762:             if ($cgroup) {
 3763:                 $r->print('<th colspan="3">'.
 3764:                 &mt("in Group")." $cgroup</th>");
 3765:             }
 3766:             $r->print(<<ENDTABLEHEADFOUR);
 3767: </tr><tr><th>$lt{'aut'}</th><th>$lt{'type'}</th>
 3768: <th>$lt{'emof'}</th><th>$lt{'part'}</th><th>$lt{'pn'}</th>
 3769: <th>$lt{'gen'}</th><th>$lt{'foremf'}</th>
 3770: <th>$lt{'def'}</th><th>$lt{'femof'}</th><th>$lt{'fr'}</th>
 3771: ENDTABLEHEADFOUR
 3772: 
 3773:             if ($csec) {
 3774:                 $r->print('<th>'.$lt{'gen'}.'</th><th>'.$lt{'foremf'}.'</th><th>'.$lt{'fr'}.'</th>');
 3775:             }
 3776: 
 3777:             if ($cgroup) {
 3778:                 $r->print('<th>'.$lt{'gen'}.'</th><th>'.$lt{'foremf'}.'</th><th>'.$lt{'fr'}.'</th>');
 3779:             }
 3780: 
 3781:             if ($uname) {
 3782:                 if (@usersgroups > 1) {
 3783:                     $r->print('<th>'.&mt('Control by other group?').'</th>');
 3784:                 }
 3785:                 $r->print('<th>'.$lt{'gen'}.'</th><th>'.$lt{'foremf'}.'</th><th>'.$lt{'fr'}.'</th>');
 3786:             }
 3787: 
 3788:             $r->print('</tr>');
 3789: #
 3790: # Done with the headers
 3791: # 
 3792:             my $defbgone='';
 3793:             my $defbgtwo='';
 3794:             my $defbgthree = '';
 3795: 
 3796:             foreach my $rid (@ids) {
 3797: 
 3798:                 my ($inmapid)=($rid=~/\.(\d+)$/);
 3799:                 if ((!$pssymb &&
 3800:                         (($pschp eq 'all') || ($allmaps{$pschp} eq $mapp{$rid})))
 3801:                         ||
 3802:                         ($pssymb && $pssymb eq $symbp{$rid})) {
 3803: # ------------------------------------------------------ Entry for one resource
 3804:                     if ($defbgone eq '#E0E099') {
 3805:                         $defbgone='#E0E0DD';
 3806:                     } else {
 3807:                         $defbgone='#E0E099';
 3808:                     }
 3809:                     if ($defbgtwo eq '#FFFF99') {
 3810:                         $defbgtwo='#FFFFDD';
 3811:                     } else {
 3812:                         $defbgtwo='#FFFF99';
 3813:                     }
 3814:                     if ($defbgthree eq '#FFBB99') {
 3815:                         $defbgthree='#FFBBDD';
 3816:                     } else {
 3817:                         $defbgthree='#FFBB99';
 3818:                     }
 3819: 
 3820:                     my $thistitle='';
 3821:                     my %name=   ();
 3822:                     undef %name;
 3823:                     my %part=   ();
 3824:                     my %display=();
 3825:                     my %type=   ();
 3826:                     my %default=();
 3827:                     my $uri=&Apache::lonnet::declutter($uris{$rid});
 3828:                     my $toolsymb;
 3829:                     if ($uri =~ /ext\.tool$/) {
 3830:                         $toolsymb = $symbp{$rid};
 3831:                     }
 3832: 
 3833:                     my $filter=$env{'form.filter'};
 3834:                     foreach my $tempkeyp (&keysplit($keyp{$rid})) {
 3835:                         if (grep $_ eq $tempkeyp, @catmarker) {
 3836:                             my $parmname=&Apache::lonnet::metadata($uri,$tempkeyp.'.name',$toolsymb);
 3837:     # We may only want certain parameters listed
 3838:                             if ($filter) {
 3839:                                 unless ($filter=~/\Q$parmname\E/) { next; }
 3840:                             }
 3841:                             $name{$tempkeyp}=$parmname;
 3842:                             $part{$tempkeyp}=&Apache::lonnet::metadata($uri,$tempkeyp.'.part',$toolsymb);
 3843: 
 3844:                             my $parmdis=&Apache::lonnet::metadata($uri,$tempkeyp.'.display',$toolsymb);
 3845:                             if ($allparms{$name{$tempkeyp}} ne '') {
 3846:                                 my $identifier;
 3847:                                 if ($parmdis =~ /(\s*\[Part.*)$/) {
 3848:                                     $identifier = $1;
 3849:                                 }
 3850:                                 $display{$tempkeyp} = $allparms{$name{$tempkeyp}}.$identifier;
 3851:                             } else {
 3852:                                 $display{$tempkeyp} = $parmdis;
 3853:                             }
 3854:                             unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
 3855:                             $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
 3856:                             $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$tempkeyp,$toolsymb);
 3857:                             $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$tempkeyp.'.type',$toolsymb);
 3858:                             $thistitle=&Apache::lonnet::metadata($uri,$tempkeyp.'.title',$toolsymb);
 3859:                         }
 3860:                     }
 3861:                     my $totalparms=scalar(keys(%name));
 3862:                     if ($totalparms>0) {
 3863:                         my $firstrow=1;
 3864:                         my $title=&Apache::lonnet::gettitle($symbp{$rid});
 3865:                         my $navmap = Apache::lonnavmaps::navmap->new();
 3866:                         my @recurseup;
 3867:                         if (ref($navmap) && $mapp{$rid}) {
 3868:                             @recurseup = $navmap->recurseup_maps($mapp{$rid});
 3869:                         }
 3870:                         $r->print('<tr><td style="background-color:'.$defbgone.';"'.
 3871:                              ' rowspan='.$totalparms.
 3872:                              '><tt><font size="-1">'.
 3873:                              join(' / ',split(/\//,$uri)).
 3874:                              '</font></tt><p><b>'.
 3875:                              "<a href=\"javascript:openWindow('".
 3876:                           &Apache::lonnet::clutter($uri).'?symb='.
 3877:                           &escape($symbp{$rid}).
 3878:                              "', 'metadatafile', '450', '500', 'no', 'yes');\"".
 3879:                              " target=\"_self\">$title");
 3880: 
 3881:                         if ($thistitle) {
 3882:                             $r->print(' ('.$thistitle.')');
 3883:                         }
 3884:                         $r->print('</a></b></td>');
 3885:                         $r->print('<td style="background-color:'.$defbgtwo.';"'.
 3886:                                       ' rowspan='.$totalparms.'>'.$typep{$rid}.
 3887:                                       '</td>');
 3888: 
 3889:                         $r->print('<td style="background-color:'.$defbgone.';"'.
 3890:                                       ' rowspan='.$totalparms.
 3891:                                       '>'.$maptitles{$mapp{$rid}}.'</td>');
 3892:                         foreach my $item (&keysinorder_bytype(\%name,\%keyorder)) {
 3893:                             unless ($firstrow) {
 3894:                                 $r->print('<tr>');
 3895:                             } else {
 3896:                                 undef $firstrow;
 3897:                             }
 3898:                             &print_row($r,$item,\%part,\%name,\%symbp,$rid,\%default,
 3899:                                        \%type,\%display,$defbgone,$defbgtwo,
 3900:                                        $defbgthree,$parmlev,$uname,$udom,$csec,
 3901:                                        $cgroup,\@usersgroups,$noeditgrp,$readonly,
 3902:                                        \@recurseup,\%maptitles,\%allmaps_inverted,
 3903:                                        \$numreclinks);
 3904:                         }
 3905:                     }
 3906:                 }
 3907:             } # end foreach ids
 3908: # -------------------------------------------------- End entry for one resource
 3909:             $r->print(&Apache::loncommon::end_data_table);
 3910:         } # end of  full
 3911: #--------------------------------------------------- Entry for parm level map
 3912:         if ($parmlev eq 'map') {
 3913:             my $defbgone = '#E0E099';
 3914:             my $defbgtwo = '#FFFF99';
 3915:             my $defbgthree = '#FFBB99';
 3916: 
 3917:             my %maplist;
 3918: 
 3919:             if ($pschp eq 'all') {
 3920:                 %maplist = %allmaps;
 3921:             } else {
 3922:                 %maplist = ($pschp => $mapp{$pschp});
 3923:             }
 3924: 
 3925: #-------------------------------------------- for each map, gather information
 3926:             my $mapid;
 3927:             foreach $mapid (sort {$maplist{$a} cmp $maplist{$b}} keys(%maplist)) {
 3928:                 my $maptitle = $maplist{$mapid};
 3929: 
 3930: #-----------------------  loop through ids and get all parameter types for map
 3931: #-----------------------------------------          and associated information
 3932:                 my %name = ();
 3933:                 my %part = ();
 3934:                 my %display = ();
 3935:                 my %type = ();
 3936:                 my %default = ();
 3937:                 my $map = 0;
 3938: 
 3939: #        $r->print("Catmarker: @catmarker<br />\n");
 3940: 
 3941:                 foreach my $id (@ids) {
 3942:                     ($map)=($id =~ /([\d]*?)\./);
 3943:                     my $rid = $id;
 3944: 
 3945: #                  $r->print("$mapid:$map:   $rid <br /> \n");
 3946: 
 3947:                     if ($map eq $mapid) {
 3948:                         my $uri=&Apache::lonnet::declutter($uris{$rid});
 3949:                         my $toolsymb;
 3950:                         if ($uri =~ /ext\.tool$/) {
 3951:                             $toolsymb = $symbp{$rid};
 3952:                         }
 3953: 
 3954: #                    $r->print("Keys: $keyp{$rid} <br />\n");
 3955: 
 3956: #--------------------------------------------------------------------
 3957: # @catmarker contains list of all possible parameters including part #s
 3958: # $fullkeyp contains the full part/id # for the extraction of proper parameters
 3959: # $tempkeyp contains part 0 only (no ids - ie, subparts)
 3960: # When storing information, store as part 0
 3961: # When requesting information, request from full part
 3962: #-------------------------------------------------------------------
 3963:                         foreach my $fullkeyp (&keysplit($keyp{$rid})) {
 3964:                             my $tempkeyp = $fullkeyp;
 3965:                             $tempkeyp =~ s/_\w+_/_0_/;
 3966: 
 3967:                             if ((grep $_ eq $fullkeyp, @catmarker) &&(!$name{$tempkeyp})) {
 3968:                                 $part{$tempkeyp}="0";
 3969:                                 $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name',$toolsymb);
 3970:                                 my $parmdis=&Apache::lonnet::metadata($uri,$fullkeyp.'.display',$toolsymb);
 3971:                                 if ($allparms{$name{$tempkeyp}} ne '') {
 3972:                                     my $identifier;
 3973:                                     if ($parmdis =~ /(\s*\[Part.*)$/) {
 3974:                                         $identifier = $1;
 3975:                                     }
 3976:                                     $display{$tempkeyp} = $allparms{$name{$tempkeyp}}.$identifier;
 3977:                                 } else {
 3978:                                     $display{$tempkeyp} = $parmdis;
 3979:                                 }
 3980:                                 unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
 3981:                                 $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
 3982:                                 $display{$tempkeyp} =~ s/_\w+_/_0_/;
 3983:                                 $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp,$toolsymb);
 3984:                                 $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type',$toolsymb);
 3985:                               }
 3986:                         } # end loop through keys
 3987:                     }
 3988:                 } # end loop through ids
 3989: 
 3990: #---------------------------------------------------- print header information
 3991:                 my $foldermap=&mt($maptitle=~/^uploaded/?'Folder':'Map');
 3992:                 my $showtitle=$maptitles{$maptitle}.($maptitle!~/^uploaded/?' ['.$maptitle.']':'');
 3993:                 my $tmp="";
 3994:                 if ($uname) {
 3995:                     my $person=&Apache::loncommon::plainname($uname,$udom);
 3996:                     $tmp.=&mt("User")." <font color=\"red\"><i>$uname \($person\) </i></font> ".
 3997:                         &mt('in')." \n";
 3998:                 } else {
 3999:                     $tmp.="<font color=\"red\"><i>".&mt('all').'</i></font> '.&mt('users in')." \n";
 4000:                 }
 4001:                 if ($cgroup) {
 4002:                     $tmp.=&mt("Group")." <font color=\"red\"><i>$cgroup".
 4003:                               "</i></font> ".&mt('of')." \n";
 4004:                     $csec = '';
 4005:                 } elsif ($csec) {
 4006:                     $tmp.=&mt("Section")." <font color=\"red\"><i>$csec".
 4007:                               "</i></font> ".&mt('of')." \n";
 4008:                 }
 4009:                 $r->print('<div align="center"><h4>'
 4010:                          .&mt('Set Defaults for All Resources in [_1]Specifically for [_2][_3]'
 4011:                              ,$foldermap.'<br /><font color="red"><i>'.$showtitle.'</i></font><br />'
 4012:                              ,$tmp
 4013:                              ,'<font color="red"><i>'.$coursename.'</i></font>'
 4014:                              )
 4015:                          ."<br /></h4>\n"
 4016:                 );
 4017: #---------------------------------------------------------------- print table
 4018:                 $r->print('<p>'.&Apache::loncommon::start_data_table()
 4019:                          .&Apache::loncommon::start_data_table_header_row()
 4020:                          .'<th>'.&mt('Parameter Name').'</th>'
 4021:                          .'<th>'.&mt('Value').'</th>'
 4022:                          .'<th>'.&mt('Parameter in Effect').'</th>'
 4023:                          .&Apache::loncommon::end_data_table_header_row()
 4024:                 );
 4025: 
 4026:                 my $navmap = Apache::lonnavmaps::navmap->new();
 4027:                 my @recurseup;
 4028:                 if (ref($navmap)) {
 4029:                      my $mapres = $navmap->getByMapPc($mapid);
 4030:                      if (ref($mapres)) {
 4031:                          @recurseup = $navmap->recurseup_maps($mapres->src());
 4032:                      }
 4033:                 }
 4034: 
 4035: 
 4036:                 foreach my $item (&keysinorder(\%name,\%keyorder)) {
 4037:                     $r->print(&Apache::loncommon::start_data_table_row());
 4038:                     &print_row($r,$item,\%part,\%name,\%symbp,$mapid,\%default,
 4039:                            \%type,\%display,$defbgone,$defbgtwo,$defbgthree,
 4040:                            $parmlev,$uname,$udom,$csec,$cgroup,'',$noeditgrp,
 4041:                            $readonly,\@recurseup,\%maptitles,\%allmaps_inverted,
 4042:                            \$numreclinks);
 4043:                 }
 4044:                 $r->print(&Apache::loncommon::end_data_table().'</p>'
 4045:                          .'</div>'
 4046:                 );
 4047:             } # end each map
 4048:         } # end of $parmlev eq map
 4049: #--------------------------------- Entry for parm level general (Course level)
 4050:         if ($parmlev eq 'general') {
 4051:             my $defbgone = '#E0E099';
 4052:             my $defbgtwo = '#FFFF99';
 4053:             my $defbgthree = '#FFBB99';
 4054: 
 4055: #-------------------------------------------- for each map, gather information
 4056:             my $mapid="0.0";
 4057: #-----------------------  loop through ids and get all parameter types for map
 4058: #-----------------------------------------          and associated information
 4059:             my %name = ();
 4060:             my %part = ();
 4061:             my %display = ();
 4062:             my %type = ();
 4063:             my %default = ();
 4064: 
 4065:             foreach $id (@ids) {
 4066:                 my $rid = $id;
 4067: 
 4068:                 my $uri=&Apache::lonnet::declutter($uris{$rid});
 4069:                 my $toolsymb;
 4070:                 if ($uri =~ /ext\.tool$/) {
 4071:                     $toolsymb = $symbp{$rid};
 4072:                 }
 4073: 
 4074: #--------------------------------------------------------------------
 4075: # @catmarker contains list of all possible parameters including part #s
 4076: # $fullkeyp contains the full part/id # for the extraction of proper parameters
 4077: # $tempkeyp contains part 0 only (no ids - ie, subparts)
 4078: # When storing information, store as part 0
 4079: # When requesting information, request from full part
 4080: #-------------------------------------------------------------------
 4081:                 foreach my $fullkeyp (&keysplit($keyp{$rid})) {
 4082:                     my $tempkeyp = $fullkeyp;
 4083:                     $tempkeyp =~ s/_\w+_/_0_/;
 4084:                     if ((grep $_ eq $fullkeyp, @catmarker) &&(!$name{$tempkeyp})) {
 4085:                         $part{$tempkeyp}="0";
 4086:                         $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name',$toolsymb);
 4087:                         my $parmdis=&Apache::lonnet::metadata($uri,$fullkeyp.'.display',$toolsymb);
 4088:                         if ($allparms{$name{$tempkeyp}} ne '') {
 4089:                             my $identifier;
 4090:                             if ($parmdis =~ /(\s*\[Part.*)$/) {
 4091:                                 $identifier = $1;
 4092:                             }
 4093:                             $display{$tempkeyp} = $allparms{$name{$tempkeyp}}.$identifier;
 4094:                         } else {
 4095:                             $display{$tempkeyp} = $parmdis;
 4096:                         }
 4097:                         unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
 4098:                         $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
 4099:                         $display{$tempkeyp} =~ s/_\w+_/_0_/;
 4100:                         $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp,$toolsymb);
 4101:                         $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type',$toolsymb);
 4102:                     }
 4103:                 } # end loop through keys
 4104:             } # end loop through ids
 4105: 
 4106: #---------------------------------------------------- print header information
 4107:             my $setdef=&mt("Set Defaults for All Resources in Course");
 4108:             $r->print(<<ENDMAPONE);
 4109: <center>
 4110: <h4>$setdef
 4111: <font color="red"><i>$coursename</i></font><br />
 4112: ENDMAPONE
 4113:             if ($uname) {
 4114:                 my $person=&Apache::loncommon::plainname($uname,$udom);
 4115:                 $r->print(" ".&mt("User")."<font color=\"red\"> <i>$uname \($person\) </i></font> \n");
 4116:             } else {
 4117:                 $r->print("<i><font color=\"red\"> ".&mt("ALL")."</i> ".&mt("USERS")."</font> \n");
 4118:             }
 4119: 
 4120:             if ($csec) {$r->print(&mt("Section")."<font color=\"red\"> <i>$csec</i></font>\n")};
 4121:             if ($cgroup) {$r->print(&mt("Group")."<font color=\"red\"> <i>$cgroup</i></font>\n")};
 4122:             $r->print("</h4>\n");
 4123: #---------------------------------------------------------------- print table
 4124:             $r->print('<p>'.&Apache::loncommon::start_data_table()
 4125:                      .&Apache::loncommon::start_data_table_header_row()
 4126:                      .'<th>'.&mt('Parameter Name').'</th>'
 4127:                      .'<th>'.&mt('Default Value').'</th>'
 4128:                      .'<th>'.&mt('Parameter in Effect').'</th>'
 4129:                      .&Apache::loncommon::end_data_table_header_row()
 4130:             );
 4131: 
 4132:             foreach my $item (&keysinorder(\%name,\%keyorder)) {
 4133:                 $r->print(&Apache::loncommon::start_data_table_row());
 4134:                 &print_row($r,$item,\%part,\%name,\%symbp,$mapid,\%default,
 4135:                            \%type,\%display,$defbgone,$defbgtwo,$defbgthree,
 4136:                            $parmlev,$uname,$udom,$csec,$cgroup,'',$noeditgrp,
 4137:                            $readonly);
 4138:             }
 4139:             $r->print(&Apache::loncommon::end_data_table()
 4140:                      .'</p>'
 4141:                      .'</center>'
 4142:             );
 4143:         } # end of $parmlev eq general
 4144:     }
 4145:     $r->print('</form>');
 4146:     if ($numreclinks) {
 4147:         $r->print(<<"END");
 4148: <form name="recurseform" action="/adm/parmset?action=settable" method="post">
 4149: <input type="hidden" name="pschp" />
 4150: <input type="hidden" name="pscat" />
 4151: <input type="hidden" name="psprt" />
 4152: <input type="hidden" name="hideparmsel" value="hidden" />
 4153: </form>
 4154: <script type="text/javascript">
 4155: function pjumprec(rid,name,part) {
 4156:     document.forms.recurseform.pschp.value = rid;
 4157:     document.forms.recurseform.pscat.value = name;
 4158:     document.forms.recurseform.psprt.value = part;
 4159:     document.forms.recurseform.submit();
 4160:     return false;
 4161: }
 4162: </script>
 4163: END
 4164:     }
 4165:     &endSettingsScreen($r);
 4166:     $r->print(&Apache::loncommon::end_page());
 4167: } # end sub assessparms
 4168: 
 4169: 
 4170: 
 4171: ##################################################
 4172: # OVERVIEW MODE
 4173: ##################################################
 4174: 
 4175: my $tableopen; # boolean, true if HTML table is already opened
 4176: 
 4177: # Returns HTML with the HTML table start tag and header, unless the table is already opened.
 4178: # @param {boolean} $readonly - true if values cannot be edited (otherwise more columns are added)
 4179: # @returns {string}
 4180: sub tablestart {
 4181:     my ($readonly,$is_map) = @_;
 4182:     if ($tableopen) {
 4183:         return '';
 4184:     } else {
 4185:         $tableopen=1;
 4186:         my $output = &Apache::loncommon::start_data_table().'<tr><th>'.&mt('Parameter').'</th>';
 4187:         if ($readonly) {
 4188:             $output .= '<th>'.&mt('Current value').'</th>';
 4189:         } else {
 4190:             $output .= '<th>'.&mt('Delete').'</th>'.
 4191:                        '<th>'.&mt('Set to ...').'</th>';
 4192:             if ($is_map) {
 4193:                 $output .= '<th>'.&mt('Recursive?').'</th>';
 4194:             }
 4195:         }
 4196:         $output .= '</tr>';
 4197:         return $output;
 4198:     }
 4199: }
 4200: 
 4201: # Returns HTML with the HTML table end tag, unless the table is not opened.
 4202: # @returns {string}
 4203: sub tableend {
 4204:     if ($tableopen) {
 4205:         $tableopen=0;
 4206:         return &Apache::loncommon::end_data_table();
 4207:     } else {
 4208:         return'';
 4209:     }
 4210: }
 4211: 
 4212: # Reads course and user information.
 4213: # If the context is looking for a scalar, returns the course parameters hash (result of lonnet::get_courseresdata, dump of course's resourcedata.db) with added student data from lonnet::get_userresdata (which reads the user's resourcedata.db).
 4214: # The key for student data is modified with '[useropt:'.username.':'.userdomain.'].'.
 4215: # If the context is looking for a list, returns a list with the scalar data and the class list.
 4216: # @param {string} $crs - course number
 4217: # @param {string} $dom - course domain
 4218: # @returns {hash reference|Array}
 4219: sub readdata {
 4220:     my ($crs,$dom)=@_;
 4221: # Read coursedata
 4222:     my $resourcedata=&Apache::lonnet::get_courseresdata($crs,$dom);
 4223: # Read userdata
 4224: 
 4225:     my $classlist=&Apache::loncoursedata::get_classlist();
 4226:     foreach my $user (keys(%$classlist)) {
 4227:         if ($user=~/^($match_username)\:($match_domain)$/) {
 4228:             my ($tuname,$tudom)=($1,$2);
 4229:             my $useropt=&Apache::lonnet::get_userresdata($tuname,$tudom);
 4230:             foreach my $userkey (keys(%{$useropt})) {
 4231:                 if ($userkey=~/^\Q$env{'request.course.id'}\E/) {
 4232:                     my $newkey=$userkey;
 4233:                     $newkey=~s/^($env{'request.course.id'}\.)/$1\[useropt\:$tuname\:$tudom\]\./;
 4234:                     $$resourcedata{$newkey}=$$useropt{$userkey};
 4235:                 }
 4236:             }
 4237:         }
 4238:     }
 4239:     if (wantarray) {
 4240:         return ($resourcedata,$classlist);
 4241:     } else {
 4242:         return $resourcedata;
 4243:     }
 4244: }
 4245: 
 4246: 
 4247: # Stores parameter data, using form parameters directly.
 4248: #
 4249: # Uses the following form parameters. The variable part in the names is a resourcedata key (except for a modification for user data).
 4250: # set_* (except settext, setipallow, setipdeny, setdeeplink) - set a parameter value
 4251: # del_* - remove a parameter
 4252: # datepointer_* - set a date parameter (value is key_* refering to a set of other form parameters)
 4253: # dateinterval_* - set a date interval parameter (value refers to more form parameters)
 4254: # key_* - date values
 4255: # days_* - for date intervals
 4256: # hours_* - for date intervals
 4257: # minutes_* - for date intervals
 4258: # seconds_* - for date intervals
 4259: # done_* - for date intervals
 4260: # typeof_* - parameter type
 4261: # 
 4262: # @param {Apache2::RequestRec} $r - the Apache request
 4263: # @param {string} $crs - course number
 4264: # @param {string} $dom - course domain
 4265: sub storedata {
 4266:     my ($r,$crs,$dom)=@_;
 4267: # Set userlevel immediately
 4268: # Do an intermediate store of course level
 4269:     my $olddata=&readdata($crs,$dom);
 4270:     my %newdata=();
 4271:     undef %newdata;
 4272:     my @deldata=();
 4273:     my @delrec=();
 4274:     my @delnonrec=();
 4275:     undef @deldata;
 4276:     my ($got_chostname,$chostname,$cmajor,$cminor);
 4277:     my $now = time;
 4278:     foreach my $key (keys(%env)) {
 4279:         if ($key =~ /^form\.([a-z]+)\_(.+)$/) {
 4280:             my $cmd=$1;
 4281:             my $thiskey=$2;
 4282:             my ($altkey,$recursive,$tkey,$tkeyrec,$tkeynonrec);
 4283:             next if ($cmd eq 'rec' || $cmd eq 'settext' || $cmd eq 'setipallow' || $cmd eq 'setipdeny' || $cmd eq 'setdeeplink');
 4284:             if ((($cmd eq 'set') || ($cmd eq 'datepointer') || ($cmd eq 'dateinterval') || ($cmd eq 'del')) && 
 4285:                  ($thiskey =~ /(?:sequence|page)\Q___(all)\E/)) {
 4286:                 unless ($thiskey =~ /(encrypturl|hiddenresource)$/) {
 4287:                     $altkey = $thiskey;
 4288:                     $altkey =~ s/\Q___(all)\E/___(rec)/;
 4289:                     if ($env{'form.rec_'.$thiskey}) {
 4290:                         $recursive = 1;
 4291:                     }
 4292:                 }
 4293:             }
 4294:             my ($tuname,$tudom)=&extractuser($thiskey);
 4295:             if ($tuname) {
 4296:                 $tkey=$thiskey;
 4297:                 $tkey=~s/\.\[useropt\:$tuname\:$tudom\]\./\./;
 4298:                 if ($altkey) {
 4299:                     $tkeynonrec = $tkey; 
 4300:                     $tkeyrec = $altkey;
 4301:                     $tkeyrec=~s/\.\[useropt\:$tuname\:$tudom\]\./\./;
 4302:                 }
 4303:             }
 4304:             if ($cmd eq 'set' || $cmd eq 'datepointer' || $cmd eq 'dateinterval') {
 4305:                 my ($data, $typeof, $text, $name, $valchk, $valmatch, $namematch);
 4306:                 if ($cmd eq 'set') {
 4307:                     $data=$env{$key};
 4308:                     $valmatch = '';
 4309:                     $valchk = $data;
 4310:                     $typeof=$env{'form.typeof_'.$thiskey};
 4311:                     $text = &mt('Saved modified parameter for');
 4312:                     if ($typeof eq 'string_questiontype') {
 4313:                         $name = 'type';
 4314:                     } elsif (($typeof eq 'string_lenient') || ($typeof eq 'string_deeplink')) {
 4315:                         ($name) = ($typeof =~ /^string_(lenient|deeplink)$/);
 4316:                         my $stringmatch = &standard_string_matches($typeof);
 4317:                         if (ref($stringmatch) eq 'ARRAY') {
 4318:                             foreach my $item (@{$stringmatch}) {
 4319:                                 if (ref($item) eq 'ARRAY') {
 4320:                                     my ($regexpname,$pattern) = @{$item};
 4321:                                     if ($pattern ne '') {
 4322:                                         if ($data =~ /$pattern/) {
 4323:                                             $valmatch = $regexpname;
 4324:                                             $valchk = '';
 4325:                                             last;
 4326:                                         }
 4327:                                     }
 4328:                                 }
 4329:                             }
 4330:                         }
 4331:                     } elsif ($typeof eq 'string_discussvote') {
 4332:                         $name = 'discussvote';
 4333:                     } elsif ($typeof eq 'string_examcode') {
 4334:                         $name = 'examcode';
 4335:                         if (&Apache::lonnet::validCODE($data)) {
 4336:                             $valchk = 'valid';
 4337:                         }
 4338:                     } elsif ($typeof eq 'string_yesno') {
 4339:                         if ($thiskey =~ /\.retrypartial$/) {
 4340:                             $name = 'retrypartial';
 4341:                         }
 4342:                     }
 4343:                 } elsif ($cmd eq 'datepointer') {
 4344:                     $data=&Apache::lonhtmlcommon::get_date_from_form($env{$key});
 4345:                     $typeof=$env{'form.typeof_'.$thiskey};
 4346:                     $text = &mt('Saved modified date for');
 4347:                     if ($typeof eq 'date_start') {
 4348:                         if ($thiskey =~ /\.printstartdate$/) {
 4349:                             $name = 'printstartdate';
 4350:                             if (($data) && ($data > $now)) {
 4351:                                 $valchk = 'future';
 4352:                             }
 4353:                         }
 4354:                     } elsif ($typeof eq 'date_end') {
 4355:                         if ($thiskey =~ /\.printenddate$/) {
 4356:                             $name = 'printenddate';
 4357:                             if (($data) && ($data < $now)) {
 4358:                                 $valchk = 'past';
 4359:                             }
 4360:                         }
 4361:                     }
 4362:                 } elsif ($cmd eq 'dateinterval') {
 4363:                     $data=&get_date_interval_from_form($thiskey);
 4364:                     if ($thiskey =~ /\.interval$/) {
 4365:                         $name = 'interval';
 4366:                         my $intervaltype = &get_intervaltype($name);
 4367:                         my $intervalmatch = &standard_interval_matches($intervaltype);
 4368:                         if (ref($intervalmatch) eq 'ARRAY') {
 4369:                             foreach my $item (@{$intervalmatch}) {
 4370:                                 if (ref($item) eq 'ARRAY') {
 4371:                                     my ($regexpname,$pattern) = @{$item};
 4372:                                     if ($pattern ne '') {
 4373:                                         if ($data =~ /$pattern/) {
 4374:                                             $valmatch = $regexpname;
 4375:                                             $valchk = '';
 4376:                                             last;
 4377:                                         }
 4378:                                     }
 4379:                                 }
 4380:                             }
 4381:                         }
 4382:                     }
 4383:                     $typeof=$env{'form.typeof_'.$thiskey};
 4384:                     $text = &mt('Saved modified date for');
 4385:                 }
 4386:                 if ($recursive) {
 4387:                     $namematch = 'maplevelrecurse';
 4388:                 }
 4389:                 if (($name ne '') || ($namematch ne '')) {
 4390:                     my ($needsrelease,$needsnewer);
 4391:                     if ($name ne '') {
 4392:                         $needsrelease = $Apache::lonnet::needsrelease{"parameter:$name:$valchk:$valmatch:"};
 4393:                         if ($needsrelease) {
 4394:                             unless ($got_chostname) {
 4395:                                 ($chostname,$cmajor,$cminor)=&parameter_release_vars();
 4396:                                 $got_chostname = 1;
 4397:                             }
 4398:                             $needsnewer = &parameter_releasecheck($name,$valchk,$valmatch,undef,
 4399:                                                                 $needsrelease,
 4400:                                                                 $cmajor,$cminor);
 4401:                         }
 4402:                     }
 4403:                     if ($namematch ne '') {
 4404:                         if ($needsnewer) {
 4405:                             undef($namematch);
 4406:                         } else {
 4407:                             my $currneeded;
 4408:                             if ($needsrelease) {
 4409:                                 $currneeded = $needsrelease;
 4410:                             }
 4411:                             $needsrelease =
 4412:                                 $Apache::lonnet::needsrelease{"parameter::::$namematch"};
 4413:                             if (($needsrelease) &&
 4414:                                     (($currneeded eq '') || ($needsrelease < $currneeded))) {
 4415:                                 unless ($got_chostname) {
 4416:                                     ($chostname,$cmajor,$cminor) = &parameter_release_vars();
 4417:                                     $got_chostname = 1;
 4418:                                 }
 4419:                                 $needsnewer = &parameter_releasecheck(undef,$valchk,$valmatch,
 4420:                                     $namematch, $needsrelease,$cmajor,$cminor);
 4421:                             } else {
 4422:                                 undef($namematch);
 4423:                             }
 4424:                         }
 4425:                     }
 4426:                     if ($needsnewer) {
 4427:                         $r->print('<br />'.&oldversion_warning($name,$namematch,$data,
 4428:                                                             $chostname,$cmajor,
 4429:                                                             $cminor,$needsrelease));
 4430:                         next;
 4431:                     }
 4432:                 }
 4433:                 my ($reconlychg,$haschange,$storekey);
 4434:                 if ($tuname) {
 4435:                     my $ustorekey;
 4436:                     if ($altkey) {
 4437:                         if ($recursive) {
 4438:                             if (exists($$olddata{$thiskey})) {
 4439:                                 if ($$olddata{$thiskey} eq $data) {
 4440:                                     $reconlychg = 1;
 4441:                                 }
 4442:                                 &Apache::lonnet::del('resourcedata',[$tkeynonrec,$tkeynonrec.'.type'],$tudom,$tuname);
 4443:                             }
 4444:                             if (exists($$olddata{$altkey})) {
 4445:                                 if (defined($data) && $$olddata{$altkey} ne $data) {
 4446:                                     $haschange = 1;
 4447:                                 }
 4448:                             } elsif ((!$reconlychg) && ($data ne '')) {
 4449:                                 $haschange = 1;
 4450:                             }
 4451:                             $ustorekey = $tkeyrec;
 4452:                         } else {
 4453:                             if (exists($$olddata{$altkey})) {
 4454:                                 if ($$olddata{$altkey} eq $data) {
 4455:                                     $reconlychg = 1;
 4456:                                 }
 4457:                                 &Apache::lonnet::del('resourcedata',[$tkeyrec,$tkeyrec.'.type'],$tudom,$tuname);
 4458:                             }
 4459:                             if (exists($$olddata{$thiskey})) {
 4460:                                 if (defined($data) && $$olddata{$thiskey} ne $data) {
 4461:                                     $haschange = 1;
 4462:                                 }
 4463:                             } elsif ((!$reconlychg) && ($data ne '')) {
 4464:                                 $haschange = 1;
 4465:                             }
 4466:                             $ustorekey = $tkeynonrec;
 4467:                         }
 4468:                     } else {
 4469:                         if (exists($$olddata{$tkey})) {
 4470:                             if (defined($data) && $$olddata{$tkey} ne $data) {
 4471:                                 $haschange = 1;
 4472:                             }
 4473:                             $ustorekey = $tkey;
 4474:                         }
 4475:                     }
 4476:                     if ($haschange || $reconlychg)  {
 4477:                         unless ($env{'form.del_'.$thiskey}) {
 4478:                             if (&Apache::lonnet::put('resourcedata',{$ustorekey=>$data,
 4479:                                                                      $ustorekey.'.type' => $typeof},
 4480:                                                                      $tudom,$tuname) eq 'ok') {
 4481:                                 &log_parmset({$ustorekey=>$data,$ustorekey.'.type' => $typeof},0,$tuname,$tudom);
 4482:                                 $r->print('<br />'.$text.' '.
 4483:                                           &Apache::loncommon::plainname($tuname,$tudom));
 4484:                             } else {
 4485:                                 $r->print('<div class="LC_error">'.
 4486:                                           &mt('Error saving parameters').'</div>');
 4487:                             }
 4488:                             &Apache::lonnet::devalidateuserresdata($tuname,$tudom);
 4489:                         }
 4490:                     }
 4491:                 } else {
 4492:                     if ($altkey) {
 4493:                         if ($recursive) {
 4494:                             if (exists($$olddata{$thiskey})) {
 4495:                                 if ($$olddata{$thiskey} eq $data) {
 4496:                                     $reconlychg = 1;
 4497:                                 }
 4498:                                 push(@delnonrec,($thiskey,$thiskey.'.type'));
 4499:                             }
 4500:                             if (exists($$olddata{$altkey})) {
 4501:                                 if (defined($data) && $$olddata{$altkey} ne $data) {
 4502:                                     $haschange = 1;
 4503:                                 }
 4504:                             } elsif (($data ne '') && (!$reconlychg)) {
 4505:                                 $haschange = 1;
 4506:                             }
 4507:                             $storekey = $altkey;
 4508:                         } else {
 4509:                             if (exists($$olddata{$altkey})) {
 4510:                                 if ($$olddata{$altkey} eq $data) {
 4511:                                     $reconlychg = 1;
 4512:                                 }
 4513:                                 push(@delrec,($altkey,$altkey.'.type'));
 4514:                             } 
 4515:                             if (exists($$olddata{$thiskey})) {
 4516:                                 if (defined($data) && $$olddata{$thiskey} ne $data) {
 4517:                                     $haschange = 1;
 4518:                                 }
 4519:                             } elsif (($data ne '') && (!$reconlychg)) {
 4520:                                 $haschange = 1;
 4521:                             }
 4522:                             $storekey = $thiskey;
 4523:                         }
 4524:                     } else {
 4525:                         if (defined($data) && $$olddata{$thiskey} ne $data) {
 4526:                             $haschange = 1;
 4527:                             $storekey = $thiskey;
 4528:                         }
 4529:                     }
 4530:                 }
 4531:                 if ($reconlychg || $haschange) {
 4532:                     unless ($env{'form.del_'.$thiskey}) {
 4533:                         $newdata{$storekey}=$data;
 4534:                         $newdata{$storekey.'.type'}=$typeof;
 4535:                     }
 4536:                 }
 4537:             } elsif ($cmd eq 'del') {
 4538:                 if ($tuname) {
 4539:                     my $error;
 4540:                     if ($altkey) {  
 4541:                         if (exists($$olddata{$altkey})) {
 4542:                             if (&Apache::lonnet::del('resourcedata',[$tkeyrec,$tkeyrec.'.type'],$tudom,$tuname) eq 'ok') {
 4543:                                 &log_parmset({$tkeyrec=>''},1,$tuname,$tudom);
 4544:                                 if ($recursive) {
 4545:                                     $r->print('<br />'.&mt('Deleted parameter for').' '.&Apache::loncommon::plainname($tuname,$tudom));
 4546:                                 }
 4547:                             } elsif ($recursive) {
 4548:                                 $error = 1;
 4549:                             }
 4550:                         }
 4551:                         if (exists($$olddata{$thiskey})) {
 4552:                             if (&Apache::lonnet::del('resourcedata',[$tkeynonrec,$tkeynonrec.'.type'],$tudom,$tuname) eq 'ok') {
 4553:                                 &log_parmset({$tkeynonrec=>''},1,$tuname,$tudom);
 4554:                                 unless ($recursive) {
 4555:                                     $r->print('<br />'.&mt('Deleted parameter for').' '.&Apache::loncommon::plainname($tuname,$tudom));
 4556:                                 }
 4557:                             } elsif (!$recursive) {
 4558:                                 $error = 1;
 4559:                             }
 4560:                         }
 4561:                     } else {
 4562:                         if (exists($$olddata{$thiskey})) {
 4563:                             if (&Apache::lonnet::del('resourcedata',[$tkey,$tkey.'.type'],$tudom,$tuname) eq 'ok') {
 4564:                                 &log_parmset({$tkey=>''},1,$tuname,$tudom);
 4565:                                 $r->print('<br />'.&mt('Deleted parameter for').' '.&Apache::loncommon::plainname($tuname,$tudom));
 4566:                             } else {
 4567:                                 $error = 1;
 4568:                             }
 4569:                         }
 4570:                     }
 4571:                     if ($error) { 
 4572:                         $r->print('<div class="LC_error">'.
 4573:                             &mt('Error deleting parameters').'</div>');
 4574:                     }
 4575:                     &Apache::lonnet::devalidateuserresdata($tuname,$tudom);
 4576:                 } else {
 4577:                     if ($altkey) {
 4578:                         if (exists($$olddata{$altkey})) {
 4579:                             unless (grep(/^\Q$altkey\E$/,@delrec)) {
 4580:                                 push(@deldata,($altkey,$altkey.'.type'));
 4581:                             }
 4582:                         }
 4583:                         if (exists($$olddata{$thiskey})) {
 4584:                             unless (grep(/^\Q$thiskey\E$/,@delnonrec)) {
 4585:                                 push(@deldata,($thiskey,$thiskey.'.type'));
 4586:                             }
 4587:                         }
 4588:                     } elsif (exists($$olddata{$thiskey})) {
 4589:                         push(@deldata,($thiskey,$thiskey.'.type'));
 4590:                     }
 4591:                 }
 4592:             }
 4593:         }
 4594:     }
 4595: # Store all course level
 4596:     my $delentries=$#deldata+1;
 4597:     my @alldels;
 4598:     if (@delrec) {
 4599:         push(@alldels,@delrec);
 4600:     }
 4601:     if (@delnonrec) {
 4602:         push(@alldels,@delnonrec);
 4603:     }
 4604:     if (@deldata) {
 4605:         push(@alldels,@deldata);
 4606:     }
 4607:     my @newdatakeys=keys(%newdata);
 4608:     my $putentries=$#newdatakeys+1;
 4609:     my ($delresult,$devalidate);
 4610:     if (@alldels) {
 4611:         if (&Apache::lonnet::del('resourcedata',\@alldels,$dom,$crs) eq 'ok') {
 4612:             my %loghash=map { $_ => '' } @alldels;
 4613:             &log_parmset(\%loghash,1);
 4614:             if ($delentries) {
 4615:                 $r->print('<h2>'.&mt('Deleted [quant,_1,parameter]',$delentries/2).'</h2>');
 4616:             }
 4617:         } elsif ($delentries) {
 4618:             $r->print('<div class="LC_error">'.
 4619:                 &mt('Error deleting parameters').'</div>');
 4620:         }
 4621:         $devalidate = 1; 
 4622:     }
 4623:     if ($putentries) {
 4624:         if (&Apache::lonnet::put('resourcedata',\%newdata,$dom,$crs) eq 'ok') {
 4625:                     &log_parmset(\%newdata,0);
 4626:             $r->print('<h3>'.&mt('Saved [quant,_1,parameter]',$putentries/2).'</h3>');
 4627:         } else {
 4628:             $r->print('<div class="LC_error">'.
 4629:                 &mt('Error saving parameters').'</div>');
 4630:         }
 4631:         $devalidate = 1; 
 4632:     }
 4633:     if ($devalidate) {
 4634:         &Apache::lonnet::devalidatecourseresdata($crs,$dom);
 4635:     }
 4636: }
 4637: 
 4638: # Returns the username and domain from a key created in readdata from a resourcedata key.
 4639: #
 4640: # @param {string} $key - the key
 4641: # @returns {Array}
 4642: sub extractuser {
 4643:     my $key=shift;
 4644:     return ($key=~/^$env{'request.course.id'}.\[useropt\:($match_username)\:($match_domain)\]\./);
 4645: }
 4646: 
 4647: # Parses a parameter key and returns the components.
 4648: #
 4649: # @param {string} $key - 
 4650: # @param {hash reference} $listdata - 
 4651: # @return {Array} - (student, resource, part, parameter)
 4652: sub parse_listdata_key {
 4653:     my ($key,$listdata) = @_;
 4654:     # split into student/section affected, and
 4655:     # the realm (folder/resource part and parameter
 4656:     my ($student,$realm) =
 4657:     ($key=~/^\Q$env{'request.course.id'}\E\.\[([^\.]+)\]\.(.+)$/);
 4658:     # if course wide student would be undefined
 4659:     if (!defined($student)) {
 4660:         ($realm)=($key=~/^\Q$env{'request.course.id'}\E\.(.+)$/);
 4661:     }
 4662:     # strip off the .type if it's not the Question type parameter
 4663:     if ($realm=~/\.type$/ && !exists($listdata->{$key.'.type'})) {
 4664:         $realm=~s/\.type//;
 4665:     }
 4666:     # split into resource+part and parameter name
 4667:     my ($res,    $parm) = ($realm=~/^(.*)\.(.*)$/);
 4668:        ($res, my $part) = ($res  =~/^(.*)\.(.*)$/);
 4669:     return ($student,$res,$part,$parm);
 4670: }
 4671: 
 4672: # Prints HTML with forms for the given parameter data in overview mode (newoverview or overview).
 4673: #
 4674: # @param {Apache2::RequestRec} $r - the Apache request
 4675: # @param {hash reference} $resourcedata - parameter data returned by readdata
 4676: # @param {hash reference} $listdata - data created in secgroup_lister, course id.[section id].part.name -> 1 or course id.[section id].part.name.type -> parameter type
 4677: # @param {string} $sortorder - realmstudent|studentrealm
 4678: # @param {string} $caller - name of the calling sub (overview|newoverview)
 4679: # @param {hash reference} $classlist - from loncoursedata::get_classlist
 4680: # @param {boolean} $readonly - true if editing not allowed
 4681: # @returns{integer} - number of $listdata parameters processed
 4682: sub listdata {
 4683:     my ($r,$resourcedata,$listdata,$sortorder,$caller,$classlist,$readonly)=@_;
 4684:     
 4685: # Start list output
 4686: 
 4687:     my $oldsection='';
 4688:     my $oldrealm='';
 4689:     my $oldpart='';
 4690:     my $pointer=0;
 4691:     $tableopen=0;
 4692:     my $foundkeys=0;
 4693:     my %keyorder=&standardkeyorder();
 4694:     my $readonlyall = $readonly;
 4695: 
 4696:     my ($secidx,%grouphash);
 4697:     if (($env{'request.course.sec'} ne '') && ($caller eq 'overview')) {
 4698:         $secidx = &Apache::loncoursedata::CL_SECTION();
 4699:         if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
 4700:             %grouphash = &Apache::longroup::coursegroups();
 4701:         } elsif ($env{'request.course.groups'} ne '') {
 4702:             map { $grouphash{$_} = 1; } split(/:/,$env{'request.course.groups'});
 4703:         }
 4704:     }
 4705: 
 4706:     foreach my $key (sort {
 4707:         my ($astudent,$ares,$apart,$aparm) = &parse_listdata_key($a,$listdata);
 4708:         my ($bstudent,$bres,$bpart,$bparm) = &parse_listdata_key($b,$listdata);
 4709: 
 4710:         # get the numerical order for the param
 4711:         $aparm=$keyorder{'parameter_0_'.$aparm};
 4712:         $bparm=$keyorder{'parameter_0_'.$bparm};
 4713: 
 4714:         my $result=0;
 4715: 
 4716:         if ($sortorder eq 'realmstudent') {
 4717:             if ($ares     ne $bres    ) {
 4718:                 $result = ($ares     cmp $bres);
 4719:             } elsif ($astudent ne $bstudent) {
 4720:                 $result = ($astudent cmp $bstudent);
 4721:             } elsif ($apart    ne $bpart   ) {
 4722:                 $result = ($apart    cmp $bpart);
 4723:             }
 4724:         } else {
 4725:             if      ($astudent ne $bstudent) {
 4726:                 $result = ($astudent cmp $bstudent);
 4727:             } elsif ($ares     ne $bres    ) {
 4728:                 $result = ($ares     cmp $bres);
 4729:             } elsif ($apart    ne $bpart   ) {
 4730:                 $result = ($apart    cmp $bpart);
 4731:             }
 4732:         }
 4733: 
 4734:         if (!$result) {
 4735:             if (defined($aparm) && defined($bparm)) {
 4736:                 $result = ($aparm <=> $bparm);
 4737:             } elsif (defined($aparm)) {
 4738:                 $result = -1;
 4739:             } elsif (defined($bparm)) {
 4740:                 $result = 1;
 4741:             }
 4742:         }
 4743: 
 4744:         $result;
 4745:         
 4746:     } keys(%{$listdata})) { # foreach my $key
 4747:         my $thiskey = $key;
 4748:         if ($$listdata{$thiskey.'.type'}) {
 4749:             my $thistype=$$listdata{$thiskey.'.type'};
 4750:             if ($$resourcedata{$thiskey.'.type'}) {
 4751:                 $thistype=$$resourcedata{$thiskey.'.type'};
 4752:             }
 4753:             my ($middle,$part,$name)=
 4754:                 ($thiskey=~/^$env{'request.course.id'}\.(?:(.+)\.)*([\w\s\-]+)\.(\w+)$/);
 4755:             my $section=&mt('All Students');
 4756:             $readonly = $readonlyall;
 4757:             my $userscope;
 4758:             my $showval = $$resourcedata{$thiskey}; 
 4759:             if ($middle=~/^\[(.*)\]/) {
 4760:                 my $issection=$1;
 4761:                 if ($issection=~/^useropt\:($match_username)\:($match_domain)/) {
 4762:                     my ($stuname,$studom) = ($1,$2);
 4763:                     if (($env{'request.course.sec'} ne '') && ($caller eq 'overview')) {
 4764:                         if (ref($classlist) eq 'HASH') {
 4765:                             if (ref($classlist->{$stuname.':'.$studom}) eq 'ARRAY') {
 4766:                                 next unless ($classlist->{$stuname.':'.$studom}->[$secidx] eq $env{'request.course.sec'}); 
 4767:                             }
 4768:                         }
 4769:                     }
 4770:                     $section=&mt('User').": ".&Apache::loncommon::plainname($stuname,$studom);
 4771:                     $userscope = 1;
 4772:                 } else {
 4773:                     if (($env{'request.course.sec'} ne '') && ($caller eq 'overview')) {
 4774:                         if (exists($grouphash{$issection})) {
 4775:                             $section=&mt('Group').': '.$issection;
 4776:                         } elsif ($issection eq $env{'request.course.sec'}) {
 4777:                             $section = &mt('Section').': '.$issection;
 4778:                         } else {
 4779:                             next; 
 4780:                         }
 4781:                     } else {
 4782:                         $section=&mt('Group/Section').': '.$issection;
 4783:                     }
 4784:                 }
 4785:                 $middle=~s/^\[(.*)\]//;
 4786:             } elsif (($env{'request.course.sec'} ne '') && ($caller eq 'overview')) {
 4787:                 $readonly = 1;
 4788:             }
 4789:             $middle=~s/\.+$//;
 4790:             $middle=~s/^\.+//;
 4791:             my $realm='<span class="LC_parm_scope_all">'.&mt('All Resources').'</span>';
 4792:             my ($is_map,$is_recursive,$mapurl,$maplevel);
 4793:             if ($caller eq 'overview') {
 4794:                 if ($middle=~/^(.+)\_\_\_\((all|rec)\)$/) {
 4795:                     $mapurl = $1;
 4796:                     $maplevel = $2;
 4797:                     $is_map = 1;
 4798:                 }
 4799:             } elsif ($caller eq 'newoverview') {
 4800:                 if ($middle=~/^(.+)\_\_\_\((all)\)$/) {
 4801:                     $mapurl = $1;
 4802:                     $maplevel = $2;
 4803:                     $is_map = 1;
 4804:                 }
 4805:             }
 4806:             if ($is_map) {
 4807:                 my $leveltitle = &mt('Folder/Map');
 4808:                 unless (($name eq 'hiddenresource') || ($name eq 'encrypturl')) {   
 4809:                     if ($caller eq 'newoverview') {
 4810:                         my $altkey = $thiskey;
 4811:                         $altkey =~ s/\Q___(all)\E/___(rec)/;
 4812:                         if ((exists($$resourcedata{$altkey})) & (!exists($$resourcedata{$thiskey}))) {
 4813:                             $is_recursive = 1;
 4814:                             if ($$resourcedata{$altkey.'.type'}) {
 4815:                                 $thistype=$$resourcedata{$altkey.'.type'};
 4816:                             }
 4817:                             $showval = $$resourcedata{$altkey};
 4818:                         }
 4819:                     } elsif (($caller eq 'overview') && ($maplevel eq 'rec')) {
 4820:                         $thiskey =~ s/\Q___(rec)\E/___(all)/;
 4821:                         $is_recursive = 1;
 4822:                     }
 4823:                 }
 4824:                 $realm='<span class="LC_parm_scope_folder">'.$leveltitle.': '.&Apache::lonnet::gettitle($mapurl).' <br /><span class="LC_parm_folder">('.$mapurl.')</span></span>';
 4825:             } elsif ($middle) {
 4826:                 my ($map,$id,$url)=&Apache::lonnet::decode_symb($middle);
 4827:                 $realm='<span class="LC_parm_scope_resource">'.&mt('Resource').
 4828:                     ': '.&Apache::lonnet::gettitle($middle).
 4829:                     ' <br /><span class="LC_parm_symb">('.$url.' in '.$map.' id: '.
 4830:                     $id.')</span></span>';
 4831:             }
 4832:             if ($sortorder eq 'realmstudent') {
 4833:                 if ($realm ne $oldrealm) {
 4834:                     $r->print(&tableend()."\n<hr /><h1>$realm</h1>");
 4835:                     $oldrealm=$realm;
 4836:                     $oldsection='';
 4837:                 }
 4838:                 if ($section ne $oldsection) {
 4839:                     $r->print(&tableend()."\n<h2>$section</h2>");
 4840:                     $oldsection=$section;
 4841:                     $oldpart='';
 4842:                 }
 4843:             } else {
 4844:                 if ($section ne $oldsection) {
 4845:                     $r->print(&tableend()."\n<hr /><h1>$section</h1>");
 4846:                     $oldsection=$section;
 4847:                     $oldrealm='';
 4848:                 }
 4849:                 if ($realm ne $oldrealm) {
 4850:                     $r->print(&tableend()."\n<h2>$realm</h2>");
 4851:                     $oldrealm=$realm;
 4852:                     $oldpart='';
 4853:                 }
 4854:             }
 4855:             if ($part ne $oldpart) {
 4856:                 $r->print(&tableend().
 4857:                     "\n".'<span class="LC_parm_part">'.&mt('Part').": $part</span>");
 4858:                 $oldpart=$part;
 4859:             }
 4860:     #
 4861:     # Ready to print
 4862:     #
 4863:             my $parmitem = &standard_parameter_names($name);
 4864:             $r->print(&tablestart($readonly,$is_map).
 4865:                 &Apache::loncommon::start_data_table_row().
 4866:                 '<td><b>'.&mt($parmitem).
 4867:                 '</b></td>');
 4868:             unless ($readonly) {
 4869:                 my $disabled;
 4870:                 if (($name eq 'availablestudent') &&
 4871:                     (($showval eq '') || ($userscope))) {
 4872:                     $disabled = ' disabled="disabled"';
 4873:                 }
 4874:                 $r->print('<td><input type="checkbox" name="del_'.
 4875:                         $thiskey.'"'.$disabled.' /></td>');
 4876:             }
 4877:             $r->print('<td>');
 4878:             $foundkeys++;
 4879:             if (&isdateparm($thistype)) {
 4880:                 my $jskey='key_'.$pointer;
 4881:                 my $state;
 4882:                 $pointer++;
 4883:                 if ($readonly) {
 4884:                     $state = 'disabled';
 4885:                 }
 4886:                 $r->print(
 4887:                     &Apache::lonhtmlcommon::date_setter('parmform',
 4888:                                                         $jskey,
 4889:                                                         $showval,
 4890:                                                         '',1,$state));
 4891:                 unless  ($readonly) {
 4892:                     $r->print(
 4893:     '<input type="hidden" name="datepointer_'.$thiskey.'" value="'.$jskey.'" />'.
 4894:     (($showval!=0)?'<span class="LC_nobreak"><a href="/adm/parmset?&action=dateshift1&timebase='.$showval.'">'.
 4895:     &mt('Shift all dates based on this date').'</a></span>':'').
 4896:     &date_sanity_info($showval)
 4897:                     );
 4898:                 }
 4899:             } elsif ($thistype eq 'date_interval') {
 4900:                 $r->print(&date_interval_selector($thiskey,$name,
 4901:                           $showval,$readonly));
 4902:             } elsif ($thistype =~ m/^string/) {
 4903:                 if ($name eq 'availablestudent') {
 4904:                     $readonly = 1;
 4905:                 }
 4906:                 $r->print(&string_selector($thistype,$thiskey,
 4907:                           $showval,$name,$readonly));
 4908:             } else {
 4909:                 $r->print(&default_selector($thiskey,$showval,$readonly));
 4910:             }
 4911:             unless ($readonly) {
 4912:                 $r->print('<input type="hidden" name="typeof_'.$thiskey.'" value="'.
 4913:                         $thistype.'" />');
 4914:             }
 4915:             $r->print('</td>');
 4916:             if ($is_map) {
 4917:                 if (($name eq 'encrypturl') || ($name eq 'hiddenresource')) {
 4918:                     $r->print('<td><table><tr><td>'.&mt('Yes').'</td></tr></table></td>');
 4919:                 } else {
 4920:                     my ($disabled,$recon,$recoff);
 4921:                     if ($readonly) {
 4922:                         $disabled = ' disabled="disabled"';
 4923:                     }
 4924:                     if ($is_recursive) {
 4925:                         $recon = ' checked="checked"';
 4926:                     } else {
 4927:                         $recoff = ' checked="checked"';
 4928:                     }
 4929:                     $r->print('<td><table><tr><td><label><input type="radio" name="rec_'.$thiskey.'" value="1"'.$recon.$disabled.' />'.&mt('Yes').'</label>'.
 4930:                               '</td><td><label><input type="radio" name="rec_'.$thiskey.'" value="0"'.$recoff.$disabled.' />'.&mt('No').'</label></td></tr></table></td>');
 4931:                 }
 4932:             }
 4933:             $r->print(&Apache::loncommon::end_data_table_row());
 4934:         }
 4935:     }
 4936:     return $foundkeys;
 4937: }
 4938: 
 4939: # Returns a string representing the interval, directly using form data matching the given key.
 4940: # The returned string may also include information related to proctored exams.
 4941: # Format: seconds['_done'[':'done button title':']['_proctor'['_'proctor key]]]
 4942: #
 4943: # @param {string} $key - suffix for form fields related to the interval
 4944: # @returns {string}
 4945: sub get_date_interval_from_form {
 4946:     my ($key) = @_;
 4947:     my $seconds = 0;
 4948:     foreach my $which (['days', 86400],
 4949:                ['hours', 3600],
 4950:                ['minutes', 60],
 4951:                ['seconds',  1]) {
 4952:         my ($name, $factor) = @{ $which };
 4953:         if (defined($env{'form.'.$name.'_'.$key})) {
 4954:             $seconds += $env{'form.'.$name.'_'.$key} * $factor;
 4955:         }
 4956:     }
 4957:     if (($key =~ /\.interval$/) &&
 4958:             (($env{'form.done_'.$key} eq '_done') || ($env{'form.done_'.$key} eq '_done_proctor'))) {
 4959:         if ($env{'form.done_'.$key.'_buttontext'}) {
 4960:             $env{'form.done_'.$key.'_buttontext'} =~ s/\://g;
 4961:             $seconds .= '_done:'.$env{'form.done_'.$key.'_buttontext'}.':';
 4962:             if ($env{'form.done_'.$key} eq '_done_proctor') {
 4963:                 $seconds .= '_proctor';
 4964:             }
 4965:         } else {
 4966:             $seconds .= $env{'form.done_'.$key}; 
 4967:         }
 4968:         if (($env{'form.done_'.$key} eq '_done_proctor') && 
 4969:                 ($env{'form.done_'.$key.'_proctorkey'})) {
 4970:             $seconds .= '_'.$env{'form.done_'.$key.'_proctorkey'};
 4971:         }
 4972:     }
 4973:     return $seconds;
 4974: }
 4975: 
 4976: 
 4977: # Returns HTML to enter a text value for a parameter.
 4978: #
 4979: # @param {string} $thiskey - parameter key
 4980: # @param {string} $showval - the current value
 4981: # @param {boolean} $readonly - true if the field should not be made editable
 4982: # @returns {string}
 4983: sub default_selector {
 4984:     my ($thiskey, $showval, $readonly) = @_;
 4985:     my $disabled;
 4986:     if ($readonly) {
 4987:         $disabled = ' disabled="disabled"';
 4988:     }
 4989:     return '<input type="text" name="set_'.$thiskey.'" value="'.$showval.'"'.$disabled.' />';
 4990: }
 4991: 
 4992: # Returns HTML to enter allow/deny rules related to IP addresses.
 4993: #
 4994: # @param {string} $thiskey - parameter key
 4995: # @param {string} $showval - the current value
 4996: # @param {boolean} $readonly - true if the fields should not be made editable
 4997: # @returns {string}
 4998: sub string_ip_selector {
 4999:     my ($thiskey, $showval, $readonly) = @_;
 5000:     my %access = (
 5001:                    allow => [],
 5002:                    deny  => [],
 5003:                  );
 5004:     if ($showval ne '') {
 5005:         my @current;
 5006:         if ($showval =~ /,/) {
 5007:             @current = split(/,/,$showval);
 5008:         } else {
 5009:             @current = ($showval);
 5010:         }
 5011:         foreach my $item (@current) {
 5012:             if ($item =~ /^\!([\[\]a-zA-Z\.\d\*\-]+)$/) {
 5013:                 push(@{$access{'deny'}},$1);
 5014:             } elsif ($item =~ /^([\[\]a-zA-Z\.\d\*\-]+)$/) {
 5015:                 push(@{$access{'allow'}},$item);
 5016:             }
 5017:         }
 5018:     }
 5019:     if (!@{$access{'allow'}}) {
 5020:         @{$access{'allow'}} = ('');
 5021:     }
 5022:     if (!@{$access{'deny'}}) {
 5023:         @{$access{'deny'}} = ('');
 5024:     }
 5025:     my ($disabled,$addmore);
 5026:     if ($readonly) {
 5027:         $disabled=' disabled="disabled"';
 5028:     } else {
 5029:         $addmore = "\n".'<button class="LC_add_ipacc_button">'.&mt('Add more').'</button>';
 5030:     }
 5031:     my $output = '<input type="hidden" name="set_'.$thiskey.'" />
 5032: <table><tr><th>'.&mt('Allow from').'</th><th>'.&mt('Deny from').'</th></tr><tr>';
 5033:     foreach my $acctype ('allow','deny') {
 5034:         $output .= '
 5035: <td valign="top">
 5036: <div class="LC_string_ipacc_wrap" id="LC_string_ipacc_'.$acctype.'_'.$thiskey.'">
 5037:   <div class="LC_string_ipacc_inner">'."\n";
 5038:         my $num = 0;
 5039:         foreach my $curr (@{$access{$acctype}}) {
 5040:             $output .= '<div><input type="text" name="setip'.$acctype.'_'.$thiskey.'" value="'.$curr.'"'.$disabled.' />';
 5041:             if ($num > 0) {
 5042:                 $output .= '<a href="#" class="LC_remove_ipacc">'.&mt('Remove').'</a>'; 
 5043:             }
 5044:             $output .= '</div>'."\n";
 5045:             $num ++;
 5046:         }
 5047:         $output .= '
 5048:   </div>'.$addmore.'
 5049: </div>
 5050: </td>';
 5051:    }
 5052:    $output .= '
 5053: </tr>
 5054: </table>'."\n";
 5055:     return $output;
 5056: }
 5057: 
 5058: sub string_deeplink_selector {
 5059:     my ($thiskey, $showval, $readonly) = @_;
 5060:     my (@components,%values,@current,%titles,%options,%optiontext,%defaults,
 5061:         %selectnull,%domlti,%crslti,@possmenus);
 5062:     @components = ('state','others','listing','scope','protect','menus');
 5063:     %titles = &Apache::lonlocal::texthash (
 5064:                   state   => 'Access status',
 5065:                   others  => 'Hide other resources',
 5066:                   listing => 'In Contents and/or Gradebook',
 5067:                   scope   => 'Access scope for link',
 5068:                   protect => 'Link protection',
 5069:                   menus   => 'Menu Items Displayed',
 5070:               );
 5071:     %options = (
 5072:                    state   => ['only','off','both'],
 5073:                    others  => ['hide','unhide'],
 5074:                    listing => ['full','absent','grades','details','datestatus'],
 5075:                    scope   => ['res','map','rec'],
 5076:                    protect => ['none','key','ltid','ltic'],
 5077:                    menus   => ['std','colls'],
 5078:                );
 5079:     %optiontext = &Apache::lonlocal::texthash (
 5080:                     only       => 'deep only',
 5081:                     off        => 'deeplink off',
 5082:                     both       => 'regular + deep',
 5083:                     hide       => 'Hidden',
 5084:                     unhide     => 'Unhidden',
 5085:                     full       => 'Listed (linked) in both',
 5086:                     absent     => 'Not listed',
 5087:                     grades     => 'Listed in grades only',
 5088:                     details    => 'Listed (unlinked) in both',
 5089:                     datestatus => 'Listed (unlinked) inc. status in both',
 5090:                     res        => 'resource only',
 5091:                     map        => 'enclosing map/folder',
 5092:                     rec        => 'recursive map/folder',
 5093:                     none       => 'not in use',
 5094:                     key        => 'key access',
 5095:                     ltic       => 'LTI access (course)',
 5096:                     ltid       => 'LTI access (domain)' ,
 5097:                     std        => 'Standard (all menus)',
 5098:                     colls      => 'Numbered collection',
 5099:                   );
 5100:     %selectnull = &Apache::lonlocal::texthash (
 5101:                     ltic => 'Select Launcher',
 5102:                     ltid => 'Select Launcher', 
 5103:                     colls => 'Select',
 5104:                   );
 5105:     if ($showval =~ /,/) {
 5106:         %values=();
 5107:         @current = split(/,/,$showval);
 5108:         ($values{'state'}) = ($current[0] =~ /^(only|off|both)$/);
 5109:         ($values{'others'}) = ($current[1] =~ /^(hide|unhide)$/);
 5110:         ($values{'listing'}) = ($current[2] =~ /^(full|absent|grades|details|datestatus)$/);
 5111:         ($values{'scope'}) = ($current[3] =~ /^(res|map|rec)$/);
 5112:         ($values{'protect'}) = ($current[4] =~ /^(key:[a-zA-Z\d_.!\@#\$%^&*()+=-]+|ltic:\d+|ltid:\d+)$/);
 5113:         ($values{'menus'}) = ($current[5] =~ /^(\d+)$/);
 5114:     } else {
 5115:         $defaults{'state'} = 'off',
 5116:         $defaults{'others'} = 'unhide',
 5117:         $defaults{'listing'} = 'full';
 5118:         $defaults{'scope'} = 'res';
 5119:         $defaults{'protect'} = 'none';
 5120:         $defaults{'menus'} = '0';
 5121:     }
 5122:     my $disabled;
 5123:     if ($readonly) {
 5124:         $disabled=' disabled="disabled"';
 5125:     }
 5126:     my %courselti =
 5127:         &Apache::lonnet::get_course_lti($env{'course.'.$env{'request.course.id'}.'.num'},
 5128:                                         $env{'course.'.$env{'request.course.id'}.'.domain'});
 5129:     foreach my $item (keys(%courselti)) {
 5130:         if (ref($courselti{$item}) eq 'HASH') {
 5131:             $crslti{$item} = $courselti{$item}{'name'};
 5132:         }
 5133:     }
 5134:     my %lti =
 5135:         &Apache::lonnet::get_domain_lti($env{'course.'.$env{'request.course.id'}.'.domain'},
 5136:                                         'linkprot');
 5137:     foreach my $item (keys(%lti)) {
 5138:         if (($item =~ /^\d+$/) && (ref($lti{$item}) eq 'HASH')) {
 5139:             $domlti{$item} = $lti{$item}{'name'};
 5140:         }
 5141:     }
 5142:     if ($env{'course.'.$env{'request.course.id'}.'.menucollections'}) {
 5143:         foreach my $item (split(/;/,$env{'course.'.$env{'request.course.id'}.'.menucollections'})) {
 5144:             my ($num,$value) = split(/\%/,$item);
 5145:             if ($num =~ /^\d+$/) {
 5146:                 push(@possmenus,$num);
 5147:             }
 5148:         }
 5149:     }
 5150: 
 5151:     my $output = '<input type="hidden" name="set_'.$thiskey.'" /><table><tr>';
 5152:     foreach my $item (@components) {
 5153:         $output .= '<th>'.$titles{$item}.'</th>';
 5154:     }
 5155:     $output .= '</tr><tr>';
 5156:     foreach my $item (@components) {
 5157:         $output .= '<td>';
 5158:         if (($item eq 'protect') || ($item eq 'menus')) {
 5159:             my $selected = $values{$item};
 5160:             foreach my $option (@{$options{$item}}) {
 5161:                 if ($item eq 'protect') { 
 5162:                     if ($option eq 'ltid') {
 5163:                         next unless (keys(%domlti));
 5164:                     } elsif ($option eq 'ltic') {
 5165:                         next unless (keys(%crslti));
 5166:                     }
 5167:                 } elsif (($item eq 'menus') && ($option eq 'colls')) {
 5168:                     next unless (@possmenus);
 5169:                 }
 5170:                 my $checked;
 5171:                 if ($item eq 'menus') {
 5172:                     if (($selected =~ /^\d+$/) && (@possmenus) &&
 5173:                         (grep(/^\Q$selected\E$/,@possmenus))) {
 5174:                         if ($option eq 'colls') {
 5175:                             $checked = ' checked="checked"';
 5176:                         }
 5177:                     } elsif (($option eq 'std') && ($selected == 0) && ($selected ne '')) {
 5178:                         $checked = ' checked="checked"';
 5179:                     }
 5180:                 } elsif ($selected =~ /^\Q$option\E/) {
 5181:                     $checked = ' checked="checked"';
 5182:                 }
 5183:                 my $onclick;
 5184:                 unless ($readonly) {
 5185:                     my $esc_key = &js_escape($thiskey);
 5186:                     $onclick = ' onclick="toggleDeepLink(this.form,'."'$item','$esc_key'".');"';
 5187:                 }
 5188:                 $output .= '<span class="LC_nobreak"><label>'.
 5189:                            '<input type="radio" name="deeplink_'.$item.'_'.$thiskey.'" value="'.$option.'"'.$onclick.$disabled.$checked.' />'."\n".
 5190:                            $optiontext{$option}.'</label>';
 5191:                 if (($item eq 'protect') && ($option eq 'key')) {
 5192:                     my $visibility="hidden";
 5193:                     my $currkey;
 5194:                     if ($checked) {
 5195:                         $visibility = "text";
 5196:                         $currkey = (split(/\:/,$values{$item}))[1];
 5197:                     }
 5198:                     $output .= '&nbsp;'.
 5199:                         '<input type="'.$visibility.'" name="deeplink_'.$option.'_'.$thiskey.'" id="deeplink_'.$option.'_'.$item.'_'.$thiskey.'" value="'.$currkey.'" size="10"'.$disabled.' />';
 5200:                 } elsif (($option eq 'ltic') || ($option eq 'ltid') || ($option eq 'colls')) {
 5201:                     my $display="none";
 5202:                     my ($current,$blankcheck,@possibles);
 5203:                     if ($checked) {
 5204:                         $display = 'inline-block';
 5205:                         if (($option eq 'ltic') || ($option eq 'ltid'))  {
 5206:                             $current = (split(/\:/,$selected))[1];
 5207:                         } else {
 5208:                             $current = $selected;
 5209:                         }
 5210:                     } else {
 5211:                         $blankcheck = ' selected="selected"';
 5212:                     }
 5213:                     if ($option eq 'ltid') {
 5214:                         @possibles = keys(%domlti);
 5215:                     } elsif ($option eq 'ltic') {
 5216:                         @possibles = keys(%crslti); 
 5217:                     } else {
 5218:                         @possibles = @possmenus;
 5219:                     }
 5220:                     $output .= '<div id="deeplinkdiv_'.$option.'_'.$item.'_'.$thiskey.'"'.
 5221:                                ' style="display: '.$display.'">&nbsp;<select name="'.
 5222:                                'deeplink_'.$option.'_'.$thiskey.'"'.$disabled.'>';
 5223:                     if (@possibles > 1) {
 5224:                         $output .= '<option value=""'.$blankcheck.'>'.$selectnull{$option}.
 5225:                                    '</option>'."\n";
 5226:                     }
 5227:                     foreach my $poss (sort { $a <=> $b } @possibles) {
 5228:                         my $selected;
 5229:                         if (($poss == $current) || (scalar(@possibles) ==1)) {
 5230:                             $selected = ' selected="selected"';
 5231:                         }
 5232:                         my $shown = $poss;
 5233:                         if ($option eq 'ltid') {
 5234:                             $shown = $domlti{$poss};
 5235:                         } elsif ($option eq 'ltic') {
 5236:                             $shown = $crslti{$poss};
 5237:                         }
 5238:                         $output .= '<option value="'.$poss.'"'.$selected.'>'.$shown.'</option>';
 5239:                     }
 5240:                     $output .= '</select></div>';
 5241:                 }
 5242:                 $output .= '</span> ';
 5243:             }
 5244:         } else {
 5245:             my $selected = $values{$item};
 5246:             my $defsel;
 5247:             if ($selected eq '') {
 5248:                 $defsel = ' selected="selected"';
 5249:             }
 5250:             $output .= '<select name="deeplink_'.$item.'_'.$thiskey.'"'.$disabled.'>'."\n".
 5251:                        '<option value=""'.$defsel.'>'.&mt('Please select').'</option>'."\n";
 5252:             foreach my $option (@{$options{$item}}) {
 5253:                 $output .= '<option value="'.$option.'"';
 5254:                 if ($option eq $selected) {
 5255:                     $output .= ' selected="selected"';
 5256:                 }
 5257:                 $output .= '>'.$optiontext{$option}.'</option>';
 5258:             }
 5259:             $output .= '</select>';
 5260:         }
 5261:         $output .= '</td>';
 5262:     }
 5263:     $output .= '</tr></table>'."\n";
 5264:     return $output;
 5265: }
 5266: 
 5267: 
 5268: { # block using some constants related to parameter types (overview mode)
 5269: 
 5270: my %strings =
 5271:     (
 5272:      'string_yesno'
 5273:              => [[ 'yes', 'Yes' ],
 5274:                  [ 'no', 'No' ]],
 5275:      'string_problemstatus'
 5276:              => [[ 'yes', 'Yes' ],
 5277:          [ 'answer', 'Yes, and show correct answer if they exceed the maximum number of tries.' ],
 5278:          [ 'no', 'No, don\'t show correct/incorrect feedback.' ],
 5279:          [ 'no_feedback_ever', 'No, show no feedback at all.' ]],
 5280:      'string_questiontype'
 5281:              => [[ 'problem', 'Standard Problem'],
 5282:                  [ 'survey', 'Survey'],
 5283:                  [ 'anonsurveycred', 'Anonymous Survey (credit for submission)'],
 5284:                  [ 'exam', 'Bubblesheet Exam'],
 5285:                  [ 'anonsurvey', 'Anonymous Survey'],
 5286:                  [ 'randomizetry', 'New Randomization Each N Tries (default N=1)'],
 5287:                  [ 'practice', 'Practice'],
 5288:                  [ 'surveycred', 'Survey (credit for submission)']],
 5289:      'string_lenient'
 5290:              => [['yes', 'Yes' ],
 5291:                  [ 'no', 'No' ],
 5292:                  [ 'default', 'Default - only bubblesheet grading is lenient' ],
 5293:                  [ 'weighted', 'Yes, weighted (optionresponse in checkbox mode)' ]],
 5294:      'string_discussvote'
 5295:              => [['yes','Yes'],
 5296:                  ['notended','Yes, unless discussion ended'],
 5297:                  ['no','No']],
 5298:      'string_ip'
 5299:              => [['_allowfrom_','Hostname(s), or IP(s) from which access is allowed'],
 5300:                  ['_denyfrom_','Hostname(s) or IP(s) from which access is disallowed']], 
 5301:      'string_deeplink'
 5302:              => [['on','Set choices for link protection, resource listing, access scope, and shown menu items']],
 5303:     );
 5304:    
 5305: 
 5306: my %stringmatches = (
 5307:          'string_lenient'
 5308:               => [['weighted','^\-?[.\d]+,\-?[.\d]+,\-?[.\d]+,\-?[.\d]+$'],],
 5309:          'string_ip'
 5310:               => [['_allowfrom_','[^\!]+'],
 5311:                   ['_denyfrom_','\!']],
 5312:          'string_deeplink'
 5313:               => [['on','^(only|off|both)\,(hide|unhide)\,(full|absent|grades|details|datestatus)\,(res|map|rec)\,(none|key\:\w+|ltic\:\d+|ltid\:\d+)\,(\d+|)$']],
 5314:     );
 5315: 
 5316: my %stringtypes = (
 5317:                     type         => 'string_questiontype',
 5318:                     lenient      => 'string_lenient',
 5319:                     retrypartial => 'string_yesno',
 5320:                     discussvote  => 'string_discussvote',
 5321:                     examcode     => 'string_examcode',
 5322:                     acc          => 'string_ip',
 5323:                     deeplink     => 'string_deeplink',
 5324:                   );
 5325: 
 5326: # Returns the possible values and titles for a given string type, or undef if there are none.
 5327: # Used by courseprefs.
 5328: #
 5329: # @param {string} $string_type - a parameter type for strings
 5330: # @returns {array reference} - 2D array, containing values and English titles
 5331: sub standard_string_options {
 5332:     my ($string_type) = @_;
 5333:     if (ref($strings{$string_type}) eq 'ARRAY') {
 5334:         return $strings{$string_type};
 5335:     }
 5336:     return;
 5337: }
 5338: 
 5339: # Returns regular expressions to match kinds of string types, or undef if there are none.
 5340: #
 5341: # @param {string} $string_type - a parameter type for strings
 5342: # @returns {array reference}  - 2D array, containing regular expression names and regular expressions
 5343: sub standard_string_matches {
 5344:     my ($string_type) = @_;
 5345:     if (ref($stringmatches{$string_type}) eq 'ARRAY') {
 5346:         return $stringmatches{$string_type};
 5347:     }
 5348:     return;
 5349: }
 5350: 
 5351: # Returns a parameter type for a given parameter with a string type, or undef if not known.
 5352: #
 5353: # @param {string} $name - parameter name
 5354: # @returns {string}
 5355: sub get_stringtype {
 5356:     my ($name) = @_;
 5357:     if (exists($stringtypes{$name})) {
 5358:         return $stringtypes{$name};
 5359:     }
 5360:     return;
 5361: }
 5362: 
 5363: # Returns HTML to edit a string parameter.
 5364: #
 5365: # @param {string} $thistype - parameter type
 5366: # @param {string} $thiskey - parameter key
 5367: # @param {string} $showval - parameter current value
 5368: # @param {string} $name - parameter name
 5369: # @param {boolean} $readonly - true if the values should not be made editable
 5370: # @returns {string}
 5371: sub string_selector {
 5372:     my ($thistype, $thiskey, $showval, $name, $readonly) = @_;
 5373: 
 5374:     if (!exists($strings{$thistype})) {
 5375:         return &default_selector($thiskey,$showval,$readonly);
 5376:     }
 5377: 
 5378:     my %skiptype;
 5379:     if (($thistype eq 'string_questiontype') || 
 5380:             ($thistype eq 'string_lenient') ||
 5381:             ($thistype eq 'string_discussvote') ||
 5382:             ($thistype eq 'string_ip') ||
 5383:             ($thistype eq 'string_deeplink') ||
 5384:             ($name eq 'retrypartial')) {
 5385:         my ($got_chostname,$chostname,$cmajor,$cminor); 
 5386:         foreach my $possibilities (@{ $strings{$thistype} }) {
 5387:             next unless (ref($possibilities) eq 'ARRAY');
 5388:             my ($parmval, $description) = @{ $possibilities };
 5389:             my $parmmatch;
 5390:             if (ref($stringmatches{$thistype}) eq 'ARRAY') {
 5391:                 foreach my $item (@{$stringmatches{$thistype}}) {
 5392:                     if (ref($item) eq 'ARRAY') {
 5393:                         if ($parmval eq $item->[0]) {
 5394:                             $parmmatch = $parmval;
 5395:                             $parmval = '';
 5396:                             last;
 5397:                         }
 5398:                     }
 5399:                 }
 5400:             }
 5401:             my $needsrelease=$Apache::lonnet::needsrelease{"parameter:$name:$parmval:$parmmatch"}; 
 5402:             if ($needsrelease) {
 5403:                 unless ($got_chostname) {
 5404:                     ($chostname,$cmajor,$cminor)=&parameter_release_vars();
 5405:                     $got_chostname = 1;
 5406:                 }
 5407:                 my $needsnewer=&parameter_releasecheck($name,$parmval,$parmmatch,undef,
 5408:                                                        $needsrelease,$cmajor,$cminor);
 5409:                 if ($needsnewer) {
 5410:                     if ($parmmatch ne '') {
 5411:                         $skiptype{$parmmatch} = 1;
 5412:                     } elsif ($parmval ne '') {
 5413:                         $skiptype{$parmval} = 1;
 5414:                     }
 5415:                 }
 5416:             }
 5417:         }
 5418:     }
 5419: 
 5420:     if ($thistype eq 'string_ip') {
 5421:         return &string_ip_selector($thiskey,$showval,$readonly); 
 5422:     } elsif ($thistype eq 'string_deeplink') {
 5423:         return &string_deeplink_selector($thiskey,$showval,$readonly);
 5424:     }
 5425: 
 5426:     my ($result,$disabled);
 5427: 
 5428:     if ($readonly) {
 5429:         $disabled = ' disabled="disabled"';
 5430:     }
 5431:     my $numinrow = 3;
 5432:     if ($thistype eq 'string_problemstatus') {
 5433:         $numinrow = 2;
 5434:     } elsif ($thistype eq 'string_questiontype') {
 5435:         if (keys(%skiptype) > 0) {
 5436:              $numinrow = 4;
 5437:         }
 5438:     }
 5439:     my $rem;
 5440:     if (ref($strings{$thistype}) eq 'ARRAY') {
 5441:         my $i=0;
 5442:         foreach my $possibilities (@{ $strings{$thistype} }) {
 5443:             next unless (ref($possibilities) eq 'ARRAY');
 5444:             my ($name, $description) = @{ $possibilities };
 5445:             next if ($skiptype{$name});
 5446:             $rem = $i%($numinrow);
 5447:             if ($rem == 0) {
 5448:                 if ($i > 0) {
 5449:                     $result .= '</tr>';
 5450:                 }
 5451:                 $result .= '<tr>';
 5452:             }
 5453:             my $colspan;
 5454:             if ($i == @{ $strings{$thistype} }-1) {
 5455:                 $rem = @{ $strings{$thistype} }%($numinrow);
 5456:                 if ($rem) {
 5457:                     my $colsleft = $numinrow - $rem;
 5458:                     if ($colsleft) {
 5459:                         $colspan = $colsleft+1;
 5460:                         $colspan = ' colspan="'.$colspan.'"';
 5461:                     }
 5462:                 }
 5463:             }
 5464:             my ($add,$onchange,$css_class);
 5465:             if ($thistype eq 'string_lenient') {
 5466:                 if ($name eq 'weighted') {
 5467:                     my $display;
 5468:                     my %relatives = &Apache::lonlocal::texthash(
 5469:                                         corrchkd     => 'Correct (checked)',
 5470:                                         corrunchkd   => 'Correct (unchecked)',
 5471:                                         incorrchkd   => 'Incorrect (checked)',
 5472:                                         incorrunchkd => 'Incorrect (unchecked)',
 5473:                     );
 5474:                     my %textval = (
 5475:                                     corrchkd     => '1.0',
 5476:                                     corrunchkd   => '1.0',
 5477:                                     incorrchkd   => '0.0',
 5478:                                     incorrunchkd => '0.0',
 5479:                     );
 5480:                     if ($showval =~ /^([\-\d\.]+)\,([\-\d\.]+)\,([\-\d\.]+)\,([\-\d\.]+)$/) {
 5481:                         $textval{'corrchkd'} = $1;
 5482:                         $textval{'corrunchkd'} = $2;
 5483:                         $textval{'incorrchkd'} = $3;
 5484:                         $textval{'incorrunchkd'} = $4;
 5485:                         $display = 'inline';
 5486:                         $showval = $name;
 5487:                     } else {
 5488:                         $display = 'none';
 5489:                     }
 5490:                     $add = ' <div id="LC_parmtext_'.$thiskey.'" style="display:'.$display.'"><table>'.
 5491:                            '<tr><th colspan="2">'.&mt("Foil's submission status").'</th><th>'.&mt('Points').'</th></tr>';  
 5492:                     foreach my $reltype ('corrchkd','corrunchkd','incorrchkd','incorrunchkd') {
 5493:                         $add .= '<tr><td>&nbsp;</td><td>'.$relatives{$reltype}.'</td>'."\n".
 5494:                                 '<td><input type="text" name="settext_'.$thiskey.'"'.
 5495:                                 ' value="'.$textval{$reltype}.'" size="3"'.$disabled.' />'.
 5496:                                 '</td></tr>';
 5497:                     }
 5498:                     $add .= '</table></div>'."\n";
 5499:                 }
 5500:                 $onchange = ' onclick="javascript:toggleParmTextbox(this.form,'."'$thiskey'".');"';
 5501:                 $css_class = ' class="LC_lenient_radio"';
 5502:             }
 5503:             $result .= '<td class="LC_left_item"'.$colspan.'>'.
 5504:                        '<span class="LC_nobreak"><label>'.
 5505:                        '<input type="radio" name="set_'.$thiskey.
 5506:                        '" value="'.$name.'"'.$onchange.$css_class.$disabled;
 5507:             if ($showval eq $name) {
 5508:                 $result .= ' checked="checked"';
 5509:             }
 5510:             $result .= ' />'.&mt($description).'</label>'.$add.'</span></td>';
 5511:             $i++;
 5512:         }
 5513:         $result .= '</tr>';
 5514:     }
 5515:     if ($result) {
 5516:         $result = '<table border="0">'.$result.'</table>';
 5517:     }
 5518:     return $result;
 5519: }
 5520: 
 5521: my %intervals =
 5522:     (
 5523:      'date_interval'
 5524:              => [[ 'done', 'Yes' ],
 5525:                  [ 'done_proctor', 'Yes, with proctor key'],                  
 5526:                  [ '', 'No' ]],
 5527:     );
 5528: 
 5529: my %intervalmatches = (
 5530:          'date_interval'
 5531:               => [['done','\d+_done(|\:[^\:]+\:)$'],
 5532:                   ['done_proctor','\d+_done(|\:[^\:]+\:)_proctor_']],
 5533:     );
 5534: 
 5535: my %intervaltypes = (
 5536:                       interval => 'date_interval',
 5537:     );
 5538: 
 5539: # Returns regular expressions to match kinds of interval type, or undef if there are none.
 5540: #
 5541: # @param {string} $interval_type - a parameter type for intervals
 5542: # @returns {array reference}  - 2D array, containing regular expression names and regular expressions
 5543: sub standard_interval_matches {
 5544:     my ($interval_type) = @_;
 5545:     if (ref($intervalmatches{$interval_type}) eq 'ARRAY') {
 5546:         return $intervalmatches{$interval_type};
 5547:     }
 5548:     return;
 5549: }
 5550: 
 5551: # Returns a parameter type for a given parameter with an interval type, or undef if not known.
 5552: #
 5553: # @param {string} $name - parameter name
 5554: # @returns {string}
 5555: sub get_intervaltype {
 5556:     my ($name) = @_;
 5557:     if (exists($intervaltypes{$name})) {
 5558:         return $intervaltypes{$name};
 5559:     }
 5560:     return;
 5561: }
 5562: 
 5563: # Returns the possible values and titles for a given interval type, or undef if there are none.
 5564: # Used by courseprefs.
 5565: #
 5566: # @param {string} $interval_type - a parameter type for intervals
 5567: # @returns {array reference} - 2D array, containing values and English titles
 5568: sub standard_interval_options {
 5569:     my ($interval_type) = @_;
 5570:     if (ref($intervals{$interval_type}) eq 'ARRAY') {
 5571:         return $intervals{$interval_type};
 5572:     }
 5573:     return;
 5574: }
 5575: 
 5576: # Returns HTML to edit a date interval parameter.
 5577: #
 5578: # @param {string} $thiskey - parameter key
 5579: # @param {string} $name - parameter name
 5580: # @param {string} $showval - parameter current value
 5581: # @param {boolean} $readonly - true if the values should not be made editable
 5582: # @returns {string}
 5583: sub date_interval_selector {
 5584:     my ($thiskey, $name, $showval, $readonly) = @_;
 5585:     my ($result,%skipval);
 5586:     if ($name eq 'interval') {
 5587:         my $intervaltype = &get_intervaltype($name);
 5588:         my ($got_chostname,$chostname,$cmajor,$cminor);
 5589:         foreach my $possibilities (@{ $intervals{$intervaltype} }) {
 5590:             next unless (ref($possibilities) eq 'ARRAY');
 5591:             my ($parmval, $description) = @{ $possibilities };
 5592:             my $parmmatch;
 5593:             if (ref($intervalmatches{$intervaltype}) eq 'ARRAY') {
 5594:                 foreach my $item (@{$intervalmatches{$intervaltype}}) {
 5595:                     if (ref($item) eq 'ARRAY') {
 5596:                         if ($parmval eq $item->[0]) {
 5597:                             $parmmatch = $parmval;
 5598:                             $parmval = '';
 5599:                             last;
 5600:                         }
 5601:                     }
 5602:                 }
 5603:             }
 5604:             my $needsrelease=$Apache::lonnet::needsrelease{"parameter:$name:$parmval:$parmmatch"};
 5605:             if ($needsrelease) {
 5606:                 unless ($got_chostname) {
 5607:                     ($chostname,$cmajor,$cminor)=&parameter_release_vars();
 5608:                     $got_chostname = 1;
 5609:                 }
 5610:                 my $needsnewer=&parameter_releasecheck($name,$parmval,$parmmatch,undef,
 5611:                                                        $needsrelease,$cmajor,$cminor);
 5612:                 if ($needsnewer) {
 5613:                     if ($parmmatch ne '') {
 5614:                         $skipval{$parmmatch} = 1;
 5615:                     } elsif ($parmval ne '') {
 5616:                         $skipval{$parmval} = 1;
 5617:                     }
 5618:                 }
 5619:             }
 5620:         }
 5621:     }
 5622: 
 5623:     my $currval = $showval;
 5624:     foreach my $which (['days', 86400, 31],
 5625:                ['hours', 3600, 23],
 5626:                ['minutes', 60, 59],
 5627:                ['seconds',  1, 59]) {
 5628:         my ($name, $factor, $max) = @{ $which };
 5629:         my $amount = int($showval/$factor);
 5630:         $showval  %= $factor;
 5631:         my %select = ((map {$_ => $_} (0..$max)),
 5632:                 'select_form_order' => [0..$max]);
 5633:         $result .= &Apache::loncommon::select_form($amount,$name.'_'.$thiskey,
 5634:                             \%select,'',$readonly);
 5635:         $result .= ' '.&mt($name);
 5636:     }
 5637:     if ($name eq 'interval') {
 5638:         unless ($skipval{'done'}) {
 5639:             my $checkedon = '';
 5640:             my $checkedproc = '';
 5641:             my $currproctorkey = '';
 5642:             my $currprocdisplay = 'hidden';
 5643:             my $currdonetext = &mt('Done');
 5644:             my $checkedoff = ' checked="checked"';
 5645:             if ($currval =~ /^(?:\d+)_done$/) {
 5646:                 $checkedon = ' checked="checked"';
 5647:                 $checkedoff = '';
 5648:             } elsif ($currval =~ /^(?:\d+)_done\:([^\:]+)\:$/) {
 5649:                 $currdonetext = $1;
 5650:                 $checkedon = ' checked="checked"';
 5651:                 $checkedoff = '';
 5652:             } elsif ($currval =~ /^(?:\d+)_done_proctor_(.+)$/) {
 5653:                 $currproctorkey = $1;
 5654:                 $checkedproc = ' checked="checked"';
 5655:                 $checkedoff = '';
 5656:                 $currprocdisplay = 'text';
 5657:             } elsif ($currval =~ /^(?:\d+)_done\:([^\:]+)\:_proctor_(.+)$/) {
 5658:                 $currdonetext = $1;
 5659:                 $currproctorkey = $2;
 5660:                 $checkedproc = ' checked="checked"';
 5661:                 $checkedoff = '';
 5662:                 $currprocdisplay = 'text';
 5663:             }
 5664:             my $onclick = ' onclick="toggleSecret(this.form,'."'done_','$thiskey'".');"';
 5665:             my $disabled;
 5666:             if ($readonly) {
 5667:                 $disabled = ' disabled="disabled"';
 5668:             }
 5669:             $result .= '<br /><span class="LC_nobreak">'.&mt('Include "done" button').
 5670:                        '<label><input type="radio" value="" name="done_'.$thiskey.'"'.$checkedoff.$onclick.$disabled.' />'.
 5671:                        &mt('No').'</label>'.('&nbsp;'x2).
 5672:                        '<label><input type="radio" value="_done" name="done_'.$thiskey.'"'.$checkedon.$onclick.$disabled.' />'.
 5673:                        &mt('Yes').'</label>'.('&nbsp;'x2).
 5674:                        '<label><input type="radio" value="_done_proctor" name="done_'.$thiskey.'"'.$checkedproc.$onclick.$disabled.' />'.
 5675:                        &mt('Yes, with proctor key').'</label>'.
 5676:                        '<input type="'.$currprocdisplay.'" id="done_'.$thiskey.'_proctorkey" '.
 5677:                        'name="done_'.$thiskey.'_proctorkey" value="'.&HTML::Entities::encode($currproctorkey,'"<>&').'"'.$disabled.' /></span><br />'.
 5678:                        '<span class="LC_nobreak">'.&mt('Button text').': '.
 5679:                        '<input type="text" name="done_'.$thiskey.'_buttontext" value="'.&HTML::Entities::encode($currdonetext,'"<>&').'"'.$disabled.' /></span>';
 5680:         }
 5681:     }
 5682:     unless ($readonly) {
 5683:         $result .= '<input type="hidden" name="dateinterval_'.$thiskey.'" />';
 5684:     }
 5685:     return $result;
 5686: }
 5687: 
 5688: # Returns HTML with a warning if a parameter requires a more recent version of LON-CAPA.
 5689: #
 5690: # @param {string} $name - parameter name
 5691: # @param {string} $namematch - parameter level name (recognized: resourcelevel|maplevel|maplevelrecurse|courselevel)
 5692: # @param {string} $value - parameter value
 5693: # @param {string} $chostname - course server name
 5694: # @param {integer} $cmajor - major version number
 5695: # @param {integer} $cminor - minor version number
 5696: # @param {string} $needsrelease - release version needed (major.minor)
 5697: # @returns {string}
 5698: sub oldversion_warning {
 5699:     my ($name,$namematch,$value,$chostname,$cmajor,$cminor,$needsrelease) = @_;
 5700:     my $standard_name = &standard_parameter_names($name);
 5701:     if ($namematch) {
 5702:         my $level = &standard_parameter_levels($namematch);
 5703:         my $msg = '';
 5704:         if ($level) {
 5705:             $msg = &mt('[_1] was [_2]not[_3] set at the level of: [_4].',
 5706:                        $standard_name,'<b>','</b>','"'.$level.'"');
 5707:         } else {
 5708:             $msg = &mt('[_1] was [_2]not[_3] set.',
 5709:                       $standard_name,'<b>','</b>');
 5710:         }
 5711:         return '<p class="LC_warning">'.$msg.'<br />'.
 5712:                &mt('LON-CAPA version ([_1]) installed on home server ([_2]) does not meet version requirements ([_3] or newer).',
 5713:                    $cmajor.'.'.$cminor,$chostname,
 5714:                    $needsrelease).
 5715:                    '</p>';
 5716:     }
 5717:     my $desc;
 5718:     my $stringtype = &get_stringtype($name);
 5719:     if ($stringtype ne '') {
 5720:         if ($name eq 'examcode') {
 5721:             $desc = $value;
 5722:         } elsif (ref($strings{$stringtypes{$name}}) eq 'ARRAY') {
 5723:             foreach my $possibilities (@{ $strings{$stringtypes{$name}} }) {
 5724:                 next unless (ref($possibilities) eq 'ARRAY');
 5725:                 my ($parmval, $description) = @{ $possibilities };
 5726:                 my $parmmatch;
 5727:                 if (ref($stringmatches{$stringtypes{$name}}) eq 'ARRAY') {
 5728:                     foreach my $item (@{$stringmatches{$stringtypes{$name}}}) {
 5729:                         if (ref($item) eq 'ARRAY') {
 5730:                             my ($regexpname,$pattern) = @{$item};
 5731:                             if ($parmval eq $regexpname) {
 5732:                                 if ($value =~ /$pattern/) {
 5733:                                     $desc = $description; 
 5734:                                     $parmmatch = 1;
 5735:                                     last;
 5736:                                 }
 5737:                             }
 5738:                         }
 5739:                     }
 5740:                     last if ($parmmatch);
 5741:                 } elsif ($parmval eq $value) {
 5742:                     $desc = $description;
 5743:                     last;
 5744:                 }
 5745:             }
 5746:         }
 5747:     } elsif (($name eq 'printstartdate') || ($name eq 'printenddate')) {
 5748:         my $now = time;
 5749:         if ($value =~ /^\d+$/) {
 5750:             if ($name eq 'printstartdate') {
 5751:                 if ($value > $now) {
 5752:                     $desc = &Apache::lonlocal::locallocaltime($value);
 5753:                 }
 5754:             } elsif ($name eq 'printenddate') {
 5755:                 if ($value < $now) {
 5756:                     $desc = &Apache::lonlocal::locallocaltime($value);
 5757:                 }
 5758:             }
 5759:         }
 5760:     }
 5761:     return '<p class="LC_warning">'.
 5762:        &mt('[_1] was [_2]not[_3] set to [_4].',
 5763:            $standard_name,'<b>','</b>','"'.$desc.'"').'<br />'.
 5764:        &mt('LON-CAPA version ([_1]) installed on home server ([_2]) does not meet version requirements ([_3] or newer).',
 5765:        $cmajor.'.'.$cminor,$chostname,
 5766:        $needsrelease).
 5767:        '</p>';
 5768: }
 5769: 
 5770: } # end of block using some constants related to parameter types
 5771: 
 5772: 
 5773: 
 5774: # Shifts all start and end dates in the current course by $shift.
 5775: #
 5776: # @param {integer} $shift - time to shift, in seconds
 5777: # @returns {string} - error name or 'ok'
 5778: sub dateshift {
 5779:     my ($shift,$numchanges)=@_;
 5780:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 5781:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
 5782:     my $sec = $env{'request.course.sec'};
 5783:     my $secgrpregex;
 5784:     if ($sec ne '') {
 5785:         my @groups;
 5786:         if ($env{'request.course.groups'} ne '') {
 5787:             @groups = split(/:/,$env{'request.course.groups'});
 5788:         }
 5789:         if (@groups) {
 5790:             $secgrpregex = '(?:'.join('|',($sec,@groups)).')';
 5791:         } else {
 5792:             $secgrpregex = $sec;
 5793:         }
 5794:     }
 5795:     my %data=&Apache::lonnet::dump('resourcedata',$dom,$crs);
 5796: # ugly retro fix for broken version of types
 5797:     foreach my $key (keys(%data)) {
 5798:         if ($key=~/\wtype$/) {
 5799:             my $newkey=$key;
 5800:             $newkey=~s/type$/\.type/;
 5801:             $data{$newkey}=$data{$key};
 5802:             delete $data{$key};
 5803:         }
 5804:     }
 5805:     my %storecontent=();
 5806: # go through all parameters and look for dates
 5807:     foreach my $key (keys(%data)) {
 5808:        if ($data{$key.'.type'}=~/^date_(start|end)$/) {
 5809:           if ($sec ne '') {
 5810:               next unless ($key =~ /^$env{'request.course.id'}\.\[$secgrpregex\]\./);
 5811:           }
 5812:           my $newdate=$data{$key}+$shift;
 5813:           $$numchanges ++;
 5814:           $storecontent{$key}=$newdate;
 5815:        }
 5816:     }
 5817:     my $reply=&Apache::lonnet::cput
 5818:                 ('resourcedata',\%storecontent,$dom,$crs);
 5819:     if ($reply eq 'ok') {
 5820:        &log_parmset(\%storecontent);
 5821:     }
 5822:     &Apache::lonnet::devalidatecourseresdata($crs,$dom);
 5823:     return $reply;
 5824: }
 5825: 
 5826: # Overview mode UI to edit course parameters.
 5827: #
 5828: # @param {Apache2::RequestRec} $r - the Apache request
 5829: sub newoverview {
 5830:     my ($r,$parm_permission) = @_;
 5831: 
 5832:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 5833:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
 5834:     my $crstype =  $env{'course.'.$env{'request.course.id'}.'.type'};
 5835:     my $readonly = 1;
 5836:     if ($parm_permission->{'edit'}) {
 5837:         undef($readonly);
 5838:     }
 5839:     &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setoverview',
 5840:         text=>"Overview Mode"});
 5841: 
 5842:     my %loaditems = (
 5843:                       'onload'   => "showHide_courseContent(); resize_scrollbox('mapmenuscroll','1','1'); showHideLenient();",
 5844:                     );
 5845:     my $js = '
 5846: <script type="text/javascript">
 5847: // <![CDATA[
 5848: '.
 5849:             &Apache::lonhtmlcommon::resize_scrollbox_js('params')."\n".
 5850:             &showhide_js()."\n".
 5851:             &toggleparmtextbox_js()."\n".
 5852:             &validateparms_js()."\n".
 5853:             &ipacc_boxes_js()."\n".
 5854:             &done_proctor_js()."\n".
 5855:             &deeplink_js()."\n".
 5856: '// ]]>
 5857: </script>
 5858: ';
 5859: 
 5860:     my $start_page = &Apache::loncommon::start_page('Set Parameters',$js,
 5861:                                                     {'add_entries' => \%loaditems,});
 5862:     my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Overview');
 5863:     $r->print($start_page.$breadcrumbs);
 5864:     &startSettingsScreen($r,'parmset',$crstype);
 5865:     $r->print(<<ENDOVER);
 5866: <form method="post" action="/adm/parmset?action=newoverview" name="parmform" onsubmit="return validateParms();">
 5867: ENDOVER
 5868:     my @ids=();
 5869:     my %typep=();
 5870:     my %keyp=();
 5871:     my %allparms=();
 5872:     my %allparts=();
 5873:     my %allmaps=();
 5874:     my %mapp=();
 5875:     my %symbp=();
 5876:     my %maptitles=();
 5877:     my %uris=();
 5878:     my %keyorder=&standardkeyorder();
 5879:     my %defkeytype=();
 5880: 
 5881:     my %alllevs=();
 5882:     $alllevs{'Resource Level'}='full';
 5883:     $alllevs{'Map/Folder Level'}='map';
 5884:     $alllevs{'Course Level'}='general';
 5885: 
 5886:     my $csec=$env{'form.csec'};
 5887:     my $cgroup=$env{'form.cgroup'};
 5888: 
 5889:     my @pscat=&Apache::loncommon::get_env_multiple('form.pscat');
 5890:     my $pschp=$env{'form.pschp'};
 5891: 
 5892:     my @psprt=&Apache::loncommon::get_env_multiple('form.psprt');
 5893:     if (!@psprt) { $psprt[0]='all'; }
 5894: 
 5895:     my @selected_sections =
 5896:     &Apache::loncommon::get_env_multiple('form.Section');
 5897:     @selected_sections = ('all') if (! @selected_sections);
 5898:     foreach my $sec (@selected_sections) {
 5899:         if ($sec eq 'all') {
 5900:             @selected_sections = ('all');
 5901:         }
 5902:     }
 5903:     if ($env{'request.course.sec'} ne '') {
 5904:         @selected_sections = ($env{'request.course.sec'});
 5905:     }
 5906:     my @selected_groups =
 5907:         &Apache::loncommon::get_env_multiple('form.Group');
 5908: 
 5909:     my $pssymb='';
 5910:     my $parmlev='';
 5911: 
 5912:     unless ($env{'form.parmlev'}) {
 5913:         $parmlev = 'map';
 5914:     } else {
 5915:         $parmlev = $env{'form.parmlev'};
 5916:     }
 5917: 
 5918:     &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allmaps,
 5919:                 \%mapp, \%symbp,\%maptitles,\%uris,
 5920:                 \%keyorder,\%defkeytype,$pssymb);
 5921: 
 5922:     if (grep {$_ eq 'all'} (@psprt)) {
 5923:         @psprt = keys(%allparts);
 5924:     }
 5925: # Menu to select levels, etc
 5926: 
 5927:     $r->print('<div class="LC_Box">');
 5928:     #$r->print('<h2 class="LC_hcell">Step 1</h2>');
 5929:     $r->print('<div>');
 5930:     $r->print(&Apache::lonhtmlcommon::start_pick_box(undef,'parmlevel'));
 5931:     &levelmenu($r,\%alllevs,$parmlev);
 5932:     if ($parmlev ne 'general') {
 5933:         $r->print(&Apache::lonhtmlcommon::row_closure());
 5934:         &mapmenu($r,\%allmaps,$pschp,\%maptitles,\%symbp);
 5935:     }
 5936:     $r->print(&Apache::lonhtmlcommon::row_closure(1));
 5937:     $r->print(&Apache::lonhtmlcommon::end_pick_box());
 5938:     $r->print('</div></div>');
 5939: 
 5940:     $r->print('<div class="LC_Box">');
 5941:     $r->print('<div>');
 5942:     &displaymenu($r,\%allparms,\@pscat,\%keyorder);
 5943:     $r->print(&Apache::lonhtmlcommon::start_pick_box());
 5944:     $r->print(&Apache::lonhtmlcommon::row_title(&mt('Select Parts to View')));
 5945:     my $sectionselector = &sectionmenu(\@selected_sections);
 5946:     my $groupselector = &groupmenu(\@selected_groups);
 5947:     $r->print('<table>'.
 5948:               '<tr><th>'.&mt('Parts').'</th>');
 5949:     if ($sectionselector) {
 5950:         $r->print('<th>'.&mt('Section(s)').'</th>');
 5951:     }
 5952:     if ($groupselector) {
 5953:         $r->print('<th>'.&mt('Group(s)').'</th>');
 5954:     }
 5955:     $r->print('</tr><tr><td>');
 5956:     &partmenu($r,\%allparts,\@psprt);
 5957:     $r->print('</td>');
 5958:     if ($sectionselector) { 
 5959:         $r->print('<td>'.$sectionselector.'</td>');
 5960:     }
 5961:     if ($groupselector) {
 5962:         $r->print('<td>'.$groupselector.'</td>');
 5963:     }
 5964:     $r->print('</tr></table>');
 5965:     $r->print(&Apache::lonhtmlcommon::row_closure(1));
 5966:     $r->print(&Apache::lonhtmlcommon::end_pick_box());
 5967:     $r->print('</div></div>');
 5968: 
 5969:     $r->print('<div class="LC_Box">');
 5970:     $r->print('<div>');
 5971:     my $sortorder=$env{'form.sortorder'};
 5972:     unless ($sortorder) { $sortorder='realmstudent'; }
 5973:     &sortmenu($r,$sortorder);
 5974:     $r->print('</div></div>');
 5975: 
 5976:     $r->print('<p><input type="submit" name="dis" value="'.&mt('Display').'" /></p>');
 5977: 
 5978: # Build the list data hash from the specified parms
 5979: 
 5980:     my $listdata;
 5981:     %{$listdata}=();
 5982: 
 5983:     foreach my $cat (@pscat) {
 5984:         &secgroup_lister($cat,$pschp,$parmlev,$listdata,\@psprt,\@selected_sections,\%defkeytype,\%allmaps,\@ids,\%symbp);
 5985:         &secgroup_lister($cat,$pschp,$parmlev,$listdata,\@psprt,\@selected_groups,\%defkeytype,\%allmaps,\@ids,\%symbp);
 5986:     }
 5987: 
 5988:     if (($env{'form.store'}) || ($env{'form.dis'})) {
 5989: 
 5990:         if ($env{'form.store'}) { &storedata($r,$crs,$dom); }
 5991: 
 5992: # Read modified data
 5993: 
 5994:         my $resourcedata=&readdata($crs,$dom);
 5995: 
 5996: # List data
 5997: 
 5998:         &listdata($r,$resourcedata,$listdata,$sortorder,'newoverview',undef,$readonly);
 5999:     }
 6000:     $r->print(&tableend());
 6001:     unless ($readonly) {
 6002:         $r->print( ((($env{'form.store'}) || ($env{'form.dis'}))?'<p><input type="submit" name="store" value="'.&mt('Save').'" /></p>':'') );
 6003:     }
 6004:     $r->print('</form>');
 6005:     &endSettingsScreen($r);
 6006:     $r->print(&Apache::loncommon::end_page());
 6007: }
 6008: 
 6009: # Fills $listdata with parameter information.
 6010: # Keys use the format course id.[section id].part.name and course id.[section id].part.name.type.
 6011: # The non-type value is always 1.
 6012: #
 6013: # @param {string} $cat - parameter name
 6014: # @param {string} $pschp - selected map pc, or 'all'
 6015: # @param {string} $parmlev - selected level value (full|map|general), or ''
 6016: # @param {hash reference} $listdata - the parameter data that will be modified
 6017: # @param {array reference} $psprt - selected parts
 6018: # @param {array reference} $selections - selected sections
 6019: # @param {hash reference} $defkeytype - hash parameter name -> parameter type
 6020: # @param {hash reference} $allmaps - hash map pc -> map src
 6021: # @param {array reference} $ids - resource and map ids
 6022: # @param {hash reference} $symbp - hash map pc or resource/map id -> map src.'___(all)' or resource symb
 6023: sub secgroup_lister {
 6024:     my ($cat,$pschp,$parmlev,$listdata,$psprt,$selections,$defkeytype,$allmaps,$ids,$symbp) = @_;
 6025:     foreach my $item (@{$selections}) {
 6026:         foreach my $part (@{$psprt}) {
 6027:             my $rootparmkey=$env{'request.course.id'};
 6028:             if (($item ne 'all') && ($item ne 'none') && ($item)) {
 6029:                 $rootparmkey.='.['.$item.']';
 6030:             }
 6031:             if ($parmlev eq 'general') {
 6032: # course-level parameter
 6033:                 my $newparmkey=$rootparmkey.'.'.$part.'.'.$cat;
 6034:                 $$listdata{$newparmkey}=1;
 6035:                 $$listdata{$newparmkey.'.type'}=$$defkeytype{$cat};
 6036:             } elsif ($parmlev eq 'map') {
 6037: # map-level parameter
 6038:                 foreach my $mapid (keys(%{$allmaps})) {
 6039:                     if (($pschp ne 'all') && ($pschp ne $mapid)) { next; }
 6040:                     my $newparmkey=$rootparmkey.'.'.$$allmaps{$mapid}.'___(all).'.$part.'.'.$cat;
 6041:                     $$listdata{$newparmkey}=1;
 6042:                     $$listdata{$newparmkey.'.type'}=$$defkeytype{$cat};
 6043:                 }
 6044:             } else {
 6045: # resource-level parameter
 6046:                 foreach my $rid (@{$ids}) {
 6047:                     my ($map,$resid,$url)=&Apache::lonnet::decode_symb($$symbp{$rid});
 6048:                     if (($pschp ne 'all') && ($$allmaps{$pschp} ne $map)) { next; }
 6049:                     my $newparmkey=$rootparmkey.'.'.$$symbp{$rid}.'.'.$part.'.'.$cat;
 6050:                     $$listdata{$newparmkey}=1;
 6051:                     $$listdata{$newparmkey.'.type'}=$$defkeytype{$cat};
 6052:                 }
 6053:             }
 6054:         }
 6055:     }
 6056: }
 6057: 
 6058: # UI to edit parameter settings starting with a list of all existing parameters.
 6059: # (called by setoverview action)
 6060: #
 6061: # @param {Apache2::RequestRec} $r - the Apache request
 6062: sub overview {
 6063:     my ($r,$parm_permission) = @_;
 6064:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 6065:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
 6066:     my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
 6067:     my $readonly = 1;
 6068:     if ($parm_permission->{'edit'}) {
 6069:         undef($readonly);
 6070:     }
 6071:     my $js = '<script type="text/javascript">'."\n".
 6072:              '// <![CDATA['."\n".
 6073:              &toggleparmtextbox_js()."\n".
 6074:              &validateparms_js()."\n".
 6075:              &ipacc_boxes_js()."\n".
 6076:              &done_proctor_js()."\n".
 6077:              &deeplink_js()."\n".
 6078:              '// ]]>'."\n".
 6079:              '</script>'."\n";
 6080:     &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setoverview',
 6081:     text=>"Overview Mode"});
 6082:     my %loaditems = (
 6083:                       'onload'   => "showHideLenient();",
 6084:                     );
 6085: 
 6086:     my $start_page=&Apache::loncommon::start_page('Modify Parameters',$js,{'add_entries' => \%loaditems,});
 6087:     my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Overview');
 6088:     $r->print($start_page.$breadcrumbs);
 6089:     &startSettingsScreen($r,'parmset',$crstype);
 6090:     $r->print('<form method="post" action="/adm/parmset?action=setoverview" name="parmform" onsubmit="return validateParms();">');
 6091: 
 6092: # Store modified
 6093: 
 6094:     unless ($readonly) {
 6095:         &storedata($r,$crs,$dom);
 6096:     }
 6097: 
 6098: # Read modified data
 6099: 
 6100:     my ($resourcedata,$classlist)=&readdata($crs,$dom);
 6101: 
 6102: 
 6103:     my $sortorder=$env{'form.sortorder'};
 6104:     unless ($sortorder) { $sortorder='realmstudent'; }
 6105:     &sortmenu($r,$sortorder);
 6106: 
 6107:     my $submitbutton = '<input type="submit" value="'.&mt('Save').'" />';
 6108: 
 6109:     if ($readonly) {
 6110:         $r->print('<p>'.$submitbutton.'</p>');
 6111:     }
 6112: 
 6113: # List data
 6114: 
 6115:     my $foundkeys=&listdata($r,$resourcedata,$resourcedata,$sortorder,'overview',$classlist,$readonly);
 6116:     $r->print(&tableend().'<p>');
 6117:     if ($foundkeys) {
 6118:         unless ($readonly) {
 6119:             $r->print('<p>'.$submitbutton.'</p>');
 6120:         }
 6121:     } else {
 6122:         $r->print('<p class="LC_info">'.&mt('There are no parameters.').'</p>');
 6123:     }
 6124:     $r->print('</form>'.&Apache::loncommon::end_page());
 6125: }
 6126: 
 6127: # Unused sub.
 6128: #
 6129: # @param {Apache2::RequestRec} $r - the Apache request
 6130: sub clean_parameters {
 6131:     my ($r) = @_;
 6132:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 6133:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
 6134: 
 6135:     &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=cleanparameters',
 6136:         text=>"Clean Parameters"});
 6137:     my $start_page=&Apache::loncommon::start_page('Clean Parameters');
 6138:     my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Clean');
 6139:     $r->print(<<ENDOVER);
 6140: $start_page
 6141: $breadcrumbs
 6142: <form method="post" action="/adm/parmset?action=cleanparameters" name="parmform">
 6143: ENDOVER
 6144: # Store modified
 6145: 
 6146:     &storedata($r,$crs,$dom);
 6147: 
 6148: # Read modified data
 6149: 
 6150:     my $resourcedata=&readdata($crs,$dom);
 6151: 
 6152: # List data
 6153: 
 6154:     $r->print('<h3>'.
 6155:           &mt('These parameters refer to resources that do not exist.').
 6156:           '</h3>'.
 6157:           '<input type="submit" value="'.&mt('Delete Selected').'" />'.'<br />'.
 6158:           '<br />');
 6159:     $r->print(&Apache::loncommon::start_data_table().
 6160:           '<tr>'.
 6161:           '<th>'.&mt('Delete').'</th>'.
 6162:           '<th>'.&mt('Parameter').'</th>'.
 6163:           '</tr>');
 6164:     foreach my $thiskey (sort(keys(%{$resourcedata}))) {
 6165:         next if (!exists($resourcedata->{$thiskey.'.type'})
 6166:             && $thiskey=~/\.type$/);
 6167:         my %data = &parse_key($thiskey);
 6168:         if (1) { #exists($data{'realm_exists'})
 6169:             #&& !$data{'realm_exists'}) {
 6170:             $r->print(&Apache::loncommon::start_data_table_row().
 6171:                 '<tr>'.
 6172:                 '<td><input type="checkbox" name="del_'.$thiskey.'" /></td>'              );
 6173: 
 6174:             $r->print('<td>');
 6175:             my $display_value = $resourcedata->{$thiskey};
 6176:             if (&isdateparm($resourcedata->{$thiskey.'.type'})) {
 6177:             $display_value =
 6178:                 &Apache::lonlocal::locallocaltime($display_value);
 6179:             }
 6180:             my $parmitem = &standard_parameter_names($data{'parameter_name'});
 6181:             $parmitem = &mt($parmitem);
 6182:             $r->print(&mt('Parameter: "[_1]" with value: "[_2]"',
 6183:                 $parmitem,$resourcedata->{$thiskey}));
 6184:             $r->print('<br />');
 6185:             if ($data{'scope_type'} eq 'all') {
 6186:                 $r->print(&mt('All users'));
 6187:             } elsif ($data{'scope_type'} eq 'user') {
 6188:                 $r->print(&mt('User: [_1]',join(':',@{$data{'scope'}})));
 6189:             } elsif ($data{'scope_type'} eq 'secgroup') {
 6190:                 $r->print(&mt('Group/Section: [_1]',$data{'scope'}));
 6191:             }
 6192:             $r->print('<br />');
 6193:             if ($data{'realm_type'} eq 'all') {
 6194:                 $r->print(&mt('All Resources'));
 6195:             } elsif ($data{'realm_type'} eq 'folder') {
 6196:                 $r->print(&mt('Folder: [_1]'),$data{'realm'});
 6197:             } elsif ($data{'realm_type'} eq 'symb') {
 6198:             my ($map,$resid,$url) =
 6199:                 &Apache::lonnet::decode_symb($data{'realm'});
 6200:             $r->print(&mt('Resource: [_1]with ID: [_2]in folder [_3]',
 6201:                         $url.' <br />&nbsp;&nbsp;&nbsp;',
 6202:                         $resid.' <br />&nbsp;&nbsp;&nbsp;',$map));
 6203:             }
 6204:             $r->print(' <br />&nbsp;&nbsp;&nbsp;'.&mt('Part: [_1]',$data{'parameter_part'}));
 6205:             $r->print('</td></tr>');
 6206: 
 6207:         }
 6208:     }
 6209:     $r->print(&Apache::loncommon::end_data_table().'<p>'.
 6210:           '<input type="submit" value="'.&mt('Delete Selected').'" />'.
 6211:           '</p></form>');
 6212:     &endSettingsScreen($r);
 6213:     $r->print(&Apache::loncommon::end_page());
 6214: }
 6215: 
 6216: # UI to shift all dates (called by dateshift1 action).
 6217: # Used by overview mode.
 6218: #
 6219: # @param {Apache2::RequestRec} $r - the Apache request
 6220: sub date_shift_one {
 6221:     my ($r) = @_;
 6222:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 6223:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
 6224:     my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
 6225:     my $sec = $env{'request.course.sec'};
 6226:     &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=dateshift1&timebase='.$env{'form.timebase'},
 6227:         text=>"Shifting Dates"});
 6228:     my $submit_text = &mt('Shift all dates accordingly');
 6229:     if ($sec ne '') {
 6230:         my @groups;
 6231:         if ($env{'request.course.groups'} ne '') {
 6232:             @groups = split(/:/,$env{'request.course.groups'});
 6233:         }
 6234:         if (@groups) {
 6235:             $submit_text = &mt("Shift dates set just for your section/group(s), accordingly");
 6236:         } else {
 6237:             $submit_text = &mt("Shift dates set just for your section, accordingly");
 6238:         }
 6239:     }
 6240:     my $start_page=&Apache::loncommon::start_page('Shift Dates');
 6241:     my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Shift');
 6242:     $r->print($start_page.$breadcrumbs);
 6243:     &startSettingsScreen($r,'parmset',$crstype);
 6244:     $r->print('<form name="shiftform" method="post" action="">'.
 6245:               '<table><tr><td>'.&mt('Currently set date:').'</td><td>'.
 6246:               &Apache::lonlocal::locallocaltime($env{'form.timebase'}).'</td></tr>'.
 6247:               '<tr><td>'.&mt('Shifted date:').'</td><td>'.
 6248:                     &Apache::lonhtmlcommon::date_setter('shiftform',
 6249:                                                         'timeshifted',
 6250:                                                         $env{'form.timebase'},,
 6251:                                                         '').
 6252:               '</td></tr></table>'.
 6253:               '<input type="hidden" name="action" value="dateshift2" />'.
 6254:               '<input type="hidden" name="timebase" value="'.$env{'form.timebase'}.'" />'.
 6255:               '<input type="submit" value="'.$submit_text.'" /></form>');
 6256:     &endSettingsScreen($r);
 6257:     $r->print(&Apache::loncommon::end_page());
 6258: }
 6259: 
 6260: # UI to shift all dates (second form).
 6261: #
 6262: # @param {Apache2::RequestRec} $r - the Apache request
 6263: sub date_shift_two {
 6264:     my ($r) = @_;
 6265:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 6266:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
 6267:     my $sec = $env{'request.course.sec'};
 6268:     my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
 6269:     &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=dateshift1&timebase='.$env{'form.timebase'},
 6270:         text=>"Shifting Dates"});
 6271:     my $start_page=&Apache::loncommon::start_page('Shift Dates');
 6272:     my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Shift');
 6273:     $r->print($start_page.$breadcrumbs);
 6274:     &startSettingsScreen($r,'parmset',$crstype);
 6275:     my $timeshifted=&Apache::lonhtmlcommon::get_date_from_form('timeshifted');
 6276:     $r->print('<h2>'.&mt('Shift Dates').'</h2>');
 6277:     if ($sec ne '') {
 6278:         my @groups;
 6279:         if ($env{'request.course.groups'} ne '') {
 6280:             @groups = split(/:/,$env{'request.course.groups'});
 6281:         }
 6282:         if (@groups) {
 6283:             $r->print('<p>'.
 6284:                       &mt("Shift dates set just for your section/group(s), such that [_1] becomes [_2]",
 6285:                           &Apache::lonlocal::locallocaltime($env{'form.timebase'}),
 6286:                           &Apache::lonlocal::locallocaltime($timeshifted)).
 6287:                       '</p>');
 6288:         } else {
 6289:             $r->print('<p>'.
 6290:                       &mt("Shift dates set just for your section, such that [_1] becomes [_2]",
 6291:                           &Apache::lonlocal::locallocaltime($env{'form.timebase'}),
 6292:                           &Apache::lonlocal::locallocaltime($timeshifted)).
 6293:                       '</p>');
 6294:         }
 6295:     } else {
 6296:         $r->print('<p>'.&mt('Shifting all dates such that [_1] becomes [_2]',
 6297:                             &Apache::lonlocal::locallocaltime($env{'form.timebase'}),
 6298:                             &Apache::lonlocal::locallocaltime($timeshifted)).
 6299:                   '</p>');
 6300:     }
 6301:     my $delta=$timeshifted-$env{'form.timebase'};
 6302:     my $numchanges = 0;
 6303:     my $result = &dateshift($delta,\$numchanges);
 6304:     if ($result eq 'ok') {
 6305:         $r->print(
 6306:             &Apache::lonhtmlcommon::confirm_success(&mt('Completed shifting of [quant,_1,date setting]',
 6307:                                                     $numchanges)));
 6308:     } elsif ($result eq 'con_delayed') {
 6309:         $r->print(
 6310:             &Apache::lonhtmlcommon::confirm_success(&mt('Queued shifting of [quant,_1,date setting]',
 6311:                                                         $numchanges)));
 6312:     } else {
 6313:         $r->print(
 6314:             &Apache::lonhtmlcommon::confirm_success(&mt('An error occurred attempting to shift dates'),1));
 6315:     }
 6316:     $r->print(
 6317:         '<br /><br />'.
 6318:         &Apache::lonhtmlcommon::actionbox(
 6319:             ['<a href="/adm/parmset">'.&mt('Content and Problem Settings').'</a>']));
 6320:     &endSettingsScreen($r);
 6321:     $r->print(&Apache::loncommon::end_page());
 6322: }
 6323: 
 6324: # Returns the different components of a resourcedata key.
 6325: # Keys: scope_type, scope, realm_type, realm, realm_title,
 6326: #       realm_exists, parameter_part, parameter_name.
 6327: # Was used by clean_parameters (which is unused).
 6328: #
 6329: # @param {string} $key - the parameter key
 6330: # @returns {hash}
 6331: sub parse_key {
 6332:     my ($key) = @_;
 6333:     my %data;
 6334:     my ($middle,$part,$name)=
 6335:     ($key=~/^$env{'request.course.id'}\.(?:(.+)\.)*([\w\s\-]+)\.(\w+)$/);
 6336:     $data{'scope_type'} = 'all';
 6337:     if ($middle=~/^\[(.*)\]/) {
 6338:         $data{'scope'} = $1;
 6339:         if ($data{'scope'}=~/^useropt\:($match_username)\:($match_domain)/) {
 6340:             $data{'scope_type'} = 'user';
 6341:             $data{'scope'} = [$1,$2];
 6342:         } else {
 6343:             $data{'scope_type'} = 'secgroup';
 6344:         }
 6345:         $middle=~s/^\[(.*)\]//;
 6346:     }
 6347:     $middle=~s/\.+$//;
 6348:     $middle=~s/^\.+//;
 6349:     $data{'realm_type'}='all';
 6350:     if ($middle=~/^(.+)\_\_\_\(all\)$/) {
 6351:         $data{'realm'} = $1;
 6352:         $data{'realm_type'} = 'folder';
 6353:         $data{'realm_title'} = &Apache::lonnet::gettitle($data{'realm'});
 6354:         ($data{'realm_exists'}) = &Apache::lonnet::is_on_map($data{'realm'});
 6355:     } elsif ($middle) {
 6356:         $data{'realm'} = $middle;
 6357:         $data{'realm_type'} = 'symb';
 6358:         $data{'realm_title'} = &Apache::lonnet::gettitle($data{'realm'});
 6359:         my ($map,$resid,$url) = &Apache::lonnet::decode_symb($data{'realm'});
 6360:         $data{'realm_exists'} = &Apache::lonnet::symbverify($data{'realm'},$url);
 6361:     }
 6362: 
 6363:     $data{'parameter_part'} = $part;
 6364:     $data{'parameter_name'} = $name;
 6365: 
 6366:     return %data;
 6367: }
 6368: 
 6369: 
 6370: # Calls loncommon::start_page with the "Settings" title.
 6371: sub header {
 6372:     return &Apache::loncommon::start_page('Settings');
 6373: }
 6374: 
 6375: 
 6376: 
 6377: ##################################################
 6378: # MAIN MENU
 6379: ##################################################
 6380: 
 6381: # Content and problem settings main menu.
 6382: #
 6383: # @param {Apache2::RequestRec} $r - the Apache request
 6384: # @param {boolean} $parm_permission - true if the user has permission to edit the current course or section
 6385: sub print_main_menu {
 6386:     my ($r,$parm_permission)=@_;
 6387:     #
 6388:     $r->print(&header());
 6389:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content and Problem Settings'));
 6390:     my $crstype = &Apache::loncommon::course_type();
 6391:     my $lc_crstype = lc($crstype);
 6392: 
 6393:     &startSettingsScreen($r,'parmset',$crstype);
 6394:     $r->print(<<ENDMAINFORMHEAD);
 6395: <form method="post" enctype="multipart/form-data"
 6396:       action="/adm/parmset" name="studentform">
 6397: ENDMAINFORMHEAD
 6398: #
 6399:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 6400:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 6401:     my $vgr  = &Apache::lonnet::allowed('vgr',$env{'request.course.id'});
 6402:     my $mgr  = &Apache::lonnet::allowed('mgr',$env{'request.course.id'});
 6403:     my $dcm = &Apache::lonnet::allowed('dcm',$env{'request.course.id'});
 6404:     my $vcb = &Apache::lonnet::allowed('vcb',$env{'request.course.id'});
 6405:     my $vpa = &Apache::lonnet::allowed('vpa',$env{'request.course.id'});
 6406:     if ((!$dcm) && ($env{'request.course.sec'} ne '')) {
 6407:         $dcm = &Apache::lonnet::allowed('dcm',$env{'request.course.id'}.
 6408:                                         '/'.$env{'request.course.sec'});
 6409:     }
 6410:     if ((!$vcb) && ($env{'request.course.sec'} ne '')) {
 6411:         $vcb = &Apache::lonnet::allowed('vcb',$env{'request.course.id'}.
 6412:                                         '/'.$env{'request.course.sec'});
 6413:     }
 6414:     my (%linktext,%linktitle,%url);
 6415:     if ($parm_permission->{'edit'}) {
 6416:         %linktext = (
 6417:                      newoverview     => 'Edit Resource Parameters - Overview Mode',
 6418:                      settable        => 'Edit Resource Parameters - Table Mode',
 6419:                      setoverview     => 'Modify Resource Parameters - Overview Mode',
 6420:                     );
 6421:         %linktitle = (
 6422:                      newoverview     => 'Set/Modify resource parameters in overview mode.',
 6423:                      settable        => 'Set/Modify resource parameters in table mode.',
 6424:                      setoverview     => 'Set/Modify existing resource parameters in overview mode.',
 6425:                      );
 6426:     } else {
 6427:         %linktext = (
 6428:                      newoverview     => 'View Resource Parameters - Overview Mode',
 6429:                      settable        => 'View Resource Parameters - Table Mode',
 6430:                      setoverview     => 'View Resource Parameters - Overview Mode',
 6431:                    );
 6432:         %linktitle = (
 6433:                      newoverview     => 'Display resource parameters in overview mode.',
 6434:                      settable        => 'Display resource parameters in table mode.',
 6435:                      setoverview     => 'Display existing resource parameters in overview mode.',
 6436:                      );
 6437:     }
 6438:     if ($mgr) {
 6439:         $linktext{'resettimes'} = 'Reset Student Access Times';
 6440:         $linktitle{'resettimes'} = "Reset access times for folders/maps, resources or the $lc_crstype.";
 6441:         $url{'resettimes'} = '/adm/helper/resettimes.helper';
 6442:     } elsif ($vgr) {
 6443:         $linktext{'resettimes'} = 'Display Student Access Times',
 6444:         $linktitle{'resettimes'} = "Display access times for folders/maps, resources or the $lc_crstype.",
 6445:         $url{'resettimes'} = '/adm/accesstimes';
 6446:     }
 6447:     my @menu =
 6448:         ( { categorytitle=>"Content Settings for this $crstype",
 6449:         items => [
 6450:           { linktext => 'Portfolio Metadata',
 6451:             url => '/adm/parmset?action=setrestrictmeta',
 6452:             permission => $parm_permission->{'setrestrictmeta'},
 6453:             linktitle => "Restrict metadata for this $lc_crstype." ,
 6454:             icon =>'contact-new.png'   ,
 6455:             },
 6456:           { linktext => $linktext{'resettimes'},
 6457:             url => $url{'resettimes'},
 6458:             permission => ($vgr || $mgr),
 6459:             linktitle => $linktitle{'resettimes'},
 6460:             icon => 'start-here.png',
 6461:             },
 6462:           { linktext => 'Blocking Communication/Resource Access',
 6463:             url => '/adm/setblock',
 6464:             permission => ($vcb || $dcm),
 6465:             linktitle => 'Configure blocking of communication/collaboration and access to resources during an exam',
 6466:             icon => 'comblock.png',
 6467:             },
 6468:           { linktext => 'Set Parameter Setting Default Actions',
 6469:             url => '/adm/parmset?action=setdefaults',
 6470:             permission => $parm_permission->{'setdefaults'},
 6471:             linktitle =>'Set default actions for parameters.'  ,
 6472:             icon => 'folder-new.png'  ,
 6473:             }]},
 6474:       { categorytitle => 'New and Existing Parameter Settings for Resources',
 6475:         items => [
 6476:           { linktext => 'Edit Resource Parameters - Helper Mode',
 6477:             url => '/adm/helper/parameter.helper',
 6478:             permission => $parm_permission->{'helper'},
 6479:             linktitle =>'Set/Modify resource parameters in helper mode.'  ,
 6480:             icon => 'dialog-information.png'  ,
 6481:             #help => 'Parameter_Helper',
 6482:             },
 6483:           { linktext => $linktext{'newoverview'},
 6484:             url => '/adm/parmset?action=newoverview',
 6485:             permission => $parm_permission->{'newoverview'},
 6486:             linktitle => $linktitle{'newoverview'},
 6487:             icon => 'edit-find.png',
 6488:             #help => 'Parameter_Overview',
 6489:             },
 6490:           { linktext => $linktext{'settable'},
 6491:             url => '/adm/parmset?action=settable',
 6492:             permission => $parm_permission->{'settable'},
 6493:             linktitle => $linktitle{'settable'},
 6494:             icon => 'edit-copy.png',
 6495:             #help => 'Table_Mode',
 6496:             }]},
 6497:            { categorytitle => 'Existing Parameter Settings for Resources',
 6498:          items => [
 6499:           { linktext => $linktext{'setoverview'},
 6500:             url => '/adm/parmset?action=setoverview',
 6501:             permission => $parm_permission->{'setoverview'},
 6502:             linktitle => $linktitle{'setoverview'},
 6503:             icon => 'preferences-desktop-wallpaper.png',
 6504:             #help => 'Parameter_Overview',
 6505:             },
 6506:           { linktext => 'Change Log',
 6507:             url => '/adm/parmset?action=parameterchangelog',
 6508:             permission => $parm_permission->{'parameterchangelog'},
 6509:             linktitle =>"View parameter and $lc_crstype blog posting/user notification change log."  ,
 6510:             icon => 'document-properties.png',
 6511:             }]}
 6512:           );
 6513:     $r->print(&Apache::lonhtmlcommon::generate_menu(@menu));
 6514:     $r->print('</form>');
 6515:     &endSettingsScreen($r);
 6516:     $r->print(&Apache::loncommon::end_page());
 6517:     return;
 6518: }
 6519: 
 6520: 
 6521: 
 6522: ##################################################
 6523: # PORTFOLIO METADATA
 6524: ##################################################
 6525: 
 6526: # Prints HTML to edit an item of portfolio metadata. The HTML contains several td elements (no tr).
 6527: # It looks like field titles are not localized.
 6528: #
 6529: # @param {Apache2::RequestRec} $r - the Apache request
 6530: # @param {string} $field_name - metadata field name
 6531: # @param {string} $field_text - metadata field title, in English unless manually added
 6532: # @param {boolean} $added_flag - true if the field was manually added
 6533: sub output_row {
 6534:     my ($r, $field_name, $field_text, $added_flag) = @_;
 6535:     my $output;
 6536:     my $options=$env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.options'};
 6537:     my $values=$env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.values'};
 6538:     if (!defined($options)) {
 6539:         $options = 'active,stuadd';
 6540:         $values = '';
 6541:     }
 6542:     if (!($options =~ /deleted/)) {
 6543:         my @options= ( ['active', 'Show to student'],
 6544:                     ['stuadd', 'Provide text area for students to type metadata'],
 6545:                     ['choices','Provide choices for students to select from']);
 6546: #           ['onlyone','Student may select only one choice']);
 6547:         if ($added_flag) {
 6548:             push @options,['deleted', 'Delete Metadata Field'];
 6549:         }
 6550:        $output = &Apache::loncommon::start_data_table_row();
 6551:         $output .= '<td><strong>'.$field_text.':</strong></td>';
 6552:         $output .= &Apache::loncommon::end_data_table_row();
 6553:         foreach my $opt (@options) {
 6554:             my $checked = ($options =~ m/$opt->[0]/) ? ' checked="checked" ' : '' ;
 6555:             $output .= &Apache::loncommon::continue_data_table_row();
 6556:             $output .= '<td>'.('&nbsp;' x 5).'<label>
 6557:                     <input type="checkbox" name="'.
 6558:                     $field_name.'_'.$opt->[0].'" value="yes"'.$checked.' />'.
 6559:                     &mt($opt->[1]).'</label></td>';
 6560:             $output .= &Apache::loncommon::end_data_table_row();
 6561:         }
 6562:         $output .= &Apache::loncommon::continue_data_table_row();
 6563:         $output .= '<td>'.('&nbsp;' x 10).'<input name="'.$field_name.'_values" type="text" value="'.$values.'" size="80" /></td>';
 6564:         $output .= &Apache::loncommon::end_data_table_row();
 6565:         my $multiple_checked;
 6566:         my $single_checked;
 6567:         if ($options =~ m/onlyone/) {
 6568:             $multiple_checked = '';
 6569:             $single_checked = ' checked="checked"';
 6570:         } else {
 6571:             $multiple_checked = ' checked="checked"';
 6572:             $single_checked = '';
 6573:         }
 6574:         $output .= &Apache::loncommon::continue_data_table_row();
 6575:         $output .= '<td>'.('&nbsp;' x 10).'
 6576:                     <input type="radio" name="'.$field_name.'_onlyone" value="multiple"'.$multiple_checked .' />
 6577:                     '.&mt('Student may select multiple choices from list').'</td>';
 6578:         $output .= &Apache::loncommon::end_data_table_row();
 6579:         $output .= &Apache::loncommon::continue_data_table_row();
 6580:         $output .= '<td>'.('&nbsp;' x 10).'
 6581:                     <input type="radio" name="'.$field_name.'_onlyone"  value="single"'.$single_checked.' />
 6582:                     '.&mt('Student may select only one choice from list').'</td>';
 6583:         $output .= &Apache::loncommon::end_data_table_row();
 6584:     }
 6585:     return ($output);
 6586: }
 6587: 
 6588: 
 6589: # UI to order portfolio metadata fields.
 6590: # Currently useless because addmetafield does not work.
 6591: #
 6592: # @param {Apache2::RequestRec} $r - the Apache request
 6593: sub order_meta_fields {
 6594:     my ($r)=@_;
 6595:     my $idx = 1;
 6596:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 6597:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
 6598:     my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};;
 6599:     $r->print(&Apache::loncommon::start_page('Order Metadata Fields'));
 6600:     &Apache::lonhtmlcommon::add_breadcrumb(
 6601:         {href=>'/adm/parmset?action=addmetadata',
 6602:         text=>"Add Metadata Field"});
 6603:     &Apache::lonhtmlcommon::add_breadcrumb(
 6604:         {href=>"/adm/parmset?action=setrestrictmeta",
 6605:         text=>"Restrict Metadata"},
 6606:         {text=>"Order Metadata"});
 6607:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Order Metadata'));
 6608:     &startSettingsScreen($r,'parmset',$crstype);
 6609:     if ($env{'form.storeorder'}) {
 6610:         my $newpos = $env{'form.newpos'} - 1;
 6611:         my $currentpos = $env{'form.currentpos'} - 1;
 6612:         my @neworder = ();
 6613:         my @oldorder = split(/,/,$env{'course.'.$env{'request.course.id'}.'.metadata.addedorder'});
 6614:         my $i;
 6615:         if ($newpos > $currentpos) {
 6616:         # moving stuff up
 6617:             for ($i=0;$i<$currentpos;$i++) {
 6618:                 $neworder[$i]=$oldorder[$i];
 6619:             }
 6620:             for ($i=$currentpos;$i<$newpos;$i++) {
 6621:                 $neworder[$i]=$oldorder[$i+1];
 6622:             }
 6623:             $neworder[$newpos]=$oldorder[$currentpos];
 6624:             for ($i=$newpos+1;$i<=$#oldorder;$i++) {
 6625:                 $neworder[$i]=$oldorder[$i];
 6626:             }
 6627:         } else {
 6628:         # moving stuff down
 6629:             for ($i=0;$i<$newpos;$i++) {
 6630:                 $neworder[$i]=$oldorder[$i];
 6631:             }
 6632:             $neworder[$newpos]=$oldorder[$currentpos];
 6633:             for ($i=$newpos+1;$i<$currentpos+1;$i++) {
 6634:                 $neworder[$i]=$oldorder[$i-1];
 6635:             }
 6636:             for ($i=$currentpos+1;$i<=$#oldorder;$i++) {
 6637:                 $neworder[$i]=$oldorder[$i];
 6638:             }
 6639:         }
 6640:         my $ordered_fields = join ",", @neworder;
 6641:         my $put_result = &Apache::lonnet::put('environment',
 6642:                         {'metadata.addedorder'=>$ordered_fields},$dom,$crs);
 6643:         &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.metadata.addedorder' => $ordered_fields});
 6644:     }
 6645:     my $fields = &get_added_meta_fieldnames($env{'request.course.id'});
 6646:     my $ordered_fields;
 6647:     my @fields_in_order = split(/,/,$env{'course.'.$env{'request.course.id'}.'.metadata.addedorder'});
 6648:     if (!@fields_in_order) {
 6649:         # no order found, pick sorted order then create metadata.addedorder key.
 6650:         foreach my $key (sort(keys(%$fields))) {
 6651:             push @fields_in_order, $key;
 6652:             $ordered_fields = join ",", @fields_in_order;
 6653:         }
 6654:         my $put_result = &Apache::lonnet::put('environment',
 6655:                             {'metadata.addedorder'=>$ordered_fields},$dom,$crs);
 6656:     }
 6657:     $r->print('<table>');
 6658:     my $num_fields = scalar(@fields_in_order);
 6659:     foreach my $key (@fields_in_order) {
 6660:         $r->print('<tr><td>');
 6661:         $r->print('<form method="post" action="">');
 6662:         $r->print('<select name="newpos" onchange="this.form.submit()">');
 6663:         for (my $i = 1;$i le $num_fields;$i ++) {
 6664:             if ($i eq $idx) {
 6665:                 $r->print('<option value="'.$i.'"  SELECTED>('.$i.')</option>');
 6666:             } else {
 6667:                 $r->print('<option value="'.$i.'">'.$i.'</option>');
 6668:             }
 6669:         }
 6670:         $r->print('</select></td><td>');
 6671:         $r->print('<input type="hidden" name="currentpos" value="'.$idx.'" />');
 6672:         $r->print('<input type="hidden" name="storeorder" value="true" />');
 6673:         $r->print('</form>');
 6674:         $r->print($$fields{$key}.'</td></tr>');
 6675:         $idx ++;
 6676:     }
 6677:     $r->print('</table>');
 6678:     &endSettingsScreen($r);
 6679:     return 'ok';
 6680: }
 6681: 
 6682: 
 6683: # Returns HTML with a Continue button redirecting to the initial portfolio metadata screen.
 6684: # @returns {string}
 6685: sub continue {
 6686:     my $output;
 6687:     $output .= '<form action="" method="post">';
 6688:     $output .= '<input type="hidden" name="action" value="setrestrictmeta" />';
 6689:     $output .= '<input type="submit" value="'.&mt('Continue').'" />';
 6690:     return ($output);
 6691: }
 6692: 
 6693: 
 6694: # UI to add a metadata field.
 6695: # Currenly does not work because of an HTML error (the field is not visible).
 6696: #
 6697: # @param {Apache2::RequestRec} $r - the Apache request
 6698: sub addmetafield {
 6699:     my ($r)=@_;
 6700:     &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=addmetadata',
 6701:         text=>"Add Metadata Field"});
 6702:     $r->print(&Apache::loncommon::start_page('Add Metadata Field'));
 6703:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Add Metadata Field'));
 6704:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 6705:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
 6706:     my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
 6707:     &startSettingsScreen($r,'parmset',$crstype);
 6708:     if (exists($env{'form.undelete'})) {
 6709:         my @meta_fields = &Apache::loncommon::get_env_multiple('form.undeletefield');
 6710:         foreach my $meta_field(@meta_fields) {
 6711:             my $options = $env{'course.'.$env{'request.course.id'}.'.metadata.'.$meta_field.'.options'};
 6712:             $options =~ s/deleted//;
 6713:             $options =~ s/,,/,/;
 6714:             my $put_result = &Apache::lonnet::put('environment',
 6715:                                         {'metadata.'.$meta_field.'.options'=>$options},$dom,$crs);
 6716: 
 6717:             $r->print(&mt('Undeleted Metadata Field [_1] with result [_2]',
 6718:                           '<strong>'.$env{'course.'.$env{'request.course.id'}.'.metadata.'.$meta_field.'.added'}.
 6719:                           '</strong>',$put_result).
 6720:                       '<br />');
 6721:         }
 6722:         $r->print(&continue());
 6723:     } elsif (exists($env{'form.fieldname'})) {
 6724:         my $meta_field = $env{'form.fieldname'};
 6725:         my $display_field = $env{'form.fieldname'};
 6726:         $meta_field =~ s/\W/_/g;
 6727:         $meta_field =~ tr/A-Z/a-z/;
 6728:         my $put_result = &Apache::lonnet::put('environment',
 6729:                             {'metadata.'.$meta_field.'.values'=>"",
 6730:                              'metadata.'.$meta_field.'.added'=>"$display_field",
 6731:                              'metadata.'.$meta_field.'.options'=>""},$dom,$crs);
 6732:         $r->print(&mt('Added new Metadata Field [_1] with result [_2]',
 6733:                       '<strong>'.$env{'form.fieldname'}.'</strong>',$put_result).
 6734:                   '<br />');
 6735:         $r->print(&continue());
 6736:     } else {
 6737:         my $fields = &get_deleted_meta_fieldnames($env{'request.course.id'});
 6738:         if ($fields) {
 6739:             $r->print(&mt('You may undelete previously deleted fields.').
 6740:                       '<br />'.
 6741:                       &mt('Check those you wish to undelete and click Undelete.').
 6742:                       '<br />');
 6743:             $r->print('<form method="post" action="">');
 6744:             foreach my $key(keys(%$fields)) {
 6745:                 $r->print('<label><input type="checkbox" name="undeletefield" value="'.$key.'" />'.$$fields{$key}.'</label><br /');
 6746:             }
 6747:             $r->print('<input type="submit" name="undelete" value="'.&mt('Undelete').'" />');
 6748:             $r->print('</form>');
 6749:         }
 6750:         $r->print('<hr />'.
 6751:                   &mt('[_1]Or[_2] you may enter a new metadata field name.',
 6752:                       '<strong>','</strong>').
 6753:                   '<form method="post" action="/adm/parmset?action=addmetadata">');
 6754:         $r->print('<input type="text" name="fieldname" /><br />');
 6755:         $r->print('<input type="submit" value="'.&mt('Add Metadata Field').'" />');
 6756:         $r->print('</form>');
 6757:     }
 6758:     &endSettingsScreen($r);
 6759: }
 6760: 
 6761: 
 6762: 
 6763: # Display or save portfolio metadata.
 6764: #
 6765: # @param {Apache2::RequestRec} $r - the Apache request
 6766: sub setrestrictmeta {
 6767:     my ($r)=@_;
 6768:     my $next_meta;
 6769:     my $output;
 6770:     my $item_num;
 6771:     my $put_result;
 6772:     &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setrestrictmeta',
 6773:         text=>"Restrict Metadata"});
 6774:     $r->print(&Apache::loncommon::start_page('Restrict Metadata'));
 6775:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Restrict Metadata'));
 6776:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 6777:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
 6778:     my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
 6779:     &startSettingsScreen($r,'parmset',$crstype);
 6780:     my $key_base = $env{'course.'.$env{'request.course.id'}.'.'};
 6781:     my $save_field = '';
 6782:     my %lt = &Apache::lonlocal::texthash(
 6783:                                            addm => 'Add Metadata Field',
 6784:                                            ordm => 'Order Metadata Fields',
 6785:                                            save => 'Save',
 6786:                                         );
 6787:     if ($env{'form.restrictmeta'}) {
 6788:         foreach my $field (sort(keys(%env))) {
 6789:             if ($field=~m/^form.(.+)_(.+)$/) {
 6790:                 my $options;
 6791:                 my $meta_field = $1;
 6792:                 my $meta_key = $2;
 6793:                 if ($save_field ne $meta_field) {
 6794:                     $save_field = $meta_field;
 6795:                     if ($env{'form.'.$meta_field.'_stuadd'}) {
 6796:                         $options.='stuadd,';
 6797:                     }
 6798:                     if ($env{'form.'.$meta_field.'_choices'}) {
 6799:                         $options.='choices,';
 6800:                     }
 6801:                     if ($env{'form.'.$meta_field.'_onlyone'} eq 'single') {
 6802:                         $options.='onlyone,';
 6803:                     }
 6804:                     if ($env{'form.'.$meta_field.'_active'}) {
 6805:                         $options.='active,';
 6806:                     }
 6807:                     if ($env{'form.'.$meta_field.'_deleted'}) {
 6808:                         $options.='deleted,';
 6809:                     }
 6810:                     my $name = $save_field;
 6811:                     $put_result = &Apache::lonnet::put('environment',
 6812:                         {'metadata.'.$meta_field.'.options'=>$options,
 6813:                         'metadata.'.$meta_field.'.values'=>$env{'form.'.$meta_field.'_values'},
 6814:                         },$dom,$crs);
 6815:                 }
 6816:             }
 6817:         }
 6818:     }
 6819:     &Apache::lonnet::coursedescription($env{'request.course.id'},
 6820:                        {'freshen_cache' => 1});
 6821:     # Get the default metadata fields
 6822:     my %metadata_fields = &Apache::lonmeta::fieldnames('portfolio');
 6823:     # Now get possible added metadata fields
 6824:     my $added_metadata_fields = &get_added_meta_fieldnames($env{'request.course.id'});
 6825:     $output .= &Apache::loncommon::start_data_table();
 6826:     foreach my $field (sort(keys(%metadata_fields))) {
 6827:         if ($field ne 'courserestricted') {
 6828:             $output.= &output_row($r,$field,$metadata_fields{$field});
 6829:         }
 6830:     }
 6831:     my $buttons = (<<ENDButtons);
 6832:         <input type="submit" name="restrictmeta" value="$lt{'save'}" />
 6833:         </form><br />
 6834:         <form method="post" action="/adm/parmset?action=addmetadata" name="form1">
 6835:         <input type="submit" name="restrictmeta" value="$lt{'addm'}" />
 6836:         </form>
 6837:         <br />
 6838:         <form method="post" action="/adm/parmset?action=ordermetadata" name="form2">
 6839:         <input type="submit" name="restrictmeta" value="$lt{'ordm'}" />
 6840: ENDButtons
 6841:     my $added_flag = 1;
 6842:     foreach my $field (sort(keys(%$added_metadata_fields))) {
 6843:         $output.= &output_row($r,$field,$$added_metadata_fields{$field},$added_flag);
 6844:     }
 6845:     $output .= &Apache::loncommon::end_data_table();
 6846:     $r->print(<<ENDenv);
 6847:         <form method="post" action="/adm/parmset?action=setrestrictmeta" name="form">
 6848:         $output
 6849:         $buttons
 6850:         </form>
 6851: ENDenv
 6852:     &endSettingsScreen($r);
 6853:     $r->print(&Apache::loncommon::end_page());
 6854:     return 'ok';
 6855: }
 6856: 
 6857: 
 6858: # Returns metadata fields that have been manually added.
 6859: #
 6860: # @param {string} $cid - course id
 6861: # @returns {hash reference} - hash field name -> field title (not localized)
 6862: sub get_added_meta_fieldnames {
 6863:     my ($cid) = @_;
 6864:     my %fields;
 6865:     foreach my $key(%env) {
 6866:         if ($key =~ m/\Q$cid\E\.metadata\.(.+)\.added$/) {
 6867:             my $field_name = $1;
 6868:             my ($display_field_name) = $env{$key};
 6869:             $fields{$field_name} = $display_field_name;
 6870:         }
 6871:     }
 6872:     return \%fields;
 6873: }
 6874: 
 6875: 
 6876: # Returns metadata fields that have been manually added and deleted.
 6877: #
 6878: # @param {string} $cid - course id
 6879: # @returns {hash reference} - hash field name -> field title (not localized)
 6880: sub get_deleted_meta_fieldnames {
 6881:     my ($cid) = @_;
 6882:     my %fields;
 6883:     foreach my $key(%env) {
 6884:         if ($key =~ m/\Q$cid\E\.metadata\.(.+)\.added$/) {
 6885:             my $field_name = $1;
 6886:             if ($env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.options'} =~ m/deleted/) {
 6887:                 my ($display_field_name) = $env{$key};
 6888:                 $fields{$field_name} = $display_field_name;
 6889:             }
 6890:         }
 6891:     }
 6892:     return \%fields;
 6893: }
 6894: 
 6895: 
 6896: ##################################################
 6897: # PARAMETER SETTINGS DEFAULT ACTIONS
 6898: ##################################################
 6899: 
 6900: # UI to change parameter setting default actions
 6901: #
 6902: # @param {Apache2::RequestRec} $r - the Apache request
 6903: sub defaultsetter {
 6904:     my ($r) = @_;
 6905: 
 6906:     &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setdefaults',
 6907:         text=>"Set Defaults"});
 6908:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 6909:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 6910:     my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
 6911:     my $start_page =
 6912:         &Apache::loncommon::start_page('Parameter Setting Default Actions');
 6913:     my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Defaults');
 6914:     $r->print($start_page.$breadcrumbs);
 6915:     &startSettingsScreen($r,'parmset',$crstype);
 6916:     $r->print('<form method="post" action="/adm/parmset?action=setdefaults" name="defaultform">');
 6917: 
 6918:     my @ids=();
 6919:     my %typep=();
 6920:     my %keyp=();
 6921:     my %allparms=();
 6922:     my %allparts=();
 6923:     my %allmaps=();
 6924:     my %mapp=();
 6925:     my %symbp=();
 6926:     my %maptitles=();
 6927:     my %uris=();
 6928:     my %keyorder=&standardkeyorder();
 6929:     my %defkeytype=();
 6930: 
 6931:     &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allmaps,
 6932:                 \%mapp, \%symbp,\%maptitles,\%uris,
 6933:                 \%keyorder,\%defkeytype);
 6934:     if ($env{'form.storerules'}) {
 6935:         my %newrules=();
 6936:         my @delrules=();
 6937:         my %triggers=();
 6938:         foreach my $key (keys(%env)) {
 6939:             if ($key=~/^form\.(\w+)\_action$/) {
 6940:                 my $tempkey=$1;
 6941:                 my $action=$env{$key};
 6942:                 if ($action) {
 6943:                     $newrules{$tempkey.'_action'}=$action;
 6944:                     if ($action ne 'default') {
 6945:                         my ($whichaction,$whichparm)=($action=~/^(.*\_)([^\_]+)$/);
 6946:                         $triggers{$whichparm}.=$tempkey.':';
 6947:                     }
 6948:                     $newrules{$tempkey.'_type'}=$defkeytype{$tempkey};
 6949:                     if (&isdateparm($defkeytype{$tempkey})) {
 6950:                         $newrules{$tempkey.'_days'}=$env{'form.'.$tempkey.'_days'};
 6951:                         $newrules{$tempkey.'_hours'}=$env{'form.'.$tempkey.'_hours'};
 6952:                         $newrules{$tempkey.'_min'}=$env{'form.'.$tempkey.'_min'};
 6953:                         $newrules{$tempkey.'_sec'}=$env{'form.'.$tempkey.'_sec'};
 6954:                     } else {
 6955:                         $newrules{$tempkey.'_value'}=$env{'form.'.$tempkey.'_value'};
 6956:                         $newrules{$tempkey.'_triggervalue'}=$env{'form.'.$tempkey.'_triggervalue'};
 6957:                     }
 6958:                 } else {
 6959:                     push(@delrules,$tempkey.'_action');
 6960:                     push(@delrules,$tempkey.'_type');
 6961:                     push(@delrules,$tempkey.'_hours');
 6962:                     push(@delrules,$tempkey.'_min');
 6963:                     push(@delrules,$tempkey.'_sec');
 6964:                     push(@delrules,$tempkey.'_value');
 6965:                 }
 6966:             }
 6967:         }
 6968:         foreach my $key (keys(%allparms)) {
 6969:             $newrules{$key.'_triggers'}=$triggers{$key};
 6970:         }
 6971:         &Apache::lonnet::put('parmdefactions',\%newrules,$cdom,$cnum);
 6972:         &Apache::lonnet::del('parmdefactions',\@delrules,$cdom,$cnum);
 6973:         &resetrulescache();
 6974:     }
 6975:     my %lt=&Apache::lonlocal::texthash('days' => 'Days',
 6976:                        'hours' => 'Hours',
 6977:                        'min' => 'Minutes',
 6978:                        'sec' => 'Seconds',
 6979:                        'yes' => 'Yes',
 6980:                        'no' => 'No');
 6981:     my @standardoptions=('','default');
 6982:     my @standarddisplay=('',&mt('Default value when manually setting'));
 6983:     my @dateoptions=('','default');
 6984:     my @datedisplay=('',&mt('Default value when manually setting'));
 6985:     foreach my $tempkey (&keysindisplayorder(\%allparms,\%keyorder)) {
 6986:         unless ($tempkey) { next; }
 6987:         push @standardoptions,'when_setting_'.$tempkey;
 6988:         push @standarddisplay,&mt('Automatically set when setting ').$tempkey;
 6989:         if (&isdateparm($defkeytype{$tempkey})) {
 6990:             push @dateoptions,'later_than_'.$tempkey;
 6991:             push @datedisplay,&mt('Automatically set later than ').$tempkey;
 6992:             push @dateoptions,'earlier_than_'.$tempkey;
 6993:             push @datedisplay,&mt('Automatically set earlier than ').$tempkey;
 6994:         }
 6995:     }
 6996:     $r->print(&mt('Manual setting rules apply to all interfaces.').'<br />'.
 6997:         &mt('Automatic setting rules apply to table mode interfaces only.'));
 6998:     $r->print("\n".&Apache::loncommon::start_data_table().
 6999:           &Apache::loncommon::start_data_table_header_row().
 7000:           "<th>".&mt('Rule for parameter').'</th><th>'.
 7001:           &mt('Action').'</th><th>'.&mt('Value').'</th>'.
 7002:           &Apache::loncommon::end_data_table_header_row());
 7003:     foreach my $tempkey (&keysindisplayorder(\%allparms,\%keyorder)) {
 7004:         unless ($tempkey) { next; }
 7005:         $r->print("\n".&Apache::loncommon::start_data_table_row().
 7006:             "<td>".$allparms{$tempkey}."\n<br />(".$tempkey.')</td><td>');
 7007:         my $action=&rulescache($tempkey.'_action');
 7008:         $r->print('<select name="'.$tempkey.'_action">');
 7009:         if (&isdateparm($defkeytype{$tempkey})) {
 7010:             for (my $i=0;$i<=$#dateoptions;$i++) {
 7011:             if ($dateoptions[$i]=~/\_$tempkey$/) { next; }
 7012:             $r->print("\n<option value='$dateoptions[$i]'".
 7013:                 ($dateoptions[$i] eq $action?' selected="selected"':'').
 7014:                 ">$datedisplay[$i]</option>");
 7015:             }
 7016:         } else {
 7017:             for (my $i=0;$i<=$#standardoptions;$i++) {
 7018:             if ($standardoptions[$i]=~/\_$tempkey$/) { next; }
 7019:             $r->print("\n<option value='$standardoptions[$i]'".
 7020:                 ($standardoptions[$i] eq $action?' selected="selected"':'').
 7021:                 ">$standarddisplay[$i]</option>");
 7022:             }
 7023:         }
 7024:         $r->print('</select>');
 7025:         unless (&isdateparm($defkeytype{$tempkey})) {
 7026:             $r->print("\n<br />".&mt('Triggering value(s) of other parameter (optional, comma-separated):').
 7027:                 '<input type="text" size="20" name="'.$tempkey.'_triggervalue" value="'.&rulescache($tempkey.'_triggervalue').'" />');
 7028:         }
 7029:         $r->print("\n</td><td>\n");
 7030: 
 7031:         if (&isdateparm($defkeytype{$tempkey})) {
 7032:             my $days=&rulescache($tempkey.'_days');
 7033:             my $hours=&rulescache($tempkey.'_hours');
 7034:             my $min=&rulescache($tempkey.'_min');
 7035:             my $sec=&rulescache($tempkey.'_sec');
 7036:             $r->print(<<ENDINPUTDATE);
 7037:     <input name="$tempkey\_days" type="text" size="4" value="$days" />$lt{'days'}<br />
 7038:     <input name="$tempkey\_hours" type="text" size="4" value="$hours" />$lt{'hours'}<br />
 7039:     <input name="$tempkey\_min" type="text" size="4" value="$min" />$lt{'min'}<br />
 7040:     <input name="$tempkey\_sec" type="text" size="4" value="$sec" />$lt{'sec'}
 7041: ENDINPUTDATE
 7042:         } elsif ($defkeytype{$tempkey} eq 'string_yesno') {
 7043:                 my $yeschecked='';
 7044:                 my $nochecked='';
 7045:                 if (&rulescache($tempkey.'_value') eq 'yes') { $yeschecked=' checked="checked"'; }
 7046:                 if (&rulescache($tempkey.'_value') eq 'no') { $nochecked=' checked="checked"'; }
 7047: 
 7048:             $r->print(<<ENDYESNO);
 7049:     <label><input type="radio" name="$tempkey\_value" value="yes"$yeschecked /> $lt{'yes'}</label><br />
 7050:     <label><input type="radio" name="$tempkey\_value" value="no"$nochecked /> $lt{'no'}</label>
 7051: ENDYESNO
 7052:         } else {
 7053:             $r->print('<input type="text" size="20" name="'.$tempkey.'_value" value="'.&rulescache($tempkey.'_value').'" />');
 7054:         }
 7055:         $r->print('</td>'.&Apache::loncommon::end_data_table_row());
 7056:     }
 7057:     $r->print(&Apache::loncommon::end_data_table().
 7058:           "\n".'<input type="submit" name="storerules" value="'.
 7059:           &mt('Save').'" /></form>'."\n");
 7060:     &endSettingsScreen($r);
 7061:     $r->print(&Apache::loncommon::end_page());
 7062:     return;
 7063: }
 7064: 
 7065: ##################################################
 7066: # PARAMETER CHANGES LOG
 7067: ##################################################
 7068: 
 7069: # Returns some info for a parameter log entry.
 7070: # Returned entries:
 7071: # $realm - HTML title for the parameter level and resource
 7072: # $section - parameter section
 7073: # $name - parameter name
 7074: # $part - parameter part
 7075: # $what - $part.'.'.$name
 7076: # $middle - resource symb ?
 7077: # $uname - user name (same as given)
 7078: # $udom - user domain (same as given)
 7079: # $issection - section or group name
 7080: # $realmdescription - title for the parameter level and resource (without using HTML)
 7081: #
 7082: # @param {string} $key - parameter log key
 7083: # @param {string} $uname - user name
 7084: # @param {string} $udom - user domain
 7085: # @param {boolean} $typeflag - .type log entry
 7086: # @returns {Array}
 7087: sub components {
 7088:     my ($key,$uname,$udom,$typeflag)=@_;
 7089: 
 7090:     if ($typeflag) {
 7091:         $key=~s/\.type$//;
 7092:     }
 7093: 
 7094:     my ($middle,$part,$name)=
 7095:         ($key=~/^$env{'request.course.id'}\.(?:(.+)\.)*([\w\s\-]+)\.(\w+)$/);
 7096:     my $issection;
 7097: 
 7098:     my $section=&mt('All Students');
 7099:     if ($middle=~/^\[(.*)\]/) {
 7100:         $issection=$1;
 7101:         $section=&mt('Group/Section').': '.$issection;
 7102:         $middle=~s/^\[(.*)\]//;
 7103:     }
 7104:     $middle=~s/\.+$//;
 7105:     $middle=~s/^\.+//;
 7106:     if ($uname) {
 7107:         $section=&mt('User').": ".&Apache::loncommon::plainname($uname,$udom);
 7108:         $issection='';
 7109:     }
 7110:     my $realm='<span class="LC_parm_scope_all">'.&mt('All Resources').'</span>';
 7111:     my $realmdescription=&mt('all resources');
 7112:     if ($middle=~/^(.+)\_\_\_\((all|rec)\)$/) {
 7113:         my $mapurl = $1;
 7114:         my $maplevel = $2;
 7115:         my $leveltitle = &mt('Folder/Map');
 7116:         if ($maplevel eq 'rec') {
 7117:             $leveltitle = &mt('Recursive');
 7118:         }
 7119:         $realm='<span class="LC_parm_scope_folder">'.$leveltitle.
 7120:             ': '.&Apache::lonnet::gettitle($mapurl).' <span class="LC_parm_folder"><br />('.
 7121:             $mapurl.')</span></span>';
 7122:         $realmdescription=&mt('folder').' '.&Apache::lonnet::gettitle($mapurl);
 7123:     } elsif ($middle) {
 7124:         my ($map,$id,$url)=&Apache::lonnet::decode_symb($middle);
 7125:         $realm='<span class="LC_parm_scope_resource">'.&mt('Resource').
 7126:             ': '.&Apache::lonnet::gettitle($middle).' <br /><span class="LC_parm_symb">('.$url.
 7127:             ' in '.$map.' id: '.$id.')</span></span>';
 7128:         $realmdescription=&mt('resource').' '.&Apache::lonnet::gettitle($middle);
 7129:     }
 7130:     my $what=$part.'.'.$name;
 7131:     return ($realm,$section,$name,$part,
 7132:         $what,$middle,$uname,$udom,$issection,$realmdescription);
 7133: }
 7134: 
 7135: my %standard_parms; # hash parameter name -> parameter title (not localized)
 7136: my %standard_parms_types; # hash parameter name -> parameter type
 7137: 
 7138: # Reads parameter info from packages.tab into %standard_parms.
 7139: sub load_parameter_names {
 7140:     open(my $config,"<","$Apache::lonnet::perlvar{'lonTabDir'}/packages.tab");
 7141:     while (my $configline=<$config>) {
 7142:         if ($configline !~ /\S/ || $configline=~/^\#/) { next; }
 7143:         chomp($configline);
 7144:         my ($short,$plain)=split(/:/,$configline);
 7145:         my (undef,$name,$type)=split(/\&/,$short,3);
 7146:         if ($type eq 'display') {
 7147:             $standard_parms{$name} = $plain;
 7148:         } elsif ($type eq 'type') {
 7149:                 $standard_parms_types{$name} = $plain;
 7150:         }
 7151:     }
 7152:     close($config);
 7153:     $standard_parms{'int_pos'}      = 'Positive Integer';
 7154:     $standard_parms{'int_zero_pos'} = 'Positive Integer or Zero';
 7155:     $standard_parms{'scoreformat'}  = 'Format for display of score';
 7156: }
 7157: 
 7158: # Returns a parameter title for standard parameters, the name for others.
 7159: #
 7160: # @param {string} $name - parameter name
 7161: # @returns {string}
 7162: sub standard_parameter_names {
 7163:     my ($name)=@_;
 7164:     if (!%standard_parms) {
 7165:         &load_parameter_names();
 7166:     }
 7167:     if ($standard_parms{$name}) {
 7168:         return $standard_parms{$name};
 7169:     } else {
 7170:         return $name;
 7171:     }
 7172: }
 7173: 
 7174: # Returns a parameter type for standard parameters, undef for others.
 7175: #
 7176: # @param {string} $name - parameter name
 7177: # @returns {string}
 7178: sub standard_parameter_types {
 7179:     my ($name)=@_;
 7180:     if (!%standard_parms_types) {
 7181:         &load_parameter_names();
 7182:     }
 7183:     if ($standard_parms_types{$name}) {
 7184:         return $standard_parms_types{$name};
 7185:     }
 7186:     return;
 7187: }
 7188: 
 7189: # Returns a parameter level title (not localized) from the parameter level name.
 7190: #
 7191: # @param {string} $name - parameter level name (recognized: resourcelevel|maplevel|maplevelrecurse|courselevel)
 7192: # @returns {string}
 7193: sub standard_parameter_levels {
 7194:     my ($name)=@_;
 7195:     my %levels = (
 7196:                     'resourcelevel'   => 'a single resource',
 7197:                     'maplevel'        => 'the enclosing map/folder', 
 7198:                     'maplevelrecurse' => 'the enclosing map/folder (recursive into sub-folders)',
 7199:                     'courselevel'     => 'the general (course) level',
 7200:                  );
 7201:     if ($levels{$name}) {
 7202:         return $levels{$name};
 7203:     }
 7204:     return;
 7205: }
 7206: 
 7207: # Display log for parameter changes, blog postings, user notification changes.
 7208: #
 7209: # @param {Apache2::RequestRec} $r - the Apache request
 7210: sub parm_change_log {
 7211:     my ($r,$parm_permission)=@_;
 7212:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 7213:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 7214:     my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
 7215:     &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=settable',
 7216:     text=>"Parameter Change Log"});
 7217:     my $js = '<script type="text/javascript">'."\n".
 7218:              '// <![CDATA['."\n".
 7219:              &Apache::loncommon::display_filter_js('parmslog')."\n".
 7220:              '// ]]>'."\n".
 7221:              '</script>'."\n";
 7222:     $r->print(&Apache::loncommon::start_page('Parameter Change Log',$js));
 7223:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Parameter Change Log'));
 7224:     &startSettingsScreen($r,'parmset',$crstype);
 7225:     my %parmlog=&Apache::lonnet::dump('nohist_parameterlog',$cdom,$cnum);
 7226: 
 7227:     if ((keys(%parmlog))[0]=~/^error\:/) { undef(%parmlog); }
 7228: 
 7229:     $r->print('<div class="LC_left_float">'.
 7230:               '<fieldset><legend>'.&mt('Display of Changes').'</legend>'.
 7231:               '<form action="/adm/parmset?action=parameterchangelog"
 7232:                      method="post" name="parameterlog">');
 7233: 
 7234:     my %saveable_parameters = ('show' => 'scalar',);
 7235:     &Apache::loncommon::store_course_settings('parameter_log',
 7236:                                               \%saveable_parameters);
 7237:     &Apache::loncommon::restore_course_settings('parameter_log',
 7238:                                                 \%saveable_parameters);
 7239:     $r->print(&Apache::loncommon::display_filter('parmslog').'&nbsp;'."\n".
 7240:               '<input type="submit" value="'.&mt('Display').'" />'.
 7241:               '</form></fieldset></div><br clear="all" />');
 7242: 
 7243:     my $readonly = 1;
 7244:     if ($parm_permission->{'edit'}) {
 7245:         undef($readonly);
 7246:     }
 7247:     my $courseopt=&Apache::lonnet::get_courseresdata($cnum,$cdom);
 7248:     $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
 7249:           '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Extent').'</th><th>'.&mt('Users').'</th><th>'.
 7250:           &mt('Parameter').'</th><th>'.&mt('Part').'</th><th>'.&mt('New Value').'</th>');
 7251:     unless ($readonly) {
 7252:         $r->print('<th>'.&mt('Announce').'</th>');
 7253:     }
 7254:     $r->print(&Apache::loncommon::end_data_table_header_row());
 7255:     my $shown=0;
 7256:     my $folder='';
 7257:     if ($env{'form.displayfilter'} eq 'currentfolder') {
 7258:         my $last='';
 7259:         if (tie(my %hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
 7260:                 &GDBM_READER(),0640)) {
 7261:             $last=$hash{'last_known'};
 7262:             untie(%hash);
 7263:         }
 7264:         if ($last) { ($folder) = &Apache::lonnet::decode_symb($last); }
 7265:     }
 7266:     my $numgroups = 0;
 7267:     my @groups;
 7268:     if ($env{'request.course.groups'} ne '') {
 7269:         @groups = split(/:/,$env{'request.course.groups'});
 7270:         $numgroups = scalar(@groups);
 7271:     }
 7272:     foreach my $id (sort {
 7273:                 if ($parmlog{$b}{'exe_time'} ne $parmlog{$a}{'exe_time'}) {
 7274:                     return $parmlog{$b}{'exe_time'} <=>$parmlog{$a}{'exe_time'}
 7275:                 }
 7276:                 my $aid = (split('00000',$a))[-1];
 7277:                 my $bid = (split('00000',$b))[-1];
 7278:                 return $bid<=>$aid;
 7279:             } (keys(%parmlog))) {
 7280:         my @changes=keys(%{$parmlog{$id}{'logentry'}});
 7281:         my $count = 0;
 7282:         my $time =
 7283:             &Apache::lonlocal::locallocaltime($parmlog{$id}{'exe_time'});
 7284:         my $plainname =
 7285:             &Apache::loncommon::plainname($parmlog{$id}{'exe_uname'},
 7286:                         $parmlog{$id}{'exe_udom'});
 7287:         my $about_me_link =
 7288:             &Apache::loncommon::aboutmewrapper($plainname,
 7289:                             $parmlog{$id}{'exe_uname'},
 7290:                             $parmlog{$id}{'exe_udom'});
 7291:         my $send_msg_link='';
 7292:         if ((!$readonly) && 
 7293:             (($parmlog{$id}{'exe_uname'} ne $env{'user.name'})
 7294:             || ($parmlog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
 7295:             $send_msg_link ='<br />'.
 7296:             &Apache::loncommon::messagewrapper(&mt('Send message'),
 7297:                             $parmlog{$id}{'exe_uname'},
 7298:                             $parmlog{$id}{'exe_udom'});
 7299:         }
 7300:         my $row_start=&Apache::loncommon::start_data_table_row();
 7301:         my $makenewrow=0;
 7302:         my %istype=();
 7303:         my $output;
 7304:         foreach my $changed (reverse(sort(@changes))) {
 7305:                 my $value=$parmlog{$id}{'logentry'}{$changed};
 7306:             my $typeflag = ($changed =~/\.type$/ &&
 7307:                     !exists($parmlog{$id}{'logentry'}{$changed.'.type'}));
 7308:             my ($realm,$section,$parmname,$part,$what,$middle,$uname,$udom,$issection,$realmdescription)=
 7309:                 &components($changed,$parmlog{$id}{'uname'},$parmlog{$id}{'udom'},$typeflag);
 7310:             if ($env{'request.course.sec'} ne '') {
 7311:                 next if (($issection ne '') && (!(($issection eq $env{'request.course.sec'}) ||
 7312:                                                   ($numgroups && (grep(/^\Q$issection\E$/,@groups))))));
 7313:                 if ($uname ne '') {
 7314:                     my $stusection = &Apache::lonnet::getsection($uname,$udom,$env{'request.course.id'});
 7315:                     next if (($stusection ne '-1') && ($stusection ne $env{'request.course.sec'})); 
 7316:                 }
 7317:             }
 7318:             if ($env{'form.displayfilter'} eq 'currentfolder') {
 7319:                 if ($folder) {
 7320:                     if ($middle!~/^\Q$folder\E/) { next; }
 7321:                 }
 7322:             }
 7323:             if ($typeflag) {
 7324:                 $istype{$parmname}=$value;
 7325:                 if (!$env{'form.includetypes'}) { next; }
 7326:             }
 7327:             $count++;
 7328:             if ($makenewrow) {
 7329:                 $output .= $row_start;
 7330:             } else {
 7331:                 $makenewrow=1;
 7332:             }
 7333:             my $parmitem = &standard_parameter_names($parmname);
 7334:             $output .='<td>'.$realm.'</td><td>'.$section.'</td><td>'.
 7335:                 &mt($parmitem).'</td><td>'.
 7336:                 ($part?&mt('Part: [_1]',$part):&mt('All Parts')).'</td><td>';
 7337:             my $stillactive=0;
 7338:             if ($parmlog{$id}{'delflag'}) {
 7339:                 $output .= &mt('Deleted');
 7340:             } else {
 7341:                 if ($typeflag) {
 7342:                     my $parmitem = &standard_parameter_names($value); 
 7343:                     $parmitem = &mt($parmitem);
 7344:                     $output .= &mt('Type: [_1]',$parmitem);
 7345:                 } else {
 7346:                     my $toolsymb;
 7347:                     if ($middle =~ /ext\.tool$/) {
 7348:                         $toolsymb = $middle;
 7349:                     }
 7350:                     my ($level,@all)=&parmval_by_symb($what,$middle,
 7351:                         &Apache::lonnet::metadata($middle,$what,$toolsymb),
 7352:                         $uname,$udom,$issection,$issection,$courseopt);
 7353:                     my $showvalue = $value;
 7354:                     if ($istype{$parmname} eq '') {
 7355:                         my $type = &standard_parameter_types($parmname);
 7356:                         if ($type ne '') {
 7357:                             if (&isdateparm($type)) {
 7358:                                 $showvalue =
 7359:                                     &Apache::lonlocal::locallocaltime($value);
 7360:                             }
 7361:                         }
 7362:                     } else {
 7363:                         if (&isdateparm($istype{$parmname})) {
 7364:                             $showvalue = &Apache::lonlocal::locallocaltime($value);
 7365:                         }
 7366:                     }
 7367:                     $output .= $showvalue;
 7368:                     if ($value ne $all[$level]) {
 7369:                         $output .= '<br /><span class="LC_warning">'.&mt('Not active anymore').'</span>';
 7370:                     } else {
 7371:                         $stillactive=1;
 7372:                     }
 7373:                 }
 7374:             }
 7375:             $output .= '</td>';
 7376: 
 7377:             unless ($readonly) { 
 7378:                 $output .= '<td>';
 7379:                 if ($stillactive) {
 7380:                     my $parmitem = &standard_parameter_names($parmname);
 7381:                     $parmitem = &mt($parmitem);
 7382:                     my $title=&mt('Changed [_1]',$parmitem);
 7383:                     my $description=&mt('Changed [_1] for [_2] to [_3]',
 7384:                         $parmitem,$realmdescription,
 7385:                         (&isdateparm($istype{$parmname})?&Apache::lonlocal::locallocaltime($value):$value));
 7386:                     if (($uname) && ($udom)) {
 7387:                         $output .=
 7388:                         &Apache::loncommon::messagewrapper('Notify User',
 7389:                                                            $uname,$udom,$title,
 7390:                                                            $description);
 7391:                     } else {
 7392:                         $output .=
 7393:                             &Apache::lonrss::course_blog_link($id,$title,
 7394:                                                               $description);
 7395:                     }
 7396:                 }
 7397:                 $output .= '</td>';
 7398:             }
 7399:             $output .= &Apache::loncommon::end_data_table_row();
 7400:         }
 7401:         if ($env{'form.displayfilter'} eq 'containing') {
 7402:             my $wholeentry=$about_me_link.':'.
 7403:             $parmlog{$id}{'exe_uname'}.':'.$parmlog{$id}{'exe_udom'}.':'.
 7404:             $output;
 7405:             if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
 7406:         }
 7407:         if ($count) {
 7408:             $r->print($row_start.'<td rowspan="'.$count.'">'.$time.'</td>
 7409:                         <td rowspan="'.$count.'">'.$about_me_link.
 7410:             '<br /><tt>'.$parmlog{$id}{'exe_uname'}.
 7411:                         ':'.$parmlog{$id}{'exe_udom'}.'</tt>'.
 7412:             $send_msg_link.'</td>'.$output);
 7413:             $shown++;
 7414:         }
 7415:         if (!($env{'form.show'} eq &mt('all')
 7416:             || $shown<=$env{'form.show'})) { last; }
 7417:     }
 7418:     $r->print(&Apache::loncommon::end_data_table());
 7419:     &endSettingsScreen($r);
 7420:     $r->print(&Apache::loncommon::end_page());
 7421: }
 7422: 
 7423: ##################################################
 7424: # MISC !
 7425: ##################################################
 7426: 
 7427: # Stores slot information.
 7428: # Used by table UI
 7429: # FIXME: I don't understand how this can work when the symb is not defined (if only a map was selected)
 7430: #
 7431: # @param {string} $slot_name - slot name
 7432: # @param {string} $cdom - course domain
 7433: # @param {string} $cnum - course number
 7434: # @param {string} $symb - resource symb
 7435: # @param {string} $uname - user name
 7436: # @param {string} $udom - user domain
 7437: # @returns {string} - 'ok' or error name
 7438: sub update_slots {
 7439:     my ($slot_name,$cdom,$cnum,$symb,$uname,$udom) = @_;
 7440:     my %slot=&Apache::lonnet::get_slot($slot_name);
 7441:     if (!keys(%slot)) {
 7442:         return 'error: slot does not exist';
 7443:     }
 7444:     my $max=$slot{'maxspace'};
 7445:     if (!defined($max)) { $max=99999; }
 7446: 
 7447:     my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
 7448:                                        "^$slot_name\0");
 7449:     my ($tmp)=%consumed;
 7450:     if ($tmp=~/^error: 2 / ) {
 7451:         return 'error: unable to determine current slot status';
 7452:     }
 7453:     my $last=0;
 7454:     foreach my $key (keys(%consumed)) {
 7455:         my $num=(split('\0',$key))[1];
 7456:         if ($num > $last) { $last=$num; }
 7457:         if ($consumed{$key}->{'name'} eq $uname.':'.$udom) {
 7458:             return 'ok';
 7459:         }
 7460:     }
 7461: 
 7462:     if (scalar(keys(%consumed)) >= $max) {
 7463:         return 'error: no space left in slot';
 7464:     }
 7465:     my $wanted=$last+1;
 7466: 
 7467:     my %reservation=('name'      => $uname.':'.$udom,
 7468:                      'timestamp' => time,
 7469:                      'symb'      => $symb);
 7470: 
 7471:     my $success=&Apache::lonnet::newput('slot_reservations',
 7472:                                         {"$slot_name\0$wanted" =>
 7473:                                              \%reservation},
 7474:                                         $cdom, $cnum);
 7475:     if ($success eq 'ok') {
 7476:         my %storehash = (
 7477:                           symb    => $symb,
 7478:                           slot    => $slot_name,
 7479:                           action  => 'reserve',
 7480:                           context => 'parameter',
 7481:                         );
 7482:         &Apache::lonnet::write_log('course','slotreservationslog',\%storehash,
 7483:                                    '',$uname,$udom,$cnum,$cdom);
 7484: 
 7485:         &Apache::lonnet::write_log('course',$cdom.'_'.$cnum.'_slotlog',\%storehash,
 7486:                                    '',$uname,$udom,$uname,$udom);
 7487:     }
 7488:     return $success;
 7489: }
 7490: 
 7491: # Deletes a slot reservation.
 7492: # Used by table UI
 7493: # FIXME: I don't understand how this can work when the symb is not defined (if only a map was selected)
 7494: #
 7495: # @param {string} $slot_name - slot name
 7496: # @param {string} $cdom - course domain
 7497: # @param {string} $cnum - course number
 7498: # @param {string} $uname - user name
 7499: # @param {string} $udom - user domain
 7500: # @param {string} $symb - resource symb
 7501: # @returns {string} - 'ok' or error name
 7502: sub delete_slots {
 7503:     my ($slot_name,$cdom,$cnum,$uname,$udom,$symb) = @_;
 7504:     my $delresult;
 7505:     my %consumed = &Apache::lonnet::dump('slot_reservations',$cdom,
 7506:                                          $cnum, "^$slot_name\0");
 7507:     if (&Apache::lonnet::error(%consumed)) {
 7508:         return 'error: unable to determine current slot status';
 7509:     }
 7510:     my ($tmp)=%consumed;
 7511:     if ($tmp=~/^error: 2 /) {
 7512:         return 'error: unable to determine current slot status';
 7513:     }
 7514:     foreach my $key (keys(%consumed)) {
 7515:         if ($consumed{$key}->{'name'} eq $uname.':'.$udom) {
 7516:             my $num=(split('\0',$key))[1];
 7517:             my $entry = $slot_name.'\0'.$num;
 7518:             $delresult = &Apache::lonnet::del('slot_reservations',[$entry],
 7519:                                               $cdom,$cnum);
 7520:             if ($delresult eq 'ok') {
 7521:                 my %storehash = (
 7522:                                   symb    => $symb,
 7523:                                   slot    => $slot_name,
 7524:                                   action  => 'release',
 7525:                                   context => 'parameter',
 7526:                                 );
 7527:                 &Apache::lonnet::write_log('course','slotreservationslog',\%storehash,
 7528:                                            1,$uname,$udom,$cnum,$cdom);
 7529:                 &Apache::lonnet::write_log('course',$cdom.'_'.$cnum.'_slotlog',\%storehash,
 7530:                                            1,$uname,$udom,$uname,$udom);
 7531:             }
 7532:         }
 7533:     }
 7534:     return $delresult;
 7535: }
 7536: 
 7537: # Returns true if there is a current course.
 7538: # Used by handler
 7539: #
 7540: # @returns {boolean}
 7541: sub check_for_course_info {
 7542:     my $navmap = Apache::lonnavmaps::navmap->new();
 7543:     return 1 if ($navmap);
 7544:     return 0;
 7545: }
 7546: 
 7547: # Returns the current course host and host LON-CAPA version.
 7548: #
 7549: # @returns {Array} - (course hostname, major version number, minor version number)
 7550: sub parameter_release_vars { 
 7551:    my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 7552:    my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
 7553:    my $chostname = &Apache::lonnet::hostname($chome);
 7554:    my ($cmajor,$cminor) = 
 7555:        split(/\./,&Apache::lonnet::get_server_loncaparev($cdom,$chome));
 7556:    return ($chostname,$cmajor,$cminor);
 7557: }
 7558: 
 7559: # Checks if the course host version can handle a parameter required version,
 7560: # and if it does, stores the release needed for the course.
 7561: #
 7562: # @param {string} $name - parameter name
 7563: # @param {string} $value - parameter value
 7564: # @param {string} $valmatch - name of the test used for checking the value
 7565: # @param {string} $namematch - name of the test used for checking the name
 7566: # @param {string} $needsrelease - version needed by the parameter, major.minor
 7567: # @param {integer} $cmajor - course major version number
 7568: # @param {integer} $cminor - course minor version number
 7569: # @returns {boolean} - true if a newer version is needed
 7570: sub parameter_releasecheck {
 7571:     my ($name,$value,$valmatch,$namematch,$needsrelease,$cmajor,$cminor) = @_;
 7572:     my $needsnewer;
 7573:     my ($needsmajor,$needsminor) = split(/\./,$needsrelease);
 7574:     if (($cmajor < $needsmajor) || 
 7575:         ($cmajor == $needsmajor && $cminor < $needsminor)) {
 7576:         $needsnewer = 1;
 7577:     } elsif ($name) {
 7578:         if ($valmatch) {
 7579:             &Apache::lonnet::update_released_required($Apache::lonnet::needsrelease{'parameter:'.$name.'::'.$valmatch.':'});
 7580:         } elsif ($value) { 
 7581:             &Apache::lonnet::update_released_required($Apache::lonnet::needsrelease{'parameter:'.$name.':'.$value.'::'});
 7582:         }
 7583:     } elsif ($namematch) {
 7584:         &Apache::lonnet::update_released_required($Apache::lonnet::needsrelease{'parameter::::'.$namematch});
 7585:     }
 7586:     return $needsnewer;
 7587: }
 7588: 
 7589: sub get_permission {
 7590:     my %permission;
 7591:     my $allowed = 0;
 7592:     return (\%permission,$allowed) unless ($env{'request.course.id'});
 7593:     if ((&Apache::lonnet::allowed('opa',$env{'request.course.id'})) ||
 7594:         (&Apache::lonnet::allowed('opa',$env{'request.course.id'}.'/'.
 7595:                   $env{'request.course.sec'}))) {
 7596:         %permission= (
 7597:                        'edit'               => 1,
 7598:                        'set'                => 1,
 7599:                        'setoverview'        => 1,
 7600:                        'addmetadata'        => 1,
 7601:                        'ordermetadata'      => 1,
 7602:                        'setrestrictmeta'    => 1,
 7603:                        'newoverview'        => 1,
 7604:                        'setdefaults'        => 1,
 7605:                        'settable'           => 1,
 7606:                        'parameterchangelog' => 1,
 7607:                        'cleanparameters'    => 1,
 7608:                        'dateshift1'         => 1,
 7609:                        'dateshift2'         => 1,
 7610:                        'helper'             => 1,
 7611:          );
 7612:     } elsif ((&Apache::lonnet::allowed('vpa',$env{'request.course.id'})) ||
 7613:              (&Apache::lonnet::allowed('vpa',$env{'request.course.id'}.'/'.
 7614:                   $env{'request.course.sec'}))) {
 7615:         %permission = (
 7616:                        'set'                => 1,
 7617:                        'settable'           => 1,
 7618:                        'newoverview'        => 1,
 7619:                        'setoverview'        => 1,
 7620:                        'parameterchangelog' => 1,
 7621:                       );
 7622:     }
 7623:     foreach my $perm (values(%permission)) {
 7624:         if ($perm) { $allowed=1; last; }
 7625:     }
 7626:     return (\%permission,$allowed);
 7627: }
 7628: 
 7629: ##################################################
 7630: # HANDLER
 7631: ##################################################
 7632: 
 7633: # Main handler for lonparmset.
 7634: # Sub called based on request parameters action and command:
 7635: # no command or action: print_main_menu
 7636: # command 'set': assessparms (direct access to table mode for a resource)
 7637: #                (this can also be accessed simply with the symb parameter)
 7638: # action 'setoverview': overview (display all existing parameter settings)
 7639: # action 'addmetadata': addmetafield (called to add a portfolio metadata field)
 7640: # action 'ordermetadata': order_meta_fields (called to order portfolio metadata fields)
 7641: # action 'setrestrictmeta': setrestrictmeta (display or save portfolio metadata)
 7642: # action 'newoverview': newoverview (overview mode)
 7643: # action 'setdefaults': defaultsetter (UI to change parameter setting default actions)
 7644: # action 'settable': assessparms (table mode)
 7645: # action 'parameterchangelog': parm_change_log (display log for parameter changes,
 7646: #                              blog postings, user notification changes)
 7647: # action 'cleanparameters': clean_parameters (unused)
 7648: # action 'dateshift1': date_shift_one (overview mode, shift all dates)
 7649: # action 'dateshift2': date_shift_two (overview mode, shift all dates)
 7650: sub handler {
 7651:     my $r=shift;
 7652: 
 7653:     &reset_caches();
 7654: 
 7655:     &Apache::loncommon::content_type($r,'text/html');
 7656:     $r->send_http_header;
 7657:     return OK if $r->header_only;
 7658: 
 7659:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
 7660:                         ['action','state',
 7661:                                              'pres_marker',
 7662:                                              'pres_value',
 7663:                                              'pres_type',
 7664:                                              'filter','part',
 7665:                                              'udom','uname','symb','serial','timebase']);
 7666: 
 7667: 
 7668:     &Apache::lonhtmlcommon::clear_breadcrumbs();
 7669:     &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/parmset",
 7670:                         text=>"Content and Problem Settings",
 7671:                         faq=>10,
 7672:                         bug=>'Instructor Interface',
 7673:                                             help =>
 7674:                                             'Parameter_Manager,Course_Environment,Parameter_Helper,Parameter_Overview,Table_Mode'});
 7675: 
 7676: # ----------------------------------------------------- Needs to be in a course
 7677:     my ($parm_permission,$allowed) = &get_permission();
 7678:     my $exists = &check_for_course_info();
 7679: 
 7680:     if ($env{'request.course.id'} && $allowed && $exists) {
 7681:         #
 7682:         # Main switch on form.action and form.state, as appropriate
 7683:         #
 7684:         # Check first if coming from someone else headed directly for
 7685:         #  the table mode
 7686:         if (($parm_permission->{'set'}) && 
 7687:             ((($env{'form.command'} eq 'set') && ($env{'form.url'})
 7688:                 && (!$env{'form.dis'})) || ($env{'form.symb'}))) {
 7689:             &assessparms($r,$parm_permission);
 7690:         } elsif (! exists($env{'form.action'})) {
 7691:             &print_main_menu($r,$parm_permission);
 7692:         } elsif (!$parm_permission->{$env{'form.action'}}) {
 7693:             &print_main_menu($r,$parm_permission);
 7694:         } elsif ($env{'form.action'} eq 'setoverview') {
 7695:             &overview($r,$parm_permission);
 7696:         } elsif ($env{'form.action'} eq 'addmetadata') {
 7697:             &addmetafield($r);
 7698:         } elsif ($env{'form.action'} eq 'ordermetadata') {
 7699:             &order_meta_fields($r);
 7700:         } elsif ($env{'form.action'} eq 'setrestrictmeta') {
 7701:             &setrestrictmeta($r);
 7702:         } elsif ($env{'form.action'} eq 'newoverview') {
 7703:             &newoverview($r,$parm_permission);
 7704:         } elsif ($env{'form.action'} eq 'setdefaults') {
 7705:             &defaultsetter($r);
 7706:         } elsif ($env{'form.action'} eq 'settable') {
 7707:             &assessparms($r,$parm_permission);
 7708:         } elsif ($env{'form.action'} eq 'parameterchangelog') {
 7709:             &parm_change_log($r,$parm_permission);
 7710:         } elsif ($env{'form.action'} eq 'cleanparameters') {
 7711:             &clean_parameters($r);
 7712:         } elsif ($env{'form.action'} eq 'dateshift1') {
 7713:             &date_shift_one($r);
 7714:         } elsif ($env{'form.action'} eq 'dateshift2') {
 7715:             &date_shift_two($r);
 7716:         }
 7717:     } else {
 7718: # ----------------------------- Not in a course, or not allowed to modify parms
 7719:         if ($exists) {
 7720:             $env{'user.error.msg'}=
 7721:             "/adm/parmset:opa:0:0:Cannot modify assessment parameters";
 7722:         } else {
 7723:             $env{'user.error.msg'}=
 7724:             "/adm/parmset::0:1:Course environment gone, reinitialize the course";
 7725:         }
 7726:         return HTTP_NOT_ACCEPTABLE;
 7727:     }
 7728:     &reset_caches();
 7729: 
 7730:     return OK;
 7731: }
 7732: 
 7733: 1;
 7734: __END__
 7735: 
 7736: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>