File:  [LON-CAPA] / loncom / interface / lonparmset.pm
Revision 1.593: download - view: text, annotated - select for diffs
Tue Jan 14 21:09:19 2020 UTC (4 years, 4 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Reverse part of changes in 1.554.
  $name: third arg in calls to &valout() was never used by routine, so
  remove it.

    1: # The LearningOnline Network with CAPA
    2: # Handler to set parameters for assessments
    3: #
    4: # $Id: lonparmset.pm,v 1.593 2020/01/14 21:09:19 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,$name,$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 ipallowRegExp = /^setipallow_/;
 1245:     var ipdenyRegExp = /^setipdeny_/; 
 1246:     var deeplinkRegExp = /^deeplink_(listing|scope)_/;
 1247:     var deeplinkUrlsRegExp = /^deeplink_urls_/;
 1248:     var deeplinkltiRegExp = /^deeplink_lti_/;
 1249:     var deeplinkkeyRegExp = /^deeplink_key_/;
 1250:     var patternIP = /[\[\]\*\.a-zA-Z\d\-]+/;
 1251:     if ((document.parmform.elements.length != 'undefined')  && (document.parmform.elements.length) != 'null') {
 1252:         if (document.parmform.elements.length) {
 1253:             for (i=0; i<document.parmform.elements.length; i++) {
 1254:                 var name=document.parmform.elements[i].name;
 1255:                 if (textRegExp.test(name)) {
 1256:                     var identifier = name.replace(textRegExp,'');
 1257:                     if (tailLenient.test(identifier)) {
 1258:                         if (document.parmform.elements['set_'+identifier].length) {
 1259:                             for (var j=0; j<document.parmform.elements['set_'+identifier].length; j++) {
 1260:                                 if (document.parmform.elements['set_'+identifier][j].checked) {
 1261:                                     if (!(patternLenientStd.test(document.parmform.elements['set_'+identifier][j].value))) {
 1262:                                         var relweight = document.parmform.elements[i].value;
 1263:                                         relweight = relweight.replace(/^\s+|\s+$/g,'');
 1264:                                         if (!patternRelWeight.test(relweight)) {
 1265:                                             relweight = '0.0';
 1266:                                         }
 1267:                                         if (document.parmform.elements['set_'+identifier][j].value == 'weighted') {
 1268:                                             document.parmform.elements['set_'+identifier][j].value = relweight;
 1269:                                         } else {
 1270:                                             document.parmform.elements['set_'+identifier][j].value += ','+relweight;
 1271:                                         }
 1272:                                     }
 1273:                                     break;
 1274:                                 }
 1275:                             }
 1276:                         }
 1277:                     }
 1278:                 } else if (ipallowRegExp.test(name)) {
 1279:                     var identifier = name.replace(ipallowRegExp,'');
 1280:                     var possallow = document.parmform.elements[i].value;
 1281:                     possallow = possallow.replace(/^\s+|\s+$/g,'');
 1282:                     if (patternIP.test(possallow)) {
 1283:                         if (document.parmform.elements['set_'+identifier].value) {
 1284:                             possallow = ','+possallow;
 1285:                         }
 1286:                         document.parmform.elements['set_'+identifier].value += possallow;
 1287:                     }
 1288:                 } else if (ipdenyRegExp.test(name)) {
 1289:                     var identifier = name.replace(ipdenyRegExp,'');
 1290:                     var possdeny = document.parmform.elements[i].value;
 1291:                     possdeny = possdeny.replace(/^\s+|\s+$/g,'');
 1292:                     if (patternIP.test(possdeny)) {
 1293:                         possdeny = '!'+possdeny;
 1294:                         if (document.parmform.elements['set_'+identifier].value) {
 1295:                             possdeny = ','+possdeny;
 1296:                         }
 1297:                         document.parmform.elements['set_'+identifier].value += possdeny;
 1298:                     }
 1299:                 } else if (deeplinkRegExp.test(name)) {
 1300:                     var identifier =  name.replace(deeplinkRegExp,'');
 1301:                     var possdeeplink = document.parmform.elements[i].value;
 1302:                     possdeeplink = possdeeplink.replace(/^\s+|\s+$/g,'');
 1303:                     if (document.parmform.elements['set_'+identifier].value) {
 1304:                         possdeeplink = ','+possdeeplink;
 1305:                     }
 1306:                     document.parmform.elements['set_'+identifier].value += possdeeplink;
 1307:                 } else if (deeplinkUrlsRegExp.test(name)) {
 1308:                     if (document.parmform.elements[i].checked) {
 1309:                         var identifier =  name.replace(deeplinkUrlsRegExp,'');
 1310:                         var posslinkurl = document.parmform.elements[i].value;
 1311:                         posslinkurl = posslinkurl.replace(/^\s+|\s+$/g,'');
 1312:                         if (document.parmform.elements['set_'+identifier].value) {
 1313:                             posslinkurl = ','+posslinkurl;
 1314:                         }
 1315:                         document.parmform.elements['set_'+identifier].value += posslinkurl;
 1316:                     }
 1317:                 } else if (deeplinkltiRegExp.test(name)) {
 1318:                     var identifier = name.replace(deeplinkltiRegExp,'');
 1319:                     var posslti = document.parmform.elements[i].value;
 1320:                     posslti = posslti.replace(/\D+/g,'');
 1321:                     if (document.parmform.elements['set_'+identifier].value) {
 1322:                         posslti = ':'+posslti;
 1323:                     }
 1324:                     document.parmform.elements['set_'+identifier].value += posslti;
 1325:                 } else if (deeplinkkeyRegExp.test(name)) {
 1326:                     var identifier = name.replace(deeplinkkeyRegExp,'');
 1327:                     var posskey = document.parmform.elements[i].value;
 1328:                     posskey = posskey.replace(/\W+/g,'');
 1329:                     if (document.parmform.elements['set_'+identifier].value) {
 1330:                         posslti = ':'+posskey;
 1331:                     }
 1332:                     document.parmform.elements['set_'+identifier].value += posskey;
 1333:                 }
 1334:             }
 1335:         }
 1336:     }
 1337:     return true;
 1338: }
 1339: 
 1340: ENDSCRIPT
 1341: }
 1342: 
 1343: # Javascript initialization, for overview mode
 1344: sub ipacc_boxes_js  {
 1345:     my $remove = &mt('Remove');
 1346:     return <<"END";
 1347: \$(document).ready(function() {
 1348:     var wrapper         = \$(".LC_string_ipacc_wrap");
 1349:     var add_button      = \$(".LC_add_ipacc_button");
 1350:     var ipaccRegExp     = /^LC_string_ipacc_/;
 1351: 
 1352:     \$(add_button).click(function(e){
 1353:         e.preventDefault();
 1354:         var identifier = \$(this).closest("div").attr("id");
 1355:         identifier = identifier.replace(ipaccRegExp,'');
 1356:         \$(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>');
 1357:     });
 1358: 
 1359:     \$(wrapper).delegate(".LC_remove_ipacc","click", function(e){
 1360:         e.preventDefault(); \$(this).closest("div").remove();
 1361:     })
 1362: });
 1363: 
 1364: 
 1365: END
 1366: }
 1367: 
 1368: # Javascript function toggleSecret, for overview mode.
 1369: sub done_proctor_js {
 1370:     return <<"END";
 1371: function toggleSecret(form,radio,key) {
 1372:     var radios = form[radio+key];
 1373:     if (radios.length) {
 1374:         for (var i=0; i<radios.length; i++) {
 1375:             if (radios[i].checked) {
 1376:                 if (radios[i].value == '_done_proctor') {
 1377:                     if (document.getElementById('done_'+key+'_proctorkey')) {
 1378:                         document.getElementById('done_'+key+'_proctorkey').type='text';
 1379:                     }
 1380:                 } else {
 1381:                     if (document.getElementById('done_'+key+'_proctorkey')) {
 1382:                         document.getElementById('done_'+key+'_proctorkey').type='hidden';
 1383:                         document.getElementById('done_'+key+'_proctorkey').value='';
 1384:                     }
 1385:                 }
 1386:             }
 1387:         }
 1388:     }
 1389: }
 1390: END
 1391: 
 1392: }
 1393: 
 1394: # Javascript function toggle
 1395: sub deeplink_js {
 1396:     return <<"END";
 1397: function toggleDeepLink(form,item,key) {
 1398:     var radios = form['deeplink_'+item+'_'+key];
 1399:     if (radios.length) {
 1400:         var keybox;
 1401:         if (document.getElementById('deeplink_key_'+item+'_'+key)) {
 1402:             keybox = document.getElementById('deeplink_key_'+item+'_'+key);
 1403:         }
 1404:         var ltidiv;
 1405:         if (document.getElementById('deeplinkdiv_lti_'+item+'_'+key)) {
 1406:             ltidiv = document.getElementById('deeplinkdiv_lti_'+item+'_'+key);
 1407:         }
 1408:         for (var i=0; i<radios.length; i++) {
 1409:             if (radios[i].checked) {
 1410:                 if (radios[i].value == 'lti') {
 1411:                     ltidiv.style.display = 'inline-block';
 1412:                     keybox.type = 'hidden';
 1413:                     keybox.value = '';
 1414:                 } else {
 1415:                     if (ltidiv != '') {
 1416:                         ltidiv.style.display = 'none';
 1417:                         form['deeplink_lti_'+key].selectedIndex = 0;
 1418:                     }
 1419:                     if (radios[i].value == 'key') {
 1420:                         keybox.type = 'text';
 1421:                     } else {
 1422:                         keybox.type = 'hidden';
 1423:                     }
 1424:                 }
 1425:             }
 1426:         }
 1427:     }
 1428: }
 1429: END
 1430: 
 1431: }
 1432: 
 1433: # Prints HTML page start for table mode.
 1434: # @param {Apache2::RequestRec} $r - the Apache request
 1435: # @param {string} $psymb - resource symb
 1436: # @param {string} $crstype - course type (Community / Course / Placement Test)
 1437: sub startpage {
 1438:     my ($r,$psymb,$crstype) = @_;
 1439: 
 1440:     my %loaditems = (
 1441:                       'onload'   => "group_or_section('cgroup')",
 1442:                     );
 1443:     if (!$psymb) {
 1444:         $loaditems{'onload'} = "showHide_courseContent(); group_or_section('cgroup'); resize_scrollbox('mapmenuscroll','1','1');";
 1445:     }
 1446: 
 1447:     if ((($env{'form.command'} eq 'set') && ($env{'form.url'}) &&
 1448:             (!$env{'form.dis'})) || ($env{'form.symb'})) {
 1449:         &Apache::lonhtmlcommon::add_breadcrumb({help=>'Problem_Parameters',
 1450:             text=>"Problem Parameters"});
 1451:     } else {
 1452:         &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=settable',
 1453:             text=>"Table Mode",
 1454:             help => 'Course_Setting_Parameters'});
 1455:     }
 1456:     my $js = &page_js().'
 1457: <script type="text/javascript">
 1458: // <![CDATA[
 1459: '.
 1460:             &Apache::lonhtmlcommon::resize_scrollbox_js('params').'
 1461: // ]]>
 1462: </script>
 1463: ';
 1464:     my $start_page =
 1465:         &Apache::loncommon::start_page('Set/Modify Course Parameters',$js,
 1466:                                        {'add_entries' => \%loaditems,});
 1467:     my $breadcrumbs =
 1468:     &Apache::lonhtmlcommon::breadcrumbs('Table Mode Parameter Setting','Table_Mode');
 1469:     my $escfilter=&Apache::lonhtmlcommon::entity_encode($env{'form.filter'});
 1470:     my $escpart=&Apache::lonhtmlcommon::entity_encode($env{'form.part'});
 1471:     $r->print($start_page.$breadcrumbs);
 1472:     &startSettingsScreen($r,'parmset',$crstype);
 1473:     $r->print(<<ENDHEAD);
 1474: <form method="post" action="/adm/parmset?action=settable" name="parmform">
 1475: <input type="hidden" value="" name="pres_value" />
 1476: <input type="hidden" value="" name="pres_type" />
 1477: <input type="hidden" value="" name="pres_marker" />
 1478: <input type="hidden" value="1" name="prevvisit" />
 1479: <input type="hidden" value="$escfilter" name="filter" />
 1480: <input type="hidden" value="$escpart" name="part" />
 1481: ENDHEAD
 1482: }
 1483: 
 1484: 
 1485: # Prints a row for table mode (except for the tr start).
 1486: # Every time a hash reference is passed, a single entry is used, so print_row
 1487: # could just use these values, but why make it simple when it can be complicated ?
 1488: #
 1489: # @param {Apache2::RequestRec} $r - the Apache request
 1490: # @param {string} $which - parameter key ('parameter_'.part.'_'.name)
 1491: # @param {hash reference} $part - parameter key -> parameter part (can be problem part.'_'.response id for response parameters)
 1492: # @param {hash reference} $name - parameter key -> parameter name
 1493: # @param {hash reference} $symbp - map pc or resource/map id -> map src.'___(all)' or resource symb
 1494: # @param {string} $rid - resource id
 1495: # @param {hash reference} $default - parameter key -> resource parameter default value
 1496: # @param {hash reference} $defaulttype - parameter key -> resource parameter default type
 1497: # @param {hash reference} $display - parameter key -> full title for the parameter
 1498: # @param {string} $defbgone - user level and other levels background color
 1499: # @param {string} $defbgtwo - section level background color, also used for part number
 1500: # @param {string} $defbgthree - group level background color
 1501: # @param {string} $parmlev - parameter level (Resource:'full', Map:'map', Course:'general')
 1502: # @param {string} $uname - user name
 1503: # @param {string} $udom - user domain
 1504: # @param {string} $csec - section name
 1505: # @param {string} $cgroup - group name
 1506: # @param {array reference} $usersgroups - list of groups the user belongs to, if any
 1507: # @param {boolean} $noeditgrp - true if no edit is allowed for group level parameters
 1508: # @param {boolean} $readonly - true if no editing allowed.
 1509: # @param {array reference} - $recurseup - list of maps containing current one, ending at top-level.
 1510: # @param {hash reference} - $maptitles - - hash map id or src -> map title 
 1511: # @param {hash reference} - $allmaps_inverted - hash map src -> map pc
 1512: # @param {scalar reference} - $reclinks - number of "parameter in effect" cells with link to map where recursive param was set 
 1513: sub print_row {
 1514:     my ($r,$which,$part,$name,$symbp,$rid,$default,$defaulttype,$display,$defbgone,
 1515:     $defbgtwo,$defbgthree,$parmlev,$uname,$udom,$csec,$cgroup,$usersgroups,$noeditgrp,
 1516:     $readonly,$recurseup,$maptitles,$allmaps_inverted,$reclinks)=@_;
 1517:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 1518:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 1519:     my $courseopt=&Apache::lonnet::get_courseresdata($cnum,$cdom);
 1520:     my $numlinks = 0;
 1521: 
 1522:     # get the values for the parameter in cascading order
 1523:     # empty levels will remain empty
 1524:     my ($result,@outpar)=&parmval($$part{$which}.'.'.$$name{$which},
 1525:       $rid,$$default{$which},$uname,$udom,$csec,$cgroup,$courseopt);
 1526:     # get the type for the parameters
 1527:     # problem: these may not be set for all levels
 1528:     my ($typeresult,@typeoutpar)=&parmval($$part{$which}.'.'.
 1529:                                           $$name{$which}.'.type',$rid,
 1530:          $$defaulttype{$which},$uname,$udom,$csec,$cgroup,$courseopt);
 1531:     # cascade down manually
 1532:     my $cascadetype=$$defaulttype{$which};
 1533:     for (my $i=18;$i>0;$i--) {
 1534:         if ($typeoutpar[$i]) {
 1535:             $cascadetype=$typeoutpar[$i];
 1536:         } else {
 1537:             $typeoutpar[$i]=$cascadetype;
 1538:         }
 1539:     }
 1540:     my $parm=$$display{$which};
 1541: 
 1542:     if ($parmlev eq 'full') {
 1543:         $r->print('<td style="background-color:'.$defbgtwo.';" align="center">'
 1544:                   .($$part{$which} eq '0'?'0 ('.&mt('default').')':$$part{$which}).'</td>');
 1545:     } else {
 1546:         $parm=~s|\[.*\]\s||g;
 1547:     }
 1548:     my $automatic=&rulescache(($which=~/\_([^\_]+)$/)[0].'_triggers');
 1549:     if ($automatic) {
 1550:         $parm.='<span class="LC_warning"><br />'.&mt('Automatically sets').' '.join(', ',split(/\:/,$automatic)).'</span>';
 1551:     }
 1552:     $r->print('<td>'.$parm.'</td>');
 1553: 
 1554:     my $thismarker=$which;
 1555:     $thismarker=~s/^parameter\_//;
 1556:     my $mprefix=$rid.'&'.$thismarker.'&';
 1557:     my ($parmname)=($thismarker=~/\_([^\_]+)$/);
 1558:     my ($othergrp,$grp_parm,$controlgrp,$effective_parm,$effparm_rec,$effparm_level,
 1559:         $eff_groupparm,$recurse_check,$recursinfo,$extra);
 1560:     if ((ref($recurseup) eq 'ARRAY') && (@{$recurseup} > 0)) {
 1561:         if ($result eq '') {
 1562:             $recurse_check = 1;
 1563:         } elsif (($uname ne '') && ($result > 3)) {
 1564:             $recurse_check = 1;
 1565:         } elsif (($cgroup ne '') && ($result > 7)) {
 1566:             $recurse_check = 1;
 1567:         } elsif (($csec ne '') && ($result > 11)) {
 1568:             $recurse_check = 1;
 1569:         } elsif ($result > 17) {
 1570:             $recurse_check = 1;
 1571:         }
 1572:         if ($recurse_check) {
 1573:             my $what = $$part{$which}.'.'.$$name{$which};
 1574:             my $prefix;
 1575:             if (($uname ne '') && ($udom ne '')) {
 1576:                 my $useropt = &Apache::lonnet::get_userresdata($uname,$udom);
 1577:                 $prefix = $env{'request.course.id'};
 1578:                 $recursinfo = &get_recursive($recurseup,$useropt,$what,$prefix);
 1579:                 if (ref($recursinfo) eq 'ARRAY') {
 1580:                     $effparm_rec = 1;
 1581:                     $effparm_level = &mt('user: [_1]',$uname);
 1582:                 }
 1583:             }
 1584:             if (($cgroup ne '') && (!$effparm_rec)) {
 1585:                 $prefix = $env{'request.course.id'}.'.['.$cgroup.']';
 1586:                 $recursinfo = &get_recursive($recurseup,$courseopt,$what,$prefix);
 1587:                 if (ref($recursinfo) eq 'ARRAY') {
 1588:                     $effparm_rec = 1;
 1589:                     $effparm_level = &mt('group: [_1]',$cgroup);
 1590:                 }
 1591:             }
 1592:             if (($csec ne '') && (!$effparm_rec)) {
 1593:                 $prefix = $env{'request.course.id'}.'.['.$csec.']';
 1594:                 $recursinfo = &get_recursive($recurseup,$courseopt,$what,$prefix);
 1595:                 if (ref($recursinfo) eq 'ARRAY') {
 1596:                     $effparm_rec = 1;
 1597:                     $effparm_level = &mt('section: [_1]',$csec);
 1598:                 }
 1599:             }
 1600:             if (!$effparm_rec) {
 1601:                 $prefix = $env{'request.course.id'};
 1602:                 $recursinfo = &get_recursive($recurseup,$courseopt,$what,$prefix); 
 1603:                 if (ref($recursinfo) eq 'ARRAY') {
 1604:                     $effparm_rec = 1;
 1605:                 }
 1606:             }
 1607:         }
 1608:     }
 1609:     if ((!$effparm_rec) && ($result == 17 || $result == 11 || $result == 7 || $result == 3)) {
 1610:         $effparm_rec = 1;
 1611:     }
 1612:     if ((!$effparm_rec) && 
 1613:         (($$name{$which} eq 'encrypturl') || ($$name{$which} eq 'hiddenresource')) && 
 1614:         ($result == 16 || $result == 10 || $result == 6 || $result == 2)) {
 1615:         $effparm_rec = 1;
 1616:     }
 1617:     if ($parmname eq 'deeplink') {
 1618:         my %posslti;
 1619:         my %lti =
 1620:             &Apache::lonnet::get_domain_lti($env{'course.'.$env{'request.course.id'}.'.domain'},
 1621:                                             'provider');
 1622:         foreach my $item (keys(%lti)) {
 1623:             if (ref($lti{$item}) eq 'HASH') {
 1624:                 unless ($lti{$item}{'requser'}) {
 1625:                     $posslti{$item} = $lti{$item}{'consumer'};
 1626:                 }
 1627:             }
 1628:         }
 1629:         if (keys(%posslti)) {
 1630:             $extra = 'lti_';
 1631:             foreach my $lti (sort { $a <=> $b } keys(%posslti)) {
 1632:                 $extra .= $lti.':'.&js_escape($posslti{$lti}).',';
 1633:             }
 1634:             $extra =~ s/,$//;
 1635:         }
 1636:     }
 1637:     if ($parmlev eq 'general') {
 1638:         if ($uname) {
 1639:             &print_td($r,4,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra);
 1640:         } elsif ($cgroup) {
 1641:             &print_td($r,8,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp,$readonly,'',$extra);
 1642:         } elsif ($csec) {
 1643:             &print_td($r,12,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra);
 1644:         } else {
 1645:             &print_td($r,18,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra);
 1646:         }
 1647:     } elsif ($parmlev eq 'map') {
 1648:         if ($uname) {
 1649:             &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,1,$extra);
 1650:         } elsif ($cgroup) {
 1651:             &print_td($r,6,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp,$readonly,1,$extra);
 1652:         } elsif ($csec) {
 1653:             &print_td($r,10,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,1,$extra);
 1654:         } else {
 1655:             &print_td($r,16,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,1,$extra);
 1656:         }
 1657:     } else {
 1658:         if ($uname) {
 1659:             if (@{$usersgroups} > 1) {
 1660:                 (my $coursereply,$othergrp,$grp_parm,$controlgrp,my $grp_is_rec) =
 1661:                     &check_other_groups($$part{$which}.'.'.$$name{$which},
 1662:                        $rid,$cgroup,$defbgone,$usersgroups,$result,$courseopt);
 1663:                 if (($coursereply) && ($result > 4)) {
 1664:                     if (defined($controlgrp)) {
 1665:                         if ($cgroup ne $controlgrp) {
 1666:                             $eff_groupparm = $grp_parm;
 1667:                             undef($result);
 1668:                             undef($effparm_rec);
 1669:                             if ($grp_is_rec) {
 1670:                                  $effparm_rec = 1;
 1671:                             }
 1672:                         }
 1673:                     }
 1674:                 }
 1675:             }
 1676:         }
 1677: 
 1678:         &print_td($r,18,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra);
 1679:         &print_td($r,16,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,1,$extra);
 1680:         &print_td($r,15,'#FFDDDD',$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra);
 1681:         &print_td($r,14,'#FFDDDD',$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra);
 1682:         &print_td($r,13,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra);
 1683: 
 1684:         if ($csec) {
 1685:             &print_td($r,12,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra);
 1686:             &print_td($r,10,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,1,$extra);
 1687:             &print_td($r,9,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra);
 1688:         }
 1689: 
 1690:         if ($cgroup) {
 1691:             &print_td($r,8,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp,$readonly,'',$extra);
 1692:             &print_td($r,6,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp,$readonly,1,$extra);
 1693:             &print_td($r,5,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp.$readonly,'',$extra);
 1694:         }
 1695: 
 1696:         if ($uname) {
 1697:             if ($othergrp) {
 1698:                 $r->print($othergrp);
 1699:             }
 1700:             &print_td($r,4,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra);
 1701:             &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,1,$extra);
 1702:             &print_td($r,1,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra);
 1703:         }
 1704:     } # end of $parmlev if/else
 1705:     if (ref($recursinfo) eq 'ARRAY') {
 1706:         my $rectitle = &mt('recursive');
 1707:         if ((ref($maptitles) eq 'HASH') && (exists($maptitles->{$recursinfo->[2]}))) {
 1708:             if ((ref($allmaps_inverted) eq 'HASH') && (exists($allmaps_inverted->{$recursinfo->[2]}))) {
 1709:                 $rectitle = &mt('set in: [_1]','"'.
 1710:                                 '<a href="javascript:pjumprec('."'".$allmaps_inverted->{$recursinfo->[2]}."',".
 1711:                                                               "'$parmname','$$part{$which}'".');">'.
 1712:                                 $maptitles->{$recursinfo->[2]}.'</a>"');
 1713:               
 1714:                 $numlinks ++;
 1715:             }
 1716:         }
 1717:         my ($parmname)=($thismarker=~/\_([^\_]+)$/);
 1718:         $effective_parm = &valout($recursinfo->[0],$recursinfo->[1]);
 1719:         $r->print('<td style="background-color:#CCCCFF;" align="center">'.$effective_parm.
 1720:                   '<br /><span class="LC_parm_recursive">'.$rectitle.'&nbsp;'.
 1721:                   $effparm_level.'</span></td>');
 1722:     } else {
 1723:         if ($result) {
 1724:             $effective_parm = &valout($outpar[$result],$typeoutpar[$result]);
 1725:         }
 1726:         if ($eff_groupparm) {
 1727:             $effective_parm = $eff_groupparm;
 1728:         }
 1729:         $r->print('<td style="background-color:#CCCCFF;" align="center">'.$effective_parm.
 1730:                   ($effparm_rec?'<br /><span class="LC_parm_recursive">'.&mt('recursive').
 1731:                                 '</span>':'').'</td>');
 1732:     }
 1733:     if ($parmlev eq 'full') {
 1734:         my $sessionval=&Apache::lonnet::EXT('resource.'.$$part{$which}.
 1735:                                         '.'.$$name{$which},$$symbp{$rid});
 1736:         my $sessionvaltype=$typeoutpar[$result];
 1737:         if (!defined($sessionvaltype)) {
 1738:             $sessionvaltype=$$defaulttype{$which};
 1739:         }
 1740:         $r->print('<td style="background-color:#999999;" align="center"><font color="#FFFFFF">'.
 1741:                   &valout($sessionval,$sessionvaltype).'&nbsp;'.
 1742:                   '</font></td>');
 1743:     }
 1744:     $r->print('</tr>');
 1745:     $r->print("\n");
 1746:     if (($numlinks) && (ref($reclinks))) {
 1747:         $$reclinks = $numlinks;
 1748:     }
 1749: }
 1750: 
 1751: # Prints a cell for table mode.
 1752: #
 1753: # FIXME: some of these parameter names are uninspired ($which and $value)
 1754: # Also, it would make more sense to pass the display for this cell rather
 1755: # than the full display hash and the key to use.
 1756: #
 1757: # @param {Apache2::RequestRec} $r - the Apache request
 1758: # @param {integer} $which - level
 1759: # @param {string} $defbg - cell background color
 1760: # @param {integer} $result - the most specific level that is defined for that parameter
 1761: # @param {array reference} $outpar - array level -> parameter value (when defined)
 1762: # @param {string} $mprefix - resource id.'&'.part.'_'.parameter name.'&'
 1763: # @param {string} $value - parameter key ('parameter_'.part.'_'.name)
 1764: # @param {array reference} $typeoutpar - array level -> parameter type (when defined)
 1765: # @param {hash reference} $display - parameter key -> full title for the parameter
 1766: # @param {boolean} $noeditgrp - true if no edit is allowed for group level parameters
 1767: # @param {boolean} $readonly -true if editing not allowed.
 1768: # @param {boolean} $ismaplevel - true if level is for a map.
 1769: # @param {strring} $extra - extra informatio to pass to plink.
 1770: sub print_td {
 1771:     my ($r,$which,$defbg,$result,$outpar,$mprefix,$value,$typeoutpar,$display,
 1772:         $noeditgrp,$readonly,$ismaplevel,$extra)=@_;
 1773:     my ($ineffect,$recursive,$currval,$currtype,$currlevel);
 1774:     $ineffect = 0;
 1775:     $currval = $$outpar[$which];
 1776:     $currtype = $$typeoutpar[$which];
 1777:     $currlevel = $which;
 1778:     if (($result) && ($result == $which)) {
 1779:         $ineffect = 1;
 1780:     } 
 1781:     if ($ismaplevel) {
 1782:         if ($mprefix =~ /(hiddenresource|encrypturl)\&/) {
 1783:             if (($result) && ($result == $which)) {
 1784:                 $recursive = 1;
 1785:             }
 1786:         } elsif ($$outpar[$which+1] ne '') {
 1787:             $recursive = 1;
 1788:             $currlevel = $which+1;
 1789:             $currval = $$outpar[$currlevel];
 1790:             $currtype = $$typeoutpar[$currlevel];
 1791:             if (($result) && ($result == $currlevel)) {
 1792:                 $ineffect = 1;
 1793:             }
 1794:         }
 1795:     }
 1796:     $r->print('<td style="background-color:'.($ineffect?'#AAFFAA':$defbg).
 1797:               ';" align="center">');
 1798:     my $nolink = 0;
 1799:     if ($readonly) {
 1800:         $nolink = 1;
 1801:     } else { 
 1802:         if ($which == 14 || $which == 15 || $mprefix =~ /mapalias\&$/) {
 1803:             $nolink = 1;
 1804:         } elsif (($env{'request.course.sec'} ne '') && ($which > 12)) {
 1805:             $nolink = 1;
 1806:         } elsif ($which == 5 || $which ==  6 || $which == 7 || $which == 8) {
 1807:             if ($noeditgrp) {
 1808:                 $nolink = 1;
 1809:             }
 1810:         } elsif ($mprefix =~ /availablestudent\&$/) {
 1811:             if ($which > 4) {
 1812:                 $nolink = 1;
 1813:             }
 1814:         } elsif ($mprefix =~ /examcode\&$/) {
 1815:             unless ($which == 2) {
 1816:                 $nolink = 1;
 1817:             }
 1818:         }
 1819:     }
 1820:     if ($nolink) {
 1821:         my ($parmname)=((split(/\&/,$mprefix))[1]=~/\_([^\_]+)$/);
 1822:         $r->print(&valout($currval,$currtype));
 1823:     } else {
 1824:         $r->print(&plink($currtype,
 1825:                          $$display{$value},$currval,
 1826:                          $mprefix.$currlevel,'parmform.pres','psub',$recursive,
 1827:                          $extra));
 1828:     }
 1829:     $r->print('</td>'."\n");
 1830: }
 1831: 
 1832: # Returns HTML and other info for the cell added when a user is selected
 1833: # and that user is in several groups. This is the cell with the title "Control by other group".
 1834: #
 1835: # @param {string} $what - parameter part.'.'.parameter name
 1836: # @param {string} $rid - resource id
 1837: # @param {string} $cgroup - group name
 1838: # @param {string} $defbg - cell background color
 1839: # @param {array reference} $usersgroups - list of groups the user belongs to, if any
 1840: # @param {integer} $result - level
 1841: # @param {hash reference} $courseopt - course parameters hash (result of lonnet::get_courseresdata, dump of course's resourcedata.db)
 1842: # @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)
 1843: sub check_other_groups {
 1844:     my ($what,$rid,$cgroup,$defbg,$usersgroups,$result,$courseopt) = @_;
 1845:     my $courseid = $env{'request.course.id'};
 1846:     my $output;
 1847:     my $symb = &symbcache($rid);
 1848:     my $symbparm=$symb.'.'.$what;
 1849:     my $map=(&Apache::lonnet::decode_symb($symb))[0];
 1850:     my $recurseparm=$map.'___(rec).'.$what; 
 1851:     my $mapparm=$map.'___(all).'.$what;
 1852:     my ($coursereply,$resultitem,$resultgroup,$resultlevel,$resulttype) =
 1853:           &parm_control_group($courseid,$usersgroups,$symbparm,$mapparm,
 1854:                               $recurseparm,$what,$courseopt);
 1855:     my $bgcolor = $defbg;
 1856:     my ($grp_parm,$grp_is_rec);
 1857:     if (($coursereply) && ($cgroup ne $resultgroup)) {
 1858:         my ($parmname) = ($what =~ /\.([^.]+)$/);
 1859:         if ($result > 3) {
 1860:             $bgcolor = '#AAFFAA';
 1861:         }
 1862:         $grp_parm = &valout($coursereply,$resulttype);
 1863:         $output = '<td style="background-color:'.$bgcolor.';" align="center">';
 1864:         if ($resultgroup && $resultlevel) {
 1865:             if ($resultlevel eq 'recursive') {
 1866:                 $resultlevel = 'map/folder';
 1867:                 $grp_is_rec = 1;
 1868:             }
 1869:             $output .= '<small><b>'.$resultgroup.'</b> ('.$resultlevel.'): </small>'.$grp_parm.
 1870:                        ($grp_is_rec?'<span class="LC_parm_recursive">'.&mt('recursive').'</span>':'');
 1871:              
 1872:         } else {
 1873:             $output .= '&nbsp;';
 1874:         }
 1875:         $output .= '</td>';
 1876:     } else {
 1877:         $output .= '<td style="background-color:'.$bgcolor.';">&nbsp;</td>';
 1878:     }
 1879:     return ($coursereply,$output,$grp_parm,$resultgroup,$grp_is_rec);
 1880: }
 1881: 
 1882: # Looks for a group with a defined parameter for given user and parameter.
 1883: # Used by check_other_groups.
 1884: #
 1885: # @param {string} $courseid - the course id
 1886: # @param {array reference} $usersgroups - list of groups the user belongs to, if any
 1887: # @param {string} $symbparm - end of the course parameter hash key for the group resource level
 1888: # @param {string} $mapparm - end of the course parameter hash key for the group map/folder level
 1889: # @param {string} $recurseparm - end of the course parameter hash key for the group recursive level
 1890: # @param {string} $what - parameter part.'.'.parameter name
 1891: # @param {hash reference} $courseopt - course parameters hash
 1892: # @returns {Array} - (parameter value for the group, course parameter hash key for the parameter, name of the group, level name, parameter type)
 1893: sub parm_control_group {
 1894:     my ($courseid,$usersgroups,$symbparm,$mapparm,$recurseparm,$what,$courseopt) = @_;
 1895:     my ($coursereply,$resultitem,$resultgroup,$resultlevel,$resulttype);
 1896:     my $grpfound = 0;
 1897:     my @levels = ($symbparm,$mapparm,$recurseparm,$what);
 1898:     my @levelnames = ('resource','map/folder','recursive','general');
 1899:     foreach my $group (@{$usersgroups}) {
 1900:         if ($grpfound) { last; }
 1901:         for (my $i=0; $i<@levels; $i++) {
 1902:             my $item = $courseid.'.['.$group.'].'.$levels[$i];
 1903:             if (defined($$courseopt{$item})) {
 1904:                 $coursereply = $$courseopt{$item};
 1905:                 $resultitem = $item;
 1906:                 $resultgroup = $group;
 1907:                 $resultlevel = $levelnames[$i];
 1908:                 $resulttype = $$courseopt{$item.'.type'};
 1909:                 $grpfound = 1;
 1910:                 last;
 1911:             }
 1912:         }
 1913:     }
 1914:     return($coursereply,$resultitem,$resultgroup,$resultlevel,$resulttype);
 1915: }
 1916: 
 1917: 
 1918: 
 1919: # Extracts lots of information about all of the the course's resources into a variety of hashes, using lonnavmaps and lonnet::metadata.
 1920: # All the parameters are references and are filled by the sub.
 1921: #
 1922: # @param {array reference} $ids - resource and map ids
 1923: # @param {hash reference} $typep - hash resource/map id -> resource type (file extension)
 1924: # @param {hash reference} $keyp - hash resource/map id -> comma-separated list of parameter keys from lonnet::metadata
 1925: # @param {hash reference} $allparms - hash parameter name -> parameter title
 1926: # @param {hash reference} $allparts - hash parameter part -> part title (a parameter part can be problem part.'_'.response id for response parameters)
 1927: # @param {hash reference} $allmaps - hash map pc -> map src
 1928: # @param {hash reference} $mapp - hash map pc or resource/map id -> enclosing map src
 1929: # @param {hash reference} $symbp - hash map pc or resource/map id -> map src.'___(all)' for a map or resource symb for a resource
 1930: # @param {hash reference} $maptitles - hash map pc or src -> map title (this should really be two separate hashes)
 1931: # @param {hash reference} $uris - hash resource/map id -> resource src
 1932: # @param {hash reference} $keyorder - hash parameter key -> appearance rank for this parameter when looking through every resource and every parameter, starting at 100 (integer)
 1933: # @param {hash reference} $defkeytype - hash parameter name -> parameter type
 1934: sub extractResourceInformation {
 1935:     my $ids = shift;
 1936:     my $typep = shift;
 1937:     my $keyp = shift;
 1938:     my $allparms = shift;
 1939:     my $allparts = shift;
 1940:     my $allmaps = shift;
 1941:     my $mapp = shift;
 1942:     my $symbp = shift;
 1943:     my $maptitles=shift;
 1944:     my $uris=shift;
 1945:     my $keyorder=shift;
 1946:     my $defkeytype=shift;
 1947: 
 1948:     my $keyordercnt=100;
 1949: 
 1950:     my $navmap = Apache::lonnavmaps::navmap->new();
 1951:     my @allres=$navmap->retrieveResources(undef,undef,1,undef,1);
 1952:     foreach my $resource (@allres) {
 1953:         my $id=$resource->id();
 1954:         my ($mapid,$resid)=split(/\./,$id);
 1955:         if ($mapid eq '0') { next; }
 1956:         $$ids[$#$ids+1]=$id;
 1957:         my $srcf=$resource->src();
 1958:         $srcf=~/\.(\w+)$/;
 1959:         $$typep{$id}=$1;
 1960:         my $toolsymb;
 1961:         if ($srcf =~ /ext\.tool$/) {
 1962:             $toolsymb = $resource->symb();
 1963:         }
 1964:         $$keyp{$id}='';
 1965:         $$uris{$id}=$srcf;
 1966: 
 1967:         foreach my $key (split(/\,/,&Apache::lonnet::metadata($srcf,'allpossiblekeys',$toolsymb))) {
 1968:             next if ($key!~/^parameter_/);
 1969: 
 1970: # Hidden parameters
 1971:             next if (&Apache::lonnet::metadata($srcf,$key.'.hidden',$toolsymb) eq 'parm');
 1972: #
 1973: # allparms is a hash of parameter names
 1974: #
 1975:             my $name=&Apache::lonnet::metadata($srcf,$key.'.name',$toolsymb);
 1976:             if (!exists($$allparms{$name}) || $$allparms{$name} =~ m/^\s*$/ ) {
 1977:                 my ($display,$parmdis);
 1978:                 $display = &standard_parameter_names($name);
 1979:                 if ($display eq '') {
 1980:                     $display= &Apache::lonnet::metadata($srcf,$key.'.display',$toolsymb);
 1981:                     $parmdis = $display;
 1982:                     $parmdis =~ s/\s*\[Part.*$//g;
 1983:                 } else {
 1984:                     $parmdis = &mt($display);
 1985:                 }
 1986:                 $$allparms{$name}=$parmdis;
 1987:                 if (ref($defkeytype)) {
 1988:                     $$defkeytype{$name}=
 1989:                     &Apache::lonnet::metadata($srcf,$key.'.type',$toolsymb);
 1990:                 }
 1991:             }
 1992: 
 1993: #
 1994: # allparts is a hash of all parts
 1995: #
 1996:             my $part= &Apache::lonnet::metadata($srcf,$key.'.part',$toolsymb);
 1997:             $$allparts{$part} = &mt('Part: [_1]',$part);
 1998: #
 1999: # Remember all keys going with this resource
 2000: #
 2001:             if ($$keyp{$id}) {
 2002:                 $$keyp{$id}.=','.$key;
 2003:             } else {
 2004:                 $$keyp{$id}=$key;
 2005:             }   
 2006: #
 2007: # Put in order
 2008: #
 2009:             unless ($$keyorder{$key}) {
 2010:                 $$keyorder{$key}=$keyordercnt;
 2011:                 $keyordercnt++;
 2012:             }
 2013:         }
 2014: 
 2015: 
 2016:         if (!exists($$mapp{$mapid})) {
 2017:             $$mapp{$id}=
 2018:             &Apache::lonnet::declutter($resource->enclosing_map_src());
 2019:             $$mapp{$mapid}=$$mapp{$id};
 2020:             $$allmaps{$mapid}=$$mapp{$id};
 2021:             if ($mapid eq '1') {
 2022:                 $$maptitles{$mapid}=&mt('Main Content');
 2023:             } else {
 2024:                 $$maptitles{$mapid}=&Apache::lonnet::gettitle($$mapp{$id});
 2025:             }
 2026:             $$maptitles{$$mapp{$id}}=$$maptitles{$mapid};
 2027:             $$symbp{$mapid}=$$mapp{$id}.'___(all)';  # Added in rev. 1.57, but seems not to be used.
 2028:                                                      # Lines 1038 and 1114 which use $symbp{$mapid}
 2029:                                                      # are commented out in rev. 1.57
 2030:         } else {
 2031:             $$mapp{$id} = $$mapp{$mapid};
 2032:         }
 2033:         $$symbp{$id}=&Apache::lonnet::encode_symb($$mapp{$id},$resid,$srcf);
 2034:     }
 2035: }
 2036: 
 2037: sub get_recursive {
 2038:     my ($recurseup,$resdata,$what,$prefix) = @_; 
 2039:     if ((ref($resdata) eq 'HASH') && (ref($recurseup) eq 'ARRAY')) {
 2040:         foreach my $item (@{$recurseup}) {
 2041:             my $norecursechk=$prefix.'.'.$item.'___(all).'.$what;
 2042:             if (defined($resdata->{$norecursechk})) {
 2043:                 if ($what =~ /\.(encrypturl|hiddenresource)$/) {
 2044:                     my $type = $resdata->{$norecursechk.'.type'};
 2045:                     return [$resdata->{$norecursechk},$type,$item];
 2046:                 } else {
 2047:                     last;
 2048:                 }
 2049:             }
 2050:             my $recursechk=$prefix.'.'.$item.'___(rec).'.$what;
 2051:             if (defined($resdata->{$recursechk})) {
 2052:                 my $type = $resdata->{$recursechk.'.type'};
 2053:                 return [$resdata->{$recursechk},$type,$item];
 2054:             }
 2055:         }
 2056:     }
 2057:     return;
 2058: }
 2059: 
 2060: 
 2061: # Tells if a parameter type is a date.
 2062: #
 2063: # @param {string} type - parameter type
 2064: # @returns{boolean} - true if it is a date
 2065: sub isdateparm {
 2066:     my $type=shift;
 2067:     return (($type=~/^date/) && (!($type eq 'date_interval')));
 2068: }
 2069: 
 2070: # Determine if parameter type is specialized string type (i.e.,
 2071: # not just string or string_yesno.  
 2072: 
 2073: sub is_specialstring {
 2074:     my $type=shift;
 2075:     return (($type=~/^string_/) && (($type ne 'string_yesno')));
 2076: }
 2077: 
 2078: # Prints the HTML and Javascript to select parameters, with various shortcuts.
 2079: #
 2080: # @param {Apache2::RequestRec} $r - the Apache request
 2081: sub parmmenu {
 2082:     my ($r)=@_;
 2083:     $r->print(<<ENDSCRIPT);
 2084: <script type="text/javascript">
 2085: // <![CDATA[
 2086:     function checkall(value, checkName) {
 2087: 
 2088:         var li = "_li";
 2089:         var displayOverview = "";
 2090:         
 2091:         if (value == false) {
 2092:             displayOverview = "none"
 2093:         }
 2094: 
 2095:         for (i=0; i<document.forms.parmform.elements.length; i++) {
 2096:             ele = document.forms.parmform.elements[i];
 2097:             if (ele.name == checkName) {
 2098:                 document.forms.parmform.elements[i].checked=value;
 2099:             }
 2100:         }
 2101:     }
 2102: 
 2103:     function checkthis(thisvalue, checkName) {
 2104:         for (i=0; i<document.forms.parmform.elements.length; i++) {
 2105:             ele = document.forms.parmform.elements[i];
 2106:             if (ele.name == checkName) {
 2107:                 if (ele.value == thisvalue) {
 2108:                     document.forms.parmform.elements[i].checked=true;
 2109:                 }
 2110:             }
 2111:         }
 2112:     }
 2113: 
 2114:     function checkdates() {
 2115:         checkthis('duedate','pscat');
 2116:         checkthis('opendate','pscat');
 2117:         checkthis('answerdate','pscat');
 2118:     }
 2119: 
 2120:     function checkdisset() {
 2121:         checkthis('discussend','pscat');
 2122:         checkthis('discusshide','pscat');
 2123:         checkthis('discussvote','pscat');
 2124:     }
 2125: 
 2126:     function checkcontdates() {
 2127:         checkthis('contentopen','pscat');
 2128:         checkthis('contentclose','pscat');
 2129:     }
 2130: 
 2131:     function checkvisi() {
 2132:         checkthis('hiddenresource','pscat');
 2133:         checkthis('encrypturl','pscat');
 2134:         checkthis('problemstatus','pscat');
 2135:         checkthis('contentopen','pscat');
 2136:         checkthis('opendate','pscat');
 2137:     }
 2138: 
 2139:     function checkparts() {
 2140:         checkthis('hiddenparts','pscat');
 2141:         checkthis('display','pscat');
 2142:         checkthis('ordered','pscat');
 2143:     }
 2144: 
 2145:     function checkstandard() {
 2146:         checkall(false,'pscat');
 2147:         checkdates();
 2148:         checkthis('weight','pscat');
 2149:         checkthis('maxtries','pscat');
 2150:         checkthis('type','pscat');
 2151:         checkthis('problemstatus','pscat');
 2152:     }
 2153: 
 2154: // ]]>
 2155: </script>
 2156: ENDSCRIPT
 2157: 
 2158:     $r->print('<hr />');
 2159:     &shortCuts($r);
 2160:     $r->print('<hr />');
 2161: }
 2162: 
 2163: # Returns parameter categories.
 2164: #
 2165: # @returns {hash} - category name -> title in English
 2166: sub categories {
 2167:     return ('time_settings' => 'Time Settings',
 2168:     'grading' => 'Grading',
 2169:     'tries' => 'Tries',
 2170:     'problem_appearance' => 'Problem Appearance',
 2171:     'behaviour_of_input_fields' => 'Behaviour of Input Fields',
 2172:     'hiding' => 'Hiding',
 2173:     'high_level_randomization' => 'High Level Randomization',
 2174:     'slots' => 'Slots',
 2175:     'file_submission' => 'File Submission',
 2176:     'misc' => 'Miscellaneous' ); 
 2177: }
 2178: 
 2179: # Returns the category for each parameter.
 2180: #
 2181: # @returns {hash} - parameter name -> category name
 2182: sub lookUpTableParameter {
 2183:  
 2184:     return ( 
 2185:         'opendate' => 'time_settings',
 2186:         'duedate' => 'time_settings',
 2187:         'answerdate' => 'time_settings',
 2188:         'interval' => 'time_settings',
 2189:         'contentopen' => 'time_settings',
 2190:         'contentclose' => 'time_settings',
 2191:         'discussend' => 'time_settings',
 2192:         'printstartdate' => 'time_settings',
 2193:         'printenddate' => 'time_settings',
 2194:         'weight' => 'grading',
 2195:         'handgrade' => 'grading',
 2196:         'maxtries' => 'tries',
 2197:         'hinttries' => 'tries',
 2198:         'randomizeontries' => 'tries',
 2199:         'type' => 'problem_appearance',
 2200:         'problemstatus' => 'problem_appearance',
 2201:         'display' => 'problem_appearance',
 2202:         'ordered' => 'problem_appearance',
 2203:         'numbubbles' => 'problem_appearance',
 2204:         'tol' => 'behaviour_of_input_fields',
 2205:         'sig' => 'behaviour_of_input_fields',
 2206:         'turnoffunit' => 'behaviour_of_input_fields',
 2207:         'hiddenresource' => 'hiding',
 2208:         'hiddenparts' => 'hiding',
 2209:         'discusshide' => 'hiding',
 2210:         'buttonshide' => 'hiding',
 2211:         'turnoffeditor' => 'hiding',
 2212:         'encrypturl' => 'hiding',
 2213:         'deeplink' => 'hiding',
 2214:         'randomorder' => 'high_level_randomization',
 2215:         'randompick' => 'high_level_randomization',
 2216:         'available' => 'slots',
 2217:         'useslots' => 'slots',
 2218:         'availablestudent' => 'slots',
 2219:         'uploadedfiletypes' => 'file_submission',
 2220:         'maxfilesize' => 'file_submission',
 2221:         'cssfile' => 'misc',
 2222:         'mapalias' => 'misc',
 2223:         'acc' => 'misc',
 2224:         'maxcollaborators' => 'misc',
 2225:         'scoreformat' => 'misc',
 2226:         'lenient' => 'grading',
 2227:         'retrypartial' => 'tries',
 2228:         'discussvote'  => 'misc',
 2229:         'examcode' => 'high_level_randomization',
 2230:     );
 2231: }
 2232: 
 2233: # Adds the given parameter name to an array of arrays listing all parameters for each category.
 2234: #
 2235: # @param {string} $name - parameter name
 2236: # @param {array reference} $catList - array reference category name -> array reference of parameter names
 2237: sub whatIsMyCategory {
 2238:     my $name = shift;
 2239:     my $catList = shift;
 2240:     my @list;
 2241:     my %lookUpList = &lookUpTableParameter; #Initilize the lookupList
 2242:     my $cat = $lookUpList{$name};
 2243:     if (defined($cat)) {
 2244:         if (!defined($$catList{$cat})){
 2245:             push @list, ($name);
 2246:             $$catList{$cat} = \@list;
 2247:         } else {
 2248:             push @{${$catList}{$cat}}, ($name);     
 2249:         }
 2250:     } else {
 2251:         if (!defined($$catList{'misc'})){
 2252:             push @list, ($name);
 2253:             $$catList{'misc'} = \@list;
 2254:         } else {
 2255:             push @{${$catList}{'misc'}}, ($name);     
 2256:         }
 2257:     }        
 2258: }
 2259: 
 2260: # Sorts parameter names based on appearance order.
 2261: #
 2262: # @param {array reference} name - array reference of parameter names
 2263: # @param {hash reference} $keyorder - hash parameter key -> appearance rank
 2264: # @returns {Array} - array of parameter names
 2265: sub keysindisplayorderCategory {
 2266:     my ($name,$keyorder)=@_;
 2267:     return sort {
 2268:         $$keyorder{'parameter_0_'.$a} <=> $$keyorder{'parameter_0_'.$b}; 
 2269:     } ( @{$name});
 2270: }
 2271: 
 2272: # Returns a hash category name -> order, starting at 1 (integer)
 2273: #
 2274: # @returns {hash}
 2275: sub category_order {
 2276:     return (
 2277:         'time_settings' => 1,
 2278:         'grading' => 2,
 2279:         'tries' => 3,
 2280:         'problem_appearance' => 4,
 2281:         'hiding' => 5,
 2282:         'behaviour_of_input_fields' => 6,
 2283:         'high_level_randomization'  => 7,
 2284:         'slots' => 8,
 2285:         'file_submission' => 9,
 2286:         'misc' => 10
 2287:     );
 2288: 
 2289: }
 2290: 
 2291: # Prints HTML to let the user select parameters, from a list of all parameters organized by category.
 2292: #
 2293: # @param {Apache2::RequestRec} $r - the Apache request
 2294: # @param {hash reference} $allparms - hash parameter name -> parameter title
 2295: # @param {array reference} $pscat - list of selected parameter names
 2296: # @param {hash reference} $keyorder - hash parameter key -> appearance rank
 2297: sub parmboxes {
 2298:     my ($r,$allparms,$pscat,$keyorder)=@_;
 2299:     my %categories = &categories();
 2300:     my %category_order = &category_order();
 2301:     my %categoryList = (
 2302:         'time_settings' => [],
 2303:         'grading' => [],
 2304:         'tries' => [],
 2305:         'problem_appearance' => [],
 2306:         'behaviour_of_input_fields' => [],
 2307:         'hiding' => [],
 2308:         'high_level_randomization' => [],
 2309:         'slots' => [],
 2310:         'file_submission' => [],
 2311:         'misc' => [],
 2312:     );
 2313: 
 2314:     foreach my $tempparameter (keys(%$allparms)) {
 2315:         &whatIsMyCategory($tempparameter, \%categoryList);
 2316:     }
 2317:     #part to print the parm-list
 2318:     foreach my $key (sort { $category_order{$a} <=> $category_order{$b} } keys(%categoryList)) {
 2319:         next if (@{$categoryList{$key}} == 0);
 2320:         next if ($key eq '');
 2321:         $r->print('<div class="LC_Box LC_400Box">'
 2322:                  .'<h4 class="LC_hcell">'.&mt($categories{$key}).'</h4>'."\n");
 2323:         foreach my $tempkey (&keysindisplayorderCategory($categoryList{$key},$keyorder)) {
 2324:             next if ($tempkey eq '');
 2325:             $r->print('<span class="LC_nobreak">'
 2326:                      .'<label><input type="checkbox" name="pscat" '
 2327:                      .'value="'.$tempkey.'" ');
 2328:             if ($$pscat[0] eq "all" || grep $_ eq $tempkey, @{$pscat}) {
 2329:                 $r->print( ' checked="checked"');
 2330:             }
 2331:             $r->print(' />'.($$allparms{$tempkey}=~/\S/ ? $$allparms{$tempkey}
 2332:                                                       : $tempkey)
 2333:                      .'</label></span><br />'."\n");
 2334:         }
 2335:         $r->print('</div>');
 2336:     }
 2337:     $r->print("\n");
 2338: }
 2339: 
 2340: # Prints HTML with shortcuts to select groups of parameters in one click, or deselect all.
 2341: #
 2342: # @param {Apache2::RequestRec} $r - the Apache request
 2343: sub shortCuts {
 2344:     my ($r)=@_;
 2345: 
 2346:     # Parameter Selection
 2347:     $r->print(
 2348:         &Apache::lonhtmlcommon::start_funclist(&mt('Parameter Selection'))
 2349:        .&Apache::lonhtmlcommon::add_item_funclist(
 2350:             '<a href="javascript:checkall(true, \'pscat\')">'.&mt('Select All').'</a>')
 2351:        .&Apache::lonhtmlcommon::add_item_funclist(
 2352:             '<a href="javascript:checkstandard()">'.&mt('Select Common Only').'</a>')
 2353:        .&Apache::lonhtmlcommon::add_item_funclist(
 2354:             '<a href="javascript:checkall(false, \'pscat\')">'.&mt('Unselect All').'</a>')
 2355:        .&Apache::lonhtmlcommon::end_funclist()
 2356:     );
 2357: 
 2358:     # Add Selection for...
 2359:     $r->print(
 2360:         &Apache::lonhtmlcommon::start_funclist(&mt('Add Selection for...'))
 2361:        .&Apache::lonhtmlcommon::add_item_funclist(
 2362:             '<a href="javascript:checkdates()">'.&mt('Problem Dates').'</a>')
 2363:        .&Apache::lonhtmlcommon::add_item_funclist(
 2364:             '<a href="javascript:checkcontdates()">'.&mt('Content Dates').'</a>')
 2365:        .&Apache::lonhtmlcommon::add_item_funclist(
 2366:             '<a href="javascript:checkdisset()">'.&mt('Discussion Settings').'</a>')
 2367:        .&Apache::lonhtmlcommon::add_item_funclist(
 2368:             '<a href="javascript:checkvisi()">'.&mt('Visibilities').'</a>')
 2369:        .&Apache::lonhtmlcommon::add_item_funclist(
 2370:             '<a href="javascript:checkparts()">'.&mt('Part Parameters').'</a>')
 2371:        .&Apache::lonhtmlcommon::end_funclist()
 2372:     );
 2373: }
 2374: 
 2375: # Prints HTML to select parts to view (except for the title).
 2376: # Used by table and overview modes.
 2377: #
 2378: # @param {Apache2::RequestRec} $r - the Apache request
 2379: # @param {hash reference} $allparts - hash parameter part -> part title
 2380: # @param {array reference} $psprt - list of selected parameter parts
 2381: sub partmenu {
 2382:     my ($r,$allparts,$psprt)=@_;
 2383:     my $selsize = 1+scalar(keys(%{$allparts}));
 2384:     if ($selsize > 8) {
 2385:         $selsize = 8;
 2386:     }
 2387: 
 2388:     $r->print('<select multiple="multiple" name="psprt" size="'.$selsize.'">');
 2389:     $r->print('<option value="all"');
 2390:     $r->print(' selected="selected"') unless (@{$psprt}); # useless, the array is never empty
 2391:     $r->print('>'.&mt('All Parts').'</option>');
 2392:     my %temphash=();
 2393:     foreach (@{$psprt}) { $temphash{$_}=1; }
 2394:     foreach my $tempkey (sort {
 2395:                 if ($a==$b) { return ($a cmp $b) } else { return ($a <=> $b); }
 2396:             } keys(%{$allparts})) {
 2397:         unless ($tempkey =~ /\./) {
 2398:             $r->print('<option value="'.$tempkey.'"');
 2399:             if ($$psprt[0] eq "all" ||  $temphash{$tempkey}) {
 2400:                 $r->print(' selected="selected"');
 2401:             }
 2402:             $r->print('>'.$$allparts{$tempkey}.'</option>');
 2403:         }
 2404:     }
 2405:     $r->print('</select>');
 2406: }
 2407: 
 2408: # Prints HTML to select a user and/or a group.
 2409: # Used by table mode.
 2410: #
 2411: # @param {Apache2::RequestRec} $r - the Apache request
 2412: # @param {string} $uname - selected user name
 2413: # @param {string} $id - selected Student/Employee ID
 2414: # @param {string} $udom - selected user domain
 2415: # @param {string} $csec - selected section name
 2416: # @param {string} $cgroup - selected group name
 2417: # @param {string} $parmlev - parameter level (Resource:'full', Map:'map', Course:'general')
 2418: # @param {array reference} $usersgroups - list of groups the user belongs to, if any
 2419: # @param {string} $pssymb - resource symb (when a single resource is selected)
 2420: sub usermenu {
 2421:     my ($r,$uname,$id,$udom,$csec,$cgroup,$parmlev,$usersgroups,$pssymb)=@_;
 2422:     my $chooseopt=&Apache::loncommon::select_dom_form($udom,'udom').' '.
 2423:         &Apache::loncommon::selectstudent_link('parmform','uname','udom');
 2424:     my $selscript=&Apache::loncommon::studentbrowser_javascript();
 2425: 
 2426:     my $sections='';
 2427:     my %sectionhash = &Apache::loncommon::get_sections();
 2428: 
 2429:     my $groups;
 2430:     my %grouphash;
 2431:     if (($pssymb) || &Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
 2432:         %grouphash = &Apache::longroup::coursegroups();
 2433:     } elsif ($env{'request.course.groups'} ne '') {
 2434:         map { $grouphash{$_} = 1; } split(/:/,$env{'request.course.groups'});
 2435:     }
 2436: 
 2437:     my $g_s_header='';
 2438:     my $g_s_footer='';
 2439: 
 2440:     my $currsec = $env{'request.course.sec'};
 2441:     if ($currsec) {
 2442:         $sections=&mt('Section:').' '.$currsec;
 2443:         if (%grouphash) {
 2444:             $sections .= ';'.('&nbsp;' x2);
 2445:         }
 2446:     } elsif (%sectionhash && $currsec eq '') {
 2447:         $sections=&mt('Section:').' <select name="csec"';
 2448:         if (%grouphash && $parmlev ne 'full') {
 2449:             $sections .= qq| onchange="group_or_section('csec')" |;
 2450:         }
 2451:         $sections .= '>';
 2452:     foreach my $section ('',sort(keys(%sectionhash))) {
 2453:         $sections.='<option value="'.$section.'" '.
 2454:         ($section eq $csec?'selected="selected"':'').'>'.$section.
 2455:                                                               '</option>';
 2456:         }
 2457:         $sections.='</select>';
 2458:     }
 2459: 
 2460:     if (%sectionhash && %grouphash && $parmlev ne 'full' && $currsec eq '') {
 2461:         $sections .= '&nbsp;'.&mt('or').'&nbsp;';
 2462:         $sections .= qq|
 2463: <script type="text/javascript">
 2464: // <![CDATA[
 2465: function group_or_section(caller) {
 2466:    if (caller == "cgroup") {
 2467:        if (document.parmform.cgroup.selectedIndex != 0) {
 2468:            document.parmform.csec.selectedIndex = 0;
 2469:        }
 2470:    } else {
 2471:        if (document.parmform.csec.selectedIndex != 0) {
 2472:            document.parmform.cgroup.selectedIndex = 0;
 2473:        }
 2474:    }
 2475: }
 2476: // ]]>
 2477: </script>
 2478: |;
 2479:     } else {
 2480:         $sections .= qq|
 2481: <script type="text/javascript">
 2482: // <![CDATA[
 2483: function group_or_section(caller) {
 2484:     return;
 2485: }
 2486: // ]]>
 2487: </script>
 2488: |;
 2489:     }
 2490: 
 2491:     if (%grouphash) {
 2492:         $groups=&mt('Group:').' <select name="cgroup"';
 2493:         if (%sectionhash && $env{'form.action'} eq 'settable' && $currsec eq '') {
 2494:             $groups .= qq| onchange="group_or_section('cgroup')" |;
 2495:         }
 2496:         $groups .= '>';
 2497:         foreach my $grp ('',sort(keys(%grouphash))) {
 2498:             $groups.='<option value="'.$grp.'" ';
 2499:             if ($grp eq $cgroup) {
 2500:                 unless ((defined($uname)) && ($grp eq '')) {
 2501:                     $groups .=  'selected="selected" ';
 2502:                 }
 2503:             } elsif (!defined($cgroup)) {
 2504:                 if (@{$usersgroups} == 1) {
 2505:                     if ($grp eq $$usersgroups[0]) {
 2506:                         $groups .=  'selected="selected" ';
 2507:                     }
 2508:                 }
 2509:             }
 2510:             $groups .= '>'.$grp.'</option>';
 2511:         }
 2512:         $groups.='</select>';
 2513:     }
 2514: 
 2515:     if (%sectionhash || %grouphash) {
 2516:         $r->print(&Apache::lonhtmlcommon::row_title(&mt('Group/Section')));
 2517:         $r->print($sections.$groups);
 2518:         $r->print(&Apache::lonhtmlcommon::row_closure());
 2519:     } else {
 2520:         $r->print($sections); 
 2521:     }
 2522: 
 2523:     $r->print(&Apache::lonhtmlcommon::row_title(&mt('User')));
 2524:     $r->print(&mt('For User [_1] or Student/Employee ID [_2] at Domain [_3]'
 2525:                  ,'<input type="text" value="'.$uname.'" size="12" name="uname" />'
 2526:                  ,'<input type="text" value="'.$id.'" size="12" name="id" /> '
 2527:                  ,$chooseopt));
 2528: }
 2529: 
 2530: # Prints HTML to select parameters from a list of all parameters.
 2531: # Uses parmmenu and parmboxes.
 2532: # Used by table and overview modes.
 2533: #
 2534: # @param {Apache2::RequestRec} $r - the Apache request
 2535: # @param {hash reference} $allparms - hash parameter name -> parameter title
 2536: # @param {array reference} $pscat - list of selected parameter names
 2537: # @param {hash reference} $keyorder - hash parameter key -> appearance rank
 2538: # @param {string} [$divid] - name used to give an id to the HTML element for the scroll box
 2539: sub displaymenu {
 2540:     my ($r,$allparms,$pscat,$keyorder,$divid)=@_;
 2541: 
 2542:     $r->print(&Apache::lonhtmlcommon::start_pick_box());
 2543:     $r->print(&Apache::lonhtmlcommon::row_title(&mt('Select Parameters to View')));
 2544: 
 2545:     &parmmenu($r);
 2546:     $r->print(&Apache::loncommon::start_scrollbox('480px','440px','200px',$divid));
 2547:     &parmboxes($r,$allparms,$pscat,$keyorder);
 2548:     $r->print(&Apache::loncommon::end_scrollbox());
 2549: 
 2550:     $r->print(&Apache::lonhtmlcommon::row_closure(1));
 2551:     $r->print(&Apache::lonhtmlcommon::end_pick_box());
 2552:  
 2553: }
 2554: 
 2555: # Prints HTML to select a map.
 2556: # Used by table mode and overview mode.
 2557: #
 2558: # @param {Apache2::RequestRec} $r - the Apache request
 2559: # @param {hash reference} $allmaps - hash map pc -> map src
 2560: # @param {string} $pschp - selected map pc, or 'all'
 2561: # @param {hash reference} $maptitles - hash map id or src -> map title
 2562: # @param {hash reference} $symbp - hash map pc or resource/map id -> map src.'___(all)' or resource symb
 2563: sub mapmenu {
 2564:     my ($r,$allmaps,$pschp,$maptitles,$symbp)=@_;
 2565:     my %allmaps_inverted = reverse %$allmaps;
 2566:     my $navmap = Apache::lonnavmaps::navmap->new();
 2567:     my $tree=[];
 2568:     my $treeinfo={};
 2569:     if (defined($navmap)) {
 2570:         my $it=$navmap->getIterator(undef,undef,undef,1,1,undef);
 2571:         my $curRes;
 2572:         my $depth = 0;
 2573:         my %parent = ();
 2574:         my $startcount = 5;
 2575:         my $lastcontainer = $startcount;
 2576: # preparing what is to show ...
 2577:         while ($curRes = $it->next()) {
 2578:             if ($curRes == $it->BEGIN_MAP()) {
 2579:                 $depth++;
 2580:                 $parent{$depth}= $lastcontainer;
 2581:             }
 2582:             if ($curRes == $it->END_MAP()) {
 2583:                 $depth--;
 2584:                 $lastcontainer = $parent{$depth};
 2585:             }
 2586:             if (ref($curRes)) {
 2587:                 my $symb = $curRes->symb();
 2588:                 my $ressymb = $symb;
 2589:                 if (($curRes->is_sequence()) || ($curRes->is_page())) {
 2590:                     my $type = 'sequence';
 2591:                     if ($curRes->is_page()) {
 2592:                         $type = 'page';
 2593:                     }
 2594:                     my $id= $curRes->id();
 2595:                     my $srcf = $curRes->src();
 2596:                     my $resource_name = &Apache::lonnet::gettitle($srcf);
 2597:                     if(!exists($treeinfo->{$id})) {
 2598:                         push(@$tree,$id);
 2599:                         my $enclosing_map_folder = &Apache::lonnet::declutter($curRes->enclosing_map_src());        
 2600:                         $treeinfo->{$id} = {
 2601:                                     depth => $depth,
 2602:                                     type  => $type,
 2603:                                     name  => $resource_name,
 2604:                                     enclosing_map_folder => $enclosing_map_folder,
 2605:                                     };
 2606:                     }
 2607:                 }
 2608:             }
 2609:         }
 2610:     }
 2611: # Show it ...    
 2612:     $r->print(&Apache::lonhtmlcommon::row_title(&mt('Select Enclosing Map or Folder'),'','',' id="mapmenu"'));
 2613:     if ((ref($tree) eq 'ARRAY') && (ref($treeinfo) eq 'HASH')) {
 2614:         my $icon = '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" />';
 2615:         my $whitespace =
 2616:             '<img src="'
 2617:            .&Apache::loncommon::lonhttpdurl('/adm/lonIcons/whitespace_21.gif')
 2618:            .'" alt="" />';
 2619: 
 2620:         # Info about selectable folders/maps
 2621:         $r->print(
 2622:             '<div class="LC_info">'
 2623:            .&mt('You can only select maps and folders which have modifiable settings.')
 2624:            .' '.&Apache::loncommon::help_open_topic('Parameter_Set_Folder') 
 2625:            .'</div>'
 2626:         );
 2627: 
 2628:         $r->print(&Apache::loncommon::start_scrollbox('700px','680px','400px','mapmenuscroll'));
 2629:         $r->print(&Apache::loncommon::start_data_table(undef,'mapmenuinner'));
 2630: 
 2631:         # Display row: "All Maps or Folders"
 2632:         $r->print(
 2633:             &Apache::loncommon::start_data_table_row(undef,'picklevel')
 2634:            .'<td>'
 2635:            .'<label>'
 2636:            .'<input type="radio" name="pschp"'
 2637:         );
 2638:         $r->print(' checked="checked"') if ($pschp eq 'all' || !$pschp);
 2639:         $r->print(
 2640:             ' value="all" />&nbsp;'.$icon.'&nbsp;'
 2641:            .&mt('All Maps or Folders')
 2642:            .'</label>'
 2643:            .'<hr /></td>'
 2644:            .&Apache::loncommon::end_data_table_row()
 2645:         );
 2646: 
 2647:         # Display row: "Main Content"
 2648:         if (exists($$allmaps{1})) {
 2649:             $r->print(
 2650:                 &Apache::loncommon::start_data_table_row()
 2651:                .'<td>'
 2652:                .'<label>'
 2653:                .'<input type="radio" name="pschp" value="1"'
 2654:             );
 2655:             $r->print(' checked="checked"') if ($pschp eq '1');
 2656:             $r->print(
 2657:                 '/>&nbsp;'.$icon.'&nbsp;'
 2658:                .$$maptitles{1}
 2659:                .($$allmaps{1} !~/^uploaded/?' ['.$$allmaps{1}.']':'')
 2660:                .'</label>'
 2661:                .'</td>'
 2662:                .&Apache::loncommon::end_data_table_row()
 2663:             );
 2664:         }
 2665: 
 2666:         # Display rows for all course maps and folders
 2667:         foreach my $id (@{$tree}) {
 2668:             my ($mapid,$resid)=split(/\./,$id);
 2669:             # Indentation
 2670:             my $depth = $treeinfo->{$id}->{'depth'};
 2671:             my $indent;
 2672:             for (my $i = 0; $i < $depth; $i++) {
 2673:                 $indent.= $whitespace;
 2674:             }
 2675:             $icon =  '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" />';
 2676:             if ($treeinfo->{$id}->{'type'} eq 'page') {
 2677:                 $icon = '<img src="/adm/lonIcons/navmap.page.open.gif" alt="" />';
 2678:             }
 2679:             my $symb_name = $$symbp{$id};
 2680:             my ($front, $tail) = split (/___${resid}___/, $symb_name);
 2681:             $symb_name = $tail;
 2682:             $r->print(
 2683:                 &Apache::loncommon::start_data_table_row()
 2684:                .'<td>'
 2685:                .'<label>'
 2686:             );
 2687:             # Only offer radio button for folders/maps which can be parameterized
 2688:             if ($allmaps_inverted{$symb_name}) {
 2689:                 $r->print(
 2690:                     '<input type ="radio" name="pschp"'
 2691:                    .' value="'.$allmaps_inverted{$symb_name}.'"'
 2692:                 );
 2693:                 $r->print(' checked="checked"') if ($allmaps_inverted{$symb_name} eq $pschp);
 2694:                 $r->print('/>');
 2695:             } else {
 2696:                 $r->print($whitespace);
 2697:             }
 2698:             $r->print(
 2699:                 $indent.$icon.'&nbsp;'
 2700:                .$treeinfo->{$id}->{name}
 2701:                .($$allmaps{$mapid}!~/^uploaded/?' ['.$$allmaps{$mapid}.']':'')
 2702:                .'</label>'
 2703:                .'</td>'
 2704:                .&Apache::loncommon::end_data_table_row()
 2705:             );
 2706:         }
 2707: 
 2708:         $r->print(&Apache::loncommon::end_data_table().
 2709:                   '<br style="line-height:2px;" />'.
 2710:                   &Apache::loncommon::end_scrollbox());
 2711:     }
 2712: }
 2713: 
 2714: # Prints HTML to select the parameter level (resource, map/folder or course).
 2715: # Used by table and overview modes.
 2716: #
 2717: # @param {Apache2::RequestRec} $r - the Apache request
 2718: # @param {hash reference} $alllevs - all parameter levels, hash English title -> value
 2719: # @param {string} $parmlev - selected level value (full|map|general), or ''
 2720: sub levelmenu {
 2721:     my ($r,$alllevs,$parmlev)=@_;
 2722: 
 2723:     $r->print(&Apache::lonhtmlcommon::row_title(&mt('Select Parameter Level').
 2724:                                                 &Apache::loncommon::help_open_topic('Course_Parameter_Levels')));
 2725:     $r->print('<select id="parmlev" name="parmlev" onchange="showHide_courseContent()">');
 2726:     foreach my $lev (reverse(sort(keys(%{$alllevs})))) {
 2727:         $r->print('<option value="'.$$alllevs{$lev}.'"');
 2728:         if ($parmlev eq $$alllevs{$lev}) {
 2729:             $r->print(' selected="selected"');
 2730:         }
 2731:         $r->print('>'.&mt($lev).'</option>');
 2732:     }
 2733:     $r->print("</select>");
 2734: }
 2735: 
 2736: 
 2737: # Returns HTML to select a section (with a select HTML element).
 2738: # Used by overview mode.
 2739: #
 2740: # @param {array reference} $selectedsections - list of selected section ids
 2741: # @returns {string}
 2742: sub sectionmenu {
 2743:     my ($selectedsections)=@_;
 2744:     my %sectionhash = &Apache::loncommon::get_sections();
 2745:     return '' if (!%sectionhash);
 2746: 
 2747:     my (@possibles,$disabled);
 2748:     if ($env{'request.course.sec'} ne '') {
 2749:         @possibles = ($env{'request.course.sec'});
 2750:         $selectedsections = [$env{'request.course.sec'}];
 2751:         $disabled = ' disabled="disabled"';
 2752:     } else {
 2753:         @possibles = ('all',sort(keys(%sectionhash)));
 2754:     }
 2755:     my $output = '<select name="Section" multiple="multiple" size="8"'.$disabled.'>';
 2756:     foreach my $s (@possibles) {
 2757:         $output .= '    <option value="'.$s.'"';
 2758:         if ((@{$selectedsections}) && (grep(/^\Q$s\E$/,@{$selectedsections}))) {  
 2759:             $output .= ' selected="selected"';
 2760:         }
 2761:         $output .= '>'."$s</option>\n";
 2762:     }
 2763:     $output .= "</select>\n";
 2764:     return $output;
 2765: }
 2766: 
 2767: # Returns HTML to select a group (with a select HTML element).
 2768: # Used by overview mode.
 2769: #
 2770: # @param {array reference} $selectedgroups - list of selected group names
 2771: # @returns {string}
 2772: sub groupmenu {
 2773:     my ($selectedgroups)=@_;
 2774:     my %grouphash;
 2775:     if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
 2776:         %grouphash = &Apache::longroup::coursegroups();
 2777:     } elsif ($env{'request.course.groups'} ne '') {
 2778:          map { $grouphash{$_} = 1; } split(/:/,$env{'request.course.groups'});
 2779:     }
 2780:     return '' if (!%grouphash);
 2781: 
 2782:     my $output = '<select name="Group" multiple="multiple" size="8">';
 2783:     foreach my $group (sort(keys(%grouphash))) {
 2784:         $output .= '    <option value="'.$group.'"';
 2785:         if ((@{$selectedgroups}) && (grep(/^\Q$group\E$/,\@{$selectedgroups}))) {
 2786:             $output .=  ' selected="selected"';
 2787:         }
 2788:         $output .= '>'."$group</option>\n";
 2789:     }
 2790:     $output .= "</select>\n";
 2791:     return $output;
 2792: }
 2793: 
 2794: # Returns an array with the given parameter split by comma.
 2795: # Used by assessparms (table mode).
 2796: #
 2797: # @param {string} $keyp - the string to split
 2798: # @returns {Array<string>}
 2799: sub keysplit {
 2800:     my $keyp=shift;
 2801:     return (split(/\,/,$keyp));
 2802: }
 2803: 
 2804: # Returns the keys in $name, sorted using $keyorder.
 2805: # Parameters are sorted by key, which means they are sorted by part first, then by name.
 2806: # Used by assessparms (table mode) for resource level.
 2807: #
 2808: # @param {hash reference} $name - parameter key -> parameter name
 2809: # @param {hash reference} $keyorder - hash parameter key -> appearance rank
 2810: # @returns {Array<string>}
 2811: sub keysinorder {
 2812:     my ($name,$keyorder)=@_;
 2813:     return sort {
 2814:         $$keyorder{$a} <=> $$keyorder{$b};
 2815:     } (keys(%{$name}));
 2816: }
 2817: 
 2818: # Returns the keys in $name, sorted using $keyorder to sort parameters by name first, then by part.
 2819: # Used by assessparms (table mode) for map and general levels.
 2820: #
 2821: # @param {hash reference} $name - parameter key -> parameter name
 2822: # @param {hash reference} $keyorder - hash parameter key -> appearance rank
 2823: # @returns {Array<string>}
 2824: sub keysinorder_bytype {
 2825:     my ($name,$keyorder)=@_;
 2826:     return sort {
 2827:         my $ta=(split('_',$a))[-1]; # parameter name
 2828:         my $tb=(split('_',$b))[-1];
 2829:         if ($$keyorder{'parameter_0_'.$ta} == $$keyorder{'parameter_0_'.$tb}) {
 2830:             return ($a cmp $b);
 2831:         }
 2832:         $$keyorder{'parameter_0_'.$ta} <=> $$keyorder{'parameter_0_'.$tb};
 2833:     } (keys(%{$name}));
 2834: }
 2835: 
 2836: # Returns the keys in $name, sorted using $keyorder to sort parameters by name.
 2837: # Used by defaultsetter (parameter settings default actions).
 2838: #
 2839: # @param {hash reference} $name - hash parameter name -> parameter title
 2840: # @param {hash reference} $keyorder - hash parameter key -> appearance rank
 2841: # @returns {Array<string>}
 2842: sub keysindisplayorder {
 2843:     my ($name,$keyorder)=@_;
 2844:     return sort {
 2845:         $$keyorder{'parameter_0_'.$a} <=> $$keyorder{'parameter_0_'.$b};
 2846:     } (keys(%{$name}));
 2847: }
 2848: 
 2849: # Prints HTML with a choice to sort results by realm or student first.
 2850: # Used by overview mode.
 2851: #
 2852: # @param {Apache2::RequestRec} $r - the Apache request
 2853: # @param {string} $sortorder - realmstudent|studentrealm
 2854: sub sortmenu {
 2855:     my ($r,$sortorder)=@_;
 2856:     $r->print('<br /><label><input type="radio" name="sortorder" value="realmstudent"');
 2857:     if ($sortorder eq 'realmstudent') {
 2858:        $r->print(' checked="checked"');
 2859:     }
 2860:     $r->print(' />'.&mt('Sort by realm first, then student (group/section)'));
 2861:     $r->print('</label><br /><label><input type="radio" name="sortorder" value="studentrealm"');
 2862:     if ($sortorder eq 'studentrealm') {
 2863:        $r->print(' checked="checked"');
 2864:     }
 2865:     $r->print(' />'.&mt('Sort by student (group/section) first, then realm').
 2866:           '</label>');
 2867: }
 2868: 
 2869: # Returns a hash parameter key -> order (integer) giving the order for some parameters.
 2870: #
 2871: # @returns {hash}
 2872: sub standardkeyorder {
 2873:     return ('parameter_0_opendate' => 1,
 2874:         'parameter_0_duedate' => 2,
 2875:         'parameter_0_answerdate' => 3,
 2876:         'parameter_0_interval' => 4,
 2877:         'parameter_0_weight' => 5,
 2878:         'parameter_0_maxtries' => 6,
 2879:         'parameter_0_hinttries' => 7,
 2880:         'parameter_0_contentopen' => 8,
 2881:         'parameter_0_contentclose' => 9,
 2882:         'parameter_0_type' => 10,
 2883:         'parameter_0_problemstatus' => 11,
 2884:         'parameter_0_hiddenresource' => 12,
 2885:         'parameter_0_hiddenparts' => 13,
 2886:         'parameter_0_display' => 14,
 2887:         'parameter_0_ordered' => 15,
 2888:         'parameter_0_tol' => 16,
 2889:         'parameter_0_sig' => 17,
 2890:         'parameter_0_turnoffunit' => 18,
 2891:         'parameter_0_discussend' => 19,
 2892:         'parameter_0_discusshide' => 20,
 2893:         'parameter_0_discussvote' => 21,
 2894:         'parameter_0_printstartdate'  =>  22,
 2895:         'parameter_0_printenddate' =>  23);
 2896: }
 2897: 
 2898: 
 2899: # Table mode UI.
 2900: # If nothing is selected, prints HTML forms to select resources, parts, parameters, user, group and section.
 2901: # Otherwise, prints the parameter table, with a link to change the selection unless a single resource is selected.
 2902: #
 2903: # Parameters used from the request:
 2904: # action - handler action (see handler), usermenu is checking for value 'settable'
 2905: # cgroup - selected group
 2906: # command - 'set': direct access to table mode for a resource
 2907: # csec - selected section
 2908: # dis - set when the "Update Display" button was used, used only to discard command 'set'
 2909: # hideparmsel - can be 'hidden' to hide the parameter selection div initially and display the "Change Parameter Selection" link instead (which displays the div)
 2910: # id - student/employee ID
 2911: # parmlev - selected level (full|map|general)
 2912: # part - selected part (unused ?)
 2913: # pres_marker - &&&-separated parameter identifiers, "resource id&part_parameter name&level"
 2914: # pres_type - &&&-separated parameter types
 2915: # pres_value - &&&-separated parameter values
 2916: # prevvisit - '1' if the user has submitted the form before
 2917: # pscat (multiple values) - selected parameter names
 2918: # pschp - selected map pc, or 'all'
 2919: # psprt (multiple values) - list of selected parameter parts
 2920: # filter - part of or whole parameter name, to be filtered out when parameters are displayed (unused ?)
 2921: # recent_* (* = parameter type) - recent values entered by the user for parameter types
 2922: # symb - resource symb (when a single resource is selected)
 2923: # udom - selected user domain
 2924: # uname - selected user name
 2925: # url - used only with command 'set', the resource url
 2926: #
 2927: # @param {Apache2::RequestRec} $r - the Apache request
 2928: # @param $parm_permission - ref to hash of permissions
 2929: #                           if $parm_permission->{'edit'} is true, editing is allowed.
 2930: sub assessparms {
 2931: 
 2932:     my ($r,$parm_permission) = @_;
 2933: 
 2934: 
 2935: # -------------------------------------------------------- Variable declaration
 2936:     my @ids=(); # resource and map ids
 2937:     my %symbp=(); # hash map pc or resource/map id -> map src.'___(all)' or resource symb
 2938:     my %mapp=(); # hash map pc or resource/map id -> enclosing map src
 2939:     my %typep=(); # hash resource/map id -> resource type (file extension)
 2940:     my %keyp=(); # hash resource/map id -> comma-separated list of parameter keys
 2941:     my %uris=(); # hash resource/map id -> resource src
 2942:     my %maptitles=(); # hash map pc or src -> map title
 2943:     my %allmaps=(); # hash map pc -> map src
 2944:     my %allmaps_inverted=(); # hash map src -> map pc
 2945:     my %alllevs=(); # hash English level title -> value
 2946: 
 2947:     my $uname; # selected user name
 2948:     my $udom; # selected user domain
 2949:     my $uhome; # server with the user's files, or 'no_host'
 2950:     my $csec; # selected section name
 2951:     my $cgroup; # selected group name
 2952:     my @usersgroups = (); # list of the user groups
 2953:     my $numreclinks = 0;
 2954: 
 2955:     my $coursename=$env{'course.'.$env{'request.course.id'}.'.description'};
 2956: 
 2957:     $alllevs{'Resource Level'}='full';
 2958:     $alllevs{'Map/Folder Level'}='map';
 2959:     $alllevs{'Course Level'}='general';
 2960: 
 2961:     my %allparms; # hash parameter name -> parameter title
 2962:     my %allparts; # hash parameter part -> part title
 2963: # ------------------------------------------------------------------------------
 2964: 
 2965: #
 2966: # Order in which these parameters will be displayed
 2967: #
 2968:     my %keyorder=&standardkeyorder();
 2969: 
 2970: #    @ids=();
 2971: #    %symbp=();       # These seem defined above already.
 2972: #    %typep=();
 2973: 
 2974:     my $message='';
 2975: 
 2976:     $csec=$env{'form.csec'};
 2977:     if ($env{'request.course.sec'} ne '') {
 2978:         $csec = $env{'request.course.sec'};    
 2979:     }
 2980: 
 2981: # Check group privs.
 2982:     $cgroup=$env{'form.cgroup'};
 2983:     my $noeditgrp; 
 2984:     if ($cgroup ne '') {
 2985:         unless (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
 2986:             if (($env{'request.course.groups'} eq '') || 
 2987:                 (!grep(/^\Q$cgroup\E$/,split(/:/,$env{'request.course.groups'})))) {
 2988:                 $noeditgrp = 1;
 2989:             }
 2990:         }
 2991:     }
 2992: 
 2993:     if      ($udom=$env{'form.udom'}) {
 2994:     } elsif ($udom=$env{'request.role.domain'}) {
 2995:     } elsif ($udom=$env{'user.domain'}) {
 2996:     } else {
 2997:         $udom=$r->dir_config('lonDefDomain');
 2998:     }
 2999:     
 3000: 
 3001:     my @pscat=&Apache::loncommon::get_env_multiple('form.pscat');
 3002:     my $pschp=$env{'form.pschp'};
 3003: 
 3004: 
 3005:     my @psprt=&Apache::loncommon::get_env_multiple('form.psprt');
 3006:     if (!@psprt) { $psprt[0]='all'; }
 3007:     if (($env{'form.part'}) && ($psprt[0] ne 'all')) { $psprt[0]=$env{'form.part'}; }
 3008: 
 3009:     my $pssymb='';
 3010:     my $parmlev='';
 3011: 
 3012:     unless ($env{'form.parmlev'}) {
 3013:         $parmlev = 'map';
 3014:     } else {
 3015:         $parmlev = $env{'form.parmlev'};
 3016:     }
 3017: 
 3018: # ----------------------------------------------- Was this started from grades?
 3019: 
 3020:     if (($env{'form.command'} eq 'set') && ($env{'form.url'}) &&
 3021:             (!$env{'form.dis'})) {
 3022:         my $url=$env{'form.url'};
 3023:         $url=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
 3024:         $pssymb=&Apache::lonnet::symbread($url);
 3025:         if (!@pscat) { @pscat=('all'); }
 3026:         $pschp='';
 3027:         $parmlev = 'full';
 3028:     } elsif ($env{'form.symb'}) {
 3029:         $pssymb=$env{'form.symb'};
 3030:         if (!@pscat) { @pscat=('all'); }
 3031:         $pschp='';
 3032:         $parmlev = 'full';
 3033:     } else {
 3034:         $env{'form.url'}='';
 3035:     }
 3036: 
 3037:     my $id=$env{'form.id'};
 3038:     if (($id) && ($udom)) {
 3039:         $uname=(&Apache::lonnet::idget($udom,[$id],'ids'))[1];
 3040:         if ($uname) {
 3041:             $id='';
 3042:         } else {
 3043:             $message=
 3044:                 '<p class="LC_warning">'.
 3045:                 &mt('Unknown ID [_1] at domain [_2]',
 3046:                     "'".$id."'","'".$udom."'").
 3047:                 '</p>';
 3048:         }
 3049:     } else {
 3050:         $uname=$env{'form.uname'};
 3051:     }
 3052:     unless ($udom) { $uname=''; }
 3053:     $uhome='';
 3054:     if ($uname) {
 3055:         $uhome=&Apache::lonnet::homeserver($uname,$udom);
 3056:         if ($uhome eq 'no_host') {
 3057:             $message=
 3058:                 '<p class="LC_warning">'.
 3059:                 &mt('Unknown user [_1] at domain [_2]',
 3060:                     "'".$uname."'","'".$udom."'").
 3061:                 '</p>';
 3062:             $uname='';
 3063:         } else {
 3064:             $csec=&Apache::lonnet::getsection($udom,$uname,
 3065:                           $env{'request.course.id'});
 3066:             if ($csec eq '-1') {
 3067:                 $message=
 3068:                     '<p class="LC_warning">'.
 3069:                     &mt('User [_1] at domain [_2] not in this course',
 3070:                         "'".$uname."'","'".$udom."'").
 3071:                     '</p>';
 3072:                 $uname='';
 3073:                 $csec=$env{'form.csec'};
 3074:                 $cgroup=$env{'form.cgroup'};
 3075:             } else {
 3076:                 my %name=&Apache::lonnet::userenvironment($udom,$uname,
 3077:                   ('firstname','middlename','lastname','generation','id'));
 3078:                 $message="\n<p>\n".&mt("Full Name").": ".
 3079:                 $name{'firstname'}.' '.$name{'middlename'}.' '
 3080:                 .$name{'lastname'}.' '.$name{'generation'}.
 3081:                 "<br />\n".&mt('Student/Employee ID').": ".$name{'id'}.'<p>';
 3082:             }
 3083:             @usersgroups = &Apache::lonnet::get_users_groups(
 3084:                                        $udom,$uname,$env{'request.course.id'});
 3085:             if (@usersgroups > 0) {
 3086:                 unless (grep(/^\Q$cgroup\E$/,@usersgroups)) {
 3087:                     $cgroup = $usersgroups[0];
 3088:                 }
 3089:             }
 3090:         }
 3091:     }
 3092: 
 3093:     unless ($csec) { $csec=''; }
 3094:     unless ($cgroup) { $cgroup=''; }
 3095: 
 3096: # --------------------------------------------------------- Get all assessments
 3097:     &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allmaps,
 3098:                 \%mapp, \%symbp,\%maptitles,\%uris,
 3099:                 \%keyorder);
 3100: 
 3101:     %allmaps_inverted = reverse(%allmaps);
 3102: 
 3103:     $mapp{'0.0'} = '';
 3104:     $symbp{'0.0'} = '';
 3105: 
 3106: # ---------------------------------------------------------- Anything to store?
 3107:     if ($env{'form.pres_marker'} && $parm_permission->{'edit'}) {
 3108:         my @markers=split(/\&\&\&/,$env{'form.pres_marker'});
 3109:         my @values=split(/\&\&\&/,$env{'form.pres_value'});
 3110:         my @types=split(/\&\&\&/,$env{'form.pres_type'});
 3111:         my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 3112:         my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 3113:         my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
 3114:         my ($got_chostname,$chostname,$cmajor,$cminor);
 3115:         my $totalstored = 0;
 3116:         my $now = time;
 3117:         for (my $i=0;$i<=$#markers;$i++) {
 3118:             my ($needsrelease,$needsnewer,$name,$namematch);
 3119:             if (($env{'request.course.sec'} ne '') && ($markers[$i] =~ /\&(9|10|11|12)$/)) {
 3120:                 next if ($csec ne $env{'request.course.sec'});
 3121:             }
 3122:             if ($markers[$i] =~ /\&(8|7|6|5)$/) {
 3123:                 next if ($noeditgrp);
 3124:             }
 3125:             if ($markers[$i] =~ /\&(17|11|7|3)$/) {
 3126:                 $namematch = 'maplevelrecurse';
 3127:             }
 3128:             if ($markers[$i] =~ /^[\d.]+\&0_availablestudent\&(1|2|3|4)$/) {
 3129:                 my (@ok_slots,@fail_slots,@del_slots);
 3130:                 my $courseopt=&Apache::lonnet::get_courseresdata($cnum,$cdom);
 3131:                 my ($level,@all) =
 3132:                     &parmval_by_symb('0.availablestudent',$pssymb,'',$uname,$udom,
 3133:                                      $csec,$cgroup,$courseopt);
 3134:                 foreach my $slot_name (split(/:/,$values[$i])) {
 3135:                     next if ($slot_name eq '');
 3136:                     if (&update_slots($slot_name,$cdom,$cnum,$pssymb,$uname,$udom) eq 'ok') {
 3137:                         push(@ok_slots,$slot_name);
 3138: 
 3139:                     } else {
 3140:                         push(@fail_slots,$slot_name);
 3141:                     }
 3142:                 }
 3143:                 if (@ok_slots) {
 3144:                     $values[$i] = join(':',@ok_slots);
 3145:                 } else {
 3146:                     $values[$i] = '';
 3147:                 }
 3148:                 if ($all[$level] ne '') {
 3149:                     my @existing = split(/:/,$all[$level]);
 3150:                     foreach my $slot_name (@existing) {
 3151:                         if (!grep(/^\Q$slot_name\E$/,split(/:/,$values[$i]))) {
 3152:                             if (&delete_slots($slot_name,$cdom,$cnum,$uname,$udom,$pssymb) eq 'ok') {
 3153:                                 push(@del_slots,$slot_name);
 3154:                             }
 3155:                         }
 3156:                     }
 3157:                 }
 3158:             } elsif ($markers[$i] =~ /_(type|lenient|retrypartial|discussvote|examcode|printstartdate|printenddate|acc|interval)\&\d+$/) {
 3159:                 $name = $1;
 3160:                 my $val = $values[$i];
 3161:                 my $valmatch = '';
 3162:                 if ($name eq 'examcode') {
 3163:                     if (&Apache::lonnet::validCODE($values[$i])) {
 3164:                         $val = 'valid';
 3165:                     }
 3166:                 } elsif ($name eq 'printstartdate') {
 3167:                     if ($val =~ /^\d+$/) {
 3168:                         if ($val > $now) {
 3169:                             $val = 'future';
 3170:                         }
 3171:                     } 
 3172:                 } elsif ($name eq 'printenddate') {
 3173:                     if ($val =~ /^\d+$/) {
 3174:                         if ($val < $now) {
 3175:                             $val = 'past';
 3176:                         }
 3177:                     }
 3178:                 } elsif (($name eq 'lenient') || ($name eq 'acc')) {
 3179:                     my $stringtype = &get_stringtype($name);
 3180:                     my $stringmatch = &standard_string_matches($stringtype);
 3181:                     if (ref($stringmatch) eq 'ARRAY') {
 3182:                         foreach my $item (@{$stringmatch}) {
 3183:                             if (ref($item) eq 'ARRAY') {
 3184:                                 my ($regexpname,$pattern) = @{$item};
 3185:                                 if ($pattern ne '') {
 3186:                                     if ($val =~ /$pattern/) {
 3187:                                         $valmatch = $regexpname;
 3188:                                         $val = '';
 3189:                                         last;
 3190:                                     }
 3191:                                 }
 3192:                             }
 3193:                         }
 3194:                     }
 3195:                 } elsif ($name eq 'interval') {
 3196:                     my $intervaltype = &get_intervaltype($name);
 3197:                     my $intervalmatch = &standard_interval_matches($intervaltype);
 3198:                     if (ref($intervalmatch) eq 'ARRAY') {
 3199:                         foreach my $item (@{$intervalmatch}) {
 3200:                             if (ref($item) eq 'ARRAY') {
 3201:                                 my ($regexpname,$pattern) = @{$item};
 3202:                                 if ($pattern ne '') {
 3203:                                     if ($val =~ /$pattern/) {
 3204:                                         $valmatch = $regexpname;
 3205:                                         $val = '';
 3206:                                         last;
 3207:                                     }
 3208:                                 }
 3209:                             }
 3210:                         }
 3211:                     }
 3212:                 }
 3213:                 $needsrelease =
 3214:                     $Apache::lonnet::needsrelease{"parameter:$name:$val:$valmatch:"};
 3215:                 if ($needsrelease) {
 3216:                     unless ($got_chostname) {
 3217:                         ($chostname,$cmajor,$cminor) = &parameter_release_vars();
 3218:                         $got_chostname = 1;
 3219:                     } 
 3220:                     $needsnewer = &parameter_releasecheck($name,$val,$valmatch,undef,
 3221:                                                           $needsrelease,
 3222:                                                           $cmajor,$cminor);
 3223:                 }
 3224:             }
 3225:             if ($needsnewer) {
 3226:                 undef($namematch);
 3227:             } else {
 3228:                 my $currneeded;
 3229:                 if ($needsrelease) {
 3230:                     $currneeded = $needsrelease;
 3231:                 }
 3232:                 if ($namematch) {
 3233:                     $needsrelease =
 3234:                         $Apache::lonnet::needsrelease{"parameter::::$namematch"};
 3235:                     if (($needsrelease) && (($currneeded eq '') || ($needsrelease < $currneeded))) {
 3236:                         unless ($got_chostname) {
 3237:                             ($chostname,$cmajor,$cminor) = &parameter_release_vars();
 3238:                             $got_chostname = 1;
 3239:                         }
 3240:                         $needsnewer = &parameter_releasecheck(undef,undef,undef,$namematch,
 3241:                                                               $needsrelease,
 3242:                                                               $cmajor,$cminor);
 3243:                     } else {
 3244:                         undef($namematch);
 3245:                     }
 3246:                 }
 3247:             }
 3248:             if ($needsnewer) {
 3249:                 $message .= &oldversion_warning($name,$namematch,$values[$i],$chostname,$cmajor,
 3250:                                                 $cminor,$needsrelease);
 3251:             } else {
 3252:                 $message.=&storeparm(split(/\&/,$markers[$i]),
 3253:                                      $values[$i],
 3254:                                      $types[$i],
 3255:                                      $uname,$udom,$csec,$cgroup);
 3256:                 $totalstored ++;
 3257:             }
 3258:         }
 3259: # ---------------------------------------------------------------- Done storing
 3260:         if ($totalstored) {
 3261:             $message.='<p class="LC_warning">'
 3262:                      .&mt('Changes can take up to 10 minutes before being active for all students.')
 3263:                      .&Apache::loncommon::help_open_topic('Caching')
 3264:                      .'</p>';
 3265:         }
 3266:     }
 3267: 
 3268: #----------------------------------------------- if all selected, fill in array
 3269:     if ($pscat[0] eq "all") {
 3270:         @pscat = (keys(%allparms));
 3271:     }
 3272:     if (!@pscat) {
 3273:         @pscat=('duedate','opendate','answerdate','weight','maxtries','type','problemstatus')
 3274:     };
 3275:     if ($psprt[0] eq "all" || !@psprt) {
 3276:         @psprt = (keys(%allparts));
 3277:     }
 3278: # ------------------------------------------------------------------ Start page
 3279: 
 3280:     my $crstype = &Apache::loncommon::course_type();
 3281:     &startpage($r,$pssymb,$crstype);
 3282: 
 3283:     foreach my $item ('tolerance','date_default','date_start','date_end',
 3284:             'date_interval','int','float','string','string_lenient',
 3285:             'string_examcode','string_deeplink','string_discussvote',
 3286:             'string_useslots','string_problemstatus','string_ip',
 3287:             'string_questiontype') {
 3288:         $r->print('<input type="hidden" value="'.
 3289:             &HTML::Entities::encode($env{'form.recent_'.$item},'"&<>').
 3290:             '" name="recent_'.$item.'" />');
 3291:     }
 3292: 
 3293:     # ----- Start Parameter Selection
 3294: 
 3295:     # Hide parm selection?
 3296:     $r->print(<<ENDPARMSELSCRIPT);
 3297: <script type="text/javascript">
 3298: // <![CDATA[
 3299: function parmsel_show() {
 3300:     document.getElementById('parmsel').style.display = "";
 3301:     document.getElementById('parmsellink').style.display = "none";
 3302: }
 3303: // ]]>
 3304: </script>
 3305: ENDPARMSELSCRIPT
 3306:     
 3307:     if (!$pssymb) {
 3308:         # No single resource selected, print forms to select things (hidden after first selection)
 3309:         my $parmselhiddenstyle=' style="display:none"';
 3310:         if($env{'form.hideparmsel'} eq 'hidden') {
 3311:            $r->print('<div id="parmsel"'.$parmselhiddenstyle.'>');
 3312:         } else  {
 3313:            $r->print('<div id="parmsel">');
 3314:         }
 3315: 
 3316:         # Step 1
 3317:         $r->print(&Apache::lonhtmlcommon::topic_bar(1,&mt('Resource Specification'),'parmstep1'));
 3318:         $r->print('
 3319: <script type="text/javascript">
 3320: // <![CDATA['.
 3321:                  &showhide_js().'
 3322: // ]]>
 3323: </script>
 3324: ');
 3325:         $r->print(&Apache::lonhtmlcommon::start_pick_box(undef,'parmlevel'));
 3326:         &levelmenu($r,\%alllevs,$parmlev);
 3327:         $r->print(&Apache::lonhtmlcommon::row_closure());
 3328:         &mapmenu($r,\%allmaps,$pschp,\%maptitles, \%symbp);
 3329:         $r->print(&Apache::lonhtmlcommon::row_closure());
 3330:         $r->print(&Apache::lonhtmlcommon::row_title(&mt('Select Parts to View')));
 3331:         &partmenu($r,\%allparts,\@psprt);
 3332:         $r->print(&Apache::lonhtmlcommon::row_closure(1));
 3333:         $r->print(&Apache::lonhtmlcommon::end_pick_box());
 3334: 
 3335:         # Step 2
 3336:         $r->print(&Apache::lonhtmlcommon::topic_bar(2,&mt('Parameter Specification'),'parmstep2'));
 3337:         &displaymenu($r,\%allparms,\@pscat,\%keyorder,'parmmenuscroll');
 3338: 
 3339:         # Step 3
 3340:         $r->print(&Apache::lonhtmlcommon::topic_bar(3,&mt('User Specification (optional)'),'parmstep3'));
 3341:         $r->print(&Apache::lonhtmlcommon::start_pick_box());
 3342:         &usermenu($r,$uname,$id,$udom,$csec,$cgroup,$parmlev,\@usersgroups,$pssymb);
 3343:         $r->print(&Apache::lonhtmlcommon::row_closure(1));
 3344:         $r->print(&Apache::lonhtmlcommon::end_pick_box());
 3345: 
 3346:         # Update Display Button
 3347:         $r->print('<p>'
 3348:              .'<input type="submit" name="dis"'
 3349:              .' value="'.&mt('Update Display').'" />'
 3350:              .'<input type="hidden" name="hideparmsel" value="hidden" />'
 3351:              .'</p>');
 3352:         $r->print('</div>');
 3353: 
 3354:         # Offer link to display parameter selection again
 3355:         $r->print('<p id="parmsellink"');
 3356:         if ($env{'form.hideparmsel'} ne 'hidden') {
 3357:            $r->print($parmselhiddenstyle);
 3358:         }
 3359:         $r->print('>'
 3360:              .'<a href="javascript:parmsel_show()">'
 3361:              .&mt('Change Parameter Selection')
 3362:              .'</a>'
 3363:              .'</p>');
 3364:     } else {
 3365:         # parameter screen for a single resource. 
 3366:         my ($map,$iid,$resource)=&Apache::lonnet::decode_symb($pssymb);
 3367:         my $title = &Apache::lonnet::gettitle($pssymb);
 3368:         $r->print(&mt('Specific Resource: [_1] ([_2])',
 3369:                          $title,'<span class="LC_filename">'.$resource.'</span>').
 3370:                 '<input type="hidden" value="'.$pssymb.'" name="symb" />'.
 3371:                   '<br />');
 3372:         $r->print(&Apache::lonhtmlcommon::topic_bar('',&mt('Additional Display Specification (optional)')));
 3373:         $r->print(&Apache::lonhtmlcommon::start_pick_box());
 3374:         &usermenu($r,$uname,$id,$udom,$csec,$cgroup,$parmlev,\@usersgroups,$pssymb);
 3375:         $r->print(&Apache::lonhtmlcommon::row_closure(1));
 3376:         $r->print(&Apache::lonhtmlcommon::end_pick_box());
 3377:         $r->print('<p>'
 3378:              .'<input type="submit" name="dis"'
 3379:              .' value="'.&mt('Update Display').'" />'
 3380:              .'<input type="hidden" name="hideparmsel" value="hidden" />'
 3381:              .'</p>');
 3382:     }
 3383:     
 3384:     # ----- End Parameter Selection
 3385: 
 3386:     # Display Messages
 3387:     $r->print('<div>'.$message.'</div>');
 3388: 
 3389: 
 3390:     my @temp_pscat;
 3391:     map {
 3392:         my $cat = $_;
 3393:         push(@temp_pscat, map { $_.'.'.$cat } @psprt);
 3394:     } @pscat;
 3395: 
 3396:     @pscat = @temp_pscat;
 3397: 
 3398: 
 3399:     if (($env{'form.prevvisit'}) || ($pschp) || ($pssymb)) {
 3400: # ----------------------------------------------------------------- Start Table
 3401:         my @catmarker=map { tr|.|_|; 'parameter_'.$_; } @pscat;
 3402:         my $csuname=$env{'user.name'};
 3403:         my $csudom=$env{'user.domain'};
 3404:         my $readonly = 1;
 3405:         if ($parm_permission->{'edit'}) {
 3406:             undef($readonly); 
 3407:         }
 3408: 
 3409:         if ($parmlev eq 'full') {
 3410: #
 3411: # This produces the cascading table output of parameters
 3412: #
 3413:             my $coursespan=$csec?8:5;
 3414:             my $userspan=3;
 3415:             if ($cgroup ne '') {
 3416:                 $coursespan += 3;
 3417:             }
 3418: 
 3419:             $r->print(&Apache::loncommon::start_data_table());
 3420:             #
 3421:             # This produces the headers
 3422:             #
 3423:             $r->print('<tr><td colspan="5"></td>');
 3424:             $r->print('<th colspan="'.($coursespan).'">'.&mt('Any User').'</th>');
 3425:             if ($uname) {
 3426:                 if (@usersgroups > 1) {
 3427:                     $userspan ++;
 3428:                 }
 3429:                 $r->print('<th colspan="'.$userspan.'" rowspan="2">');
 3430:                 $r->print(&mt('User [_1] at Domain [_2]',"'".$uname."'","'".$udom."'").'</th>');
 3431:             }
 3432:             my %lt=&Apache::lonlocal::texthash(
 3433:                 'pie'    => "Parameter in Effect",
 3434:                 'csv'    => "Current Session Value",
 3435:                 'rl'     => "Resource Level",
 3436:                 'ic'     => 'in Course',
 3437:                 'aut'    => "Assessment URL and Title",
 3438:                 'type'   => 'Type',
 3439:                 'emof'   => "Enclosing Map or Folder",
 3440:                 'part'   => 'Part',
 3441:                 'pn'     => 'Parameter Name',
 3442:                 'def'    => 'default',
 3443:                 'femof'  => 'from Enclosing Map or Folder',
 3444:                 'gen'    => 'general',
 3445:                 'foremf' => 'for Enclosing Map or Folder',
 3446:                 'fr'     => 'for Resource'
 3447:             );
 3448:             $r->print(<<ENDTABLETWO);
 3449: <th rowspan="3">$lt{'pie'}</th>
 3450: <th rowspan="3">$lt{'csv'}<br />($csuname:$csudom)</th>
 3451: </tr><tr><td colspan="5"></td><th colspan="2">$lt{'ic'}</th><th colspan="2">$lt{'rl'}</th>
 3452: <th colspan="1">$lt{'ic'}</th>
 3453: 
 3454: ENDTABLETWO
 3455:             if ($csec) {
 3456:                 $r->print('<th colspan="3">'.
 3457:                 &mt("in Section")." $csec</th>");
 3458:             }
 3459:             if ($cgroup) {
 3460:                 $r->print('<th colspan="3">'.
 3461:                 &mt("in Group")." $cgroup</th>");
 3462:             }
 3463:             $r->print(<<ENDTABLEHEADFOUR);
 3464: </tr><tr><th>$lt{'aut'}</th><th>$lt{'type'}</th>
 3465: <th>$lt{'emof'}</th><th>$lt{'part'}</th><th>$lt{'pn'}</th>
 3466: <th>$lt{'gen'}</th><th>$lt{'foremf'}</th>
 3467: <th>$lt{'def'}</th><th>$lt{'femof'}</th><th>$lt{'fr'}</th>
 3468: ENDTABLEHEADFOUR
 3469: 
 3470:             if ($csec) {
 3471:                 $r->print('<th>'.$lt{'gen'}.'</th><th>'.$lt{'foremf'}.'</th><th>'.$lt{'fr'}.'</th>');
 3472:             }
 3473: 
 3474:             if ($cgroup) {
 3475:                 $r->print('<th>'.$lt{'gen'}.'</th><th>'.$lt{'foremf'}.'</th><th>'.$lt{'fr'}.'</th>');
 3476:             }
 3477: 
 3478:             if ($uname) {
 3479:                 if (@usersgroups > 1) {
 3480:                     $r->print('<th>'.&mt('Control by other group?').'</th>');
 3481:                 }
 3482:                 $r->print('<th>'.$lt{'gen'}.'</th><th>'.$lt{'foremf'}.'</th><th>'.$lt{'fr'}.'</th>');
 3483:             }
 3484: 
 3485:             $r->print('</tr>');
 3486: #
 3487: # Done with the headers
 3488: # 
 3489:             my $defbgone='';
 3490:             my $defbgtwo='';
 3491:             my $defbgthree = '';
 3492: 
 3493:             foreach my $rid (@ids) {
 3494: 
 3495:                 my ($inmapid)=($rid=~/\.(\d+)$/);
 3496:                 if ((!$pssymb &&
 3497:                         (($pschp eq 'all') || ($allmaps{$pschp} eq $mapp{$rid})))
 3498:                         ||
 3499:                         ($pssymb && $pssymb eq $symbp{$rid})) {
 3500: # ------------------------------------------------------ Entry for one resource
 3501:                     if ($defbgone eq '#E0E099') {
 3502:                         $defbgone='#E0E0DD';
 3503:                     } else {
 3504:                         $defbgone='#E0E099';
 3505:                     }
 3506:                     if ($defbgtwo eq '#FFFF99') {
 3507:                         $defbgtwo='#FFFFDD';
 3508:                     } else {
 3509:                         $defbgtwo='#FFFF99';
 3510:                     }
 3511:                     if ($defbgthree eq '#FFBB99') {
 3512:                         $defbgthree='#FFBBDD';
 3513:                     } else {
 3514:                         $defbgthree='#FFBB99';
 3515:                     }
 3516: 
 3517:                     my $thistitle='';
 3518:                     my %name=   ();
 3519:                     undef %name;
 3520:                     my %part=   ();
 3521:                     my %display=();
 3522:                     my %type=   ();
 3523:                     my %default=();
 3524:                     my $uri=&Apache::lonnet::declutter($uris{$rid});
 3525:                     my $toolsymb;
 3526:                     if ($uri =~ /ext\.tool$/) {
 3527:                         $toolsymb = $symbp{$rid};
 3528:                     }
 3529: 
 3530:                     my $filter=$env{'form.filter'};
 3531:                     foreach my $tempkeyp (&keysplit($keyp{$rid})) {
 3532:                         if (grep $_ eq $tempkeyp, @catmarker) {
 3533:                             my $parmname=&Apache::lonnet::metadata($uri,$tempkeyp.'.name',$toolsymb);
 3534:     # We may only want certain parameters listed
 3535:                             if ($filter) {
 3536:                                 unless ($filter=~/\Q$parmname\E/) { next; }
 3537:                             }
 3538:                             $name{$tempkeyp}=$parmname;
 3539:                             $part{$tempkeyp}=&Apache::lonnet::metadata($uri,$tempkeyp.'.part',$toolsymb);
 3540: 
 3541:                             my $parmdis=&Apache::lonnet::metadata($uri,$tempkeyp.'.display',$toolsymb);
 3542:                             if ($allparms{$name{$tempkeyp}} ne '') {
 3543:                                 my $identifier;
 3544:                                 if ($parmdis =~ /(\s*\[Part.*)$/) {
 3545:                                     $identifier = $1;
 3546:                                 }
 3547:                                 $display{$tempkeyp} = $allparms{$name{$tempkeyp}}.$identifier;
 3548:                             } else {
 3549:                                 $display{$tempkeyp} = $parmdis;
 3550:                             }
 3551:                             unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
 3552:                             $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
 3553:                             $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$tempkeyp,$toolsymb);
 3554:                             $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$tempkeyp.'.type',$toolsymb);
 3555:                             $thistitle=&Apache::lonnet::metadata($uri,$tempkeyp.'.title',$toolsymb);
 3556:                         }
 3557:                     }
 3558:                     my $totalparms=scalar(keys(%name));
 3559:                     if ($totalparms>0) {
 3560:                         my $firstrow=1;
 3561:                         my $title=&Apache::lonnet::gettitle($symbp{$rid});
 3562:                         my $navmap = Apache::lonnavmaps::navmap->new();
 3563:                         my @recurseup;
 3564:                         if (ref($navmap) && $mapp{$rid}) {
 3565:                             @recurseup = $navmap->recurseup_maps($mapp{$rid});
 3566:                         }
 3567:                         $r->print('<tr><td style="background-color:'.$defbgone.';"'.
 3568:                              ' rowspan='.$totalparms.
 3569:                              '><tt><font size="-1">'.
 3570:                              join(' / ',split(/\//,$uri)).
 3571:                              '</font></tt><p><b>'.
 3572:                              "<a href=\"javascript:openWindow('".
 3573:                           &Apache::lonnet::clutter($uri).'?symb='.
 3574:                           &escape($symbp{$rid}).
 3575:                              "', 'metadatafile', '450', '500', 'no', 'yes');\"".
 3576:                              " target=\"_self\">$title");
 3577: 
 3578:                         if ($thistitle) {
 3579:                             $r->print(' ('.$thistitle.')');
 3580:                         }
 3581:                         $r->print('</a></b></td>');
 3582:                         $r->print('<td style="background-color:'.$defbgtwo.';"'.
 3583:                                       ' rowspan='.$totalparms.'>'.$typep{$rid}.
 3584:                                       '</td>');
 3585: 
 3586:                         $r->print('<td style="background-color:'.$defbgone.';"'.
 3587:                                       ' rowspan='.$totalparms.
 3588:                                       '>'.$maptitles{$mapp{$rid}}.'</td>');
 3589:                         foreach my $item (&keysinorder_bytype(\%name,\%keyorder)) {
 3590:                             unless ($firstrow) {
 3591:                                 $r->print('<tr>');
 3592:                             } else {
 3593:                                 undef $firstrow;
 3594:                             }
 3595:                             &print_row($r,$item,\%part,\%name,\%symbp,$rid,\%default,
 3596:                                        \%type,\%display,$defbgone,$defbgtwo,
 3597:                                        $defbgthree,$parmlev,$uname,$udom,$csec,
 3598:                                        $cgroup,\@usersgroups,$noeditgrp,$readonly,
 3599:                                        \@recurseup,\%maptitles,\%allmaps_inverted,
 3600:                                        \$numreclinks);
 3601:                         }
 3602:                     }
 3603:                 }
 3604:             } # end foreach ids
 3605: # -------------------------------------------------- End entry for one resource
 3606:             $r->print(&Apache::loncommon::end_data_table);
 3607:         } # end of  full
 3608: #--------------------------------------------------- Entry for parm level map
 3609:         if ($parmlev eq 'map') {
 3610:             my $defbgone = '#E0E099';
 3611:             my $defbgtwo = '#FFFF99';
 3612:             my $defbgthree = '#FFBB99';
 3613: 
 3614:             my %maplist;
 3615: 
 3616:             if ($pschp eq 'all') {
 3617:                 %maplist = %allmaps;
 3618:             } else {
 3619:                 %maplist = ($pschp => $mapp{$pschp});
 3620:             }
 3621: 
 3622: #-------------------------------------------- for each map, gather information
 3623:             my $mapid;
 3624:             foreach $mapid (sort {$maplist{$a} cmp $maplist{$b}} keys(%maplist)) {
 3625:                 my $maptitle = $maplist{$mapid};
 3626: 
 3627: #-----------------------  loop through ids and get all parameter types for map
 3628: #-----------------------------------------          and associated information
 3629:                 my %name = ();
 3630:                 my %part = ();
 3631:                 my %display = ();
 3632:                 my %type = ();
 3633:                 my %default = ();
 3634:                 my $map = 0;
 3635: 
 3636: #        $r->print("Catmarker: @catmarker<br />\n");
 3637: 
 3638:                 foreach my $id (@ids) {
 3639:                     ($map)=($id =~ /([\d]*?)\./);
 3640:                     my $rid = $id;
 3641: 
 3642: #                  $r->print("$mapid:$map:   $rid <br /> \n");
 3643: 
 3644:                     if ($map eq $mapid) {
 3645:                         my $uri=&Apache::lonnet::declutter($uris{$rid});
 3646:                         my $toolsymb;
 3647:                         if ($uri =~ /ext\.tool$/) {
 3648:                             $toolsymb = $symbp{$rid};
 3649:                         }
 3650: 
 3651: #                    $r->print("Keys: $keyp{$rid} <br />\n");
 3652: 
 3653: #--------------------------------------------------------------------
 3654: # @catmarker contains list of all possible parameters including part #s
 3655: # $fullkeyp contains the full part/id # for the extraction of proper parameters
 3656: # $tempkeyp contains part 0 only (no ids - ie, subparts)
 3657: # When storing information, store as part 0
 3658: # When requesting information, request from full part
 3659: #-------------------------------------------------------------------
 3660:                         foreach my $fullkeyp (&keysplit($keyp{$rid})) {
 3661:                             my $tempkeyp = $fullkeyp;
 3662:                             $tempkeyp =~ s/_\w+_/_0_/;
 3663: 
 3664:                             if ((grep $_ eq $fullkeyp, @catmarker) &&(!$name{$tempkeyp})) {
 3665:                                 $part{$tempkeyp}="0";
 3666:                                 $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name',$toolsymb);
 3667:                                 my $parmdis=&Apache::lonnet::metadata($uri,$fullkeyp.'.display',$toolsymb);
 3668:                                 if ($allparms{$name{$tempkeyp}} ne '') {
 3669:                                     my $identifier;
 3670:                                     if ($parmdis =~ /(\s*\[Part.*)$/) {
 3671:                                         $identifier = $1;
 3672:                                     }
 3673:                                     $display{$tempkeyp} = $allparms{$name{$tempkeyp}}.$identifier;
 3674:                                 } else {
 3675:                                     $display{$tempkeyp} = $parmdis;
 3676:                                 }
 3677:                                 unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
 3678:                                 $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
 3679:                                 $display{$tempkeyp} =~ s/_\w+_/_0_/;
 3680:                                 $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp,$toolsymb);
 3681:                                 $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type',$toolsymb);
 3682:                               }
 3683:                         } # end loop through keys
 3684:                     }
 3685:                 } # end loop through ids
 3686: 
 3687: #---------------------------------------------------- print header information
 3688:                 my $foldermap=&mt($maptitle=~/^uploaded/?'Folder':'Map');
 3689:                 my $showtitle=$maptitles{$maptitle}.($maptitle!~/^uploaded/?' ['.$maptitle.']':'');
 3690:                 my $tmp="";
 3691:                 if ($uname) {
 3692:                     my $person=&Apache::loncommon::plainname($uname,$udom);
 3693:                     $tmp.=&mt("User")." <font color=\"red\"><i>$uname \($person\) </i></font> ".
 3694:                         &mt('in')." \n";
 3695:                 } else {
 3696:                     $tmp.="<font color=\"red\"><i>".&mt('all').'</i></font> '.&mt('users in')." \n";
 3697:                 }
 3698:                 if ($cgroup) {
 3699:                     $tmp.=&mt("Group")." <font color=\"red\"><i>$cgroup".
 3700:                               "</i></font> ".&mt('of')." \n";
 3701:                     $csec = '';
 3702:                 } elsif ($csec) {
 3703:                     $tmp.=&mt("Section")." <font color=\"red\"><i>$csec".
 3704:                               "</i></font> ".&mt('of')." \n";
 3705:                 }
 3706:                 $r->print('<div align="center"><h4>'
 3707:                          .&mt('Set Defaults for All Resources in [_1]Specifically for [_2][_3]'
 3708:                              ,$foldermap.'<br /><font color="red"><i>'.$showtitle.'</i></font><br />'
 3709:                              ,$tmp
 3710:                              ,'<font color="red"><i>'.$coursename.'</i></font>'
 3711:                              )
 3712:                          ."<br /></h4>\n"
 3713:                 );
 3714: #---------------------------------------------------------------- print table
 3715:                 $r->print('<p>'.&Apache::loncommon::start_data_table()
 3716:                          .&Apache::loncommon::start_data_table_header_row()
 3717:                          .'<th>'.&mt('Parameter Name').'</th>'
 3718:                          .'<th>'.&mt('Value').'</th>'
 3719:                          .'<th>'.&mt('Parameter in Effect').'</th>'
 3720:                          .&Apache::loncommon::end_data_table_header_row()
 3721:                 );
 3722: 
 3723:                 my $navmap = Apache::lonnavmaps::navmap->new();
 3724:                 my @recurseup;
 3725:                 if (ref($navmap)) {
 3726:                      my $mapres = $navmap->getByMapPc($mapid);
 3727:                      if (ref($mapres)) {
 3728:                          @recurseup = $navmap->recurseup_maps($mapres->src());
 3729:                      }
 3730:                 }
 3731: 
 3732: 
 3733:                 foreach my $item (&keysinorder(\%name,\%keyorder)) {
 3734:                     $r->print(&Apache::loncommon::start_data_table_row());
 3735:                     &print_row($r,$item,\%part,\%name,\%symbp,$mapid,\%default,
 3736:                            \%type,\%display,$defbgone,$defbgtwo,$defbgthree,
 3737:                            $parmlev,$uname,$udom,$csec,$cgroup,'',$noeditgrp,
 3738:                            $readonly,\@recurseup,\%maptitles,\%allmaps_inverted,
 3739:                            \$numreclinks);
 3740:                 }
 3741:                 $r->print(&Apache::loncommon::end_data_table().'</p>'
 3742:                          .'</div>'
 3743:                 );
 3744:             } # end each map
 3745:         } # end of $parmlev eq map
 3746: #--------------------------------- Entry for parm level general (Course level)
 3747:         if ($parmlev eq 'general') {
 3748:             my $defbgone = '#E0E099';
 3749:             my $defbgtwo = '#FFFF99';
 3750:             my $defbgthree = '#FFBB99';
 3751: 
 3752: #-------------------------------------------- for each map, gather information
 3753:             my $mapid="0.0";
 3754: #-----------------------  loop through ids and get all parameter types for map
 3755: #-----------------------------------------          and associated information
 3756:             my %name = ();
 3757:             my %part = ();
 3758:             my %display = ();
 3759:             my %type = ();
 3760:             my %default = ();
 3761: 
 3762:             foreach $id (@ids) {
 3763:                 my $rid = $id;
 3764: 
 3765:                 my $uri=&Apache::lonnet::declutter($uris{$rid});
 3766:                 my $toolsymb;
 3767:                 if ($uri =~ /ext\.tool$/) {
 3768:                     $toolsymb = $symbp{$rid};
 3769:                 }
 3770: 
 3771: #--------------------------------------------------------------------
 3772: # @catmarker contains list of all possible parameters including part #s
 3773: # $fullkeyp contains the full part/id # for the extraction of proper parameters
 3774: # $tempkeyp contains part 0 only (no ids - ie, subparts)
 3775: # When storing information, store as part 0
 3776: # When requesting information, request from full part
 3777: #-------------------------------------------------------------------
 3778:                 foreach my $fullkeyp (&keysplit($keyp{$rid})) {
 3779:                     my $tempkeyp = $fullkeyp;
 3780:                     $tempkeyp =~ s/_\w+_/_0_/;
 3781:                     if ((grep $_ eq $fullkeyp, @catmarker) &&(!$name{$tempkeyp})) {
 3782:                         $part{$tempkeyp}="0";
 3783:                         $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name',$toolsymb);
 3784:                         my $parmdis=&Apache::lonnet::metadata($uri,$fullkeyp.'.display',$toolsymb);
 3785:                         if ($allparms{$name{$tempkeyp}} ne '') {
 3786:                             my $identifier;
 3787:                             if ($parmdis =~ /(\s*\[Part.*)$/) {
 3788:                                 $identifier = $1;
 3789:                             }
 3790:                             $display{$tempkeyp} = $allparms{$name{$tempkeyp}}.$identifier;
 3791:                         } else {
 3792:                             $display{$tempkeyp} = $parmdis;
 3793:                         }
 3794:                         unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
 3795:                         $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
 3796:                         $display{$tempkeyp} =~ s/_\w+_/_0_/;
 3797:                         $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp,$toolsymb);
 3798:                         $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type',$toolsymb);
 3799:                     }
 3800:                 } # end loop through keys
 3801:             } # end loop through ids
 3802: 
 3803: #---------------------------------------------------- print header information
 3804:             my $setdef=&mt("Set Defaults for All Resources in Course");
 3805:             $r->print(<<ENDMAPONE);
 3806: <center>
 3807: <h4>$setdef
 3808: <font color="red"><i>$coursename</i></font><br />
 3809: ENDMAPONE
 3810:             if ($uname) {
 3811:                 my $person=&Apache::loncommon::plainname($uname,$udom);
 3812:                 $r->print(" ".&mt("User")."<font color=\"red\"> <i>$uname \($person\) </i></font> \n");
 3813:             } else {
 3814:                 $r->print("<i><font color=\"red\"> ".&mt("ALL")."</i> ".&mt("USERS")."</font> \n");
 3815:             }
 3816: 
 3817:             if ($csec) {$r->print(&mt("Section")."<font color=\"red\"> <i>$csec</i></font>\n")};
 3818:             if ($cgroup) {$r->print(&mt("Group")."<font color=\"red\"> <i>$cgroup</i></font>\n")};
 3819:             $r->print("</h4>\n");
 3820: #---------------------------------------------------------------- print table
 3821:             $r->print('<p>'.&Apache::loncommon::start_data_table()
 3822:                      .&Apache::loncommon::start_data_table_header_row()
 3823:                      .'<th>'.&mt('Parameter Name').'</th>'
 3824:                      .'<th>'.&mt('Default Value').'</th>'
 3825:                      .'<th>'.&mt('Parameter in Effect').'</th>'
 3826:                      .&Apache::loncommon::end_data_table_header_row()
 3827:             );
 3828: 
 3829:             foreach my $item (&keysinorder(\%name,\%keyorder)) {
 3830:                 $r->print(&Apache::loncommon::start_data_table_row());
 3831:                 &print_row($r,$item,\%part,\%name,\%symbp,$mapid,\%default,
 3832:                            \%type,\%display,$defbgone,$defbgtwo,$defbgthree,
 3833:                            $parmlev,$uname,$udom,$csec,$cgroup,'',$noeditgrp,
 3834:                            $readonly);
 3835:             }
 3836:             $r->print(&Apache::loncommon::end_data_table()
 3837:                      .'</p>'
 3838:                      .'</center>'
 3839:             );
 3840:         } # end of $parmlev eq general
 3841:     }
 3842:     $r->print('</form>');
 3843:     if ($numreclinks) {
 3844:         $r->print(<<"END");
 3845: <form name="recurseform" action="/adm/parmset?action=settable" method="post">
 3846: <input type="hidden" name="pschp" />
 3847: <input type="hidden" name="pscat" />
 3848: <input type="hidden" name="psprt" />
 3849: <input type="hidden" name="hideparmsel" value="hidden" />
 3850: </form>
 3851: <script type="text/javascript">
 3852: function pjumprec(rid,name,part) {
 3853:     document.forms.recurseform.pschp.value = rid;
 3854:     document.forms.recurseform.pscat.value = name;
 3855:     document.forms.recurseform.psprt.value = part;
 3856:     document.forms.recurseform.submit();
 3857:     return false;
 3858: }
 3859: </script>
 3860: END
 3861:     }
 3862:     &endSettingsScreen($r);
 3863:     $r->print(&Apache::loncommon::end_page());
 3864: } # end sub assessparms
 3865: 
 3866: 
 3867: 
 3868: ##################################################
 3869: # OVERVIEW MODE
 3870: ##################################################
 3871: 
 3872: my $tableopen; # boolean, true if HTML table is already opened
 3873: 
 3874: # Returns HTML with the HTML table start tag and header, unless the table is already opened.
 3875: # @param {boolean} $readonly - true if values cannot be edited (otherwise more columns are added)
 3876: # @returns {string}
 3877: sub tablestart {
 3878:     my ($readonly,$is_map) = @_;
 3879:     if ($tableopen) {
 3880:         return '';
 3881:     } else {
 3882:         $tableopen=1;
 3883:         my $output = &Apache::loncommon::start_data_table().'<tr><th>'.&mt('Parameter').'</th>';
 3884:         if ($readonly) {
 3885:             $output .= '<th>'.&mt('Current value').'</th>';
 3886:         } else {
 3887:             $output .= '<th>'.&mt('Delete').'</th>'.
 3888:                        '<th>'.&mt('Set to ...').'</th>';
 3889:             if ($is_map) {
 3890:                 $output .= '<th>'.&mt('Recursive?').'</th>';
 3891:             }
 3892:         }
 3893:         $output .= '</tr>';
 3894:         return $output;
 3895:     }
 3896: }
 3897: 
 3898: # Returns HTML with the HTML table end tag, unless the table is not opened.
 3899: # @returns {string}
 3900: sub tableend {
 3901:     if ($tableopen) {
 3902:         $tableopen=0;
 3903:         return &Apache::loncommon::end_data_table();
 3904:     } else {
 3905:         return'';
 3906:     }
 3907: }
 3908: 
 3909: # Reads course and user information.
 3910: # 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).
 3911: # The key for student data is modified with '[useropt:'.username.':'.userdomain.'].'.
 3912: # If the context is looking for a list, returns a list with the scalar data and the class list.
 3913: # @param {string} $crs - course number
 3914: # @param {string} $dom - course domain
 3915: # @returns {hash reference|Array}
 3916: sub readdata {
 3917:     my ($crs,$dom)=@_;
 3918: # Read coursedata
 3919:     my $resourcedata=&Apache::lonnet::get_courseresdata($crs,$dom);
 3920: # Read userdata
 3921: 
 3922:     my $classlist=&Apache::loncoursedata::get_classlist();
 3923:     foreach my $user (keys(%$classlist)) {
 3924:         if ($user=~/^($match_username)\:($match_domain)$/) {
 3925:             my ($tuname,$tudom)=($1,$2);
 3926:             my $useropt=&Apache::lonnet::get_userresdata($tuname,$tudom);
 3927:             foreach my $userkey (keys(%{$useropt})) {
 3928:                 if ($userkey=~/^\Q$env{'request.course.id'}\E/) {
 3929:                     my $newkey=$userkey;
 3930:                     $newkey=~s/^($env{'request.course.id'}\.)/$1\[useropt\:$tuname\:$tudom\]\./;
 3931:                     $$resourcedata{$newkey}=$$useropt{$userkey};
 3932:                 }
 3933:             }
 3934:         }
 3935:     }
 3936:     if (wantarray) {
 3937:         return ($resourcedata,$classlist);
 3938:     } else {
 3939:         return $resourcedata;
 3940:     }
 3941: }
 3942: 
 3943: 
 3944: # Stores parameter data, using form parameters directly.
 3945: #
 3946: # Uses the following form parameters. The variable part in the names is a resourcedata key (except for a modification for user data).
 3947: # set_* (except settext, setipallow, setipdeny, setdeeplink) - set a parameter value
 3948: # del_* - remove a parameter
 3949: # datepointer_* - set a date parameter (value is key_* refering to a set of other form parameters)
 3950: # dateinterval_* - set a date interval parameter (value refers to more form parameters)
 3951: # key_* - date values
 3952: # days_* - for date intervals
 3953: # hours_* - for date intervals
 3954: # minutes_* - for date intervals
 3955: # seconds_* - for date intervals
 3956: # done_* - for date intervals
 3957: # typeof_* - parameter type
 3958: # 
 3959: # @param {Apache2::RequestRec} $r - the Apache request
 3960: # @param {string} $crs - course number
 3961: # @param {string} $dom - course domain
 3962: sub storedata {
 3963:     my ($r,$crs,$dom)=@_;
 3964: # Set userlevel immediately
 3965: # Do an intermediate store of course level
 3966:     my $olddata=&readdata($crs,$dom);
 3967:     my %newdata=();
 3968:     undef %newdata;
 3969:     my @deldata=();
 3970:     my @delrec=();
 3971:     my @delnonrec=();
 3972:     undef @deldata;
 3973:     my ($got_chostname,$chostname,$cmajor,$cminor);
 3974:     my $now = time;
 3975:     foreach my $key (keys(%env)) {
 3976:         if ($key =~ /^form\.([a-z]+)\_(.+)$/) {
 3977:             my $cmd=$1;
 3978:             my $thiskey=$2;
 3979:             my ($altkey,$recursive,$tkey,$tkeyrec,$tkeynonrec);
 3980:             next if ($cmd eq 'rec' || $cmd eq 'settext' || $cmd eq 'setipallow' || $cmd eq 'setipdeny' || $cmd eq 'setdeeplink');
 3981:             if ((($cmd eq 'set') || ($cmd eq 'datepointer') || ($cmd eq 'dateinterval') || ($cmd eq 'del')) && 
 3982:                  ($thiskey =~ /(?:sequence|page)\Q___(all)\E/)) {
 3983:                 unless ($thiskey =~ /(encrypturl|hiddenresource)$/) {
 3984:                     $altkey = $thiskey;
 3985:                     $altkey =~ s/\Q___(all)\E/___(rec)/;
 3986:                     if ($env{'form.rec_'.$thiskey}) {
 3987:                         $recursive = 1;
 3988:                     }
 3989:                 }
 3990:             }
 3991:             my ($tuname,$tudom)=&extractuser($thiskey);
 3992:             if ($tuname) {
 3993:                 $tkey=$thiskey;
 3994:                 $tkey=~s/\.\[useropt\:$tuname\:$tudom\]\./\./;
 3995:                 if ($altkey) {
 3996:                     $tkeynonrec = $tkey; 
 3997:                     $tkeyrec = $altkey;
 3998:                     $tkeyrec=~s/\.\[useropt\:$tuname\:$tudom\]\./\./;
 3999:                 }
 4000:             }
 4001:             if ($cmd eq 'set' || $cmd eq 'datepointer' || $cmd eq 'dateinterval') {
 4002:                 my ($data, $typeof, $text, $name, $valchk, $valmatch, $namematch);
 4003:                 if ($cmd eq 'set') {
 4004:                     $data=$env{$key};
 4005:                     $valmatch = '';
 4006:                     $valchk = $data;
 4007:                     $typeof=$env{'form.typeof_'.$thiskey};
 4008:                     $text = &mt('Saved modified parameter for');
 4009:                     if ($typeof eq 'string_questiontype') {
 4010:                         $name = 'type';
 4011:                     } elsif (($typeof eq 'string_lenient') || ($typeof eq 'string_deeplink')) {
 4012:                         ($name) = ($typeof =~ /^string_(lenient|deeplink)$/);
 4013:                         my $stringmatch = &standard_string_matches($typeof);
 4014:                         if (ref($stringmatch) eq 'ARRAY') {
 4015:                             foreach my $item (@{$stringmatch}) {
 4016:                                 if (ref($item) eq 'ARRAY') {
 4017:                                     my ($regexpname,$pattern) = @{$item};
 4018:                                     if ($pattern ne '') {
 4019:                                         if ($data =~ /$pattern/) {
 4020:                                             $valmatch = $regexpname;
 4021:                                             $valchk = '';
 4022:                                             last;
 4023:                                         }
 4024:                                     }
 4025:                                 }
 4026:                             }
 4027:                         }
 4028:                     } elsif ($typeof eq 'string_discussvote') {
 4029:                         $name = 'discussvote';
 4030:                     } elsif ($typeof eq 'string_examcode') {
 4031:                         $name = 'examcode';
 4032:                         if (&Apache::lonnet::validCODE($data)) {
 4033:                             $valchk = 'valid';
 4034:                         }
 4035:                     } elsif ($typeof eq 'string_yesno') {
 4036:                         if ($thiskey =~ /\.retrypartial$/) {
 4037:                             $name = 'retrypartial';
 4038:                         }
 4039:                     }
 4040:                 } elsif ($cmd eq 'datepointer') {
 4041:                     $data=&Apache::lonhtmlcommon::get_date_from_form($env{$key});
 4042:                     $typeof=$env{'form.typeof_'.$thiskey};
 4043:                     $text = &mt('Saved modified date for');
 4044:                     if ($typeof eq 'date_start') {
 4045:                         if ($thiskey =~ /\.printstartdate$/) {
 4046:                             $name = 'printstartdate';
 4047:                             if (($data) && ($data > $now)) {
 4048:                                 $valchk = 'future';
 4049:                             }
 4050:                         }
 4051:                     } elsif ($typeof eq 'date_end') {
 4052:                         if ($thiskey =~ /\.printenddate$/) {
 4053:                             $name = 'printenddate';
 4054:                             if (($data) && ($data < $now)) {
 4055:                                 $valchk = 'past';
 4056:                             }
 4057:                         }
 4058:                     }
 4059:                 } elsif ($cmd eq 'dateinterval') {
 4060:                     $data=&get_date_interval_from_form($thiskey);
 4061:                     if ($thiskey =~ /\.interval$/) {
 4062:                         $name = 'interval';
 4063:                         my $intervaltype = &get_intervaltype($name);
 4064:                         my $intervalmatch = &standard_interval_matches($intervaltype);
 4065:                         if (ref($intervalmatch) eq 'ARRAY') {
 4066:                             foreach my $item (@{$intervalmatch}) {
 4067:                                 if (ref($item) eq 'ARRAY') {
 4068:                                     my ($regexpname,$pattern) = @{$item};
 4069:                                     if ($pattern ne '') {
 4070:                                         if ($data =~ /$pattern/) {
 4071:                                             $valmatch = $regexpname;
 4072:                                             $valchk = '';
 4073:                                             last;
 4074:                                         }
 4075:                                     }
 4076:                                 }
 4077:                             }
 4078:                         }
 4079:                     }
 4080:                     $typeof=$env{'form.typeof_'.$thiskey};
 4081:                     $text = &mt('Saved modified date for');
 4082:                 }
 4083:                 if ($recursive) {
 4084:                     $namematch = 'maplevelrecurse';
 4085:                 }
 4086:                 if (($name ne '') || ($namematch ne '')) {
 4087:                     my ($needsrelease,$needsnewer);
 4088:                     if ($name ne '') {
 4089:                         $needsrelease = $Apache::lonnet::needsrelease{"parameter:$name:$valchk:$valmatch:"};
 4090:                         if ($needsrelease) {
 4091:                             unless ($got_chostname) {
 4092:                                 ($chostname,$cmajor,$cminor)=&parameter_release_vars();
 4093:                                 $got_chostname = 1;
 4094:                             }
 4095:                             $needsnewer = &parameter_releasecheck($name,$valchk,$valmatch,undef,
 4096:                                                                 $needsrelease,
 4097:                                                                 $cmajor,$cminor);
 4098:                         }
 4099:                     }
 4100:                     if ($namematch ne '') {
 4101:                         if ($needsnewer) {
 4102:                             undef($namematch);
 4103:                         } else {
 4104:                             my $currneeded;
 4105:                             if ($needsrelease) {
 4106:                                 $currneeded = $needsrelease;
 4107:                             }
 4108:                             $needsrelease =
 4109:                                 $Apache::lonnet::needsrelease{"parameter::::$namematch"};
 4110:                             if (($needsrelease) &&
 4111:                                     (($currneeded eq '') || ($needsrelease < $currneeded))) {
 4112:                                 unless ($got_chostname) {
 4113:                                     ($chostname,$cmajor,$cminor) = &parameter_release_vars();
 4114:                                     $got_chostname = 1;
 4115:                                 }
 4116:                                 $needsnewer = &parameter_releasecheck(undef,$valchk,$valmatch,
 4117:                                     $namematch, $needsrelease,$cmajor,$cminor);
 4118:                             } else {
 4119:                                 undef($namematch);
 4120:                             }
 4121:                         }
 4122:                     }
 4123:                     if ($needsnewer) {
 4124:                         $r->print('<br />'.&oldversion_warning($name,$namematch,$data,
 4125:                                                             $chostname,$cmajor,
 4126:                                                             $cminor,$needsrelease));
 4127:                         next;
 4128:                     }
 4129:                 }
 4130:                 my ($reconlychg,$haschange,$storekey);
 4131:                 if ($tuname) {
 4132:                     my $ustorekey;
 4133:                     if ($altkey) {
 4134:                         if ($recursive) {
 4135:                             if (exists($$olddata{$thiskey})) {
 4136:                                 if ($$olddata{$thiskey} eq $data) {
 4137:                                     $reconlychg = 1;
 4138:                                 }
 4139:                                 &Apache::lonnet::del('resourcedata',[$tkeynonrec,$tkeynonrec.'.type'],$tudom,$tuname);
 4140:                             }
 4141:                             if (exists($$olddata{$altkey})) {
 4142:                                 if (defined($data) && $$olddata{$altkey} ne $data) {
 4143:                                     $haschange = 1;
 4144:                                 }
 4145:                             } elsif ((!$reconlychg) && ($data ne '')) {
 4146:                                 $haschange = 1;
 4147:                             }
 4148:                             $ustorekey = $tkeyrec;
 4149:                         } else {
 4150:                             if (exists($$olddata{$altkey})) {
 4151:                                 if ($$olddata{$altkey} eq $data) {
 4152:                                     $reconlychg = 1;
 4153:                                 }
 4154:                                 &Apache::lonnet::del('resourcedata',[$tkeyrec,$tkeyrec.'.type'],$tudom,$tuname);
 4155:                             }
 4156:                             if (exists($$olddata{$thiskey})) {
 4157:                                 if (defined($data) && $$olddata{$thiskey} ne $data) {
 4158:                                     $haschange = 1;
 4159:                                 }
 4160:                             } elsif ((!$reconlychg) && ($data ne '')) {
 4161:                                 $haschange = 1;
 4162:                             }
 4163:                             $ustorekey = $tkeynonrec;
 4164:                         }
 4165:                     } else {
 4166:                         if (exists($$olddata{$tkey})) {
 4167:                             if (defined($data) && $$olddata{$tkey} ne $data) {
 4168:                                 $haschange = 1;
 4169:                             }
 4170:                             $ustorekey = $tkey;
 4171:                         }
 4172:                     }
 4173:                     if ($haschange || $reconlychg)  {
 4174:                         unless ($env{'form.del_'.$thiskey}) {
 4175:                             if (&Apache::lonnet::put('resourcedata',{$ustorekey=>$data,
 4176:                                                                      $ustorekey.'.type' => $typeof},
 4177:                                                                      $tudom,$tuname) eq 'ok') {
 4178:                                 &log_parmset({$ustorekey=>$data,$ustorekey.'.type' => $typeof},0,$tuname,$tudom);
 4179:                                 $r->print('<br />'.$text.' '.
 4180:                                           &Apache::loncommon::plainname($tuname,$tudom));
 4181:                             } else {
 4182:                                 $r->print('<div class="LC_error">'.
 4183:                                           &mt('Error saving parameters').'</div>');
 4184:                             }
 4185:                             &Apache::lonnet::devalidateuserresdata($tuname,$tudom);
 4186:                         }
 4187:                     }
 4188:                 } else {
 4189:                     if ($altkey) {
 4190:                         if ($recursive) {
 4191:                             if (exists($$olddata{$thiskey})) {
 4192:                                 if ($$olddata{$thiskey} eq $data) {
 4193:                                     $reconlychg = 1;
 4194:                                 }
 4195:                                 push(@delnonrec,($thiskey,$thiskey.'.type'));
 4196:                             }
 4197:                             if (exists($$olddata{$altkey})) {
 4198:                                 if (defined($data) && $$olddata{$altkey} ne $data) {
 4199:                                     $haschange = 1;
 4200:                                 }
 4201:                             } elsif (($data ne '') && (!$reconlychg)) {
 4202:                                 $haschange = 1;
 4203:                             }
 4204:                             $storekey = $altkey;
 4205:                         } else {
 4206:                             if (exists($$olddata{$altkey})) {
 4207:                                 if ($$olddata{$altkey} eq $data) {
 4208:                                     $reconlychg = 1;
 4209:                                 }
 4210:                                 push(@delrec,($altkey,$altkey.'.type'));
 4211:                             } 
 4212:                             if (exists($$olddata{$thiskey})) {
 4213:                                 if (defined($data) && $$olddata{$thiskey} ne $data) {
 4214:                                     $haschange = 1;
 4215:                                 }
 4216:                             } elsif (($data ne '') && (!$reconlychg)) {
 4217:                                 $haschange = 1;
 4218:                             }
 4219:                             $storekey = $thiskey;
 4220:                         }
 4221:                     } else {
 4222:                         if (defined($data) && $$olddata{$thiskey} ne $data) {
 4223:                             $haschange = 1;
 4224:                             $storekey = $thiskey;
 4225:                         }
 4226:                     }
 4227:                 }
 4228:                 if ($reconlychg || $haschange) {
 4229:                     unless ($env{'form.del_'.$thiskey}) {
 4230:                         $newdata{$storekey}=$data;
 4231:                         $newdata{$storekey.'.type'}=$typeof;
 4232:                     }
 4233:                 }
 4234:             } elsif ($cmd eq 'del') {
 4235:                 if ($tuname) {
 4236:                     my $error;
 4237:                     if ($altkey) {  
 4238:                         if (exists($$olddata{$altkey})) {
 4239:                             if (&Apache::lonnet::del('resourcedata',[$tkeyrec,$tkeyrec.'.type'],$tudom,$tuname) eq 'ok') {
 4240:                                 &log_parmset({$tkeyrec=>''},1,$tuname,$tudom);
 4241:                                 if ($recursive) {
 4242:                                     $r->print('<br />'.&mt('Deleted parameter for').' '.&Apache::loncommon::plainname($tuname,$tudom));
 4243:                                 }
 4244:                             } elsif ($recursive) {
 4245:                                 $error = 1;
 4246:                             }
 4247:                         }
 4248:                         if (exists($$olddata{$thiskey})) {
 4249:                             if (&Apache::lonnet::del('resourcedata',[$tkeynonrec,$tkeynonrec.'.type'],$tudom,$tuname) eq 'ok') {
 4250:                                 &log_parmset({$tkeynonrec=>''},1,$tuname,$tudom);
 4251:                                 unless ($recursive) {
 4252:                                     $r->print('<br />'.&mt('Deleted parameter for').' '.&Apache::loncommon::plainname($tuname,$tudom));
 4253:                                 }
 4254:                             } elsif (!$recursive) {
 4255:                                 $error = 1;
 4256:                             }
 4257:                         }
 4258:                     } else {
 4259:                         if (exists($$olddata{$thiskey})) {
 4260:                             if (&Apache::lonnet::del('resourcedata',[$tkey,$tkey.'.type'],$tudom,$tuname) eq 'ok') {
 4261:                                 &log_parmset({$tkey=>''},1,$tuname,$tudom);
 4262:                                 $r->print('<br />'.&mt('Deleted parameter for').' '.&Apache::loncommon::plainname($tuname,$tudom));
 4263:                             } else {
 4264:                                 $error = 1;
 4265:                             }
 4266:                         }
 4267:                     }
 4268:                     if ($error) { 
 4269:                         $r->print('<div class="LC_error">'.
 4270:                             &mt('Error deleting parameters').'</div>');
 4271:                     }
 4272:                     &Apache::lonnet::devalidateuserresdata($tuname,$tudom);
 4273:                 } else {
 4274:                     if ($altkey) {
 4275:                         if (exists($$olddata{$altkey})) {
 4276:                             unless (grep(/^\Q$altkey\E$/,@delrec)) {
 4277:                                 push(@deldata,($altkey,$altkey.'.type'));
 4278:                             }
 4279:                         }
 4280:                         if (exists($$olddata{$thiskey})) {
 4281:                             unless (grep(/^\Q$thiskey\E$/,@delnonrec)) {
 4282:                                 push(@deldata,($thiskey,$thiskey.'.type'));
 4283:                             }
 4284:                         }
 4285:                     } elsif (exists($$olddata{$thiskey})) {
 4286:                         push(@deldata,($thiskey,$thiskey.'.type'));
 4287:                     }
 4288:                 }
 4289:             }
 4290:         }
 4291:     }
 4292: # Store all course level
 4293:     my $delentries=$#deldata+1;
 4294:     my @alldels;
 4295:     if (@delrec) {
 4296:         push(@alldels,@delrec);
 4297:     }
 4298:     if (@delnonrec) {
 4299:         push(@alldels,@delnonrec);
 4300:     }
 4301:     if (@deldata) {
 4302:         push(@alldels,@deldata);
 4303:     }
 4304:     my @newdatakeys=keys(%newdata);
 4305:     my $putentries=$#newdatakeys+1;
 4306:     my ($delresult,$devalidate);
 4307:     if (@alldels) {
 4308:         if (&Apache::lonnet::del('resourcedata',\@alldels,$dom,$crs) eq 'ok') {
 4309:             my %loghash=map { $_ => '' } @alldels;
 4310:             &log_parmset(\%loghash,1);
 4311:             if ($delentries) {
 4312:                 $r->print('<h2>'.&mt('Deleted [quant,_1,parameter]',$delentries/2).'</h2>');
 4313:             }
 4314:         } elsif ($delentries) {
 4315:             $r->print('<div class="LC_error">'.
 4316:                 &mt('Error deleting parameters').'</div>');
 4317:         }
 4318:         $devalidate = 1; 
 4319:     }
 4320:     if ($putentries) {
 4321:         if (&Apache::lonnet::put('resourcedata',\%newdata,$dom,$crs) eq 'ok') {
 4322:                     &log_parmset(\%newdata,0);
 4323:             $r->print('<h3>'.&mt('Saved [quant,_1,parameter]',$putentries/2).'</h3>');
 4324:         } else {
 4325:             $r->print('<div class="LC_error">'.
 4326:                 &mt('Error saving parameters').'</div>');
 4327:         }
 4328:         $devalidate = 1; 
 4329:     }
 4330:     if ($devalidate) {
 4331:         &Apache::lonnet::devalidatecourseresdata($crs,$dom);
 4332:     }
 4333: }
 4334: 
 4335: # Returns the username and domain from a key created in readdata from a resourcedata key.
 4336: #
 4337: # @param {string} $key - the key
 4338: # @returns {Array}
 4339: sub extractuser {
 4340:     my $key=shift;
 4341:     return ($key=~/^$env{'request.course.id'}.\[useropt\:($match_username)\:($match_domain)\]\./);
 4342: }
 4343: 
 4344: # Parses a parameter key and returns the components.
 4345: #
 4346: # @param {string} $key - 
 4347: # @param {hash reference} $listdata - 
 4348: # @return {Array} - (student, resource, part, parameter)
 4349: sub parse_listdata_key {
 4350:     my ($key,$listdata) = @_;
 4351:     # split into student/section affected, and
 4352:     # the realm (folder/resource part and parameter
 4353:     my ($student,$realm) =
 4354:     ($key=~/^\Q$env{'request.course.id'}\E\.\[([^\.]+)\]\.(.+)$/);
 4355:     # if course wide student would be undefined
 4356:     if (!defined($student)) {
 4357:         ($realm)=($key=~/^\Q$env{'request.course.id'}\E\.(.+)$/);
 4358:     }
 4359:     # strip off the .type if it's not the Question type parameter
 4360:     if ($realm=~/\.type$/ && !exists($listdata->{$key.'.type'})) {
 4361:         $realm=~s/\.type//;
 4362:     }
 4363:     # split into resource+part and parameter name
 4364:     my ($res,    $parm) = ($realm=~/^(.*)\.(.*)$/);
 4365:        ($res, my $part) = ($res  =~/^(.*)\.(.*)$/);
 4366:     return ($student,$res,$part,$parm);
 4367: }
 4368: 
 4369: # Prints HTML with forms for the given parameter data in overview mode (newoverview or overview).
 4370: #
 4371: # @param {Apache2::RequestRec} $r - the Apache request
 4372: # @param {hash reference} $resourcedata - parameter data returned by readdata
 4373: # @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
 4374: # @param {string} $sortorder - realmstudent|studentrealm
 4375: # @param {string} $caller - name of the calling sub (overview|newoverview)
 4376: # @param {hash reference} $classlist - from loncoursedata::get_classlist
 4377: # @param {boolean} $readonly - true if editing not allowed
 4378: # @returns{integer} - number of $listdata parameters processed
 4379: sub listdata {
 4380:     my ($r,$resourcedata,$listdata,$sortorder,$caller,$classlist,$readonly)=@_;
 4381:     
 4382: # Start list output
 4383: 
 4384:     my $oldsection='';
 4385:     my $oldrealm='';
 4386:     my $oldpart='';
 4387:     my $pointer=0;
 4388:     $tableopen=0;
 4389:     my $foundkeys=0;
 4390:     my %keyorder=&standardkeyorder();
 4391: 
 4392:     my ($secidx,%grouphash);
 4393:     if (($env{'request.course.sec'} ne '') && ($caller eq 'overview')) {
 4394:         $secidx = &Apache::loncoursedata::CL_SECTION();
 4395:         if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
 4396:             %grouphash = &Apache::longroup::coursegroups();
 4397:         } elsif ($env{'request.course.groups'} ne '') {
 4398:             map { $grouphash{$_} = 1; } split(/:/,$env{'request.course.groups'});
 4399:         }
 4400:     }
 4401: 
 4402:     foreach my $key (sort {
 4403:         my ($astudent,$ares,$apart,$aparm) = &parse_listdata_key($a,$listdata);
 4404:         my ($bstudent,$bres,$bpart,$bparm) = &parse_listdata_key($b,$listdata);
 4405: 
 4406:         # get the numerical order for the param
 4407:         $aparm=$keyorder{'parameter_0_'.$aparm};
 4408:         $bparm=$keyorder{'parameter_0_'.$bparm};
 4409: 
 4410:         my $result=0;
 4411: 
 4412:         if ($sortorder eq 'realmstudent') {
 4413:             if ($ares     ne $bres    ) {
 4414:                 $result = ($ares     cmp $bres);
 4415:             } elsif ($astudent ne $bstudent) {
 4416:                 $result = ($astudent cmp $bstudent);
 4417:             } elsif ($apart    ne $bpart   ) {
 4418:                 $result = ($apart    cmp $bpart);
 4419:             }
 4420:         } else {
 4421:             if      ($astudent ne $bstudent) {
 4422:                 $result = ($astudent cmp $bstudent);
 4423:             } elsif ($ares     ne $bres    ) {
 4424:                 $result = ($ares     cmp $bres);
 4425:             } elsif ($apart    ne $bpart   ) {
 4426:                 $result = ($apart    cmp $bpart);
 4427:             }
 4428:         }
 4429: 
 4430:         if (!$result) {
 4431:             if (defined($aparm) && defined($bparm)) {
 4432:                 $result = ($aparm <=> $bparm);
 4433:             } elsif (defined($aparm)) {
 4434:                 $result = -1;
 4435:             } elsif (defined($bparm)) {
 4436:                 $result = 1;
 4437:             }
 4438:         }
 4439: 
 4440:         $result;
 4441:         
 4442:     } keys(%{$listdata})) { # foreach my $key
 4443:         my $thiskey = $key;
 4444:         if ($$listdata{$thiskey.'.type'}) {
 4445:             my $thistype=$$listdata{$thiskey.'.type'};
 4446:             if ($$resourcedata{$thiskey.'.type'}) {
 4447:                 $thistype=$$resourcedata{$thiskey.'.type'};
 4448:             }
 4449:             my ($middle,$part,$name)=
 4450:                 ($thiskey=~/^$env{'request.course.id'}\.(?:(.+)\.)*([\w\s\-]+)\.(\w+)$/);
 4451:             my $section=&mt('All Students');
 4452:             my $showval = $$resourcedata{$thiskey}; 
 4453:             if ($middle=~/^\[(.*)\]/) {
 4454:                 my $issection=$1;
 4455:                 if ($issection=~/^useropt\:($match_username)\:($match_domain)/) {
 4456:                     my ($stuname,$studom) = ($1,$2);
 4457:                     if (($env{'request.course.sec'} ne '') && ($caller eq 'overview')) {
 4458:                         if (ref($classlist) eq 'HASH') {
 4459:                             if (ref($classlist->{$stuname.':'.$studom}) eq 'ARRAY') {
 4460:                                 next unless ($classlist->{$stuname.':'.$studom}->[$secidx] eq $env{'request.course.sec'}); 
 4461:                             }
 4462:                         }
 4463:                     }
 4464:                     $section=&mt('User').": ".&Apache::loncommon::plainname($stuname,$studom);
 4465:                 } else {
 4466:                     if (($env{'request.course.sec'} ne '') && ($caller eq 'overview')) {
 4467:                         if (exists($grouphash{$issection})) {
 4468:                             $section=&mt('Group').': '.$issection;
 4469:                         } elsif ($issection eq $env{'request.course.sec'}) {
 4470:                             $section = &mt('Section').': '.$issection;
 4471:                         } else {
 4472:                             next; 
 4473:                         }
 4474:                     } else {
 4475:                         $section=&mt('Group/Section').': '.$issection;
 4476:                     }
 4477:                 }
 4478:                 $middle=~s/^\[(.*)\]//;
 4479:             } elsif (($env{'request.course.sec'} ne '') && ($caller eq 'overview')) {
 4480:                 $readonly = 1;
 4481:             }
 4482:             $middle=~s/\.+$//;
 4483:             $middle=~s/^\.+//;
 4484:             my $realm='<span class="LC_parm_scope_all">'.&mt('All Resources').'</span>';
 4485:             my ($is_map,$is_recursive,$mapurl,$maplevel);
 4486:             if ($caller eq 'overview') {
 4487:                 if ($middle=~/^(.+)\_\_\_\((all|rec)\)$/) {
 4488:                     $mapurl = $1;
 4489:                     $maplevel = $2;
 4490:                     $is_map = 1;
 4491:                 }
 4492:             } elsif ($caller eq 'newoverview') {
 4493:                 if ($middle=~/^(.+)\_\_\_\((all)\)$/) {
 4494:                     $mapurl = $1;
 4495:                     $maplevel = $2;
 4496:                     $is_map = 1;
 4497:                 }
 4498:             }
 4499:             if ($is_map) {
 4500:                 my $leveltitle = &mt('Folder/Map');
 4501:                 unless (($name eq 'hiddenresource') || ($name eq 'encrypturl')) {   
 4502:                     if ($caller eq 'newoverview') {
 4503:                         my $altkey = $thiskey;
 4504:                         $altkey =~ s/\Q___(all)\E/___(rec)/;
 4505:                         if ((exists($$resourcedata{$altkey})) & (!exists($$resourcedata{$thiskey}))) {
 4506:                             $is_recursive = 1;
 4507:                             if ($$resourcedata{$altkey.'.type'}) {
 4508:                                 $thistype=$$resourcedata{$altkey.'.type'};
 4509:                             }
 4510:                             $showval = $$resourcedata{$altkey};
 4511:                         }
 4512:                     } elsif (($caller eq 'overview') && ($maplevel eq 'rec')) {
 4513:                         $thiskey =~ s/\Q___(rec)\E/___(all)/;
 4514:                         $is_recursive = 1;
 4515:                     }
 4516:                 }
 4517:                 $realm='<span class="LC_parm_scope_folder">'.$leveltitle.': '.&Apache::lonnet::gettitle($mapurl).' <br /><span class="LC_parm_folder">('.$mapurl.')</span></span>';
 4518:             } elsif ($middle) {
 4519:                 my ($map,$id,$url)=&Apache::lonnet::decode_symb($middle);
 4520:                 $realm='<span class="LC_parm_scope_resource">'.&mt('Resource').
 4521:                     ': '.&Apache::lonnet::gettitle($middle).
 4522:                     ' <br /><span class="LC_parm_symb">('.$url.' in '.$map.' id: '.
 4523:                     $id.')</span></span>';
 4524:             }
 4525:             if ($sortorder eq 'realmstudent') {
 4526:                 if ($realm ne $oldrealm) {
 4527:                     $r->print(&tableend()."\n<hr /><h1>$realm</h1>");
 4528:                     $oldrealm=$realm;
 4529:                     $oldsection='';
 4530:                 }
 4531:                 if ($section ne $oldsection) {
 4532:                     $r->print(&tableend()."\n<h2>$section</h2>");
 4533:                     $oldsection=$section;
 4534:                     $oldpart='';
 4535:                 }
 4536:             } else {
 4537:                 if ($section ne $oldsection) {
 4538:                     $r->print(&tableend()."\n<hr /><h1>$section</h1>");
 4539:                     $oldsection=$section;
 4540:                     $oldrealm='';
 4541:                 }
 4542:                 if ($realm ne $oldrealm) {
 4543:                     $r->print(&tableend()."\n<h2>$realm</h2>");
 4544:                     $oldrealm=$realm;
 4545:                     $oldpart='';
 4546:                 }
 4547:             }
 4548:             if ($part ne $oldpart) {
 4549:                 $r->print(&tableend().
 4550:                     "\n".'<span class="LC_parm_part">'.&mt('Part').": $part</span>");
 4551:                 $oldpart=$part;
 4552:             }
 4553:     #
 4554:     # Ready to print
 4555:     #
 4556:             my $parmitem = &standard_parameter_names($name);
 4557:             $r->print(&tablestart($readonly,$is_map).
 4558:                 &Apache::loncommon::start_data_table_row().
 4559:                 '<td><b>'.&mt($parmitem).
 4560:                 '</b></td>');
 4561:             unless ($readonly) {
 4562:                 $r->print('<td><input type="checkbox" name="del_'.
 4563:                         $thiskey.'" /></td>');
 4564:             }
 4565:             $r->print('<td>');
 4566:             $foundkeys++;
 4567:             if (&isdateparm($thistype)) {
 4568:                 my $jskey='key_'.$pointer;
 4569:                 my $state;
 4570:                 $pointer++;
 4571:                 if ($readonly) {
 4572:                     $state = 'disabled';
 4573:                 }
 4574:                 $r->print(
 4575:                     &Apache::lonhtmlcommon::date_setter('parmform',
 4576:                                                         $jskey,
 4577:                                                         $showval,
 4578:                                                         '',1,$state));
 4579:                 unless  ($readonly) {
 4580:                     $r->print(
 4581:     '<input type="hidden" name="datepointer_'.$thiskey.'" value="'.$jskey.'" />'.
 4582:     (($showval!=0)?'<span class="LC_nobreak"><a href="/adm/parmset?&action=dateshift1&timebase='.$showval.'">'.
 4583:     &mt('Shift all dates based on this date').'</a></span>':'').
 4584:     &date_sanity_info($showval)
 4585:                     );
 4586:                 }
 4587:             } elsif ($thistype eq 'date_interval') {
 4588:                 $r->print(&date_interval_selector($thiskey,$name,
 4589:                           $showval,$readonly));
 4590:             } elsif ($thistype =~ m/^string/) {
 4591:                 $r->print(&string_selector($thistype,$thiskey,
 4592:                           $showval,$name,$readonly));
 4593:             } else {
 4594:                 $r->print(&default_selector($thiskey,$showval,$readonly));
 4595:             }
 4596:             unless ($readonly) {
 4597:                 $r->print('<input type="hidden" name="typeof_'.$thiskey.'" value="'.
 4598:                         $thistype.'" />');
 4599:             }
 4600:             $r->print('</td>');
 4601:             if ($is_map) {
 4602:                 if (($name eq 'encrypturl') || ($name eq 'hiddenresource')) {
 4603:                     $r->print('<td><table><tr><td>'.&mt('Yes').'</td></tr></table></td>');
 4604:                 } else {
 4605:                     my ($disabled,$recon,$recoff);
 4606:                     if ($readonly) {
 4607:                         $disabled = ' disabled="disabled"';
 4608:                     }
 4609:                     if ($is_recursive) {
 4610:                         $recon = ' checked="checked"';
 4611:                     } else {
 4612:                         $recoff = ' checked="checked"';
 4613:                     }
 4614:                     $r->print('<td><table><tr><td><label><input type="radio" name="rec_'.$thiskey.'" value="1"'.$recon.$disabled.' />'.&mt('Yes').'</label>'.
 4615:                               '</td><td><label><input type="radio" name="rec_'.$thiskey.'" value="0"'.$recoff.$disabled.' />'.&mt('No').'</label></td></tr></table></td>');
 4616:                 }
 4617:             }
 4618:             $r->print(&Apache::loncommon::end_data_table_row());
 4619:         }
 4620:     }
 4621:     return $foundkeys;
 4622: }
 4623: 
 4624: # Returns a string representing the interval, directly using form data matching the given key.
 4625: # The returned string may also include information related to proctored exams.
 4626: # Format: seconds['_done'[':'done button title':']['_proctor'['_'proctor key]]]
 4627: #
 4628: # @param {string} $key - suffix for form fields related to the interval
 4629: # @returns {string}
 4630: sub get_date_interval_from_form {
 4631:     my ($key) = @_;
 4632:     my $seconds = 0;
 4633:     foreach my $which (['days', 86400],
 4634:                ['hours', 3600],
 4635:                ['minutes', 60],
 4636:                ['seconds',  1]) {
 4637:         my ($name, $factor) = @{ $which };
 4638:         if (defined($env{'form.'.$name.'_'.$key})) {
 4639:             $seconds += $env{'form.'.$name.'_'.$key} * $factor;
 4640:         }
 4641:     }
 4642:     if (($key =~ /\.interval$/) &&
 4643:             (($env{'form.done_'.$key} eq '_done') || ($env{'form.done_'.$key} eq '_done_proctor'))) {
 4644:         if ($env{'form.done_'.$key.'_buttontext'}) {
 4645:             $env{'form.done_'.$key.'_buttontext'} =~ s/\://g;
 4646:             $seconds .= '_done:'.$env{'form.done_'.$key.'_buttontext'}.':';
 4647:             if ($env{'form.done_'.$key} eq '_done_proctor') {
 4648:                 $seconds .= '_proctor';
 4649:             }
 4650:         } else {
 4651:             $seconds .= $env{'form.done_'.$key}; 
 4652:         }
 4653:         if (($env{'form.done_'.$key} eq '_done_proctor') && 
 4654:                 ($env{'form.done_'.$key.'_proctorkey'})) {
 4655:             $seconds .= '_'.$env{'form.done_'.$key.'_proctorkey'};
 4656:         }
 4657:     }
 4658:     return $seconds;
 4659: }
 4660: 
 4661: 
 4662: # Returns HTML to enter a text value for a parameter.
 4663: #
 4664: # @param {string} $thiskey - parameter key
 4665: # @param {string} $showval - the current value
 4666: # @param {boolean} $readonly - true if the field should not be made editable
 4667: # @returns {string}
 4668: sub default_selector {
 4669:     my ($thiskey, $showval, $readonly) = @_;
 4670:     my $disabled;
 4671:     if ($readonly) {
 4672:         $disabled = ' disabled="disabled"';
 4673:     }
 4674:     return '<input type="text" name="set_'.$thiskey.'" value="'.$showval.'"'.$disabled.' />';
 4675: }
 4676: 
 4677: # Returns HTML to enter allow/deny rules related to IP addresses.
 4678: #
 4679: # @param {string} $thiskey - parameter key
 4680: # @param {string} $showval - the current value
 4681: # @param {boolean} $readonly - true if the fields should not be made editable
 4682: # @returns {string}
 4683: sub string_ip_selector {
 4684:     my ($thiskey, $showval, $readonly) = @_;
 4685:     my %access = (
 4686:                    allow => [],
 4687:                    deny  => [],
 4688:                  );
 4689:     if ($showval ne '') {
 4690:         my @current;
 4691:         if ($showval =~ /,/) {
 4692:             @current = split(/,/,$showval);
 4693:         } else {
 4694:             @current = ($showval);
 4695:         }
 4696:         foreach my $item (@current) {
 4697:             if ($item =~ /^\!([\[\]a-zA-Z\.\d\*\-]+)$/) {
 4698:                 push(@{$access{'deny'}},$1);
 4699:             } elsif ($item =~ /^([\[\]a-zA-Z\.\d\*\-]+)$/) {
 4700:                 push(@{$access{'allow'}},$item);
 4701:             }
 4702:         }
 4703:     }
 4704:     if (!@{$access{'allow'}}) {
 4705:         @{$access{'allow'}} = ('');
 4706:     }
 4707:     if (!@{$access{'deny'}}) {
 4708:         @{$access{'deny'}} = ('');
 4709:     }
 4710:     my ($disabled,$addmore);
 4711:     if ($readonly) {
 4712:         $disabled=' disabled="disabled"';
 4713:     } else {
 4714:         $addmore = "\n".'<button class="LC_add_ipacc_button">'.&mt('Add more').'</button>';
 4715:     }
 4716:     my $output = '<input type="hidden" name="set_'.$thiskey.'" />
 4717: <table><tr><th>'.&mt('Allow from').'</th><th>'.&mt('Deny from').'</th></tr><tr>';
 4718:     foreach my $acctype ('allow','deny') {
 4719:         $output .= '
 4720: <td valign="top">
 4721: <div class="LC_string_ipacc_wrap" id="LC_string_ipacc_'.$acctype.'_'.$thiskey.'">
 4722:   <div class="LC_string_ipacc_inner">'."\n";
 4723:         my $num = 0;
 4724:         foreach my $curr (@{$access{$acctype}}) {
 4725:             $output .= '<div><input type="text" name="setip'.$acctype.'_'.$thiskey.'" value="'.$curr.'"'.$disabled.' />';
 4726:             if ($num > 0) {
 4727:                 $output .= '<a href="#" class="LC_remove_ipacc">'.&mt('Remove').'</a>'; 
 4728:             }
 4729:             $output .= '</div>'."\n";
 4730:             $num ++;
 4731:         }
 4732:         $output .= '
 4733:   </div>'.$addmore.'
 4734: </div>
 4735: </td>';
 4736:    }
 4737:    $output .= '
 4738: </tr>
 4739: </table>'."\n";
 4740:     return $output;
 4741: }
 4742: 
 4743: sub string_deeplink_selector {
 4744:     my ($thiskey, $showval, $readonly) = @_;
 4745:     my (@components,%values,@current,%titles,%options,%optiontext,%defaults,%posslti);
 4746:     @components = ('listing','scope','urls');
 4747:     %titles = &Apache::lonlocal::texthash (
 4748:                   listing => 'In Contents and/or Gradebook',
 4749:                   scope   => 'Access scope for link',
 4750:                   urls    => 'Supported link types',
 4751:               );
 4752:     %options = (
 4753:                    listing => ['full','absent','grades','details','datestatus'],
 4754:                    scope   => ['res','map','rec'],
 4755:                    urls    => ['any','only','key','lti'],
 4756:                );
 4757:     %optiontext = &Apache::lonlocal::texthash (
 4758:                     full       => 'Listed (linked) in both',
 4759:                     absent     => 'Not listed',
 4760:                     grades     => 'Listed in grades only',
 4761:                     details    => 'Listed (unlinked) in both',
 4762:                     datestatus => 'Listed (unlinked) inc. status in both',
 4763:                     res        => 'resource only',
 4764:                     map        => 'enclosing map/folder',
 4765:                     rec        => 'recursive map/folder',
 4766:                     any        => 'regular + deep',
 4767:                     only       => 'deep only',
 4768:                     key        => 'deep with key',
 4769:                     lti        => 'deep with LTI launch',
 4770:                   );
 4771:     if ($showval =~ /,/) {
 4772:         @current = split(/,/,$showval);
 4773:         ($values{'listing'}) = ($current[0] =~ /^(full|absent|grades|details|datestatus)$/);
 4774:         ($values{'scope'}) = ($current[1] =~ /^(res|map|rec)$/);
 4775:         ($values{'urls'}) = ($current[2] =~ /^(any|only|key:\w+|lti:\d+)$/);
 4776:     } else {
 4777:         $defaults{'listing'} = 'full';
 4778:         $defaults{'scope'} = 'res';
 4779:         $defaults{'urls'} = 'any';
 4780:     }
 4781:     my $disabled;
 4782:     if ($readonly) {
 4783:         $disabled=' disabled="disabled"';
 4784:     }
 4785:     my %lti = 
 4786:         &Apache::lonnet::get_domain_lti($env{'course.'.$env{'request.course.id'}.'.domain'},
 4787:                                         'provider');
 4788:     foreach my $item (keys(%lti)) {
 4789:         if (ref($lti{$item}) eq 'HASH') {
 4790:             unless ($lti{$item}{'requser'}) {
 4791:                 $posslti{$item} = $lti{$item}{'consumer'};
 4792:             }
 4793:         }
 4794:     }
 4795:     my $output = '<input type="hidden" name="set_'.$thiskey.'" /><table><tr>';
 4796:     foreach my $item ('listing','scope','urls') {
 4797:         $output .= '<th>'.$titles{$item}.'</th>';
 4798:     }
 4799:     $output .= '</tr><tr>';
 4800:     foreach my $item (@components) {
 4801:         $output .= '<td>';
 4802:         if ($item eq 'urls') {
 4803:             my $selected = $values{$item};
 4804:             foreach my $option (@{$options{$item}}) {
 4805:                 if ($option eq 'lti') {
 4806:                     next unless (keys(%posslti));
 4807:                 }
 4808:                 my $checked;
 4809:                 if ($selected =~ /^\Q$option\E/) {
 4810:                     $checked = ' checked="checked"';
 4811:                 }
 4812:                 my $onclick;
 4813:                 unless ($readonly) {
 4814:                     my $esc_key = &js_escape($thiskey);
 4815:                     $onclick = ' onclick="toggleDeepLink(this.form,'."'$item','$esc_key'".');"';
 4816:                 }
 4817:                 $output .= '<span class="LC_nobreak"><label>'.
 4818:                            '<input type="radio" name="deeplink_'.$item.'_'.$thiskey.'" value="'.$option.'"'.$onclick.$disabled.$checked.' />'."\n".
 4819:                            $optiontext{$option}.'</label>';
 4820:                 if ($option eq 'key') {
 4821:                     my $visibility="hidden";
 4822:                     my $currkey;
 4823:                     if ($checked) {
 4824:                         $visibility = "text";
 4825:                         $currkey = (split(/\:/,$values{$item}))[1];
 4826:                     }
 4827:                     $output .= '&nbsp;'.
 4828:                         '<input type="'.$visibility.'" name="deeplink_'.$option.'_'.$thiskey.'" id="deeplink_'.$option.'_'.$item.'_'.$thiskey.'" value="'.$currkey.'" size="6"'.$disabled.' />';
 4829:                 } elsif ($option eq 'lti') {
 4830:                     my $display="none";
 4831:                     my ($currlti,$blankcheck);
 4832:                     if ($checked) {
 4833:                         $display = 'inline-block';
 4834:                         $currlti = (split(/\:/,$values{$item}))[1];
 4835:                     } else {
 4836:                         $blankcheck = ' selected="selected"';
 4837:                     }
 4838:                     $output .= '<div id="deeplinkdiv_'.$option.'_'.$item.'_'.$thiskey.'"'.
 4839:                                ' style="display: '.$display.'">&nbsp;<select name="'.
 4840:                                'deeplink_'.$option.'_'.$thiskey.'"'.$disabled.'>'.
 4841:                                '<option value=""'.$blankcheck.'>'.&mt('Select Provider').'</option>'."\n";
 4842:                     foreach my $lti (sort { $a <=> $b } keys(%posslti)) {
 4843:                         my $selected;
 4844:                         if ($lti == $currlti) {
 4845:                             $selected = ' selected="selected"';
 4846:                         }
 4847:                         $output .= '<option value="'.$lti.'"'.$selected.'>'.$posslti{$lti}.'</option>';
 4848:                     }
 4849:                     $output .= '</select></div>';
 4850:                 }
 4851:                 $output .= '</span> ';
 4852:             }
 4853:         } else {
 4854:             my $selected = $values{$item};
 4855:             my $defsel;
 4856:             if ($selected eq '') {
 4857:                 $defsel = ' selected="selected"';
 4858:             }
 4859:             $output .= '<select name="deeplink_'.$item.'_'.$thiskey.'"'.$disabled.'>'."\n".
 4860:                        '<option value=""'.$defsel.'>'.&mt('Please select').'</option>'."\n";
 4861:             foreach my $option (@{$options{$item}}) {
 4862:                 $output .= '<option value="'.$option.'"';
 4863:                 if ($option eq $selected) {
 4864:                     $output .= ' selected="selected"';
 4865:                 }
 4866:                 $output .= '>'.$optiontext{$option}.'</option>';
 4867:             }
 4868:             $output .= '</select>';
 4869:         }
 4870:         $output .= '</td>';
 4871:     }
 4872:     $output .= '</tr></table>'."\n";
 4873:     return $output;
 4874: }
 4875: 
 4876: 
 4877: { # block using some constants related to parameter types (overview mode)
 4878: 
 4879: my %strings =
 4880:     (
 4881:      'string_yesno'
 4882:              => [[ 'yes', 'Yes' ],
 4883:                  [ 'no', 'No' ]],
 4884:      'string_problemstatus'
 4885:              => [[ 'yes', 'Yes' ],
 4886:          [ 'answer', 'Yes, and show correct answer if they exceed the maximum number of tries.' ],
 4887:          [ 'no', 'No, don\'t show correct/incorrect feedback.' ],
 4888:          [ 'no_feedback_ever', 'No, show no feedback at all.' ]],
 4889:      'string_questiontype'
 4890:              => [[ 'problem', 'Standard Problem'],
 4891:                  [ 'survey', 'Survey'],
 4892:                  [ 'anonsurveycred', 'Anonymous Survey (credit for submission)'],
 4893:                  [ 'exam', 'Bubblesheet Exam'],
 4894:                  [ 'anonsurvey', 'Anonymous Survey'],
 4895:                  [ 'randomizetry', 'New Randomization Each N Tries (default N=1)'],
 4896:                  [ 'practice', 'Practice'],
 4897:                  [ 'surveycred', 'Survey (credit for submission)']],
 4898:      'string_lenient'
 4899:              => [['yes', 'Yes' ],
 4900:                  [ 'no', 'No' ],
 4901:                  [ 'default', 'Default - only bubblesheet grading is lenient' ],
 4902:                  [ 'weighted', 'Yes, weighted (optionresponse in checkbox mode)' ]],
 4903:      'string_discussvote'
 4904:              => [['yes','Yes'],
 4905:                  ['notended','Yes, unless discussion ended'],
 4906:                  ['no','No']],
 4907:      'string_ip'
 4908:              => [['_allowfrom_','Hostname(s), or IP(s) from which access is allowed'],
 4909:                  ['_denyfrom_','Hostname(s) or IP(s) from which access is disallowed']], 
 4910:      'string_deeplink'
 4911:              => [['on','Set choices for link protection, resource listing, and access scope']],
 4912:     );
 4913:    
 4914: 
 4915: my %stringmatches = (
 4916:          'string_lenient'
 4917:               => [['weighted','^\-?[.\d]+,\-?[.\d]+,\-?[.\d]+,\-?[.\d]+$'],],
 4918:          'string_ip'
 4919:               => [['_allowfrom_','[^\!]+'],
 4920:                   ['_denyfrom_','\!']],
 4921:          'string_deeplink'
 4922:               => [['on','^(full|absent|grades|details|datestatus)\,(res|map|rec)\,(any|only|key\:\w+|lti\:\d+)$']],
 4923:     );
 4924: 
 4925: my %stringtypes = (
 4926:                     type         => 'string_questiontype',
 4927:                     lenient      => 'string_lenient',
 4928:                     retrypartial => 'string_yesno',
 4929:                     discussvote  => 'string_discussvote',
 4930:                     examcode     => 'string_examcode',
 4931:                     acc          => 'string_ip',
 4932:                     deeplink     => 'string_deeplink',
 4933:                   );
 4934: 
 4935: # Returns the possible values and titles for a given string type, or undef if there are none.
 4936: # Used by courseprefs.
 4937: #
 4938: # @param {string} $string_type - a parameter type for strings
 4939: # @returns {array reference} - 2D array, containing values and English titles
 4940: sub standard_string_options {
 4941:     my ($string_type) = @_;
 4942:     if (ref($strings{$string_type}) eq 'ARRAY') {
 4943:         return $strings{$string_type};
 4944:     }
 4945:     return;
 4946: }
 4947: 
 4948: # Returns regular expressions to match kinds of string types, or undef if there are none.
 4949: #
 4950: # @param {string} $string_type - a parameter type for strings
 4951: # @returns {array reference}  - 2D array, containing regular expression names and regular expressions
 4952: sub standard_string_matches {
 4953:     my ($string_type) = @_;
 4954:     if (ref($stringmatches{$string_type}) eq 'ARRAY') {
 4955:         return $stringmatches{$string_type};
 4956:     }
 4957:     return;
 4958: }
 4959: 
 4960: # Returns a parameter type for a given parameter with a string type, or undef if not known.
 4961: #
 4962: # @param {string} $name - parameter name
 4963: # @returns {string}
 4964: sub get_stringtype {
 4965:     my ($name) = @_;
 4966:     if (exists($stringtypes{$name})) {
 4967:         return $stringtypes{$name};
 4968:     }
 4969:     return;
 4970: }
 4971: 
 4972: # Returns HTML to edit a string parameter.
 4973: #
 4974: # @param {string} $thistype - parameter type
 4975: # @param {string} $thiskey - parameter key
 4976: # @param {string} $showval - parameter current value
 4977: # @param {string} $name - parameter name
 4978: # @param {boolean} $readonly - true if the values should not be made editable
 4979: # @returns {string}
 4980: sub string_selector {
 4981:     my ($thistype, $thiskey, $showval, $name, $readonly) = @_;
 4982: 
 4983:     if (!exists($strings{$thistype})) {
 4984:         return &default_selector($thiskey,$showval,$readonly);
 4985:     }
 4986: 
 4987:     my %skiptype;
 4988:     if (($thistype eq 'string_questiontype') || 
 4989:             ($thistype eq 'string_lenient') ||
 4990:             ($thistype eq 'string_discussvote') ||
 4991:             ($thistype eq 'string_ip') ||
 4992:             ($thistype eq 'string_deeplink') ||
 4993:             ($name eq 'retrypartial')) {
 4994:         my ($got_chostname,$chostname,$cmajor,$cminor); 
 4995:         foreach my $possibilities (@{ $strings{$thistype} }) {
 4996:             next unless (ref($possibilities) eq 'ARRAY');
 4997:             my ($parmval, $description) = @{ $possibilities };
 4998:             my $parmmatch;
 4999:             if (ref($stringmatches{$thistype}) eq 'ARRAY') {
 5000:                 foreach my $item (@{$stringmatches{$thistype}}) {
 5001:                     if (ref($item) eq 'ARRAY') {
 5002:                         if ($parmval eq $item->[0]) {
 5003:                             $parmmatch = $parmval;
 5004:                             $parmval = '';
 5005:                             last;
 5006:                         }
 5007:                     }
 5008:                 }
 5009:             }
 5010:             my $needsrelease=$Apache::lonnet::needsrelease{"parameter:$name:$parmval:$parmmatch"}; 
 5011:             if ($needsrelease) {
 5012:                 unless ($got_chostname) {
 5013:                     ($chostname,$cmajor,$cminor)=&parameter_release_vars();
 5014:                     $got_chostname = 1;
 5015:                 }
 5016:                 my $needsnewer=&parameter_releasecheck($name,$parmval,$parmmatch,undef,
 5017:                                                        $needsrelease,$cmajor,$cminor);
 5018:                 if ($needsnewer) {
 5019:                     if ($parmmatch ne '') {
 5020:                         $skiptype{$parmmatch} = 1;
 5021:                     } elsif ($parmval ne '') {
 5022:                         $skiptype{$parmval} = 1;
 5023:                     }
 5024:                 }
 5025:             }
 5026:         }
 5027:     }
 5028: 
 5029:     if ($thistype eq 'string_ip') {
 5030:         return &string_ip_selector($thiskey,$showval,$readonly); 
 5031:     } elsif ($thistype eq 'string_deeplink') {
 5032:         return &string_deeplink_selector($thiskey,$showval,$readonly);
 5033:     }
 5034: 
 5035:     my ($result,$disabled);
 5036: 
 5037:     if ($readonly) {
 5038:         $disabled = ' disabled="disabled"';
 5039:     }
 5040:     my $numinrow = 3;
 5041:     if ($thistype eq 'string_problemstatus') {
 5042:         $numinrow = 2;
 5043:     } elsif ($thistype eq 'string_questiontype') {
 5044:         if (keys(%skiptype) > 0) {
 5045:              $numinrow = 4;
 5046:         }
 5047:     }
 5048:     my $rem;
 5049:     if (ref($strings{$thistype}) eq 'ARRAY') {
 5050:         my $i=0;
 5051:         foreach my $possibilities (@{ $strings{$thistype} }) {
 5052:             next unless (ref($possibilities) eq 'ARRAY');
 5053:             my ($name, $description) = @{ $possibilities };
 5054:             next if ($skiptype{$name});
 5055:             $rem = $i%($numinrow);
 5056:             if ($rem == 0) {
 5057:                 if ($i > 0) {
 5058:                     $result .= '</tr>';
 5059:                 }
 5060:                 $result .= '<tr>';
 5061:             }
 5062:             my $colspan;
 5063:             if ($i == @{ $strings{$thistype} }-1) {
 5064:                 $rem = @{ $strings{$thistype} }%($numinrow);
 5065:                 if ($rem) {
 5066:                     my $colsleft = $numinrow - $rem;
 5067:                     if ($colsleft) {
 5068:                         $colspan = $colsleft+1;
 5069:                         $colspan = ' colspan="'.$colspan.'"';
 5070:                     }
 5071:                 }
 5072:             }
 5073:             my ($add,$onchange,$css_class);
 5074:             if ($thistype eq 'string_lenient') {
 5075:                 if ($name eq 'weighted') {
 5076:                     my $display;
 5077:                     my %relatives = &Apache::lonlocal::texthash(
 5078:                                         corrchkd     => 'Correct (checked)',
 5079:                                         corrunchkd   => 'Correct (unchecked)',
 5080:                                         incorrchkd   => 'Incorrect (checked)',
 5081:                                         incorrunchkd => 'Incorrect (unchecked)',
 5082:                     );
 5083:                     my %textval = (
 5084:                                     corrchkd     => '1.0',
 5085:                                     corrunchkd   => '1.0',
 5086:                                     incorrchkd   => '0.0',
 5087:                                     incorrunchkd => '0.0',
 5088:                     );
 5089:                     if ($showval =~ /^([\-\d\.]+)\,([\-\d\.]+)\,([\-\d\.]+)\,([\-\d\.]+)$/) {
 5090:                         $textval{'corrchkd'} = $1;
 5091:                         $textval{'corrunchkd'} = $2;
 5092:                         $textval{'incorrchkd'} = $3;
 5093:                         $textval{'incorrunchkd'} = $4;
 5094:                         $display = 'inline';
 5095:                         $showval = $name;
 5096:                     } else {
 5097:                         $display = 'none';
 5098:                     }
 5099:                     $add = ' <div id="LC_parmtext_'.$thiskey.'" style="display:'.$display.'"><table>'.
 5100:                            '<tr><th colspan="2">'.&mt("Foil's submission status").'</th><th>'.&mt('Points').'</th></tr>';  
 5101:                     foreach my $reltype ('corrchkd','corrunchkd','incorrchkd','incorrunchkd') {
 5102:                         $add .= '<tr><td>&nbsp;</td><td>'.$relatives{$reltype}.'</td>'."\n".
 5103:                                 '<td><input type="text" name="settext_'.$thiskey.'"'.
 5104:                                 ' value="'.$textval{$reltype}.'" size="3"'.$disabled.' />'.
 5105:                                 '</td></tr>';
 5106:                     }
 5107:                     $add .= '</table></div>'."\n";
 5108:                 }
 5109:                 $onchange = ' onclick="javascript:toggleParmTextbox(this.form,'."'$thiskey'".');"';
 5110:                 $css_class = ' class="LC_lenient_radio"';
 5111:             }
 5112:             $result .= '<td class="LC_left_item"'.$colspan.'>'.
 5113:                        '<span class="LC_nobreak"><label>'.
 5114:                        '<input type="radio" name="set_'.$thiskey.
 5115:                        '" value="'.$name.'"'.$onchange.$css_class.$disabled;
 5116:             if ($showval eq $name) {
 5117:                 $result .= ' checked="checked"';
 5118:             }
 5119:             $result .= ' />'.&mt($description).'</label>'.$add.'</span></td>';
 5120:             $i++;
 5121:         }
 5122:         $result .= '</tr>';
 5123:     }
 5124:     if ($result) {
 5125:         $result = '<table border="0">'.$result.'</table>';
 5126:     }
 5127:     return $result;
 5128: }
 5129: 
 5130: my %intervals =
 5131:     (
 5132:      'date_interval'
 5133:              => [[ 'done', 'Yes' ],
 5134:                  [ 'done_proctor', 'Yes, with proctor key'],                  
 5135:                  [ '', 'No' ]],
 5136:     );
 5137: 
 5138: my %intervalmatches = (
 5139:          'date_interval'
 5140:               => [['done','\d+_done(|\:[^\:]+\:)$'],
 5141:                   ['done_proctor','\d+_done(|\:[^\:]+\:)_proctor_']],
 5142:     );
 5143: 
 5144: my %intervaltypes = (
 5145:                       interval => 'date_interval',
 5146:     );
 5147: 
 5148: # Returns regular expressions to match kinds of interval type, or undef if there are none.
 5149: #
 5150: # @param {string} $interval_type - a parameter type for intervals
 5151: # @returns {array reference}  - 2D array, containing regular expression names and regular expressions
 5152: sub standard_interval_matches {
 5153:     my ($interval_type) = @_;
 5154:     if (ref($intervalmatches{$interval_type}) eq 'ARRAY') {
 5155:         return $intervalmatches{$interval_type};
 5156:     }
 5157:     return;
 5158: }
 5159: 
 5160: # Returns a parameter type for a given parameter with an interval type, or undef if not known.
 5161: #
 5162: # @param {string} $name - parameter name
 5163: # @returns {string}
 5164: sub get_intervaltype {
 5165:     my ($name) = @_;
 5166:     if (exists($intervaltypes{$name})) {
 5167:         return $intervaltypes{$name};
 5168:     }
 5169:     return;
 5170: }
 5171: 
 5172: # Returns the possible values and titles for a given interval type, or undef if there are none.
 5173: # Used by courseprefs.
 5174: #
 5175: # @param {string} $interval_type - a parameter type for intervals
 5176: # @returns {array reference} - 2D array, containing values and English titles
 5177: sub standard_interval_options {
 5178:     my ($interval_type) = @_;
 5179:     if (ref($intervals{$interval_type}) eq 'ARRAY') {
 5180:         return $intervals{$interval_type};
 5181:     }
 5182:     return;
 5183: }
 5184: 
 5185: # Returns HTML to edit a date interval parameter.
 5186: #
 5187: # @param {string} $thiskey - parameter key
 5188: # @param {string} $name - parameter name
 5189: # @param {string} $showval - parameter current value
 5190: # @param {boolean} $readonly - true if the values should not be made editable
 5191: # @returns {string}
 5192: sub date_interval_selector {
 5193:     my ($thiskey, $name, $showval, $readonly) = @_;
 5194:     my ($result,%skipval);
 5195:     if ($name eq 'interval') {
 5196:         my $intervaltype = &get_intervaltype($name);
 5197:         my ($got_chostname,$chostname,$cmajor,$cminor);
 5198:         foreach my $possibilities (@{ $intervals{$intervaltype} }) {
 5199:             next unless (ref($possibilities) eq 'ARRAY');
 5200:             my ($parmval, $description) = @{ $possibilities };
 5201:             my $parmmatch;
 5202:             if (ref($intervalmatches{$intervaltype}) eq 'ARRAY') {
 5203:                 foreach my $item (@{$intervalmatches{$intervaltype}}) {
 5204:                     if (ref($item) eq 'ARRAY') {
 5205:                         if ($parmval eq $item->[0]) {
 5206:                             $parmmatch = $parmval;
 5207:                             $parmval = '';
 5208:                             last;
 5209:                         }
 5210:                     }
 5211:                 }
 5212:             }
 5213:             my $needsrelease=$Apache::lonnet::needsrelease{"parameter:$name:$parmval:$parmmatch"};
 5214:             if ($needsrelease) {
 5215:                 unless ($got_chostname) {
 5216:                     ($chostname,$cmajor,$cminor)=&parameter_release_vars();
 5217:                     $got_chostname = 1;
 5218:                 }
 5219:                 my $needsnewer=&parameter_releasecheck($name,$parmval,$parmmatch,undef,
 5220:                                                        $needsrelease,$cmajor,$cminor);
 5221:                 if ($needsnewer) {
 5222:                     if ($parmmatch ne '') {
 5223:                         $skipval{$parmmatch} = 1;
 5224:                     } elsif ($parmval ne '') {
 5225:                         $skipval{$parmval} = 1;
 5226:                     }
 5227:                 }
 5228:             }
 5229:         }
 5230:     }
 5231: 
 5232:     my $currval = $showval;
 5233:     foreach my $which (['days', 86400, 31],
 5234:                ['hours', 3600, 23],
 5235:                ['minutes', 60, 59],
 5236:                ['seconds',  1, 59]) {
 5237:         my ($name, $factor, $max) = @{ $which };
 5238:         my $amount = int($showval/$factor);
 5239:         $showval  %= $factor;
 5240:         my %select = ((map {$_ => $_} (0..$max)),
 5241:                 'select_form_order' => [0..$max]);
 5242:         $result .= &Apache::loncommon::select_form($amount,$name.'_'.$thiskey,
 5243:                             \%select,'',$readonly);
 5244:         $result .= ' '.&mt($name);
 5245:     }
 5246:     if ($name eq 'interval') {
 5247:         unless ($skipval{'done'}) {
 5248:             my $checkedon = '';
 5249:             my $checkedproc = '';
 5250:             my $currproctorkey = '';
 5251:             my $currprocdisplay = 'hidden';
 5252:             my $currdonetext = &mt('Done');
 5253:             my $checkedoff = ' checked="checked"';
 5254:             if ($currval =~ /^(?:\d+)_done$/) {
 5255:                 $checkedon = ' checked="checked"';
 5256:                 $checkedoff = '';
 5257:             } elsif ($currval =~ /^(?:\d+)_done\:([^\:]+)\:$/) {
 5258:                 $currdonetext = $1;
 5259:                 $checkedon = ' checked="checked"';
 5260:                 $checkedoff = '';
 5261:             } elsif ($currval =~ /^(?:\d+)_done_proctor_(.+)$/) {
 5262:                 $currproctorkey = $1;
 5263:                 $checkedproc = ' checked="checked"';
 5264:                 $checkedoff = '';
 5265:                 $currprocdisplay = 'text';
 5266:             } elsif ($currval =~ /^(?:\d+)_done\:([^\:]+)\:_proctor_(.+)$/) {
 5267:                 $currdonetext = $1;
 5268:                 $currproctorkey = $2;
 5269:                 $checkedproc = ' checked="checked"';
 5270:                 $checkedoff = '';
 5271:                 $currprocdisplay = 'text';
 5272:             }
 5273:             my $onclick = ' onclick="toggleSecret(this.form,'."'done_','$thiskey'".');"';
 5274:             my $disabled;
 5275:             if ($readonly) {
 5276:                 $disabled = ' disabled="disabled"';
 5277:             }
 5278:             $result .= '<br /><span class="LC_nobreak">'.&mt('Include "done" button').
 5279:                        '<label><input type="radio" value="" name="done_'.$thiskey.'"'.$checkedoff.$onclick.$disabled.' />'.
 5280:                        &mt('No').'</label>'.('&nbsp;'x2).
 5281:                        '<label><input type="radio" value="_done" name="done_'.$thiskey.'"'.$checkedon.$onclick.$disabled.' />'.
 5282:                        &mt('Yes').'</label>'.('&nbsp;'x2).
 5283:                        '<label><input type="radio" value="_done_proctor" name="done_'.$thiskey.'"'.$checkedproc.$onclick.$disabled.' />'.
 5284:                        &mt('Yes, with proctor key').'</label>'.
 5285:                        '<input type="'.$currprocdisplay.'" id="done_'.$thiskey.'_proctorkey" '.
 5286:                        'name="done_'.$thiskey.'_proctorkey" value="'.&HTML::Entities::encode($currproctorkey,'"<>&').'"'.$disabled.' /></span><br />'.
 5287:                        '<span class="LC_nobreak">'.&mt('Button text').': '.
 5288:                        '<input type="text" name="done_'.$thiskey.'_buttontext" value="'.&HTML::Entities::encode($currdonetext,'"<>&').'"'.$disabled.' /></span>';
 5289:         }
 5290:     }
 5291:     unless ($readonly) {
 5292:         $result .= '<input type="hidden" name="dateinterval_'.$thiskey.'" />';
 5293:     }
 5294:     return $result;
 5295: }
 5296: 
 5297: # Returns HTML with a warning if a parameter requires a more recent version of LON-CAPA.
 5298: #
 5299: # @param {string} $name - parameter name
 5300: # @param {string} $namematch - parameter level name (recognized: resourcelevel|maplevel|maplevelrecurse|courselevel)
 5301: # @param {string} $value - parameter value
 5302: # @param {string} $chostname - course server name
 5303: # @param {integer} $cmajor - major version number
 5304: # @param {integer} $cminor - minor version number
 5305: # @param {string} $needsrelease - release version needed (major.minor)
 5306: # @returns {string}
 5307: sub oldversion_warning {
 5308:     my ($name,$namematch,$value,$chostname,$cmajor,$cminor,$needsrelease) = @_;
 5309:     my $standard_name = &standard_parameter_names($name);
 5310:     if ($namematch) {
 5311:         my $level = &standard_parameter_levels($namematch);
 5312:         my $msg = '';
 5313:         if ($level) {
 5314:             $msg = &mt('[_1] was [_2]not[_3] set at the level of: [_4].',
 5315:                        $standard_name,'<b>','</b>','"'.$level.'"');
 5316:         } else {
 5317:             $msg = &mt('[_1] was [_2]not[_3] set.',
 5318:                       $standard_name,'<b>','</b>');
 5319:         }
 5320:         return '<p class="LC_warning">'.$msg.'<br />'.
 5321:                &mt('LON-CAPA version ([_1]) installed on home server ([_2]) does not meet version requirements ([_3] or newer).',
 5322:                    $cmajor.'.'.$cminor,$chostname,
 5323:                    $needsrelease).
 5324:                    '</p>';
 5325:     }
 5326:     my $desc;
 5327:     my $stringtype = &get_stringtype($name);
 5328:     if ($stringtype ne '') {
 5329:         if ($name eq 'examcode') {
 5330:             $desc = $value;
 5331:         } elsif (ref($strings{$stringtypes{$name}}) eq 'ARRAY') {
 5332:             foreach my $possibilities (@{ $strings{$stringtypes{$name}} }) {
 5333:                 next unless (ref($possibilities) eq 'ARRAY');
 5334:                 my ($parmval, $description) = @{ $possibilities };
 5335:                 my $parmmatch;
 5336:                 if (ref($stringmatches{$stringtypes{$name}}) eq 'ARRAY') {
 5337:                     foreach my $item (@{$stringmatches{$stringtypes{$name}}}) {
 5338:                         if (ref($item) eq 'ARRAY') {
 5339:                             my ($regexpname,$pattern) = @{$item};
 5340:                             if ($parmval eq $regexpname) {
 5341:                                 if ($value =~ /$pattern/) {
 5342:                                     $desc = $description; 
 5343:                                     $parmmatch = 1;
 5344:                                     last;
 5345:                                 }
 5346:                             }
 5347:                         }
 5348:                     }
 5349:                     last if ($parmmatch);
 5350:                 } elsif ($parmval eq $value) {
 5351:                     $desc = $description;
 5352:                     last;
 5353:                 }
 5354:             }
 5355:         }
 5356:     } elsif (($name eq 'printstartdate') || ($name eq 'printenddate')) {
 5357:         my $now = time;
 5358:         if ($value =~ /^\d+$/) {
 5359:             if ($name eq 'printstartdate') {
 5360:                 if ($value > $now) {
 5361:                     $desc = &Apache::lonlocal::locallocaltime($value);
 5362:                 }
 5363:             } elsif ($name eq 'printenddate') {
 5364:                 if ($value < $now) {
 5365:                     $desc = &Apache::lonlocal::locallocaltime($value);
 5366:                 }
 5367:             }
 5368:         }
 5369:     }
 5370:     return '<p class="LC_warning">'.
 5371:        &mt('[_1] was [_2]not[_3] set to [_4].',
 5372:            $standard_name,'<b>','</b>','"'.$desc.'"').'<br />'.
 5373:        &mt('LON-CAPA version ([_1]) installed on home server ([_2]) does not meet version requirements ([_3] or newer).',
 5374:        $cmajor.'.'.$cminor,$chostname,
 5375:        $needsrelease).
 5376:        '</p>';
 5377: }
 5378: 
 5379: } # end of block using some constants related to parameter types
 5380: 
 5381: 
 5382: 
 5383: # Shifts all start and end dates in the current course by $shift.
 5384: #
 5385: # @param {integer} $shift - time to shift, in seconds
 5386: # @returns {string} - error name or 'ok'
 5387: sub dateshift {
 5388:     my ($shift)=@_;
 5389:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 5390:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
 5391:     my %data=&Apache::lonnet::dump('resourcedata',$dom,$crs);
 5392: # ugly retro fix for broken version of types
 5393:     foreach my $key (keys(%data)) {
 5394:         if ($key=~/\wtype$/) {
 5395:             my $newkey=$key;
 5396:             $newkey=~s/type$/\.type/;
 5397:             $data{$newkey}=$data{$key};
 5398:             delete $data{$key};
 5399:         }
 5400:     }
 5401:     my %storecontent=();
 5402: # go through all parameters and look for dates
 5403:     foreach my $key (keys(%data)) {
 5404:        if ($data{$key.'.type'}=~/^date_(start|end)$/) {
 5405:           my $newdate=$data{$key}+$shift;
 5406:           $storecontent{$key}=$newdate;
 5407:        }
 5408:     }
 5409:     my $reply=&Apache::lonnet::cput
 5410:                 ('resourcedata',\%storecontent,$dom,$crs);
 5411:     if ($reply eq 'ok') {
 5412:        &log_parmset(\%storecontent);
 5413:     }
 5414:     &Apache::lonnet::devalidatecourseresdata($crs,$dom);
 5415:     return $reply;
 5416: }
 5417: 
 5418: # Overview mode UI to edit course parameters.
 5419: #
 5420: # @param {Apache2::RequestRec} $r - the Apache request
 5421: sub newoverview {
 5422:     my ($r,$parm_permission) = @_;
 5423: 
 5424:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 5425:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
 5426:     my $crstype =  $env{'course.'.$env{'request.course.id'}.'.type'};
 5427:     my $readonly = 1;
 5428:     if ($parm_permission->{'edit'}) {
 5429:         undef($readonly);
 5430:     }
 5431:     &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setoverview',
 5432:         text=>"Overview Mode"});
 5433: 
 5434:     my %loaditems = (
 5435:                       'onload'   => "showHide_courseContent(); resize_scrollbox('mapmenuscroll','1','1'); showHideLenient();",
 5436:                     );
 5437:     my $js = '
 5438: <script type="text/javascript">
 5439: // <![CDATA[
 5440: '.
 5441:             &Apache::lonhtmlcommon::resize_scrollbox_js('params')."\n".
 5442:             &showhide_js()."\n".
 5443:             &toggleparmtextbox_js()."\n".
 5444:             &validateparms_js()."\n".
 5445:             &ipacc_boxes_js()."\n".
 5446:             &done_proctor_js()."\n".
 5447:             &deeplink_js()."\n".
 5448: '// ]]>
 5449: </script>
 5450: ';
 5451: 
 5452:     my $start_page = &Apache::loncommon::start_page('Set Parameters',$js,
 5453:                                                     {'add_entries' => \%loaditems,});
 5454:     my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Overview');
 5455:     $r->print($start_page.$breadcrumbs);
 5456:     &startSettingsScreen($r,'parmset',$crstype);
 5457:     $r->print(<<ENDOVER);
 5458: <form method="post" action="/adm/parmset?action=newoverview" name="parmform" onsubmit="return validateParms();">
 5459: ENDOVER
 5460:     my @ids=();
 5461:     my %typep=();
 5462:     my %keyp=();
 5463:     my %allparms=();
 5464:     my %allparts=();
 5465:     my %allmaps=();
 5466:     my %mapp=();
 5467:     my %symbp=();
 5468:     my %maptitles=();
 5469:     my %uris=();
 5470:     my %keyorder=&standardkeyorder();
 5471:     my %defkeytype=();
 5472: 
 5473:     my %alllevs=();
 5474:     $alllevs{'Resource Level'}='full';
 5475:     $alllevs{'Map/Folder Level'}='map';
 5476:     $alllevs{'Course Level'}='general';
 5477: 
 5478:     my $csec=$env{'form.csec'};
 5479:     my $cgroup=$env{'form.cgroup'};
 5480: 
 5481:     my @pscat=&Apache::loncommon::get_env_multiple('form.pscat');
 5482:     my $pschp=$env{'form.pschp'};
 5483: 
 5484:     my @psprt=&Apache::loncommon::get_env_multiple('form.psprt');
 5485:     if (!@psprt) { $psprt[0]='all'; }
 5486: 
 5487:     my @selected_sections =
 5488:     &Apache::loncommon::get_env_multiple('form.Section');
 5489:     @selected_sections = ('all') if (! @selected_sections);
 5490:     foreach my $sec (@selected_sections) {
 5491:         if ($sec eq 'all') {
 5492:             @selected_sections = ('all');
 5493:         }
 5494:     }
 5495:     if ($env{'request.course.sec'} ne '') {
 5496:         @selected_sections = ($env{'request.course.sec'});
 5497:     }
 5498:     my @selected_groups =
 5499:         &Apache::loncommon::get_env_multiple('form.Group');
 5500: 
 5501:     my $pssymb='';
 5502:     my $parmlev='';
 5503: 
 5504:     unless ($env{'form.parmlev'}) {
 5505:         $parmlev = 'map';
 5506:     } else {
 5507:         $parmlev = $env{'form.parmlev'};
 5508:     }
 5509: 
 5510:     &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allmaps,
 5511:                 \%mapp, \%symbp,\%maptitles,\%uris,
 5512:                 \%keyorder,\%defkeytype);
 5513: 
 5514:     if (grep {$_ eq 'all'} (@psprt)) {
 5515:         @psprt = keys(%allparts);
 5516:     }
 5517: # Menu to select levels, etc
 5518: 
 5519:     $r->print('<div class="LC_Box">');
 5520:     #$r->print('<h2 class="LC_hcell">Step 1</h2>');
 5521:     $r->print('<div>');
 5522:     $r->print(&Apache::lonhtmlcommon::start_pick_box(undef,'parmlevel'));
 5523:     &levelmenu($r,\%alllevs,$parmlev);
 5524:     if ($parmlev ne 'general') {
 5525:         $r->print(&Apache::lonhtmlcommon::row_closure());
 5526:         &mapmenu($r,\%allmaps,$pschp,\%maptitles,\%symbp);
 5527:     }
 5528:     $r->print(&Apache::lonhtmlcommon::row_closure(1));
 5529:     $r->print(&Apache::lonhtmlcommon::end_pick_box());
 5530:     $r->print('</div></div>');
 5531: 
 5532:     $r->print('<div class="LC_Box">');
 5533:     $r->print('<div>');
 5534:     &displaymenu($r,\%allparms,\@pscat,\%keyorder);
 5535:     $r->print(&Apache::lonhtmlcommon::start_pick_box());
 5536:     $r->print(&Apache::lonhtmlcommon::row_title(&mt('Select Parts to View')));
 5537:     my $sectionselector = &sectionmenu(\@selected_sections);
 5538:     my $groupselector = &groupmenu(\@selected_groups);
 5539:     $r->print('<table>'.
 5540:               '<tr><th>'.&mt('Parts').'</th>');
 5541:     if ($sectionselector) {
 5542:         $r->print('<th>'.&mt('Section(s)').'</th>');
 5543:     }
 5544:     if ($groupselector) {
 5545:         $r->print('<th>'.&mt('Group(s)').'</th>');
 5546:     }
 5547:     $r->print('</tr><tr><td>');
 5548:     &partmenu($r,\%allparts,\@psprt);
 5549:     $r->print('</td>');
 5550:     if ($sectionselector) { 
 5551:         $r->print('<td>'.$sectionselector.'</td>');
 5552:     }
 5553:     if ($groupselector) {
 5554:         $r->print('<td>'.$groupselector.'</td>');
 5555:     }
 5556:     $r->print('</tr></table>');
 5557:     $r->print(&Apache::lonhtmlcommon::row_closure(1));
 5558:     $r->print(&Apache::lonhtmlcommon::end_pick_box());
 5559:     $r->print('</div></div>');
 5560: 
 5561:     $r->print('<div class="LC_Box">');
 5562:     $r->print('<div>');
 5563:     my $sortorder=$env{'form.sortorder'};
 5564:     unless ($sortorder) { $sortorder='realmstudent'; }
 5565:     &sortmenu($r,$sortorder);
 5566:     $r->print('</div></div>');
 5567: 
 5568:     $r->print('<p><input type="submit" name="dis" value="'.&mt('Display').'" /></p>');
 5569: 
 5570: # Build the list data hash from the specified parms
 5571: 
 5572:     my $listdata;
 5573:     %{$listdata}=();
 5574: 
 5575:     foreach my $cat (@pscat) {
 5576:         &secgroup_lister($cat,$pschp,$parmlev,$listdata,\@psprt,\@selected_sections,\%defkeytype,\%allmaps,\@ids,\%symbp);
 5577:         &secgroup_lister($cat,$pschp,$parmlev,$listdata,\@psprt,\@selected_groups,\%defkeytype,\%allmaps,\@ids,\%symbp);
 5578:     }
 5579: 
 5580:     if (($env{'form.store'}) || ($env{'form.dis'})) {
 5581: 
 5582:         if ($env{'form.store'}) { &storedata($r,$crs,$dom); }
 5583: 
 5584: # Read modified data
 5585: 
 5586:         my $resourcedata=&readdata($crs,$dom);
 5587: 
 5588: # List data
 5589: 
 5590:         &listdata($r,$resourcedata,$listdata,$sortorder,'newoverview',undef,$readonly);
 5591:     }
 5592:     $r->print(&tableend());
 5593:     unless ($readonly) {
 5594:         $r->print( ((($env{'form.store'}) || ($env{'form.dis'}))?'<p><input type="submit" name="store" value="'.&mt('Save').'" /></p>':'') );
 5595:     }
 5596:     $r->print('</form>');
 5597:     &endSettingsScreen($r);
 5598:     $r->print(&Apache::loncommon::end_page());
 5599: }
 5600: 
 5601: # Fills $listdata with parameter information.
 5602: # Keys use the format course id.[section id].part.name and course id.[section id].part.name.type.
 5603: # The non-type value is always 1.
 5604: #
 5605: # @param {string} $cat - parameter name
 5606: # @param {string} $pschp - selected map pc, or 'all'
 5607: # @param {string} $parmlev - selected level value (full|map|general), or ''
 5608: # @param {hash reference} $listdata - the parameter data that will be modified
 5609: # @param {array reference} $psprt - selected parts
 5610: # @param {array reference} $selections - selected sections
 5611: # @param {hash reference} $defkeytype - hash parameter name -> parameter type
 5612: # @param {hash reference} $allmaps - hash map pc -> map src
 5613: # @param {array reference} $ids - resource and map ids
 5614: # @param {hash reference} $symbp - hash map pc or resource/map id -> map src.'___(all)' or resource symb
 5615: sub secgroup_lister {
 5616:     my ($cat,$pschp,$parmlev,$listdata,$psprt,$selections,$defkeytype,$allmaps,$ids,$symbp) = @_;
 5617:     foreach my $item (@{$selections}) {
 5618:         foreach my $part (@{$psprt}) {
 5619:             my $rootparmkey=$env{'request.course.id'};
 5620:             if (($item ne 'all') && ($item ne 'none') && ($item)) {
 5621:                 $rootparmkey.='.['.$item.']';
 5622:             }
 5623:             if ($parmlev eq 'general') {
 5624: # course-level parameter
 5625:                 my $newparmkey=$rootparmkey.'.'.$part.'.'.$cat;
 5626:                 $$listdata{$newparmkey}=1;
 5627:                 $$listdata{$newparmkey.'.type'}=$$defkeytype{$cat};
 5628:             } elsif ($parmlev eq 'map') {
 5629: # map-level parameter
 5630:                 foreach my $mapid (keys(%{$allmaps})) {
 5631:                     if (($pschp ne 'all') && ($pschp ne $mapid)) { next; }
 5632:                     my $newparmkey=$rootparmkey.'.'.$$allmaps{$mapid}.'___(all).'.$part.'.'.$cat;
 5633:                     $$listdata{$newparmkey}=1;
 5634:                     $$listdata{$newparmkey.'.type'}=$$defkeytype{$cat};
 5635:                 }
 5636:             } else {
 5637: # resource-level parameter
 5638:                 foreach my $rid (@{$ids}) {
 5639:                     my ($map,$resid,$url)=&Apache::lonnet::decode_symb($$symbp{$rid});
 5640:                     if (($pschp ne 'all') && ($$allmaps{$pschp} ne $map)) { next; }
 5641:                     my $newparmkey=$rootparmkey.'.'.$$symbp{$rid}.'.'.$part.'.'.$cat;
 5642:                     $$listdata{$newparmkey}=1;
 5643:                     $$listdata{$newparmkey.'.type'}=$$defkeytype{$cat};
 5644:                 }
 5645:             }
 5646:         }
 5647:     }
 5648: }
 5649: 
 5650: # UI to edit parameter settings starting with a list of all existing parameters.
 5651: # (called by setoverview action)
 5652: #
 5653: # @param {Apache2::RequestRec} $r - the Apache request
 5654: sub overview {
 5655:     my ($r,$parm_permission) = @_;
 5656:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 5657:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
 5658:     my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
 5659:     my $readonly = 1;
 5660:     if ($parm_permission->{'edit'}) {
 5661:         undef($readonly);
 5662:     }
 5663:     my $js = '<script type="text/javascript">'."\n".
 5664:              '// <![CDATA['."\n".
 5665:              &toggleparmtextbox_js()."\n".
 5666:              &validateparms_js()."\n".
 5667:              &ipacc_boxes_js()."\n".
 5668:              &done_proctor_js()."\n".
 5669:              &deeplink_js()."\n".
 5670:              '// ]]>'."\n".
 5671:              '</script>'."\n";
 5672:     &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setoverview',
 5673:     text=>"Overview Mode"});
 5674:     my %loaditems = (
 5675:                       'onload'   => "showHideLenient();",
 5676:                     );
 5677: 
 5678:     my $start_page=&Apache::loncommon::start_page('Modify Parameters',$js,{'add_entries' => \%loaditems,});
 5679:     my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Overview');
 5680:     $r->print($start_page.$breadcrumbs);
 5681:     &startSettingsScreen($r,'parmset',$crstype);
 5682:     $r->print('<form method="post" action="/adm/parmset?action=setoverview" name="parmform" onsubmit="return validateParms();">');
 5683: 
 5684: # Store modified
 5685: 
 5686:     unless ($readonly) {
 5687:         &storedata($r,$crs,$dom);
 5688:     }
 5689: 
 5690: # Read modified data
 5691: 
 5692:     my ($resourcedata,$classlist)=&readdata($crs,$dom);
 5693: 
 5694: 
 5695:     my $sortorder=$env{'form.sortorder'};
 5696:     unless ($sortorder) { $sortorder='realmstudent'; }
 5697:     &sortmenu($r,$sortorder);
 5698: 
 5699:     my $submitbutton = '<input type="submit" value="'.&mt('Save').'" />';
 5700: 
 5701:     if ($readonly) {
 5702:         $r->print('<p>'.$submitbutton.'</p>');
 5703:     }
 5704: 
 5705: # List data
 5706: 
 5707:     my $foundkeys=&listdata($r,$resourcedata,$resourcedata,$sortorder,'overview',$classlist,$readonly);
 5708:     $r->print(&tableend().'<p>');
 5709:     if ($foundkeys) {
 5710:         unless ($readonly) {
 5711:             $r->print('<p>'.$submitbutton.'</p>');
 5712:         }
 5713:     } else {
 5714:         $r->print('<p class="LC_info">'.&mt('There are no parameters.').'</p>');
 5715:     }
 5716:     $r->print('</form>'.&Apache::loncommon::end_page());
 5717: }
 5718: 
 5719: # Unused sub.
 5720: #
 5721: # @param {Apache2::RequestRec} $r - the Apache request
 5722: sub clean_parameters {
 5723:     my ($r) = @_;
 5724:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 5725:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
 5726: 
 5727:     &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=cleanparameters',
 5728:         text=>"Clean Parameters"});
 5729:     my $start_page=&Apache::loncommon::start_page('Clean Parameters');
 5730:     my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Clean');
 5731:     $r->print(<<ENDOVER);
 5732: $start_page
 5733: $breadcrumbs
 5734: <form method="post" action="/adm/parmset?action=cleanparameters" name="parmform">
 5735: ENDOVER
 5736: # Store modified
 5737: 
 5738:     &storedata($r,$crs,$dom);
 5739: 
 5740: # Read modified data
 5741: 
 5742:     my $resourcedata=&readdata($crs,$dom);
 5743: 
 5744: # List data
 5745: 
 5746:     $r->print('<h3>'.
 5747:           &mt('These parameters refer to resources that do not exist.').
 5748:           '</h3>'.
 5749:           '<input type="submit" value="'.&mt('Delete Selected').'" />'.'<br />'.
 5750:           '<br />');
 5751:     $r->print(&Apache::loncommon::start_data_table().
 5752:           '<tr>'.
 5753:           '<th>'.&mt('Delete').'</th>'.
 5754:           '<th>'.&mt('Parameter').'</th>'.
 5755:           '</tr>');
 5756:     foreach my $thiskey (sort(keys(%{$resourcedata}))) {
 5757:         next if (!exists($resourcedata->{$thiskey.'.type'})
 5758:             && $thiskey=~/\.type$/);
 5759:         my %data = &parse_key($thiskey);
 5760:         if (1) { #exists($data{'realm_exists'})
 5761:             #&& !$data{'realm_exists'}) {
 5762:             $r->print(&Apache::loncommon::start_data_table_row().
 5763:                 '<tr>'.
 5764:                 '<td><input type="checkbox" name="del_'.$thiskey.'" /></td>'              );
 5765: 
 5766:             $r->print('<td>');
 5767:             my $display_value = $resourcedata->{$thiskey};
 5768:             if (&isdateparm($resourcedata->{$thiskey.'.type'})) {
 5769:             $display_value =
 5770:                 &Apache::lonlocal::locallocaltime($display_value);
 5771:             }
 5772:             my $parmitem = &standard_parameter_names($data{'parameter_name'});
 5773:             $parmitem = &mt($parmitem);
 5774:             $r->print(&mt('Parameter: "[_1]" with value: "[_2]"',
 5775:                 $parmitem,$resourcedata->{$thiskey}));
 5776:             $r->print('<br />');
 5777:             if ($data{'scope_type'} eq 'all') {
 5778:                 $r->print(&mt('All users'));
 5779:             } elsif ($data{'scope_type'} eq 'user') {
 5780:                 $r->print(&mt('User: [_1]',join(':',@{$data{'scope'}})));
 5781:             } elsif ($data{'scope_type'} eq 'secgroup') {
 5782:                 $r->print(&mt('Group/Section: [_1]',$data{'scope'}));
 5783:             }
 5784:             $r->print('<br />');
 5785:             if ($data{'realm_type'} eq 'all') {
 5786:                 $r->print(&mt('All Resources'));
 5787:             } elsif ($data{'realm_type'} eq 'folder') {
 5788:                 $r->print(&mt('Folder: [_1]'),$data{'realm'});
 5789:             } elsif ($data{'realm_type'} eq 'symb') {
 5790:             my ($map,$resid,$url) =
 5791:                 &Apache::lonnet::decode_symb($data{'realm'});
 5792:             $r->print(&mt('Resource: [_1]with ID: [_2]in folder [_3]',
 5793:                         $url.' <br />&nbsp;&nbsp;&nbsp;',
 5794:                         $resid.' <br />&nbsp;&nbsp;&nbsp;',$map));
 5795:             }
 5796:             $r->print(' <br />&nbsp;&nbsp;&nbsp;'.&mt('Part: [_1]',$data{'parameter_part'}));
 5797:             $r->print('</td></tr>');
 5798: 
 5799:         }
 5800:     }
 5801:     $r->print(&Apache::loncommon::end_data_table().'<p>'.
 5802:           '<input type="submit" value="'.&mt('Delete Selected').'" />'.
 5803:           '</p></form>');
 5804:     &endSettingsScreen($r);
 5805:     $r->print(&Apache::loncommon::end_page());
 5806: }
 5807: 
 5808: # UI to shift all dates (called by dateshift1 action).
 5809: # Used by overview mode.
 5810: #
 5811: # @param {Apache2::RequestRec} $r - the Apache request
 5812: sub date_shift_one {
 5813:     my ($r) = @_;
 5814:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 5815:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
 5816:     my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
 5817: 
 5818:     &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=dateshift1&timebase='.$env{'form.timebase'},
 5819:         text=>"Shifting Dates"});
 5820:     my $start_page=&Apache::loncommon::start_page('Shift Dates');
 5821:     my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Shift');
 5822:     $r->print($start_page.$breadcrumbs);
 5823:     &startSettingsScreen($r,'parmset',$crstype);
 5824:     $r->print('<form name="shiftform" method="post" action="">'.
 5825:               '<table><tr><td>'.&mt('Currently set date:').'</td><td>'.
 5826:               &Apache::lonlocal::locallocaltime($env{'form.timebase'}).'</td></tr>'.
 5827:               '<tr><td>'.&mt('Shifted date:').'</td><td>'.
 5828:                     &Apache::lonhtmlcommon::date_setter('shiftform',
 5829:                                                         'timeshifted',
 5830:                                                         $env{'form.timebase'},,
 5831:                                                         '').
 5832:               '</td></tr></table>'.
 5833:               '<input type="hidden" name="action" value="dateshift2" />'.
 5834:               '<input type="hidden" name="timebase" value="'.$env{'form.timebase'}.'" />'.
 5835:               '<input type="submit" value="'.&mt('Shift all dates accordingly').'" /></form>');
 5836:     &endSettingsScreen($r);
 5837:     $r->print(&Apache::loncommon::end_page());
 5838: }
 5839: 
 5840: # UI to shift all dates (second form).
 5841: #
 5842: # @param {Apache2::RequestRec} $r - the Apache request
 5843: sub date_shift_two {
 5844:     my ($r) = @_;
 5845:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 5846:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
 5847:     my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
 5848:     &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=dateshift1&timebase='.$env{'form.timebase'},
 5849:         text=>"Shifting Dates"});
 5850:     my $start_page=&Apache::loncommon::start_page('Shift Dates');
 5851:     my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Shift');
 5852:     $r->print($start_page.$breadcrumbs);
 5853:     &startSettingsScreen($r,'parmset',$crstype);
 5854:     my $timeshifted=&Apache::lonhtmlcommon::get_date_from_form('timeshifted');
 5855:     $r->print('<h2>'.&mt('Shift Dates').'</h2>'.
 5856:               '<p>'.&mt('Shifting all dates such that [_1] becomes [_2]',
 5857:               &Apache::lonlocal::locallocaltime($env{'form.timebase'}),
 5858:               &Apache::lonlocal::locallocaltime($timeshifted)).'</p>');
 5859:     my $delta=$timeshifted-$env{'form.timebase'};
 5860:     &dateshift($delta);
 5861:     $r->print(
 5862:         &Apache::lonhtmlcommon::confirm_success(&mt('Done')).
 5863:         '<br /><br />'.
 5864:         &Apache::lonhtmlcommon::actionbox(
 5865:             ['<a href="/adm/parmset">'.&mt('Content and Problem Settings').'</a>']));
 5866:     &endSettingsScreen($r);
 5867:     $r->print(&Apache::loncommon::end_page());
 5868: }
 5869: 
 5870: # Returns the different components of a resourcedata key.
 5871: # Keys: scope_type, scope, realm_type, realm, realm_title,
 5872: #       realm_exists, parameter_part, parameter_name.
 5873: # Was used by clean_parameters (which is unused).
 5874: #
 5875: # @param {string} $key - the parameter key
 5876: # @returns {hash}
 5877: sub parse_key {
 5878:     my ($key) = @_;
 5879:     my %data;
 5880:     my ($middle,$part,$name)=
 5881:     ($key=~/^$env{'request.course.id'}\.(?:(.+)\.)*([\w\s\-]+)\.(\w+)$/);
 5882:     $data{'scope_type'} = 'all';
 5883:     if ($middle=~/^\[(.*)\]/) {
 5884:         $data{'scope'} = $1;
 5885:         if ($data{'scope'}=~/^useropt\:($match_username)\:($match_domain)/) {
 5886:             $data{'scope_type'} = 'user';
 5887:             $data{'scope'} = [$1,$2];
 5888:         } else {
 5889:             $data{'scope_type'} = 'secgroup';
 5890:         }
 5891:         $middle=~s/^\[(.*)\]//;
 5892:     }
 5893:     $middle=~s/\.+$//;
 5894:     $middle=~s/^\.+//;
 5895:     $data{'realm_type'}='all';
 5896:     if ($middle=~/^(.+)\_\_\_\(all\)$/) {
 5897:         $data{'realm'} = $1;
 5898:         $data{'realm_type'} = 'folder';
 5899:         $data{'realm_title'} = &Apache::lonnet::gettitle($data{'realm'});
 5900:         ($data{'realm_exists'}) = &Apache::lonnet::is_on_map($data{'realm'});
 5901:     } elsif ($middle) {
 5902:         $data{'realm'} = $middle;
 5903:         $data{'realm_type'} = 'symb';
 5904:         $data{'realm_title'} = &Apache::lonnet::gettitle($data{'realm'});
 5905:         my ($map,$resid,$url) = &Apache::lonnet::decode_symb($data{'realm'});
 5906:         $data{'realm_exists'} = &Apache::lonnet::symbverify($data{'realm'},$url);
 5907:     }
 5908: 
 5909:     $data{'parameter_part'} = $part;
 5910:     $data{'parameter_name'} = $name;
 5911: 
 5912:     return %data;
 5913: }
 5914: 
 5915: 
 5916: # Calls loncommon::start_page with the "Settings" title.
 5917: sub header {
 5918:     return &Apache::loncommon::start_page('Settings');
 5919: }
 5920: 
 5921: 
 5922: 
 5923: ##################################################
 5924: # MAIN MENU
 5925: ##################################################
 5926: 
 5927: # Content and problem settings main menu.
 5928: #
 5929: # @param {Apache2::RequestRec} $r - the Apache request
 5930: # @param {boolean} $parm_permission - true if the user has permission to edit the current course or section
 5931: sub print_main_menu {
 5932:     my ($r,$parm_permission)=@_;
 5933:     #
 5934:     $r->print(&header());
 5935:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content and Problem Settings'));
 5936:     my $crstype = &Apache::loncommon::course_type();
 5937:     my $lc_crstype = lc($crstype);
 5938: 
 5939:     &startSettingsScreen($r,'parmset',$crstype);
 5940:     $r->print(<<ENDMAINFORMHEAD);
 5941: <form method="post" enctype="multipart/form-data"
 5942:       action="/adm/parmset" name="studentform">
 5943: ENDMAINFORMHEAD
 5944: #
 5945:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 5946:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 5947:     my $vgr  = &Apache::lonnet::allowed('vgr',$env{'request.course.id'});
 5948:     my $mgr  = &Apache::lonnet::allowed('mgr',$env{'request.course.id'});
 5949:     my $dcm = &Apache::lonnet::allowed('dcm',$env{'request.course.id'});
 5950:     my $vcb = &Apache::lonnet::allowed('vcb',$env{'request.course.id'});
 5951:     my $vpa = &Apache::lonnet::allowed('vpa',$env{'request.course.id'});
 5952:     if ((!$dcm) && ($env{'request.course.sec'} ne '')) {
 5953:         $dcm = &Apache::lonnet::allowed('dcm',$env{'request.course.id'}.
 5954:                                         '/'.$env{'request.course.sec'});
 5955:     }
 5956:     if ((!$vcb) && ($env{'request.course.sec'} ne '')) {
 5957:         $vcb = &Apache::lonnet::allowed('vcb',$env{'request.course.id'}.
 5958:                                         '/'.$env{'request.course.sec'});
 5959:     }
 5960:     my (%linktext,%linktitle,%url);
 5961:     if ($parm_permission->{'edit'}) {
 5962:         %linktext = (
 5963:                      newoverview     => 'Edit Resource Parameters - Overview Mode',
 5964:                      settable        => 'Edit Resource Parameters - Table Mode',
 5965:                      setoverview     => 'Modify Resource Parameters - Overview Mode',
 5966:                     );
 5967:         %linktitle = (
 5968:                      newoverview     => 'Set/Modify resource parameters in overview mode.',
 5969:                      settable        => 'Set/Modify resource parameters in table mode.',
 5970:                      setoverview     => 'Set/Modify existing resource parameters in overview mode.',
 5971:                      );
 5972:     } else {
 5973:         %linktext = (
 5974:                      newoverview     => 'View Resource Parameters - Overview Mode',
 5975:                      settable        => 'View Resource Parameters - Table Mode',
 5976:                      setoverview     => 'View Resource Parameters - Overview Mode',
 5977:                    );
 5978:         %linktitle = (
 5979:                      newoverview     => 'Display resource parameters in overview mode.',
 5980:                      settable        => 'Display resource parameters in table mode.',
 5981:                      setoverview     => 'Display existing resource parameters in overview mode.',
 5982:                      );
 5983:     }
 5984:     if ($mgr) {
 5985:         $linktext{'resettimes'} = 'Reset Student Access Times';
 5986:         $linktitle{'resettimes'} = "Reset access times for folders/maps, resources or the $lc_crstype.";
 5987:         $url{'resettimes'} = '/adm/helper/resettimes.helper';
 5988:     } elsif ($vgr) {
 5989:         $linktext{'resettimes'} = 'Display Student Access Times',
 5990:         $linktitle{'resettimes'} = "Display access times for folders/maps, resources or the $lc_crstype.",
 5991:         $url{'resettimes'} = '/adm/accesstimes';
 5992:     }
 5993:     my @menu =
 5994:         ( { categorytitle=>"Content Settings for this $crstype",
 5995:         items => [
 5996:           { linktext => 'Portfolio Metadata',
 5997:             url => '/adm/parmset?action=setrestrictmeta',
 5998:             permission => $parm_permission->{'setrestrictmeta'},
 5999:             linktitle => "Restrict metadata for this $lc_crstype." ,
 6000:             icon =>'contact-new.png'   ,
 6001:             },
 6002:           { linktext => $linktext{'resettimes'},
 6003:             url => $url{'resettimes'},
 6004:             permission => ($vgr || $mgr),
 6005:             linktitle => $linktitle{'resettimes'},
 6006:             icon => 'start-here.png',
 6007:             },
 6008:           { linktext => 'Blocking Communication/Resource Access',
 6009:             url => '/adm/setblock',
 6010:             permission => ($vcb || $dcm),
 6011:             linktitle => 'Configure blocking of communication/collaboration and access to resources during an exam',
 6012:             icon => 'comblock.png',
 6013:             },
 6014:           { linktext => 'Set Parameter Setting Default Actions',
 6015:             url => '/adm/parmset?action=setdefaults',
 6016:             permission => $parm_permission->{'setdefaults'},
 6017:             linktitle =>'Set default actions for parameters.'  ,
 6018:             icon => 'folder-new.png'  ,
 6019:             }]},
 6020:       { categorytitle => 'New and Existing Parameter Settings for Resources',
 6021:         items => [
 6022:           { linktext => 'Edit Resource Parameters - Helper Mode',
 6023:             url => '/adm/helper/parameter.helper',
 6024:             permission => $parm_permission->{'helper'},
 6025:             linktitle =>'Set/Modify resource parameters in helper mode.'  ,
 6026:             icon => 'dialog-information.png'  ,
 6027:             #help => 'Parameter_Helper',
 6028:             },
 6029:           { linktext => $linktext{'newoverview'},
 6030:             url => '/adm/parmset?action=newoverview',
 6031:             permission => $parm_permission->{'newoverview'},
 6032:             linktitle => $linktitle{'newoverview'},
 6033:             icon => 'edit-find.png',
 6034:             #help => 'Parameter_Overview',
 6035:             },
 6036:           { linktext => $linktext{'settable'},
 6037:             url => '/adm/parmset?action=settable',
 6038:             permission => $parm_permission->{'settable'},
 6039:             linktitle => $linktitle{'settable'},
 6040:             icon => 'edit-copy.png',
 6041:             #help => 'Table_Mode',
 6042:             }]},
 6043:            { categorytitle => 'Existing Parameter Settings for Resources',
 6044:          items => [
 6045:           { linktext => $linktext{'setoverview'},
 6046:             url => '/adm/parmset?action=setoverview',
 6047:             permission => $parm_permission->{'setoverview'},
 6048:             linktitle => $linktitle{'setoverview'},
 6049:             icon => 'preferences-desktop-wallpaper.png',
 6050:             #help => 'Parameter_Overview',
 6051:             },
 6052:           { linktext => 'Change Log',
 6053:             url => '/adm/parmset?action=parameterchangelog',
 6054:             permission => $parm_permission->{'parameterchangelog'},
 6055:             linktitle =>"View parameter and $lc_crstype blog posting/user notification change log."  ,
 6056:             icon => 'document-properties.png',
 6057:             }]}
 6058:           );
 6059:     $r->print(&Apache::lonhtmlcommon::generate_menu(@menu));
 6060:     $r->print('</form>');
 6061:     &endSettingsScreen($r);
 6062:     $r->print(&Apache::loncommon::end_page());
 6063:     return;
 6064: }
 6065: 
 6066: 
 6067: 
 6068: ##################################################
 6069: # PORTFOLIO METADATA
 6070: ##################################################
 6071: 
 6072: # Prints HTML to edit an item of portfolio metadata. The HTML contains several td elements (no tr).
 6073: # It looks like field titles are not localized.
 6074: #
 6075: # @param {Apache2::RequestRec} $r - the Apache request
 6076: # @param {string} $field_name - metadata field name
 6077: # @param {string} $field_text - metadata field title, in English unless manually added
 6078: # @param {boolean} $added_flag - true if the field was manually added
 6079: sub output_row {
 6080:     my ($r, $field_name, $field_text, $added_flag) = @_;
 6081:     my $output;
 6082:     my $options=$env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.options'};
 6083:     my $values=$env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.values'};
 6084:     if (!defined($options)) {
 6085:         $options = 'active,stuadd';
 6086:         $values = '';
 6087:     }
 6088:     if (!($options =~ /deleted/)) {
 6089:         my @options= ( ['active', 'Show to student'],
 6090:                     ['stuadd', 'Provide text area for students to type metadata'],
 6091:                     ['choices','Provide choices for students to select from']);
 6092: #           ['onlyone','Student may select only one choice']);
 6093:         if ($added_flag) {
 6094:             push @options,['deleted', 'Delete Metadata Field'];
 6095:         }
 6096:        $output = &Apache::loncommon::start_data_table_row();
 6097:         $output .= '<td><strong>'.$field_text.':</strong></td>';
 6098:         $output .= &Apache::loncommon::end_data_table_row();
 6099:         foreach my $opt (@options) {
 6100:             my $checked = ($options =~ m/$opt->[0]/) ? ' checked="checked" ' : '' ;
 6101:             $output .= &Apache::loncommon::continue_data_table_row();
 6102:             $output .= '<td>'.('&nbsp;' x 5).'<label>
 6103:                     <input type="checkbox" name="'.
 6104:                     $field_name.'_'.$opt->[0].'" value="yes"'.$checked.' />'.
 6105:                     &mt($opt->[1]).'</label></td>';
 6106:             $output .= &Apache::loncommon::end_data_table_row();
 6107:         }
 6108:         $output .= &Apache::loncommon::continue_data_table_row();
 6109:         $output .= '<td>'.('&nbsp;' x 10).'<input name="'.$field_name.'_values" type="text" value="'.$values.'" size="80" /></td>';
 6110:         $output .= &Apache::loncommon::end_data_table_row();
 6111:         my $multiple_checked;
 6112:         my $single_checked;
 6113:         if ($options =~ m/onlyone/) {
 6114:             $multiple_checked = '';
 6115:             $single_checked = ' checked="checked"';
 6116:         } else {
 6117:             $multiple_checked = ' checked="checked"';
 6118:             $single_checked = '';
 6119:         }
 6120:         $output .= &Apache::loncommon::continue_data_table_row();
 6121:         $output .= '<td>'.('&nbsp;' x 10).'
 6122:                     <input type="radio" name="'.$field_name.'_onlyone" value="multiple"'.$multiple_checked .' />
 6123:                     '.&mt('Student may select multiple choices from list').'</td>';
 6124:         $output .= &Apache::loncommon::end_data_table_row();
 6125:         $output .= &Apache::loncommon::continue_data_table_row();
 6126:         $output .= '<td>'.('&nbsp;' x 10).'
 6127:                     <input type="radio" name="'.$field_name.'_onlyone"  value="single"'.$single_checked.' />
 6128:                     '.&mt('Student may select only one choice from list').'</td>';
 6129:         $output .= &Apache::loncommon::end_data_table_row();
 6130:     }
 6131:     return ($output);
 6132: }
 6133: 
 6134: 
 6135: # UI to order portfolio metadata fields.
 6136: # Currently useless because addmetafield does not work.
 6137: #
 6138: # @param {Apache2::RequestRec} $r - the Apache request
 6139: sub order_meta_fields {
 6140:     my ($r)=@_;
 6141:     my $idx = 1;
 6142:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 6143:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
 6144:     my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};;
 6145:     $r->print(&Apache::loncommon::start_page('Order Metadata Fields'));
 6146:     &Apache::lonhtmlcommon::add_breadcrumb(
 6147:         {href=>'/adm/parmset?action=addmetadata',
 6148:         text=>"Add Metadata Field"});
 6149:     &Apache::lonhtmlcommon::add_breadcrumb(
 6150:         {href=>"/adm/parmset?action=setrestrictmeta",
 6151:         text=>"Restrict Metadata"},
 6152:         {text=>"Order Metadata"});
 6153:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Order Metadata'));
 6154:     &startSettingsScreen($r,'parmset',$crstype);
 6155:     if ($env{'form.storeorder'}) {
 6156:         my $newpos = $env{'form.newpos'} - 1;
 6157:         my $currentpos = $env{'form.currentpos'} - 1;
 6158:         my @neworder = ();
 6159:         my @oldorder = split(/,/,$env{'course.'.$env{'request.course.id'}.'.metadata.addedorder'});
 6160:         my $i;
 6161:         if ($newpos > $currentpos) {
 6162:         # moving stuff up
 6163:             for ($i=0;$i<$currentpos;$i++) {
 6164:                 $neworder[$i]=$oldorder[$i];
 6165:             }
 6166:             for ($i=$currentpos;$i<$newpos;$i++) {
 6167:                 $neworder[$i]=$oldorder[$i+1];
 6168:             }
 6169:             $neworder[$newpos]=$oldorder[$currentpos];
 6170:             for ($i=$newpos+1;$i<=$#oldorder;$i++) {
 6171:                 $neworder[$i]=$oldorder[$i];
 6172:             }
 6173:         } else {
 6174:         # moving stuff down
 6175:             for ($i=0;$i<$newpos;$i++) {
 6176:                 $neworder[$i]=$oldorder[$i];
 6177:             }
 6178:             $neworder[$newpos]=$oldorder[$currentpos];
 6179:             for ($i=$newpos+1;$i<$currentpos+1;$i++) {
 6180:                 $neworder[$i]=$oldorder[$i-1];
 6181:             }
 6182:             for ($i=$currentpos+1;$i<=$#oldorder;$i++) {
 6183:                 $neworder[$i]=$oldorder[$i];
 6184:             }
 6185:         }
 6186:         my $ordered_fields = join ",", @neworder;
 6187:         my $put_result = &Apache::lonnet::put('environment',
 6188:                         {'metadata.addedorder'=>$ordered_fields},$dom,$crs);
 6189:         &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.metadata.addedorder' => $ordered_fields});
 6190:     }
 6191:     my $fields = &get_added_meta_fieldnames($env{'request.course.id'});
 6192:     my $ordered_fields;
 6193:     my @fields_in_order = split(/,/,$env{'course.'.$env{'request.course.id'}.'.metadata.addedorder'});
 6194:     if (!@fields_in_order) {
 6195:         # no order found, pick sorted order then create metadata.addedorder key.
 6196:         foreach my $key (sort(keys(%$fields))) {
 6197:             push @fields_in_order, $key;
 6198:             $ordered_fields = join ",", @fields_in_order;
 6199:         }
 6200:         my $put_result = &Apache::lonnet::put('environment',
 6201:                             {'metadata.addedorder'=>$ordered_fields},$dom,$crs);
 6202:     }
 6203:     $r->print('<table>');
 6204:     my $num_fields = scalar(@fields_in_order);
 6205:     foreach my $key (@fields_in_order) {
 6206:         $r->print('<tr><td>');
 6207:         $r->print('<form method="post" action="">');
 6208:         $r->print('<select name="newpos" onchange="this.form.submit()">');
 6209:         for (my $i = 1;$i le $num_fields;$i ++) {
 6210:             if ($i eq $idx) {
 6211:                 $r->print('<option value="'.$i.'"  SELECTED>('.$i.')</option>');
 6212:             } else {
 6213:                 $r->print('<option value="'.$i.'">'.$i.'</option>');
 6214:             }
 6215:         }
 6216:         $r->print('</select></td><td>');
 6217:         $r->print('<input type="hidden" name="currentpos" value="'.$idx.'" />');
 6218:         $r->print('<input type="hidden" name="storeorder" value="true" />');
 6219:         $r->print('</form>');
 6220:         $r->print($$fields{$key}.'</td></tr>');
 6221:         $idx ++;
 6222:     }
 6223:     $r->print('</table>');
 6224:     &endSettingsScreen($r);
 6225:     return 'ok';
 6226: }
 6227: 
 6228: 
 6229: # Returns HTML with a Continue button redirecting to the initial portfolio metadata screen.
 6230: # @returns {string}
 6231: sub continue {
 6232:     my $output;
 6233:     $output .= '<form action="" method="post">';
 6234:     $output .= '<input type="hidden" name="action" value="setrestrictmeta" />';
 6235:     $output .= '<input type="submit" value="'.&mt('Continue').'" />';
 6236:     return ($output);
 6237: }
 6238: 
 6239: 
 6240: # UI to add a metadata field.
 6241: # Currenly does not work because of an HTML error (the field is not visible).
 6242: #
 6243: # @param {Apache2::RequestRec} $r - the Apache request
 6244: sub addmetafield {
 6245:     my ($r)=@_;
 6246:     &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=addmetadata',
 6247:         text=>"Add Metadata Field"});
 6248:     $r->print(&Apache::loncommon::start_page('Add Metadata Field'));
 6249:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Add Metadata Field'));
 6250:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 6251:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
 6252:     my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
 6253:     &startSettingsScreen($r,'parmset',$crstype);
 6254:     if (exists($env{'form.undelete'})) {
 6255:         my @meta_fields = &Apache::loncommon::get_env_multiple('form.undeletefield');
 6256:         foreach my $meta_field(@meta_fields) {
 6257:             my $options = $env{'course.'.$env{'request.course.id'}.'.metadata.'.$meta_field.'.options'};
 6258:             $options =~ s/deleted//;
 6259:             $options =~ s/,,/,/;
 6260:             my $put_result = &Apache::lonnet::put('environment',
 6261:                                         {'metadata.'.$meta_field.'.options'=>$options},$dom,$crs);
 6262: 
 6263:             $r->print(&mt('Undeleted Metadata Field [_1] with result [_2]',
 6264:                           '<strong>'.$env{'course.'.$env{'request.course.id'}.'.metadata.'.$meta_field.'.added'}.
 6265:                           '</strong>',$put_result).
 6266:                       '<br />');
 6267:         }
 6268:         $r->print(&continue());
 6269:     } elsif (exists($env{'form.fieldname'})) {
 6270:         my $meta_field = $env{'form.fieldname'};
 6271:         my $display_field = $env{'form.fieldname'};
 6272:         $meta_field =~ s/\W/_/g;
 6273:         $meta_field =~ tr/A-Z/a-z/;
 6274:         my $put_result = &Apache::lonnet::put('environment',
 6275:                             {'metadata.'.$meta_field.'.values'=>"",
 6276:                              'metadata.'.$meta_field.'.added'=>"$display_field",
 6277:                              'metadata.'.$meta_field.'.options'=>""},$dom,$crs);
 6278:         $r->print(&mt('Added new Metadata Field [_1] with result [_2]',
 6279:                       '<strong>'.$env{'form.fieldname'}.'</strong>',$put_result).
 6280:                   '<br />');
 6281:         $r->print(&continue());
 6282:     } else {
 6283:         my $fields = &get_deleted_meta_fieldnames($env{'request.course.id'});
 6284:         if ($fields) {
 6285:             $r->print(&mt('You may undelete previously deleted fields.').
 6286:                       '<br />'.
 6287:                       &mt('Check those you wish to undelete and click Undelete.').
 6288:                       '<br />');
 6289:             $r->print('<form method="post" action="">');
 6290:             foreach my $key(keys(%$fields)) {
 6291:                 $r->print('<label><input type="checkbox" name="undeletefield" value="'.$key.'" />'.$$fields{$key}.'</label><br /');
 6292:             }
 6293:             $r->print('<input type="submit" name="undelete" value="'.&mt('Undelete').'" />');
 6294:             $r->print('</form>');
 6295:         }
 6296:         $r->print('<hr />'.
 6297:                   &mt('[_1]Or[_2] you may enter a new metadata field name.',
 6298:                       '<strong>','</strong>').
 6299:                   '<form method="post" action="/adm/parmset?action=addmetadata">');
 6300:         $r->print('<input type="text" name="fieldname" /><br />');
 6301:         $r->print('<input type="submit" value="'.&mt('Add Metadata Field').'" />');
 6302:         $r->print('</form>');
 6303:     }
 6304:     &endSettingsScreen($r);
 6305: }
 6306: 
 6307: 
 6308: 
 6309: # Display or save portfolio metadata.
 6310: #
 6311: # @param {Apache2::RequestRec} $r - the Apache request
 6312: sub setrestrictmeta {
 6313:     my ($r)=@_;
 6314:     my $next_meta;
 6315:     my $output;
 6316:     my $item_num;
 6317:     my $put_result;
 6318:     &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setrestrictmeta',
 6319:         text=>"Restrict Metadata"});
 6320:     $r->print(&Apache::loncommon::start_page('Restrict Metadata'));
 6321:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Restrict Metadata'));
 6322:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 6323:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
 6324:     my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
 6325:     &startSettingsScreen($r,'parmset',$crstype);
 6326:     my $key_base = $env{'course.'.$env{'request.course.id'}.'.'};
 6327:     my $save_field = '';
 6328:     my %lt = &Apache::lonlocal::texthash(
 6329:                                            addm => 'Add Metadata Field',
 6330:                                            ordm => 'Order Metadata Fields',
 6331:                                            save => 'Save',
 6332:                                         );
 6333:     if ($env{'form.restrictmeta'}) {
 6334:         foreach my $field (sort(keys(%env))) {
 6335:             if ($field=~m/^form.(.+)_(.+)$/) {
 6336:                 my $options;
 6337:                 my $meta_field = $1;
 6338:                 my $meta_key = $2;
 6339:                 if ($save_field ne $meta_field) {
 6340:                     $save_field = $meta_field;
 6341:                     if ($env{'form.'.$meta_field.'_stuadd'}) {
 6342:                         $options.='stuadd,';
 6343:                     }
 6344:                     if ($env{'form.'.$meta_field.'_choices'}) {
 6345:                         $options.='choices,';
 6346:                     }
 6347:                     if ($env{'form.'.$meta_field.'_onlyone'} eq 'single') {
 6348:                         $options.='onlyone,';
 6349:                     }
 6350:                     if ($env{'form.'.$meta_field.'_active'}) {
 6351:                         $options.='active,';
 6352:                     }
 6353:                     if ($env{'form.'.$meta_field.'_deleted'}) {
 6354:                         $options.='deleted,';
 6355:                     }
 6356:                     my $name = $save_field;
 6357:                     $put_result = &Apache::lonnet::put('environment',
 6358:                         {'metadata.'.$meta_field.'.options'=>$options,
 6359:                         'metadata.'.$meta_field.'.values'=>$env{'form.'.$meta_field.'_values'},
 6360:                         },$dom,$crs);
 6361:                 }
 6362:             }
 6363:         }
 6364:     }
 6365:     &Apache::lonnet::coursedescription($env{'request.course.id'},
 6366:                        {'freshen_cache' => 1});
 6367:     # Get the default metadata fields
 6368:     my %metadata_fields = &Apache::lonmeta::fieldnames('portfolio');
 6369:     # Now get possible added metadata fields
 6370:     my $added_metadata_fields = &get_added_meta_fieldnames($env{'request.course.id'});
 6371:     $output .= &Apache::loncommon::start_data_table();
 6372:     foreach my $field (sort(keys(%metadata_fields))) {
 6373:         if ($field ne 'courserestricted') {
 6374:             $output.= &output_row($r,$field,$metadata_fields{$field});
 6375:         }
 6376:     }
 6377:     my $buttons = (<<ENDButtons);
 6378:         <input type="submit" name="restrictmeta" value="$lt{'save'}" />
 6379:         </form><br />
 6380:         <form method="post" action="/adm/parmset?action=addmetadata" name="form1">
 6381:         <input type="submit" name="restrictmeta" value="$lt{'addm'}" />
 6382:         </form>
 6383:         <br />
 6384:         <form method="post" action="/adm/parmset?action=ordermetadata" name="form2">
 6385:         <input type="submit" name="restrictmeta" value="$lt{'ordm'}" />
 6386: ENDButtons
 6387:     my $added_flag = 1;
 6388:     foreach my $field (sort(keys(%$added_metadata_fields))) {
 6389:         $output.= &output_row($r,$field,$$added_metadata_fields{$field},$added_flag);
 6390:     }
 6391:     $output .= &Apache::loncommon::end_data_table();
 6392:     $r->print(<<ENDenv);
 6393:         <form method="post" action="/adm/parmset?action=setrestrictmeta" name="form">
 6394:         $output
 6395:         $buttons
 6396:         </form>
 6397: ENDenv
 6398:     &endSettingsScreen($r);
 6399:     $r->print(&Apache::loncommon::end_page());
 6400:     return 'ok';
 6401: }
 6402: 
 6403: 
 6404: # Returns metadata fields that have been manually added.
 6405: #
 6406: # @param {string} $cid - course id
 6407: # @returns {hash reference} - hash field name -> field title (not localized)
 6408: sub get_added_meta_fieldnames {
 6409:     my ($cid) = @_;
 6410:     my %fields;
 6411:     foreach my $key(%env) {
 6412:         if ($key =~ m/\Q$cid\E\.metadata\.(.+)\.added$/) {
 6413:             my $field_name = $1;
 6414:             my ($display_field_name) = $env{$key};
 6415:             $fields{$field_name} = $display_field_name;
 6416:         }
 6417:     }
 6418:     return \%fields;
 6419: }
 6420: 
 6421: 
 6422: # Returns metadata fields that have been manually added and deleted.
 6423: #
 6424: # @param {string} $cid - course id
 6425: # @returns {hash reference} - hash field name -> field title (not localized)
 6426: sub get_deleted_meta_fieldnames {
 6427:     my ($cid) = @_;
 6428:     my %fields;
 6429:     foreach my $key(%env) {
 6430:         if ($key =~ m/\Q$cid\E\.metadata\.(.+)\.added$/) {
 6431:             my $field_name = $1;
 6432:             if ($env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.options'} =~ m/deleted/) {
 6433:                 my ($display_field_name) = $env{$key};
 6434:                 $fields{$field_name} = $display_field_name;
 6435:             }
 6436:         }
 6437:     }
 6438:     return \%fields;
 6439: }
 6440: 
 6441: 
 6442: ##################################################
 6443: # PARAMETER SETTINGS DEFAULT ACTIONS
 6444: ##################################################
 6445: 
 6446: # UI to change parameter setting default actions
 6447: #
 6448: # @param {Apache2::RequestRec} $r - the Apache request
 6449: sub defaultsetter {
 6450:     my ($r) = @_;
 6451: 
 6452:     &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setdefaults',
 6453:         text=>"Set Defaults"});
 6454:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 6455:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 6456:     my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
 6457:     my $start_page =
 6458:         &Apache::loncommon::start_page('Parameter Setting Default Actions');
 6459:     my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Defaults');
 6460:     $r->print($start_page.$breadcrumbs);
 6461:     &startSettingsScreen($r,'parmset',$crstype);
 6462:     $r->print('<form method="post" action="/adm/parmset?action=setdefaults" name="defaultform">');
 6463: 
 6464:     my @ids=();
 6465:     my %typep=();
 6466:     my %keyp=();
 6467:     my %allparms=();
 6468:     my %allparts=();
 6469:     my %allmaps=();
 6470:     my %mapp=();
 6471:     my %symbp=();
 6472:     my %maptitles=();
 6473:     my %uris=();
 6474:     my %keyorder=&standardkeyorder();
 6475:     my %defkeytype=();
 6476: 
 6477:     &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allmaps,
 6478:                 \%mapp, \%symbp,\%maptitles,\%uris,
 6479:                 \%keyorder,\%defkeytype);
 6480:     if ($env{'form.storerules'}) {
 6481:         my %newrules=();
 6482:         my @delrules=();
 6483:         my %triggers=();
 6484:         foreach my $key (keys(%env)) {
 6485:             if ($key=~/^form\.(\w+)\_action$/) {
 6486:                 my $tempkey=$1;
 6487:                 my $action=$env{$key};
 6488:                 if ($action) {
 6489:                     $newrules{$tempkey.'_action'}=$action;
 6490:                     if ($action ne 'default') {
 6491:                         my ($whichaction,$whichparm)=($action=~/^(.*\_)([^\_]+)$/);
 6492:                         $triggers{$whichparm}.=$tempkey.':';
 6493:                     }
 6494:                     $newrules{$tempkey.'_type'}=$defkeytype{$tempkey};
 6495:                     if (&isdateparm($defkeytype{$tempkey})) {
 6496:                         $newrules{$tempkey.'_days'}=$env{'form.'.$tempkey.'_days'};
 6497:                         $newrules{$tempkey.'_hours'}=$env{'form.'.$tempkey.'_hours'};
 6498:                         $newrules{$tempkey.'_min'}=$env{'form.'.$tempkey.'_min'};
 6499:                         $newrules{$tempkey.'_sec'}=$env{'form.'.$tempkey.'_sec'};
 6500:                     } else {
 6501:                         $newrules{$tempkey.'_value'}=$env{'form.'.$tempkey.'_value'};
 6502:                         $newrules{$tempkey.'_triggervalue'}=$env{'form.'.$tempkey.'_triggervalue'};
 6503:                     }
 6504:                 } else {
 6505:                     push(@delrules,$tempkey.'_action');
 6506:                     push(@delrules,$tempkey.'_type');
 6507:                     push(@delrules,$tempkey.'_hours');
 6508:                     push(@delrules,$tempkey.'_min');
 6509:                     push(@delrules,$tempkey.'_sec');
 6510:                     push(@delrules,$tempkey.'_value');
 6511:                 }
 6512:             }
 6513:         }
 6514:         foreach my $key (keys(%allparms)) {
 6515:             $newrules{$key.'_triggers'}=$triggers{$key};
 6516:         }
 6517:         &Apache::lonnet::put('parmdefactions',\%newrules,$cdom,$cnum);
 6518:         &Apache::lonnet::del('parmdefactions',\@delrules,$cdom,$cnum);
 6519:         &resetrulescache();
 6520:     }
 6521:     my %lt=&Apache::lonlocal::texthash('days' => 'Days',
 6522:                        'hours' => 'Hours',
 6523:                        'min' => 'Minutes',
 6524:                        'sec' => 'Seconds',
 6525:                        'yes' => 'Yes',
 6526:                        'no' => 'No');
 6527:     my @standardoptions=('','default');
 6528:     my @standarddisplay=('',&mt('Default value when manually setting'));
 6529:     my @dateoptions=('','default');
 6530:     my @datedisplay=('',&mt('Default value when manually setting'));
 6531:     foreach my $tempkey (&keysindisplayorder(\%allparms,\%keyorder)) {
 6532:         unless ($tempkey) { next; }
 6533:         push @standardoptions,'when_setting_'.$tempkey;
 6534:         push @standarddisplay,&mt('Automatically set when setting ').$tempkey;
 6535:         if (&isdateparm($defkeytype{$tempkey})) {
 6536:             push @dateoptions,'later_than_'.$tempkey;
 6537:             push @datedisplay,&mt('Automatically set later than ').$tempkey;
 6538:             push @dateoptions,'earlier_than_'.$tempkey;
 6539:             push @datedisplay,&mt('Automatically set earlier than ').$tempkey;
 6540:         }
 6541:     }
 6542:     $r->print(&mt('Manual setting rules apply to all interfaces.').'<br />'.
 6543:         &mt('Automatic setting rules apply to table mode interfaces only.'));
 6544:     $r->print("\n".&Apache::loncommon::start_data_table().
 6545:           &Apache::loncommon::start_data_table_header_row().
 6546:           "<th>".&mt('Rule for parameter').'</th><th>'.
 6547:           &mt('Action').'</th><th>'.&mt('Value').'</th>'.
 6548:           &Apache::loncommon::end_data_table_header_row());
 6549:     foreach my $tempkey (&keysindisplayorder(\%allparms,\%keyorder)) {
 6550:         unless ($tempkey) { next; }
 6551:         $r->print("\n".&Apache::loncommon::start_data_table_row().
 6552:             "<td>".$allparms{$tempkey}."\n<br />(".$tempkey.')</td><td>');
 6553:         my $action=&rulescache($tempkey.'_action');
 6554:         $r->print('<select name="'.$tempkey.'_action">');
 6555:         if (&isdateparm($defkeytype{$tempkey})) {
 6556:             for (my $i=0;$i<=$#dateoptions;$i++) {
 6557:             if ($dateoptions[$i]=~/\_$tempkey$/) { next; }
 6558:             $r->print("\n<option value='$dateoptions[$i]'".
 6559:                 ($dateoptions[$i] eq $action?' selected="selected"':'').
 6560:                 ">$datedisplay[$i]</option>");
 6561:             }
 6562:         } else {
 6563:             for (my $i=0;$i<=$#standardoptions;$i++) {
 6564:             if ($standardoptions[$i]=~/\_$tempkey$/) { next; }
 6565:             $r->print("\n<option value='$standardoptions[$i]'".
 6566:                 ($standardoptions[$i] eq $action?' selected="selected"':'').
 6567:                 ">$standarddisplay[$i]</option>");
 6568:             }
 6569:         }
 6570:         $r->print('</select>');
 6571:         unless (&isdateparm($defkeytype{$tempkey})) {
 6572:             $r->print("\n<br />".&mt('Triggering value(s) of other parameter (optional, comma-separated):').
 6573:                 '<input type="text" size="20" name="'.$tempkey.'_triggervalue" value="'.&rulescache($tempkey.'_triggervalue').'" />');
 6574:         }
 6575:         $r->print("\n</td><td>\n");
 6576: 
 6577:         if (&isdateparm($defkeytype{$tempkey})) {
 6578:             my $days=&rulescache($tempkey.'_days');
 6579:             my $hours=&rulescache($tempkey.'_hours');
 6580:             my $min=&rulescache($tempkey.'_min');
 6581:             my $sec=&rulescache($tempkey.'_sec');
 6582:             $r->print(<<ENDINPUTDATE);
 6583:     <input name="$tempkey\_days" type="text" size="4" value="$days" />$lt{'days'}<br />
 6584:     <input name="$tempkey\_hours" type="text" size="4" value="$hours" />$lt{'hours'}<br />
 6585:     <input name="$tempkey\_min" type="text" size="4" value="$min" />$lt{'min'}<br />
 6586:     <input name="$tempkey\_sec" type="text" size="4" value="$sec" />$lt{'sec'}
 6587: ENDINPUTDATE
 6588:         } elsif ($defkeytype{$tempkey} eq 'string_yesno') {
 6589:                 my $yeschecked='';
 6590:                 my $nochecked='';
 6591:                 if (&rulescache($tempkey.'_value') eq 'yes') { $yeschecked=' checked="checked"'; }
 6592:                 if (&rulescache($tempkey.'_value') eq 'no') { $nochecked=' checked="checked"'; }
 6593: 
 6594:             $r->print(<<ENDYESNO);
 6595:     <label><input type="radio" name="$tempkey\_value" value="yes"$yeschecked /> $lt{'yes'}</label><br />
 6596:     <label><input type="radio" name="$tempkey\_value" value="no"$nochecked /> $lt{'no'}</label>
 6597: ENDYESNO
 6598:         } else {
 6599:             $r->print('<input type="text" size="20" name="'.$tempkey.'_value" value="'.&rulescache($tempkey.'_value').'" />');
 6600:         }
 6601:         $r->print('</td>'.&Apache::loncommon::end_data_table_row());
 6602:     }
 6603:     $r->print(&Apache::loncommon::end_data_table().
 6604:           "\n".'<input type="submit" name="storerules" value="'.
 6605:           &mt('Save').'" /></form>'."\n");
 6606:     &endSettingsScreen($r);
 6607:     $r->print(&Apache::loncommon::end_page());
 6608:     return;
 6609: }
 6610: 
 6611: ##################################################
 6612: # PARAMETER CHANGES LOG
 6613: ##################################################
 6614: 
 6615: # Returns some info for a parameter log entry.
 6616: # Returned entries:
 6617: # $realm - HTML title for the parameter level and resource
 6618: # $section - parameter section
 6619: # $name - parameter name
 6620: # $part - parameter part
 6621: # $what - $part.'.'.$name
 6622: # $middle - resource symb ?
 6623: # $uname - user name (same as given)
 6624: # $udom - user domain (same as given)
 6625: # $issection - section or group name
 6626: # $realmdescription - title for the parameter level and resource (without using HTML)
 6627: #
 6628: # @param {string} $key - parameter log key
 6629: # @param {string} $uname - user name
 6630: # @param {string} $udom - user domain
 6631: # @param {boolean} $typeflag - .type log entry
 6632: # @returns {Array}
 6633: sub components {
 6634:     my ($key,$uname,$udom,$typeflag)=@_;
 6635: 
 6636:     if ($typeflag) {
 6637:         $key=~s/\.type$//;
 6638:     }
 6639: 
 6640:     my ($middle,$part,$name)=
 6641:         ($key=~/^$env{'request.course.id'}\.(?:(.+)\.)*([\w\s\-]+)\.(\w+)$/);
 6642:     my $issection;
 6643: 
 6644:     my $section=&mt('All Students');
 6645:     if ($middle=~/^\[(.*)\]/) {
 6646:         $issection=$1;
 6647:         $section=&mt('Group/Section').': '.$issection;
 6648:         $middle=~s/^\[(.*)\]//;
 6649:     }
 6650:     $middle=~s/\.+$//;
 6651:     $middle=~s/^\.+//;
 6652:     if ($uname) {
 6653:         $section=&mt('User').": ".&Apache::loncommon::plainname($uname,$udom);
 6654:         $issection='';
 6655:     }
 6656:     my $realm='<span class="LC_parm_scope_all">'.&mt('All Resources').'</span>';
 6657:     my $realmdescription=&mt('all resources');
 6658:     if ($middle=~/^(.+)\_\_\_\((all|rec)\)$/) {
 6659:         my $mapurl = $1;
 6660:         my $maplevel = $2;
 6661:         my $leveltitle = &mt('Folder/Map');
 6662:         if ($maplevel eq 'rec') {
 6663:             $leveltitle = &mt('Recursive');
 6664:         }
 6665:         $realm='<span class="LC_parm_scope_folder">'.$leveltitle.
 6666:             ': '.&Apache::lonnet::gettitle($mapurl).' <span class="LC_parm_folder"><br />('.
 6667:             $mapurl.')</span></span>';
 6668:         $realmdescription=&mt('folder').' '.&Apache::lonnet::gettitle($mapurl);
 6669:     } elsif ($middle) {
 6670:         my ($map,$id,$url)=&Apache::lonnet::decode_symb($middle);
 6671:         $realm='<span class="LC_parm_scope_resource">'.&mt('Resource').
 6672:             ': '.&Apache::lonnet::gettitle($middle).' <br /><span class="LC_parm_symb">('.$url.
 6673:             ' in '.$map.' id: '.$id.')</span></span>';
 6674:         $realmdescription=&mt('resource').' '.&Apache::lonnet::gettitle($middle);
 6675:     }
 6676:     my $what=$part.'.'.$name;
 6677:     return ($realm,$section,$name,$part,
 6678:         $what,$middle,$uname,$udom,$issection,$realmdescription);
 6679: }
 6680: 
 6681: my %standard_parms; # hash parameter name -> parameter title (not localized)
 6682: my %standard_parms_types; # hash parameter name -> parameter type
 6683: 
 6684: # Reads parameter info from packages.tab into %standard_parms.
 6685: sub load_parameter_names {
 6686:     open(my $config,"<","$Apache::lonnet::perlvar{'lonTabDir'}/packages.tab");
 6687:     while (my $configline=<$config>) {
 6688:         if ($configline !~ /\S/ || $configline=~/^\#/) { next; }
 6689:         chomp($configline);
 6690:         my ($short,$plain)=split(/:/,$configline);
 6691:         my (undef,$name,$type)=split(/\&/,$short,3);
 6692:         if ($type eq 'display') {
 6693:             $standard_parms{$name} = $plain;
 6694:         } elsif ($type eq 'type') {
 6695:                 $standard_parms_types{$name} = $plain;
 6696:         }
 6697:     }
 6698:     close($config);
 6699:     $standard_parms{'int_pos'}      = 'Positive Integer';
 6700:     $standard_parms{'int_zero_pos'} = 'Positive Integer or Zero';
 6701:     $standard_parms{'scoreformat'}  = 'Format for display of score';
 6702: }
 6703: 
 6704: # Returns a parameter title for standard parameters, the name for others.
 6705: #
 6706: # @param {string} $name - parameter name
 6707: # @returns {string}
 6708: sub standard_parameter_names {
 6709:     my ($name)=@_;
 6710:     if (!%standard_parms) {
 6711:         &load_parameter_names();
 6712:     }
 6713:     if ($standard_parms{$name}) {
 6714:         return $standard_parms{$name};
 6715:     } else {
 6716:         return $name;
 6717:     }
 6718: }
 6719: 
 6720: # Returns a parameter type for standard parameters, undef for others.
 6721: #
 6722: # @param {string} $name - parameter name
 6723: # @returns {string}
 6724: sub standard_parameter_types {
 6725:     my ($name)=@_;
 6726:     if (!%standard_parms_types) {
 6727:         &load_parameter_names();
 6728:     }
 6729:     if ($standard_parms_types{$name}) {
 6730:         return $standard_parms_types{$name};
 6731:     }
 6732:     return;
 6733: }
 6734: 
 6735: # Returns a parameter level title (not localized) from the parameter level name.
 6736: #
 6737: # @param {string} $name - parameter level name (recognized: resourcelevel|maplevel|maplevelrecurse|courselevel)
 6738: # @returns {string}
 6739: sub standard_parameter_levels {
 6740:     my ($name)=@_;
 6741:     my %levels = (
 6742:                     'resourcelevel'   => 'a single resource',
 6743:                     'maplevel'        => 'the enclosing map/folder', 
 6744:                     'maplevelrecurse' => 'the enclosing map/folder (recursive into sub-folders)',
 6745:                     'courselevel'     => 'the general (course) level',
 6746:                  );
 6747:     if ($levels{$name}) {
 6748:         return $levels{$name};
 6749:     }
 6750:     return;
 6751: }
 6752: 
 6753: # Display log for parameter changes, blog postings, user notification changes.
 6754: #
 6755: # @param {Apache2::RequestRec} $r - the Apache request
 6756: sub parm_change_log {
 6757:     my ($r,$parm_permission)=@_;
 6758:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 6759:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 6760:     my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
 6761:     &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=settable',
 6762:     text=>"Parameter Change Log"});
 6763:     my $js = '<script type="text/javascript">'."\n".
 6764:              '// <![CDATA['."\n".
 6765:              &Apache::loncommon::display_filter_js('parmslog')."\n".
 6766:              '// ]]>'."\n".
 6767:              '</script>'."\n";
 6768:     $r->print(&Apache::loncommon::start_page('Parameter Change Log',$js));
 6769:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Parameter Change Log'));
 6770:     &startSettingsScreen($r,'parmset',$crstype);
 6771:     my %parmlog=&Apache::lonnet::dump('nohist_parameterlog',$cdom,$cnum);
 6772: 
 6773:     if ((keys(%parmlog))[0]=~/^error\:/) { undef(%parmlog); }
 6774: 
 6775:     $r->print('<div class="LC_left_float">'.
 6776:               '<fieldset><legend>'.&mt('Display of Changes').'</legend>'.
 6777:               '<form action="/adm/parmset?action=parameterchangelog"
 6778:                      method="post" name="parameterlog">');
 6779: 
 6780:     my %saveable_parameters = ('show' => 'scalar',);
 6781:     &Apache::loncommon::store_course_settings('parameter_log',
 6782:                                               \%saveable_parameters);
 6783:     &Apache::loncommon::restore_course_settings('parameter_log',
 6784:                                                 \%saveable_parameters);
 6785:     $r->print(&Apache::loncommon::display_filter('parmslog').'&nbsp;'."\n".
 6786:               '<input type="submit" value="'.&mt('Display').'" />'.
 6787:               '</form></fieldset></div><br clear="all" />');
 6788: 
 6789:     my $readonly = 1;
 6790:     if ($parm_permission->{'edit'}) {
 6791:         undef($readonly);
 6792:     }
 6793:     my $courseopt=&Apache::lonnet::get_courseresdata($cnum,$cdom);
 6794:     $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
 6795:           '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Extent').'</th><th>'.&mt('Users').'</th><th>'.
 6796:           &mt('Parameter').'</th><th>'.&mt('Part').'</th><th>'.&mt('New Value').'</th>');
 6797:     unless ($readonly) {
 6798:         $r->print('<th>'.&mt('Announce').'</th>');
 6799:     }
 6800:     $r->print(&Apache::loncommon::end_data_table_header_row());
 6801:     my $shown=0;
 6802:     my $folder='';
 6803:     if ($env{'form.displayfilter'} eq 'currentfolder') {
 6804:         my $last='';
 6805:         if (tie(my %hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
 6806:                 &GDBM_READER(),0640)) {
 6807:             $last=$hash{'last_known'};
 6808:             untie(%hash);
 6809:         }
 6810:         if ($last) { ($folder) = &Apache::lonnet::decode_symb($last); }
 6811:     }
 6812:     foreach my $id (sort {
 6813:                 if ($parmlog{$b}{'exe_time'} ne $parmlog{$a}{'exe_time'}) {
 6814:                     return $parmlog{$b}{'exe_time'} <=>$parmlog{$a}{'exe_time'}
 6815:                 }
 6816:                 my $aid = (split('00000',$a))[-1];
 6817:                 my $bid = (split('00000',$b))[-1];
 6818:                 return $bid<=>$aid;
 6819:             } (keys(%parmlog))) {
 6820:         my @changes=keys(%{$parmlog{$id}{'logentry'}});
 6821:         my $count = 0;
 6822:         my $time =
 6823:             &Apache::lonlocal::locallocaltime($parmlog{$id}{'exe_time'});
 6824:         my $plainname =
 6825:             &Apache::loncommon::plainname($parmlog{$id}{'exe_uname'},
 6826:                         $parmlog{$id}{'exe_udom'});
 6827:         my $about_me_link =
 6828:             &Apache::loncommon::aboutmewrapper($plainname,
 6829:                             $parmlog{$id}{'exe_uname'},
 6830:                             $parmlog{$id}{'exe_udom'});
 6831:         my $send_msg_link='';
 6832:         if ((!$readonly) && 
 6833:             (($parmlog{$id}{'exe_uname'} ne $env{'user.name'})
 6834:             || ($parmlog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
 6835:             $send_msg_link ='<br />'.
 6836:             &Apache::loncommon::messagewrapper(&mt('Send message'),
 6837:                             $parmlog{$id}{'exe_uname'},
 6838:                             $parmlog{$id}{'exe_udom'});
 6839:         }
 6840:         my $row_start=&Apache::loncommon::start_data_table_row();
 6841:         my $makenewrow=0;
 6842:         my %istype=();
 6843:         my $output;
 6844:         foreach my $changed (reverse(sort(@changes))) {
 6845:                 my $value=$parmlog{$id}{'logentry'}{$changed};
 6846:             my $typeflag = ($changed =~/\.type$/ &&
 6847:                     !exists($parmlog{$id}{'logentry'}{$changed.'.type'}));
 6848:             my ($realm,$section,$parmname,$part,$what,$middle,$uname,$udom,$issection,$realmdescription)=
 6849:                 &components($changed,$parmlog{$id}{'uname'},$parmlog{$id}{'udom'},$typeflag);
 6850:             if ($env{'request.course.sec'} ne '') {
 6851:                 next if (($issection ne '') && ($issection ne $env{'request.course.sec'}));
 6852:                 if ($uname ne '') {
 6853:                     my $stusection = &Apache::lonnet::getsection($uname,$udom,$env{'request.course.id'});
 6854:                     next if (($stusection ne '-1') && ($stusection ne $env{'request.course.sec'})); 
 6855:                 }
 6856:             }
 6857:             if ($env{'form.displayfilter'} eq 'currentfolder') {
 6858:                 if ($folder) {
 6859:                     if ($middle!~/^\Q$folder\E/) { next; }
 6860:                 }
 6861:             }
 6862:             if ($typeflag) {
 6863:                 $istype{$parmname}=$value;
 6864:                 if (!$env{'form.includetypes'}) { next; }
 6865:             }
 6866:             $count++;
 6867:             if ($makenewrow) {
 6868:                 $output .= $row_start;
 6869:             } else {
 6870:                 $makenewrow=1;
 6871:             }
 6872:             my $parmitem = &standard_parameter_names($parmname);
 6873:             $output .='<td>'.$realm.'</td><td>'.$section.'</td><td>'.
 6874:                 &mt($parmitem).'</td><td>'.
 6875:                 ($part?&mt('Part: [_1]',$part):&mt('All Parts')).'</td><td>';
 6876:             my $stillactive=0;
 6877:             if ($parmlog{$id}{'delflag'}) {
 6878:                 $output .= &mt('Deleted');
 6879:             } else {
 6880:                 if ($typeflag) {
 6881:                     my $parmitem = &standard_parameter_names($value); 
 6882:                     $parmitem = &mt($parmitem);
 6883:                     $output .= &mt('Type: [_1]',$parmitem);
 6884:                 } else {
 6885:                     my $toolsymb;
 6886:                     if ($middle =~ /ext\.tool$/) {
 6887:                         $toolsymb = $middle;
 6888:                     }
 6889:                     my ($level,@all)=&parmval_by_symb($what,$middle,
 6890:                         &Apache::lonnet::metadata($middle,$what,$toolsymb),
 6891:                         $uname,$udom,$issection,$issection,$courseopt);
 6892:                     my $showvalue = $value;
 6893:                     if ($istype{$parmname} eq '') {
 6894:                         my $type = &standard_parameter_types($parmname);
 6895:                         if ($type ne '') {
 6896:                             if (&isdateparm($type)) {
 6897:                                 $showvalue =
 6898:                                     &Apache::lonlocal::locallocaltime($value);
 6899:                             }
 6900:                         }
 6901:                     } else {
 6902:                         if (&isdateparm($istype{$parmname})) {
 6903:                             $showvalue = &Apache::lonlocal::locallocaltime($value);
 6904:                         }
 6905:                     }
 6906:                     $output .= $showvalue;
 6907:                     if ($value ne $all[$level]) {
 6908:                         $output .= '<br /><span class="LC_warning">'.&mt('Not active anymore').'</span>';
 6909:                     } else {
 6910:                         $stillactive=1;
 6911:                     }
 6912:                 }
 6913:             }
 6914:             $output .= '</td>';
 6915: 
 6916:             unless ($readonly) { 
 6917:                 $output .= '<td>';
 6918:                 if ($stillactive) {
 6919:                     my $parmitem = &standard_parameter_names($parmname);
 6920:                     $parmitem = &mt($parmitem);
 6921:                     my $title=&mt('Changed [_1]',$parmitem);
 6922:                     my $description=&mt('Changed [_1] for [_2] to [_3]',
 6923:                         $parmitem,$realmdescription,
 6924:                         (&isdateparm($istype{$parmname})?&Apache::lonlocal::locallocaltime($value):$value));
 6925:                     if (($uname) && ($udom)) {
 6926:                         $output .=
 6927:                         &Apache::loncommon::messagewrapper('Notify User',
 6928:                                                            $uname,$udom,$title,
 6929:                                                            $description);
 6930:                     } else {
 6931:                         $output .=
 6932:                             &Apache::lonrss::course_blog_link($id,$title,
 6933:                                                               $description);
 6934:                     }
 6935:                 }
 6936:                 $output .= '</td>';
 6937:             }
 6938:             $output .= &Apache::loncommon::end_data_table_row();
 6939:         }
 6940:         if ($env{'form.displayfilter'} eq 'containing') {
 6941:             my $wholeentry=$about_me_link.':'.
 6942:             $parmlog{$id}{'exe_uname'}.':'.$parmlog{$id}{'exe_udom'}.':'.
 6943:             $output;
 6944:             if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
 6945:         }
 6946:         if ($count) {
 6947:             $r->print($row_start.'<td rowspan="'.$count.'">'.$time.'</td>
 6948:                         <td rowspan="'.$count.'">'.$about_me_link.
 6949:             '<br /><tt>'.$parmlog{$id}{'exe_uname'}.
 6950:                         ':'.$parmlog{$id}{'exe_udom'}.'</tt>'.
 6951:             $send_msg_link.'</td>'.$output);
 6952:             $shown++;
 6953:         }
 6954:         if (!($env{'form.show'} eq &mt('all')
 6955:             || $shown<=$env{'form.show'})) { last; }
 6956:     }
 6957:     $r->print(&Apache::loncommon::end_data_table());
 6958:     &endSettingsScreen($r);
 6959:     $r->print(&Apache::loncommon::end_page());
 6960: }
 6961: 
 6962: ##################################################
 6963: # MISC !
 6964: ##################################################
 6965: 
 6966: # Stores slot information.
 6967: # Used by table UI
 6968: # FIXME: I don't understand how this can work when the symb is not defined (if only a map was selected)
 6969: #
 6970: # @param {string} $slot_name - slot name
 6971: # @param {string} $cdom - course domain
 6972: # @param {string} $cnum - course number
 6973: # @param {string} $symb - resource symb
 6974: # @param {string} $uname - user name
 6975: # @param {string} $udom - user domain
 6976: # @returns {string} - 'ok' or error name
 6977: sub update_slots {
 6978:     my ($slot_name,$cdom,$cnum,$symb,$uname,$udom) = @_;
 6979:     my %slot=&Apache::lonnet::get_slot($slot_name);
 6980:     if (!keys(%slot)) {
 6981:         return 'error: slot does not exist';
 6982:     }
 6983:     my $max=$slot{'maxspace'};
 6984:     if (!defined($max)) { $max=99999; }
 6985: 
 6986:     my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
 6987:                                        "^$slot_name\0");
 6988:     my ($tmp)=%consumed;
 6989:     if ($tmp=~/^error: 2 / ) {
 6990:         return 'error: unable to determine current slot status';
 6991:     }
 6992:     my $last=0;
 6993:     foreach my $key (keys(%consumed)) {
 6994:         my $num=(split('\0',$key))[1];
 6995:         if ($num > $last) { $last=$num; }
 6996:         if ($consumed{$key}->{'name'} eq $uname.':'.$udom) {
 6997:             return 'ok';
 6998:         }
 6999:     }
 7000: 
 7001:     if (scalar(keys(%consumed)) >= $max) {
 7002:         return 'error: no space left in slot';
 7003:     }
 7004:     my $wanted=$last+1;
 7005: 
 7006:     my %reservation=('name'      => $uname.':'.$udom,
 7007:                      'timestamp' => time,
 7008:                      'symb'      => $symb);
 7009: 
 7010:     my $success=&Apache::lonnet::newput('slot_reservations',
 7011:                                         {"$slot_name\0$wanted" =>
 7012:                                              \%reservation},
 7013:                                         $cdom, $cnum);
 7014:     if ($success eq 'ok') {
 7015:         my %storehash = (
 7016:                           symb    => $symb,
 7017:                           slot    => $slot_name,
 7018:                           action  => 'reserve',
 7019:                           context => 'parameter',
 7020:                         );
 7021:         &Apache::lonnet::write_log('course','slotreservationslog',\%storehash,
 7022:                                    '',$uname,$udom,$cnum,$cdom);
 7023: 
 7024:         &Apache::lonnet::write_log('course',$cdom.'_'.$cnum.'_slotlog',\%storehash,
 7025:                                    '',$uname,$udom,$uname,$udom);
 7026:     }
 7027:     return $success;
 7028: }
 7029: 
 7030: # Deletes a slot reservation.
 7031: # Used by table UI
 7032: # FIXME: I don't understand how this can work when the symb is not defined (if only a map was selected)
 7033: #
 7034: # @param {string} $slot_name - slot name
 7035: # @param {string} $cdom - course domain
 7036: # @param {string} $cnum - course number
 7037: # @param {string} $uname - user name
 7038: # @param {string} $udom - user domain
 7039: # @param {string} $symb - resource symb
 7040: # @returns {string} - 'ok' or error name
 7041: sub delete_slots {
 7042:     my ($slot_name,$cdom,$cnum,$uname,$udom,$symb) = @_;
 7043:     my $delresult;
 7044:     my %consumed = &Apache::lonnet::dump('slot_reservations',$cdom,
 7045:                                          $cnum, "^$slot_name\0");
 7046:     if (&Apache::lonnet::error(%consumed)) {
 7047:         return 'error: unable to determine current slot status';
 7048:     }
 7049:     my ($tmp)=%consumed;
 7050:     if ($tmp=~/^error: 2 /) {
 7051:         return 'error: unable to determine current slot status';
 7052:     }
 7053:     foreach my $key (keys(%consumed)) {
 7054:         if ($consumed{$key}->{'name'} eq $uname.':'.$udom) {
 7055:             my $num=(split('\0',$key))[1];
 7056:             my $entry = $slot_name.'\0'.$num;
 7057:             $delresult = &Apache::lonnet::del('slot_reservations',[$entry],
 7058:                                               $cdom,$cnum);
 7059:             if ($delresult eq 'ok') {
 7060:                 my %storehash = (
 7061:                                   symb    => $symb,
 7062:                                   slot    => $slot_name,
 7063:                                   action  => 'release',
 7064:                                   context => 'parameter',
 7065:                                 );
 7066:                 &Apache::lonnet::write_log('course','slotreservationslog',\%storehash,
 7067:                                            1,$uname,$udom,$cnum,$cdom);
 7068:                 &Apache::lonnet::write_log('course',$cdom.'_'.$cnum.'_slotlog',\%storehash,
 7069:                                            1,$uname,$udom,$uname,$udom);
 7070:             }
 7071:         }
 7072:     }
 7073:     return $delresult;
 7074: }
 7075: 
 7076: # Returns true if there is a current course.
 7077: # Used by handler
 7078: #
 7079: # @returns {boolean}
 7080: sub check_for_course_info {
 7081:     my $navmap = Apache::lonnavmaps::navmap->new();
 7082:     return 1 if ($navmap);
 7083:     return 0;
 7084: }
 7085: 
 7086: # Returns the current course host and host LON-CAPA version.
 7087: #
 7088: # @returns {Array} - (course hostname, major version number, minor version number)
 7089: sub parameter_release_vars { 
 7090:    my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 7091:    my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
 7092:    my $chostname = &Apache::lonnet::hostname($chome);
 7093:    my ($cmajor,$cminor) = 
 7094:        split(/\./,&Apache::lonnet::get_server_loncaparev($cdom,$chome));
 7095:    return ($chostname,$cmajor,$cminor);
 7096: }
 7097: 
 7098: # Checks if the course host version can handle a parameter required version,
 7099: # and if it does, stores the release needed for the course.
 7100: #
 7101: # @param {string} $name - parameter name
 7102: # @param {string} $value - parameter value
 7103: # @param {string} $valmatch - name of the test used for checking the value
 7104: # @param {string} $namematch - name of the test used for checking the name
 7105: # @param {string} $needsrelease - version needed by the parameter, major.minor
 7106: # @param {integer} $cmajor - course major version number
 7107: # @param {integer} $cminor - course minor version number
 7108: # @returns {boolean} - true if a newer version is needed
 7109: sub parameter_releasecheck {
 7110:     my ($name,$value,$valmatch,$namematch,$needsrelease,$cmajor,$cminor) = @_;
 7111:     my $needsnewer;
 7112:     my ($needsmajor,$needsminor) = split(/\./,$needsrelease);
 7113:     if (($cmajor < $needsmajor) || 
 7114:         ($cmajor == $needsmajor && $cminor < $needsminor)) {
 7115:         $needsnewer = 1;
 7116:     } elsif ($name) {
 7117:         if ($valmatch) {
 7118:             &Apache::lonnet::update_released_required($Apache::lonnet::needsrelease{'parameter:'.$name.'::'.$valmatch.':'});
 7119:         } elsif ($value) { 
 7120:             &Apache::lonnet::update_released_required($Apache::lonnet::needsrelease{'parameter:'.$name.':'.$value.'::'});
 7121:         }
 7122:     } elsif ($namematch) {
 7123:         &Apache::lonnet::update_released_required($Apache::lonnet::needsrelease{'parameter::::'.$namematch});
 7124:     }
 7125:     return $needsnewer;
 7126: }
 7127: 
 7128: sub get_permission {
 7129:     my %permission;
 7130:     my $allowed = 0;
 7131:     return (\%permission,$allowed) unless ($env{'request.course.id'});
 7132:     if ((&Apache::lonnet::allowed('opa',$env{'request.course.id'})) ||
 7133:         (&Apache::lonnet::allowed('opa',$env{'request.course.id'}.'/'.
 7134:                   $env{'request.course.sec'}))) {
 7135:         %permission= (
 7136:                        'edit'               => 1,
 7137:                        'set'                => 1,
 7138:                        'setoverview'        => 1,
 7139:                        'addmetadata'        => 1,
 7140:                        'ordermetadata'      => 1,
 7141:                        'setrestrictmeta'    => 1,
 7142:                        'newoverview'        => 1,
 7143:                        'setdefaults'        => 1,
 7144:                        'settable'           => 1,
 7145:                        'parameterchangelog' => 1,
 7146:                        'cleanparameters'    => 1,
 7147:                        'dateshift1'         => 1,
 7148:                        'dateshift2'         => 1,
 7149:                        'helper'             => 1,
 7150:          );
 7151:     } elsif ((&Apache::lonnet::allowed('vpa',$env{'request.course.id'})) ||
 7152:              (&Apache::lonnet::allowed('vpa',$env{'request.course.id'}.'/'.
 7153:                   $env{'request.course.sec'}))) {
 7154:         %permission = (
 7155:                        'set'                => 1,
 7156:                        'settable'           => 1,
 7157:                        'newoverview'        => 1,
 7158:                        'setoverview'        => 1,
 7159:                        'parameterchangelog' => 1,
 7160:                       );
 7161:     }
 7162:     foreach my $perm (values(%permission)) {
 7163:         if ($perm) { $allowed=1; last; }
 7164:     }
 7165:     return (\%permission,$allowed);
 7166: }
 7167: 
 7168: ##################################################
 7169: # HANDLER
 7170: ##################################################
 7171: 
 7172: # Main handler for lonparmset.
 7173: # Sub called based on request parameters action and command:
 7174: # no command or action: print_main_menu
 7175: # command 'set': assessparms (direct access to table mode for a resource)
 7176: #                (this can also be accessed simply with the symb parameter)
 7177: # action 'setoverview': overview (display all existing parameter settings)
 7178: # action 'addmetadata': addmetafield (called to add a portfolio metadata field)
 7179: # action 'ordermetadata': order_meta_fields (called to order portfolio metadata fields)
 7180: # action 'setrestrictmeta': setrestrictmeta (display or save portfolio metadata)
 7181: # action 'newoverview': newoverview (overview mode)
 7182: # action 'setdefaults': defaultsetter (UI to change parameter setting default actions)
 7183: # action 'settable': assessparms (table mode)
 7184: # action 'parameterchangelog': parm_change_log (display log for parameter changes,
 7185: #                              blog postings, user notification changes)
 7186: # action 'cleanparameters': clean_parameters (unused)
 7187: # action 'dateshift1': date_shift_one (overview mode, shift all dates)
 7188: # action 'dateshift2': date_shift_two (overview mode, shift all dates)
 7189: sub handler {
 7190:     my $r=shift;
 7191: 
 7192:     &reset_caches();
 7193: 
 7194:     &Apache::loncommon::content_type($r,'text/html');
 7195:     $r->send_http_header;
 7196:     return OK if $r->header_only;
 7197: 
 7198:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
 7199:                         ['action','state',
 7200:                                              'pres_marker',
 7201:                                              'pres_value',
 7202:                                              'pres_type',
 7203:                                              'filter','part',
 7204:                                              'udom','uname','symb','serial','timebase']);
 7205: 
 7206: 
 7207:     &Apache::lonhtmlcommon::clear_breadcrumbs();
 7208:     &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/parmset",
 7209:                         text=>"Content and Problem Settings",
 7210:                         faq=>10,
 7211:                         bug=>'Instructor Interface',
 7212:                                             help =>
 7213:                                             'Parameter_Manager,Course_Environment,Parameter_Helper,Parameter_Overview,Table_Mode'});
 7214: 
 7215: # ----------------------------------------------------- Needs to be in a course
 7216:     my ($parm_permission,$allowed) = &get_permission();
 7217:     my $exists = &check_for_course_info();
 7218: 
 7219:     if ($env{'request.course.id'} && $allowed && $exists) {
 7220:         #
 7221:         # Main switch on form.action and form.state, as appropriate
 7222:         #
 7223:         # Check first if coming from someone else headed directly for
 7224:         #  the table mode
 7225:         if (($parm_permission->{'set'}) && 
 7226:             ((($env{'form.command'} eq 'set') && ($env{'form.url'})
 7227:                 && (!$env{'form.dis'})) || ($env{'form.symb'}))) {
 7228:             &assessparms($r,$parm_permission);
 7229:         } elsif (! exists($env{'form.action'})) {
 7230:             &print_main_menu($r,$parm_permission);
 7231:         } elsif (!$parm_permission->{$env{'form.action'}}) {
 7232:             &print_main_menu($r,$parm_permission);
 7233:         } elsif ($env{'form.action'} eq 'setoverview') {
 7234:             &overview($r,$parm_permission);
 7235:         } elsif ($env{'form.action'} eq 'addmetadata') {
 7236:             &addmetafield($r);
 7237:         } elsif ($env{'form.action'} eq 'ordermetadata') {
 7238:             &order_meta_fields($r);
 7239:         } elsif ($env{'form.action'} eq 'setrestrictmeta') {
 7240:             &setrestrictmeta($r);
 7241:         } elsif ($env{'form.action'} eq 'newoverview') {
 7242:             &newoverview($r,$parm_permission);
 7243:         } elsif ($env{'form.action'} eq 'setdefaults') {
 7244:             &defaultsetter($r);
 7245:         } elsif ($env{'form.action'} eq 'settable') {
 7246:             &assessparms($r,$parm_permission);
 7247:         } elsif ($env{'form.action'} eq 'parameterchangelog') {
 7248:             &parm_change_log($r,$parm_permission);
 7249:         } elsif ($env{'form.action'} eq 'cleanparameters') {
 7250:             &clean_parameters($r);
 7251:         } elsif ($env{'form.action'} eq 'dateshift1') {
 7252:             &date_shift_one($r);
 7253:         } elsif ($env{'form.action'} eq 'dateshift2') {
 7254:             &date_shift_two($r);
 7255:         }
 7256:     } else {
 7257: # ----------------------------- Not in a course, or not allowed to modify parms
 7258:         if ($exists) {
 7259:             $env{'user.error.msg'}=
 7260:             "/adm/parmset:opa:0:0:Cannot modify assessment parameters";
 7261:         } else {
 7262:             $env{'user.error.msg'}=
 7263:             "/adm/parmset::0:1:Course environment gone, reinitialize the course";
 7264:         }
 7265:         return HTTP_NOT_ACCEPTABLE;
 7266:     }
 7267:     &reset_caches();
 7268: 
 7269:     return OK;
 7270: }
 7271: 
 7272: 1;
 7273: __END__
 7274: 
 7275: 

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