Annotation of loncom/interface/loncommon.pm, revision 1.718

1.10      albertel    1: # The LearningOnline Network with CAPA
1.1       albertel    2: # a pile of common routines
1.10      albertel    3: #
1.718   ! raeburn     4: # $Id: loncommon.pm,v 1.717 2008/12/15 11:44:41 tempelho Exp $
1.10      albertel    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
1.1       albertel   28: 
                     29: # Makes a table out of the previous attempts
1.2       albertel   30: # Inputs result_from_symbread, user, domain, course_id
1.16      harris41   31: # Reads in non-network-related .tab files
1.1       albertel   32: 
1.35      matthew    33: # POD header:
                     34: 
1.45      matthew    35: =pod
                     36: 
1.35      matthew    37: =head1 NAME
                     38: 
                     39: Apache::loncommon - pile of common routines
                     40: 
                     41: =head1 SYNOPSIS
                     42: 
1.112     bowersj2   43: Common routines for manipulating connections, student answers,
                     44:     domains, common Javascript fragments, etc.
1.35      matthew    45: 
1.112     bowersj2   46: =head1 OVERVIEW
1.35      matthew    47: 
1.112     bowersj2   48: A collection of commonly used subroutines that don't have a natural
                     49: home anywhere else. This collection helps remove
1.35      matthew    50: redundancy from other modules and increase efficiency of memory usage.
                     51: 
                     52: =cut 
                     53: 
                     54: # End of POD header
1.1       albertel   55: package Apache::loncommon;
                     56: 
                     57: use strict;
1.258     albertel   58: use Apache::lonnet;
1.46      matthew    59: use GDBM_File;
1.51      www        60: use POSIX qw(strftime mktime);
1.82      www        61: use Apache::lonmenu();
1.498     albertel   62: use Apache::lonenc();
1.117     www        63: use Apache::lonlocal;
1.685     tempelho   64: use Apache::lonnet();
1.139     matthew    65: use HTML::Entities;
1.334     albertel   66: use Apache::lonhtmlcommon();
                     67: use Apache::loncoursedata();
1.344     albertel   68: use Apache::lontexconvert();
1.444     albertel   69: use Apache::lonclonecourse();
1.479     albertel   70: use LONCAPA qw(:DEFAULT :match);
1.657     raeburn    71: use DateTime::TimeZone;
1.687     raeburn    72: use DateTime::Locale::Catalog;
1.117     www        73: 
1.517     raeburn    74: # ---------------------------------------------- Designs
                     75: use vars qw(%defaultdesign);
                     76: 
1.22      www        77: my $readit;
                     78: 
1.517     raeburn    79: 
1.157     matthew    80: ##
                     81: ## Global Variables
                     82: ##
1.46      matthew    83: 
1.643     foxr       84: 
                     85: # ----------------------------------------------- SSI with retries:
                     86: #
                     87: 
                     88: =pod
                     89: 
1.648     raeburn    90: =head1 Server Side include with retries:
1.643     foxr       91: 
                     92: =over 4
                     93: 
1.648     raeburn    94: =item * &ssi_with_retries(resource,retries form)
1.643     foxr       95: 
                     96: Performs an ssi with some number of retries.  Retries continue either
                     97: until the result is ok or until the retry count supplied by the
                     98: caller is exhausted.  
                     99: 
                    100: Inputs:
1.648     raeburn   101: 
                    102: =over 4
                    103: 
1.643     foxr      104: resource   - Identifies the resource to insert.
1.648     raeburn   105: 
1.643     foxr      106: retries    - Count of the number of retries allowed.
1.648     raeburn   107: 
1.643     foxr      108: form       - Hash that identifies the rendering options.
                    109: 
1.648     raeburn   110: =back
                    111: 
                    112: Returns:
                    113: 
                    114: =over 4
                    115: 
1.643     foxr      116: content    - The content of the response.  If retries were exhausted this is empty.
1.648     raeburn   117: 
1.643     foxr      118: response   - The response from the last attempt (which may or may not have been successful.
                    119: 
1.648     raeburn   120: =back
                    121: 
                    122: =back
                    123: 
1.643     foxr      124: =cut
                    125: 
                    126: sub ssi_with_retries {
                    127:     my ($resource, $retries, %form) = @_;
                    128: 
                    129: 
                    130:     my $ok = 0;			# True if we got a good response.
                    131:     my $content;
                    132:     my $response;
                    133: 
                    134:     # Try to get the ssi done. within the retries count:
                    135: 
                    136:     do {
                    137: 	($content, $response) = &Apache::lonnet::ssi($resource, %form);
                    138: 	$ok      = $response->is_success;
1.650     www       139:         if (!$ok) {
                    140:             &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
                    141:         }
1.643     foxr      142: 	$retries--;
                    143:     } while (!$ok && ($retries > 0));
                    144: 
                    145:     if (!$ok) {
                    146: 	$content = '';		# On error return an empty content.
                    147:     }
                    148:     return ($content, $response);
                    149: 
                    150: }
                    151: 
                    152: 
                    153: 
1.20      www       154: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12      harris41  155: my %language;
1.124     www       156: my %supported_language;
1.12      harris41  157: my %cprtag;
1.192     taceyjo1  158: my %scprtag;
1.351     www       159: my %fe; my %fd; my %fm;
1.41      ng        160: my %category_extensions;
1.12      harris41  161: 
1.46      matthew   162: # ---------------------------------------------- Thesaurus variables
1.144     matthew   163: #
                    164: # %Keywords:
                    165: #      A hash used by &keyword to determine if a word is considered a keyword.
                    166: # $thesaurus_db_file 
                    167: #      Scalar containing the full path to the thesaurus database.
1.46      matthew   168: 
                    169: my %Keywords;
                    170: my $thesaurus_db_file;
                    171: 
1.144     matthew   172: #
                    173: # Initialize values from language.tab, copyright.tab, filetypes.tab,
                    174: # thesaurus.tab, and filecategories.tab.
                    175: #
1.18      www       176: BEGIN {
1.46      matthew   177:     # Variable initialization
                    178:     $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
                    179:     #
1.22      www       180:     unless ($readit) {
1.12      harris41  181: # ------------------------------------------------------------------- languages
                    182:     {
1.158     raeburn   183:         my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    184:                                    '/language.tab';
                    185:         if ( open(my $fh,"<$langtabfile") ) {
1.356     albertel  186:             while (my $line = <$fh>) {
                    187:                 next if ($line=~/^\#/);
                    188:                 chomp($line);
                    189:                 my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
1.158     raeburn   190:                 $language{$key}=$val.' - '.$enc;
                    191:                 if ($sup) {
                    192:                     $supported_language{$key}=$sup;
                    193:                 }
                    194:             }
                    195:             close($fh);
                    196:         }
1.12      harris41  197:     }
                    198: # ------------------------------------------------------------------ copyrights
                    199:     {
1.158     raeburn   200:         my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
                    201:                                   '/copyright.tab';
                    202:         if ( open (my $fh,"<$copyrightfile") ) {
1.356     albertel  203:             while (my $line = <$fh>) {
                    204:                 next if ($line=~/^\#/);
                    205:                 chomp($line);
                    206:                 my ($key,$val)=(split(/\s+/,$line,2));
1.158     raeburn   207:                 $cprtag{$key}=$val;
                    208:             }
                    209:             close($fh);
                    210:         }
1.12      harris41  211:     }
1.351     www       212: # ----------------------------------------------------------- source copyrights
1.192     taceyjo1  213:     {
                    214:         my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
                    215:                                   '/source_copyright.tab';
                    216:         if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356     albertel  217:             while (my $line = <$fh>) {
                    218:                 next if ($line =~ /^\#/);
                    219:                 chomp($line);
                    220:                 my ($key,$val)=(split(/\s+/,$line,2));
1.192     taceyjo1  221:                 $scprtag{$key}=$val;
                    222:             }
                    223:             close($fh);
                    224:         }
                    225:     }
1.63      www       226: 
1.517     raeburn   227: # -------------------------------------------------------------- default domain designs
1.63      www       228:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517     raeburn   229:     my $designfile = $designdir.'/default.tab';
                    230:     if ( open (my $fh,"<$designfile") ) {
                    231:         while (my $line = <$fh>) {
                    232:             next if ($line =~ /^\#/);
                    233:             chomp($line);
                    234:             my ($key,$val)=(split(/\=/,$line));
                    235:             if ($val) { $defaultdesign{$key}=$val; }
                    236:         }
                    237:         close($fh);
1.63      www       238:     }
                    239: 
1.15      harris41  240: # ------------------------------------------------------------- file categories
                    241:     {
1.158     raeburn   242:         my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    243:                                   '/filecategories.tab';
                    244:         if ( open (my $fh,"<$categoryfile") ) {
1.356     albertel  245: 	    while (my $line = <$fh>) {
                    246: 		next if ($line =~ /^\#/);
                    247: 		chomp($line);
                    248:                 my ($extension,$category)=(split(/\s+/,$line,2));
1.158     raeburn   249:                 push @{$category_extensions{lc($category)}},$extension;
                    250:             }
                    251:             close($fh);
                    252:         }
                    253: 
1.15      harris41  254:     }
1.12      harris41  255: # ------------------------------------------------------------------ file types
                    256:     {
1.158     raeburn   257:         my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    258:                '/filetypes.tab';
                    259:         if ( open (my $fh,"<$typesfile") ) {
1.356     albertel  260:             while (my $line = <$fh>) {
                    261: 		next if ($line =~ /^\#/);
                    262: 		chomp($line);
                    263:                 my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158     raeburn   264:                 if ($descr ne '') {
                    265:                     $fe{$ending}=lc($emb);
                    266:                     $fd{$ending}=$descr;
1.351     www       267:                     if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158     raeburn   268:                 }
                    269:             }
                    270:             close($fh);
                    271:         }
1.12      harris41  272:     }
1.22      www       273:     &Apache::lonnet::logthis(
1.705     tempelho  274:              "<span style='color:yellow;'>INFO: Read file types</span>");
1.22      www       275:     $readit=1;
1.46      matthew   276:     }  # end of unless($readit) 
1.32      matthew   277:     
                    278: }
1.112     bowersj2  279: 
1.42      matthew   280: ###############################################################
                    281: ##           HTML and Javascript Helper Functions            ##
                    282: ###############################################################
                    283: 
                    284: =pod 
                    285: 
1.112     bowersj2  286: =head1 HTML and Javascript Functions
1.42      matthew   287: 
1.112     bowersj2  288: =over 4
                    289: 
1.648     raeburn   290: =item * &browser_and_searcher_javascript()
1.112     bowersj2  291: 
                    292: X<browsing, javascript>X<searching, javascript>Returns a string
                    293: containing javascript with two functions, C<openbrowser> and
                    294: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
                    295: tags.
1.42      matthew   296: 
1.648     raeburn   297: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42      matthew   298: 
                    299: inputs: formname, elementname, only, omit
                    300: 
                    301: formname and elementname indicate the name of the html form and name of
                    302: the element that the results of the browsing selection are to be placed in. 
                    303: 
                    304: Specifying 'only' will restrict the browser to displaying only files
1.185     www       305: with the given extension.  Can be a comma separated list.
1.42      matthew   306: 
                    307: Specifying 'omit' will restrict the browser to NOT displaying files
1.185     www       308: with the given extension.  Can be a comma separated list.
1.42      matthew   309: 
1.648     raeburn   310: =item * &opensearcher(formname,elementname) [javascript]
1.42      matthew   311: 
                    312: Inputs: formname, elementname
                    313: 
                    314: formname and elementname specify the name of the html form and the name
                    315: of the element the selection from the search results will be placed in.
1.542     raeburn   316: 
1.42      matthew   317: =cut
                    318: 
                    319: sub browser_and_searcher_javascript {
1.199     albertel  320:     my ($mode)=@_;
                    321:     if (!defined($mode)) { $mode='edit'; }
1.453     albertel  322:     my $resurl=&escape_single(&lastresurl());
1.42      matthew   323:     return <<END;
1.219     albertel  324: // <!-- BEGIN LON-CAPA Internal
1.50      matthew   325:     var editbrowser = null;
1.135     albertel  326:     function openbrowser(formname,elementname,only,omit,titleelement) {
1.170     www       327:         var url = '$resurl/?';
1.42      matthew   328:         if (editbrowser == null) {
                    329:             url += 'launch=1&';
                    330:         }
                    331:         url += 'catalogmode=interactive&';
1.199     albertel  332:         url += 'mode=$mode&';
1.611     albertel  333:         url += 'inhibitmenu=yes&';
1.42      matthew   334:         url += 'form=' + formname + '&';
                    335:         if (only != null) {
                    336:             url += 'only=' + only + '&';
1.217     albertel  337:         } else {
                    338:             url += 'only=&';
                    339: 	}
1.42      matthew   340:         if (omit != null) {
                    341:             url += 'omit=' + omit + '&';
1.217     albertel  342:         } else {
                    343:             url += 'omit=&';
                    344: 	}
1.135     albertel  345:         if (titleelement != null) {
                    346:             url += 'titleelement=' + titleelement + '&';
1.217     albertel  347:         } else {
                    348: 	    url += 'titleelement=&';
                    349: 	}
1.42      matthew   350:         url += 'element=' + elementname + '';
                    351:         var title = 'Browser';
1.435     albertel  352:         var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42      matthew   353:         options += ',width=700,height=600';
                    354:         editbrowser = open(url,title,options,'1');
                    355:         editbrowser.focus();
                    356:     }
                    357:     var editsearcher;
1.135     albertel  358:     function opensearcher(formname,elementname,titleelement) {
1.42      matthew   359:         var url = '/adm/searchcat?';
                    360:         if (editsearcher == null) {
                    361:             url += 'launch=1&';
                    362:         }
                    363:         url += 'catalogmode=interactive&';
1.199     albertel  364:         url += 'mode=$mode&';
1.42      matthew   365:         url += 'form=' + formname + '&';
1.135     albertel  366:         if (titleelement != null) {
                    367:             url += 'titleelement=' + titleelement + '&';
1.217     albertel  368:         } else {
                    369: 	    url += 'titleelement=&';
                    370: 	}
1.42      matthew   371:         url += 'element=' + elementname + '';
                    372:         var title = 'Search';
1.435     albertel  373:         var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42      matthew   374:         options += ',width=700,height=600';
                    375:         editsearcher = open(url,title,options,'1');
                    376:         editsearcher.focus();
                    377:     }
1.219     albertel  378: // END LON-CAPA Internal -->
1.42      matthew   379: END
1.170     www       380: }
                    381: 
                    382: sub lastresurl {
1.258     albertel  383:     if ($env{'environment.lastresurl'}) {
                    384: 	return $env{'environment.lastresurl'}
1.170     www       385:     } else {
                    386: 	return '/res';
                    387:     }
                    388: }
                    389: 
                    390: sub storeresurl {
                    391:     my $resurl=&Apache::lonnet::clutter(shift);
                    392:     unless ($resurl=~/^\/res/) { return 0; }
                    393:     $resurl=~s/\/$//;
                    394:     &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646     raeburn   395:     &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170     www       396:     return 1;
1.42      matthew   397: }
                    398: 
1.74      www       399: sub studentbrowser_javascript {
1.111     www       400:    unless (
1.258     albertel  401:             (($env{'request.course.id'}) && 
1.302     albertel  402:              (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    403: 	      || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                    404: 					  '/'.$env{'request.course.sec'})
                    405: 	      ))
1.258     albertel  406:          || ($env{'request.role'}=~/^(au|dc|su)/)
1.111     www       407:           ) { return ''; }  
1.74      www       408:    return (<<'ENDSTDBRW');
                    409: <script type="text/javascript" language="Javascript" >
                    410:     var stdeditbrowser;
1.558     albertel  411:     function openstdbrowser(formname,uname,udom,roleflag,ignorefilter) {
1.74      www       412:         var url = '/adm/pickstudent?';
                    413:         var filter;
1.558     albertel  414: 	if (!ignorefilter) {
                    415: 	    eval('filter=document.'+formname+'.'+uname+'.value;');
                    416: 	}
1.74      www       417:         if (filter != null) {
                    418:            if (filter != '') {
                    419:                url += 'filter='+filter+'&';
                    420: 	   }
                    421:         }
                    422:         url += 'form=' + formname + '&unameelement='+uname+
                    423:                                     '&udomelement='+udom;
1.111     www       424: 	if (roleflag) { url+="&roles=1"; }
1.102     www       425:         var title = 'Student_Browser';
1.74      www       426:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    427:         options += ',width=700,height=600';
                    428:         stdeditbrowser = open(url,title,options,'1');
                    429:         stdeditbrowser.focus();
                    430:     }
                    431: </script>
                    432: ENDSTDBRW
                    433: }
1.42      matthew   434: 
1.74      www       435: sub selectstudent_link {
1.111     www       436:    my ($form,$unameele,$udomele)=@_;
1.258     albertel  437:    if ($env{'request.course.id'}) {  
1.302     albertel  438:        if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    439: 	   && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                    440: 					'/'.$env{'request.course.sec'})) {
1.111     www       441: 	   return '';
                    442:        }
                    443:        return "<a href='".'javascript:openstdbrowser("'.$form.'","'.$unameele.
1.607     albertel  444:         '","'.$udomele.'");'."'>".&mt('Select User')."</a>";
1.74      www       445:    }
1.258     albertel  446:    if ($env{'request.role'}=~/^(au|dc|su)/) {
1.111     www       447:        return "<a href='".'javascript:openstdbrowser("'.$form.'","'.$unameele.
1.119     www       448:         '","'.$udomele.'",1);'."'>".&mt('Select User')."</a>";
1.111     www       449:    }
                    450:    return '';
1.91      www       451: }
                    452: 
1.653     raeburn   453: sub authorbrowser_javascript {
                    454:     return <<"ENDAUTHORBRW";
                    455: <script type="text/javascript">
                    456: var stdeditbrowser;
                    457: 
                    458: function openauthorbrowser(formname,udom) {
                    459:     var url = '/adm/pickauthor?';
                    460:     url += 'form='+formname+'&roledom='+udom;
                    461:     var title = 'Author_Browser';
                    462:     var options = 'scrollbars=1,resizable=1,menubar=0';
                    463:     options += ',width=700,height=600';
                    464:     stdeditbrowser = open(url,title,options,'1');
                    465:     stdeditbrowser.focus();
                    466: }
                    467: 
                    468: </script>
                    469: ENDAUTHORBRW
                    470: }
                    471: 
1.91      www       472: sub coursebrowser_javascript {
1.468     raeburn   473:     my ($domainfilter,$sec_element,$formname)=@_;
1.377     raeburn   474:     my $crs_or_grp_alert = &mt('Please select the type of LON-CAPA entity - Course or Group - for which you wish to add/modify a user role');
1.468     raeburn   475:    my $output = '
1.538     albertel  476: <script type="text/javascript">
1.468     raeburn   477:     var stdeditbrowser;'."\n";
                    478:    $output .= <<"ENDSTDBRW";
1.377     raeburn   479:     function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
1.91      www       480:         var url = '/adm/pickcourse?';
1.468     raeburn   481:         var domainfilter = '';
                    482:         var formid = getFormIdByName(formname);
                    483:         if (formid > -1) {
                    484:             var domid = getIndexByName(formid,udom);
                    485:             if (domid > -1) {
                    486:                 if (document.forms[formid].elements[domid].type == 'select-one') {
                    487:                     domainfilter=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
                    488:                 }
                    489:                 if (document.forms[formid].elements[domid].type == 'hidden') {
                    490:                     domainfilter=document.forms[formid].elements[domid].value;
                    491:                 }
                    492:             }
1.91      www       493:         }
1.128     albertel  494:         if (domainfilter != null) {
                    495:            if (domainfilter != '') {
                    496:                url += 'domainfilter='+domainfilter+'&';
                    497: 	   }
                    498:         }
1.91      www       499:         url += 'form=' + formname + '&cnumelement='+uname+
1.187     albertel  500: 	                            '&cdomelement='+udom+
                    501:                                     '&cnameelement='+desc;
1.468     raeburn   502:         if (extra_element !=null && extra_element != '') {
1.594     raeburn   503:             if (formname == 'rolechoice' || formname == 'studentform') {
1.468     raeburn   504:                 url += '&roleelement='+extra_element;
                    505:                 if (domainfilter == null || domainfilter == '') {
                    506:                     url += '&domainfilter='+extra_element;
                    507:                 }
1.234     raeburn   508:             }
1.468     raeburn   509:             else {
                    510:                 if (formname == 'portform') {
                    511:                     url += '&setroles='+extra_element;
                    512:                 }
                    513:             }     
1.230     raeburn   514:         }
1.293     raeburn   515:         if (multflag !=null && multflag != '') {
                    516:             url += '&multiple='+multflag;
                    517:         }
1.377     raeburn   518:         if (crstype == 'Course/Group') {
                    519:             if (formname == 'cu') {
                    520:                 crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value; 
                    521:                 if (crstype == "") {
                    522:                     alert("$crs_or_grp_alert");
                    523:                     return;
                    524:                 }
                    525:             }
                    526:         }
                    527:         if (crstype !=null && crstype != '') {
                    528:             url += '&type='+crstype;
                    529:         }
1.102     www       530:         var title = 'Course_Browser';
1.91      www       531:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    532:         options += ',width=700,height=600';
                    533:         stdeditbrowser = open(url,title,options,'1');
                    534:         stdeditbrowser.focus();
                    535:     }
1.468     raeburn   536: 
                    537:     function getFormIdByName(formname) {
                    538:         for (var i=0;i<document.forms.length;i++) {
                    539:             if (document.forms[i].name == formname) {
                    540:                 return i;
                    541:             }
                    542:         }
                    543:         return -1; 
                    544:     }
                    545: 
                    546:     function getIndexByName(formid,item) {
                    547:         for (var i=0;i<document.forms[formid].elements.length;i++) {
                    548:             if (document.forms[formid].elements[i].name == item) {
                    549:                 return i;
                    550:             }
                    551:         }
                    552:         return -1;
                    553:     }
1.91      www       554: ENDSTDBRW
1.468     raeburn   555:     if ($sec_element ne '') {
                    556:         $output .= &setsec_javascript($sec_element,$formname);
                    557:     }
                    558:     $output .= '
                    559: </script>';
                    560:     return $output;
                    561: }
                    562: 
                    563: sub setsec_javascript {
                    564:     my ($sec_element,$formname) = @_;
                    565:     my $setsections = qq|
                    566: function setSect(sectionlist) {
1.629     raeburn   567:     var sectionsArray = new Array();
                    568:     if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
                    569:         sectionsArray = sectionlist.split(",");
                    570:     }
1.468     raeburn   571:     var numSections = sectionsArray.length;
                    572:     document.$formname.$sec_element.length = 0;
                    573:     if (numSections == 0) {
                    574:         document.$formname.$sec_element.multiple=false;
                    575:         document.$formname.$sec_element.size=1;
                    576:         document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
                    577:     } else {
                    578:         if (numSections == 1) {
                    579:             document.$formname.$sec_element.multiple=false;
                    580:             document.$formname.$sec_element.size=1;
                    581:             document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
                    582:             document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
                    583:             document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
                    584:         } else {
                    585:             for (var i=0; i<numSections; i++) {
                    586:                 document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
                    587:             }
                    588:             document.$formname.$sec_element.multiple=true
                    589:             if (numSections < 3) {
                    590:                 document.$formname.$sec_element.size=numSections;
                    591:             } else {
                    592:                 document.$formname.$sec_element.size=3;
                    593:             }
                    594:             document.$formname.$sec_element.options[0].selected = false
                    595:         }
                    596:     }
1.91      www       597: }
1.468     raeburn   598: |;
                    599:     return $setsections;
                    600: }
                    601: 
1.91      www       602: 
                    603: sub selectcourse_link {
1.377     raeburn   604:    my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
1.492     albertel  605:    return "<a href='".'javascript:opencrsbrowser("'.$form.'","'.$unameele.
                    606:         '","'.$udomele.'","'.$desc.'","'.$extra_element.'","'.$multflag.'","'.$selecttype.'");'."'>".&mt('Select Course')."</a>";
1.74      www       607: }
1.42      matthew   608: 
1.653     raeburn   609: sub selectauthor_link {
                    610:    my ($form,$udom)=@_;
                    611:    return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
                    612:           &mt('Select Author').'</a>';
                    613: }
                    614: 
1.273     raeburn   615: sub check_uncheck_jscript {
                    616:     my $jscript = <<"ENDSCRT";
                    617: function checkAll(field) {
                    618:     if (field.length > 0) {
                    619:         for (i = 0; i < field.length; i++) {
                    620:             field[i].checked = true ;
                    621:         }
                    622:     } else {
                    623:         field.checked = true
                    624:     }
                    625: }
                    626:  
                    627: function uncheckAll(field) {
                    628:     if (field.length > 0) {
                    629:         for (i = 0; i < field.length; i++) {
                    630:             field[i].checked = false ;
1.543     albertel  631:         }
                    632:     } else {
1.273     raeburn   633:         field.checked = false ;
                    634:     }
                    635: }
                    636: ENDSCRT
                    637:     return $jscript;
                    638: }
                    639: 
1.656     www       640: sub select_timezone {
1.659     raeburn   641:    my ($name,$selected,$onchange,$includeempty)=@_;
                    642:    my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    643:    if ($includeempty) {
                    644:        $output .= '<option value=""';
                    645:        if (($selected eq '') || ($selected eq 'local')) {
                    646:            $output .= ' selected="selected" ';
                    647:        }
                    648:        $output .= '> </option>';
                    649:    }
1.657     raeburn   650:    my @timezones = DateTime::TimeZone->all_names;
                    651:    foreach my $tzone (@timezones) {
                    652:        $output.= '<option value="'.$tzone.'"';
                    653:        if ($tzone eq $selected) {
                    654:            $output.=' selected="selected"';
                    655:        }
                    656:        $output.=">$tzone</option>\n";
1.656     www       657:    }
                    658:    $output.="</select>";
                    659:    return $output;
                    660: }
1.273     raeburn   661: 
1.687     raeburn   662: sub select_datelocale {
                    663:     my ($name,$selected,$onchange,$includeempty)=@_;
                    664:     my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    665:     if ($includeempty) {
                    666:         $output .= '<option value=""';
                    667:         if ($selected eq '') {
                    668:             $output .= ' selected="selected" ';
                    669:         }
                    670:         $output .= '> </option>';
                    671:     }
                    672:     my (@possibles,%locale_names);
                    673:     my @locales = DateTime::Locale::Catalog::Locales;
                    674:     foreach my $locale (@locales) {
                    675:         if (ref($locale) eq 'HASH') {
                    676:             my $id = $locale->{'id'};
                    677:             if ($id ne '') {
                    678:                 my $en_terr = $locale->{'en_territory'};
                    679:                 my $native_terr = $locale->{'native_territory'};
1.695     raeburn   680:                 my @languages = &Apache::lonlocal::preferred_languages();
1.687     raeburn   681:                 if (grep(/^en$/,@languages) || !@languages) {
                    682:                     if ($en_terr ne '') {
                    683:                         $locale_names{$id} = '('.$en_terr.')';
                    684:                     } elsif ($native_terr ne '') {
                    685:                         $locale_names{$id} = $native_terr;
                    686:                     }
                    687:                 } else {
                    688:                     if ($native_terr ne '') {
                    689:                         $locale_names{$id} = $native_terr.' ';
                    690:                     } elsif ($en_terr ne '') {
                    691:                         $locale_names{$id} = '('.$en_terr.')';
                    692:                     }
                    693:                 }
                    694:                 push (@possibles,$id);
                    695:             }
                    696:         }
                    697:     }
                    698:     foreach my $item (sort(@possibles)) {
                    699:         $output.= '<option value="'.$item.'"';
                    700:         if ($item eq $selected) {
                    701:             $output.=' selected="selected"';
                    702:         }
                    703:         $output.=">$item";
                    704:         if ($locale_names{$item} ne '') {
                    705:             $output.="  $locale_names{$item}</option>\n";
                    706:         }
                    707:         $output.="</option>\n";
                    708:     }
                    709:     $output.="</select>";
                    710:     return $output;
                    711: }
                    712: 
1.42      matthew   713: =pod
1.36      matthew   714: 
1.648     raeburn   715: =item * &linked_select_forms(...)
1.36      matthew   716: 
                    717: linked_select_forms returns a string containing a <script></script> block
                    718: and html for two <select> menus.  The select menus will be linked in that
                    719: changing the value of the first menu will result in new values being placed
                    720: in the second menu.  The values in the select menu will appear in alphabetical
1.609     raeburn   721: order unless a defined order is provided.
1.36      matthew   722: 
                    723: linked_select_forms takes the following ordered inputs:
                    724: 
                    725: =over 4
                    726: 
1.112     bowersj2  727: =item * $formname, the name of the <form> tag
1.36      matthew   728: 
1.112     bowersj2  729: =item * $middletext, the text which appears between the <select> tags
1.36      matthew   730: 
1.112     bowersj2  731: =item * $firstdefault, the default value for the first menu
1.36      matthew   732: 
1.112     bowersj2  733: =item * $firstselectname, the name of the first <select> tag
1.36      matthew   734: 
1.112     bowersj2  735: =item * $secondselectname, the name of the second <select> tag
1.36      matthew   736: 
1.112     bowersj2  737: =item * $hashref, a reference to a hash containing the data for the menus.
1.36      matthew   738: 
1.609     raeburn   739: =item * $menuorder, the order of values in the first menu
                    740: 
1.41      ng        741: =back 
                    742: 
1.36      matthew   743: Below is an example of such a hash.  Only the 'text', 'default', and 
                    744: 'select2' keys must appear as stated.  keys(%menu) are the possible 
                    745: values for the first select menu.  The text that coincides with the 
1.41      ng        746: first menu value is given in $menu{$choice1}->{'text'}.  The values 
1.36      matthew   747: and text for the second menu are given in the hash pointed to by 
                    748: $menu{$choice1}->{'select2'}.  
                    749: 
1.112     bowersj2  750:  my %menu = ( A1 => { text =>"Choice A1" ,
                    751:                        default => "B3",
                    752:                        select2 => { 
                    753:                            B1 => "Choice B1",
                    754:                            B2 => "Choice B2",
                    755:                            B3 => "Choice B3",
                    756:                            B4 => "Choice B4"
1.609     raeburn   757:                            },
                    758:                        order => ['B4','B3','B1','B2'],
1.112     bowersj2  759:                    },
                    760:                A2 => { text =>"Choice A2" ,
                    761:                        default => "C2",
                    762:                        select2 => { 
                    763:                            C1 => "Choice C1",
                    764:                            C2 => "Choice C2",
                    765:                            C3 => "Choice C3"
1.609     raeburn   766:                            },
                    767:                        order => ['C2','C1','C3'],
1.112     bowersj2  768:                    },
                    769:                A3 => { text =>"Choice A3" ,
                    770:                        default => "D6",
                    771:                        select2 => { 
                    772:                            D1 => "Choice D1",
                    773:                            D2 => "Choice D2",
                    774:                            D3 => "Choice D3",
                    775:                            D4 => "Choice D4",
                    776:                            D5 => "Choice D5",
                    777:                            D6 => "Choice D6",
                    778:                            D7 => "Choice D7"
1.609     raeburn   779:                            },
                    780:                        order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112     bowersj2  781:                    }
                    782:                );
1.36      matthew   783: 
                    784: =cut
                    785: 
                    786: sub linked_select_forms {
                    787:     my ($formname,
                    788:         $middletext,
                    789:         $firstdefault,
                    790:         $firstselectname,
                    791:         $secondselectname, 
1.609     raeburn   792:         $hashref,
                    793:         $menuorder,
1.36      matthew   794:         ) = @_;
                    795:     my $second = "document.$formname.$secondselectname";
                    796:     my $first = "document.$formname.$firstselectname";
                    797:     # output the javascript to do the changing
                    798:     my $result = '';
1.219     albertel  799:     $result.="<script type=\"text/javascript\">\n";
1.36      matthew   800:     $result.="var select2data = new Object();\n";
                    801:     $" = '","';
                    802:     my $debug = '';
                    803:     foreach my $s1 (sort(keys(%$hashref))) {
                    804:         $result.="select2data.d_$s1 = new Object();\n";        
                    805:         $result.="select2data.d_$s1.def = new String('".
                    806:             $hashref->{$s1}->{'default'}."');\n";
1.609     raeburn   807:         $result.="select2data.d_$s1.values = new Array(";
1.36      matthew   808:         my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609     raeburn   809:         if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
                    810:             @s2values = @{$hashref->{$s1}->{'order'}};
                    811:         }
1.36      matthew   812:         $result.="\"@s2values\");\n";
                    813:         $result.="select2data.d_$s1.texts = new Array(";        
                    814:         my @s2texts;
                    815:         foreach my $value (@s2values) {
                    816:             push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
                    817:         }
                    818:         $result.="\"@s2texts\");\n";
                    819:     }
                    820:     $"=' ';
                    821:     $result.= <<"END";
                    822: 
                    823: function select1_changed() {
                    824:     // Determine new choice
                    825:     var newvalue = "d_" + $first.value;
                    826:     // update select2
                    827:     var values     = select2data[newvalue].values;
                    828:     var texts      = select2data[newvalue].texts;
                    829:     var select2def = select2data[newvalue].def;
                    830:     var i;
                    831:     // out with the old
                    832:     for (i = 0; i < $second.options.length; i++) {
                    833:         $second.options[i] = null;
                    834:     }
                    835:     // in with the nuclear
                    836:     for (i=0;i<values.length; i++) {
                    837:         $second.options[i] = new Option(values[i]);
1.143     matthew   838:         $second.options[i].value = values[i];
1.36      matthew   839:         $second.options[i].text = texts[i];
                    840:         if (values[i] == select2def) {
                    841:             $second.options[i].selected = true;
                    842:         }
                    843:     }
                    844: }
                    845: </script>
                    846: END
                    847:     # output the initial values for the selection lists
                    848:     $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609     raeburn   849:     my @order = sort(keys(%{$hashref}));
                    850:     if (ref($menuorder) eq 'ARRAY') {
                    851:         @order = @{$menuorder};
                    852:     }
                    853:     foreach my $value (@order) {
1.36      matthew   854:         $result.="    <option value=\"$value\" ";
1.253     albertel  855:         $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119     www       856:         $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36      matthew   857:     }
                    858:     $result .= "</select>\n";
                    859:     my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
                    860:     $result .= $middletext;
                    861:     $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
                    862:     my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609     raeburn   863:     
                    864:     my @secondorder = sort(keys(%select2));
                    865:     if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
                    866:         @secondorder = @{$hashref->{$firstdefault}->{'order'}};
                    867:     }
                    868:     foreach my $value (@secondorder) {
1.36      matthew   869:         $result.="    <option value=\"$value\" ";        
1.253     albertel  870:         $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119     www       871:         $result.=">".&mt($select2{$value})."</option>\n";
1.36      matthew   872:     }
                    873:     $result .= "</select>\n";
                    874:     #    return $debug;
                    875:     return $result;
                    876: }   #  end of sub linked_select_forms {
                    877: 
1.45      matthew   878: =pod
1.44      bowersj2  879: 
1.648     raeburn   880: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
1.44      bowersj2  881: 
1.112     bowersj2  882: Returns a string corresponding to an HTML link to the given help
                    883: $topic, where $topic corresponds to the name of a .tex file in
                    884: /home/httpd/html/adm/help/tex, with underscores replaced by
                    885: spaces. 
                    886: 
                    887: $text will optionally be linked to the same topic, allowing you to
                    888: link text in addition to the graphic. If you do not want to link
                    889: text, but wish to specify one of the later parameters, pass an
                    890: empty string. 
                    891: 
                    892: $stayOnPage is a value that will be interpreted as a boolean. If true,
                    893: the link will not open a new window. If false, the link will open
                    894: a new window using Javascript. (Default is false.) 
                    895: 
                    896: $width and $height are optional numerical parameters that will
                    897: override the width and height of the popped up window, which may
                    898: be useful for certain help topics with big pictures included. 
1.44      bowersj2  899: 
                    900: =cut
                    901: 
                    902: sub help_open_topic {
1.48      bowersj2  903:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
                    904:     $text = "" if (not defined $text);
1.44      bowersj2  905:     $stayOnPage = 0 if (not defined $stayOnPage);
1.552     banghart  906:     if ($env{'browser.interface'} eq 'textual') {
1.79      www       907: 	$stayOnPage=1;
                    908:     }
1.44      bowersj2  909:     $width = 350 if (not defined $width);
                    910:     $height = 400 if (not defined $height);
                    911:     my $filename = $topic;
                    912:     $filename =~ s/ /_/g;
                    913: 
1.48      bowersj2  914:     my $template = "";
                    915:     my $link;
1.572     banghart  916:     
1.159     www       917:     $topic=~s/\W/\_/g;
1.44      bowersj2  918: 
1.572     banghart  919:     if (!$stayOnPage) {
1.72      bowersj2  920: 	$link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1.572     banghart  921:     } else {
1.48      bowersj2  922: 	$link = "/adm/help/${filename}.hlp";
                    923:     }
                    924: 
                    925:     # Add the text
1.572     banghart  926:     if ($text ne "") {
1.77      www       927: 	$template .= 
1.572     banghart  928:             "<table bgcolor='#3333AA' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho  929:             "<td bgcolor='#5555FF'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.48      bowersj2  930:     }
                    931: 
                    932:     # Add the graphic
1.179     matthew   933:     my $title = &mt('Online Help');
1.667     raeburn   934:     my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.48      bowersj2  935:     $template .= <<"ENDTEMPLATE";
1.436     albertel  936:  <a target="_top" href="$link" title="$title"><img src="$helpicon" border="0" alt="(Help: $topic)" /></a>
1.44      bowersj2  937: ENDTEMPLATE
1.705     tempelho  938:     if ($text ne '') { $template.='</td></tr></table>' };
1.44      bowersj2  939:     return $template;
                    940: 
1.106     bowersj2  941: }
                    942: 
                    943: # This is a quicky function for Latex cheatsheet editing, since it 
                    944: # appears in at least four places
                    945: sub helpLatexCheatsheet {
                    946:     my $other = shift;
                    947:     my $addOther = '';
                    948:     if ($other) {
                    949: 	$addOther = Apache::loncommon::help_open_topic($other, shift,
                    950: 						       undef, undef, 600) .
                    951: 							   '</td><td>';
                    952:     }
                    953:     return '<table><tr><td>'.
                    954: 	$addOther .
1.636     raeburn   955: 	&Apache::loncommon::help_open_topic("Greek_Symbols",&mt('Greek Symbols'),
1.106     bowersj2  956: 					    undef,undef,600)
                    957: 	.'</td><td>'.
1.636     raeburn   958: 	&Apache::loncommon::help_open_topic("Other_Symbols",&mt('Other Symbols'),
1.106     bowersj2  959: 					    undef,undef,600)
1.673     felicia   960: 	.'</td><td>'.
                    961: 	&Apache::loncommon::help_open_topic("Authoring_Output_Tags",&mt('Output Tags'),
                    962: 	                                    undef,undef,600)
1.106     bowersj2  963: 	.'</td></tr></table>';
1.172     www       964: }
                    965: 
1.430     albertel  966: sub general_help {
                    967:     my $helptopic='Student_Intro';
                    968:     if ($env{'request.role'}=~/^(ca|au)/) {
                    969: 	$helptopic='Authoring_Intro';
                    970:     } elsif ($env{'request.role'}=~/^cc/) {
                    971: 	$helptopic='Course_Coordination_Intro';
1.672     raeburn   972:     } elsif ($env{'request.role'}=~/^dc/) {
                    973:         $helptopic='Domain_Coordination_Intro';
1.430     albertel  974:     }
                    975:     return $helptopic;
                    976: }
                    977: 
                    978: sub update_help_link {
                    979:     my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
                    980:     my $origurl = $ENV{'REQUEST_URI'};
                    981:     $origurl=~s|^/~|/priv/|;
                    982:     my $timestamp = time;
                    983:     foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
                    984:         $$datum = &escape($$datum);
                    985:     }
                    986: 
                    987:     my $banner_link = "/adm/helpmenu?page=banner&amp;topic=$topic&amp;component_help=$component_help&amp;faq=$faq&amp;bug=$bug&amp;origurl=$origurl&amp;stamp=$timestamp&amp;stayonpage=$stayOnPage";
                    988:     my $output .= <<"ENDOUTPUT";
                    989: <script type="text/javascript">
                    990: banner_link = '$banner_link';
                    991: </script>
                    992: ENDOUTPUT
                    993:     return $output;
                    994: }
                    995: 
                    996: # now just updates the help link and generates a blue icon
1.193     raeburn   997: sub help_open_menu {
1.430     albertel  998:     my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text) 
1.552     banghart  999: 	= @_;    
1.430     albertel 1000:     $stayOnPage = 0 if (not defined $stayOnPage);
1.572     banghart 1001:     # only use pop-up help (stayOnPage == 0)
1.552     banghart 1002:     # if environment.remote is on (using remote control UI)
1.572     banghart 1003:     if ($env{'browser.interface'} eq 'textual' ||
                   1004:     	$env{'environment.remote'} eq 'off' ) {
1.552     banghart 1005:         $stayOnPage=1;
1.430     albertel 1006:     }
                   1007:     my $output;
                   1008:     if ($component_help) {
                   1009: 	if (!$text) {
                   1010: 	    $output=&help_open_topic($component_help,undef,$stayOnPage,
                   1011: 				       $width,$height);
                   1012: 	} else {
                   1013: 	    my $help_text;
                   1014: 	    $help_text=&unescape($topic);
                   1015: 	    $output='<table><tr><td>'.
                   1016: 		&help_open_topic($component_help,$help_text,$stayOnPage,
                   1017: 				 $width,$height).'</td></tr></table>';
                   1018: 	}
                   1019:     }
                   1020:     my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
                   1021:     return $output.$banner_link;
                   1022: }
                   1023: 
                   1024: sub top_nav_help {
                   1025:     my ($text) = @_;
1.436     albertel 1026:     $text = &mt($text);
1.572     banghart 1027:     my $stay_on_page = 
1.436     albertel 1028: 	($env{'browser.interface'}  eq 'textual' ||
                   1029: 	 $env{'environment.remote'} eq 'off' );
1.572     banghart 1030:     my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436     albertel 1031: 	                     : "javascript:helpMenu('open')";
1.572     banghart 1032:     my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436     albertel 1033: 
1.201     raeburn  1034:     my $title = &mt('Get help');
1.436     albertel 1035: 
                   1036:     return <<"END";
                   1037: $banner_link
                   1038:  <a href="$link" title="$title">$text</a>
                   1039: END
                   1040: }
                   1041: 
                   1042: sub help_menu_js {
                   1043:     my ($text) = @_;
                   1044: 
                   1045:     my $stayOnPage = 
                   1046: 	($env{'browser.interface'}  eq 'textual' ||
                   1047: 	 $env{'environment.remote'} eq 'off' );
                   1048: 
                   1049:     my $width = 620;
                   1050:     my $height = 600;
1.430     albertel 1051:     my $helptopic=&general_help();
                   1052:     my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261     albertel 1053:     my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331     albertel 1054:     my $start_page =
                   1055:         &Apache::loncommon::start_page('Help Menu', undef,
                   1056: 				       {'frameset'    => 1,
                   1057: 					'js_ready'    => 1,
                   1058: 					'add_entries' => {
                   1059: 					    'border' => '0',
1.579     raeburn  1060: 					    'rows'   => "110,*",},});
1.331     albertel 1061:     my $end_page =
                   1062:         &Apache::loncommon::end_page({'frameset' => 1,
                   1063: 				      'js_ready' => 1,});
                   1064: 
1.436     albertel 1065:     my $template .= <<"ENDTEMPLATE";
                   1066: <script type="text/javascript">
1.253     albertel 1067: // <!-- BEGIN LON-CAPA Internal
                   1068: // <![CDATA[
1.430     albertel 1069: var banner_link = '';
1.243     raeburn  1070: function helpMenu(target) {
                   1071:     var caller = this;
                   1072:     if (target == 'open') {
                   1073:         var newWindow = null;
                   1074:         try {
1.262     albertel 1075:             newWindow =  window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243     raeburn  1076:         }
                   1077:         catch(error) {
                   1078:             writeHelp(caller);
                   1079:             return;
                   1080:         }
                   1081:         if (newWindow) {
                   1082:             caller = newWindow;
                   1083:         }
1.193     raeburn  1084:     }
1.243     raeburn  1085:     writeHelp(caller);
                   1086:     return;
                   1087: }
                   1088: function writeHelp(caller) {
1.430     albertel 1089:     caller.document.writeln('$start_page<frame name="bannerframe"  src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243     raeburn  1090:     caller.document.close()
                   1091:     caller.focus()
1.193     raeburn  1092: }
1.253     albertel 1093: // ]]>
1.219     albertel 1094: // END LON-CAPA Internal -->
1.436     albertel 1095: </script>
1.193     raeburn  1096: ENDTEMPLATE
                   1097:     return $template;
                   1098: }
                   1099: 
1.172     www      1100: sub help_open_bug {
                   1101:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1102:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1103:     unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
                   1104:     $text = "" if (not defined $text);
                   1105:     $stayOnPage = 0 if (not defined $stayOnPage);
1.258     albertel 1106:     if ($env{'browser.interface'} eq 'textual' ||
                   1107: 	$env{'environment.remote'} eq 'off' ) {
1.172     www      1108: 	$stayOnPage=1;
                   1109:     }
1.184     albertel 1110:     $width = 600 if (not defined $width);
                   1111:     $height = 600 if (not defined $height);
1.172     www      1112: 
                   1113:     $topic=~s/\W+/\+/g;
                   1114:     my $link='';
                   1115:     my $template='';
1.379     albertel 1116:     my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&amp;bug_file_loc='.
                   1117: 	&escape($ENV{'REQUEST_URI'}).'&amp;component='.$topic;
1.172     www      1118:     if (!$stayOnPage)
                   1119:     {
                   1120: 	$link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1121:     }
                   1122:     else
                   1123:     {
                   1124: 	$link = $url;
                   1125:     }
                   1126:     # Add the text
                   1127:     if ($text ne "")
                   1128:     {
                   1129: 	$template .= 
                   1130:   "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1131:   "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172     www      1132:     }
                   1133: 
                   1134:     # Add the graphic
1.179     matthew  1135:     my $title = &mt('Report a Bug');
1.215     albertel 1136:     my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172     www      1137:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1138:  <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172     www      1139: ENDTEMPLATE
                   1140:     if ($text ne '') { $template.='</td></tr></table>' };
                   1141:     return $template;
                   1142: 
                   1143: }
                   1144: 
                   1145: sub help_open_faq {
                   1146:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1147:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1148:     unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
                   1149:     $text = "" if (not defined $text);
                   1150:     $stayOnPage = 0 if (not defined $stayOnPage);
1.258     albertel 1151:     if ($env{'browser.interface'} eq 'textual' ||
                   1152: 	$env{'environment.remote'} eq 'off' ) {
1.172     www      1153: 	$stayOnPage=1;
                   1154:     }
                   1155:     $width = 350 if (not defined $width);
                   1156:     $height = 400 if (not defined $height);
                   1157: 
                   1158:     $topic=~s/\W+/\+/g;
                   1159:     my $link='';
                   1160:     my $template='';
                   1161:     my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
                   1162:     if (!$stayOnPage)
                   1163:     {
                   1164: 	$link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1165:     }
                   1166:     else
                   1167:     {
                   1168: 	$link = $url;
                   1169:     }
                   1170: 
                   1171:     # Add the text
                   1172:     if ($text ne "")
                   1173:     {
                   1174: 	$template .= 
1.173     www      1175:   "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1176:   "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172     www      1177:     }
                   1178: 
                   1179:     # Add the graphic
1.179     matthew  1180:     my $title = &mt('View the FAQ');
1.215     albertel 1181:     my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172     www      1182:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1183:  <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172     www      1184: ENDTEMPLATE
                   1185:     if ($text ne '') { $template.='</td></tr></table>' };
                   1186:     return $template;
                   1187: 
1.44      bowersj2 1188: }
1.37      matthew  1189: 
1.180     matthew  1190: ###############################################################
                   1191: ###############################################################
                   1192: 
1.45      matthew  1193: =pod
                   1194: 
1.648     raeburn  1195: =item * &change_content_javascript():
1.256     matthew  1196: 
                   1197: This and the next function allow you to create small sections of an
                   1198: otherwise static HTML page that you can update on the fly with
                   1199: Javascript, even in Netscape 4.
                   1200: 
                   1201: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
                   1202: must be written to the HTML page once. It will prove the Javascript
                   1203: function "change(name, content)". Calling the change function with the
                   1204: name of the section 
                   1205: you want to update, matching the name passed to C<changable_area>, and
                   1206: the new content you want to put in there, will put the content into
                   1207: that area.
                   1208: 
                   1209: B<Note>: Netscape 4 only reserves enough space for the changable area
                   1210: to contain room for the original contents. You need to "make space"
                   1211: for whatever changes you wish to make, and be B<sure> to check your
                   1212: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
                   1213: it's adequate for updating a one-line status display, but little more.
                   1214: This script will set the space to 100% width, so you only need to
                   1215: worry about height in Netscape 4.
                   1216: 
                   1217: Modern browsers are much less limiting, and if you can commit to the
                   1218: user not using Netscape 4, this feature may be used freely with
                   1219: pretty much any HTML.
                   1220: 
                   1221: =cut
                   1222: 
                   1223: sub change_content_javascript {
                   1224:     # If we're on Netscape 4, we need to use Layer-based code
1.258     albertel 1225:     if ($env{'browser.type'} eq 'netscape' &&
                   1226: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1227: 	return (<<NETSCAPE4);
                   1228: 	function change(name, content) {
                   1229: 	    doc = document.layers[name+"___escape"].layers[0].document;
                   1230: 	    doc.open();
                   1231: 	    doc.write(content);
                   1232: 	    doc.close();
                   1233: 	}
                   1234: NETSCAPE4
                   1235:     } else {
                   1236: 	# Otherwise, we need to use semi-standards-compliant code
                   1237: 	# (technically, "innerHTML" isn't standard but the equivalent
                   1238: 	# is really scary, and every useful browser supports it
                   1239: 	return (<<DOMBASED);
                   1240: 	function change(name, content) {
                   1241: 	    element = document.getElementById(name);
                   1242: 	    element.innerHTML = content;
                   1243: 	}
                   1244: DOMBASED
                   1245:     }
                   1246: }
                   1247: 
                   1248: =pod
                   1249: 
1.648     raeburn  1250: =item * &changable_area($name,$origContent):
1.256     matthew  1251: 
                   1252: This provides a "changable area" that can be modified on the fly via
                   1253: the Javascript code provided in C<change_content_javascript>. $name is
                   1254: the name you will use to reference the area later; do not repeat the
                   1255: same name on a given HTML page more then once. $origContent is what
                   1256: the area will originally contain, which can be left blank.
                   1257: 
                   1258: =cut
                   1259: 
                   1260: sub changable_area {
                   1261:     my ($name, $origContent) = @_;
                   1262: 
1.258     albertel 1263:     if ($env{'browser.type'} eq 'netscape' &&
                   1264: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1265: 	# If this is netscape 4, we need to use the Layer tag
                   1266: 	return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
                   1267:     } else {
                   1268: 	return "<span id='$name'>$origContent</span>";
                   1269:     }
                   1270: }
                   1271: 
                   1272: =pod
                   1273: 
1.648     raeburn  1274: =item * &viewport_geometry_js 
1.590     raeburn  1275: 
                   1276: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
                   1277: 
                   1278: =cut
                   1279: 
                   1280: 
                   1281: sub viewport_geometry_js { 
                   1282:     return <<"GEOMETRY";
                   1283: var Geometry = {};
                   1284: function init_geometry() {
                   1285:     if (Geometry.init) { return };
                   1286:     Geometry.init=1;
                   1287:     if (window.innerHeight) {
                   1288:         Geometry.getViewportHeight   = function() { return window.innerHeight; };
                   1289:         Geometry.getViewportWidth   = function() { return window.innerWidth; };
                   1290:         Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
                   1291:         Geometry.getVerticalScroll   = function() { return window.pageYOffset; };
                   1292:     }
                   1293:     else if (document.documentElement && document.documentElement.clientHeight) {
                   1294:         Geometry.getViewportHeight =
                   1295:             function() { return document.documentElement.clientHeight; };
                   1296:         Geometry.getViewportWidth =
                   1297:             function() { return document.documentElement.clientWidth; };
                   1298: 
                   1299:         Geometry.getHorizontalScroll =
                   1300:             function() { return document.documentElement.scrollLeft; };
                   1301:         Geometry.getVerticalScroll =
                   1302:             function() { return document.documentElement.scrollTop; };
                   1303:     }
                   1304:     else if (document.body.clientHeight) {
                   1305:         Geometry.getViewportHeight =
                   1306:             function() { return document.body.clientHeight; };
                   1307:         Geometry.getViewportWidth =
                   1308:             function() { return document.body.clientWidth; };
                   1309:         Geometry.getHorizontalScroll =
                   1310:             function() { return document.body.scrollLeft; };
                   1311:         Geometry.getVerticalScroll =
                   1312:             function() { return document.body.scrollTop; };
                   1313:     }
                   1314: }
                   1315: 
                   1316: GEOMETRY
                   1317: }
                   1318: 
                   1319: =pod
                   1320: 
1.648     raeburn  1321: =item * &viewport_size_js()
1.590     raeburn  1322: 
                   1323: Provides a javascript function to set values of two form elements - width and height (elements are passed in as arguments to the javascript function) to the dimensions of the user's browser window. 
                   1324: 
                   1325: =cut
                   1326: 
                   1327: sub viewport_size_js {
                   1328:     my $geometry = &viewport_geometry_js();
                   1329:     return <<"DIMS";
                   1330: 
                   1331: $geometry
                   1332: 
                   1333: function getViewportDims(width,height) {
                   1334:     init_geometry();
                   1335:     width.value = Geometry.getViewportWidth();
                   1336:     height.value = Geometry.getViewportHeight();
                   1337:     return;
                   1338: }
                   1339: 
                   1340: DIMS
                   1341: }
                   1342: 
                   1343: =pod
                   1344: 
1.648     raeburn  1345: =item * &resize_textarea_js()
1.565     albertel 1346: 
                   1347: emits the needed javascript to resize a textarea to be as big as possible
                   1348: 
                   1349: creates a function resize_textrea that takes two IDs first should be
                   1350: the id of the element to resize, second should be the id of a div that
                   1351: surrounds everything that comes after the textarea, this routine needs
                   1352: to be attached to the <body> for the onload and onresize events.
                   1353: 
1.648     raeburn  1354: =back
1.565     albertel 1355: 
                   1356: =cut
                   1357: 
                   1358: sub resize_textarea_js {
1.590     raeburn  1359:     my $geometry = &viewport_geometry_js();
1.565     albertel 1360:     return <<"RESIZE";
                   1361:     <script type="text/javascript">
1.590     raeburn  1362: $geometry
1.565     albertel 1363: 
1.588     albertel 1364: function getX(element) {
                   1365:     var x = 0;
                   1366:     while (element) {
                   1367: 	x += element.offsetLeft;
                   1368: 	element = element.offsetParent;
                   1369:     }
                   1370:     return x;
                   1371: }
                   1372: function getY(element) {
                   1373:     var y = 0;
                   1374:     while (element) {
                   1375: 	y += element.offsetTop;
                   1376: 	element = element.offsetParent;
                   1377:     }
                   1378:     return y;
                   1379: }
                   1380: 
                   1381: 
1.565     albertel 1382: function resize_textarea(textarea_id,bottom_id) {
                   1383:     init_geometry();
                   1384:     var textarea        = document.getElementById(textarea_id);
                   1385:     //alert(textarea);
                   1386: 
1.588     albertel 1387:     var textarea_top    = getY(textarea);
1.565     albertel 1388:     var textarea_height = textarea.offsetHeight;
                   1389:     var bottom          = document.getElementById(bottom_id);
1.588     albertel 1390:     var bottom_top      = getY(bottom);
1.565     albertel 1391:     var bottom_height   = bottom.offsetHeight;
                   1392:     var window_height   = Geometry.getViewportHeight();
1.588     albertel 1393:     var fudge           = 23;
1.565     albertel 1394:     var new_height      = window_height-fudge-textarea_top-bottom_height;
                   1395:     if (new_height < 300) {
                   1396: 	new_height = 300;
                   1397:     }
                   1398:     textarea.style.height=new_height+'px';
                   1399: }
                   1400: </script>
                   1401: RESIZE
                   1402: 
                   1403: }
                   1404: 
                   1405: =pod
                   1406: 
1.256     matthew  1407: =head1 Excel and CSV file utility routines
                   1408: 
                   1409: =over 4
                   1410: 
                   1411: =cut
                   1412: 
                   1413: ###############################################################
                   1414: ###############################################################
                   1415: 
                   1416: =pod
                   1417: 
1.648     raeburn  1418: =item * &csv_translate($text) 
1.37      matthew  1419: 
1.185     www      1420: Translate $text to allow it to be output as a 'comma separated values' 
1.37      matthew  1421: format.
                   1422: 
                   1423: =cut
                   1424: 
1.180     matthew  1425: ###############################################################
                   1426: ###############################################################
1.37      matthew  1427: sub csv_translate {
                   1428:     my $text = shift;
                   1429:     $text =~ s/\"/\"\"/g;
1.209     albertel 1430:     $text =~ s/\n/ /g;
1.37      matthew  1431:     return $text;
                   1432: }
1.180     matthew  1433: 
                   1434: ###############################################################
                   1435: ###############################################################
                   1436: 
                   1437: =pod
                   1438: 
1.648     raeburn  1439: =item * &define_excel_formats()
1.180     matthew  1440: 
                   1441: Define some commonly used Excel cell formats.
                   1442: 
                   1443: Currently supported formats:
                   1444: 
                   1445: =over 4
                   1446: 
                   1447: =item header
                   1448: 
                   1449: =item bold
                   1450: 
                   1451: =item h1
                   1452: 
                   1453: =item h2
                   1454: 
                   1455: =item h3
                   1456: 
1.256     matthew  1457: =item h4
                   1458: 
                   1459: =item i
                   1460: 
1.180     matthew  1461: =item date
                   1462: 
                   1463: =back
                   1464: 
                   1465: Inputs: $workbook
                   1466: 
                   1467: Returns: $format, a hash reference.
                   1468: 
                   1469: =cut
                   1470: 
                   1471: ###############################################################
                   1472: ###############################################################
                   1473: sub define_excel_formats {
                   1474:     my ($workbook) = @_;
                   1475:     my $format;
                   1476:     $format->{'header'} = $workbook->add_format(bold      => 1, 
                   1477:                                                 bottom    => 1,
                   1478:                                                 align     => 'center');
                   1479:     $format->{'bold'} = $workbook->add_format(bold=>1);
                   1480:     $format->{'h1'}   = $workbook->add_format(bold=>1, size=>18);
                   1481:     $format->{'h2'}   = $workbook->add_format(bold=>1, size=>16);
                   1482:     $format->{'h3'}   = $workbook->add_format(bold=>1, size=>14);
1.255     matthew  1483:     $format->{'h4'}   = $workbook->add_format(bold=>1, size=>12);
1.246     matthew  1484:     $format->{'i'}    = $workbook->add_format(italic=>1);
1.180     matthew  1485:     $format->{'date'} = $workbook->add_format(num_format=>
1.207     matthew  1486:                                             'mm/dd/yyyy hh:mm:ss');
1.180     matthew  1487:     return $format;
                   1488: }
                   1489: 
                   1490: ###############################################################
                   1491: ###############################################################
1.113     bowersj2 1492: 
                   1493: =pod
                   1494: 
1.648     raeburn  1495: =item * &create_workbook()
1.255     matthew  1496: 
                   1497: Create an Excel worksheet.  If it fails, output message on the
                   1498: request object and return undefs.
                   1499: 
                   1500: Inputs: Apache request object
                   1501: 
                   1502: Returns (undef) on failure, 
                   1503:     Excel worksheet object, scalar with filename, and formats 
                   1504:     from &Apache::loncommon::define_excel_formats on success
                   1505: 
                   1506: =cut
                   1507: 
                   1508: ###############################################################
                   1509: ###############################################################
                   1510: sub create_workbook {
                   1511:     my ($r) = @_;
                   1512:         #
                   1513:     # Create the excel spreadsheet
                   1514:     my $filename = '/prtspool/'.
1.258     albertel 1515:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255     matthew  1516:         time.'_'.rand(1000000000).'.xls';
                   1517:     my $workbook  = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
                   1518:     if (! defined($workbook)) {
                   1519:         $r->log_error("Error creating excel spreadsheet $filename: $!");
                   1520:         $r->print('<p>'.&mt("Unable to create new Excel file.  ".
                   1521:                             "This error has been logged.  ".
                   1522:                             "Please alert your LON-CAPA administrator").
                   1523:                   '</p>');
                   1524:         return (undef);
                   1525:     }
                   1526:     #
                   1527:     $workbook->set_tempdir('/home/httpd/perl/tmp');
                   1528:     #
                   1529:     my $format = &Apache::loncommon::define_excel_formats($workbook);
                   1530:     return ($workbook,$filename,$format);
                   1531: }
                   1532: 
                   1533: ###############################################################
                   1534: ###############################################################
                   1535: 
                   1536: =pod
                   1537: 
1.648     raeburn  1538: =item * &create_text_file()
1.113     bowersj2 1539: 
1.542     raeburn  1540: Create a file to write to and eventually make available to the user.
1.256     matthew  1541: If file creation fails, outputs an error message on the request object and 
                   1542: return undefs.
1.113     bowersj2 1543: 
1.256     matthew  1544: Inputs: Apache request object, and file suffix
1.113     bowersj2 1545: 
1.256     matthew  1546: Returns (undef) on failure, 
                   1547:     Filehandle and filename on success.
1.113     bowersj2 1548: 
                   1549: =cut
                   1550: 
1.256     matthew  1551: ###############################################################
                   1552: ###############################################################
                   1553: sub create_text_file {
                   1554:     my ($r,$suffix) = @_;
                   1555:     if (! defined($suffix)) { $suffix = 'txt'; };
                   1556:     my $fh;
                   1557:     my $filename = '/prtspool/'.
1.258     albertel 1558:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256     matthew  1559:         time.'_'.rand(1000000000).'.'.$suffix;
                   1560:     $fh = Apache::File->new('>/home/httpd'.$filename);
                   1561:     if (! defined($fh)) {
                   1562:         $r->log_error("Couldn't open $filename for output $!");
1.683     bisitz   1563:         $r->print(&mt('Problems occurred in creating the output file. '
                   1564:                      .'This error has been logged. '
                   1565:                      .'Please alert your LON-CAPA administrator.'));
1.113     bowersj2 1566:     }
1.256     matthew  1567:     return ($fh,$filename)
1.113     bowersj2 1568: }
                   1569: 
                   1570: 
1.256     matthew  1571: =pod 
1.113     bowersj2 1572: 
                   1573: =back
                   1574: 
                   1575: =cut
1.37      matthew  1576: 
                   1577: ###############################################################
1.33      matthew  1578: ##        Home server <option> list generating code          ##
                   1579: ###############################################################
1.35      matthew  1580: 
1.169     www      1581: # ------------------------------------------
                   1582: 
                   1583: sub domain_select {
                   1584:     my ($name,$value,$multiple)=@_;
                   1585:     my %domains=map { 
1.514     albertel 1586: 	$_ => $_.' '. &Apache::lonnet::domain($_,'description') 
1.512     albertel 1587:     } &Apache::lonnet::all_domains();
1.169     www      1588:     if ($multiple) {
                   1589: 	$domains{''}=&mt('Any domain');
1.550     albertel 1590: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287     albertel 1591: 	return &multiple_select_form($name,$value,4,\%domains);
1.169     www      1592:     } else {
1.550     albertel 1593: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169     www      1594: 	return &select_form($name,$value,%domains);
                   1595:     }
                   1596: }
                   1597: 
1.282     albertel 1598: #-------------------------------------------
                   1599: 
                   1600: =pod
                   1601: 
1.519     raeburn  1602: =head1 Routines for form select boxes
                   1603: 
                   1604: =over 4
                   1605: 
1.648     raeburn  1606: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282     albertel 1607: 
                   1608: Returns a string containing a <select> element int multiple mode
                   1609: 
                   1610: 
                   1611: Args:
                   1612:   $name - name of the <select> element
1.506     raeburn  1613:   $value - scalar or array ref of values that should already be selected
1.282     albertel 1614:   $size - number of rows long the select element is
1.283     albertel 1615:   $hash - the elements should be 'option' => 'shown text'
1.282     albertel 1616:           (shown text should already have been &mt())
1.506     raeburn  1617:   $order - (optional) array ref of the order to show the elements in
1.283     albertel 1618: 
1.282     albertel 1619: =cut
                   1620: 
                   1621: #-------------------------------------------
1.169     www      1622: sub multiple_select_form {
1.284     albertel 1623:     my ($name,$value,$size,$hash,$order)=@_;
1.169     www      1624:     my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
                   1625:     my $output='';
1.191     matthew  1626:     if (! defined($size)) {
                   1627:         $size = 4;
1.283     albertel 1628:         if (scalar(keys(%$hash))<4) {
                   1629:             $size = scalar(keys(%$hash));
1.191     matthew  1630:         }
                   1631:     }
1.169     www      1632:     $output.="\n<select name='$name' size='$size' multiple='1'>";
1.501     banghart 1633:     my @order;
1.506     raeburn  1634:     if (ref($order) eq 'ARRAY')  {
                   1635:         @order = @{$order};
                   1636:     } else {
                   1637:         @order = sort(keys(%$hash));
1.501     banghart 1638:     }
                   1639:     if (exists($$hash{'select_form_order'})) {
                   1640:         @order = @{$$hash{'select_form_order'}};
                   1641:     }
                   1642:         
1.284     albertel 1643:     foreach my $key (@order) {
1.356     albertel 1644:         $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284     albertel 1645:         $output.='selected="selected" ' if ($selected{$key});
                   1646:         $output.='>'.$hash->{$key}."</option>\n";
1.169     www      1647:     }
                   1648:     $output.="</select>\n";
                   1649:     return $output;
                   1650: }
                   1651: 
1.88      www      1652: #-------------------------------------------
                   1653: 
                   1654: =pod
                   1655: 
1.648     raeburn  1656: =item * &select_form($defdom,$name,%hash)
1.88      www      1657: 
                   1658: Returns a string containing a <select name='$name' size='1'> form to 
                   1659: allow a user to select options from a hash option_name => displayed text.  
                   1660: See lonrights.pm for an example invocation and use.
                   1661: 
                   1662: =cut
                   1663: 
                   1664: #-------------------------------------------
                   1665: sub select_form {
                   1666:     my ($def,$name,%hash) = @_;
                   1667:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128     albertel 1668:     my @keys;
                   1669:     if (exists($hash{'select_form_order'})) {
                   1670: 	@keys=@{$hash{'select_form_order'}};
                   1671:     } else {
                   1672: 	@keys=sort(keys(%hash));
                   1673:     }
1.356     albertel 1674:     foreach my $key (@keys) {
                   1675:         $selectform.=
                   1676: 	    '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
                   1677:             ($key eq $def ? 'selected="selected" ' : '').
                   1678:                 ">".&mt($hash{$key})."</option>\n";
1.88      www      1679:     }
                   1680:     $selectform.="</select>";
                   1681:     return $selectform;
                   1682: }
                   1683: 
1.475     www      1684: # For display filters
                   1685: 
                   1686: sub display_filter {
                   1687:     if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477     www      1688:     if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714     bisitz   1689:     return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475     www      1690: 			       &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
                   1691: 							   (&mt('all'),10,20,50,100,1000,10000))).
1.714     bisitz   1692: 	   '</label></span> <span class="LC_nobreak">'.
1.475     www      1693:            &mt('Filter [_1]',
1.477     www      1694: 	   &select_form($env{'form.displayfilter'},
                   1695: 			'displayfilter',
                   1696: 			('currentfolder' => 'Current folder/page',
                   1697: 			 'containing' => 'Containing phrase',
                   1698: 			 'none' => 'None'))).
1.714     bisitz   1699: 			 '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475     www      1700: }
                   1701: 
1.167     www      1702: sub gradeleveldescription {
                   1703:     my $gradelevel=shift;
                   1704:     my %gradelevels=(0 => 'Not specified',
                   1705: 		     1 => 'Grade 1',
                   1706: 		     2 => 'Grade 2',
                   1707: 		     3 => 'Grade 3',
                   1708: 		     4 => 'Grade 4',
                   1709: 		     5 => 'Grade 5',
                   1710: 		     6 => 'Grade 6',
                   1711: 		     7 => 'Grade 7',
                   1712: 		     8 => 'Grade 8',
                   1713: 		     9 => 'Grade 9',
                   1714: 		     10 => 'Grade 10',
                   1715: 		     11 => 'Grade 11',
                   1716: 		     12 => 'Grade 12',
                   1717: 		     13 => 'Grade 13',
                   1718: 		     14 => '100 Level',
                   1719: 		     15 => '200 Level',
                   1720: 		     16 => '300 Level',
                   1721: 		     17 => '400 Level',
                   1722: 		     18 => 'Graduate Level');
                   1723:     return &mt($gradelevels{$gradelevel});
                   1724: }
                   1725: 
1.163     www      1726: sub select_level_form {
                   1727:     my ($deflevel,$name)=@_;
                   1728:     unless ($deflevel) { $deflevel=0; }
1.167     www      1729:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
                   1730:     for (my $i=0; $i<=18; $i++) {
                   1731:         $selectform.="<option value=\"$i\" ".
1.253     albertel 1732:             ($i==$deflevel ? 'selected="selected" ' : '').
1.167     www      1733:                 ">".&gradeleveldescription($i)."</option>\n";
                   1734:     }
                   1735:     $selectform.="</select>";
                   1736:     return $selectform;
1.163     www      1737: }
1.167     www      1738: 
1.35      matthew  1739: #-------------------------------------------
                   1740: 
1.45      matthew  1741: =pod
                   1742: 
1.648     raeburn  1743: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc)
1.35      matthew  1744: 
                   1745: Returns a string containing a <select name='$name' size='1'> form to 
                   1746: allow a user to select the domain to preform an operation in.  
                   1747: See loncreateuser.pm for an example invocation and use.
                   1748: 
1.90      www      1749: If the $includeempty flag is set, it also includes an empty choice ("no domain
                   1750: selected");
                   1751: 
1.563     raeburn  1752: If the $showdomdesc flag is set, the domain name is followed by the domain description. 
                   1753: 
1.35      matthew  1754: =cut
                   1755: 
                   1756: #-------------------------------------------
1.34      matthew  1757: sub select_dom_form {
1.563     raeburn  1758:     my ($defdom,$name,$includeempty,$showdomdesc) = @_;
1.550     albertel 1759:     my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90      www      1760:     if ($includeempty) { @domains=('',@domains); }
1.34      matthew  1761:     my $selectdomain = "<select name=\"$name\" size=\"1\">\n";
1.356     albertel 1762:     foreach my $dom (@domains) {
                   1763:         $selectdomain.="<option value=\"$dom\" ".
1.563     raeburn  1764:             ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
                   1765:         if ($showdomdesc) {
                   1766:             if ($dom ne '') {
                   1767:                 my $domdesc = &Apache::lonnet::domain($dom,'description');
                   1768:                 if ($domdesc ne '') {
                   1769:                     $selectdomain .= ' ('.$domdesc.')';
                   1770:                 }
                   1771:             } 
                   1772:         }
                   1773:         $selectdomain .= "</option>\n";
1.34      matthew  1774:     }
                   1775:     $selectdomain.="</select>";
                   1776:     return $selectdomain;
                   1777: }
                   1778: 
1.35      matthew  1779: #-------------------------------------------
                   1780: 
1.45      matthew  1781: =pod
                   1782: 
1.648     raeburn  1783: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35      matthew  1784: 
1.586     raeburn  1785: input: 4 arguments (two required, two optional) - 
                   1786:     $domain - domain of new user
                   1787:     $name - name of form element
                   1788:     $default - Value of 'default' causes a default item to be first 
                   1789:                             option, and selected by default. 
                   1790:     $hide - Value of 'hide' causes hiding of the name of the server, 
                   1791:                             if 1 server found, or default, if 0 found.
1.594     raeburn  1792: output: returns 2 items: 
1.586     raeburn  1793: (a) form element which contains either:
                   1794:    (i) <select name="$name">
                   1795:         <option value="$hostid1">$hostid $servers{$hostid}</option>
                   1796:         <option value="$hostid2">$hostid $servers{$hostid}</option>       
                   1797:        </select>
                   1798:        form item if there are multiple library servers in $domain, or
                   1799:    (ii) an <input type="hidden" name="$name" value="$hostid" /> form item 
                   1800:        if there is only one library server in $domain.
                   1801: 
                   1802: (b) number of library servers found.
                   1803: 
                   1804: See loncreateuser.pm for example of use.
1.35      matthew  1805: 
                   1806: =cut
                   1807: 
                   1808: #-------------------------------------------
1.586     raeburn  1809: sub home_server_form_item {
                   1810:     my ($domain,$name,$default,$hide) = @_;
1.513     albertel 1811:     my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586     raeburn  1812:     my $result;
                   1813:     my $numlib = keys(%servers);
                   1814:     if ($numlib > 1) {
                   1815:         $result .= '<select name="'.$name.'" />'."\n";
                   1816:         if ($default) {
                   1817:             $result .= '<option value="default" selected>'.&mt('default').
                   1818:                        '</option>'."\n";
                   1819:         }
                   1820:         foreach my $hostid (sort(keys(%servers))) {
                   1821:             $result.= '<option value="'.$hostid.'">'.
                   1822: 	              $hostid.' '.$servers{$hostid}."</option>\n";
                   1823:         }
                   1824:         $result .= '</select>'."\n";
                   1825:     } elsif ($numlib == 1) {
                   1826:         my $hostid;
                   1827:         foreach my $item (keys(%servers)) {
                   1828:             $hostid = $item;
                   1829:         }
                   1830:         $result .= '<input type="hidden" name="'.$name.'" value="'.
                   1831:                    $hostid.'" />';
                   1832:                    if (!$hide) {
                   1833:                        $result .= $hostid.' '.$servers{$hostid};
                   1834:                    }
                   1835:                    $result .= "\n";
                   1836:     } elsif ($default) {
                   1837:         $result .= '<input type="hidden" name="'.$name.
                   1838:                    '" value="default" />';
                   1839:                    if (!$hide) {
                   1840:                        $result .= &mt('default');
                   1841:                    }
                   1842:                    $result .= "\n";
1.33      matthew  1843:     }
1.586     raeburn  1844:     return ($result,$numlib);
1.33      matthew  1845: }
1.112     bowersj2 1846: 
                   1847: =pod
                   1848: 
1.534     albertel 1849: =back 
                   1850: 
1.112     bowersj2 1851: =cut
1.87      matthew  1852: 
                   1853: ###############################################################
1.112     bowersj2 1854: ##                  Decoding User Agent                      ##
1.87      matthew  1855: ###############################################################
                   1856: 
                   1857: =pod
                   1858: 
1.112     bowersj2 1859: =head1 Decoding the User Agent
                   1860: 
                   1861: =over 4
                   1862: 
                   1863: =item * &decode_user_agent()
1.87      matthew  1864: 
                   1865: Inputs: $r
                   1866: 
                   1867: Outputs:
                   1868: 
                   1869: =over 4
                   1870: 
1.112     bowersj2 1871: =item * $httpbrowser
1.87      matthew  1872: 
1.112     bowersj2 1873: =item * $clientbrowser
1.87      matthew  1874: 
1.112     bowersj2 1875: =item * $clientversion
1.87      matthew  1876: 
1.112     bowersj2 1877: =item * $clientmathml
1.87      matthew  1878: 
1.112     bowersj2 1879: =item * $clientunicode
1.87      matthew  1880: 
1.112     bowersj2 1881: =item * $clientos
1.87      matthew  1882: 
                   1883: =back
                   1884: 
1.157     matthew  1885: =back 
                   1886: 
1.87      matthew  1887: =cut
                   1888: 
                   1889: ###############################################################
                   1890: ###############################################################
                   1891: sub decode_user_agent {
1.247     albertel 1892:     my ($r)=@_;
1.87      matthew  1893:     my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
                   1894:     my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
                   1895:     my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247     albertel 1896:     if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87      matthew  1897:     my $clientbrowser='unknown';
                   1898:     my $clientversion='0';
                   1899:     my $clientmathml='';
                   1900:     my $clientunicode='0';
                   1901:     for (my $i=0;$i<=$#browsertype;$i++) {
                   1902:         my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
                   1903: 	if (($httpbrowser=~/$match/i)  && ($httpbrowser!~/$notmatch/i)) {
                   1904: 	    $clientbrowser=$bname;
                   1905:             $httpbrowser=~/$vreg/i;
                   1906: 	    $clientversion=$1;
                   1907:             $clientmathml=($clientversion>=$minv);
                   1908:             $clientunicode=($clientversion>=$univ);
                   1909: 	}
                   1910:     }
                   1911:     my $clientos='unknown';
                   1912:     if (($httpbrowser=~/linux/i) ||
                   1913:         ($httpbrowser=~/unix/i) ||
                   1914:         ($httpbrowser=~/ux/i) ||
                   1915:         ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
                   1916:     if (($httpbrowser=~/vax/i) ||
                   1917:         ($httpbrowser=~/vms/i)) { $clientos='vms'; }
                   1918:     if ($httpbrowser=~/next/i) { $clientos='next'; }
                   1919:     if (($httpbrowser=~/mac/i) ||
                   1920:         ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
                   1921:     if ($httpbrowser=~/win/i) { $clientos='win'; }
                   1922:     if ($httpbrowser=~/embed/i) { $clientos='pda'; }
                   1923:     return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   1924:             $clientunicode,$clientos,);
                   1925: }
                   1926: 
1.32      matthew  1927: ###############################################################
                   1928: ##    Authentication changing form generation subroutines    ##
                   1929: ###############################################################
                   1930: ##
                   1931: ## All of the authform_xxxxxxx subroutines take their inputs in a
                   1932: ## hash, and have reasonable default values.
                   1933: ##
                   1934: ##    formname = the name given in the <form> tag.
1.35      matthew  1935: #-------------------------------------------
                   1936: 
1.45      matthew  1937: =pod
                   1938: 
1.112     bowersj2 1939: =head1 Authentication Routines
                   1940: 
                   1941: =over 4
                   1942: 
1.648     raeburn  1943: =item * &authform_xxxxxx()
1.35      matthew  1944: 
                   1945: The authform_xxxxxx subroutines provide javascript and html forms which 
                   1946: handle some of the conveniences required for authentication forms.  
                   1947: This is not an optimal method, but it works.  
                   1948: 
                   1949: =over 4
                   1950: 
1.112     bowersj2 1951: =item * authform_header
1.35      matthew  1952: 
1.112     bowersj2 1953: =item * authform_authorwarning
1.35      matthew  1954: 
1.112     bowersj2 1955: =item * authform_nochange
1.35      matthew  1956: 
1.112     bowersj2 1957: =item * authform_kerberos
1.35      matthew  1958: 
1.112     bowersj2 1959: =item * authform_internal
1.35      matthew  1960: 
1.112     bowersj2 1961: =item * authform_filesystem
1.35      matthew  1962: 
                   1963: =back
                   1964: 
1.648     raeburn  1965: See loncreateuser.pm for invocation and use examples.
1.157     matthew  1966: 
1.35      matthew  1967: =cut
                   1968: 
                   1969: #-------------------------------------------
1.32      matthew  1970: sub authform_header{  
                   1971:     my %in = (
                   1972:         formname => 'cu',
1.80      albertel 1973:         kerb_def_dom => '',
1.32      matthew  1974:         @_,
                   1975:     );
                   1976:     $in{'formname'} = 'document.' . $in{'formname'};
                   1977:     my $result='';
1.80      albertel 1978: 
                   1979: #---------------------------------------------- Code for upper case translation
                   1980:     my $Javascript_toUpperCase;
                   1981:     unless ($in{kerb_def_dom}) {
                   1982:         $Javascript_toUpperCase =<<"END";
                   1983:         switch (choice) {
                   1984:            case 'krb': currentform.elements[choicearg].value =
                   1985:                currentform.elements[choicearg].value.toUpperCase();
                   1986:                break;
                   1987:            default:
                   1988:         }
                   1989: END
                   1990:     } else {
                   1991:         $Javascript_toUpperCase = "";
                   1992:     }
                   1993: 
1.165     raeburn  1994:     my $radioval = "'nochange'";
1.591     raeburn  1995:     if (defined($in{'curr_authtype'})) {
                   1996:         if ($in{'curr_authtype'} ne '') {
                   1997:             $radioval = "'".$in{'curr_authtype'}."arg'";
                   1998:         }
1.174     matthew  1999:     }
1.165     raeburn  2000:     my $argfield = 'null';
1.591     raeburn  2001:     if (defined($in{'mode'})) {
1.165     raeburn  2002:         if ($in{'mode'} eq 'modifycourse')  {
1.591     raeburn  2003:             if (defined($in{'curr_autharg'})) {
                   2004:                 if ($in{'curr_autharg'} ne '') {
1.165     raeburn  2005:                     $argfield = "'$in{'curr_autharg'}'";
                   2006:                 }
                   2007:             }
                   2008:         }
                   2009:     }
                   2010: 
1.32      matthew  2011:     $result.=<<"END";
                   2012: var current = new Object();
1.165     raeburn  2013: current.radiovalue = $radioval;
                   2014: current.argfield = $argfield;
1.32      matthew  2015: 
                   2016: function changed_radio(choice,currentform) {
                   2017:     var choicearg = choice + 'arg';
                   2018:     // If a radio button in changed, we need to change the argfield
                   2019:     if (current.radiovalue != choice) {
                   2020:         current.radiovalue = choice;
                   2021:         if (current.argfield != null) {
                   2022:             currentform.elements[current.argfield].value = '';
                   2023:         }
                   2024:         if (choice == 'nochange') {
                   2025:             current.argfield = null;
                   2026:         } else {
                   2027:             current.argfield = choicearg;
                   2028:             switch(choice) {
                   2029:                 case 'krb': 
                   2030:                     currentform.elements[current.argfield].value = 
                   2031:                         "$in{'kerb_def_dom'}";
                   2032:                 break;
                   2033:               default:
                   2034:                 break;
                   2035:             }
                   2036:         }
                   2037:     }
                   2038:     return;
                   2039: }
1.22      www      2040: 
1.32      matthew  2041: function changed_text(choice,currentform) {
                   2042:     var choicearg = choice + 'arg';
                   2043:     if (currentform.elements[choicearg].value !='') {
1.80      albertel 2044:         $Javascript_toUpperCase
1.32      matthew  2045:         // clear old field
                   2046:         if ((current.argfield != choicearg) && (current.argfield != null)) {
                   2047:             currentform.elements[current.argfield].value = '';
                   2048:         }
                   2049:         current.argfield = choicearg;
                   2050:     }
                   2051:     set_auth_radio_buttons(choice,currentform);
                   2052:     return;
1.20      www      2053: }
1.32      matthew  2054: 
                   2055: function set_auth_radio_buttons(newvalue,currentform) {
                   2056:     var i=0;
                   2057:     while (i < currentform.login.length) {
                   2058:         if (currentform.login[i].value == newvalue) { break; }
                   2059:         i++;
                   2060:     }
                   2061:     if (i == currentform.login.length) {
                   2062:         return;
                   2063:     }
                   2064:     current.radiovalue = newvalue;
                   2065:     currentform.login[i].checked = true;
                   2066:     return;
                   2067: }
                   2068: END
                   2069:     return $result;
                   2070: }
                   2071: 
                   2072: sub authform_authorwarning{
                   2073:     my $result='';
1.144     matthew  2074:     $result='<i>'.
                   2075:         &mt('As a general rule, only authors or co-authors should be '.
                   2076:             'filesystem authenticated '.
                   2077:             '(which allows access to the server filesystem).')."</i>\n";
1.32      matthew  2078:     return $result;
                   2079: }
                   2080: 
                   2081: sub authform_nochange{  
                   2082:     my %in = (
                   2083:               formname => 'document.cu',
                   2084:               kerb_def_dom => 'MSU.EDU',
                   2085:               @_,
                   2086:           );
1.586     raeburn  2087:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'}); 
                   2088:     my $result;
                   2089:     if (keys(%can_assign) == 0) {
                   2090:         $result = &mt('Under you current role you are not permitted to change login settings for this user');  
                   2091:     } else {
                   2092:         $result = '<label>'.&mt('[_1] Do not change login data',
                   2093:                   '<input type="radio" name="login" value="nochange" '.
                   2094:                   'checked="checked" onclick="'.
1.281     albertel 2095:             "javascript:changed_radio('nochange',$in{'formname'});".'" />').
                   2096: 	    '</label>';
1.586     raeburn  2097:     }
1.32      matthew  2098:     return $result;
                   2099: }
                   2100: 
1.591     raeburn  2101: sub authform_kerberos {
1.32      matthew  2102:     my %in = (
                   2103:               formname => 'document.cu',
                   2104:               kerb_def_dom => 'MSU.EDU',
1.80      albertel 2105:               kerb_def_auth => 'krb4',
1.32      matthew  2106:               @_,
                   2107:               );
1.586     raeburn  2108:     my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
                   2109:         $autharg,$jscall);
                   2110:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.80      albertel 2111:     if ($in{'kerb_def_auth'} eq 'krb5') {
1.586     raeburn  2112:        $check5 = ' checked="on"';
1.80      albertel 2113:     } else {
1.586     raeburn  2114:        $check4 = ' checked="on"';
1.80      albertel 2115:     }
1.165     raeburn  2116:     $krbarg = $in{'kerb_def_dom'};
1.591     raeburn  2117:     if (defined($in{'curr_authtype'})) {
                   2118:         if ($in{'curr_authtype'} eq 'krb') {
1.586     raeburn  2119:             $krbcheck = ' checked="on"';
1.623     raeburn  2120:             if (defined($in{'mode'})) {
                   2121:                 if ($in{'mode'} eq 'modifyuser') {
                   2122:                     $krbcheck = '';
                   2123:                 }
                   2124:             }
1.591     raeburn  2125:             if (defined($in{'curr_kerb_ver'})) {
                   2126:                 if ($in{'curr_krb_ver'} eq '5') {
                   2127:                     $check5 = ' checked="on"';
                   2128:                     $check4 = '';
                   2129:                 } else {
                   2130:                     $check4 = ' checked="on"';
                   2131:                     $check5 = '';
                   2132:                 }
1.586     raeburn  2133:             }
1.591     raeburn  2134:             if (defined($in{'curr_autharg'})) {
1.165     raeburn  2135:                 $krbarg = $in{'curr_autharg'};
                   2136:             }
1.586     raeburn  2137:             if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591     raeburn  2138:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2139:                     $result = 
                   2140:     &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
                   2141:         $in{'curr_autharg'},$krbver);
                   2142:                 } else {
                   2143:                     $result =
                   2144:     &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
                   2145:                 }
                   2146:                 return $result; 
                   2147:             }
                   2148:         }
                   2149:     } else {
                   2150:         if ($authnum == 1) {
                   2151:             $authtype = '<input type="hidden" name="login" value="krb">';
1.165     raeburn  2152:         }
                   2153:     }
1.586     raeburn  2154:     if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
                   2155:         return;
1.587     raeburn  2156:     } elsif ($authtype eq '') {
1.591     raeburn  2157:         if (defined($in{'mode'})) {
1.587     raeburn  2158:             if ($in{'mode'} eq 'modifycourse') {
                   2159:                 if ($authnum == 1) {
                   2160:                     $authtype = '<input type="hidden" name="login" value="krb">';
                   2161:                 }
                   2162:             }
                   2163:         }
1.586     raeburn  2164:     }
                   2165:     $jscall = "javascript:changed_radio('krb',$in{'formname'});";
                   2166:     if ($authtype eq '') {
                   2167:         $authtype = '<input type="radio" name="login" value="krb" '.
                   2168:                     'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
                   2169:                     $krbcheck.' />';
                   2170:     }
                   2171:     if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
                   2172:         ($can_assign{'krb4'} && !$can_assign{'krb5'} && 
                   2173:          $in{'curr_authtype'} eq 'krb5') ||
                   2174:         (!$can_assign{'krb4'} && $can_assign{'krb5'} && 
                   2175:          $in{'curr_authtype'} eq 'krb4')) {
                   2176:         $result .= &mt
1.144     matthew  2177:         ('[_1] Kerberos authenticated with domain [_2] '.
1.281     albertel 2178:          '[_3] Version 4 [_4] Version 5 [_5]',
1.586     raeburn  2179:          '<label>'.$authtype,
1.281     albertel 2180:          '</label><input type="text" size="10" name="krbarg" '.
1.165     raeburn  2181:              'value="'.$krbarg.'" '.
1.144     matthew  2182:              'onchange="'.$jscall.'" />',
1.281     albertel 2183:          '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
                   2184:          '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
                   2185: 	 '</label>');
1.586     raeburn  2186:     } elsif ($can_assign{'krb4'}) {
                   2187:         $result .= &mt
                   2188:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2189:          '[_3] Version 4 [_4]',
                   2190:          '<label>'.$authtype,
                   2191:          '</label><input type="text" size="10" name="krbarg" '.
                   2192:              'value="'.$krbarg.'" '.
                   2193:              'onchange="'.$jscall.'" />',
                   2194:          '<label><input type="hidden" name="krbver" value="4" />',
                   2195:          '</label>');
                   2196:     } elsif ($can_assign{'krb5'}) {
                   2197:         $result .= &mt
                   2198:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2199:          '[_3] Version 5 [_4]',
                   2200:          '<label>'.$authtype,
                   2201:          '</label><input type="text" size="10" name="krbarg" '.
                   2202:              'value="'.$krbarg.'" '.
                   2203:              'onchange="'.$jscall.'" />',
                   2204:          '<label><input type="hidden" name="krbver" value="5" />',
                   2205:          '</label>');
                   2206:     }
1.32      matthew  2207:     return $result;
                   2208: }
                   2209: 
                   2210: sub authform_internal{  
1.586     raeburn  2211:     my %in = (
1.32      matthew  2212:                 formname => 'document.cu',
                   2213:                 kerb_def_dom => 'MSU.EDU',
                   2214:                 @_,
                   2215:                 );
1.586     raeburn  2216:     my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
                   2217:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2218:     if (defined($in{'curr_authtype'})) {
                   2219:         if ($in{'curr_authtype'} eq 'int') {
1.586     raeburn  2220:             if ($can_assign{'int'}) {
                   2221:                 $intcheck = 'checked="on" ';
1.623     raeburn  2222:                 if (defined($in{'mode'})) {
                   2223:                     if ($in{'mode'} eq 'modifyuser') {
                   2224:                         $intcheck = '';
                   2225:                     }
                   2226:                 }
1.591     raeburn  2227:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2228:                     $intarg = $in{'curr_autharg'};
                   2229:                 }
                   2230:             } else {
                   2231:                 $result = &mt('Currently internally authenticated.');
                   2232:                 return $result;
1.165     raeburn  2233:             }
                   2234:         }
1.586     raeburn  2235:     } else {
                   2236:         if ($authnum == 1) {
                   2237:             $authtype = '<input type="hidden" name="login" value="int">';
                   2238:         }
                   2239:     }
                   2240:     if (!$can_assign{'int'}) {
                   2241:         return;
1.587     raeburn  2242:     } elsif ($authtype eq '') {
1.591     raeburn  2243:         if (defined($in{'mode'})) {
1.587     raeburn  2244:             if ($in{'mode'} eq 'modifycourse') {
                   2245:                 if ($authnum == 1) {
                   2246:                     $authtype = '<input type="hidden" name="login" value="int">';
                   2247:                 }
                   2248:             }
                   2249:         }
1.165     raeburn  2250:     }
1.586     raeburn  2251:     $jscall = "javascript:changed_radio('int',$in{'formname'});";
                   2252:     if ($authtype eq '') {
                   2253:         $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
                   2254:                     ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
                   2255:     }
1.605     bisitz   2256:     $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586     raeburn  2257:                $intarg.'" onchange="'.$jscall.'" />';
                   2258:     $result = &mt
1.144     matthew  2259:         ('[_1] Internally authenticated (with initial password [_2])',
1.586     raeburn  2260:          '<label>'.$authtype,'</label>'.$autharg);
1.620     www      2261:     $result.="<label><input type=\"checkbox\" name=\"visible\" onClick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
1.32      matthew  2262:     return $result;
                   2263: }
                   2264: 
                   2265: sub authform_local{  
                   2266:     my %in = (
                   2267:               formname => 'document.cu',
                   2268:               kerb_def_dom => 'MSU.EDU',
                   2269:               @_,
                   2270:               );
1.586     raeburn  2271:     my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
                   2272:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2273:     if (defined($in{'curr_authtype'})) {
                   2274:         if ($in{'curr_authtype'} eq 'loc') {
1.586     raeburn  2275:             if ($can_assign{'loc'}) {
                   2276:                 $loccheck = 'checked="on" ';
1.623     raeburn  2277:                 if (defined($in{'mode'})) {
                   2278:                     if ($in{'mode'} eq 'modifyuser') {
                   2279:                         $loccheck = '';
                   2280:                     }
                   2281:                 }
1.591     raeburn  2282:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2283:                     $locarg = $in{'curr_autharg'};
                   2284:                 }
                   2285:             } else {
                   2286:                 $result = &mt('Currently using local (institutional) authentication.');
                   2287:                 return $result;
1.165     raeburn  2288:             }
                   2289:         }
1.586     raeburn  2290:     } else {
                   2291:         if ($authnum == 1) {
                   2292:             $authtype = '<input type="hidden" name="login" value="loc">';
                   2293:         }
                   2294:     }
                   2295:     if (!$can_assign{'loc'}) {
                   2296:         return;
1.587     raeburn  2297:     } elsif ($authtype eq '') {
1.591     raeburn  2298:         if (defined($in{'mode'})) {
1.587     raeburn  2299:             if ($in{'mode'} eq 'modifycourse') {
                   2300:                 if ($authnum == 1) {
                   2301:                     $authtype = '<input type="hidden" name="login" value="loc">';
                   2302:                 }
                   2303:             }
                   2304:         }
1.165     raeburn  2305:     }
1.586     raeburn  2306:     $jscall = "javascript:changed_radio('loc',$in{'formname'});";
                   2307:     if ($authtype eq '') {
                   2308:         $authtype = '<input type="radio" name="login" value="loc" '.
                   2309:                     $loccheck.' onchange="'.$jscall.'" onclick="'.
                   2310:                     $jscall.'" />';
                   2311:     }
                   2312:     $autharg = '<input type="text" size="10" name="locarg" value="'.
                   2313:                $locarg.'" onchange="'.$jscall.'" />';
                   2314:     $result = &mt('[_1] Local Authentication with argument [_2]',
                   2315:                   '<label>'.$authtype,'</label>'.$autharg);
1.32      matthew  2316:     return $result;
                   2317: }
                   2318: 
                   2319: sub authform_filesystem{  
                   2320:     my %in = (
                   2321:               formname => 'document.cu',
                   2322:               kerb_def_dom => 'MSU.EDU',
                   2323:               @_,
                   2324:               );
1.586     raeburn  2325:     my ($fsyscheck,$result,$authtype,$autharg,$jscall);
                   2326:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2327:     if (defined($in{'curr_authtype'})) {
                   2328:         if ($in{'curr_authtype'} eq 'fsys') {
1.586     raeburn  2329:             if ($can_assign{'fsys'}) {
                   2330:                 $fsyscheck = 'checked="on" ';
1.623     raeburn  2331:                 if (defined($in{'mode'})) {
                   2332:                     if ($in{'mode'} eq 'modifyuser') {
                   2333:                         $fsyscheck = '';
                   2334:                     }
                   2335:                 }
1.586     raeburn  2336:             } else {
                   2337:                 $result = &mt('Currently Filesystem Authenticated.');
                   2338:                 return $result;
                   2339:             }           
                   2340:         }
                   2341:     } else {
                   2342:         if ($authnum == 1) {
                   2343:             $authtype = '<input type="hidden" name="login" value="fsys">';
                   2344:         }
                   2345:     }
                   2346:     if (!$can_assign{'fsys'}) {
                   2347:         return;
1.587     raeburn  2348:     } elsif ($authtype eq '') {
1.591     raeburn  2349:         if (defined($in{'mode'})) {
1.587     raeburn  2350:             if ($in{'mode'} eq 'modifycourse') {
                   2351:                 if ($authnum == 1) {
                   2352:                     $authtype = '<input type="hidden" name="login" value="fsys">';
                   2353:                 }
                   2354:             }
                   2355:         }
1.586     raeburn  2356:     }
                   2357:     $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
                   2358:     if ($authtype eq '') {
                   2359:         $authtype = '<input type="radio" name="login" value="fsys" '.
                   2360:                     $fsyscheck.' onchange="'.$jscall.'" onclick="'.
                   2361:                     $jscall.'" />';
                   2362:     }
                   2363:     $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
                   2364:                ' onchange="'.$jscall.'" />';
                   2365:     $result = &mt
1.144     matthew  2366:         ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281     albertel 2367:          '<label><input type="radio" name="login" value="fsys" '.
1.586     raeburn  2368:          $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605     bisitz   2369:          '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144     matthew  2370:                   'onchange="'.$jscall.'" />');
1.32      matthew  2371:     return $result;
                   2372: }
                   2373: 
1.586     raeburn  2374: sub get_assignable_auth {
                   2375:     my ($dom) = @_;
                   2376:     if ($dom eq '') {
                   2377:         $dom = $env{'request.role.domain'};
                   2378:     }
                   2379:     my %can_assign = (
                   2380:                           krb4 => 1,
                   2381:                           krb5 => 1,
                   2382:                           int  => 1,
                   2383:                           loc  => 1,
                   2384:                      );
                   2385:     my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
                   2386:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   2387:         if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
                   2388:             my $authhash = $domconfig{'usercreation'}{'authtypes'};
                   2389:             my $context;
                   2390:             if ($env{'request.role'} =~ /^au/) {
                   2391:                 $context = 'author';
                   2392:             } elsif ($env{'request.role'} =~ /^dc/) {
                   2393:                 $context = 'domain';
                   2394:             } elsif ($env{'request.course.id'}) {
                   2395:                 $context = 'course';
                   2396:             }
                   2397:             if ($context) {
                   2398:                 if (ref($authhash->{$context}) eq 'HASH') {
                   2399:                    %can_assign = %{$authhash->{$context}}; 
                   2400:                 }
                   2401:             }
                   2402:         }
                   2403:     }
                   2404:     my $authnum = 0;
                   2405:     foreach my $key (keys(%can_assign)) {
                   2406:         if ($can_assign{$key}) {
                   2407:             $authnum ++;
                   2408:         }
                   2409:     }
                   2410:     if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
                   2411:         $authnum --;
                   2412:     }
                   2413:     return ($authnum,%can_assign);
                   2414: }
                   2415: 
1.80      albertel 2416: ###############################################################
                   2417: ##    Get Kerberos Defaults for Domain                 ##
                   2418: ###############################################################
                   2419: ##
                   2420: ## Returns default kerberos version and an associated argument
                   2421: ## as listed in file domain.tab. If not listed, provides
                   2422: ## appropriate default domain and kerberos version.
                   2423: ##
                   2424: #-------------------------------------------
                   2425: 
                   2426: =pod
                   2427: 
1.648     raeburn  2428: =item * &get_kerberos_defaults()
1.80      albertel 2429: 
                   2430: get_kerberos_defaults($target_domain) returns the default kerberos
1.641     raeburn  2431: version and domain. If not found, it defaults to version 4 and the 
                   2432: domain of the server.
1.80      albertel 2433: 
1.648     raeburn  2434: =over 4
                   2435: 
1.80      albertel 2436: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
                   2437: 
1.648     raeburn  2438: =back
                   2439: 
                   2440: =back
                   2441: 
1.80      albertel 2442: =cut
                   2443: 
                   2444: #-------------------------------------------
                   2445: sub get_kerberos_defaults {
                   2446:     my $domain=shift;
1.641     raeburn  2447:     my ($krbdef,$krbdefdom);
                   2448:     my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
                   2449:     if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
                   2450:         $krbdef = $domdefaults{'auth_def'};
                   2451:         $krbdefdom = $domdefaults{'auth_arg_def'};
                   2452:     } else {
1.80      albertel 2453:         $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
                   2454:         my $krbdefdom=$1;
                   2455:         $krbdefdom=~tr/a-z/A-Z/;
                   2456:         $krbdef = "krb4";
                   2457:     }
                   2458:     return ($krbdef,$krbdefdom);
                   2459: }
1.112     bowersj2 2460: 
1.32      matthew  2461: 
1.46      matthew  2462: ###############################################################
                   2463: ##                Thesaurus Functions                        ##
                   2464: ###############################################################
1.20      www      2465: 
1.46      matthew  2466: =pod
1.20      www      2467: 
1.112     bowersj2 2468: =head1 Thesaurus Functions
                   2469: 
                   2470: =over 4
                   2471: 
1.648     raeburn  2472: =item * &initialize_keywords()
1.46      matthew  2473: 
                   2474: Initializes the package variable %Keywords if it is empty.  Uses the
                   2475: package variable $thesaurus_db_file.
                   2476: 
                   2477: =cut
                   2478: 
                   2479: ###################################################
                   2480: 
                   2481: sub initialize_keywords {
                   2482:     return 1 if (scalar keys(%Keywords));
                   2483:     # If we are here, %Keywords is empty, so fill it up
                   2484:     #   Make sure the file we need exists...
                   2485:     if (! -e $thesaurus_db_file) {
                   2486:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
                   2487:                                  " failed because it does not exist");
                   2488:         return 0;
                   2489:     }
                   2490:     #   Set up the hash as a database
                   2491:     my %thesaurus_db;
                   2492:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2493:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2494:         &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
                   2495:                                  $thesaurus_db_file);
                   2496:         return 0;
                   2497:     } 
                   2498:     #  Get the average number of appearances of a word.
                   2499:     my $avecount = $thesaurus_db{'average.count'};
                   2500:     #  Put keywords (those that appear > average) into %Keywords
                   2501:     while (my ($word,$data)=each (%thesaurus_db)) {
                   2502:         my ($count,undef) = split /:/,$data;
                   2503:         $Keywords{$word}++ if ($count > $avecount);
                   2504:     }
                   2505:     untie %thesaurus_db;
                   2506:     # Remove special values from %Keywords.
1.356     albertel 2507:     foreach my $value ('total.count','average.count') {
                   2508:         delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586     raeburn  2509:   }
1.46      matthew  2510:     return 1;
                   2511: }
                   2512: 
                   2513: ###################################################
                   2514: 
                   2515: =pod
                   2516: 
1.648     raeburn  2517: =item * &keyword($word)
1.46      matthew  2518: 
                   2519: Returns true if $word is a keyword.  A keyword is a word that appears more 
                   2520: than the average number of times in the thesaurus database.  Calls 
                   2521: &initialize_keywords
                   2522: 
                   2523: =cut
                   2524: 
                   2525: ###################################################
1.20      www      2526: 
                   2527: sub keyword {
1.46      matthew  2528:     return if (!&initialize_keywords());
                   2529:     my $word=lc(shift());
                   2530:     $word=~s/\W//g;
                   2531:     return exists($Keywords{$word});
1.20      www      2532: }
1.46      matthew  2533: 
                   2534: ###############################################################
                   2535: 
                   2536: =pod 
1.20      www      2537: 
1.648     raeburn  2538: =item * &get_related_words()
1.46      matthew  2539: 
1.160     matthew  2540: Look up a word in the thesaurus.  Takes a scalar argument and returns
1.46      matthew  2541: an array of words.  If the keyword is not in the thesaurus, an empty array
                   2542: will be returned.  The order of the words returned is determined by the
                   2543: database which holds them.
                   2544: 
                   2545: Uses global $thesaurus_db_file.
                   2546: 
                   2547: =cut
                   2548: 
                   2549: ###############################################################
                   2550: sub get_related_words {
                   2551:     my $keyword = shift;
                   2552:     my %thesaurus_db;
                   2553:     if (! -e $thesaurus_db_file) {
                   2554:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
                   2555:                                  "failed because the file does not exist");
                   2556:         return ();
                   2557:     }
                   2558:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2559:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2560:         return ();
                   2561:     } 
                   2562:     my @Words=();
1.429     www      2563:     my $count=0;
1.46      matthew  2564:     if (exists($thesaurus_db{$keyword})) {
1.356     albertel 2565: 	# The first element is the number of times
                   2566: 	# the word appears.  We do not need it now.
1.429     www      2567: 	my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
                   2568: 	my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
                   2569: 	my $threshold=$mostfrequentcount/10;
                   2570:         foreach my $possibleword (@RelatedWords) {
                   2571:             my ($word,$wordcount)=split(/\,/,$possibleword);
                   2572:             if ($wordcount>$threshold) {
                   2573: 		push(@Words,$word);
                   2574:                 $count++;
                   2575:                 if ($count>10) { last; }
                   2576: 	    }
1.20      www      2577:         }
                   2578:     }
1.46      matthew  2579:     untie %thesaurus_db;
                   2580:     return @Words;
1.14      harris41 2581: }
1.46      matthew  2582: 
1.112     bowersj2 2583: =pod
                   2584: 
                   2585: =back
                   2586: 
                   2587: =cut
1.61      www      2588: 
                   2589: # -------------------------------------------------------------- Plaintext name
1.81      albertel 2590: =pod
                   2591: 
1.112     bowersj2 2592: =head1 User Name Functions
                   2593: 
                   2594: =over 4
                   2595: 
1.648     raeburn  2596: =item * &plainname($uname,$udom,$first)
1.81      albertel 2597: 
1.112     bowersj2 2598: Takes a users logon name and returns it as a string in
1.226     albertel 2599: "first middle last generation" form 
                   2600: if $first is set to 'lastname' then it returns it as
                   2601: 'lastname generation, firstname middlename' if their is a lastname
1.81      albertel 2602: 
                   2603: =cut
1.61      www      2604: 
1.295     www      2605: 
1.81      albertel 2606: ###############################################################
1.61      www      2607: sub plainname {
1.226     albertel 2608:     my ($uname,$udom,$first)=@_;
1.537     albertel 2609:     return if (!defined($uname) || !defined($udom));
1.295     www      2610:     my %names=&getnames($uname,$udom);
1.226     albertel 2611:     my $name=&Apache::lonnet::format_name($names{'firstname'},
                   2612: 					  $names{'middlename'},
                   2613: 					  $names{'lastname'},
                   2614: 					  $names{'generation'},$first);
                   2615:     $name=~s/^\s+//;
1.62      www      2616:     $name=~s/\s+$//;
                   2617:     $name=~s/\s+/ /g;
1.353     albertel 2618:     if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62      www      2619:     return $name;
1.61      www      2620: }
1.66      www      2621: 
                   2622: # -------------------------------------------------------------------- Nickname
1.81      albertel 2623: =pod
                   2624: 
1.648     raeburn  2625: =item * &nickname($uname,$udom)
1.81      albertel 2626: 
                   2627: Gets a users name and returns it as a string as
                   2628: 
                   2629: "&quot;nickname&quot;"
1.66      www      2630: 
1.81      albertel 2631: if the user has a nickname or
                   2632: 
                   2633: "first middle last generation"
                   2634: 
                   2635: if the user does not
                   2636: 
                   2637: =cut
1.66      www      2638: 
                   2639: sub nickname {
                   2640:     my ($uname,$udom)=@_;
1.537     albertel 2641:     return if (!defined($uname) || !defined($udom));
1.295     www      2642:     my %names=&getnames($uname,$udom);
1.68      albertel 2643:     my $name=$names{'nickname'};
1.66      www      2644:     if ($name) {
                   2645:        $name='&quot;'.$name.'&quot;'; 
                   2646:     } else {
                   2647:        $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
                   2648: 	     $names{'lastname'}.' '.$names{'generation'};
                   2649:        $name=~s/\s+$//;
                   2650:        $name=~s/\s+/ /g;
                   2651:     }
                   2652:     return $name;
                   2653: }
                   2654: 
1.295     www      2655: sub getnames {
                   2656:     my ($uname,$udom)=@_;
1.537     albertel 2657:     return if (!defined($uname) || !defined($udom));
1.433     albertel 2658:     if ($udom eq 'public' && $uname eq 'public') {
                   2659: 	return ('lastname' => &mt('Public'));
                   2660:     }
1.295     www      2661:     my $id=$uname.':'.$udom;
                   2662:     my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
                   2663:     if ($cached) {
                   2664: 	return %{$names};
                   2665:     } else {
                   2666: 	my %loadnames=&Apache::lonnet::get('environment',
                   2667:                     ['firstname','middlename','lastname','generation','nickname'],
                   2668: 					 $udom,$uname);
                   2669: 	&Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
                   2670: 	return %loadnames;
                   2671:     }
                   2672: }
1.61      www      2673: 
1.542     raeburn  2674: # -------------------------------------------------------------------- getemails
1.648     raeburn  2675: 
1.542     raeburn  2676: =pod
                   2677: 
1.648     raeburn  2678: =item * &getemails($uname,$udom)
1.542     raeburn  2679: 
                   2680: Gets a user's email information and returns it as a hash with keys:
                   2681: notification, critnotification, permanentemail
                   2682: 
                   2683: For notification and critnotification, values are comma-separated lists 
1.648     raeburn  2684: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542     raeburn  2685:  
1.648     raeburn  2686: 
1.542     raeburn  2687: =cut
                   2688: 
1.648     raeburn  2689: 
1.466     albertel 2690: sub getemails {
                   2691:     my ($uname,$udom)=@_;
                   2692:     if ($udom eq 'public' && $uname eq 'public') {
                   2693: 	return;
                   2694:     }
1.467     www      2695:     if (!$udom) { $udom=$env{'user.domain'}; }
                   2696:     if (!$uname) { $uname=$env{'user.name'}; }
1.466     albertel 2697:     my $id=$uname.':'.$udom;
                   2698:     my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
                   2699:     if ($cached) {
                   2700: 	return %{$names};
                   2701:     } else {
                   2702: 	my %loadnames=&Apache::lonnet::get('environment',
                   2703:                     			   ['notification','critnotification',
                   2704: 					    'permanentemail'],
                   2705: 					   $udom,$uname);
                   2706: 	&Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
                   2707: 	return %loadnames;
                   2708:     }
                   2709: }
                   2710: 
1.551     albertel 2711: sub flush_email_cache {
                   2712:     my ($uname,$udom)=@_;
                   2713:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2714:     if (!$uname) { $uname=$env{'user.name'};   }
                   2715:     return if ($udom eq 'public' && $uname eq 'public');
                   2716:     my $id=$uname.':'.$udom;
                   2717:     &Apache::lonnet::devalidate_cache_new('emailscache',$id);
                   2718: }
                   2719: 
1.61      www      2720: # ------------------------------------------------------------------ Screenname
1.81      albertel 2721: 
                   2722: =pod
                   2723: 
1.648     raeburn  2724: =item * &screenname($uname,$udom)
1.81      albertel 2725: 
                   2726: Gets a users screenname and returns it as a string
                   2727: 
                   2728: =cut
1.61      www      2729: 
                   2730: sub screenname {
                   2731:     my ($uname,$udom)=@_;
1.258     albertel 2732:     if ($uname eq $env{'user.name'} &&
                   2733: 	$udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212     albertel 2734:     my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68      albertel 2735:     return $names{'screenname'};
1.62      www      2736: }
                   2737: 
1.212     albertel 2738: 
1.62      www      2739: # ------------------------------------------------------------- Message Wrapper
                   2740: 
                   2741: sub messagewrapper {
1.369     www      2742:     my ($link,$username,$domain,$subject,$text)=@_;
1.62      www      2743:     return 
1.441     albertel 2744:         '<a href="/adm/email?compose=individual&amp;'.
                   2745:         'recname='.$username.'&amp;recdom='.$domain.
                   2746: 	'&amp;subject='.&escape($subject).'&amp;text='.&escape($text).'" '.
1.200     matthew  2747:         'title="'.&mt('Send message').'">'.$link.'</a>';
1.74      www      2748: }
                   2749: # --------------------------------------------------------------- Notes Wrapper
                   2750: 
                   2751: sub noteswrapper {
                   2752:     my ($link,$un,$do)=@_;
                   2753:     return 
                   2754: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62      www      2755: }
                   2756: # ------------------------------------------------------------- Aboutme Wrapper
                   2757: 
                   2758: sub aboutmewrapper {
1.166     www      2759:     my ($link,$username,$domain,$target)=@_;
1.447     raeburn  2760:     if (!defined($username)  && !defined($domain)) {
                   2761:         return;
                   2762:     }
1.205     www      2763:     return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.454     banghart 2764: 	($target?' target="$target"':'').' title="'.&mt("View this user's personal page").'">'.$link.'</a>';
1.62      www      2765: }
                   2766: 
                   2767: # ------------------------------------------------------------ Syllabus Wrapper
                   2768: 
                   2769: 
                   2770: sub syllabuswrapper {
1.707     bisitz   2771:     my ($linktext,$coursedir,$domain)=@_;
1.208     matthew  2772:     return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61      www      2773: }
1.14      harris41 2774: 
1.208     matthew  2775: sub track_student_link {
1.268     albertel 2776:     my ($linktext,$sname,$sdom,$target,$start) = @_;
                   2777:     my $link ="/adm/trackstudent?";
1.208     matthew  2778:     my $title = 'View recent activity';
                   2779:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   2780:         defined($sdom)  && $sdom  !~ /^\s*$/) {
1.268     albertel 2781:         $link .= "selected_student=$sname:$sdom";
1.208     matthew  2782:         $title .= ' of this student';
1.268     albertel 2783:     } 
1.208     matthew  2784:     if (defined($target) && $target !~ /^\s*$/) {
                   2785:         $target = qq{target="$target"};
                   2786:     } else {
                   2787:         $target = '';
                   2788:     }
1.268     albertel 2789:     if ($start) { $link.='&amp;start='.$start; }
1.554     albertel 2790:     $title = &mt($title);
                   2791:     $linktext = &mt($linktext);
1.448     albertel 2792:     return qq{<a href="$link" title="$title" $target>$linktext</a>}.
                   2793: 	&help_open_topic('View_recent_activity');
1.208     matthew  2794: }
                   2795: 
1.508     www      2796: # ===================================================== Display a student photo
                   2797: 
                   2798: 
1.509     albertel 2799: sub student_image_tag {
1.508     www      2800:     my ($domain,$user)=@_;
                   2801:     my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
                   2802:     if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
                   2803: 	return '<img src="'.$imgsrc.'" align="right" />';
                   2804:     } else {
                   2805: 	return '';
                   2806:     }
                   2807: }
                   2808: 
1.112     bowersj2 2809: =pod
                   2810: 
                   2811: =back
                   2812: 
                   2813: =head1 Access .tab File Data
                   2814: 
                   2815: =over 4
                   2816: 
1.648     raeburn  2817: =item * &languageids() 
1.112     bowersj2 2818: 
                   2819: returns list of all language ids
                   2820: 
                   2821: =cut
                   2822: 
1.14      harris41 2823: sub languageids {
1.16      harris41 2824:     return sort(keys(%language));
1.14      harris41 2825: }
                   2826: 
1.112     bowersj2 2827: =pod
                   2828: 
1.648     raeburn  2829: =item * &languagedescription() 
1.112     bowersj2 2830: 
                   2831: returns description of a specified language id
                   2832: 
                   2833: =cut
                   2834: 
1.14      harris41 2835: sub languagedescription {
1.125     www      2836:     my $code=shift;
                   2837:     return  ($supported_language{$code}?'* ':'').
                   2838:             $language{$code}.
1.126     www      2839: 	    ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145     www      2840: }
                   2841: 
                   2842: sub plainlanguagedescription {
                   2843:     my $code=shift;
                   2844:     return $language{$code};
                   2845: }
                   2846: 
                   2847: sub supportedlanguagecode {
                   2848:     my $code=shift;
                   2849:     return $supported_language{$code};
1.97      www      2850: }
                   2851: 
1.112     bowersj2 2852: =pod
                   2853: 
1.648     raeburn  2854: =item * &copyrightids() 
1.112     bowersj2 2855: 
                   2856: returns list of all copyrights
                   2857: 
                   2858: =cut
                   2859: 
                   2860: sub copyrightids {
                   2861:     return sort(keys(%cprtag));
                   2862: }
                   2863: 
                   2864: =pod
                   2865: 
1.648     raeburn  2866: =item * &copyrightdescription() 
1.112     bowersj2 2867: 
                   2868: returns description of a specified copyright id
                   2869: 
                   2870: =cut
                   2871: 
                   2872: sub copyrightdescription {
1.166     www      2873:     return &mt($cprtag{shift(@_)});
1.112     bowersj2 2874: }
1.197     matthew  2875: 
                   2876: =pod
                   2877: 
1.648     raeburn  2878: =item * &source_copyrightids() 
1.192     taceyjo1 2879: 
                   2880: returns list of all source copyrights
                   2881: 
                   2882: =cut
                   2883: 
                   2884: sub source_copyrightids {
                   2885:     return sort(keys(%scprtag));
                   2886: }
                   2887: 
                   2888: =pod
                   2889: 
1.648     raeburn  2890: =item * &source_copyrightdescription() 
1.192     taceyjo1 2891: 
                   2892: returns description of a specified source copyright id
                   2893: 
                   2894: =cut
                   2895: 
                   2896: sub source_copyrightdescription {
                   2897:     return &mt($scprtag{shift(@_)});
                   2898: }
1.112     bowersj2 2899: 
                   2900: =pod
                   2901: 
1.648     raeburn  2902: =item * &filecategories() 
1.112     bowersj2 2903: 
                   2904: returns list of all file categories
                   2905: 
                   2906: =cut
                   2907: 
                   2908: sub filecategories {
                   2909:     return sort(keys(%category_extensions));
                   2910: }
                   2911: 
                   2912: =pod
                   2913: 
1.648     raeburn  2914: =item * &filecategorytypes() 
1.112     bowersj2 2915: 
                   2916: returns list of file types belonging to a given file
                   2917: category
                   2918: 
                   2919: =cut
                   2920: 
                   2921: sub filecategorytypes {
1.356     albertel 2922:     my ($cat) = @_;
                   2923:     return @{$category_extensions{lc($cat)}};
1.112     bowersj2 2924: }
                   2925: 
                   2926: =pod
                   2927: 
1.648     raeburn  2928: =item * &fileembstyle() 
1.112     bowersj2 2929: 
                   2930: returns embedding style for a specified file type
                   2931: 
                   2932: =cut
                   2933: 
                   2934: sub fileembstyle {
                   2935:     return $fe{lc(shift(@_))};
1.169     www      2936: }
                   2937: 
1.351     www      2938: sub filemimetype {
                   2939:     return $fm{lc(shift(@_))};
                   2940: }
                   2941: 
1.169     www      2942: 
                   2943: sub filecategoryselect {
                   2944:     my ($name,$value)=@_;
1.189     matthew  2945:     return &select_form($value,$name,
1.169     www      2946: 			'' => &mt('Any category'),
                   2947: 			map { $_,$_ } sort(keys(%category_extensions)));
1.112     bowersj2 2948: }
                   2949: 
                   2950: =pod
                   2951: 
1.648     raeburn  2952: =item * &filedescription() 
1.112     bowersj2 2953: 
                   2954: returns description for a specified file type
                   2955: 
                   2956: =cut
                   2957: 
                   2958: sub filedescription {
1.188     matthew  2959:     my $file_description = $fd{lc(shift())};
                   2960:     $file_description =~ s:([\[\]]):~$1:g;
                   2961:     return &mt($file_description);
1.112     bowersj2 2962: }
                   2963: 
                   2964: =pod
                   2965: 
1.648     raeburn  2966: =item * &filedescriptionex() 
1.112     bowersj2 2967: 
                   2968: returns description for a specified file type with
                   2969: extra formatting
                   2970: 
                   2971: =cut
                   2972: 
                   2973: sub filedescriptionex {
                   2974:     my $ex=shift;
1.188     matthew  2975:     my $file_description = $fd{lc($ex)};
                   2976:     $file_description =~ s:([\[\]]):~$1:g;
                   2977:     return '.'.$ex.' '.&mt($file_description);
1.112     bowersj2 2978: }
                   2979: 
                   2980: # End of .tab access
                   2981: =pod
                   2982: 
                   2983: =back
                   2984: 
                   2985: =cut
                   2986: 
                   2987: # ------------------------------------------------------------------ File Types
                   2988: sub fileextensions {
                   2989:     return sort(keys(%fe));
                   2990: }
                   2991: 
1.97      www      2992: # ----------------------------------------------------------- Display Languages
                   2993: # returns a hash with all desired display languages
                   2994: #
                   2995: 
                   2996: sub display_languages {
                   2997:     my %languages=();
1.695     raeburn  2998:     foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356     albertel 2999: 	$languages{$lang}=1;
1.97      www      3000:     }
                   3001:     &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258     albertel 3002:     if ($env{'form.displaylanguage'}) {
1.356     albertel 3003: 	foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
                   3004: 	    $languages{$lang}=1;
1.97      www      3005:         }
                   3006:     }
                   3007:     return %languages;
1.14      harris41 3008: }
                   3009: 
1.582     albertel 3010: sub languages {
                   3011:     my ($possible_langs) = @_;
1.695     raeburn  3012:     my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582     albertel 3013:     if (!ref($possible_langs)) {
                   3014: 	if( wantarray ) {
                   3015: 	    return @preferred_langs;
                   3016: 	} else {
                   3017: 	    return $preferred_langs[0];
                   3018: 	}
                   3019:     }
                   3020:     my %possibilities = map { $_ => 1 } (@$possible_langs);
                   3021:     my @preferred_possibilities;
                   3022:     foreach my $preferred_lang (@preferred_langs) {
                   3023: 	if (exists($possibilities{$preferred_lang})) {
                   3024: 	    push(@preferred_possibilities, $preferred_lang);
                   3025: 	}
                   3026:     }
                   3027:     if( wantarray ) {
                   3028: 	return @preferred_possibilities;
                   3029:     }
                   3030:     return $preferred_possibilities[0];
                   3031: }
                   3032: 
1.112     bowersj2 3033: ###############################################################
                   3034: ##               Student Answer Attempts                     ##
                   3035: ###############################################################
                   3036: 
                   3037: =pod
                   3038: 
                   3039: =head1 Alternate Problem Views
                   3040: 
                   3041: =over 4
                   3042: 
1.648     raeburn  3043: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112     bowersj2 3044:     $getattempt, $regexp, $gradesub)
                   3045: 
                   3046: Return string with previous attempt on problem. Arguments:
                   3047: 
                   3048: =over 4
                   3049: 
                   3050: =item * $symb: Problem, including path
                   3051: 
                   3052: =item * $username: username of the desired student
                   3053: 
                   3054: =item * $domain: domain of the desired student
1.14      harris41 3055: 
1.112     bowersj2 3056: =item * $course: Course ID
1.14      harris41 3057: 
1.112     bowersj2 3058: =item * $getattempt: Leave blank for all attempts, otherwise put
                   3059:     something
1.14      harris41 3060: 
1.112     bowersj2 3061: =item * $regexp: if string matches this regexp, the string will be
                   3062:     sent to $gradesub
1.14      harris41 3063: 
1.112     bowersj2 3064: =item * $gradesub: routine that processes the string if it matches $regexp
1.14      harris41 3065: 
1.112     bowersj2 3066: =back
1.14      harris41 3067: 
1.112     bowersj2 3068: The output string is a table containing all desired attempts, if any.
1.16      harris41 3069: 
1.112     bowersj2 3070: =cut
1.1       albertel 3071: 
                   3072: sub get_previous_attempt {
1.43      ng       3073:   my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1       albertel 3074:   my $prevattempts='';
1.43      ng       3075:   no strict 'refs';
1.1       albertel 3076:   if ($symb) {
1.3       albertel 3077:     my (%returnhash)=
                   3078:       &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1       albertel 3079:     if ($returnhash{'version'}) {
                   3080:       my %lasthash=();
                   3081:       my $version;
                   3082:       for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356     albertel 3083:         foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
                   3084: 	  $lasthash{$key}=$returnhash{$version.':'.$key};
1.19      harris41 3085:         }
1.1       albertel 3086:       }
1.596     albertel 3087:       $prevattempts=&start_data_table().&start_data_table_header_row();
                   3088:       $prevattempts.='<th>'.&mt('History').'</th>';
1.356     albertel 3089:       foreach my $key (sort(keys(%lasthash))) {
                   3090: 	my ($ign,@parts) = split(/\./,$key);
1.41      ng       3091: 	if ($#parts > 0) {
1.31      albertel 3092: 	  my $data=$parts[-1];
                   3093: 	  pop(@parts);
1.596     albertel 3094: 	  $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.'&nbsp;</th>';
1.31      albertel 3095: 	} else {
1.41      ng       3096: 	  if ($#parts == 0) {
                   3097: 	    $prevattempts.='<th>'.$parts[0].'</th>';
                   3098: 	  } else {
                   3099: 	    $prevattempts.='<th>'.$ign.'</th>';
                   3100: 	  }
1.31      albertel 3101: 	}
1.16      harris41 3102:       }
1.596     albertel 3103:       $prevattempts.=&end_data_table_header_row();
1.40      ng       3104:       if ($getattempt eq '') {
                   3105: 	for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596     albertel 3106: 	  $prevattempts.=&start_data_table_row().
                   3107: 	      '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356     albertel 3108: 	    foreach my $key (sort(keys(%lasthash))) {
1.581     albertel 3109: 		my $value = &format_previous_attempt_value($key,
                   3110: 							   $returnhash{$version.':'.$key});
                   3111: 		$prevattempts.='<td>'.$value.'&nbsp;</td>';   
1.40      ng       3112: 	    }
1.596     albertel 3113: 	  $prevattempts.=&end_data_table_row();
1.40      ng       3114: 	 }
1.1       albertel 3115:       }
1.596     albertel 3116:       $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356     albertel 3117:       foreach my $key (sort(keys(%lasthash))) {
1.581     albertel 3118: 	my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356     albertel 3119: 	if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40      ng       3120: 	$prevattempts.='<td>'.$value.'&nbsp;</td>';
1.16      harris41 3121:       }
1.596     albertel 3122:       $prevattempts.= &end_data_table_row().&end_data_table();
1.1       albertel 3123:     } else {
1.596     albertel 3124:       $prevattempts=
                   3125: 	  &start_data_table().&start_data_table_row().
                   3126: 	  '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
                   3127: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3128:     }
                   3129:   } else {
1.596     albertel 3130:     $prevattempts=
                   3131: 	  &start_data_table().&start_data_table_row().
                   3132: 	  '<td>'.&mt('No data.').'</td>'.
                   3133: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3134:   }
1.10      albertel 3135: }
                   3136: 
1.581     albertel 3137: sub format_previous_attempt_value {
                   3138:     my ($key,$value) = @_;
                   3139:     if ($key =~ /timestamp/) {
                   3140: 	$value = &Apache::lonlocal::locallocaltime($value);
                   3141:     } elsif (ref($value) eq 'ARRAY') {
                   3142: 	$value = '('.join(', ', @{ $value }).')';
                   3143:     } else {
                   3144: 	$value = &unescape($value);
                   3145:     }
                   3146:     return $value;
                   3147: }
                   3148: 
                   3149: 
1.107     albertel 3150: sub relative_to_absolute {
                   3151:     my ($url,$output)=@_;
                   3152:     my $parser=HTML::TokeParser->new(\$output);
                   3153:     my $token;
                   3154:     my $thisdir=$url;
                   3155:     my @rlinks=();
                   3156:     while ($token=$parser->get_token) {
                   3157: 	if ($token->[0] eq 'S') {
                   3158: 	    if ($token->[1] eq 'a') {
                   3159: 		if ($token->[2]->{'href'}) {
                   3160: 		    $rlinks[$#rlinks+1]=$token->[2]->{'href'};
                   3161: 		}
                   3162: 	    } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
                   3163: 		$rlinks[$#rlinks+1]=$token->[2]->{'src'};
                   3164: 	    } elsif ($token->[1] eq 'base') {
                   3165: 		$thisdir=$token->[2]->{'href'};
                   3166: 	    }
                   3167: 	}
                   3168:     }
                   3169:     $thisdir=~s-/[^/]*$--;
1.356     albertel 3170:     foreach my $link (@rlinks) {
                   3171: 	unless (($link=~/^http:\/\//i) ||
                   3172: 		($link=~/^\//) ||
                   3173: 		($link=~/^javascript:/i) ||
                   3174: 		($link=~/^mailto:/i) ||
                   3175: 		($link=~/^\#/)) {
                   3176: 	    my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
                   3177: 	    $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107     albertel 3178: 	}
                   3179:     }
                   3180: # -------------------------------------------------- Deal with Applet codebases
                   3181:     $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
                   3182:     return $output;
                   3183: }
                   3184: 
1.112     bowersj2 3185: =pod
                   3186: 
1.648     raeburn  3187: =item * &get_student_view()
1.112     bowersj2 3188: 
                   3189: show a snapshot of what student was looking at
                   3190: 
                   3191: =cut
                   3192: 
1.10      albertel 3193: sub get_student_view {
1.186     albertel 3194:   my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114     www      3195:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3196:   my (%form);
1.10      albertel 3197:   my @elements=('symb','courseid','domain','username');
                   3198:   foreach my $element (@elements) {
1.186     albertel 3199:       $form{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3200:   }
1.186     albertel 3201:   if (defined($moreenv)) {
                   3202:       %form=(%form,%{$moreenv});
                   3203:   }
1.236     albertel 3204:   if (defined($target)) { $form{'grade_target'} = $target; }
1.107     albertel 3205:   $feedurl=&Apache::lonnet::clutter($feedurl);
1.650     www      3206:   my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11      albertel 3207:   $userview=~s/\<body[^\>]*\>//gi;
                   3208:   $userview=~s/\<\/body\>//gi;
                   3209:   $userview=~s/\<html\>//gi;
                   3210:   $userview=~s/\<\/html\>//gi;
                   3211:   $userview=~s/\<head\>//gi;
                   3212:   $userview=~s/\<\/head\>//gi;
                   3213:   $userview=~s/action\s*\=/would_be_action\=/gi;
1.107     albertel 3214:   $userview=&relative_to_absolute($feedurl,$userview);
1.650     www      3215:   if (wantarray) {
                   3216:      return ($userview,$response);
                   3217:   } else {
                   3218:      return $userview;
                   3219:   }
                   3220: }
                   3221: 
                   3222: sub get_student_view_with_retries {
                   3223:   my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
                   3224: 
                   3225:     my $ok = 0;                 # True if we got a good response.
                   3226:     my $content;
                   3227:     my $response;
                   3228: 
                   3229:     # Try to get the student_view done. within the retries count:
                   3230:     
                   3231:     do {
                   3232:          ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
                   3233:          $ok      = $response->is_success;
                   3234:          if (!$ok) {
                   3235:             &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
                   3236:          }
                   3237:          $retries--;
                   3238:     } while (!$ok && ($retries > 0));
                   3239:     
                   3240:     if (!$ok) {
                   3241:        $content = '';          # On error return an empty content.
                   3242:     }
1.651     www      3243:     if (wantarray) {
                   3244:        return ($content, $response);
                   3245:     } else {
                   3246:        return $content;
                   3247:     }
1.11      albertel 3248: }
                   3249: 
1.112     bowersj2 3250: =pod
                   3251: 
1.648     raeburn  3252: =item * &get_student_answers() 
1.112     bowersj2 3253: 
                   3254: show a snapshot of how student was answering problem
                   3255: 
                   3256: =cut
                   3257: 
1.11      albertel 3258: sub get_student_answers {
1.100     sakharuk 3259:   my ($symb,$username,$domain,$courseid,%form) = @_;
1.114     www      3260:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3261:   my (%moreenv);
1.11      albertel 3262:   my @elements=('symb','courseid','domain','username');
                   3263:   foreach my $element (@elements) {
1.186     albertel 3264:     $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3265:   }
1.186     albertel 3266:   $moreenv{'grade_target'}='answer';
                   3267:   %moreenv=(%form,%moreenv);
1.497     raeburn  3268:   $feedurl = &Apache::lonnet::clutter($feedurl);
                   3269:   my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10      albertel 3270:   return $userview;
1.1       albertel 3271: }
1.116     albertel 3272: 
                   3273: =pod
                   3274: 
                   3275: =item * &submlink()
                   3276: 
1.242     albertel 3277: Inputs: $text $uname $udom $symb $target
1.116     albertel 3278: 
                   3279: Returns: A link to grades.pm such as to see the SUBM view of a student
                   3280: 
                   3281: =cut
                   3282: 
                   3283: ###############################################
                   3284: sub submlink {
1.242     albertel 3285:     my ($text,$uname,$udom,$symb,$target)=@_;
1.116     albertel 3286:     if (!($uname && $udom)) {
                   3287: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3288: 	    &Apache::lonnet::whichuser($symb);
1.116     albertel 3289: 	if (!$symb) { $symb=$cursymb; }
                   3290:     }
1.254     matthew  3291:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3292:     $symb=&escape($symb);
1.242     albertel 3293:     if ($target) { $target="target=\"$target\""; }
                   3294:     return '<a href="/adm/grades?&command=submission&'.
                   3295: 	'symb='.$symb.'&student='.$uname.
                   3296: 	'&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
                   3297: }
                   3298: ##############################################
                   3299: 
                   3300: =pod
                   3301: 
                   3302: =item * &pgrdlink()
                   3303: 
                   3304: Inputs: $text $uname $udom $symb $target
                   3305: 
                   3306: Returns: A link to grades.pm such as to see the PGRD view of a student
                   3307: 
                   3308: =cut
                   3309: 
                   3310: ###############################################
                   3311: sub pgrdlink {
                   3312:     my $link=&submlink(@_);
                   3313:     $link=~s/(&command=submission)/$1&showgrading=yes/;
                   3314:     return $link;
                   3315: }
                   3316: ##############################################
                   3317: 
                   3318: =pod
                   3319: 
                   3320: =item * &pprmlink()
                   3321: 
                   3322: Inputs: $text $uname $udom $symb $target
                   3323: 
                   3324: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283     albertel 3325: student and a specific resource
1.242     albertel 3326: 
                   3327: =cut
                   3328: 
                   3329: ###############################################
                   3330: sub pprmlink {
                   3331:     my ($text,$uname,$udom,$symb,$target)=@_;
                   3332:     if (!($uname && $udom)) {
                   3333: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3334: 	    &Apache::lonnet::whichuser($symb);
1.242     albertel 3335: 	if (!$symb) { $symb=$cursymb; }
                   3336:     }
1.254     matthew  3337:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3338:     $symb=&escape($symb);
1.242     albertel 3339:     if ($target) { $target="target=\"$target\""; }
1.595     albertel 3340:     return '<a href="/adm/parmset?command=set&amp;'.
                   3341: 	'symb='.$symb.'&amp;uname='.$uname.
                   3342: 	'&amp;udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116     albertel 3343: }
                   3344: ##############################################
1.37      matthew  3345: 
1.112     bowersj2 3346: =pod
                   3347: 
                   3348: =back
                   3349: 
                   3350: =cut
                   3351: 
1.37      matthew  3352: ###############################################
1.51      www      3353: 
                   3354: 
                   3355: sub timehash {
1.687     raeburn  3356:     my ($thistime) = @_;
                   3357:     my $timezone = &Apache::lonlocal::gettimezone();
                   3358:     my $dt = DateTime->from_epoch(epoch => $thistime)
                   3359:                      ->set_time_zone($timezone);
                   3360:     my $wday = $dt->day_of_week();
                   3361:     if ($wday == 7) { $wday = 0; }
                   3362:     return ( 'second' => $dt->second(),
                   3363:              'minute' => $dt->minute(),
                   3364:              'hour'   => $dt->hour(),
                   3365:              'day'     => $dt->day_of_month(),
                   3366:              'month'   => $dt->month(),
                   3367:              'year'    => $dt->year(),
                   3368:              'weekday' => $wday,
                   3369:              'dayyear' => $dt->day_of_year(),
                   3370:              'dlsav'   => $dt->is_dst() );
1.51      www      3371: }
                   3372: 
1.370     www      3373: sub utc_string {
                   3374:     my ($date)=@_;
1.371     www      3375:     return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370     www      3376: }
                   3377: 
1.51      www      3378: sub maketime {
                   3379:     my %th=@_;
1.687     raeburn  3380:     my ($epoch_time,$timezone,$dt);
                   3381:     $timezone = &Apache::lonlocal::gettimezone();
                   3382:     eval {
                   3383:         $dt = DateTime->new( year   => $th{'year'},
                   3384:                              month  => $th{'month'},
                   3385:                              day    => $th{'day'},
                   3386:                              hour   => $th{'hour'},
                   3387:                              minute => $th{'minute'},
                   3388:                              second => $th{'second'},
                   3389:                              time_zone => $timezone,
                   3390:                          );
                   3391:     };
                   3392:     if (!$@) {
                   3393:         $epoch_time = $dt->epoch;
                   3394:         if ($epoch_time) {
                   3395:             return $epoch_time;
                   3396:         }
                   3397:     }
1.51      www      3398:     return POSIX::mktime(
                   3399:         ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210     www      3400:          $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70      www      3401: }
                   3402: 
                   3403: #########################################
1.51      www      3404: 
                   3405: sub findallcourses {
1.482     raeburn  3406:     my ($roles,$uname,$udom) = @_;
1.355     albertel 3407:     my %roles;
                   3408:     if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348     albertel 3409:     my %courses;
1.51      www      3410:     my $now=time;
1.482     raeburn  3411:     if (!defined($uname)) {
                   3412:         $uname = $env{'user.name'};
                   3413:     }
                   3414:     if (!defined($udom)) {
                   3415:         $udom = $env{'user.domain'};
                   3416:     }
                   3417:     if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
                   3418:         my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
                   3419:         if (!%roles) {
                   3420:             %roles = (
                   3421:                        cc => 1,
                   3422:                        in => 1,
                   3423:                        ep => 1,
                   3424:                        ta => 1,
                   3425:                        cr => 1,
                   3426:                        st => 1,
                   3427:              );
                   3428:         }
                   3429:         foreach my $entry (keys(%roleshash)) {
                   3430:             my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
                   3431:             if ($trole =~ /^cr/) { 
                   3432:                 next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
                   3433:             } else {
                   3434:                 next if (!exists($roles{$trole}));
                   3435:             }
                   3436:             if ($tend) {
                   3437:                 next if ($tend < $now);
                   3438:             }
                   3439:             if ($tstart) {
                   3440:                 next if ($tstart > $now);
                   3441:             }
                   3442:             my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
                   3443:             (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
                   3444:             if ($secpart eq '') {
                   3445:                 ($cnum,$role) = split(/_/,$cnumpart); 
                   3446:                 $sec = 'none';
                   3447:                 $realsec = '';
                   3448:             } else {
                   3449:                 $cnum = $cnumpart;
                   3450:                 ($sec,$role) = split(/_/,$secpart);
                   3451:                 $realsec = $sec;
1.490     raeburn  3452:             }
1.482     raeburn  3453:             $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
                   3454:         }
                   3455:     } else {
                   3456:         foreach my $key (keys(%env)) {
1.483     albertel 3457: 	    if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
                   3458:                  $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482     raeburn  3459: 	        my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
                   3460: 	        next if ($role eq 'ca' || $role eq 'aa');
                   3461: 	        next if (%roles && !exists($roles{$role}));
                   3462: 	        my ($starttime,$endtime)=split(/\./,$env{$key});
                   3463:                 my $active=1;
                   3464:                 if ($starttime) {
                   3465: 		    if ($now<$starttime) { $active=0; }
                   3466:                 }
                   3467:                 if ($endtime) {
                   3468:                     if ($now>$endtime) { $active=0; }
                   3469:                 }
                   3470:                 if ($active) {
                   3471:                     if ($sec eq '') {
                   3472:                         $sec = 'none';
                   3473:                     }
                   3474:                     $courses{$cdom.'_'.$cnum}{$sec} = 
                   3475:                                      $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474     raeburn  3476:                 }
                   3477:             }
1.51      www      3478:         }
                   3479:     }
1.474     raeburn  3480:     return %courses;
1.51      www      3481: }
1.37      matthew  3482: 
1.54      www      3483: ###############################################
1.474     raeburn  3484: 
                   3485: sub blockcheck {
1.482     raeburn  3486:     my ($setters,$activity,$uname,$udom) = @_;
1.490     raeburn  3487: 
                   3488:     if (!defined($udom)) {
                   3489:         $udom = $env{'user.domain'};
                   3490:     }
                   3491:     if (!defined($uname)) {
                   3492:         $uname = $env{'user.name'};
                   3493:     }
                   3494: 
                   3495:     # If uname and udom are for a course, check for blocks in the course.
                   3496: 
                   3497:     if (&Apache::lonnet::is_course($udom,$uname)) {
                   3498:         my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502     raeburn  3499:         my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490     raeburn  3500:         return ($startblock,$endblock);
                   3501:     }
1.474     raeburn  3502: 
1.502     raeburn  3503:     my $startblock = 0;
                   3504:     my $endblock = 0;
1.482     raeburn  3505:     my %live_courses = &findallcourses(undef,$uname,$udom);
1.474     raeburn  3506: 
1.490     raeburn  3507:     # If uname is for a user, and activity is course-specific, i.e.,
                   3508:     # boards, chat or groups, check for blocking in current course only.
1.474     raeburn  3509: 
1.490     raeburn  3510:     if (($activity eq 'boards' || $activity eq 'chat' ||
                   3511:          $activity eq 'groups') && ($env{'request.course.id'})) {
                   3512:         foreach my $key (keys(%live_courses)) {
                   3513:             if ($key ne $env{'request.course.id'}) {
                   3514:                 delete($live_courses{$key});
                   3515:             }
                   3516:         }
                   3517:     }
                   3518: 
                   3519:     my $otheruser = 0;
                   3520:     my %own_courses;
                   3521:     if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
                   3522:         # Resource belongs to user other than current user.
                   3523:         $otheruser = 1;
                   3524:         # Gather courses for current user
                   3525:         %own_courses = 
                   3526:             &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
                   3527:     }
                   3528: 
                   3529:     # Gather active course roles - course coordinator, instructor, 
                   3530:     # exam proctor, ta, student, or custom role.
1.474     raeburn  3531: 
                   3532:     foreach my $course (keys(%live_courses)) {
1.482     raeburn  3533:         my ($cdom,$cnum);
                   3534:         if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
                   3535:             $cdom = $env{'course.'.$course.'.domain'};
                   3536:             $cnum = $env{'course.'.$course.'.num'};
                   3537:         } else {
1.490     raeburn  3538:             ($cdom,$cnum) = split(/_/,$course); 
1.482     raeburn  3539:         }
                   3540:         my $no_ownblock = 0;
                   3541:         my $no_userblock = 0;
1.533     raeburn  3542:         if ($otheruser && $activity ne 'com') {
1.490     raeburn  3543:             # Check if current user has 'evb' priv for this
                   3544:             if (defined($own_courses{$course})) {
                   3545:                 foreach my $sec (keys(%{$own_courses{$course}})) {
                   3546:                     my $checkrole = 'cm./'.$cdom.'/'.$cnum;
                   3547:                     if ($sec ne 'none') {
                   3548:                         $checkrole .= '/'.$sec;
                   3549:                     }
                   3550:                     if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   3551:                         $no_ownblock = 1;
                   3552:                         last;
                   3553:                     }
                   3554:                 }
                   3555:             }
                   3556:             # if they have 'evb' priv and are currently not playing student
                   3557:             next if (($no_ownblock) &&
                   3558:                  ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
                   3559:         }
1.474     raeburn  3560:         foreach my $sec (keys(%{$live_courses{$course}})) {
1.482     raeburn  3561:             my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474     raeburn  3562:             if ($sec ne 'none') {
1.482     raeburn  3563:                 $checkrole .= '/'.$sec;
1.474     raeburn  3564:             }
1.490     raeburn  3565:             if ($otheruser) {
                   3566:                 # Resource belongs to user other than current user.
                   3567:                 # Assemble privs for that user, and check for 'evb' priv.
1.482     raeburn  3568:                 my ($trole,$tdom,$tnum,$tsec);
                   3569:                 my $entry = $live_courses{$course}{$sec};
                   3570:                 if ($entry =~ /^cr/) {
                   3571:                     ($trole,$tdom,$tnum,$tsec) = 
                   3572:                       ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
                   3573:                 } else {
                   3574:                     ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
                   3575:                 }
                   3576:                 my ($spec,$area,$trest,%allroles,%userroles);
                   3577:                 $area = '/'.$tdom.'/'.$tnum;
                   3578:                 $trest = $tnum;
                   3579:                 if ($tsec ne '') {
                   3580:                     $area .= '/'.$tsec;
                   3581:                     $trest .= '/'.$tsec;
                   3582:                 }
                   3583:                 $spec = $trole.'.'.$area;
                   3584:                 if ($trole =~ /^cr/) {
                   3585:                     &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
                   3586:                                                       $tdom,$spec,$trest,$area);
                   3587:                 } else {
                   3588:                     &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
                   3589:                                                        $tdom,$spec,$trest,$area);
                   3590:                 }
                   3591:                 my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486     raeburn  3592:                 if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
                   3593:                     if ($1) {
                   3594:                         $no_userblock = 1;
                   3595:                         last;
                   3596:                     }
                   3597:                 }
1.490     raeburn  3598:             } else {
                   3599:                 # Resource belongs to current user
                   3600:                 # Check for 'evb' priv via lonnet::allowed().
1.482     raeburn  3601:                 if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   3602:                     $no_ownblock = 1;
                   3603:                     last;
                   3604:                 }
1.474     raeburn  3605:             }
                   3606:         }
                   3607:         # if they have the evb priv and are currently not playing student
1.482     raeburn  3608:         next if (($no_ownblock) &&
1.491     albertel 3609:                  ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482     raeburn  3610:         next if ($no_userblock);
1.474     raeburn  3611: 
1.490     raeburn  3612:         # Retrieve blocking times and identity of blocker for course
                   3613:         # of specified user, unless user has 'evb' privilege.
1.502     raeburn  3614:         
                   3615:         my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
                   3616:         if (($start != 0) && 
                   3617:             (($startblock == 0) || ($startblock > $start))) {
                   3618:             $startblock = $start;
                   3619:         }
                   3620:         if (($end != 0)  &&
                   3621:             (($endblock == 0) || ($endblock < $end))) {
                   3622:             $endblock = $end;
                   3623:         }
1.490     raeburn  3624:     }
                   3625:     return ($startblock,$endblock);
                   3626: }
                   3627: 
                   3628: sub get_blocks {
                   3629:     my ($setters,$activity,$cdom,$cnum) = @_;
                   3630:     my $startblock = 0;
                   3631:     my $endblock = 0;
                   3632:     my $course = $cdom.'_'.$cnum;
                   3633:     $setters->{$course} = {};
                   3634:     $setters->{$course}{'staff'} = [];
                   3635:     $setters->{$course}{'times'} = [];
                   3636:     my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
                   3637:     foreach my $record (keys(%records)) {
                   3638:         my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
                   3639:         if ($start <= time && $end >= time) {
                   3640:             my ($staff_name,$staff_dom,$title,$blocks) =
                   3641:                 &parse_block_record($records{$record});
                   3642:             if ($blocks->{$activity} eq 'on') {
                   3643:                 push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
                   3644:                 push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491     albertel 3645:                 if ( ($startblock == 0) || ($startblock > $start) ) {
                   3646:                     $startblock = $start;
1.490     raeburn  3647:                 }
1.491     albertel 3648:                 if ( ($endblock == 0) || ($endblock < $end) ) {
                   3649:                     $endblock = $end;
1.474     raeburn  3650:                 }
                   3651:             }
                   3652:         }
                   3653:     }
                   3654:     return ($startblock,$endblock);
                   3655: }
                   3656: 
                   3657: sub parse_block_record {
                   3658:     my ($record) = @_;
                   3659:     my ($setuname,$setudom,$title,$blocks);
                   3660:     if (ref($record) eq 'HASH') {
                   3661:         ($setuname,$setudom) = split(/:/,$record->{'setter'});
                   3662:         $title = &unescape($record->{'event'});
                   3663:         $blocks = $record->{'blocks'};
                   3664:     } else {
                   3665:         my @data = split(/:/,$record,3);
                   3666:         if (scalar(@data) eq 2) {
                   3667:             $title = $data[1];
                   3668:             ($setuname,$setudom) = split(/@/,$data[0]);
                   3669:         } else {
                   3670:             ($setuname,$setudom,$title) = @data;
                   3671:         }
                   3672:         $blocks = { 'com' => 'on' };
                   3673:     }
                   3674:     return ($setuname,$setudom,$title,$blocks);
                   3675: }
                   3676: 
                   3677: sub build_block_table {
                   3678:     my ($startblock,$endblock,$setters) = @_;
                   3679:     my %lt = &Apache::lonlocal::texthash(
                   3680:         'cacb' => 'Currently active communication blocks',
                   3681:         'cour' => 'Course',
                   3682:         'dura' => 'Duration',
                   3683:         'blse' => 'Block set by'
                   3684:     );
                   3685:     my $output;
1.476     raeburn  3686:     $output = '<br />'.$lt{'cacb'}.':<br />';
1.474     raeburn  3687:     $output .= &start_data_table();
                   3688:     $output .= '
                   3689: <tr>
                   3690:  <th>'.$lt{'cour'}.'</th>
                   3691:  <th>'.$lt{'dura'}.'</th>
                   3692:  <th>'.$lt{'blse'}.'</th>
                   3693: </tr>
                   3694: ';
                   3695:     foreach my $course (keys(%{$setters})) {
                   3696:         my %courseinfo=&Apache::lonnet::coursedescription($course);
                   3697:         for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
                   3698:             my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
1.490     raeburn  3699:             my $fullname = &plainname($uname,$udom);
                   3700:             if (defined($env{'user.name'}) && defined($env{'user.domain'})
                   3701:                 && $env{'user.name'} ne 'public' 
                   3702:                 && $env{'user.domain'} ne 'public') {
                   3703:                 $fullname = &aboutmewrapper($fullname,$uname,$udom);
                   3704:             }
1.474     raeburn  3705:             my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
                   3706:             $openblock = &Apache::lonlocal::locallocaltime($openblock);
                   3707:             $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
                   3708:             $output .= &Apache::loncommon::start_data_table_row().
                   3709:                        '<td>'.$courseinfo{'description'}.'</td>'.
                   3710:                        '<td>'.$openblock.' to '.$closeblock.'</td>'.
1.490     raeburn  3711:                        '<td>'.$fullname.'</td>'.
1.474     raeburn  3712:                         &Apache::loncommon::end_data_table_row();
                   3713:         }
                   3714:     }
                   3715:     $output .= &end_data_table();
                   3716: }
                   3717: 
1.490     raeburn  3718: sub blocking_status {
                   3719:     my ($activity,$uname,$udom) = @_;
                   3720:     my %setters;
                   3721:     my ($blocked,$output,$ownitem,$is_course);
                   3722:     my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
                   3723:     if ($startblock && $endblock) {
                   3724:         $blocked = 1;
                   3725:         if (wantarray) {
                   3726:             my $category;
                   3727:             if ($activity eq 'boards') {
                   3728:                 $category = 'Discussion posts in this course';
                   3729:             } elsif ($activity eq 'blogs') {
                   3730:                 $category = 'Blogs';
                   3731:             } elsif ($activity eq 'port') {
                   3732:                 if (defined($uname) && defined($udom)) {
                   3733:                     if ($uname eq $env{'user.name'} &&
                   3734:                         $udom eq $env{'user.domain'}) {
                   3735:                         $ownitem = 1;
                   3736:                     }
                   3737:                 }
                   3738:                 $is_course = &Apache::lonnet::is_course($udom,$uname);
                   3739:                 if ($ownitem) { 
                   3740:                     $category = 'Your portfolio files';  
                   3741:                 } elsif ($is_course) {
                   3742:                     my $coursedesc;
                   3743:                     foreach my $course (keys(%setters)) {
                   3744:                         my %courseinfo =
                   3745:                              &Apache::lonnet::coursedescription($course);
                   3746:                         $coursedesc = $courseinfo{'description'};
                   3747:                     }
                   3748:                     $category = "Group files in the course '$coursedesc'";
                   3749:                 } else {
                   3750:                     $category = 'Portfolio files belonging to ';
                   3751:                     if ($env{'user.name'} eq 'public' && 
                   3752:                         $env{'user.domain'} eq 'public') {
                   3753:                         $category .= &plainname($uname,$udom);
                   3754:                     } else {
                   3755:                         $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);  
                   3756:                     }
                   3757:                 }
                   3758:             } elsif ($activity eq 'groups') {
                   3759:                 $category = 'Groups in this course';
                   3760:             }
                   3761:             my $showstart = &Apache::lonlocal::locallocaltime($startblock);
                   3762:             my $showend = &Apache::lonlocal::locallocaltime($endblock);
                   3763:             $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
                   3764:             if (!($activity eq 'port' && !($ownitem) && !($is_course))) { 
                   3765:                 $output .= &build_block_table($startblock,$endblock,\%setters);
                   3766:             }
                   3767:         }
                   3768:     }
                   3769:     if (wantarray) {
                   3770:         return ($blocked,$output);
                   3771:     } else {
                   3772:         return $blocked;
                   3773:     }
                   3774: }
                   3775: 
1.60      matthew  3776: ###############################################
                   3777: 
1.682     raeburn  3778: sub check_ip_acc {
                   3779:     my ($acc)=@_;
                   3780:     &Apache::lonxml::debug("acc is $acc");
                   3781:     if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
                   3782:         return 1;
                   3783:     }
                   3784:     my $allowed=0;
                   3785:     my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
                   3786: 
                   3787:     my $name;
                   3788:     foreach my $pattern (split(',',$acc)) {
                   3789:         $pattern =~ s/^\s*//;
                   3790:         $pattern =~ s/\s*$//;
                   3791:         if ($pattern =~ /\*$/) {
                   3792:             #35.8.*
                   3793:             $pattern=~s/\*//;
                   3794:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   3795:         } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
                   3796:             #35.8.3.[34-56]
                   3797:             my $low=$2;
                   3798:             my $high=$3;
                   3799:             $pattern=$1;
                   3800:             if ($ip =~ /^\Q$pattern\E/) {
                   3801:                 my $last=(split(/\./,$ip))[3];
                   3802:                 if ($last <=$high && $last >=$low) { $allowed=1; }
                   3803:             }
                   3804:         } elsif ($pattern =~ /^\*/) {
                   3805:             #*.msu.edu
                   3806:             $pattern=~s/\*//;
                   3807:             if (!defined($name)) {
                   3808:                 use Socket;
                   3809:                 my $netaddr=inet_aton($ip);
                   3810:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   3811:             }
                   3812:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   3813:         } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
                   3814:             #127.0.0.1
                   3815:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   3816:         } else {
                   3817:             #some.name.com
                   3818:             if (!defined($name)) {
                   3819:                 use Socket;
                   3820:                 my $netaddr=inet_aton($ip);
                   3821:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   3822:             }
                   3823:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   3824:         }
                   3825:         if ($allowed) { last; }
                   3826:     }
                   3827:     return $allowed;
                   3828: }
                   3829: 
                   3830: ###############################################
                   3831: 
1.60      matthew  3832: =pod
                   3833: 
1.112     bowersj2 3834: =head1 Domain Template Functions
                   3835: 
                   3836: =over 4
                   3837: 
                   3838: =item * &determinedomain()
1.60      matthew  3839: 
                   3840: Inputs: $domain (usually will be undef)
                   3841: 
1.63      www      3842: Returns: Determines which domain should be used for designs
1.60      matthew  3843: 
                   3844: =cut
1.54      www      3845: 
1.60      matthew  3846: ###############################################
1.63      www      3847: sub determinedomain {
                   3848:     my $domain=shift;
1.531     albertel 3849:     if (! $domain) {
1.60      matthew  3850:         # Determine domain if we have not been given one
                   3851:         $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258     albertel 3852:         if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
                   3853:         if ($env{'request.role.domain'}) { 
                   3854:             $domain=$env{'request.role.domain'}; 
1.60      matthew  3855:         }
                   3856:     }
1.63      www      3857:     return $domain;
                   3858: }
                   3859: ###############################################
1.517     raeburn  3860: 
1.518     albertel 3861: sub devalidate_domconfig_cache {
                   3862:     my ($udom)=@_;
                   3863:     &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
                   3864: }
                   3865: 
                   3866: # ---------------------- Get domain configuration for a domain
                   3867: sub get_domainconf {
                   3868:     my ($udom) = @_;
                   3869:     my $cachetime=1800;
                   3870:     my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
                   3871:     if (defined($cached)) { return %{$result}; }
                   3872: 
                   3873:     my %domconfig = &Apache::lonnet::get_dom('configuration',
                   3874: 					     ['login','rolecolors'],$udom);
1.632     raeburn  3875:     my (%designhash,%legacy);
1.518     albertel 3876:     if (keys(%domconfig) > 0) {
                   3877:         if (ref($domconfig{'login'}) eq 'HASH') {
1.632     raeburn  3878:             if (keys(%{$domconfig{'login'}})) {
                   3879:                 foreach my $key (keys(%{$domconfig{'login'}})) {
1.699     raeburn  3880:                     if (ref($domconfig{'login'}{$key}) eq 'HASH') {
                   3881:                         foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
                   3882:                             $designhash{$udom.'.login.'.$key.'_'.$img} = 
                   3883:                                 $domconfig{'login'}{$key}{$img};
                   3884:                         }
                   3885:                     } else {
                   3886:                         $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
                   3887:                     }
1.632     raeburn  3888:                 }
                   3889:             } else {
                   3890:                 $legacy{'login'} = 1;
1.518     albertel 3891:             }
1.632     raeburn  3892:         } else {
                   3893:             $legacy{'login'} = 1;
1.518     albertel 3894:         }
                   3895:         if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632     raeburn  3896:             if (keys(%{$domconfig{'rolecolors'}})) {
                   3897:                 foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
                   3898:                     if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
                   3899:                         foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
                   3900:                             $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
                   3901:                         }
1.518     albertel 3902:                     }
                   3903:                 }
1.632     raeburn  3904:             } else {
                   3905:                 $legacy{'rolecolors'} = 1;
1.518     albertel 3906:             }
1.632     raeburn  3907:         } else {
                   3908:             $legacy{'rolecolors'} = 1;
1.518     albertel 3909:         }
1.632     raeburn  3910:         if (keys(%legacy) > 0) {
                   3911:             my %legacyhash = &get_legacy_domconf($udom);
                   3912:             foreach my $item (keys(%legacyhash)) {
                   3913:                 if ($item =~ /^\Q$udom\E\.login/) {
                   3914:                     if ($legacy{'login'}) { 
                   3915:                         $designhash{$item} = $legacyhash{$item};
                   3916:                     }
                   3917:                 } else {
                   3918:                     if ($legacy{'rolecolors'}) {
                   3919:                         $designhash{$item} = $legacyhash{$item};
                   3920:                     }
1.518     albertel 3921:                 }
                   3922:             }
                   3923:         }
1.632     raeburn  3924:     } else {
                   3925:         %designhash = &get_legacy_domconf($udom); 
1.518     albertel 3926:     }
                   3927:     &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
                   3928: 				  $cachetime);
                   3929:     return %designhash;
                   3930: }
                   3931: 
1.632     raeburn  3932: sub get_legacy_domconf {
                   3933:     my ($udom) = @_;
                   3934:     my %legacyhash;
                   3935:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
                   3936:     my $designfile =  $designdir.'/'.$udom.'.tab';
                   3937:     if (-e $designfile) {
                   3938:         if ( open (my $fh,"<$designfile") ) {
                   3939:             while (my $line = <$fh>) {
                   3940:                 next if ($line =~ /^\#/);
                   3941:                 chomp($line);
                   3942:                 my ($key,$val)=(split(/\=/,$line));
                   3943:                 if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
                   3944:             }
                   3945:             close($fh);
                   3946:         }
                   3947:     }
                   3948:     if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
                   3949:         $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
                   3950:     }
                   3951:     return %legacyhash;
                   3952: }
                   3953: 
1.63      www      3954: =pod
                   3955: 
1.112     bowersj2 3956: =item * &domainlogo()
1.63      www      3957: 
                   3958: Inputs: $domain (usually will be undef)
                   3959: 
                   3960: Returns: A link to a domain logo, if the domain logo exists.
                   3961: If the domain logo does not exist, a description of the domain.
                   3962: 
                   3963: =cut
1.112     bowersj2 3964: 
1.63      www      3965: ###############################################
                   3966: sub domainlogo {
1.517     raeburn  3967:     my $domain = &determinedomain(shift);
1.518     albertel 3968:     my %designhash = &get_domainconf($domain);    
1.517     raeburn  3969:     # See if there is a logo
                   3970:     if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519     raeburn  3971:         my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538     albertel 3972:         if ($imgsrc =~ m{^/(adm|res)/}) {
                   3973: 	    if ($imgsrc =~ m{^/res/}) {
                   3974: 		my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
                   3975: 		&Apache::lonnet::repcopy($local_name);
                   3976: 	    }
                   3977: 	   $imgsrc = &lonhttpdurl($imgsrc);
1.519     raeburn  3978:         } 
                   3979:         return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514     albertel 3980:     } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
                   3981:         return &Apache::lonnet::domain($domain,'description');
1.59      www      3982:     } else {
1.60      matthew  3983:         return '';
1.59      www      3984:     }
                   3985: }
1.63      www      3986: ##############################################
                   3987: 
                   3988: =pod
                   3989: 
1.112     bowersj2 3990: =item * &designparm()
1.63      www      3991: 
                   3992: Inputs: $which parameter; $domain (usually will be undef)
                   3993: 
                   3994: Returns: value of designparamter $which
                   3995: 
                   3996: =cut
1.112     bowersj2 3997: 
1.397     albertel 3998: 
1.400     albertel 3999: ##############################################
1.397     albertel 4000: sub designparm {
                   4001:     my ($which,$domain)=@_;
1.258     albertel 4002:     if ($env{'browser.blackwhite'} eq 'on') {
1.635     raeburn  4003: 	if ($which=~/\.(font|alink|vlink|link|textcol)$/) {
1.110     www      4004: 	    return '#000000';
                   4005: 	}
1.635     raeburn  4006: 	if ($which=~/\.(pgbg|sidebg|bgcol)$/) {
1.110     www      4007: 	    return '#FFFFFF';
                   4008: 	}
                   4009: 	if ($which=~/\.tabbg$/) {
                   4010: 	    return '#CCCCCC';
                   4011: 	}
                   4012:     }
1.397     albertel 4013:     if (exists($env{'environment.color.'.$which})) {
1.258     albertel 4014: 	return $env{'environment.color.'.$which};
1.96      www      4015:     }
1.63      www      4016:     $domain=&determinedomain($domain);
1.518     albertel 4017:     my %domdesign = &get_domainconf($domain);
1.520     raeburn  4018:     my $output;
1.517     raeburn  4019:     if ($domdesign{$domain.'.'.$which} ne '') {
1.520     raeburn  4020: 	$output = $domdesign{$domain.'.'.$which};
1.63      www      4021:     } else {
1.520     raeburn  4022:         $output = $defaultdesign{$which};
                   4023:     }
                   4024:     if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635     raeburn  4025:         ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538     albertel 4026:         if ($output =~ m{^/(adm|res)/}) {
                   4027: 	    if ($output =~ m{^/res/}) {
                   4028: 		my $local_name = &Apache::lonnet::filelocation('',$output);
                   4029: 		&Apache::lonnet::repcopy($local_name);
                   4030: 	    }
1.520     raeburn  4031:             $output = &lonhttpdurl($output);
                   4032:         }
1.63      www      4033:     }
1.520     raeburn  4034:     return $output;
1.63      www      4035: }
1.59      www      4036: 
1.60      matthew  4037: ###############################################
                   4038: ###############################################
                   4039: 
                   4040: =pod
                   4041: 
1.112     bowersj2 4042: =back
                   4043: 
1.549     albertel 4044: =head1 HTML Helpers
1.112     bowersj2 4045: 
                   4046: =over 4
                   4047: 
                   4048: =item * &bodytag()
1.60      matthew  4049: 
                   4050: Returns a uniform header for LON-CAPA web pages.
                   4051: 
                   4052: Inputs: 
                   4053: 
1.112     bowersj2 4054: =over 4
                   4055: 
                   4056: =item * $title, A title to be displayed on the page.
                   4057: 
                   4058: =item * $function, the current role (can be undef).
                   4059: 
                   4060: =item * $addentries, extra parameters for the <body> tag.
                   4061: 
                   4062: =item * $bodyonly, if defined, only return the <body> tag.
                   4063: 
                   4064: =item * $domain, if defined, force a given domain.
                   4065: 
                   4066: =item * $forcereg, if page should register as content page (relevant for 
1.86      www      4067:             text interface only)
1.60      matthew  4068: 
1.326     albertel 4069: =item * $customtitle, alternate text to use instead of $title
                   4070:                       in the title box that appears, this text
                   4071:                       is not auto translated like the $title is
1.309     albertel 4072: 
                   4073: =item * $notopbar, if true, keep the 'what is this' info but remove the
                   4074:                    navigational links
1.317     albertel 4075: 
1.338     albertel 4076: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
                   4077: 
                   4078: =item * $notitle, if true keep the nav controls, but remove the title bar
                   4079: 
1.361     albertel 4080: =item * $no_inline_link, if true and in remote mode, don't show the 
                   4081:          'Switch To Inline Menu' link
                   4082: 
1.460     albertel 4083: =item * $args, optional argument valid values are
                   4084:             no_auto_mt_title -> prevents &mt()ing the title arg
1.562     albertel 4085:             inherit_jsmath -> when creating popup window in a page,
                   4086:                               should it have jsmath forced on by the
                   4087:                               current page
1.460     albertel 4088: 
1.112     bowersj2 4089: =back
                   4090: 
1.60      matthew  4091: Returns: A uniform header for LON-CAPA web pages.  
                   4092: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
                   4093: If $bodyonly is undef or zero, an html string containing a <body> tag and 
                   4094: other decorations will be returned.
                   4095: 
                   4096: =cut
                   4097: 
1.54      www      4098: sub bodytag {
1.309     albertel 4099:     my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle,
1.460     albertel 4100: 	$notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_;
1.339     albertel 4101: 
1.460     albertel 4102:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339     albertel 4103: 
1.183     matthew  4104:     $function = &get_users_function() if (!$function);
1.339     albertel 4105:     my $img =    &designparm($function.'.img',$domain);
                   4106:     my $font =   &designparm($function.'.font',$domain);
                   4107:     my $pgbg   = $bgcolor || &designparm($function.'.pgbg',$domain);
                   4108: 
                   4109:     my %design = ( 'style'   => 'margin-top: 0px',
1.535     albertel 4110: 		   'bgcolor' => $pgbg,
1.339     albertel 4111: 		   'text'    => $font,
                   4112:                    'alink'   => &designparm($function.'.alink',$domain),
                   4113: 		   'vlink'   => &designparm($function.'.vlink',$domain),
                   4114: 		   'link'    => &designparm($function.'.link',$domain),);
1.438     albertel 4115:     @design{keys(%$addentries)} = @$addentries{keys(%$addentries)}; 
1.339     albertel 4116: 
1.63      www      4117:  # role and realm
1.378     raeburn  4118:     my ($role,$realm) = split(/\./,$env{'request.role'},2);
                   4119:     if ($role  eq 'ca') {
1.479     albertel 4120:         my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500     albertel 4121:         $realm = &plainname($rname,$rdom);
1.378     raeburn  4122:     } 
1.55      www      4123: # realm
1.258     albertel 4124:     if ($env{'request.course.id'}) {
1.378     raeburn  4125:         if ($env{'request.role'} !~ /^cr/) {
                   4126:             $role = &Apache::lonnet::plaintext($role,&course_type());
                   4127:         }
1.359     albertel 4128: 	$realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378     raeburn  4129:     } else {
                   4130:         $role = &Apache::lonnet::plaintext($role);
1.54      www      4131:     }
1.433     albertel 4132: 
1.359     albertel 4133:     if (!$realm) { $realm='&nbsp;'; }
1.55      www      4134: # Set messages
1.60      matthew  4135:     my $messages=&domainlogo($domain);
1.330     albertel 4136: 
1.438     albertel 4137:     my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329     albertel 4138: 
1.101     www      4139: # construct main body tag
1.359     albertel 4140:     my $bodytag = "<body $extra_body_attr>".
1.562     albertel 4141: 	&Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252     albertel 4142: 
1.530     albertel 4143:     if ($bodyonly) {
1.60      matthew  4144:         return $bodytag;
1.258     albertel 4145:     } elsif ($env{'browser.interface'} eq 'textual') {
1.95      www      4146: # Accessibility
1.224     raeburn  4147:           
1.337     albertel 4148: 	$bodytag.=&Apache::lonmenu::menubuttons($forcereg,$forcereg);
1.338     albertel 4149: 	if (!$notitle) {
1.337     albertel 4150: 	    $bodytag.='<h1>LON-CAPA: '.$title.'</h1>';
                   4151: 	}
                   4152: 	return $bodytag;
1.359     albertel 4153:     }
                   4154: 
1.410     albertel 4155:     my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433     albertel 4156:     if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
                   4157: 	undef($role);
1.434     albertel 4158:     } else {
                   4159: 	$name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433     albertel 4160:     }
1.359     albertel 4161:     
                   4162:     my $roleinfo=(<<ENDROLE);
                   4163: <td class="LC_title_bar_who">
                   4164: <div class="LC_title_bar_name">
1.410     albertel 4165:     $name
1.361     albertel 4166:     &nbsp;
1.359     albertel 4167: </div>
                   4168: <div class="LC_title_bar_role">
1.361     albertel 4169: $role&nbsp;
1.359     albertel 4170: </div>
                   4171: <div class="LC_title_bar_realm">
1.361     albertel 4172: $realm&nbsp;
1.359     albertel 4173: </div>
1.206     albertel 4174: </td>
                   4175: ENDROLE
1.235     raeburn  4176: 
1.359     albertel 4177:     my $titleinfo = '<span class="LC_title_bar_title">'.$title.'</span>';
                   4178:     if ($customtitle) {
                   4179:         $titleinfo = $customtitle;
                   4180:     }
                   4181:     #
                   4182:     # Extra info if you are the DC
                   4183:     my $dc_info = '';
                   4184:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
                   4185:                         $env{'course.'.$env{'request.course.id'}.
                   4186:                                  '.domain'}.'/'})) {
                   4187:         my $cid = $env{'request.course.id'};
                   4188:         $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380     www      4189:         $dc_info =~ s/\s+$//;
1.359     albertel 4190:         $dc_info = '('.$dc_info.')';
                   4191:     }
                   4192: 
1.644     www      4193:     if (($env{'environment.remote'} eq 'off') || ($args->{'suppress_header_logos'})) {
1.359     albertel 4194:         # No Remote
1.258     albertel 4195: 	if ($env{'request.state'} eq 'construct') {
1.359     albertel 4196: 	    $forcereg=1;
                   4197: 	}
                   4198: 
                   4199: 	if (!$customtitle && $env{'request.state'} eq 'construct') {
                   4200: 	    # this is for resources; directories have customtitle, and crumbs
                   4201:             # and select recent are created in lonpubdir.pm  
1.229     albertel 4202: 	    my ($uname,$thisdisfn)=
1.258     albertel 4203: 		($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
1.229     albertel 4204: 	    my $formaction='/priv/'.$uname.'/'.$thisdisfn;
                   4205: 	    $formaction=~s/\/+/\//g;
                   4206: 
1.359     albertel 4207: 	    my $parentpath = '';
                   4208: 	    my $lastitem = '';
                   4209: 	    if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
                   4210: 		$parentpath = $1;
                   4211: 		$lastitem = $2;
                   4212: 	    } else {
                   4213: 		$lastitem = $thisdisfn;
                   4214: 	    }
                   4215: 	    $titleinfo = 
1.640     bisitz   4216: 		&Apache::loncommon::help_open_menu('','',3,'Authoring')
                   4217: 		.'<b>'.&mt('Construction Space').'</b>:&nbsp;'
                   4218: 		.'<form name="dirs" method="post" action="'.$formaction
1.359     albertel 4219: 		.'" target="_top"><tt><b>'
1.705     tempelho 4220: 		.&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."<span class=\"LC_fontsize_big\">$lastitem</span></b></tt><br />"
1.359     albertel 4221: 		.&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
                   4222: 		.'</form>'
                   4223: 		.&Apache::lonmenu::constspaceform();
1.235     raeburn  4224:         }
1.359     albertel 4225: 
1.337     albertel 4226:         my $titletable;
1.338     albertel 4227: 	if (!$notitle) {
1.337     albertel 4228: 	    $titletable =
1.359     albertel 4229: 		'<table id="LC_title_bar">'.
                   4230:                          "<tr><td> $titleinfo $dc_info</td>".$roleinfo.
                   4231: 			 '</tr></table>';
1.337     albertel 4232: 	}
1.359     albertel 4233: 	if ($notopbar) {
                   4234: 	    $bodytag .= $titletable;
                   4235: 	} else {
                   4236: 	    if ($env{'request.state'} eq 'construct') {
1.337     albertel 4237:                 $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
                   4238: 							  $titletable);
1.272     raeburn  4239:             } else {
1.336     albertel 4240:                 $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
1.359     albertel 4241: 		    $titletable;
1.272     raeburn  4242:             }
1.235     raeburn  4243:         }
                   4244:         return $bodytag;
1.94      www      4245:     }
1.95      www      4246: 
1.93      www      4247: #
1.95      www      4248: # Top frame rendering, Remote is up
1.93      www      4249: #
1.359     albertel 4250: 
1.517     raeburn  4251:     my $imgsrc = $img;
                   4252:     if ($img =~ /^\/adm/) {
1.575     albertel 4253:         $imgsrc = &lonhttpdurl($img);
1.517     raeburn  4254:     }
                   4255:     my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359     albertel 4256: 
1.305     www      4257:     # Explicit link to get inline menu
1.361     albertel 4258:     my $menu= ($no_inline_link?''
                   4259: 	       :'<br /><a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
1.245     matthew  4260:     #
1.338     albertel 4261:     if ($notitle) {
1.337     albertel 4262: 	return $bodytag;
                   4263:     }
1.94      www      4264:     return(<<ENDBODY);
1.60      matthew  4265: $bodytag
1.359     albertel 4266: <table id="LC_title_bar" class="LC_with_remote">
1.368     albertel 4267: <tr><td class="LC_title_bar_role_logo">$upperleft</td>
1.359     albertel 4268:     <td class="LC_title_bar_domain_logo">$messages&nbsp;</td>
1.54      www      4269: </tr>
1.359     albertel 4270: <tr><td>$titleinfo $dc_info $menu</td>
                   4271: $roleinfo
1.368     albertel 4272: </tr>
1.356     albertel 4273: </table>
1.54      www      4274: ENDBODY
1.182     matthew  4275: }
                   4276: 
1.330     albertel 4277: sub make_attr_string {
                   4278:     my ($register,$attr_ref) = @_;
                   4279: 
                   4280:     if ($attr_ref && !ref($attr_ref)) {
                   4281: 	die("addentries Must be a hash ref ".
                   4282: 	    join(':',caller(1))." ".
                   4283: 	    join(':',caller(0))." ");
                   4284:     }
                   4285: 
                   4286:     if ($register) {
1.339     albertel 4287: 	my ($on_load,$on_unload);
                   4288: 	foreach my $key (keys(%{$attr_ref})) {
                   4289: 	    if      (lc($key) eq 'onload') {
                   4290: 		$on_load.=$attr_ref->{$key}.';';
                   4291: 		delete($attr_ref->{$key});
                   4292: 
                   4293: 	    } elsif (lc($key) eq 'onunload') {
                   4294: 		$on_unload.=$attr_ref->{$key}.';';
                   4295: 		delete($attr_ref->{$key});
                   4296: 	    }
                   4297: 	}
                   4298: 	$attr_ref->{'onload'}  =
                   4299: 	    &Apache::lonmenu::loadevents().  $on_load;
                   4300: 	$attr_ref->{'onunload'}=
                   4301: 	    &Apache::lonmenu::unloadevents().$on_unload;
                   4302:     }
                   4303: 
                   4304: # Accessibility font enhance
                   4305:     if ($env{'browser.fontenhance'} eq 'on') {
                   4306: 	my $style;
                   4307: 	foreach my $key (keys(%{$attr_ref})) {
                   4308: 	    if (lc($key) eq 'style') {
                   4309: 		$style.=$attr_ref->{$key}.';';
                   4310: 		delete($attr_ref->{$key});
                   4311: 	    }
                   4312: 	}
                   4313: 	$attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330     albertel 4314:     }
1.339     albertel 4315: 
                   4316:     if ($env{'browser.blackwhite'} eq 'on') {
                   4317: 	delete($attr_ref->{'font'});
                   4318: 	delete($attr_ref->{'link'});
                   4319: 	delete($attr_ref->{'alink'});
                   4320: 	delete($attr_ref->{'vlink'});
                   4321: 	delete($attr_ref->{'bgcolor'});
                   4322: 	delete($attr_ref->{'background'});
                   4323:     }
                   4324: 
1.330     albertel 4325:     my $attr_string;
                   4326:     foreach my $attr (keys(%$attr_ref)) {
                   4327: 	$attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
                   4328:     }
                   4329:     return $attr_string;
                   4330: }
                   4331: 
                   4332: 
1.182     matthew  4333: ###############################################
1.251     albertel 4334: ###############################################
                   4335: 
                   4336: =pod
                   4337: 
                   4338: =item * &endbodytag()
                   4339: 
                   4340: Returns a uniform footer for LON-CAPA web pages.
                   4341: 
1.635     raeburn  4342: Inputs: 1 - optional reference to an args hash
                   4343: If in the hash, key for noredirectlink has a value which evaluates to true,
                   4344: a 'Continue' link is not displayed if the page contains an
                   4345: internal redirect in the <head></head> section,
                   4346: i.e., $env{'internal.head.redirect'} exists   
1.251     albertel 4347: 
                   4348: =cut
                   4349: 
                   4350: sub endbodytag {
1.635     raeburn  4351:     my ($args) = @_;
1.251     albertel 4352:     my $endbodytag='</body>';
1.269     albertel 4353:     $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315     albertel 4354:     if ( exists( $env{'internal.head.redirect'} ) ) {
1.635     raeburn  4355:         if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
                   4356: 	    $endbodytag=
                   4357: 	        "<br /><a href=\"$env{'internal.head.redirect'}\">".
                   4358: 	        &mt('Continue').'</a>'.
                   4359: 	        $endbodytag;
                   4360:         }
1.315     albertel 4361:     }
1.251     albertel 4362:     return $endbodytag;
                   4363: }
                   4364: 
1.352     albertel 4365: =pod
                   4366: 
                   4367: =item * &standard_css()
                   4368: 
                   4369: Returns a style sheet
                   4370: 
                   4371: Inputs: (all optional)
                   4372:             domain         -> force to color decorate a page for a specific
                   4373:                                domain
                   4374:             function       -> force usage of a specific rolish color scheme
                   4375:             bgcolor        -> override the default page bgcolor
                   4376: 
                   4377: =cut
                   4378: 
1.343     albertel 4379: sub standard_css {
1.345     albertel 4380:     my ($function,$domain,$bgcolor) = @_;
1.352     albertel 4381:     $function  = &get_users_function() if (!$function);
                   4382:     my $img    = &designparm($function.'.img',   $domain);
                   4383:     my $tabbg  = &designparm($function.'.tabbg', $domain);
                   4384:     my $font   = &designparm($function.'.font',  $domain);
1.345     albertel 4385:     my $sidebg = &designparm($function.'.sidebg',$domain);
1.382     albertel 4386:     my $pgbg_or_bgcolor =
                   4387: 	         $bgcolor ||
1.352     albertel 4388: 	         &designparm($function.'.pgbg',  $domain);
1.382     albertel 4389:     my $pgbg   = &designparm($function.'.pgbg',  $domain);
1.352     albertel 4390:     my $alink  = &designparm($function.'.alink', $domain);
                   4391:     my $vlink  = &designparm($function.'.vlink', $domain);
                   4392:     my $link   = &designparm($function.'.link',  $domain);
                   4393: 
1.704     muellerd 4394:     my $loginbg = &designparm('login.sidebg',$domain);
1.712     muellerd 4395:     my $bgcol = &designparm('login.bgcol',$domain);
                   4396:     my $textcol = &designparm('login.textcol',$domain);
1.704     muellerd 4397: 
1.602     albertel 4398:     my $sans                 = 'Verdana,Arial,Helvetica,sans-serif';
1.395     albertel 4399:     my $mono                 = 'monospace';
1.352     albertel 4400:     my $data_table_head      = $tabbg;
                   4401:     my $data_table_light     = '#EEEEEE';
1.470     banghart 4402:     my $data_table_dark      = '#DDDDDD';
                   4403:     my $data_table_darker    = '#CCCCCC';
1.349     albertel 4404:     my $data_table_highlight = '#FFFF00';
1.352     albertel 4405:     my $mail_new             = '#FFBB77';
                   4406:     my $mail_new_hover       = '#DD9955';
                   4407:     my $mail_read            = '#BBBB77';
                   4408:     my $mail_read_hover      = '#999944';
                   4409:     my $mail_replied         = '#AAAA88';
                   4410:     my $mail_replied_hover   = '#888855';
                   4411:     my $mail_other           = '#99BBBB';
                   4412:     my $mail_other_hover     = '#669999';
1.391     albertel 4413:     my $table_header         = '#DDDDDD';
1.489     raeburn  4414:     my $feedback_link_bg     = '#BBBBBB';
1.701     harmsja  4415:     my $lg_border_color	     = '#C8C8C8';
1.392     albertel 4416: 
1.608     albertel 4417:     my $border = ($env{'browser.type'} eq 'explorer' ||
                   4418: 		  $env{'browser.type'} eq 'safari'     ) ? '0px 2px 0px 2px'
                   4419: 	                                                 : '0px 3px 0px 4px';
1.448     albertel 4420: 
1.523     albertel 4421: 
1.343     albertel 4422:     return <<END;
1.698     harmsja  4423: body{
                   4424:      font-family: $sans;
                   4425:      line-height:130%;
1.701     harmsja  4426:      font-size:0.83em;
1.698     harmsja  4427:      color:$font;
                   4428:   }
1.701     harmsja  4429: a:link, a:visited { font-size:100%; }
1.698     harmsja  4430: 
1.343     albertel 4431: a:focus { color: red; background: yellow } 
1.510     albertel 4432: table.thinborder,
                   4433: table.thinborder tr th {
                   4434:   border-style: solid;
                   4435:   border-width: 1px;
1.698     harmsja  4436:   border-color: $lg_border_color;
1.510     albertel 4437:   background: $tabbg;
                   4438: }
1.523     albertel 4439: table.thinborder tr td {
1.510     albertel 4440:   border-style: solid;
1.698     harmsja  4441:   border-width: 1px;
                   4442:   border-color: $lg_border_color;
1.510     albertel 4443: }
1.426     albertel 4444: 
1.343     albertel 4445: form, .inline { display: inline; }
                   4446: .center { text-align: center; }
1.701     harmsja  4447: .left { text-align:left; }
                   4448: .right {text-align:right;}
                   4449: .middle {vertical-align:middle;}
                   4450: .top {vertical-align:top;}
                   4451: .bottom {vertical-align:bottom;}
1.593     albertel 4452: .LC_filename {font-family: $mono; white-space:pre;}
1.350     albertel 4453: .LC_error {
                   4454:   color: red;
                   4455:   font-size: larger;
                   4456: }
1.457     albertel 4457: .LC_warning,
                   4458: .LC_diff_removed {
1.394     albertel 4459:   color: red;
                   4460: }
1.532     albertel 4461: 
                   4462: .LC_info,
1.457     albertel 4463: .LC_success,
                   4464: .LC_diff_added {
1.350     albertel 4465:   color: green;
                   4466: }
1.543     albertel 4467: .LC_unknown {
                   4468:   color: yellow;
                   4469: }
                   4470: 
1.440     albertel 4471: .LC_icon {
                   4472:   border: 0px;
                   4473: }
1.539     albertel 4474: .LC_indexer_icon {
                   4475:   border: 0px;
                   4476:   height: 22px;
                   4477: }
1.543     albertel 4478: .LC_docs_spacer {
                   4479:   width: 25px;
                   4480:   height: 1px;
                   4481:   border: 0px;
                   4482: }
1.346     albertel 4483: 
1.532     albertel 4484: .LC_internal_info {
                   4485:   color: #999;
                   4486: }
                   4487: 
1.458     albertel 4488: table.LC_pastsubmission {
                   4489:   border: 1px solid black;
                   4490:   margin: 2px;
                   4491: }
                   4492: 
1.606     albertel 4493: table#LC_top_nav, table#LC_menubuttons,table#LC_nav_location {
1.345     albertel 4494:   width: 100%;
                   4495:   background: $pgbg;
1.392     albertel 4496:   border: 2px;
1.402     albertel 4497:   border-collapse: separate;
1.403     albertel 4498:   padding: 0px;
1.345     albertel 4499: }
1.392     albertel 4500: 
1.606     albertel 4501: table#LC_title_bar, table.LC_breadcrumbs, 
1.393     albertel 4502: table#LC_title_bar.LC_with_remote {
1.359     albertel 4503:   width: 100%;
1.392     albertel 4504:   border-color: $pgbg;
                   4505:   border-style: solid;
                   4506:   border-width: $border;
                   4507: 
1.379     albertel 4508:   background: $pgbg;
                   4509:   font-family: $sans;
1.392     albertel 4510:   border-collapse: collapse;
1.403     albertel 4511:   padding: 0px;
1.359     albertel 4512: }
1.409     albertel 4513: table.LC_docs_path {
                   4514:   width: 100%;
                   4515:   border: 0;
                   4516:   background: $pgbg;
                   4517:   font-family: $sans;
                   4518:   border-collapse: collapse;
                   4519:   padding: 0px;
                   4520: }
                   4521: 
1.359     albertel 4522: table#LC_title_bar td {
                   4523:   background: $tabbg;
                   4524: }
                   4525: table#LC_title_bar td.LC_title_bar_who {
                   4526:   background: $tabbg;
                   4527:   color: $font;
1.427     albertel 4528:   font: small $sans;
1.359     albertel 4529:   text-align: right;
                   4530: }
1.469     banghart 4531: span.LC_metadata {
                   4532:     font-family: $sans;
                   4533: }
1.359     albertel 4534: span.LC_title_bar_title {
1.416     albertel 4535:   font: bold x-large $sans;
1.359     albertel 4536: }
                   4537: table#LC_title_bar td.LC_title_bar_domain_logo {
                   4538:   background: $sidebg;
                   4539:   text-align: right;
1.368     albertel 4540:   padding: 0px;
                   4541: }
                   4542: table#LC_title_bar td.LC_title_bar_role_logo {
                   4543:   background: $sidebg;
                   4544:   padding: 0px;
1.359     albertel 4545: }
                   4546: 
1.706     harmsja  4547: table#LC_menubuttons img{
1.346     albertel 4548:   border: 0px;
                   4549: }
1.345     albertel 4550: table#LC_top_nav td {
                   4551:   background: $tabbg;
1.392     albertel 4552:   border: 0px;
1.407     albertel 4553:   font-size: small;
1.706     harmsja  4554:   vertical-align:top;
                   4555:   padding:2px 5px 2px 5px;
1.345     albertel 4556: }
                   4557: table#LC_top_nav td a, div#LC_top_nav a {
                   4558:   color: $font;
                   4559:   font-family: $sans;
                   4560: }
1.364     albertel 4561: table#LC_top_nav td.LC_top_nav_logo {
                   4562:   background: $tabbg;
1.432     albertel 4563:   text-align: left;
1.408     albertel 4564:   white-space: nowrap;
1.432     albertel 4565:   width: 31px;
1.408     albertel 4566: }
                   4567: table#LC_top_nav td.LC_top_nav_logo img {
1.432     albertel 4568:   border: 0px;
1.408     albertel 4569:   vertical-align: bottom;
1.364     albertel 4570: }
1.432     albertel 4571: table#LC_top_nav td.LC_top_nav_exit,
                   4572: table#LC_top_nav td.LC_top_nav_help {
                   4573:   width: 2.0em;
                   4574: }
1.442     albertel 4575: table#LC_top_nav td.LC_top_nav_login {
                   4576:   width: 4.0em;
                   4577:   text-align: center;
                   4578: }
1.409     albertel 4579: table.LC_breadcrumbs td, table.LC_docs_path td  {
1.357     albertel 4580:   background: $tabbg;
                   4581:   color: $font;
                   4582:   font-family: $sans;
1.358     albertel 4583:   font-size: smaller;
1.357     albertel 4584: }
1.411     albertel 4585: table.LC_breadcrumbs td.LC_breadcrumbs_component,
1.409     albertel 4586: table.LC_docs_path td.LC_docs_path_component {
1.357     albertel 4587:   background: $tabbg;
                   4588:   color: $font;
                   4589:   font-family: $sans;
                   4590:   font-size: larger;
                   4591:   text-align: right;
                   4592: }
1.383     albertel 4593: td.LC_table_cell_checkbox {
                   4594:   text-align: center;
                   4595: }
1.522     albertel 4596: table#LC_mainmenu td.LC_mainmenu_column {
                   4597:     vertical-align: top;
                   4598: }
                   4599: 
1.705     tempelho 4600: .LC_fontsize_small
                   4601: {
                   4602:  font-size: 70%;
                   4603: }
                   4604: 
                   4605: .LC_fontsize_medium
                   4606: {
                   4607:  font-size: 85%;
                   4608: }
                   4609: 
                   4610: .LC_fontsize_large
                   4611: {
                   4612:  font-size: 120%;
                   4613: }
                   4614: 
                   4615: .LC_fontcolor_red
                   4616: {
                   4617:  color: #FF0000;
                   4618: }
                   4619: 
1.346     albertel 4620: .LC_menubuttons_inline_text {
                   4621:   color: $font;
                   4622:   font-family: $sans;
1.698     harmsja  4623:   font-size: 90%;
1.701     harmsja  4624:   padding-left:3px;
1.346     albertel 4625: }
                   4626: 
1.526     www      4627: .LC_menubuttons_link {
                   4628:   text-decoration: none;
                   4629: }
1.698     harmsja  4630: /*2008--9-5: new menu style sheet.Changed category*/
1.522     albertel 4631: .LC_menubuttons_category {
1.521     www      4632:   color: $font;
1.526     www      4633:   background: $pgbg;
1.521     www      4634:   font-family: $sans;
                   4635:   font-size: larger;
                   4636:   font-weight: bold;
                   4637: }
                   4638: 
1.346     albertel 4639: td.LC_menubuttons_text {
1.701     harmsja  4640:  	color: $font; 	
1.346     albertel 4641: }
1.706     harmsja  4642: 
                   4643: 
1.526     www      4644: 
1.346     albertel 4645: .LC_current_location {
                   4646:   font-family: $sans;
                   4647:   background: $tabbg;
                   4648: }
                   4649: .LC_new_mail {
                   4650:   font-family: $sans;
1.634     www      4651:   background: $tabbg;
1.346     albertel 4652:   font-weight: bold;
                   4653: }
1.347     albertel 4654: 
1.526     www      4655: 
1.527     www      4656: .LC_dropadd_labeltext {
                   4657:   font-family: $sans;
                   4658:   text-align: right;
                   4659: }
                   4660: 
                   4661: .LC_preferences_labeltext {
                   4662:   font-family: $sans;
                   4663:   text-align: right;
                   4664: }
                   4665: 
1.666     raeburn  4666: .LC_roleslog_note {
1.701     harmsja  4667:   font-size: small;
1.666     raeburn  4668: }
                   4669: 
1.715     raeburn  4670: .LC_mail_functions {
                   4671:     font-weight: bold;
                   4672: }
                   4673: 
1.440     albertel 4674: table.LC_aboutme_port {
                   4675:   border: 0px;
                   4676:   border-collapse: collapse;
                   4677:   border-spacing: 0px;
                   4678: }
1.349     albertel 4679: table.LC_data_table, table.LC_mail_list {
1.347     albertel 4680:   border: 1px solid #000000;
1.402     albertel 4681:   border-collapse: separate;
1.426     albertel 4682:   border-spacing: 1px;
1.610     albertel 4683:   background: $pgbg;
1.347     albertel 4684: }
1.422     albertel 4685: .LC_data_table_dense {
                   4686:   font-size: small;
                   4687: }
1.507     raeburn  4688: table.LC_nested_outer {
                   4689:   border: 1px solid #000000;
1.589     raeburn  4690:   border-collapse: collapse;
1.507     raeburn  4691:   border-spacing: 0px;
                   4692:   width: 100%;
                   4693: }
                   4694: table.LC_nested {
                   4695:   border: 0px;
1.589     raeburn  4696:   border-collapse: collapse;
1.507     raeburn  4697:   border-spacing: 0px;
                   4698:   width: 100%;
                   4699: }
1.523     albertel 4700: table.LC_data_table tr th, table.LC_calendar tr th, table.LC_mail_list tr th,
                   4701: table.LC_prior_tries tr th {
1.349     albertel 4702:   font-weight: bold;
                   4703:   background-color: $data_table_head;
1.701     harmsja  4704:   font-size:90%;
1.347     albertel 4705: }
1.711     raeburn  4706: table.LC_data_table tr.LC_info_row > td {
                   4707:   background-color: #CCC;
                   4708:   font-weight: bold;
                   4709:   text-align: left;
                   4710: }
1.610     albertel 4711: table.LC_data_table tr.LC_odd_row > td, 
1.709     bisitz   4712: table.LC_pick_box tr > td.LC_odd_row,
1.440     albertel 4713: table.LC_aboutme_port tr td {
1.349     albertel 4714:   background-color: $data_table_light;
1.425     albertel 4715:   padding: 2px;
1.347     albertel 4716: }
1.610     albertel 4717: table.LC_data_table tr.LC_even_row > td,
1.709     bisitz   4718: table.LC_pick_box tr > td.LC_even_row,
1.440     albertel 4719: table.LC_aboutme_port tr.LC_even_row td {
1.349     albertel 4720:   background-color: $data_table_dark;
1.709     bisitz   4721:   padding: 2px;
1.347     albertel 4722: }
1.425     albertel 4723: table.LC_data_table tr.LC_data_table_highlight td {
                   4724:   background-color: $data_table_darker;
                   4725: }
1.639     raeburn  4726: table.LC_data_table tr td.LC_leftcol_header {
                   4727:   background-color: $data_table_head;
                   4728:   font-weight: bold;
                   4729: }
1.451     albertel 4730: table.LC_data_table tr.LC_empty_row td,
1.507     raeburn  4731: table.LC_nested tr.LC_empty_row td {
1.347     albertel 4732:   background-color: #FFFFFF;
1.421     albertel 4733:   font-weight: bold;
                   4734:   font-style: italic;
                   4735:   text-align: center;
                   4736:   padding: 8px;
1.347     albertel 4737: }
1.507     raeburn  4738: table.LC_nested tr.LC_empty_row td {
1.465     albertel 4739:   padding: 4ex
                   4740: }
1.507     raeburn  4741: table.LC_nested_outer tr th {
                   4742:   font-weight: bold;
                   4743:   background-color: $data_table_head;
1.701     harmsja  4744:   font-size: small;
1.507     raeburn  4745:   border-bottom: 1px solid #000000;
                   4746: }
                   4747: table.LC_nested_outer tr td.LC_subheader {
                   4748:   background-color: $data_table_head;
                   4749:   font-weight: bold;
                   4750:   font-size: small;
                   4751:   border-bottom: 1px solid #000000;
                   4752:   text-align: right;
1.451     albertel 4753: }
1.507     raeburn  4754: table.LC_nested tr.LC_info_row td {
1.451     albertel 4755:   background-color: #CCC;
                   4756:   font-weight: bold;
                   4757:   font-size: small;
1.507     raeburn  4758:   text-align: center;
                   4759: }
1.589     raeburn  4760: table.LC_nested tr.LC_info_row td.LC_left_item,
                   4761: table.LC_nested_outer tr th.LC_left_item {
1.507     raeburn  4762:   text-align: left;
1.451     albertel 4763: }
1.507     raeburn  4764: table.LC_nested td {
1.451     albertel 4765:   background-color: #FFF;
                   4766:   font-size: small;
1.507     raeburn  4767: }
                   4768: table.LC_nested_outer tr th.LC_right_item,
                   4769: table.LC_nested tr.LC_info_row td.LC_right_item,
                   4770: table.LC_nested tr.LC_odd_row td.LC_right_item,
                   4771: table.LC_nested tr td.LC_right_item {
1.451     albertel 4772:   text-align: right;
                   4773: }
                   4774: 
1.507     raeburn  4775: table.LC_nested tr.LC_odd_row td {
1.451     albertel 4776:   background-color: #EEE;
                   4777: }
                   4778: 
1.473     raeburn  4779: table.LC_createuser {
                   4780: }
                   4781: 
                   4782: table.LC_createuser tr.LC_section_row td {
1.701     harmsja  4783:   font-size: small;
1.473     raeburn  4784: }
                   4785: 
                   4786: table.LC_createuser tr.LC_info_row td  {
                   4787:   background-color: #CCC;
                   4788:   font-weight: bold;
                   4789:   text-align: center;
                   4790: }
                   4791: 
1.349     albertel 4792: table.LC_calendar {
                   4793:   border: 1px solid #000000;
                   4794:   border-collapse: collapse;
                   4795: }
                   4796: table.LC_calendar_pickdate {
                   4797:   font-size: xx-small;
                   4798: }
                   4799: table.LC_calendar tr td {
                   4800:   border: 1px solid #000000;
                   4801:   vertical-align: top;
                   4802: }
                   4803: table.LC_calendar tr td.LC_calendar_day_empty {
                   4804:   background-color: $data_table_dark;
                   4805: }
                   4806: table.LC_calendar tr td.LC_calendar_day_current {
                   4807:   background-color: $data_table_highlight;
                   4808: }
                   4809: 
                   4810: table.LC_mail_list tr.LC_mail_new {
                   4811:   background-color: $mail_new;
                   4812: }
                   4813: table.LC_mail_list tr.LC_mail_new:hover {
                   4814:   background-color: $mail_new_hover;
                   4815: }
                   4816: table.LC_mail_list tr.LC_mail_read {
                   4817:   background-color: $mail_read;
                   4818: }
                   4819: table.LC_mail_list tr.LC_mail_read:hover {
                   4820:   background-color: $mail_read_hover;
                   4821: }
                   4822: table.LC_mail_list tr.LC_mail_replied {
                   4823:   background-color: $mail_replied;
                   4824: }
                   4825: table.LC_mail_list tr.LC_mail_replied:hover {
                   4826:   background-color: $mail_replied_hover;
                   4827: }
                   4828: table.LC_mail_list tr.LC_mail_other {
                   4829:   background-color: $mail_other;
                   4830: }
                   4831: table.LC_mail_list tr.LC_mail_other:hover {
                   4832:   background-color: $mail_other_hover;
                   4833: }
1.494     raeburn  4834: table.LC_mail_list tr.LC_mail_even {
                   4835: }
                   4836: table.LC_mail_list tr.LC_mail_odd {
                   4837: }
                   4838: 
1.696     bisitz   4839: table.LC_data_table tr > td.LC_browser_file,
                   4840: table.LC_data_table tr > td.LC_browser_file_published {
1.389     albertel 4841:   background: #CCFF88;
                   4842: }
1.696     bisitz   4843: table.LC_data_table tr > td.LC_browser_file_locked,
                   4844: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389     albertel 4845:   background: #FFAA99;
1.387     albertel 4846: }
1.696     bisitz   4847: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.389     albertel 4848:   background: #AAAAAA;
1.387     albertel 4849: }
1.696     bisitz   4850: table.LC_data_table tr > td.LC_browser_file_modified,
                   4851: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.389     albertel 4852:   background: #FFFF77;
1.387     albertel 4853: }
1.696     bisitz   4854: table.LC_data_table tr.LC_browser_folder > td {
1.389     albertel 4855:   background: #CCCCFF;
1.387     albertel 4856: }
1.696     bisitz   4857: 
1.707     bisitz   4858: table.LC_data_table tr > td.LC_roles_is {
                   4859: /*  background: #77FF77; */
                   4860: }
                   4861: table.LC_data_table tr > td.LC_roles_future {
                   4862:   background: #FFFF77;
                   4863: }
                   4864: table.LC_data_table tr > td.LC_roles_will {
                   4865:   background: #FFAA77;
                   4866: }
                   4867: table.LC_data_table tr > td.LC_roles_expired {
                   4868:   background: #FF7777;
                   4869: }
                   4870: table.LC_data_table tr > td.LC_roles_will_not {
                   4871:   background: #AAFF77;
                   4872: }
                   4873: table.LC_data_table tr > td.LC_roles_selected {
                   4874:   background: #11CC55;
                   4875: }
                   4876: 
1.388     albertel 4877: span.LC_current_location {
1.701     harmsja  4878:   font-size:larger;
1.388     albertel 4879:   background: $pgbg;
                   4880: }
1.387     albertel 4881: 
1.395     albertel 4882: span.LC_parm_menu_item {
                   4883:   font-size: larger;
                   4884:   font-family: $sans;
                   4885: }
                   4886: span.LC_parm_scope_all {
                   4887:   color: red;
                   4888: }
                   4889: span.LC_parm_scope_folder {
                   4890:   color: green;
                   4891: }
                   4892: span.LC_parm_scope_resource {
                   4893:   color: orange;
                   4894: }
                   4895: span.LC_parm_part {
                   4896:   color: blue;
                   4897: }
                   4898: span.LC_parm_folder, span.LC_parm_symb {
                   4899:   font-size: x-small;
                   4900:   font-family: $mono;
                   4901:   color: #AAAAAA;
                   4902: }
                   4903: 
1.396     albertel 4904: td.LC_parm_overview_level_menu, td.LC_parm_overview_map_menu,
                   4905: td.LC_parm_overview_parm_selectors, td.LC_parm_overview_parm_restrictions {
                   4906:   border: 1px solid black;
                   4907:   border-collapse: collapse;
                   4908: }
                   4909: table.LC_parm_overview_restrictions td {
                   4910:   border-width: 1px 4px 1px 4px;
                   4911:   border-style: solid;
                   4912:   border-color: $pgbg;
                   4913:   text-align: center;
                   4914: }
                   4915: table.LC_parm_overview_restrictions th {
                   4916:   background: $tabbg;
                   4917:   border-width: 1px 4px 1px 4px;
                   4918:   border-style: solid;
                   4919:   border-color: $pgbg;
                   4920: }
1.398     albertel 4921: table#LC_helpmenu {
                   4922:   border: 0px;
                   4923:   height: 55px;
                   4924:   border-spacing: 0px;
                   4925: }
                   4926: 
                   4927: table#LC_helpmenu fieldset legend {
                   4928:   font-size: larger;
                   4929:   font-weight: bold;
                   4930: }
1.397     albertel 4931: table#LC_helpmenu_links {
                   4932:   width: 100%;
                   4933:   border: 1px solid black;
                   4934:   background: $pgbg;
                   4935:   padding: 0px;
                   4936:   border-spacing: 1px;
                   4937: }
                   4938: table#LC_helpmenu_links tr td {
                   4939:   padding: 1px;
                   4940:   background: $tabbg;
1.399     albertel 4941:   text-align: center;
                   4942:   font-weight: bold;
1.397     albertel 4943: }
1.396     albertel 4944: 
1.397     albertel 4945: table#LC_helpmenu_links a:link, table#LC_helpmenu_links a:visited,
                   4946: table#LC_helpmenu_links a:active {
                   4947:   text-decoration: none;
                   4948:   color: $font;
                   4949: }
                   4950: table#LC_helpmenu_links a:hover {
                   4951:   text-decoration: underline;
                   4952:   color: $vlink;
                   4953: }
1.396     albertel 4954: 
1.417     albertel 4955: .LC_chrt_popup_exists {
                   4956:   border: 1px solid #339933;
                   4957:   margin: -1px;
                   4958: }
                   4959: .LC_chrt_popup_up {
                   4960:   border: 1px solid yellow;
                   4961:   margin: -1px;
                   4962: }
                   4963: .LC_chrt_popup {
                   4964:   border: 1px solid #8888FF;
                   4965:   background: #CCCCFF;
                   4966: }
1.421     albertel 4967: table.LC_pick_box {
                   4968:   border-collapse: separate;
                   4969:   background: white;
                   4970:   border: 1px solid black;
                   4971:   border-spacing: 1px;
                   4972: }
                   4973: table.LC_pick_box td.LC_pick_box_title {
                   4974:   background: $tabbg;
                   4975:   font-weight: bold;
                   4976:   text-align: right;
                   4977:   width: 184px;
                   4978:   padding: 8px;
                   4979: }
1.645     raeburn  4980: table.LC_pick_box td.LC_selfenroll_pick_box_title {
                   4981:   background: $tabbg;
                   4982:   font-weight: bold;
                   4983:   text-align: right;
                   4984:   width: 350px;
                   4985:   padding: 8px;
                   4986: }
                   4987: 
1.579     raeburn  4988: table.LC_pick_box td.LC_pick_box_value {
                   4989:   text-align: left;
                   4990:   padding: 8px;
                   4991: }
                   4992: table.LC_pick_box td.LC_pick_box_select {
                   4993:   text-align: left;
                   4994:   padding: 8px;
                   4995: }
1.424     albertel 4996: table.LC_pick_box td.LC_pick_box_separator {
1.421     albertel 4997:   padding: 0px;
                   4998:   height: 1px;
                   4999:   background: black;
                   5000: }
                   5001: table.LC_pick_box td.LC_pick_box_submit {
                   5002:   text-align: right;
                   5003: }
1.579     raeburn  5004: table.LC_pick_box td.LC_evenrow_value {
                   5005:   text-align: left;
                   5006:   padding: 8px;
                   5007:   background-color: $data_table_light;
                   5008: }
                   5009: table.LC_pick_box td.LC_oddrow_value {
                   5010:   text-align: left;
                   5011:   padding: 8px;
                   5012:   background-color: $data_table_light;
                   5013: }
                   5014: table.LC_helpform_receipt {
                   5015:   width: 620px;
                   5016:   border-collapse: separate;
                   5017:   background: white;
                   5018:   border: 1px solid black;
                   5019:   border-spacing: 1px;
                   5020: }
                   5021: table.LC_helpform_receipt td.LC_pick_box_title {
                   5022:   background: $tabbg;
                   5023:   font-weight: bold;
                   5024:   text-align: right;
                   5025:   width: 184px;
                   5026:   padding: 8px;
                   5027: }
                   5028: table.LC_helpform_receipt td.LC_evenrow_value {
                   5029:   text-align: left;
                   5030:   padding: 8px;
                   5031:   background-color: $data_table_light;
                   5032: }
                   5033: table.LC_helpform_receipt td.LC_oddrow_value {
                   5034:   text-align: left;
                   5035:   padding: 8px;
                   5036:   background-color: $data_table_light;
                   5037: }
                   5038: table.LC_helpform_receipt td.LC_pick_box_separator {
                   5039:   padding: 0px;
                   5040:   height: 1px;
                   5041:   background: black;
                   5042: }
                   5043: span.LC_helpform_receipt_cat {
                   5044:   font-weight: bold;
                   5045: }
1.424     albertel 5046: table.LC_group_priv_box {
                   5047:   background: white;
                   5048:   border: 1px solid black;
                   5049:   border-spacing: 1px;
                   5050: }
                   5051: table.LC_group_priv_box td.LC_pick_box_title {
                   5052:   background: $tabbg;
                   5053:   font-weight: bold;
                   5054:   text-align: right;
                   5055:   width: 184px;
                   5056: }
                   5057: table.LC_group_priv_box td.LC_groups_fixed {
                   5058:   background: $data_table_light;
                   5059:   text-align: center;
                   5060: }
                   5061: table.LC_group_priv_box td.LC_groups_optional {
                   5062:   background: $data_table_dark;
                   5063:   text-align: center;
                   5064: }
                   5065: table.LC_group_priv_box td.LC_groups_functionality {
                   5066:   background: $data_table_darker;
                   5067:   text-align: center;
                   5068:   font-weight: bold;
                   5069: }
                   5070: table.LC_group_priv td {
                   5071:   text-align: left;
                   5072:   padding: 0px;
                   5073: }
                   5074: 
1.421     albertel 5075: table.LC_notify_front_page {
                   5076:   background: white;
                   5077:   border: 1px solid black;
                   5078:   padding: 8px;
                   5079: }
                   5080: table.LC_notify_front_page td {
                   5081:   padding: 8px;
                   5082: }
1.424     albertel 5083: .LC_navbuttons {
                   5084:   margin: 2ex 0ex 2ex 0ex;
                   5085: }
1.423     albertel 5086: .LC_topic_bar {
                   5087:   font-family: $sans;
                   5088:   font-weight: bold;
                   5089:   width: 100%;
                   5090:   background: $tabbg;
                   5091:   vertical-align: middle;
                   5092:   margin: 2ex 0ex 2ex 0ex;
                   5093: }
                   5094: .LC_topic_bar span {
                   5095:   vertical-align: middle;
                   5096: }
                   5097: .LC_topic_bar img {
                   5098:   vertical-align: bottom;
                   5099: }
                   5100: table.LC_course_group_status {
                   5101:   margin: 20px;
                   5102: }
                   5103: table.LC_status_selector td {
                   5104:   vertical-align: top;
                   5105:   text-align: center;
1.424     albertel 5106:   padding: 4px;
                   5107: }
                   5108: table.LC_descriptive_input td.LC_description {
                   5109:   vertical-align: top;
                   5110:   text-align: right;
                   5111:   font-weight: bold;
1.423     albertel 5112: }
1.599     albertel 5113: div.LC_feedback_link {
1.616     albertel 5114:   clear: both;
1.599     albertel 5115:   background: white;
                   5116:   width: 100%;  
1.489     raeburn  5117: }
                   5118: span.LC_feedback_link {
1.599     albertel 5119:   background: $feedback_link_bg;
                   5120:   font-size: larger;
                   5121: }
                   5122: span.LC_message_link {
                   5123:   background: $feedback_link_bg;
                   5124:   font-size: larger;
                   5125:   position: absolute;
                   5126:   right: 1em;
1.489     raeburn  5127: }
1.421     albertel 5128: 
1.515     albertel 5129: table.LC_prior_tries {
1.524     albertel 5130:   border: 1px solid #000000;
                   5131:   border-collapse: separate;
                   5132:   border-spacing: 1px;
1.515     albertel 5133: }
1.523     albertel 5134: 
1.515     albertel 5135: table.LC_prior_tries td {
1.524     albertel 5136:   padding: 2px;
1.515     albertel 5137: }
1.523     albertel 5138: 
                   5139: .LC_answer_correct {
                   5140:   background: #AAFFAA;
                   5141:   color: black;
                   5142: }
                   5143: .LC_answer_charged_try {
                   5144:   background: #FFAAAA ! important;
                   5145:   color: black;
                   5146: }
                   5147: .LC_answer_not_charged_try, 
                   5148: .LC_answer_no_grade,
                   5149: .LC_answer_late {
                   5150:   background: #FFFFAA;
                   5151:   color: black;
                   5152: }
                   5153: .LC_answer_previous {
                   5154:   background: #AAAAFF;
                   5155:   color: black;
                   5156: }
                   5157: .LC_answer_no_message {
                   5158:   background: #FFFFFF;
                   5159:   color: black;
                   5160: }
                   5161: .LC_answer_unknown {
                   5162:   background: orange;
                   5163:   color: black;
                   5164: }
                   5165: 
                   5166: 
1.529     albertel 5167: span.LC_prior_numerical,
                   5168: span.LC_prior_string,
                   5169: span.LC_prior_custom,
                   5170: span.LC_prior_reaction,
                   5171: span.LC_prior_math {
1.523     albertel 5172:   font-family: monospace;
                   5173:   white-space: pre;
                   5174: }
                   5175: 
1.525     albertel 5176: span.LC_prior_string {
                   5177:   font-family: monospace;
                   5178:   white-space: pre;
                   5179: }
                   5180: 
1.523     albertel 5181: table.LC_prior_option {
                   5182:   width: 100%;
                   5183:   border-collapse: collapse;
                   5184: }
1.528     albertel 5185: table.LC_prior_rank, table.LC_prior_match {
                   5186:   border-collapse: collapse;
                   5187: }
                   5188: table.LC_prior_option tr td,
                   5189: table.LC_prior_rank tr td,
                   5190: table.LC_prior_match tr td {
1.524     albertel 5191:   border: 1px solid #000000;
1.515     albertel 5192: }
                   5193: 
1.519     raeburn  5194: span.LC_nobreak {
1.544     albertel 5195:   white-space: nowrap;
1.519     raeburn  5196: }
                   5197: 
1.576     raeburn  5198: span.LC_cusr_emph {
                   5199:   font-style: italic;
                   5200: }
                   5201: 
1.633     raeburn  5202: span.LC_cusr_subheading {
                   5203:   font-weight: normal;
                   5204:   font-size: 85%;
                   5205: }
                   5206: 
1.545     albertel 5207: table.LC_docs_documents {
                   5208:   background: #BBBBBB;
1.547     albertel 5209:   border-width: 0px;
1.545     albertel 5210:   border-collapse: collapse;
                   5211: }
                   5212: 
                   5213: table.LC_docs_documents td.LC_docs_document {
                   5214:   border: 2px solid black;
                   5215:   padding: 4px;
                   5216: }
                   5217: 
                   5218: .LC_docs_course_commands div {
                   5219:   float: left;
                   5220:   border: 4px solid #AAAAAA;
                   5221:   padding: 4px;
                   5222:   background: #DDDDCC;
                   5223: }
                   5224: 
                   5225: .LC_docs_entry_move {
                   5226:   border: 0px;
                   5227:   border-collapse: collapse;
1.544     albertel 5228: }
                   5229: 
1.545     albertel 5230: .LC_docs_entry_move td {
                   5231:   border: 2px solid #BBBBBB;
                   5232:   background: #DDDDDD;
                   5233: }
                   5234: 
                   5235: .LC_docs_editor td.LC_docs_entry_commands {
                   5236:   background: #DDDDDD;
                   5237:   font-size: x-small;
                   5238: }
1.544     albertel 5239: .LC_docs_copy {
1.545     albertel 5240:   color: #000099;
1.544     albertel 5241: }
                   5242: .LC_docs_cut {
1.545     albertel 5243:   color: #550044;
1.544     albertel 5244: }
                   5245: .LC_docs_rename {
1.545     albertel 5246:   color: #009900;
1.544     albertel 5247: }
                   5248: .LC_docs_remove {
1.545     albertel 5249:   color: #990000;
                   5250: }
                   5251: 
1.547     albertel 5252: .LC_docs_reinit_warn,
                   5253: .LC_docs_ext_edit {
                   5254:   font-size: x-small;
                   5255: }
                   5256: 
1.545     albertel 5257: .LC_docs_editor td.LC_docs_entry_title,
                   5258: .LC_docs_editor td.LC_docs_entry_icon {
                   5259:   background: #FFFFBB;
                   5260: }
                   5261: .LC_docs_editor td.LC_docs_entry_parameter {
                   5262:   background: #BBBBFF;
                   5263:   font-size: x-small;
                   5264:   white-space: nowrap;
                   5265: }
                   5266: 
                   5267: table.LC_docs_adddocs td,
                   5268: table.LC_docs_adddocs th {
                   5269:   border: 1px solid #BBBBBB;
                   5270:   padding: 4px;
                   5271:   background: #DDDDDD;
1.543     albertel 5272: }
                   5273: 
1.584     albertel 5274: table.LC_sty_begin {
                   5275:   background: #BBFFBB;
                   5276: }
                   5277: table.LC_sty_end {
                   5278:   background: #FFBBBB;
                   5279: }
                   5280: 
1.589     raeburn  5281: table.LC_double_column {
                   5282:   border-width: 0px;
                   5283:   border-collapse: collapse;
                   5284:   width: 100%;
                   5285:   padding: 2px;
                   5286: }
                   5287: 
                   5288: table.LC_double_column tr td.LC_left_col {
1.590     raeburn  5289:   top: 2px;
1.589     raeburn  5290:   left: 2px;
                   5291:   width: 47%;
                   5292:   vertical-align: top;
                   5293: }
                   5294: 
                   5295: table.LC_double_column tr td.LC_right_col {
                   5296:   top: 2px;
                   5297:   right: 2px; 
                   5298:   width: 47%;
                   5299:   vertical-align: top;
                   5300: }
                   5301: 
1.594     raeburn  5302: span.LC_role_level {
                   5303:   font-weight: bold;
                   5304: }
                   5305: 
1.591     raeburn  5306: div.LC_left_float {
                   5307:   float: left;
                   5308:   padding-right: 5%;
1.597     albertel 5309:   padding-bottom: 4px;
1.591     raeburn  5310: }
                   5311: 
                   5312: div.LC_clear_float_header {
1.597     albertel 5313:   padding-bottom: 2px;
1.591     raeburn  5314: }
                   5315: 
                   5316: div.LC_clear_float_footer {
1.597     albertel 5317:   padding-top: 10px;
1.591     raeburn  5318:   clear: both;
                   5319: }
                   5320: 
1.597     albertel 5321: 
                   5322: div.LC_grade_show_user {
                   5323:   margin-top: 20px;
                   5324:   border: 1px solid black;
                   5325: }
                   5326: div.LC_grade_user_name {
                   5327:   background: #DDDDEE;
                   5328:   border-bottom: 1px solid black;
1.705     tempelho 5329:   font-weight: bold;
                   5330:   font-size: large;
1.597     albertel 5331: }
                   5332: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
                   5333:   background: #DDEEDD;
                   5334: }
                   5335: 
                   5336: div.LC_grade_show_problem,
                   5337: div.LC_grade_submissions,
                   5338: div.LC_grade_message_center,
                   5339: div.LC_grade_info_links,
                   5340: div.LC_grade_assign {
                   5341:   margin: 5px;
                   5342:   width: 99%;
                   5343:   background: #FFFFFF;
                   5344: }
                   5345: div.LC_grade_show_problem_header,
                   5346: div.LC_grade_submissions_header,
                   5347: div.LC_grade_message_center_header,
                   5348: div.LC_grade_assign_header {
1.705     tempelho 5349:   font-weight: bold;
                   5350:   font-size: large;
1.597     albertel 5351: }
                   5352: div.LC_grade_show_problem_problem,
                   5353: div.LC_grade_submissions_body,
                   5354: div.LC_grade_message_center_body,
                   5355: div.LC_grade_assign_body {
                   5356:   border: 1px solid black;
                   5357:   width: 99%;
                   5358:   background: #FFFFFF;
                   5359: }
1.598     albertel 5360: span.LC_grade_check_note {
1.705     tempelho 5361:   font-weight: normal;
                   5362:   font-size: medium;
1.598     albertel 5363:   display: inline;
                   5364:   position: absolute;
                   5365:   right: 1em;
                   5366: }
1.597     albertel 5367: 
1.613     albertel 5368: table.LC_scantron_action {
                   5369:   width: 100%;
                   5370: }
                   5371: table.LC_scantron_action tr th {
1.698     harmsja  5372:   font-weight:bold;
                   5373:   font-style:normal;
1.613     albertel 5374: }
1.698     harmsja  5375: .LC_edit_problem_header, 
1.614     albertel 5376: div.LC_edit_problem_footer {
1.705     tempelho 5377:   font-weight: normal;
                   5378:   font-size:  medium;
1.602     albertel 5379:   margin: 2px;
1.600     albertel 5380: }
                   5381: div.LC_edit_problem_header,
1.602     albertel 5382: div.LC_edit_problem_header div,
1.614     albertel 5383: div.LC_edit_problem_footer,
                   5384: div.LC_edit_problem_footer div,
1.602     albertel 5385: div.LC_edit_problem_editxml_header,
                   5386: div.LC_edit_problem_editxml_header div {
1.600     albertel 5387:   margin-top: 5px;
                   5388: }
1.602     albertel 5389: div.LC_edit_problem_header_edit_row {
                   5390:   background: $tabbg;
                   5391:   padding: 3px;
                   5392:   margin-bottom: 5px;
                   5393: }
1.600     albertel 5394: div.LC_edit_problem_header_title {
1.705     tempelho 5395:   font-weight: bold;
                   5396:   font-size: larger;
1.602     albertel 5397:   background: $tabbg;
                   5398:   padding: 3px;
                   5399: }
                   5400: table.LC_edit_problem_header_title {
1.705     tempelho 5401:   font-size: larger;
                   5402:   font-weight:  bold;
1.602     albertel 5403:   width: 100%;
                   5404:   border-color: $pgbg;
                   5405:   border-style: solid;
                   5406:   border-width: $border;
                   5407: 
1.600     albertel 5408:   background: $tabbg;
1.602     albertel 5409:   border-collapse: collapse;
                   5410:   padding: 0px
                   5411: }
                   5412: 
                   5413: div.LC_edit_problem_discards {
                   5414:   float: left;
                   5415:   padding-bottom: 5px;
                   5416: }
                   5417: div.LC_edit_problem_saves {
                   5418:   float: right;
                   5419:   padding-bottom: 5px;
1.600     albertel 5420: }
                   5421: hr.LC_edit_problem_divide {
1.602     albertel 5422:   clear: both;
1.600     albertel 5423:   color: $tabbg;
                   5424:   background-color: $tabbg;
                   5425:   height: 3px;
                   5426:   border: 0px;
                   5427: }
1.679     riegler  5428: img.stift{
1.678     riegler  5429:   border-width:0;
1.679     riegler  5430:   vertical-align:middle;
1.677     riegler  5431: }
1.680     riegler  5432: 
1.681     riegler  5433: table#LC_mainmenu{
                   5434:  margin-top:10px;
                   5435:  width:80%;
                   5436: 
                   5437: }
                   5438: 
1.680     riegler  5439: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
                   5440:   vertical-align: top;
                   5441:   width: 45%;
                   5442: }
                   5443: .LC_mainmenu_fieldset_category {
                   5444:   color: $font;
                   5445:   background: $pgbg;
                   5446:   font-family: $sans;
                   5447:   font-size: small;
                   5448:   font-weight: bold;
                   5449: }
                   5450: 
1.716     raeburn  5451: div.LC_createcourse {
                   5452:     margin: 10px 10px 10px 10px;
                   5453: }
                   5454: 
1.693     droeschl 5455: /* ---- Remove when done ----
                   5456: # The following styles is part of the redesign of LON-CAPA and are
                   5457: # subject to change during this project.
                   5458: # Don't rely on their current functionality as they might be 
                   5459: # changed or removed.
                   5460: # --------------------------*/
                   5461: 
1.698     harmsja  5462: a:hover,
                   5463: ol.smallMenu a:hover,
                   5464: ol#MenuBreadcrumbs a:hover,
                   5465: ul#TabMainMenuContent a:hover,
                   5466: .FormSectionClearButton input:hover{
                   5467: 	color:#BF2317;
                   5468:         text-decoration:none;
1.693     droeschl 5469: }
                   5470: 
                   5471: h1 { 
1.701     harmsja  5472: 	padding:5px 10px 5px 0px;
1.693     droeschl 5473: 	line-height:130%;
                   5474: }
1.698     harmsja  5475: 
1.693     droeschl 5476: h2,h3,h4,h5,h6
                   5477: {
                   5478: margin:5px 0px 5px 0px;
                   5479: line-height:130%;
                   5480: }
1.698     harmsja  5481: .hcell{
                   5482:         padding:3px 15px 3px 15px;
                   5483:         margin:0px;
1.703     harmsja  5484: 	background-color:$tabbg;
                   5485: 	border-bottom:solid 1px $lg_border_color;       
1.693     droeschl 5486: }
1.698     harmsja  5487: .noBorder {
                   5488:         border:0px;
                   5489: }
                   5490: /*
                   5491: .bgLightGrey { background:URL(images/TabMenuBG.png) repeat-x left top; }
                   5492: .bgLightGreyYellow {background-color:#EFECE0;}
                   5493: */
1.693     droeschl 5494: 
                   5495: 
1.698     harmsja  5496: /* Main Header with discription of Person, Course, etc. */
1.693     droeschl 5497: .HeadRight {
                   5498: 	text-align: right;
                   5499: 	float: right;
                   5500: 	margin: 0px;
                   5501: 	padding: 0px;
1.698     harmsja  5502:         right:0;
1.693     droeschl 5503:         position:absolute;
1.698     harmsja  5504:         overflow:hidden;
1.693     droeschl 5505: }
                   5506: 
1.698     harmsja  5507: p {
                   5508: 	padding: 10px;
                   5509: 
                   5510: }
                   5511: .FormSectionClearButton input {
                   5512:         background-color:transparent;
                   5513:         border:0px;
                   5514:         cursor:pointer;
                   5515:         text-decoration:underline;
1.693     droeschl 5516: }
                   5517: 
                   5518: 
1.698     harmsja  5519: dl,ul,div,fieldset {
                   5520: 	margin: 10px 10px 10px 0px;
1.693     droeschl 5521: 	overflow:hidden;
                   5522: }
1.698     harmsja  5523: ol.smallMenu {
                   5524: 	margin: 0px;
1.693     droeschl 5525: }
                   5526: 
1.698     harmsja  5527: ol.smallMenu li {
1.693     droeschl 5528: 	display: inline;
                   5529: 	padding: 5px 5px 0px 10px;
                   5530: 	vertical-align: top;
                   5531: }
                   5532: 
1.698     harmsja  5533: ol.smallMenu li img {
1.693     droeschl 5534: 	vertical-align: bottom;
                   5535: }
                   5536: 
1.698     harmsja  5537: ol.smallMenu a {
1.693     droeschl 5538: 	font-size: 90%;
                   5539: 	color: RGB(80, 80, 80);
                   5540: 	text-decoration: none;
                   5541: }
                   5542: 
1.698     harmsja  5543: ol#TabMainMenuContent {
1.693     droeschl 5544: 	
                   5545: 	margin: 0px 0px 10px 0px;
                   5546: 	padding: 0px;
                   5547: }
                   5548: 
1.698     harmsja  5549: ol#TabMainMenuContent li {
1.693     droeschl 5550: 	display: inline;
                   5551: 	vertical-align: bottom;
                   5552: 	border-bottom: solid 1px RGB(175, 175, 175);
                   5553: 	border-right: solid 1px RGB(175, 175, 175);
                   5554: 	padding: 5px 15px 5px 15px;
                   5555: 	margin-right:4px;
                   5556: 	line-height: 140%;
                   5557: 	font-weight: bold;
                   5558: 	overflow:hidden;
1.698     harmsja  5559: /*	background: RGB(211, 206, 205) URL(images/TabMenuBG.png) repeat-x left top;*/
1.693     droeschl 5560: }
                   5561: 
1.698     harmsja  5562: ol#TabMainMenuContent li a{
1.693     droeschl 5563: 	color: RGB(47, 47, 47);
                   5564: 	text-decoration: none;
                   5565: }
                   5566: 
1.698     harmsja  5567: ol#TabMainMenuContent div.columnSection {
1.693     droeschl 5568: 	margin-bottom: 0px;
                   5569: }
                   5570: 
1.698     harmsja  5571: ol#MenuBreadcrumbs, ol#PathBreadcrumbs {
1.693     droeschl 5572: 	border-top: solid 1px RGB(255, 255, 255);
                   5573: 	height: 20px;
                   5574: 	line-height: 20px;
                   5575: 	vertical-align: bottom;
                   5576: 	margin: 0px 0px 30px 0px;
                   5577: 	padding-left: 10px;
                   5578: 	list-style-position: inside;
1.698     harmsja  5579: /*	background: RGB(211, 206, 205) URL(images/TabMenuBG.png) repeat-x left
                   5580: 		top;*/
1.693     droeschl 5581: }
                   5582: 
1.698     harmsja  5583: ol#MenuBreadcrumbs li, ol#PathBreadcrumbs li {
                   5584: /*	background: url(images/pfeil_white.png) no-repeat left center;*/
1.693     droeschl 5585: 	display: inline;
                   5586: 	padding: 0px 0px 0px 10px;
                   5587: 	vertical-align: bottom;
                   5588: 	overflow:hidden;
                   5589: }
                   5590: 
1.698     harmsja  5591: ol#MenuBreadcrumbs li a {
1.693     droeschl 5592: 	text-decoration: none;
                   5593: 	font-size:90%;
                   5594: }
1.698     harmsja  5595: ol#PathBreadcrumbs li a{
                   5596: 	text-decoration:none;
                   5597: 	font-size:100%;
                   5598: 	font-weight:bold;
1.693     droeschl 5599: }
                   5600: 
1.698     harmsja  5601: .ContentBoxSpecial
1.693     droeschl 5602: {
1.701     harmsja  5603: 	border: solid 1px $lg_border_color;
1.698     harmsja  5604: }
                   5605: .ContentBox {
                   5606: 	padding:10px;
1.693     droeschl 5607: }
1.698     harmsja  5608: .PopUp
1.693     droeschl 5609: {
1.698     harmsja  5610: 	padding:10px;
                   5611: 	border-left:solid 1px $lg_border_color;
                   5612:  	border-top:solid 1px $lg_border_color;
                   5613: 	border-bottom:outset 1px $lg_border_color;
                   5614: 	border-right:outset 1px $lg_border_color;
                   5615: 	display:none;
                   5616: 	position:absolute;
                   5617: 	right:0;
                   5618: 	background-color:white;
                   5619: 	z-index:5;
1.693     droeschl 5620: }
                   5621: 
1.698     harmsja  5622: dl.ListStyleClean dt {
1.693     droeschl 5623: 	padding-right: 5px;
                   5624: 	display: table-header-group;
                   5625: }
                   5626: 
1.698     harmsja  5627: dl.ListStyleClean dd {
1.693     droeschl 5628: 	display: table-row;
                   5629: }
                   5630: 
                   5631: .ListStyleClean,
                   5632: .ListStyleSimple,
                   5633: .ListStyleNormal,
                   5634: .ListStyleNormal_Border,
                   5635: .ListStyleSpecial
                   5636: 	{
                   5637: 	/*display:block;	*/
                   5638: 	list-style-position: inside;
                   5639: 	list-style-type: none;
                   5640: 	overflow: hidden;
                   5641: 	padding: 0px;
                   5642: }
                   5643: 
                   5644: .ListStyleSimple li,
1.698     harmsja  5645: .ListStyleSimple dd,
1.693     droeschl 5646: .ListStyleNormal li,
1.698     harmsja  5647: .ListStyleNormal dd,
1.693     droeschl 5648: .ListStyleSpecial li,
1.698     harmsja  5649: .ListStyleSpecial dd
1.693     droeschl 5650: 	{
                   5651: 	margin: 0px;
                   5652: 	padding: 5px 5px 5px 10px;
                   5653: 	clear: both;
                   5654: }
                   5655: 
1.698     harmsja  5656: .ListStyleClean li,
                   5657: .ListStyleClean dd {
1.693     droeschl 5658: 	padding-top: 0px;
                   5659: 	padding-bottom: 0px;
                   5660: }
                   5661: 
1.698     harmsja  5662: .ListStyleSimple dd,
                   5663: .ListStyleSimple li{
                   5664: 	border-bottom: solid 1px $lg_border_color;
1.693     droeschl 5665: }
                   5666: 
1.698     harmsja  5667: .ListStyleSpecial li,
                   5668: .ListStyleSpecial dd {
1.693     droeschl 5669: 	list-style-type: none;
                   5670: 	background-color: RGB(220, 220, 220);
                   5671: 	margin-bottom: 4px;
                   5672: }
                   5673: 
1.698     harmsja  5674: table.SimpleTable {
                   5675: 	margin:5px;
                   5676: 	border:solid 1px $lg_border_color;
1.693     droeschl 5677: 	}
                   5678: 
1.698     harmsja  5679: table.SimpleTable tr {
                   5680: 	padding:0px;
                   5681: 	border:solid 1px $lg_border_color;
1.693     droeschl 5682: }
                   5683: table.SimpleTable thead{
1.698     harmsja  5684: 	 background:rgb(220,220,220);
1.693     droeschl 5685: }
                   5686: 
1.698     harmsja  5687: div.columnSection {
1.693     droeschl 5688: 	display: block;
                   5689: 	clear: both;
                   5690: 	overflow: hidden;
                   5691: 	margin:0px;
                   5692: }
                   5693: 
1.698     harmsja  5694: div.columnSection>* {
1.693     droeschl 5695: 	float: left;
                   5696: 	margin: 10px 20px 10px 0px;
                   5697: 	overflow:hidden;	
                   5698: }
1.698     harmsja  5699: div.columnSection > .ContentBox,
                   5700: div.columnSection > .ContentBoxSpecial
1.693     droeschl 5701: 	{
1.698     harmsja  5702: 	width: 400px;
1.693     droeschl 5703: 	
                   5704: }
                   5705: 
1.694     tempelho 5706: .LC_loginpage_container {
                   5707: 	text-align:left;
                   5708: 	margin : 0 auto;
                   5709: 	width:65%;
                   5710: 	padding: 10px;
                   5711: 	height: auto;
1.712     muellerd 5712: 	background-color:#FFFFFF;
1.694     tempelho 5713: 	border:1px solid #CCCCCC;
                   5714: }
                   5715: 
                   5716: 
                   5717: .LC_loginpage_loginContainer {
                   5718: 	float:left;
1.712     muellerd 5719: 	width: 182px;
                   5720: 	border:1px solid #CCCCCC;
                   5721: 	background-color:$loginbg;
1.694     tempelho 5722: }
                   5723: 
1.717     tempelho 5724: .LC_loginpage_loginContainer h2{
1.712     muellerd 5725: 	margin-top:0;
                   5726: 	display:block;
                   5727: 	background:$bgcol;
                   5728: 	color:$textcol;
                   5729: 	padding-left:5px;
                   5730: }
1.694     tempelho 5731: .LC_loginpage_loginInfo {
                   5732: 	margin-left:20px;
                   5733: 	float:left;
                   5734: 	width:30%;
                   5735: 	border:1px solid #CCCCCC;
                   5736: 	padding:10px;
                   5737: }
                   5738: 
1.712     muellerd 5739: .LC_loginpage_loginDomain {
                   5740: 	margin-right:20px;
                   5741: 	width:20%;
                   5742: 	float:left;
                   5743: 	padding:10px;
                   5744: }
                   5745: 
1.694     tempelho 5746: .LC_loginpage_space {
                   5747: 	clear:both;
                   5748: 	margin-bottom:20px;
                   5749: 	border-bottom: 1px solid #CCCCCC;
                   5750: }
                   5751: 
                   5752: .LC_loginpage_fieldset{
                   5753: 	border: 1px solid #CCCCCC;
                   5754: 	margin: 0 auto;
                   5755: }
                   5756: 
                   5757: .LC_loginpage_legend{
                   5758: 	padding: 2px;
                   5759: 	margin: 0px;
                   5760: 	font-size:14px;
                   5761: 	font-weight:bold;
                   5762: }
                   5763: 
                   5764: 
1.343     albertel 5765: END
                   5766: }
                   5767: 
1.306     albertel 5768: =pod
                   5769: 
                   5770: =item * &headtag()
                   5771: 
                   5772: Returns a uniform footer for LON-CAPA web pages.
                   5773: 
1.307     albertel 5774: Inputs: $title - optional title for the head
                   5775:         $head_extra - optional extra HTML to put inside the <head>
1.315     albertel 5776:         $args - optional arguments
1.319     albertel 5777:             force_register - if is true call registerurl so the remote is 
                   5778:                              informed
1.415     albertel 5779:             redirect       -> array ref of
                   5780:                                    1- seconds before redirect occurs
                   5781:                                    2- url to redirect to
                   5782:                                    3- whether the side effect should occur
1.315     albertel 5783:                            (side effect of setting 
                   5784:                                $env{'internal.head.redirect'} to the url 
                   5785:                                redirected too)
1.352     albertel 5786:             domain         -> force to color decorate a page for a specific
                   5787:                                domain
                   5788:             function       -> force usage of a specific rolish color scheme
                   5789:             bgcolor        -> override the default page bgcolor
1.460     albertel 5790:             no_auto_mt_title
                   5791:                            -> prevent &mt()ing the title arg
1.464     albertel 5792: 
1.306     albertel 5793: =cut
                   5794: 
                   5795: sub headtag {
1.313     albertel 5796:     my ($title,$head_extra,$args) = @_;
1.306     albertel 5797:     
1.363     albertel 5798:     my $function = $args->{'function'} || &get_users_function();
                   5799:     my $domain   = $args->{'domain'}   || &determinedomain();
                   5800:     my $bgcolor  = $args->{'bgcolor'}  || &designparm($function.'.pgbg',$domain);
1.418     albertel 5801:     my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458     albertel 5802: 		   $Apache::lonnet::perlvar{'lonVersion'},
1.531     albertel 5803: 		   #time(),
1.418     albertel 5804: 		   $env{'environment.color.timestamp'},
1.363     albertel 5805: 		   $function,$domain,$bgcolor);
                   5806: 
1.369     www      5807:     $url = '/adm/css/'.&escape($url).'.css';
1.363     albertel 5808: 
1.308     albertel 5809:     my $result =
                   5810: 	'<head>'.
1.461     albertel 5811: 	&font_settings();
1.319     albertel 5812: 
1.461     albertel 5813:     if (!$args->{'frameset'}) {
                   5814: 	$result .= &Apache::lonhtmlcommon::htmlareaheaders();
                   5815:     }
1.319     albertel 5816:     if ($args->{'force_register'}) {
                   5817: 	$result .= &Apache::lonmenu::registerurl(1);
                   5818:     }
1.436     albertel 5819:     if (!$args->{'no_nav_bar'} 
                   5820: 	&& !$args->{'only_body'}
                   5821: 	&& !$args->{'frameset'}) {
                   5822: 	$result .= &help_menu_js();
                   5823:     }
1.319     albertel 5824: 
1.314     albertel 5825:     if (ref($args->{'redirect'})) {
1.414     albertel 5826: 	my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315     albertel 5827: 	$url = &Apache::lonenc::check_encrypt($url);
1.414     albertel 5828: 	if (!$inhibit_continue) {
                   5829: 	    $env{'internal.head.redirect'} = $url;
                   5830: 	}
1.313     albertel 5831: 	$result.=<<ADDMETA
                   5832: <meta http-equiv="pragma" content="no-cache" />
1.344     albertel 5833: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313     albertel 5834: ADDMETA
                   5835:     }
1.306     albertel 5836:     if (!defined($title)) {
                   5837: 	$title = 'The LearningOnline Network with CAPA';
                   5838:     }
1.460     albertel 5839:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
                   5840:     $result .= '<title> LON-CAPA '.$title.'</title>'
1.414     albertel 5841: 	.'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
                   5842: 	.$head_extra;
1.306     albertel 5843:     return $result;
                   5844: }
                   5845: 
                   5846: =pod
                   5847: 
1.340     albertel 5848: =item * &font_settings()
                   5849: 
                   5850: Returns neccessary <meta> to set the proper encoding
                   5851: 
                   5852: Inputs: none
                   5853: 
                   5854: =cut
                   5855: 
                   5856: sub font_settings {
                   5857:     my $headerstring='';
1.647     www      5858:     if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340     albertel 5859: 	$headerstring.=
                   5860: 	    '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
                   5861:     }
                   5862:     return $headerstring;
                   5863: }
                   5864: 
1.341     albertel 5865: =pod
                   5866: 
                   5867: =item * &xml_begin()
                   5868: 
                   5869: Returns the needed doctype and <html>
                   5870: 
                   5871: Inputs: none
                   5872: 
                   5873: =cut
                   5874: 
                   5875: sub xml_begin {
                   5876:     my $output='';
                   5877: 
1.592     albertel 5878:     if ($env{'internal.start_page'}==1) {
                   5879: 	&Apache::lonhtmlcommon::init_htmlareafields();
                   5880:     }
1.342     albertel 5881: 
1.341     albertel 5882:     if ($env{'browser.mathml'}) {
                   5883: 	$output='<?xml version="1.0"?>'
                   5884:             #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
                   5885: #            .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
                   5886:             
                   5887: #	    .'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [<!ENTITY mathns "http://www.w3.org/1998/Math/MathML">] >'
                   5888: 	    .'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">'
                   5889:             .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" ' 
                   5890: 	    .'xmlns="http://www.w3.org/1999/xhtml">';
                   5891:     } else {
                   5892: 	$output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
                   5893:     }
                   5894:     return $output;
                   5895: }
1.340     albertel 5896: 
                   5897: =pod
                   5898: 
1.306     albertel 5899: =item * &endheadtag()
                   5900: 
                   5901: Returns a uniform </head> for LON-CAPA web pages.
                   5902: 
                   5903: Inputs: none
                   5904: 
                   5905: =cut
                   5906: 
                   5907: sub endheadtag {
                   5908:     return '</head>';
                   5909: }
                   5910: 
                   5911: =pod
                   5912: 
                   5913: =item * &head()
                   5914: 
                   5915: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
                   5916: 
1.648     raeburn  5917: Inputs:
                   5918: 
                   5919: =over 4
                   5920: 
                   5921: $title - optional title for the page
                   5922: 
                   5923: $head_extra - optional extra HTML to put inside the <head>
                   5924: 
                   5925: =back
1.405     albertel 5926: 
1.306     albertel 5927: =cut
                   5928: 
                   5929: sub head {
1.325     albertel 5930:     my ($title,$head_extra,$args) = @_;
                   5931:     return &headtag($title,$head_extra,$args).&endheadtag();
1.306     albertel 5932: }
                   5933: 
                   5934: =pod
                   5935: 
                   5936: =item * &start_page()
                   5937: 
                   5938: Returns a complete <html> .. <body> section for LON-CAPA web pages.
                   5939: 
1.648     raeburn  5940: Inputs:
                   5941: 
                   5942: =over 4
                   5943: 
                   5944: $title - optional title for the page
                   5945: 
                   5946: $head_extra - optional extra HTML to incude inside the <head>
                   5947: 
                   5948: $args - additional optional args supported are:
                   5949: 
                   5950: =over 8
                   5951: 
                   5952:              only_body      -> is true will set &bodytag() onlybodytag
1.317     albertel 5953:                                     arg on
1.648     raeburn  5954:              no_nav_bar     -> is true will set &bodytag() notopbar arg on
                   5955:              add_entries    -> additional attributes to add to the  <body>
                   5956:              domain         -> force to color decorate a page for a 
1.317     albertel 5957:                                     specific domain
1.648     raeburn  5958:              function       -> force usage of a specific rolish color
1.317     albertel 5959:                                     scheme
1.648     raeburn  5960:              redirect       -> see &headtag()
                   5961:              bgcolor        -> override the default page bg color
                   5962:              js_ready       -> return a string ready for being used in 
1.317     albertel 5963:                                     a javascript writeln
1.648     raeburn  5964:              html_encode    -> return a string ready for being used in 
1.320     albertel 5965:                                     a html attribute
1.648     raeburn  5966:              force_register -> if is true will turn on the &bodytag()
1.317     albertel 5967:                                     $forcereg arg
1.648     raeburn  5968:              body_title     -> alternate text to use instead of $title
1.326     albertel 5969:                                     in the title box that appears, this text
                   5970:                                     is not auto translated like the $title is
1.648     raeburn  5971:              frameset       -> if true will start with a <frameset>
1.330     albertel 5972:                                     rather than <body>
1.648     raeburn  5973:              no_title       -> if true the title bar won't be shown
                   5974:              skip_phases    -> hash ref of 
1.338     albertel 5975:                                     head -> skip the <html><head> generation
                   5976:                                     body -> skip all <body> generation
1.648     raeburn  5977:              no_inline_link -> if true and in remote mode, don't show the 
1.361     albertel 5978:                                     'Switch To Inline Menu' link
1.648     raeburn  5979:              no_auto_mt_title -> prevent &mt()ing the title arg
                   5980:              inherit_jsmath -> when creating popup window in a page,
                   5981:                                     should it have jsmath forced on by the
                   5982:                                     current page
1.361     albertel 5983: 
1.648     raeburn  5984: =back
1.460     albertel 5985: 
1.648     raeburn  5986: =back
1.562     albertel 5987: 
1.306     albertel 5988: =cut
                   5989: 
                   5990: sub start_page {
1.309     albertel 5991:     my ($title,$head_extra,$args) = @_;
1.318     albertel 5992:     #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313     albertel 5993:     my %head_args;
1.352     albertel 5994:     foreach my $arg ('redirect','force_register','domain','function',
1.460     albertel 5995: 		     'bgcolor','frameset','no_nav_bar','only_body',
                   5996: 		     'no_auto_mt_title') {
1.319     albertel 5997: 	if (defined($args->{$arg})) {
1.324     raeburn  5998: 	    $head_args{$arg} = $args->{$arg};
1.319     albertel 5999: 	}
1.313     albertel 6000:     }
1.319     albertel 6001: 
1.315     albertel 6002:     $env{'internal.start_page'}++;
1.338     albertel 6003:     my $result;
                   6004:     if (! exists($args->{'skip_phases'}{'head'}) ) {
                   6005: 	$result.=
1.341     albertel 6006: 	    &xml_begin().
1.338     albertel 6007: 	    &headtag($title,$head_extra,\%head_args).&endheadtag();
                   6008:     }
                   6009:     
                   6010:     if (! exists($args->{'skip_phases'}{'body'}) ) {
                   6011: 	if ($args->{'frameset'}) {
                   6012: 	    my $attr_string = &make_attr_string($args->{'force_register'},
                   6013: 						$args->{'add_entries'});
                   6014: 	    $result .= "\n<frameset $attr_string>\n";
                   6015: 	} else {
                   6016: 	    $result .=
                   6017: 		&bodytag($title, 
                   6018: 			 $args->{'function'},       $args->{'add_entries'},
                   6019: 			 $args->{'only_body'},      $args->{'domain'},
                   6020: 			 $args->{'force_register'}, $args->{'body_title'},
                   6021: 			 $args->{'no_nav_bar'},     $args->{'bgcolor'},
1.460     albertel 6022: 			 $args->{'no_title'},       $args->{'no_inline_link'},
                   6023: 			 $args);
1.338     albertel 6024: 	}
1.330     albertel 6025:     }
1.338     albertel 6026: 
1.315     albertel 6027:     if ($args->{'js_ready'}) {
1.713     kaisler  6028: 		$result = &js_ready($result);
1.315     albertel 6029:     }
1.320     albertel 6030:     if ($args->{'html_encode'}) {
1.713     kaisler  6031: 		$result = &html_encode($result);
                   6032:     }
                   6033: 
1.718   ! raeburn  6034:     if (exists($args->{'bread_crumbs'})) {
        !          6035:         &Apache::lonhtmlcommon::clear_breadcrumbs();
        !          6036:         if (ref($args->{'bread_crumbs'}) eq 'ARRAY') {         
        !          6037:             foreach my $crumb (@{$args->{'bread_crumbs'}}){
        !          6038:                 &Apache::lonhtmlcommon::add_breadcrumb($crumb);
        !          6039:             }
        !          6040:         }
        !          6041:         $result .= &Apache::lonhtmlcommon::breadcrumbs();
1.320     albertel 6042:     }
1.713     kaisler  6043: 
1.315     albertel 6044:     return $result;
1.306     albertel 6045: }
                   6046: 
1.330     albertel 6047: 
1.306     albertel 6048: =pod
                   6049: 
                   6050: =item * &head()
                   6051: 
                   6052: Returns a complete </body></html> section for LON-CAPA web pages.
                   6053: 
1.315     albertel 6054: Inputs:         $args - additional optional args supported are:
                   6055:                  js_ready     -> return a string ready for being used in 
                   6056:                                  a javascript writeln
1.320     albertel 6057:                  html_encode  -> return a string ready for being used in 
                   6058:                                  a html attribute
1.330     albertel 6059:                  frameset     -> if true will start with a <frameset>
                   6060:                                  rather than <body>
1.493     albertel 6061:                  dicsussion   -> if true will get discussion from
                   6062:                                   lonxml::xmlend
                   6063:                                  (you can pass the target and parser arguments
                   6064:                                   through optional 'target' and 'parser' args
                   6065:                                   to this routine)
1.306     albertel 6066: 
                   6067: =cut
                   6068: 
                   6069: sub end_page {
1.315     albertel 6070:     my ($args) = @_;
                   6071:     $env{'internal.end_page'}++;
1.330     albertel 6072:     my $result;
1.335     albertel 6073:     if ($args->{'discussion'}) {
                   6074: 	my ($target,$parser);
                   6075: 	if (ref($args->{'discussion'})) {
                   6076: 	    ($target,$parser) =($args->{'discussion'}{'target'},
                   6077: 				$args->{'discussion'}{'parser'});
                   6078: 	}
                   6079: 	$result .= &Apache::lonxml::xmlend($target,$parser);
                   6080:     }
                   6081: 
1.330     albertel 6082:     if ($args->{'frameset'}) {
                   6083: 	$result .= '</frameset>';
                   6084:     } else {
1.635     raeburn  6085: 	$result .= &endbodytag($args);
1.330     albertel 6086:     }
                   6087:     $result .= "\n</html>";
                   6088: 
1.315     albertel 6089:     if ($args->{'js_ready'}) {
1.317     albertel 6090: 	$result = &js_ready($result);
1.315     albertel 6091:     }
1.335     albertel 6092: 
1.320     albertel 6093:     if ($args->{'html_encode'}) {
                   6094: 	$result = &html_encode($result);
                   6095:     }
1.335     albertel 6096: 
1.315     albertel 6097:     return $result;
                   6098: }
                   6099: 
1.320     albertel 6100: sub html_encode {
                   6101:     my ($result) = @_;
                   6102: 
1.322     albertel 6103:     $result = &HTML::Entities::encode($result,'<>&"');
1.320     albertel 6104:     
                   6105:     return $result;
                   6106: }
1.317     albertel 6107: sub js_ready {
                   6108:     my ($result) = @_;
                   6109: 
1.323     albertel 6110:     $result =~ s/[\n\r]/ /xmsg;
                   6111:     $result =~ s/\\/\\\\/xmsg;
                   6112:     $result =~ s/'/\\'/xmsg;
1.372     albertel 6113:     $result =~ s{</}{<\\/}xmsg;
1.317     albertel 6114:     
                   6115:     return $result;
                   6116: }
                   6117: 
1.315     albertel 6118: sub validate_page {
                   6119:     if (  exists($env{'internal.start_page'})
1.316     albertel 6120: 	  &&     $env{'internal.start_page'} > 1) {
                   6121: 	&Apache::lonnet::logthis('start_page called multiple times '.
1.318     albertel 6122: 				 $env{'internal.start_page'}.' '.
1.316     albertel 6123: 				 $ENV{'request.filename'});
1.315     albertel 6124:     }
                   6125:     if (  exists($env{'internal.end_page'})
1.316     albertel 6126: 	  &&     $env{'internal.end_page'} > 1) {
                   6127: 	&Apache::lonnet::logthis('end_page called multiple times '.
1.318     albertel 6128: 				 $env{'internal.end_page'}.' '.
1.316     albertel 6129: 				 $env{'request.filename'});
1.315     albertel 6130:     }
                   6131:     if (     exists($env{'internal.start_page'})
                   6132: 	&& ! exists($env{'internal.end_page'})) {
1.316     albertel 6133: 	&Apache::lonnet::logthis('start_page called without end_page '.
                   6134: 				 $env{'request.filename'});
1.315     albertel 6135:     }
                   6136:     if (   ! exists($env{'internal.start_page'})
                   6137: 	&&   exists($env{'internal.end_page'})) {
1.316     albertel 6138: 	&Apache::lonnet::logthis('end_page called without start_page'.
                   6139: 				 $env{'request.filename'});
1.315     albertel 6140:     }
1.306     albertel 6141: }
1.315     albertel 6142: 
1.318     albertel 6143: sub simple_error_page {
                   6144:     my ($r,$title,$msg) = @_;
                   6145:     my $page =
                   6146: 	&Apache::loncommon::start_page($title).
                   6147: 	&mt($msg).
                   6148: 	&Apache::loncommon::end_page();
                   6149:     if (ref($r)) {
                   6150: 	$r->print($page);
1.327     albertel 6151: 	return;
1.318     albertel 6152:     }
                   6153:     return $page;
                   6154: }
1.347     albertel 6155: 
                   6156: {
1.610     albertel 6157:     my @row_count;
1.347     albertel 6158:     sub start_data_table {
1.422     albertel 6159: 	my ($add_class) = @_;
                   6160: 	my $css_class = (join(' ','LC_data_table',$add_class));
1.610     albertel 6161: 	unshift(@row_count,0);
1.422     albertel 6162: 	return '<table class="'.$css_class.'">'."\n";
1.347     albertel 6163:     }
                   6164: 
                   6165:     sub end_data_table {
1.610     albertel 6166: 	shift(@row_count);
1.389     albertel 6167: 	return '</table>'."\n";;
1.347     albertel 6168:     }
                   6169: 
                   6170:     sub start_data_table_row {
1.422     albertel 6171: 	my ($add_class) = @_;
1.610     albertel 6172: 	$row_count[0]++;
                   6173: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428     albertel 6174: 	$css_class = (join(' ',$css_class,$add_class));
1.422     albertel 6175: 	return  '<tr class="'.$css_class.'">'."\n";;
1.347     albertel 6176:     }
1.471     banghart 6177:     
                   6178:     sub continue_data_table_row {
                   6179: 	my ($add_class) = @_;
1.610     albertel 6180: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471     banghart 6181: 	$css_class = (join(' ',$css_class,$add_class));
                   6182: 	return  '<tr class="'.$css_class.'">'."\n";;
                   6183:     }
1.347     albertel 6184: 
                   6185:     sub end_data_table_row {
1.389     albertel 6186: 	return '</tr>'."\n";;
1.347     albertel 6187:     }
1.367     www      6188: 
1.421     albertel 6189:     sub start_data_table_empty_row {
1.707     bisitz   6190: #	$row_count[0]++;
1.421     albertel 6191: 	return  '<tr class="LC_empty_row" >'."\n";;
                   6192:     }
                   6193: 
                   6194:     sub end_data_table_empty_row {
                   6195: 	return '</tr>'."\n";;
                   6196:     }
                   6197: 
1.367     www      6198:     sub start_data_table_header_row {
1.389     albertel 6199: 	return  '<tr class="LC_header_row">'."\n";;
1.367     www      6200:     }
                   6201: 
                   6202:     sub end_data_table_header_row {
1.389     albertel 6203: 	return '</tr>'."\n";;
1.367     www      6204:     }
1.347     albertel 6205: }
                   6206: 
1.548     albertel 6207: =pod
                   6208: 
                   6209: =item * &inhibit_menu_check($arg)
                   6210: 
                   6211: Checks for a inhibitmenu state and generates output to preserve it
                   6212: 
                   6213: Inputs:         $arg - can be any of
                   6214:                      - undef - in which case the return value is a string 
                   6215:                                to add  into arguments list of a uri
                   6216:                      - 'input' - in which case the return value is a HTML
                   6217:                                  <form> <input> field of type hidden to
                   6218:                                  preserve the value
                   6219:                      - a url - in which case the return value is the url with
                   6220:                                the neccesary cgi args added to preserve the
                   6221:                                inhibitmenu state
                   6222:                      - a ref to a url - no return value, but the string is
                   6223:                                         updated to include the neccessary cgi
                   6224:                                         args to preserve the inhibitmenu state
                   6225: 
                   6226: =cut
                   6227: 
                   6228: sub inhibit_menu_check {
                   6229:     my ($arg) = @_;
                   6230:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   6231:     if ($arg eq 'input') {
                   6232: 	if ($env{'form.inhibitmenu'}) {
                   6233: 	    return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
                   6234: 	} else {
                   6235: 	    return
                   6236: 	}
                   6237:     }
                   6238:     if ($env{'form.inhibitmenu'}) {
                   6239: 	if (ref($arg)) {
                   6240: 	    $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   6241: 	} elsif ($arg eq '') {
                   6242: 	    $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
                   6243: 	} else {
                   6244: 	    $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   6245: 	}
                   6246:     }
                   6247:     if (!ref($arg)) {
                   6248: 	return $arg;
                   6249:     }
                   6250: }
                   6251: 
1.251     albertel 6252: ###############################################
1.182     matthew  6253: 
                   6254: =pod
                   6255: 
1.549     albertel 6256: =back
                   6257: 
                   6258: =head1 User Information Routines
                   6259: 
                   6260: =over 4
                   6261: 
1.405     albertel 6262: =item * &get_users_function()
1.182     matthew  6263: 
                   6264: Used by &bodytag to determine the current users primary role.
                   6265: Returns either 'student','coordinator','admin', or 'author'.
                   6266: 
                   6267: =cut
                   6268: 
                   6269: ###############################################
                   6270: sub get_users_function {
                   6271:     my $function = 'student';
1.258     albertel 6272:     if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182     matthew  6273:         $function='coordinator';
                   6274:     }
1.258     albertel 6275:     if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182     matthew  6276:         $function='admin';
                   6277:     }
1.258     albertel 6278:     if (($env{'request.role'}=~/^(au|ca)/) ||
1.182     matthew  6279:         ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
                   6280:         $function='author';
                   6281:     }
                   6282:     return $function;
1.54      www      6283: }
1.99      www      6284: 
                   6285: ###############################################
                   6286: 
1.233     raeburn  6287: =pod
                   6288: 
1.542     raeburn  6289: =item * &check_user_status()
1.274     raeburn  6290: 
                   6291: Determines current status of supplied role for a
                   6292: specific user. Roles can be active, previous or future.
                   6293: 
                   6294: Inputs: 
                   6295: user's domain, user's username, course's domain,
1.375     raeburn  6296: course's number, optional section ID.
1.274     raeburn  6297: 
                   6298: Outputs:
                   6299: role status: active, previous or future. 
                   6300: 
                   6301: =cut
                   6302: 
                   6303: sub check_user_status {
1.412     raeburn  6304:     my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274     raeburn  6305:     my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
                   6306:     my @uroles = keys %userinfo;
                   6307:     my $srchstr;
                   6308:     my $active_chk = 'none';
1.412     raeburn  6309:     my $now = time;
1.274     raeburn  6310:     if (@uroles > 0) {
1.412     raeburn  6311:         if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274     raeburn  6312:             $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
                   6313:         } else {
1.412     raeburn  6314:             $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
                   6315:         }
                   6316:         if (grep/^\Q$srchstr\E$/,@uroles) {
1.274     raeburn  6317:             my $role_end = 0;
                   6318:             my $role_start = 0;
                   6319:             $active_chk = 'active';
1.412     raeburn  6320:             if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
                   6321:                 $role_end = $1;
                   6322:                 if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
                   6323:                     $role_start = $1;
1.274     raeburn  6324:                 }
                   6325:             }
                   6326:             if ($role_start > 0) {
1.412     raeburn  6327:                 if ($now < $role_start) {
1.274     raeburn  6328:                     $active_chk = 'future';
                   6329:                 }
                   6330:             }
                   6331:             if ($role_end > 0) {
1.412     raeburn  6332:                 if ($now > $role_end) {
1.274     raeburn  6333:                     $active_chk = 'previous';
                   6334:                 }
                   6335:             }
                   6336:         }
                   6337:     }
                   6338:     return $active_chk;
                   6339: }
                   6340: 
                   6341: ###############################################
                   6342: 
                   6343: =pod
                   6344: 
1.405     albertel 6345: =item * &get_sections()
1.233     raeburn  6346: 
                   6347: Determines all the sections for a course including
                   6348: sections with students and sections containing other roles.
1.419     raeburn  6349: Incoming parameters: 
                   6350: 
                   6351: 1. domain
                   6352: 2. course number 
                   6353: 3. reference to array containing roles for which sections should 
                   6354: be gathered (optional).
                   6355: 4. reference to array containing status types for which sections 
                   6356: should be gathered (optional).
                   6357: 
                   6358: If the third argument is undefined, sections are gathered for any role. 
                   6359: If the fourth argument is undefined, sections are gathered for any status.
                   6360: Permissible values are 'active' or 'future' or 'previous'.
1.233     raeburn  6361:  
1.374     raeburn  6362: Returns section hash (keys are section IDs, values are
                   6363: number of users in each section), subject to the
1.419     raeburn  6364: optional roles filter, optional status filter 
1.233     raeburn  6365: 
                   6366: =cut
                   6367: 
                   6368: ###############################################
                   6369: sub get_sections {
1.419     raeburn  6370:     my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366     albertel 6371:     if (!defined($cdom) || !defined($cnum)) {
                   6372:         my $cid =  $env{'request.course.id'};
                   6373: 
                   6374: 	return if (!defined($cid));
                   6375: 
                   6376:         $cdom = $env{'course.'.$cid.'.domain'};
                   6377:         $cnum = $env{'course.'.$cid.'.num'};
                   6378:     }
                   6379: 
                   6380:     my %sectioncount;
1.419     raeburn  6381:     my $now = time;
1.240     albertel 6382: 
1.366     albertel 6383:     if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276     albertel 6384: 	my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240     albertel 6385: 	my $sec_index = &Apache::loncoursedata::CL_SECTION();
                   6386: 	my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419     raeburn  6387:         my $start_index = &Apache::loncoursedata::CL_START();
                   6388:         my $end_index = &Apache::loncoursedata::CL_END();
                   6389:         my $status;
1.366     albertel 6390: 	while (my ($student,$data) = each(%$classlist)) {
1.419     raeburn  6391: 	    my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
                   6392: 				                     $data->[$status_index],
                   6393:                                                      $data->[$start_index],
                   6394:                                                      $data->[$end_index]);
                   6395:             if ($stu_status eq 'Active') {
                   6396:                 $status = 'active';
                   6397:             } elsif ($end < $now) {
                   6398:                 $status = 'previous';
                   6399:             } elsif ($start > $now) {
                   6400:                 $status = 'future';
                   6401:             } 
                   6402: 	    if ($section ne '-1' && $section !~ /^\s*$/) {
                   6403:                 if ((!defined($possible_status)) || (($status ne '') && 
                   6404:                     (grep/^\Q$status\E$/,@{$possible_status}))) { 
                   6405: 		    $sectioncount{$section}++;
                   6406:                 }
1.240     albertel 6407: 	    }
                   6408: 	}
                   6409:     }
                   6410:     my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   6411:     foreach my $user (sort(keys(%courseroles))) {
                   6412: 	if ($user !~ /^(\w{2})/) { next; }
                   6413: 	my ($role) = ($user =~ /^(\w{2})/);
                   6414: 	if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419     raeburn  6415: 	my ($section,$status);
1.240     albertel 6416: 	if ($role eq 'cr' &&
                   6417: 	    $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
                   6418: 	    $section=$1;
                   6419: 	}
                   6420: 	if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
                   6421: 	if (!defined($section) || $section eq '-1') { next; }
1.419     raeburn  6422:         my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
                   6423:         if ($end == -1 && $start == -1) {
                   6424:             next; #deleted role
                   6425:         }
                   6426:         if (!defined($possible_status)) { 
                   6427:             $sectioncount{$section}++;
                   6428:         } else {
                   6429:             if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
                   6430:                 $status = 'active';
                   6431:             } elsif ($end < $now) {
                   6432:                 $status = 'future';
                   6433:             } elsif ($start > $now) {
                   6434:                 $status = 'previous';
                   6435:             }
                   6436:             if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
                   6437:                 $sectioncount{$section}++;
                   6438:             }
                   6439:         }
1.233     raeburn  6440:     }
1.366     albertel 6441:     return %sectioncount;
1.233     raeburn  6442: }
                   6443: 
1.274     raeburn  6444: ###############################################
1.294     raeburn  6445: 
                   6446: =pod
1.405     albertel 6447: 
                   6448: =item * &get_course_users()
                   6449: 
1.275     raeburn  6450: Retrieves usernames:domains for users in the specified course
                   6451: with specific role(s), and access status. 
                   6452: 
                   6453: Incoming parameters:
1.277     albertel 6454: 1. course domain
                   6455: 2. course number
                   6456: 3. access status: users must have - either active, 
1.275     raeburn  6457: previous, future, or all.
1.277     albertel 6458: 4. reference to array of permissible roles
1.288     raeburn  6459: 5. reference to array of section restrictions (optional)
                   6460: 6. reference to results object (hash of hashes).
                   6461: 7. reference to optional userdata hash
1.609     raeburn  6462: 8. reference to optional statushash
1.630     raeburn  6463: 9. flag if privileged users (except those set to unhide in
                   6464:    course settings) should be excluded    
1.609     raeburn  6465: Keys of top level results hash are roles.
1.275     raeburn  6466: Keys of inner hashes are username:domain, with 
                   6467: values set to access type.
1.288     raeburn  6468: Optional userdata hash returns an array with arguments in the 
                   6469: same order as loncoursedata::get_classlist() for student data.
                   6470: 
1.609     raeburn  6471: Optional statushash returns
                   6472: 
1.288     raeburn  6473: Entries for end, start, section and status are blank because
                   6474: of the possibility of multiple values for non-student roles.
                   6475: 
1.275     raeburn  6476: =cut
1.405     albertel 6477: 
1.275     raeburn  6478: ###############################################
1.405     albertel 6479: 
1.275     raeburn  6480: sub get_course_users {
1.630     raeburn  6481:     my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288     raeburn  6482:     my %idx = ();
1.419     raeburn  6483:     my %seclists;
1.288     raeburn  6484: 
                   6485:     $idx{udom} = &Apache::loncoursedata::CL_SDOM();
                   6486:     $idx{uname} =  &Apache::loncoursedata::CL_SNAME();
                   6487:     $idx{end} = &Apache::loncoursedata::CL_END();
                   6488:     $idx{start} = &Apache::loncoursedata::CL_START();
                   6489:     $idx{id} = &Apache::loncoursedata::CL_ID();
                   6490:     $idx{section} = &Apache::loncoursedata::CL_SECTION();
                   6491:     $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
                   6492:     $idx{status} = &Apache::loncoursedata::CL_STATUS();
                   6493: 
1.290     albertel 6494:     if (grep(/^st$/,@{$roles})) {
1.276     albertel 6495:         my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278     raeburn  6496:         my $now = time;
1.277     albertel 6497:         foreach my $student (keys(%{$classlist})) {
1.288     raeburn  6498:             my $match = 0;
1.412     raeburn  6499:             my $secmatch = 0;
1.419     raeburn  6500:             my $section = $$classlist{$student}[$idx{section}];
1.609     raeburn  6501:             my $status = $$classlist{$student}[$idx{status}];
1.419     raeburn  6502:             if ($section eq '') {
                   6503:                 $section = 'none';
                   6504:             }
1.291     albertel 6505:             if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 6506:                 if (grep(/^all$/,@{$sections})) {
1.412     raeburn  6507:                     $secmatch = 1;
                   6508:                 } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420     albertel 6509:                     if (grep(/^none$/,@{$sections})) {
1.412     raeburn  6510:                         $secmatch = 1;
                   6511:                     }
                   6512:                 } else {  
1.419     raeburn  6513: 		    if (grep(/^\Q$section\E$/,@{$sections})) {
1.412     raeburn  6514: 		        $secmatch = 1;
                   6515:                     }
1.290     albertel 6516: 		}
1.412     raeburn  6517:                 if (!$secmatch) {
                   6518:                     next;
                   6519:                 }
1.419     raeburn  6520:             }
1.275     raeburn  6521:             if (defined($$types{'active'})) {
1.288     raeburn  6522:                 if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275     raeburn  6523:                     push(@{$$users{st}{$student}},'active');
1.288     raeburn  6524:                     $match = 1;
1.275     raeburn  6525:                 }
                   6526:             }
                   6527:             if (defined($$types{'previous'})) {
1.609     raeburn  6528:                 if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275     raeburn  6529:                     push(@{$$users{st}{$student}},'previous');
1.288     raeburn  6530:                     $match = 1;
1.275     raeburn  6531:                 }
                   6532:             }
                   6533:             if (defined($$types{'future'})) {
1.609     raeburn  6534:                 if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275     raeburn  6535:                     push(@{$$users{st}{$student}},'future');
1.288     raeburn  6536:                     $match = 1;
1.275     raeburn  6537:                 }
                   6538:             }
1.609     raeburn  6539:             if ($match) {
                   6540:                 push(@{$seclists{$student}},$section);
                   6541:                 if (ref($userdata) eq 'HASH') {
                   6542:                     $$userdata{$student} = $$classlist{$student};
                   6543:                 }
                   6544:                 if (ref($statushash) eq 'HASH') {
                   6545:                     $statushash->{$student}{'st'}{$section} = $status;
                   6546:                 }
1.288     raeburn  6547:             }
1.275     raeburn  6548:         }
                   6549:     }
1.412     raeburn  6550:     if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439     raeburn  6551:         my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   6552:         my $now = time;
1.609     raeburn  6553:         my %displaystatus = ( previous => 'Expired',
                   6554:                               active   => 'Active',
                   6555:                               future   => 'Future',
                   6556:                             );
1.630     raeburn  6557:         my %nothide;
                   6558:         if ($hidepriv) {
                   6559:             my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
                   6560:             foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
                   6561:                 if ($user !~ /:/) {
                   6562:                     $nothide{join(':',split(/[\@]/,$user))}=1;
                   6563:                 } else {
                   6564:                     $nothide{$user} = 1;
                   6565:                 }
                   6566:             }
                   6567:         }
1.439     raeburn  6568:         foreach my $person (sort(keys(%coursepersonnel))) {
1.288     raeburn  6569:             my $match = 0;
1.412     raeburn  6570:             my $secmatch = 0;
1.439     raeburn  6571:             my $status;
1.412     raeburn  6572:             my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275     raeburn  6573:             $user =~ s/:$//;
1.439     raeburn  6574:             my ($end,$start) = split(/:/,$coursepersonnel{$person});
                   6575:             if ($end == -1 || $start == -1) {
                   6576:                 next;
                   6577:             }
                   6578:             if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
                   6579:                 (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412     raeburn  6580:                 my ($uname,$udom) = split(/:/,$user);
                   6581:                 if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 6582:                     if (grep(/^all$/,@{$sections})) {
1.412     raeburn  6583:                         $secmatch = 1;
                   6584:                     } elsif ($usec eq '') {
1.420     albertel 6585:                         if (grep(/^none$/,@{$sections})) {
1.412     raeburn  6586:                             $secmatch = 1;
                   6587:                         }
                   6588:                     } else {
                   6589:                         if (grep(/^\Q$usec\E$/,@{$sections})) {
                   6590:                             $secmatch = 1;
                   6591:                         }
                   6592:                     }
                   6593:                     if (!$secmatch) {
                   6594:                         next;
                   6595:                     }
1.288     raeburn  6596:                 }
1.419     raeburn  6597:                 if ($usec eq '') {
                   6598:                     $usec = 'none';
                   6599:                 }
1.275     raeburn  6600:                 if ($uname ne '' && $udom ne '') {
1.630     raeburn  6601:                     if ($hidepriv) {
                   6602:                         if ((&Apache::lonnet::privileged($uname,$udom)) &&
                   6603:                             (!$nothide{$uname.':'.$udom})) {
                   6604:                             next;
                   6605:                         }
                   6606:                     }
1.503     raeburn  6607:                     if ($end > 0 && $end < $now) {
1.439     raeburn  6608:                         $status = 'previous';
                   6609:                     } elsif ($start > $now) {
                   6610:                         $status = 'future';
                   6611:                     } else {
                   6612:                         $status = 'active';
                   6613:                     }
1.277     albertel 6614:                     foreach my $type (keys(%{$types})) { 
1.275     raeburn  6615:                         if ($status eq $type) {
1.420     albertel 6616:                             if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419     raeburn  6617:                                 push(@{$$users{$role}{$user}},$type);
                   6618:                             }
1.288     raeburn  6619:                             $match = 1;
                   6620:                         }
                   6621:                     }
1.419     raeburn  6622:                     if (($match) && (ref($userdata) eq 'HASH')) {
                   6623:                         if (!exists($$userdata{$uname.':'.$udom})) {
                   6624: 			    &get_user_info($udom,$uname,\%idx,$userdata);
                   6625:                         }
1.420     albertel 6626:                         if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419     raeburn  6627:                             push(@{$seclists{$uname.':'.$udom}},$usec);
                   6628:                         }
1.609     raeburn  6629:                         if (ref($statushash) eq 'HASH') {
                   6630:                             $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
                   6631:                         }
1.275     raeburn  6632:                     }
                   6633:                 }
                   6634:             }
                   6635:         }
1.290     albertel 6636:         if (grep(/^ow$/,@{$roles})) {
1.279     raeburn  6637:             if ((defined($cdom)) && (defined($cnum))) {
                   6638:                 my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
                   6639:                 if ( defined($csettings{'internal.courseowner'}) ) {
                   6640:                     my $owner = $csettings{'internal.courseowner'};
1.609     raeburn  6641:                     next if ($owner eq '');
                   6642:                     my ($ownername,$ownerdom);
                   6643:                     if ($owner =~ /^([^:]+):([^:]+)$/) {
                   6644:                         $ownername = $1;
                   6645:                         $ownerdom = $2;
                   6646:                     } else {
                   6647:                         $ownername = $owner;
                   6648:                         $ownerdom = $cdom;
                   6649:                         $owner = $ownername.':'.$ownerdom;
1.439     raeburn  6650:                     }
                   6651:                     @{$$users{'ow'}{$owner}} = 'any';
1.290     albertel 6652:                     if (defined($userdata) && 
1.609     raeburn  6653: 			!exists($$userdata{$owner})) {
                   6654: 			&get_user_info($ownerdom,$ownername,\%idx,$userdata);
                   6655:                         if (!grep(/^none$/,@{$seclists{$owner}})) {
                   6656:                             push(@{$seclists{$owner}},'none');
                   6657:                         }
                   6658:                         if (ref($statushash) eq 'HASH') {
                   6659:                             $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419     raeburn  6660:                         }
1.290     albertel 6661: 		    }
1.279     raeburn  6662:                 }
                   6663:             }
                   6664:         }
1.419     raeburn  6665:         foreach my $user (keys(%seclists)) {
                   6666:             @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
                   6667:             $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
                   6668:         }
1.275     raeburn  6669:     }
                   6670:     return;
                   6671: }
                   6672: 
1.288     raeburn  6673: sub get_user_info {
                   6674:     my ($udom,$uname,$idx,$userdata) = @_;
1.289     albertel 6675:     $$userdata{$uname.':'.$udom}[$$idx{fullname}] = 
                   6676: 	&plainname($uname,$udom,'lastname');
1.291     albertel 6677:     $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297     raeburn  6678:     $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609     raeburn  6679:     my %idhash =  &Apache::lonnet::idrget($udom,($uname));
                   6680:     $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname}; 
1.288     raeburn  6681:     return;
                   6682: }
1.275     raeburn  6683: 
1.472     raeburn  6684: ###############################################
                   6685: 
                   6686: =pod
                   6687: 
                   6688: =item * &get_user_quota()
                   6689: 
                   6690: Retrieves quota assigned for storage of portfolio files for a user  
                   6691: 
                   6692: Incoming parameters:
                   6693: 1. user's username
                   6694: 2. user's domain
                   6695: 
                   6696: Returns:
1.536     raeburn  6697: 1. Disk quota (in Mb) assigned to student.
                   6698: 2. (Optional) Type of setting: custom or default
                   6699:    (individually assigned or default for user's 
                   6700:    institutional status).
                   6701: 3. (Optional) - User's institutional status (e.g., faculty, staff
                   6702:    or student - types as defined in localenroll::inst_usertypes 
                   6703:    for user's domain, which determines default quota for user.
                   6704: 4. (Optional) - Default quota which would apply to the user.
1.472     raeburn  6705: 
                   6706: If a value has been stored in the user's environment, 
1.536     raeburn  6707: it will return that, otherwise it returns the maximal default
                   6708: defined for the user's instituional status(es) in the domain.
1.472     raeburn  6709: 
                   6710: =cut
                   6711: 
                   6712: ###############################################
                   6713: 
                   6714: 
                   6715: sub get_user_quota {
                   6716:     my ($uname,$udom) = @_;
1.536     raeburn  6717:     my ($quota,$quotatype,$settingstatus,$defquota);
1.472     raeburn  6718:     if (!defined($udom)) {
                   6719:         $udom = $env{'user.domain'};
                   6720:     }
                   6721:     if (!defined($uname)) {
                   6722:         $uname = $env{'user.name'};
                   6723:     }
                   6724:     if (($udom eq '' || $uname eq '') ||
                   6725:         ($udom eq 'public') && ($uname eq 'public')) {
                   6726:         $quota = 0;
1.536     raeburn  6727:         $quotatype = 'default';
                   6728:         $defquota = 0; 
1.472     raeburn  6729:     } else {
1.536     raeburn  6730:         my $inststatus;
1.472     raeburn  6731:         if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
                   6732:             $quota = $env{'environment.portfolioquota'};
1.536     raeburn  6733:             $inststatus = $env{'environment.inststatus'};
1.472     raeburn  6734:         } else {
1.536     raeburn  6735:             my %userenv = 
                   6736:                 &Apache::lonnet::get('environment',['portfolioquota',
                   6737:                                      'inststatus'],$udom,$uname);
1.472     raeburn  6738:             my ($tmp) = keys(%userenv);
                   6739:             if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   6740:                 $quota = $userenv{'portfolioquota'};
1.536     raeburn  6741:                 $inststatus = $userenv{'inststatus'};
1.472     raeburn  6742:             } else {
                   6743:                 undef(%userenv);
                   6744:             }
                   6745:         }
1.536     raeburn  6746:         ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472     raeburn  6747:         if ($quota eq '') {
1.536     raeburn  6748:             $quota = $defquota;
                   6749:             $quotatype = 'default';
                   6750:         } else {
                   6751:             $quotatype = 'custom';
1.472     raeburn  6752:         }
                   6753:     }
1.536     raeburn  6754:     if (wantarray) {
                   6755:         return ($quota,$quotatype,$settingstatus,$defquota);
                   6756:     } else {
                   6757:         return $quota;
                   6758:     }
1.472     raeburn  6759: }
                   6760: 
                   6761: ###############################################
                   6762: 
                   6763: =pod
                   6764: 
                   6765: =item * &default_quota()
                   6766: 
1.536     raeburn  6767: Retrieves default quota assigned for storage of user portfolio files,
                   6768: given an (optional) user's institutional status.
1.472     raeburn  6769: 
                   6770: Incoming parameters:
                   6771: 1. domain
1.536     raeburn  6772: 2. (Optional) institutional status(es).  This is a : separated list of 
                   6773:    status types (e.g., faculty, staff, student etc.)
                   6774:    which apply to the user for whom the default is being retrieved.
                   6775:    If the institutional status string in undefined, the domain
                   6776:    default quota will be returned. 
1.472     raeburn  6777: 
                   6778: Returns:
                   6779: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536     raeburn  6780: 2. (Optional) institutional type which determined the value of the
                   6781:    default quota.
1.472     raeburn  6782: 
                   6783: If a value has been stored in the domain's configuration db,
                   6784: it will return that, otherwise it returns 20 (for backwards 
                   6785: compatibility with domains which have not set up a configuration
                   6786: db file; the original statically defined portfolio quota was 20 Mb). 
                   6787: 
1.536     raeburn  6788: If the user's status includes multiple types (e.g., staff and student),
                   6789: the largest default quota which applies to the user determines the
                   6790: default quota returned.
                   6791: 
1.472     raeburn  6792: =cut
                   6793: 
                   6794: ###############################################
                   6795: 
                   6796: 
                   6797: sub default_quota {
1.536     raeburn  6798:     my ($udom,$inststatus) = @_;
                   6799:     my ($defquota,$settingstatus);
                   6800:     my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622     raeburn  6801:                                             ['quotas'],$udom);
                   6802:     if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536     raeburn  6803:         if ($inststatus ne '') {
                   6804:             my @statuses = split(/:/,$inststatus);
                   6805:             foreach my $item (@statuses) {
1.711     raeburn  6806:                 if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   6807:                     if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
                   6808:                         if ($defquota eq '') {
                   6809:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   6810:                             $settingstatus = $item;
                   6811:                         } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
                   6812:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   6813:                             $settingstatus = $item;
                   6814:                         }
                   6815:                     }
                   6816:                 } else {
                   6817:                     if ($quotahash{'quotas'}{$item} ne '') {
                   6818:                         if ($defquota eq '') {
                   6819:                             $defquota = $quotahash{'quotas'}{$item};
                   6820:                             $settingstatus = $item;
                   6821:                         } elsif ($quotahash{'quotas'}{$item} > $defquota) {
                   6822:                             $defquota = $quotahash{'quotas'}{$item};
                   6823:                             $settingstatus = $item;
                   6824:                         }
1.536     raeburn  6825:                     }
                   6826:                 }
                   6827:             }
                   6828:         }
                   6829:         if ($defquota eq '') {
1.711     raeburn  6830:             if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   6831:                 $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
                   6832:             } else {
                   6833:                 $defquota = $quotahash{'quotas'}{'default'};
                   6834:             }
1.536     raeburn  6835:             $settingstatus = 'default';
                   6836:         }
                   6837:     } else {
                   6838:         $settingstatus = 'default';
                   6839:         $defquota = 20;
                   6840:     }
                   6841:     if (wantarray) {
                   6842:         return ($defquota,$settingstatus);
1.472     raeburn  6843:     } else {
1.536     raeburn  6844:         return $defquota;
1.472     raeburn  6845:     }
                   6846: }
                   6847: 
1.384     raeburn  6848: sub get_secgrprole_info {
                   6849:     my ($cdom,$cnum,$needroles,$type)  = @_;
                   6850:     my %sections_count = &get_sections($cdom,$cnum);
                   6851:     my @sections =  (sort {$a <=> $b} keys(%sections_count));
                   6852:     my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
                   6853:     my @groups = sort(keys(%curr_groups));
                   6854:     my $allroles = [];
                   6855:     my $rolehash;
                   6856:     my $accesshash = {
                   6857:                      active => 'Currently has access',
                   6858:                      future => 'Will have future access',
                   6859:                      previous => 'Previously had access',
                   6860:                   };
                   6861:     if ($needroles) {
                   6862:         $rolehash = {'all' => 'all'};
1.385     albertel 6863:         my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   6864: 	if (&Apache::lonnet::error(%user_roles)) {
                   6865: 	    undef(%user_roles);
                   6866: 	}
                   6867:         foreach my $item (keys(%user_roles)) {
1.384     raeburn  6868:             my ($role)=split(/\:/,$item,2);
                   6869:             if ($role eq 'cr') { next; }
                   6870:             if ($role =~ /^cr/) {
                   6871:                 $$rolehash{$role} = (split('/',$role))[3];
                   6872:             } else {
                   6873:                 $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
                   6874:             }
                   6875:         }
                   6876:         foreach my $key (sort(keys(%{$rolehash}))) {
                   6877:             push(@{$allroles},$key);
                   6878:         }
                   6879:         push (@{$allroles},'st');
                   6880:         $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
                   6881:     }
                   6882:     return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
                   6883: }
                   6884: 
1.555     raeburn  6885: sub user_picker {
1.627     raeburn  6886:     my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555     raeburn  6887:     my $currdom = $dom;
                   6888:     my %curr_selected = (
                   6889:                         srchin => 'dom',
1.580     raeburn  6890:                         srchby => 'lastname',
1.555     raeburn  6891:                       );
                   6892:     my $srchterm;
1.625     raeburn  6893:     if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555     raeburn  6894:         if ($srch->{'srchby'} ne '') {
                   6895:             $curr_selected{'srchby'} = $srch->{'srchby'};
                   6896:         }
                   6897:         if ($srch->{'srchin'} ne '') {
                   6898:             $curr_selected{'srchin'} = $srch->{'srchin'};
                   6899:         }
                   6900:         if ($srch->{'srchtype'} ne '') {
                   6901:             $curr_selected{'srchtype'} = $srch->{'srchtype'};
                   6902:         }
                   6903:         if ($srch->{'srchdomain'} ne '') {
                   6904:             $currdom = $srch->{'srchdomain'};
                   6905:         }
                   6906:         $srchterm = $srch->{'srchterm'};
                   6907:     }
                   6908:     my %lt=&Apache::lonlocal::texthash(
1.573     raeburn  6909:                     'usr'       => 'Search criteria',
1.563     raeburn  6910:                     'doma'      => 'Domain/institution to search',
1.558     albertel 6911:                     'uname'     => 'username',
                   6912:                     'lastname'  => 'last name',
1.555     raeburn  6913:                     'lastfirst' => 'last name, first name',
1.558     albertel 6914:                     'crs'       => 'in this course',
1.576     raeburn  6915:                     'dom'       => 'in selected LON-CAPA domain', 
1.558     albertel 6916:                     'alc'       => 'all LON-CAPA',
1.573     raeburn  6917:                     'instd'     => 'in institutional directory for selected domain',
1.558     albertel 6918:                     'exact'     => 'is',
                   6919:                     'contains'  => 'contains',
1.569     raeburn  6920:                     'begins'    => 'begins with',
1.571     raeburn  6921:                     'youm'      => "You must include some text to search for.",
                   6922:                     'thte'      => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
                   6923:                     'thet'      => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
                   6924:                     'yomc'      => "You must choose a domain when using an institutional directory search.",
                   6925:                     'ymcd'      => "You must choose a domain when using a domain search.",
                   6926:                     'whus'      => "When using searching by last,first you must include a comma as separator between last name and first name.",
                   6927:                     'whse'      => "When searching by last,first you must include at least one character in the first name.",
                   6928:                      'thfo'     => "The following need to be corrected before the search can be run:",
1.555     raeburn  6929:                                        );
1.563     raeburn  6930:     my $domform = &select_dom_form($currdom,'srchdomain',1,1);
                   6931:     my $srchinsel = ' <select name="srchin">';
1.555     raeburn  6932: 
                   6933:     my @srchins = ('crs','dom','alc','instd');
                   6934: 
                   6935:     foreach my $option (@srchins) {
                   6936:         # FIXME 'alc' option unavailable until 
                   6937:         #       loncreateuser::print_user_query_page()
                   6938:         #       has been completed.
                   6939:         next if ($option eq 'alc');
                   6940:         next if ($option eq 'crs' && !$env{'request.course.id'});
1.563     raeburn  6941:         if ($curr_selected{'srchin'} eq $option) {
                   6942:             $srchinsel .= ' 
                   6943:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   6944:         } else {
                   6945:             $srchinsel .= '
                   6946:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   6947:         }
1.555     raeburn  6948:     }
1.563     raeburn  6949:     $srchinsel .= "\n  </select>\n";
1.555     raeburn  6950: 
                   6951:     my $srchbysel =  ' <select name="srchby">';
1.580     raeburn  6952:     foreach my $option ('lastname','lastfirst','uname') {
1.555     raeburn  6953:         if ($curr_selected{'srchby'} eq $option) {
                   6954:             $srchbysel .= '
                   6955:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   6956:         } else {
                   6957:             $srchbysel .= '
                   6958:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   6959:          }
                   6960:     }
                   6961:     $srchbysel .= "\n  </select>\n";
                   6962: 
                   6963:     my $srchtypesel = ' <select name="srchtype">';
1.580     raeburn  6964:     foreach my $option ('begins','contains','exact') {
1.555     raeburn  6965:         if ($curr_selected{'srchtype'} eq $option) {
                   6966:             $srchtypesel .= '
                   6967:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   6968:         } else {
                   6969:             $srchtypesel .= '
                   6970:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   6971:         }
                   6972:     }
                   6973:     $srchtypesel .= "\n  </select>\n";
                   6974: 
1.558     albertel 6975:     my ($newuserscript,$new_user_create);
1.556     raeburn  6976: 
                   6977:     if ($forcenewuser) {
1.576     raeburn  6978:         if (ref($srch) eq 'HASH') {
                   6979:             if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627     raeburn  6980:                 if ($cancreate) {
                   6981:                     $new_user_create = '<p> <input type="submit" name="forcenew" value="'.&HTML::Entities::encode(&mt('Make new user "[_1]"',$srchterm),'<>&"').'" onclick="javascript:setSearch(\'1\','.$caller.');" /> </p>';
                   6982:                 } else {
                   6983:                     my $helplink = ' href="javascript:helpMenu('."'display'".')"';
                   6984:                     my %usertypetext = (
                   6985:                         official   => 'institutional',
                   6986:                         unofficial => 'non-institutional',
                   6987:                     );
                   6988:                     $new_user_create = '<br /><span class="LC_warning">'.&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.").' '.&mt('Contact the <a[_1]>helpdesk</a> for assistance.',$helplink).'</span><br /><br />';
                   6989:                 }
1.576     raeburn  6990:             }
                   6991:         }
                   6992: 
1.556     raeburn  6993:         $newuserscript = <<"ENDSCRIPT";
                   6994: 
1.570     raeburn  6995: function setSearch(createnew,callingForm) {
1.556     raeburn  6996:     if (createnew == 1) {
1.570     raeburn  6997:         for (var i=0; i<callingForm.srchby.length; i++) {
                   6998:             if (callingForm.srchby.options[i].value == 'uname') {
                   6999:                 callingForm.srchby.selectedIndex = i;
1.556     raeburn  7000:             }
                   7001:         }
1.570     raeburn  7002:         for (var i=0; i<callingForm.srchin.length; i++) {
                   7003:             if ( callingForm.srchin.options[i].value == 'dom') {
                   7004: 		callingForm.srchin.selectedIndex = i;
1.556     raeburn  7005:             }
                   7006:         }
1.570     raeburn  7007:         for (var i=0; i<callingForm.srchtype.length; i++) {
                   7008:             if (callingForm.srchtype.options[i].value == 'exact') {
                   7009:                 callingForm.srchtype.selectedIndex = i;
1.556     raeburn  7010:             }
                   7011:         }
1.570     raeburn  7012:         for (var i=0; i<callingForm.srchdomain.length; i++) {
                   7013:             if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
                   7014:                 callingForm.srchdomain.selectedIndex = i;
1.556     raeburn  7015:             }
                   7016:         }
                   7017:     }
                   7018: }
                   7019: ENDSCRIPT
1.558     albertel 7020: 
1.556     raeburn  7021:     }
                   7022: 
1.555     raeburn  7023:     my $output = <<"END_BLOCK";
1.556     raeburn  7024: <script type="text/javascript">
1.570     raeburn  7025: function validateEntry(callingForm) {
1.558     albertel 7026: 
1.556     raeburn  7027:     var checkok = 1;
1.558     albertel 7028:     var srchin;
1.570     raeburn  7029:     for (var i=0; i<callingForm.srchin.length; i++) {
                   7030: 	if ( callingForm.srchin[i].checked ) {
                   7031: 	    srchin = callingForm.srchin[i].value;
1.558     albertel 7032: 	}
                   7033:     }
                   7034: 
1.570     raeburn  7035:     var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
                   7036:     var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
                   7037:     var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
                   7038:     var srchterm =  callingForm.srchterm.value;
                   7039:     var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556     raeburn  7040:     var msg = "";
                   7041: 
                   7042:     if (srchterm == "") {
                   7043:         checkok = 0;
1.571     raeburn  7044:         msg += "$lt{'youm'}\\n";
1.556     raeburn  7045:     }
                   7046: 
1.569     raeburn  7047:     if (srchtype== 'begins') {
                   7048:         if (srchterm.length < 2) {
                   7049:             checkok = 0;
1.571     raeburn  7050:             msg += "$lt{'thte'}\\n";
1.569     raeburn  7051:         }
                   7052:     }
                   7053: 
1.556     raeburn  7054:     if (srchtype== 'contains') {
                   7055:         if (srchterm.length < 3) {
                   7056:             checkok = 0;
1.571     raeburn  7057:             msg += "$lt{'thet'}\\n";
1.556     raeburn  7058:         }
                   7059:     }
                   7060:     if (srchin == 'instd') {
                   7061:         if (srchdomain == '') {
                   7062:             checkok = 0;
1.571     raeburn  7063:             msg += "$lt{'yomc'}\\n";
1.556     raeburn  7064:         }
                   7065:     }
                   7066:     if (srchin == 'dom') {
                   7067:         if (srchdomain == '') {
                   7068:             checkok = 0;
1.571     raeburn  7069:             msg += "$lt{'ymcd'}\\n";
1.556     raeburn  7070:         }
                   7071:     }
                   7072:     if (srchby == 'lastfirst') {
                   7073:         if (srchterm.indexOf(",") == -1) {
                   7074:             checkok = 0;
1.571     raeburn  7075:             msg += "$lt{'whus'}\\n";
1.556     raeburn  7076:         }
                   7077:         if (srchterm.indexOf(",") == srchterm.length -1) {
                   7078:             checkok = 0;
1.571     raeburn  7079:             msg += "$lt{'whse'}\\n";
1.556     raeburn  7080:         }
                   7081:     }
                   7082:     if (checkok == 0) {
1.571     raeburn  7083:         alert("$lt{'thfo'}\\n"+msg);
1.556     raeburn  7084:         return;
                   7085:     }
                   7086:     if (checkok == 1) {
1.570     raeburn  7087:         callingForm.submit();
1.556     raeburn  7088:     }
                   7089: }
                   7090: 
                   7091: $newuserscript
                   7092: 
                   7093: </script>
1.558     albertel 7094: 
                   7095: $new_user_create
                   7096: 
1.555     raeburn  7097: <table>
1.558     albertel 7098:  <tr>
1.573     raeburn  7099:   <td>$lt{'doma'}:</td>
                   7100:   <td>$domform</td>
                   7101:   </td>
                   7102:  </tr>
                   7103:  <tr>
                   7104:   <td>$lt{'usr'}:</td>
1.563     raeburn  7105:   <td>$srchbysel
                   7106:       $srchtypesel 
                   7107:       <input type="text" size="15" name="srchterm" value="$srchterm" />
1.564     albertel 7108:       $srchinsel 
1.563     raeburn  7109:   </td>
                   7110:  </tr>
1.555     raeburn  7111: </table>
                   7112: <br />
                   7113: END_BLOCK
1.558     albertel 7114: 
1.555     raeburn  7115:     return $output;
                   7116: }
                   7117: 
1.612     raeburn  7118: sub user_rule_check {
1.615     raeburn  7119:     my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612     raeburn  7120:     my $response;
                   7121:     if (ref($usershash) eq 'HASH') {
                   7122:         foreach my $user (keys(%{$usershash})) {
                   7123:             my ($uname,$udom) = split(/:/,$user);
                   7124:             next if ($udom eq '' || $uname eq '');
1.615     raeburn  7125:             my ($id,$newuser);
1.612     raeburn  7126:             if (ref($usershash->{$user}) eq 'HASH') {
1.615     raeburn  7127:                 $newuser = $usershash->{$user}->{'newuser'};
1.612     raeburn  7128:                 $id = $usershash->{$user}->{'id'};
                   7129:             }
                   7130:             my $inst_response;
                   7131:             if (ref($checks) eq 'HASH') {
                   7132:                 if (defined($checks->{'username'})) {
1.615     raeburn  7133:                     ($inst_response,%{$inst_results->{$user}}) = 
1.612     raeburn  7134:                         &Apache::lonnet::get_instuser($udom,$uname);
                   7135:                 } elsif (defined($checks->{'id'})) {
1.615     raeburn  7136:                     ($inst_response,%{$inst_results->{$user}}) =
1.612     raeburn  7137:                         &Apache::lonnet::get_instuser($udom,undef,$id);
                   7138:                 }
1.615     raeburn  7139:             } else {
                   7140:                 ($inst_response,%{$inst_results->{$user}}) =
                   7141:                     &Apache::lonnet::get_instuser($udom,$uname);
                   7142:                 return;
1.612     raeburn  7143:             }
1.615     raeburn  7144:             if (!$got_rules->{$udom}) {
1.612     raeburn  7145:                 my %domconfig = &Apache::lonnet::get_dom('configuration',
                   7146:                                                   ['usercreation'],$udom);
                   7147:                 if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615     raeburn  7148:                     foreach my $item ('username','id') {
1.612     raeburn  7149:                         if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
                   7150:                             $$curr_rules{$udom}{$item} = 
                   7151:                                 $domconfig{'usercreation'}{$item.'_rule'};
1.585     raeburn  7152:                         }
                   7153:                     }
                   7154:                 }
1.615     raeburn  7155:                 $got_rules->{$udom} = 1;  
1.585     raeburn  7156:             }
1.612     raeburn  7157:             foreach my $item (keys(%{$checks})) {
                   7158:                 if (ref($$curr_rules{$udom}) eq 'HASH') {
                   7159:                     if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
                   7160:                         if (@{$$curr_rules{$udom}{$item}} > 0) {
                   7161:                             my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
                   7162:                             foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
                   7163:                                 if ($rule_check{$rule}) {
                   7164:                                     $$rulematch{$user}{$item} = $rule;
                   7165:                                     if ($inst_response eq 'ok') {
1.615     raeburn  7166:                                         if (ref($inst_results) eq 'HASH') {
                   7167:                                             if (ref($inst_results->{$user}) eq 'HASH') {
                   7168:                                                 if (keys(%{$inst_results->{$user}}) == 0) {
                   7169:                                                     $$alerts{$item}{$udom}{$uname} = 1;
                   7170:                                                 }
1.612     raeburn  7171:                                             }
                   7172:                                         }
1.615     raeburn  7173:                                     }
                   7174:                                     last;
1.585     raeburn  7175:                                 }
                   7176:                             }
                   7177:                         }
                   7178:                     }
                   7179:                 }
                   7180:             }
                   7181:         }
                   7182:     }
1.612     raeburn  7183:     return;
                   7184: }
                   7185: 
                   7186: sub user_rule_formats {
                   7187:     my ($domain,$domdesc,$curr_rules,$check) = @_;
                   7188:     my %text = ( 
                   7189:                  'username' => 'Usernames',
                   7190:                  'id'       => 'IDs',
                   7191:                );
                   7192:     my $output;
                   7193:     my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
                   7194:     if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
                   7195:         if (@{$ruleorder} > 0) {
                   7196:             $output = '<br />'.&mt("$text{$check} with the following format(s) may <span class=\"LC_cusr_emph\">only</span> be used for verified users at [_1]:",$domdesc).' <ul>';
                   7197:             foreach my $rule (@{$ruleorder}) {
                   7198:                 if (ref($curr_rules) eq 'ARRAY') {
                   7199:                     if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
                   7200:                         if (ref($rules->{$rule}) eq 'HASH') {
                   7201:                             $output .= '<li>'.$rules->{$rule}{'name'}.': '.
                   7202:                                         $rules->{$rule}{'desc'}.'</li>';
                   7203:                         }
                   7204:                     }
                   7205:                 }
                   7206:             }
                   7207:             $output .= '</ul>';
                   7208:         }
                   7209:     }
                   7210:     return $output;
                   7211: }
                   7212: 
                   7213: sub instrule_disallow_msg {
1.615     raeburn  7214:     my ($checkitem,$domdesc,$count,$mode) = @_;
1.612     raeburn  7215:     my $response;
                   7216:     my %text = (
                   7217:                   item   => 'username',
                   7218:                   items  => 'usernames',
                   7219:                   match  => 'matches',
                   7220:                   do     => 'does',
                   7221:                   action => 'a username',
                   7222:                   one    => 'one',
                   7223:                );
                   7224:     if ($count > 1) {
                   7225:         $text{'item'} = 'usernames';
                   7226:         $text{'match'} ='match';
                   7227:         $text{'do'} = 'do';
                   7228:         $text{'action'} = 'usernames',
                   7229:         $text{'one'} = 'ones';
                   7230:     }
                   7231:     if ($checkitem eq 'id') {
                   7232:         $text{'items'} = 'IDs';
                   7233:         $text{'item'} = 'ID';
                   7234:         $text{'action'} = 'an ID';
1.615     raeburn  7235:         if ($count > 1) {
                   7236:             $text{'item'} = 'IDs';
                   7237:             $text{'action'} = 'IDs';
                   7238:         }
1.612     raeburn  7239:     }
1.674     bisitz   7240:     $response = &mt("The $text{'item'} you chose $text{'match'} the format of $text{'items'} defined for [_1], but the $text{'item'} $text{'do'} not exist in the institutional directory.",'<span class="LC_cusr_emph">'.$domdesc.'</span>').'<br />';
1.615     raeburn  7241:     if ($mode eq 'upload') {
                   7242:         if ($checkitem eq 'username') {
                   7243:             $response .= &mt("You will need to modify your upload file so it will include $text{'action'} with a different format --  $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
                   7244:         } elsif ($checkitem eq 'id') {
1.674     bisitz   7245:             $response .= &mt("Either upload a file which includes $text{'action'} with a different format --  $text{'one'} that will not conflict with 'official' institutional $text{'items'}, or when associating fields with data columns, omit an association for the Student/Employee ID field.");
1.615     raeburn  7246:         }
1.669     raeburn  7247:     } elsif ($mode eq 'selfcreate') {
                   7248:         if ($checkitem eq 'id') {
                   7249:             $response .= &mt("You must either choose $text{'action'} with a different format --  $text{'one'} that will not conflict with 'official' institutional $text{'items'}, or leave the ID field blank.");
                   7250:         }
1.615     raeburn  7251:     } else {
                   7252:         if ($checkitem eq 'username') {
                   7253:             $response .= &mt("You must choose $text{'action'} with a different format --  $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
                   7254:         } elsif ($checkitem eq 'id') {
                   7255:             $response .= &mt("You must either choose $text{'action'} with a different format --  $text{'one'} that will not conflict with 'official' institutional $text{'items'}, or leave the ID field blank.");
                   7256:         }
1.612     raeburn  7257:     }
                   7258:     return $response;
1.585     raeburn  7259: }
                   7260: 
1.624     raeburn  7261: sub personal_data_fieldtitles {
                   7262:     my %fieldtitles = &Apache::lonlocal::texthash (
                   7263:                         id => 'Student/Employee ID',
                   7264:                         permanentemail => 'E-mail address',
                   7265:                         lastname => 'Last Name',
                   7266:                         firstname => 'First Name',
                   7267:                         middlename => 'Middle Name',
                   7268:                         generation => 'Generation',
                   7269:                         gen => 'Generation',
                   7270:                    );
                   7271:     return %fieldtitles;
                   7272: }
                   7273: 
1.642     raeburn  7274: sub sorted_inst_types {
                   7275:     my ($dom) = @_;
                   7276:     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
                   7277:     my $othertitle = &mt('All users');
                   7278:     if ($env{'request.course.id'}) {
1.668     raeburn  7279:         $othertitle  = &mt('Any users');
1.642     raeburn  7280:     }
                   7281:     my @types;
                   7282:     if (ref($order) eq 'ARRAY') {
                   7283:         @types = @{$order};
                   7284:     }
                   7285:     if (@types == 0) {
                   7286:         if (ref($usertypes) eq 'HASH') {
                   7287:             @types = sort(keys(%{$usertypes}));
                   7288:         }
                   7289:     }
                   7290:     if (keys(%{$usertypes}) > 0) {
                   7291:         $othertitle = &mt('Other users');
                   7292:     }
                   7293:     return ($othertitle,$usertypes,\@types);
                   7294: }
                   7295: 
1.645     raeburn  7296: sub get_institutional_codes {
                   7297:     my ($settings,$allcourses,$LC_code) = @_;
                   7298: # Get complete list of course sections to update
                   7299:     my @currsections = ();
                   7300:     my @currxlists = ();
                   7301:     my $coursecode = $$settings{'internal.coursecode'};
                   7302: 
                   7303:     if ($$settings{'internal.sectionnums'} ne '') {
                   7304:         @currsections = split(/,/,$$settings{'internal.sectionnums'});
                   7305:     }
                   7306: 
                   7307:     if ($$settings{'internal.crosslistings'} ne '') {
                   7308:         @currxlists = split(/,/,$$settings{'internal.crosslistings'});
                   7309:     }
                   7310: 
                   7311:     if (@currxlists > 0) {
                   7312:         foreach (@currxlists) {
                   7313:             if (m/^([^:]+):(\w*)$/) {
                   7314:                 unless (grep/^$1$/,@{$allcourses}) {
                   7315:                     push @{$allcourses},$1;
                   7316:                     $$LC_code{$1} = $2;
                   7317:                 }
                   7318:             }
                   7319:         }
                   7320:     }
                   7321:  
                   7322:     if (@currsections > 0) {
                   7323:         foreach (@currsections) {
                   7324:             if (m/^(\w+):(\w*)$/) {
                   7325:                 my $sec = $coursecode.$1;
                   7326:                 my $lc_sec = $2;
                   7327:                 unless (grep/^$sec$/,@{$allcourses}) {
                   7328:                     push @{$allcourses},$sec;
                   7329:                     $$LC_code{$sec} = $lc_sec;
                   7330:                 }
                   7331:             }
                   7332:         }
                   7333:     }
                   7334:     return;
                   7335: }
                   7336: 
1.112     bowersj2 7337: =pod
                   7338: 
1.549     albertel 7339: =back
                   7340: 
                   7341: =head1 HTTP Helpers
                   7342: 
                   7343: =over 4
                   7344: 
1.648     raeburn  7345: =item * &get_unprocessed_cgi($query,$possible_names)
1.112     bowersj2 7346: 
1.258     albertel 7347: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112     bowersj2 7348: $query.  The parameters listed in $possible_names (an array reference),
1.258     albertel 7349: will be set in $env{'form.name'} if they do not already exist.
1.112     bowersj2 7350: 
                   7351: Typically called with $ENV{'QUERY_STRING'} as the first parameter.  
                   7352: $possible_names is an ref to an array of form element names.  As an example:
                   7353: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258     albertel 7354: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112     bowersj2 7355: 
                   7356: =cut
1.1       albertel 7357: 
1.6       albertel 7358: sub get_unprocessed_cgi {
1.25      albertel 7359:   my ($query,$possible_names)= @_;
1.26      matthew  7360:   # $Apache::lonxml::debug=1;
1.356     albertel 7361:   foreach my $pair (split(/&/,$query)) {
                   7362:     my ($name, $value) = split(/=/,$pair);
1.369     www      7363:     $name = &unescape($name);
1.25      albertel 7364:     if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
                   7365:       $value =~ tr/+/ /;
                   7366:       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258     albertel 7367:       unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25      albertel 7368:     }
1.16      harris41 7369:   }
1.6       albertel 7370: }
                   7371: 
1.112     bowersj2 7372: =pod
                   7373: 
1.648     raeburn  7374: =item * &cacheheader() 
1.112     bowersj2 7375: 
                   7376: returns cache-controlling header code
                   7377: 
                   7378: =cut
                   7379: 
1.7       albertel 7380: sub cacheheader {
1.258     albertel 7381:     unless ($env{'request.method'} eq 'GET') { return ''; }
1.216     albertel 7382:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
                   7383:     my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7       albertel 7384:                 <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
                   7385:                 <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216     albertel 7386:     return $output;
1.7       albertel 7387: }
                   7388: 
1.112     bowersj2 7389: =pod
                   7390: 
1.648     raeburn  7391: =item * &no_cache($r) 
1.112     bowersj2 7392: 
                   7393: specifies header code to not have cache
                   7394: 
                   7395: =cut
                   7396: 
1.9       albertel 7397: sub no_cache {
1.216     albertel 7398:     my ($r) = @_;
                   7399:     if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258     albertel 7400: 	$env{'request.method'} ne 'GET') { return ''; }
1.216     albertel 7401:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
                   7402:     $r->no_cache(1);
                   7403:     $r->header_out("Expires" => $date);
                   7404:     $r->header_out("Pragma" => "no-cache");
1.123     www      7405: }
                   7406: 
                   7407: sub content_type {
1.181     albertel 7408:     my ($r,$type,$charset) = @_;
1.299     foxr     7409:     if ($r) {
                   7410: 	#  Note that printout.pl calls this with undef for $r.
                   7411: 	&no_cache($r);
                   7412:     }
1.258     albertel 7413:     if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181     albertel 7414:     unless ($charset) {
                   7415: 	$charset=&Apache::lonlocal::current_encoding;
                   7416:     }
                   7417:     if ($charset) { $type.='; charset='.$charset; }
                   7418:     if ($r) {
                   7419: 	$r->content_type($type);
                   7420:     } else {
                   7421: 	print("Content-type: $type\n\n");
                   7422:     }
1.9       albertel 7423: }
1.25      albertel 7424: 
1.112     bowersj2 7425: =pod
                   7426: 
1.648     raeburn  7427: =item * &add_to_env($name,$value) 
1.112     bowersj2 7428: 
1.258     albertel 7429: adds $name to the %env hash with value
1.112     bowersj2 7430: $value, if $name already exists, the entry is converted to an array
                   7431: reference and $value is added to the array.
                   7432: 
                   7433: =cut
                   7434: 
1.25      albertel 7435: sub add_to_env {
                   7436:   my ($name,$value)=@_;
1.258     albertel 7437:   if (defined($env{$name})) {
                   7438:     if (ref($env{$name})) {
1.25      albertel 7439:       #already have multiple values
1.258     albertel 7440:       push(@{ $env{$name} },$value);
1.25      albertel 7441:     } else {
                   7442:       #first time seeing multiple values, convert hash entry to an arrayref
1.258     albertel 7443:       my $first=$env{$name};
                   7444:       undef($env{$name});
                   7445:       push(@{ $env{$name} },$first,$value);
1.25      albertel 7446:     }
                   7447:   } else {
1.258     albertel 7448:     $env{$name}=$value;
1.25      albertel 7449:   }
1.31      albertel 7450: }
1.149     albertel 7451: 
                   7452: =pod
                   7453: 
1.648     raeburn  7454: =item * &get_env_multiple($name) 
1.149     albertel 7455: 
1.258     albertel 7456: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149     albertel 7457: values may be defined and end up as an array ref.
                   7458: 
                   7459: returns an array of values
                   7460: 
                   7461: =cut
                   7462: 
                   7463: sub get_env_multiple {
                   7464:     my ($name) = @_;
                   7465:     my @values;
1.258     albertel 7466:     if (defined($env{$name})) {
1.149     albertel 7467:         # exists is it an array
1.258     albertel 7468:         if (ref($env{$name})) {
                   7469:             @values=@{ $env{$name} };
1.149     albertel 7470:         } else {
1.258     albertel 7471:             $values[0]=$env{$name};
1.149     albertel 7472:         }
                   7473:     }
                   7474:     return(@values);
                   7475: }
                   7476: 
1.660     raeburn  7477: sub ask_for_embedded_content {
                   7478:     my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
                   7479:     my $upload_output = '
                   7480:    <form name="upload_embedded" action="'.$actionurl.'"
                   7481:                   method="post" enctype="multipart/form-data">';
                   7482:     $upload_output .= $state;
1.661     raeburn  7483:     $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660     raeburn  7484: 
                   7485:     my $num = 0;
                   7486:     foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
                   7487:         $upload_output .= &start_data_table_row().
                   7488:             '<td>'.$embed_file.'</td><td>';
                   7489:         if ($args->{'ignore_remote_references'}
                   7490:             && $embed_file =~ m{^\w+://}) {
                   7491:             $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
                   7492:         } elsif ($args->{'error_on_invalid_names'}
                   7493:             && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
                   7494: 
                   7495:             $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
                   7496: 
                   7497:         } else {
                   7498:             $upload_output .='
1.661     raeburn  7499:            <input name="embedded_item_'.$num.'" type="file" value="" />
1.660     raeburn  7500:            <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
                   7501:             my $attrib = join(':',@{$$allfiles{$embed_file}});
                   7502:             $upload_output .=
                   7503:                 "\n\t\t".
                   7504:                 '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
                   7505:                 $attrib.'" />';
                   7506:             if (exists($$codebase{$embed_file})) {
                   7507:                 $upload_output .=
                   7508:                     "\n\t\t".
                   7509:                     '<input name="codebase_'.$num.'" type="hidden" value="'.
                   7510:                     &escape($$codebase{$embed_file}).'" />';
                   7511:             }
                   7512:         }
                   7513:         $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
                   7514:         $num++;
                   7515:     }
                   7516:     $upload_output .= &Apache::loncommon::end_data_table().'<br />
                   7517:    <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
                   7518:    <input type ="submit" value="'.&mt('Upload Listed Files').'" />
                   7519:    '.&mt('(only files for which a location has been provided will be uploaded)').'
                   7520:    </form>';
                   7521:     return $upload_output;
                   7522: }
                   7523: 
1.661     raeburn  7524: sub upload_embedded {
                   7525:     my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
                   7526:         $current_disk_usage) = @_;
                   7527:     my $output;
                   7528:     for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
                   7529:         next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
                   7530:         my $orig_uploaded_filename =
                   7531:             $env{'form.embedded_item_'.$i.'.filename'};
                   7532: 
                   7533:         $env{'form.embedded_orig_'.$i} =
                   7534:             &unescape($env{'form.embedded_orig_'.$i});
                   7535:         my ($path,$fname) =
                   7536:             ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
                   7537:         # no path, whole string is fname
                   7538:         if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
                   7539: 
                   7540:         $path = $env{'form.currentpath'}.$path;
                   7541:         $fname = &Apache::lonnet::clean_filename($fname);
                   7542:         # See if there is anything left
                   7543:         next if ($fname eq '');
                   7544: 
                   7545:         # Check if file already exists as a file or directory.
                   7546:         my ($state,$msg);
                   7547:         if ($context eq 'portfolio') {
                   7548:             my $port_path = $dirpath;
                   7549:             if ($group ne '') {
                   7550:                 $port_path = "groups/$group/$port_path";
                   7551:             }
                   7552:             ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
                   7553:                                               $dir_root,$port_path,$disk_quota,
                   7554:                                               $current_disk_usage,$uname,$udom);
                   7555:             if ($state eq 'will_exceed_quota'
                   7556:                 || $state eq 'file_locked'
                   7557:                 || $state eq 'file_exists' ) {
                   7558:                 $output .= $msg;
                   7559:                 next;
                   7560:             }
                   7561:         } elsif (($context eq 'author') || ($context eq 'testbank')) {
                   7562:             ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
                   7563:             if ($state eq 'exists') {
                   7564:                 $output .= $msg;
                   7565:                 next;
                   7566:             }
                   7567:         }
                   7568:         # Check if extension is valid
                   7569:         if (($fname =~ /\.(\w+)$/) &&
                   7570:             (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   7571:             $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
                   7572:             next;
                   7573:         } elsif (($fname =~ /\.(\w+)$/) &&
                   7574:                  (!defined(&Apache::loncommon::fileembstyle($1)))) {
                   7575:             $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   7576:             next;
                   7577:         } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
                   7578:             $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
                   7579:             next;
                   7580:         }
                   7581: 
                   7582:         $env{'form.embedded_item_'.$i.'.filename'}=$fname;
                   7583:         if ($context eq 'portfolio') {
                   7584:             my $result=
                   7585:                 &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
                   7586:                                                 $dirpath.$path);
                   7587:             if ($result !~ m|^/uploaded/|) {
                   7588:                 $output .= '<span class="LC_error">'
                   7589:                       .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
                   7590:                            ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
                   7591:                       .'</span><br />';
                   7592:                 next;
                   7593:             } else {
                   7594:                 $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
                   7595:                            $path.$fname.'</span>').'</p>';     
                   7596:             }
                   7597:         } else {
                   7598: # Save the file
                   7599:             my $target = $env{'form.embedded_item_'.$i};
                   7600:             my $fullpath = $dir_root.$dirpath.'/'.$path;
                   7601:             my $dest = $fullpath.$fname;
                   7602:             my $url = $url_root.$dirpath.'/'.$path.$fname;
                   7603:             my @parts=split(/\//,$fullpath);
                   7604:             my $count;
                   7605:             my $filepath = $dir_root;
                   7606:             for ($count=4;$count<=$#parts;$count++) {
                   7607:                 $filepath .= "/$parts[$count]";
                   7608:                 if ((-e $filepath)!=1) {
                   7609:                     mkdir($filepath,0770);
                   7610:                 }
                   7611:             }
                   7612:             my $fh;
                   7613:             if (!open($fh,'>'.$dest)) {
                   7614:                 &Apache::lonnet::logthis('Failed to create '.$dest);
                   7615:                 $output .= '<span class="LC_error">'.
                   7616:                            &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   7617:                            '</span><br />';
                   7618:             } else {
                   7619:                 if (!print $fh $env{'form.embedded_item_'.$i}) {
                   7620:                     &Apache::lonnet::logthis('Failed to write to '.$dest);
                   7621:                     $output .= '<span class="LC_error">'.
                   7622:                               &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   7623:                               '</span><br />';
                   7624:                 } else {
                   7625:                     if ($context eq 'testbank') {
                   7626:                         $output .= &mt('Embedded file uploaded successfully:').
                   7627:                                    '&nbsp;<a href="'.$url.'">'.
                   7628:                                    $orig_uploaded_filename.'</a><br />';
                   7629:                     } else {
1.705     tempelho 7630:                         $output .= '<span class=\"LC_fontsize_large\">'.
1.661     raeburn  7631:                                    &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705     tempelho 7632:                                    $orig_uploaded_filename.'</a>').'</span><br />';
1.661     raeburn  7633:                     }
                   7634:                 }
                   7635:                 close($fh);
                   7636:             }
                   7637:         }
                   7638:     }
                   7639:     return $output;
                   7640: }
                   7641: 
                   7642: sub check_for_existing {
                   7643:     my ($path,$fname,$element) = @_;
                   7644:     my ($state,$msg);
                   7645:     if (-d $path.'/'.$fname) {
                   7646:         $state = 'exists';
                   7647:         $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   7648:     } elsif (-e $path.'/'.$fname) {
                   7649:         $state = 'exists';
                   7650:         $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   7651:     }
                   7652:     if ($state eq 'exists') {
                   7653:         $msg = '<span class="LC_error">'.$msg.'</span><br />';
                   7654:     }
                   7655:     return ($state,$msg);
                   7656: }
                   7657: 
                   7658: sub check_for_upload {
                   7659:     my ($path,$fname,$group,$element,$portfolio_root,$port_path,
                   7660:         $disk_quota,$current_disk_usage,$uname,$udom) = @_;
                   7661:     my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
                   7662:     my $getpropath = 1;
                   7663:     my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
                   7664:                                             $getpropath);
                   7665:     my $found_file = 0;
                   7666:     my $locked_file = 0;
                   7667:     foreach my $line (@dir_list) {
                   7668:         my ($file_name)=split(/\&/,$line,2);
                   7669:         if ($file_name eq $fname){
                   7670:             $file_name = $path.$file_name;
                   7671:             if ($group ne '') {
                   7672:                 $file_name = $group.$file_name;
                   7673:             }
                   7674:             $found_file = 1;
                   7675:             if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
                   7676:                 $locked_file = 1;
                   7677:             }
                   7678:         }
                   7679:     }
                   7680:     if (($current_disk_usage + $filesize) > $disk_quota){
                   7681:         my $msg = '<span class="LC_error">'.
                   7682:                 &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
                   7683:                   '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
                   7684:         return ('will_exceed_quota',$msg);
                   7685:     } elsif ($found_file) {
                   7686:         if ($locked_file) {
                   7687:             my $msg = '<span class="LC_error">';
                   7688:             $msg .= &mt('Unable to upload [_1]. A locked file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>','<span class="LC_filename">'.$port_path.$env{'form.currentpath'}.'</span>');
                   7689:             $msg .= '</span><br />';
                   7690:             $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
                   7691:             return ('file_locked',$msg);
                   7692:         } else {
                   7693:             my $msg = '<span class="LC_error">';
                   7694:             $msg .= &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
                   7695:             $msg .= '</span>';
                   7696:             $msg .= '<br />';
                   7697:             $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
                   7698:             return ('file_exists',$msg);
                   7699:         }
                   7700:     }
                   7701: }
                   7702: 
1.31      albertel 7703: 
1.41      ng       7704: =pod
1.45      matthew  7705: 
1.464     albertel 7706: =back
1.41      ng       7707: 
1.112     bowersj2 7708: =head1 CSV Upload/Handling functions
1.38      albertel 7709: 
1.41      ng       7710: =over 4
                   7711: 
1.648     raeburn  7712: =item * &upfile_store($r)
1.41      ng       7713: 
                   7714: Store uploaded file, $r should be the HTTP Request object,
1.258     albertel 7715: needs $env{'form.upfile'}
1.41      ng       7716: returns $datatoken to be put into hidden field
                   7717: 
                   7718: =cut
1.31      albertel 7719: 
                   7720: sub upfile_store {
                   7721:     my $r=shift;
1.258     albertel 7722:     $env{'form.upfile'}=~s/\r/\n/gs;
                   7723:     $env{'form.upfile'}=~s/\f/\n/gs;
                   7724:     $env{'form.upfile'}=~s/\n+/\n/gs;
                   7725:     $env{'form.upfile'}=~s/\n+$//gs;
1.31      albertel 7726: 
1.258     albertel 7727:     my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
                   7728: 	'_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31      albertel 7729:     {
1.158     raeburn  7730:         my $datafile = $r->dir_config('lonDaemons').
                   7731:                            '/tmp/'.$datatoken.'.tmp';
                   7732:         if ( open(my $fh,">$datafile") ) {
1.258     albertel 7733:             print $fh $env{'form.upfile'};
1.158     raeburn  7734:             close($fh);
                   7735:         }
1.31      albertel 7736:     }
                   7737:     return $datatoken;
                   7738: }
                   7739: 
1.56      matthew  7740: =pod
                   7741: 
1.648     raeburn  7742: =item * &load_tmp_file($r)
1.41      ng       7743: 
                   7744: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258     albertel 7745: needs $env{'form.datatoken'},
                   7746: sets $env{'form.upfile'} to the contents of the file
1.41      ng       7747: 
                   7748: =cut
1.31      albertel 7749: 
                   7750: sub load_tmp_file {
                   7751:     my $r=shift;
                   7752:     my @studentdata=();
                   7753:     {
1.158     raeburn  7754:         my $studentfile = $r->dir_config('lonDaemons').
1.258     albertel 7755:                               '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158     raeburn  7756:         if ( open(my $fh,"<$studentfile") ) {
                   7757:             @studentdata=<$fh>;
                   7758:             close($fh);
                   7759:         }
1.31      albertel 7760:     }
1.258     albertel 7761:     $env{'form.upfile'}=join('',@studentdata);
1.31      albertel 7762: }
                   7763: 
1.56      matthew  7764: =pod
                   7765: 
1.648     raeburn  7766: =item * &upfile_record_sep()
1.41      ng       7767: 
                   7768: Separate uploaded file into records
                   7769: returns array of records,
1.258     albertel 7770: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41      ng       7771: 
                   7772: =cut
1.31      albertel 7773: 
                   7774: sub upfile_record_sep {
1.258     albertel 7775:     if ($env{'form.upfiletype'} eq 'xml') {
1.31      albertel 7776:     } else {
1.248     albertel 7777: 	my @records;
1.258     albertel 7778: 	foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248     albertel 7779: 	    if ($line=~/^\s*$/) { next; }
                   7780: 	    push(@records,$line);
                   7781: 	}
                   7782: 	return @records;
1.31      albertel 7783:     }
                   7784: }
                   7785: 
1.56      matthew  7786: =pod
                   7787: 
1.648     raeburn  7788: =item * &record_sep($record)
1.41      ng       7789: 
1.258     albertel 7790: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41      ng       7791: 
                   7792: =cut
                   7793: 
1.263     www      7794: sub takeleft {
                   7795:     my $index=shift;
                   7796:     return substr('0000'.$index,-4,4);
                   7797: }
                   7798: 
1.31      albertel 7799: sub record_sep {
                   7800:     my $record=shift;
                   7801:     my %components=();
1.258     albertel 7802:     if ($env{'form.upfiletype'} eq 'xml') {
                   7803:     } elsif ($env{'form.upfiletype'} eq 'space') {
1.31      albertel 7804:         my $i=0;
1.356     albertel 7805:         foreach my $field (split(/\s+/,$record)) {
1.31      albertel 7806:             $field=~s/^(\"|\')//;
                   7807:             $field=~s/(\"|\')$//;
1.263     www      7808:             $components{&takeleft($i)}=$field;
1.31      albertel 7809:             $i++;
                   7810:         }
1.258     albertel 7811:     } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31      albertel 7812:         my $i=0;
1.356     albertel 7813:         foreach my $field (split(/\t/,$record)) {
1.31      albertel 7814:             $field=~s/^(\"|\')//;
                   7815:             $field=~s/(\"|\')$//;
1.263     www      7816:             $components{&takeleft($i)}=$field;
1.31      albertel 7817:             $i++;
                   7818:         }
                   7819:     } else {
1.561     www      7820:         my $separator=',';
1.480     banghart 7821:         if ($env{'form.upfiletype'} eq 'semisv') {
1.561     www      7822:             $separator=';';
1.480     banghart 7823:         }
1.31      albertel 7824:         my $i=0;
1.561     www      7825: # the character we are looking for to indicate the end of a quote or a record 
                   7826:         my $looking_for=$separator;
                   7827: # do not add the characters to the fields
                   7828:         my $ignore=0;
                   7829: # we just encountered a separator (or the beginning of the record)
                   7830:         my $just_found_separator=1;
                   7831: # store the field we are working on here
                   7832:         my $field='';
                   7833: # work our way through all characters in record
                   7834:         foreach my $character ($record=~/(.)/g) {
                   7835:             if ($character eq $looking_for) {
                   7836:                if ($character ne $separator) {
                   7837: # Found the end of a quote, again looking for separator
                   7838:                   $looking_for=$separator;
                   7839:                   $ignore=1;
                   7840:                } else {
                   7841: # Found a separator, store away what we got
                   7842:                   $components{&takeleft($i)}=$field;
                   7843: 	          $i++;
                   7844:                   $just_found_separator=1;
                   7845:                   $ignore=0;
                   7846:                   $field='';
                   7847:                }
                   7848:                next;
                   7849:             }
                   7850: # single or double quotation marks after a separator indicate beginning of a quote
                   7851: # we are now looking for the end of the quote and need to ignore separators
                   7852:             if ((($character eq '"') || ($character eq "'")) && ($just_found_separator))  {
                   7853:                $looking_for=$character;
                   7854:                next;
                   7855:             }
                   7856: # ignore would be true after we reached the end of a quote
                   7857:             if ($ignore) { next; }
                   7858:             if (($just_found_separator) && ($character=~/\s/)) { next; }
                   7859:             $field.=$character;
                   7860:             $just_found_separator=0; 
1.31      albertel 7861:         }
1.561     www      7862: # catch the very last entry, since we never encountered the separator
                   7863:         $components{&takeleft($i)}=$field;
1.31      albertel 7864:     }
                   7865:     return %components;
                   7866: }
                   7867: 
1.144     matthew  7868: ######################################################
                   7869: ######################################################
                   7870: 
1.56      matthew  7871: =pod
                   7872: 
1.648     raeburn  7873: =item * &upfile_select_html()
1.41      ng       7874: 
1.144     matthew  7875: Return HTML code to select a file from the users machine and specify 
                   7876: the file type.
1.41      ng       7877: 
                   7878: =cut
                   7879: 
1.144     matthew  7880: ######################################################
                   7881: ######################################################
1.31      albertel 7882: sub upfile_select_html {
1.144     matthew  7883:     my %Types = (
                   7884:                  csv   => &mt('CSV (comma separated values, spreadsheet)'),
1.480     banghart 7885:                  semisv => &mt('Semicolon separated values'),
1.144     matthew  7886:                  space => &mt('Space separated'),
                   7887:                  tab   => &mt('Tabulator separated'),
                   7888: #                 xml   => &mt('HTML/XML'),
                   7889:                  );
                   7890:     my $Str = '<input type="file" name="upfile" size="50" />'.
                   7891:         '<br />Type: <select name="upfiletype">';
                   7892:     foreach my $type (sort(keys(%Types))) {
                   7893:         $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
                   7894:     }
                   7895:     $Str .= "</select>\n";
                   7896:     return $Str;
1.31      albertel 7897: }
                   7898: 
1.301     albertel 7899: sub get_samples {
                   7900:     my ($records,$toget) = @_;
                   7901:     my @samples=({});
                   7902:     my $got=0;
                   7903:     foreach my $rec (@$records) {
                   7904: 	my %temp = &record_sep($rec);
                   7905: 	if (! grep(/\S/, values(%temp))) { next; }
                   7906: 	if (%temp) {
                   7907: 	    $samples[$got]=\%temp;
                   7908: 	    $got++;
                   7909: 	    if ($got == $toget) { last; }
                   7910: 	}
                   7911:     }
                   7912:     return \@samples;
                   7913: }
                   7914: 
1.144     matthew  7915: ######################################################
                   7916: ######################################################
                   7917: 
1.56      matthew  7918: =pod
                   7919: 
1.648     raeburn  7920: =item * &csv_print_samples($r,$records)
1.41      ng       7921: 
                   7922: Prints a table of sample values from each column uploaded $r is an
                   7923: Apache Request ref, $records is an arrayref from
                   7924: &Apache::loncommon::upfile_record_sep
                   7925: 
                   7926: =cut
                   7927: 
1.144     matthew  7928: ######################################################
                   7929: ######################################################
1.31      albertel 7930: sub csv_print_samples {
                   7931:     my ($r,$records) = @_;
1.662     bisitz   7932:     my $samples = &get_samples($records,5);
1.301     albertel 7933: 
1.594     raeburn  7934:     $r->print(&mt('Samples').'<br />'.&start_data_table().
                   7935:               &start_data_table_header_row());
1.356     albertel 7936:     foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) { 
                   7937:         $r->print('<th>'.&mt('Column&nbsp;[_1]',($sample+1)).'</th>'); }
1.594     raeburn  7938:     $r->print(&end_data_table_header_row());
1.301     albertel 7939:     foreach my $hash (@$samples) {
1.594     raeburn  7940: 	$r->print(&start_data_table_row());
1.356     albertel 7941: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31      albertel 7942: 	    $r->print('<td>');
1.356     albertel 7943: 	    if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31      albertel 7944: 	    $r->print('</td>');
                   7945: 	}
1.594     raeburn  7946: 	$r->print(&end_data_table_row());
1.31      albertel 7947:     }
1.594     raeburn  7948:     $r->print(&end_data_table().'<br />'."\n");
1.31      albertel 7949: }
                   7950: 
1.144     matthew  7951: ######################################################
                   7952: ######################################################
                   7953: 
1.56      matthew  7954: =pod
                   7955: 
1.648     raeburn  7956: =item * &csv_print_select_table($r,$records,$d)
1.41      ng       7957: 
                   7958: Prints a table to create associations between values and table columns.
1.144     matthew  7959: 
1.41      ng       7960: $r is an Apache Request ref,
                   7961: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174     matthew  7962: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41      ng       7963: 
                   7964: =cut
                   7965: 
1.144     matthew  7966: ######################################################
                   7967: ######################################################
1.31      albertel 7968: sub csv_print_select_table {
                   7969:     my ($r,$records,$d) = @_;
1.301     albertel 7970:     my $i=0;
                   7971:     my $samples = &get_samples($records,1);
1.144     matthew  7972:     $r->print(&mt('Associate columns with student attributes.')."\n".
1.594     raeburn  7973: 	      &start_data_table().&start_data_table_header_row().
1.144     matthew  7974:               '<th>'.&mt('Attribute').'</th>'.
1.594     raeburn  7975:               '<th>'.&mt('Column').'</th>'.
                   7976:               &end_data_table_header_row()."\n");
1.356     albertel 7977:     foreach my $array_ref (@$d) {
                   7978: 	my ($value,$display,$defaultcol)=@{ $array_ref };
1.705     tempelho 7979: 	$r->print(&start_data_table_row().'<tr><td>'.$display.'</td>');
1.31      albertel 7980: 
                   7981: 	$r->print('<td><select name=f'.$i.
1.32      matthew  7982: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.31      albertel 7983: 	$r->print('<option value="none"></option>');
1.356     albertel 7984: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
                   7985: 	    $r->print('<option value="'.$sample.'"'.
                   7986:                       ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662     bisitz   7987:                       '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31      albertel 7988: 	}
1.594     raeburn  7989: 	$r->print('</select></td>'.&end_data_table_row()."\n");
1.31      albertel 7990: 	$i++;
                   7991:     }
1.594     raeburn  7992:     $r->print(&end_data_table());
1.31      albertel 7993:     $i--;
                   7994:     return $i;
                   7995: }
1.56      matthew  7996: 
1.144     matthew  7997: ######################################################
                   7998: ######################################################
                   7999: 
1.56      matthew  8000: =pod
1.31      albertel 8001: 
1.648     raeburn  8002: =item * &csv_samples_select_table($r,$records,$d)
1.41      ng       8003: 
                   8004: Prints a table of sample values from the upload and can make associate samples to internal names.
                   8005: 
                   8006: $r is an Apache Request ref,
                   8007: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
                   8008: $d is an array of 2 element arrays (internal name, displayed name)
                   8009: 
                   8010: =cut
                   8011: 
1.144     matthew  8012: ######################################################
                   8013: ######################################################
1.31      albertel 8014: sub csv_samples_select_table {
                   8015:     my ($r,$records,$d) = @_;
                   8016:     my $i=0;
1.144     matthew  8017:     #
1.662     bisitz   8018:     my $max_samples = 5;
                   8019:     my $samples = &get_samples($records,$max_samples);
1.594     raeburn  8020:     $r->print(&start_data_table().
                   8021:               &start_data_table_header_row().'<th>'.
                   8022:               &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
                   8023:               &end_data_table_header_row());
1.301     albertel 8024: 
                   8025:     foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594     raeburn  8026: 	$r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32      matthew  8027: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.301     albertel 8028: 	foreach my $option (@$d) {
                   8029: 	    my ($value,$display,$defaultcol)=@{ $option };
1.174     matthew  8030: 	    $r->print('<option value="'.$value.'"'.
1.253     albertel 8031:                       ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174     matthew  8032:                       $display.'</option>');
1.31      albertel 8033: 	}
                   8034: 	$r->print('</select></td><td>');
1.662     bisitz   8035: 	foreach my $line (0..($max_samples-1)) {
1.301     albertel 8036: 	    if (defined($samples->[$line]{$key})) { 
                   8037: 		$r->print($samples->[$line]{$key}."<br />\n"); 
                   8038: 	    }
                   8039: 	}
1.594     raeburn  8040: 	$r->print('</td>'.&end_data_table_row());
1.31      albertel 8041: 	$i++;
                   8042:     }
1.594     raeburn  8043:     $r->print(&end_data_table());
1.31      albertel 8044:     $i--;
                   8045:     return($i);
1.115     matthew  8046: }
                   8047: 
1.144     matthew  8048: ######################################################
                   8049: ######################################################
                   8050: 
1.115     matthew  8051: =pod
                   8052: 
1.648     raeburn  8053: =item * &clean_excel_name($name)
1.115     matthew  8054: 
                   8055: Returns a replacement for $name which does not contain any illegal characters.
                   8056: 
                   8057: =cut
                   8058: 
1.144     matthew  8059: ######################################################
                   8060: ######################################################
1.115     matthew  8061: sub clean_excel_name {
                   8062:     my ($name) = @_;
                   8063:     $name =~ s/[:\*\?\/\\]//g;
                   8064:     if (length($name) > 31) {
                   8065:         $name = substr($name,0,31);
                   8066:     }
                   8067:     return $name;
1.25      albertel 8068: }
1.84      albertel 8069: 
1.85      albertel 8070: =pod
                   8071: 
1.648     raeburn  8072: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85      albertel 8073: 
                   8074: Returns either 1 or undef
                   8075: 
                   8076: 1 if the part is to be hidden, undef if it is to be shown
                   8077: 
                   8078: Arguments are:
                   8079: 
                   8080: $id the id of the part to be checked
                   8081: $symb, optional the symb of the resource to check
                   8082: $udom, optional the domain of the user to check for
                   8083: $uname, optional the username of the user to check for
                   8084: 
                   8085: =cut
1.84      albertel 8086: 
                   8087: sub check_if_partid_hidden {
                   8088:     my ($id,$symb,$udom,$uname) = @_;
1.133     albertel 8089:     my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84      albertel 8090: 					 $symb,$udom,$uname);
1.141     albertel 8091:     my $truth=1;
                   8092:     #if the string starts with !, then the list is the list to show not hide
                   8093:     if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84      albertel 8094:     my @hiddenlist=split(/,/,$hiddenparts);
                   8095:     foreach my $checkid (@hiddenlist) {
1.141     albertel 8096: 	if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84      albertel 8097:     }
1.141     albertel 8098:     return !$truth;
1.84      albertel 8099: }
1.127     matthew  8100: 
1.138     matthew  8101: 
                   8102: ############################################################
                   8103: ############################################################
                   8104: 
                   8105: =pod
                   8106: 
1.157     matthew  8107: =back 
                   8108: 
1.138     matthew  8109: =head1 cgi-bin script and graphing routines
                   8110: 
1.157     matthew  8111: =over 4
                   8112: 
1.648     raeburn  8113: =item * &get_cgi_id()
1.138     matthew  8114: 
                   8115: Inputs: none
                   8116: 
                   8117: Returns an id which can be used to pass environment variables
                   8118: to various cgi-bin scripts.  These environment variables will
                   8119: be removed from the users environment after a given time by
                   8120: the routine &Apache::lonnet::transfer_profile_to_env.
                   8121: 
                   8122: =cut
                   8123: 
                   8124: ############################################################
                   8125: ############################################################
1.152     albertel 8126: my $uniq=0;
1.136     matthew  8127: sub get_cgi_id {
1.154     albertel 8128:     $uniq=($uniq+1)%100000;
1.280     albertel 8129:     return (time.'_'.$$.'_'.$uniq);
1.136     matthew  8130: }
                   8131: 
1.127     matthew  8132: ############################################################
                   8133: ############################################################
                   8134: 
                   8135: =pod
                   8136: 
1.648     raeburn  8137: =item * &DrawBarGraph()
1.127     matthew  8138: 
1.138     matthew  8139: Facilitates the plotting of data in a (stacked) bar graph.
                   8140: Puts plot definition data into the users environment in order for 
                   8141: graph.png to plot it.  Returns an <img> tag for the plot.
                   8142: The bars on the plot are labeled '1','2',...,'n'.
                   8143: 
                   8144: Inputs:
                   8145: 
                   8146: =over 4
                   8147: 
                   8148: =item $Title: string, the title of the plot
                   8149: 
                   8150: =item $xlabel: string, text describing the X-axis of the plot
                   8151: 
                   8152: =item $ylabel: string, text describing the Y-axis of the plot
                   8153: 
                   8154: =item $Max: scalar, the maximum Y value to use in the plot
                   8155: If $Max is < any data point, the graph will not be rendered.
                   8156: 
1.140     matthew  8157: =item $colors: array ref holding the colors to be used for the data sets when
1.138     matthew  8158: they are plotted.  If undefined, default values will be used.
                   8159: 
1.178     matthew  8160: =item $labels: array ref holding the labels to use on the x-axis for the bars.
                   8161: 
1.138     matthew  8162: =item @Values: An array of array references.  Each array reference holds data
                   8163: to be plotted in a stacked bar chart.
                   8164: 
1.239     matthew  8165: =item If the final element of @Values is a hash reference the key/value
                   8166: pairs will be added to the graph definition.
                   8167: 
1.138     matthew  8168: =back
                   8169: 
                   8170: Returns:
                   8171: 
                   8172: An <img> tag which references graph.png and the appropriate identifying
                   8173: information for the plot.
                   8174: 
1.127     matthew  8175: =cut
                   8176: 
                   8177: ############################################################
                   8178: ############################################################
1.134     matthew  8179: sub DrawBarGraph {
1.178     matthew  8180:     my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134     matthew  8181:     #
                   8182:     if (! defined($colors)) {
                   8183:         $colors = ['#33ff00', 
                   8184:                   '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
                   8185:                   '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
                   8186:                   ]; 
                   8187:     }
1.228     matthew  8188:     my $extra_settings = {};
                   8189:     if (ref($Values[-1]) eq 'HASH') {
                   8190:         $extra_settings = pop(@Values);
                   8191:     }
1.127     matthew  8192:     #
1.136     matthew  8193:     my $identifier = &get_cgi_id();
                   8194:     my $id = 'cgi.'.$identifier;        
1.129     matthew  8195:     if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127     matthew  8196:         return '';
                   8197:     }
1.225     matthew  8198:     #
                   8199:     my @Labels;
                   8200:     if (defined($labels)) {
                   8201:         @Labels = @$labels;
                   8202:     } else {
                   8203:         for (my $i=0;$i<@{$Values[0]};$i++) {
                   8204:             push (@Labels,$i+1);
                   8205:         }
                   8206:     }
                   8207:     #
1.129     matthew  8208:     my $NumBars = scalar(@{$Values[0]});
1.225     matthew  8209:     if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129     matthew  8210:     my %ValuesHash;
                   8211:     my $NumSets=1;
                   8212:     foreach my $array (@Values) {
                   8213:         next if (! ref($array));
1.136     matthew  8214:         $ValuesHash{$id.'.data.'.$NumSets++} = 
1.132     matthew  8215:             join(',',@$array);
1.129     matthew  8216:     }
1.127     matthew  8217:     #
1.136     matthew  8218:     my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225     matthew  8219:     if ($NumBars < 3) {
                   8220:         $width = 120+$NumBars*32;
1.220     matthew  8221:         $xskip = 1;
1.225     matthew  8222:         $bar_width = 30;
                   8223:     } elsif ($NumBars < 5) {
                   8224:         $width = 120+$NumBars*20;
                   8225:         $xskip = 1;
                   8226:         $bar_width = 20;
1.220     matthew  8227:     } elsif ($NumBars < 10) {
1.136     matthew  8228:         $width = 120+$NumBars*15;
                   8229:         $xskip = 1;
                   8230:         $bar_width = 15;
                   8231:     } elsif ($NumBars <= 25) {
                   8232:         $width = 120+$NumBars*11;
                   8233:         $xskip = 5;
                   8234:         $bar_width = 8;
                   8235:     } elsif ($NumBars <= 50) {
                   8236:         $width = 120+$NumBars*8;
                   8237:         $xskip = 5;
                   8238:         $bar_width = 4;
                   8239:     } else {
                   8240:         $width = 120+$NumBars*8;
                   8241:         $xskip = 5;
                   8242:         $bar_width = 4;
                   8243:     }
                   8244:     #
1.137     matthew  8245:     $Max = 1 if ($Max < 1);
                   8246:     if ( int($Max) < $Max ) {
                   8247:         $Max++;
                   8248:         $Max = int($Max);
                   8249:     }
1.127     matthew  8250:     $Title  = '' if (! defined($Title));
                   8251:     $xlabel = '' if (! defined($xlabel));
                   8252:     $ylabel = '' if (! defined($ylabel));
1.369     www      8253:     $ValuesHash{$id.'.title'}    = &escape($Title);
                   8254:     $ValuesHash{$id.'.xlabel'}   = &escape($xlabel);
                   8255:     $ValuesHash{$id.'.ylabel'}   = &escape($ylabel);
1.137     matthew  8256:     $ValuesHash{$id.'.y_max_value'} = $Max;
1.136     matthew  8257:     $ValuesHash{$id.'.NumBars'}  = $NumBars;
                   8258:     $ValuesHash{$id.'.NumSets'}  = $NumSets;
                   8259:     $ValuesHash{$id.'.PlotType'} = 'bar';
                   8260:     $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   8261:     $ValuesHash{$id.'.height'}   = $height;
                   8262:     $ValuesHash{$id.'.width'}    = $width;
                   8263:     $ValuesHash{$id.'.xskip'}    = $xskip;
                   8264:     $ValuesHash{$id.'.bar_width'} = $bar_width;
                   8265:     $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127     matthew  8266:     #
1.228     matthew  8267:     # Deal with other parameters
                   8268:     while (my ($key,$value) = each(%$extra_settings)) {
                   8269:         $ValuesHash{$id.'.'.$key} = $value;
                   8270:     }
                   8271:     #
1.646     raeburn  8272:     &Apache::lonnet::appenv(\%ValuesHash);
1.137     matthew  8273:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   8274: }
                   8275: 
                   8276: ############################################################
                   8277: ############################################################
                   8278: 
                   8279: =pod
                   8280: 
1.648     raeburn  8281: =item * &DrawXYGraph()
1.137     matthew  8282: 
1.138     matthew  8283: Facilitates the plotting of data in an XY graph.
                   8284: Puts plot definition data into the users environment in order for 
                   8285: graph.png to plot it.  Returns an <img> tag for the plot.
                   8286: 
                   8287: Inputs:
                   8288: 
                   8289: =over 4
                   8290: 
                   8291: =item $Title: string, the title of the plot
                   8292: 
                   8293: =item $xlabel: string, text describing the X-axis of the plot
                   8294: 
                   8295: =item $ylabel: string, text describing the Y-axis of the plot
                   8296: 
                   8297: =item $Max: scalar, the maximum Y value to use in the plot
                   8298: If $Max is < any data point, the graph will not be rendered.
                   8299: 
                   8300: =item $colors: Array ref containing the hex color codes for the data to be 
                   8301: plotted in.  If undefined, default values will be used.
                   8302: 
                   8303: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   8304: 
                   8305: =item $Ydata: Array ref containing Array refs.  
1.185     www      8306: Each of the contained arrays will be plotted as a separate curve.
1.138     matthew  8307: 
                   8308: =item %Values: hash indicating or overriding any default values which are 
                   8309: passed to graph.png.  
                   8310: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   8311: 
                   8312: =back
                   8313: 
                   8314: Returns:
                   8315: 
                   8316: An <img> tag which references graph.png and the appropriate identifying
                   8317: information for the plot.
                   8318: 
1.137     matthew  8319: =cut
                   8320: 
                   8321: ############################################################
                   8322: ############################################################
                   8323: sub DrawXYGraph {
                   8324:     my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
                   8325:     #
                   8326:     # Create the identifier for the graph
                   8327:     my $identifier = &get_cgi_id();
                   8328:     my $id = 'cgi.'.$identifier;
                   8329:     #
                   8330:     $Title  = '' if (! defined($Title));
                   8331:     $xlabel = '' if (! defined($xlabel));
                   8332:     $ylabel = '' if (! defined($ylabel));
                   8333:     my %ValuesHash = 
                   8334:         (
1.369     www      8335:          $id.'.title'  => &escape($Title),
                   8336:          $id.'.xlabel' => &escape($xlabel),
                   8337:          $id.'.ylabel' => &escape($ylabel),
1.137     matthew  8338:          $id.'.y_max_value'=> $Max,
                   8339:          $id.'.labels'     => join(',',@$Xlabels),
                   8340:          $id.'.PlotType'   => 'XY',
                   8341:          );
                   8342:     #
                   8343:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   8344:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   8345:     }
                   8346:     #
                   8347:     if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
                   8348:         return '';
                   8349:     }
                   8350:     my $NumSets=1;
1.138     matthew  8351:     foreach my $array (@{$Ydata}){
1.137     matthew  8352:         next if (! ref($array));
                   8353:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
                   8354:     }
1.138     matthew  8355:     $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137     matthew  8356:     #
                   8357:     # Deal with other parameters
                   8358:     while (my ($key,$value) = each(%Values)) {
                   8359:         $ValuesHash{$id.'.'.$key} = $value;
1.127     matthew  8360:     }
                   8361:     #
1.646     raeburn  8362:     &Apache::lonnet::appenv(\%ValuesHash);
1.136     matthew  8363:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   8364: }
                   8365: 
                   8366: ############################################################
                   8367: ############################################################
                   8368: 
                   8369: =pod
                   8370: 
1.648     raeburn  8371: =item * &DrawXYYGraph()
1.138     matthew  8372: 
                   8373: Facilitates the plotting of data in an XY graph with two Y axes.
                   8374: Puts plot definition data into the users environment in order for 
                   8375: graph.png to plot it.  Returns an <img> tag for the plot.
                   8376: 
                   8377: Inputs:
                   8378: 
                   8379: =over 4
                   8380: 
                   8381: =item $Title: string, the title of the plot
                   8382: 
                   8383: =item $xlabel: string, text describing the X-axis of the plot
                   8384: 
                   8385: =item $ylabel: string, text describing the Y-axis of the plot
                   8386: 
                   8387: =item $colors: Array ref containing the hex color codes for the data to be 
                   8388: plotted in.  If undefined, default values will be used.
                   8389: 
                   8390: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   8391: 
                   8392: =item $Ydata1: The first data set
                   8393: 
                   8394: =item $Min1: The minimum value of the left Y-axis
                   8395: 
                   8396: =item $Max1: The maximum value of the left Y-axis
                   8397: 
                   8398: =item $Ydata2: The second data set
                   8399: 
                   8400: =item $Min2: The minimum value of the right Y-axis
                   8401: 
                   8402: =item $Max2: The maximum value of the left Y-axis
                   8403: 
                   8404: =item %Values: hash indicating or overriding any default values which are 
                   8405: passed to graph.png.  
                   8406: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   8407: 
                   8408: =back
                   8409: 
                   8410: Returns:
                   8411: 
                   8412: An <img> tag which references graph.png and the appropriate identifying
                   8413: information for the plot.
1.136     matthew  8414: 
                   8415: =cut
                   8416: 
                   8417: ############################################################
                   8418: ############################################################
1.137     matthew  8419: sub DrawXYYGraph {
                   8420:     my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
                   8421:                                         $Ydata2,$Min2,$Max2,%Values)=@_;
1.136     matthew  8422:     #
                   8423:     # Create the identifier for the graph
                   8424:     my $identifier = &get_cgi_id();
                   8425:     my $id = 'cgi.'.$identifier;
                   8426:     #
                   8427:     $Title  = '' if (! defined($Title));
                   8428:     $xlabel = '' if (! defined($xlabel));
                   8429:     $ylabel = '' if (! defined($ylabel));
                   8430:     my %ValuesHash = 
                   8431:         (
1.369     www      8432:          $id.'.title'  => &escape($Title),
                   8433:          $id.'.xlabel' => &escape($xlabel),
                   8434:          $id.'.ylabel' => &escape($ylabel),
1.136     matthew  8435:          $id.'.labels' => join(',',@$Xlabels),
                   8436:          $id.'.PlotType' => 'XY',
                   8437:          $id.'.NumSets' => 2,
1.137     matthew  8438:          $id.'.two_axes' => 1,
                   8439:          $id.'.y1_max_value' => $Max1,
                   8440:          $id.'.y1_min_value' => $Min1,
                   8441:          $id.'.y2_max_value' => $Max2,
                   8442:          $id.'.y2_min_value' => $Min2,
1.136     matthew  8443:          );
                   8444:     #
1.137     matthew  8445:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   8446:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   8447:     }
                   8448:     #
                   8449:     if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
                   8450:         ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136     matthew  8451:         return '';
                   8452:     }
                   8453:     my $NumSets=1;
1.137     matthew  8454:     foreach my $array ($Ydata1,$Ydata2){
1.136     matthew  8455:         next if (! ref($array));
                   8456:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137     matthew  8457:     }
                   8458:     #
                   8459:     # Deal with other parameters
                   8460:     while (my ($key,$value) = each(%Values)) {
                   8461:         $ValuesHash{$id.'.'.$key} = $value;
1.136     matthew  8462:     }
                   8463:     #
1.646     raeburn  8464:     &Apache::lonnet::appenv(\%ValuesHash);
1.130     albertel 8465:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139     matthew  8466: }
                   8467: 
                   8468: ############################################################
                   8469: ############################################################
                   8470: 
                   8471: =pod
                   8472: 
1.157     matthew  8473: =back 
                   8474: 
1.139     matthew  8475: =head1 Statistics helper routines?  
                   8476: 
                   8477: Bad place for them but what the hell.
                   8478: 
1.157     matthew  8479: =over 4
                   8480: 
1.648     raeburn  8481: =item * &chartlink()
1.139     matthew  8482: 
                   8483: Returns a link to the chart for a specific student.  
                   8484: 
                   8485: Inputs:
                   8486: 
                   8487: =over 4
                   8488: 
                   8489: =item $linktext: The text of the link
                   8490: 
                   8491: =item $sname: The students username
                   8492: 
                   8493: =item $sdomain: The students domain
                   8494: 
                   8495: =back
                   8496: 
1.157     matthew  8497: =back
                   8498: 
1.139     matthew  8499: =cut
                   8500: 
                   8501: ############################################################
                   8502: ############################################################
                   8503: sub chartlink {
                   8504:     my ($linktext, $sname, $sdomain) = @_;
                   8505:     my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369     www      8506:         '&amp;SelectedStudent='.&escape($sname.':'.$sdomain).
1.219     albertel 8507:         '&amp;chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139     matthew  8508:        '">'.$linktext.'</a>';
1.153     matthew  8509: }
                   8510: 
                   8511: #######################################################
                   8512: #######################################################
                   8513: 
                   8514: =pod
                   8515: 
                   8516: =head1 Course Environment Routines
1.157     matthew  8517: 
                   8518: =over 4
1.153     matthew  8519: 
1.648     raeburn  8520: =item * &restore_course_settings()
1.153     matthew  8521: 
1.648     raeburn  8522: =item * &store_course_settings()
1.153     matthew  8523: 
                   8524: Restores/Store indicated form parameters from the course environment.
                   8525: Will not overwrite existing values of the form parameters.
                   8526: 
                   8527: Inputs: 
                   8528: a scalar describing the data (e.g. 'chart', 'problem_analysis')
                   8529: 
                   8530: a hash ref describing the data to be stored.  For example:
                   8531:    
                   8532: %Save_Parameters = ('Status' => 'scalar',
                   8533:     'chartoutputmode' => 'scalar',
                   8534:     'chartoutputdata' => 'scalar',
                   8535:     'Section' => 'array',
1.373     raeburn  8536:     'Group' => 'array',
1.153     matthew  8537:     'StudentData' => 'array',
                   8538:     'Maps' => 'array');
                   8539: 
                   8540: Returns: both routines return nothing
                   8541: 
1.631     raeburn  8542: =back
                   8543: 
1.153     matthew  8544: =cut
                   8545: 
                   8546: #######################################################
                   8547: #######################################################
                   8548: sub store_course_settings {
1.496     albertel 8549:     return &store_settings($env{'request.course.id'},@_);
                   8550: }
                   8551: 
                   8552: sub store_settings {
1.153     matthew  8553:     # save to the environment
                   8554:     # appenv the same items, just to be safe
1.300     albertel 8555:     my $udom  = $env{'user.domain'};
                   8556:     my $uname = $env{'user.name'};
1.496     albertel 8557:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  8558:     my %SaveHash;
                   8559:     my %AppHash;
                   8560:     while (my ($setting,$type) = each(%$Settings)) {
1.496     albertel 8561:         my $basename = join('.','internal',$context,$prefix,$setting);
1.300     albertel 8562:         my $envname = 'environment.'.$basename;
1.258     albertel 8563:         if (exists($env{'form.'.$setting})) {
1.153     matthew  8564:             # Save this value away
                   8565:             if ($type eq 'scalar' &&
1.258     albertel 8566:                 (! exists($env{$envname}) || 
                   8567:                  $env{$envname} ne $env{'form.'.$setting})) {
                   8568:                 $SaveHash{$basename} = $env{'form.'.$setting};
                   8569:                 $AppHash{$envname}   = $env{'form.'.$setting};
1.153     matthew  8570:             } elsif ($type eq 'array') {
                   8571:                 my $stored_form;
1.258     albertel 8572:                 if (ref($env{'form.'.$setting})) {
1.153     matthew  8573:                     $stored_form = join(',',
                   8574:                                         map {
1.369     www      8575:                                             &escape($_);
1.258     albertel 8576:                                         } sort(@{$env{'form.'.$setting}}));
1.153     matthew  8577:                 } else {
                   8578:                     $stored_form = 
1.369     www      8579:                         &escape($env{'form.'.$setting});
1.153     matthew  8580:                 }
                   8581:                 # Determine if the array contents are the same.
1.258     albertel 8582:                 if ($stored_form ne $env{$envname}) {
1.153     matthew  8583:                     $SaveHash{$basename} = $stored_form;
                   8584:                     $AppHash{$envname}   = $stored_form;
                   8585:                 }
                   8586:             }
                   8587:         }
                   8588:     }
                   8589:     my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300     albertel 8590:                                           $udom,$uname);
1.153     matthew  8591:     if ($put_result !~ /^(ok|delayed)/) {
                   8592:         &Apache::lonnet::logthis('unable to save form parameters, '.
                   8593:                                  'got error:'.$put_result);
                   8594:     }
                   8595:     # Make sure these settings stick around in this session, too
1.646     raeburn  8596:     &Apache::lonnet::appenv(\%AppHash);
1.153     matthew  8597:     return;
                   8598: }
                   8599: 
                   8600: sub restore_course_settings {
1.499     albertel 8601:     return &restore_settings($env{'request.course.id'},@_);
1.496     albertel 8602: }
                   8603: 
                   8604: sub restore_settings {
                   8605:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  8606:     while (my ($setting,$type) = each(%$Settings)) {
1.258     albertel 8607:         next if (exists($env{'form.'.$setting}));
1.496     albertel 8608:         my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153     matthew  8609:             '.'.$setting;
1.258     albertel 8610:         if (exists($env{$envname})) {
1.153     matthew  8611:             if ($type eq 'scalar') {
1.258     albertel 8612:                 $env{'form.'.$setting} = $env{$envname};
1.153     matthew  8613:             } elsif ($type eq 'array') {
1.258     albertel 8614:                 $env{'form.'.$setting} = [ 
1.153     matthew  8615:                                            map { 
1.369     www      8616:                                                &unescape($_); 
1.258     albertel 8617:                                            } split(',',$env{$envname})
1.153     matthew  8618:                                            ];
                   8619:             }
                   8620:         }
                   8621:     }
1.127     matthew  8622: }
                   8623: 
1.618     raeburn  8624: #######################################################
                   8625: #######################################################
                   8626: 
                   8627: =pod
                   8628: 
                   8629: =head1 Domain E-mail Routines  
                   8630: 
                   8631: =over 4
                   8632: 
1.648     raeburn  8633: =item * &build_recipient_list()
1.618     raeburn  8634: 
                   8635: Build recipient lists for three types of e-mail:
                   8636: (a) Error Reports, (b) Package Updates, (c) Help requests, generated by
1.619     raeburn  8637: lonerrorhandler.pm, CHECKRPMS and lonsupportreq.pm respectively.
1.618     raeburn  8638: 
                   8639: Inputs:
1.619     raeburn  8640: defmail (scalar - email address of default recipient), 
1.618     raeburn  8641: mailing type (scalar - errormail, packagesmail, or helpdeskmail), 
1.619     raeburn  8642: defdom (domain for which to retrieve configuration settings),
                   8643: origmail (scalar - email address of recipient from loncapa.conf, 
                   8644: i.e., predates configuration by DC via domainprefs.pm 
1.618     raeburn  8645: 
1.655     raeburn  8646: Returns: comma separated list of addresses to which to send e-mail.
                   8647: 
                   8648: =back
1.618     raeburn  8649: 
                   8650: =cut
                   8651: 
                   8652: ############################################################
                   8653: ############################################################
                   8654: sub build_recipient_list {
1.619     raeburn  8655:     my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618     raeburn  8656:     my @recipients;
                   8657:     my $otheremails;
                   8658:     my %domconfig =
                   8659:          &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
                   8660:     if (ref($domconfig{'contacts'}) eq 'HASH') {
                   8661:         if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
                   8662:             my @contacts = ('adminemail','supportemail');
                   8663:             foreach my $item (@contacts) {
                   8664:                 if ($domconfig{'contacts'}{$mailing}{$item}) {
1.619     raeburn  8665:                     my $addr = $domconfig{'contacts'}{$item}; 
                   8666:                     if (!grep(/^\Q$addr\E$/,@recipients)) {
                   8667:                         push(@recipients,$addr);
                   8668:                     }
1.618     raeburn  8669:                 }
                   8670:                 $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
                   8671:             }
                   8672:         }
1.619     raeburn  8673:     } elsif ($origmail ne '') {
                   8674:         push(@recipients,$origmail);
1.618     raeburn  8675:     }
1.688     raeburn  8676:     if (defined($defmail)) {
                   8677:         if ($defmail ne '') {
                   8678:             push(@recipients,$defmail);
                   8679:         }
1.618     raeburn  8680:     }
                   8681:     if ($otheremails) {
1.619     raeburn  8682:         my @others;
                   8683:         if ($otheremails =~ /,/) {
                   8684:             @others = split(/,/,$otheremails);
1.618     raeburn  8685:         } else {
1.619     raeburn  8686:             push(@others,$otheremails);
                   8687:         }
                   8688:         foreach my $addr (@others) {
                   8689:             if (!grep(/^\Q$addr\E$/,@recipients)) {
                   8690:                 push(@recipients,$addr);
                   8691:             }
1.618     raeburn  8692:         }
                   8693:     }
1.619     raeburn  8694:     my $recipientlist = join(',',@recipients); 
1.618     raeburn  8695:     return $recipientlist;
                   8696: }
                   8697: 
1.127     matthew  8698: ############################################################
                   8699: ############################################################
1.154     albertel 8700: 
1.655     raeburn  8701: =pod
                   8702: 
                   8703: =head1 Course Catalog Routines
                   8704: 
                   8705: =over 4
                   8706: 
                   8707: =item * &gather_categories()
                   8708: 
                   8709: Converts category definitions - keys of categories hash stored in  
                   8710: coursecategories in configuration.db on the primary library server in a 
                   8711: domain - to an array.  Also generates javascript and idx hash used to 
                   8712: generate Domain Coordinator interface for editing Course Categories.
                   8713: 
                   8714: Inputs:
1.663     raeburn  8715: 
1.655     raeburn  8716: categories (reference to hash of category definitions).
1.663     raeburn  8717: 
1.655     raeburn  8718: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   8719:       categories and subcategories).
1.663     raeburn  8720: 
1.655     raeburn  8721: idx (reference to hash of counters used in Domain Coordinator interface for 
                   8722:       editing Course Categories).
1.663     raeburn  8723: 
1.655     raeburn  8724: jsarray (reference to array of categories used to create Javascript arrays for
                   8725:          Domain Coordinator interface for editing Course Categories).
                   8726: 
                   8727: Returns: nothing
                   8728: 
                   8729: Side effects: populates cats, idx and jsarray. 
                   8730: 
                   8731: =cut
                   8732: 
                   8733: sub gather_categories {
                   8734:     my ($categories,$cats,$idx,$jsarray) = @_;
                   8735:     my %counters;
                   8736:     my $num = 0;
                   8737:     foreach my $item (keys(%{$categories})) {
                   8738:         my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   8739:         if ($container eq '' && $depth == 0) {
                   8740:             $cats->[$depth][$categories->{$item}] = $cat;
                   8741:         } else {
                   8742:             $cats->[$depth]{$container}[$categories->{$item}] = $cat;
                   8743:         }
                   8744:         my ($escitem,$tail) = split(/:/,$item,2);
                   8745:         if ($counters{$tail} eq '') {
                   8746:             $counters{$tail} = $num;
                   8747:             $num ++;
                   8748:         }
                   8749:         if (ref($idx) eq 'HASH') {
                   8750:             $idx->{$item} = $counters{$tail};
                   8751:         }
                   8752:         if (ref($jsarray) eq 'ARRAY') {
                   8753:             push(@{$jsarray->[$counters{$tail}]},$item);
                   8754:         }
                   8755:     }
                   8756:     return;
                   8757: }
                   8758: 
                   8759: =pod
                   8760: 
                   8761: =item * &extract_categories()
                   8762: 
                   8763: Used to generate breadcrumb trails for course categories.
                   8764: 
                   8765: Inputs:
1.663     raeburn  8766: 
1.655     raeburn  8767: categories (reference to hash of category definitions).
1.663     raeburn  8768: 
1.655     raeburn  8769: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   8770:       categories and subcategories).
1.663     raeburn  8771: 
1.655     raeburn  8772: trails (reference to array of breacrumb trails for each category).
1.663     raeburn  8773: 
1.655     raeburn  8774: allitems (reference to hash - key is category key 
                   8775:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  8776: 
1.655     raeburn  8777: idx (reference to hash of counters used in Domain Coordinator interface for
                   8778:       editing Course Categories).
1.663     raeburn  8779: 
1.655     raeburn  8780: jsarray (reference to array of categories used to create Javascript arrays for
                   8781:          Domain Coordinator interface for editing Course Categories).
                   8782: 
1.665     raeburn  8783: subcats (reference to hash of arrays containing all subcategories within each 
                   8784:          category, -recursive)
                   8785: 
1.655     raeburn  8786: Returns: nothing
                   8787: 
                   8788: Side effects: populates trails and allitems hash references.
                   8789: 
                   8790: =cut
                   8791: 
                   8792: sub extract_categories {
1.665     raeburn  8793:     my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655     raeburn  8794:     if (ref($categories) eq 'HASH') {
                   8795:         &gather_categories($categories,$cats,$idx,$jsarray);
                   8796:         if (ref($cats->[0]) eq 'ARRAY') {
                   8797:             for (my $i=0; $i<@{$cats->[0]}; $i++) {
                   8798:                 my $name = $cats->[0][$i];
                   8799:                 my $item = &escape($name).'::0';
                   8800:                 my $trailstr;
                   8801:                 if ($name eq 'instcode') {
                   8802:                     $trailstr = &mt('Official courses (with institutional codes)');
                   8803:                 } else {
                   8804:                     $trailstr = $name;
                   8805:                 }
                   8806:                 if ($allitems->{$item} eq '') {
                   8807:                     push(@{$trails},$trailstr);
                   8808:                     $allitems->{$item} = scalar(@{$trails})-1;
                   8809:                 }
                   8810:                 my @parents = ($name);
                   8811:                 if (ref($cats->[1]{$name}) eq 'ARRAY') {
                   8812:                     for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
                   8813:                         my $category = $cats->[1]{$name}[$j];
1.665     raeburn  8814:                         if (ref($subcats) eq 'HASH') {
                   8815:                             push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
                   8816:                         }
                   8817:                         &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
                   8818:                     }
                   8819:                 } else {
                   8820:                     if (ref($subcats) eq 'HASH') {
                   8821:                         $subcats->{$item} = [];
1.655     raeburn  8822:                     }
                   8823:                 }
                   8824:             }
                   8825:         }
                   8826:     }
                   8827:     return;
                   8828: }
                   8829: 
                   8830: =pod
                   8831: 
                   8832: =item *&recurse_categories()
                   8833: 
                   8834: Recursively used to generate breadcrumb trails for course categories.
                   8835: 
                   8836: Inputs:
1.663     raeburn  8837: 
1.655     raeburn  8838: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   8839:       categories and subcategories).
1.663     raeburn  8840: 
1.655     raeburn  8841: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663     raeburn  8842: 
                   8843: category (current course category, for which breadcrumb trail is being generated).
                   8844: 
                   8845: trails (reference to array of breadcrumb trails for each category).
                   8846: 
1.655     raeburn  8847: allitems (reference to hash - key is category key
                   8848:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  8849: 
1.655     raeburn  8850: parents (array containing containers directories for current category, 
                   8851:          back to top level). 
                   8852: 
                   8853: Returns: nothing
                   8854: 
                   8855: Side effects: populates trails and allitems hash references
                   8856: 
                   8857: =cut
                   8858: 
                   8859: sub recurse_categories {
1.665     raeburn  8860:     my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655     raeburn  8861:     my $shallower = $depth - 1;
                   8862:     if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
                   8863:         for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
                   8864:             my $name = $cats->[$depth]{$category}[$k];
                   8865:             my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   8866:             my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   8867:             if ($allitems->{$item} eq '') {
                   8868:                 push(@{$trails},$trailstr);
                   8869:                 $allitems->{$item} = scalar(@{$trails})-1;
                   8870:             }
                   8871:             my $deeper = $depth+1;
                   8872:             push(@{$parents},$category);
1.665     raeburn  8873:             if (ref($subcats) eq 'HASH') {
                   8874:                 my $subcat = &escape($name).':'.$category.':'.$depth;
                   8875:                 for (my $j=@{$parents}; $j>=0; $j--) {
                   8876:                     my $higher;
                   8877:                     if ($j > 0) {
                   8878:                         $higher = &escape($parents->[$j]).':'.
                   8879:                                   &escape($parents->[$j-1]).':'.$j;
                   8880:                     } else {
                   8881:                         $higher = &escape($parents->[$j]).'::'.$j;
                   8882:                     }
                   8883:                     push(@{$subcats->{$higher}},$subcat);
                   8884:                 }
                   8885:             }
                   8886:             &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
                   8887:                                 $subcats);
1.655     raeburn  8888:             pop(@{$parents});
                   8889:         }
                   8890:     } else {
                   8891:         my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   8892:         my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   8893:         if ($allitems->{$item} eq '') {
                   8894:             push(@{$trails},$trailstr);
                   8895:             $allitems->{$item} = scalar(@{$trails})-1;
                   8896:         }
                   8897:     }
                   8898:     return;
                   8899: }
                   8900: 
1.663     raeburn  8901: =pod
                   8902: 
                   8903: =item *&assign_categories_table()
                   8904: 
                   8905: Create a datatable for display of hierarchical categories in a domain,
                   8906: with checkboxes to allow a course to be categorized. 
                   8907: 
                   8908: Inputs:
                   8909: 
                   8910: cathash - reference to hash of categories defined for the domain (from
                   8911:           configuration.db)
                   8912: 
                   8913: currcat - scalar with an & separated list of categories assigned to a course. 
                   8914: 
                   8915: Returns: $output (markup to be displayed) 
                   8916: 
                   8917: =cut
                   8918: 
                   8919: sub assign_categories_table {
                   8920:     my ($cathash,$currcat) = @_;
                   8921:     my $output;
                   8922:     if (ref($cathash) eq 'HASH') {
                   8923:         my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
                   8924:         &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
                   8925:         $maxdepth = scalar(@cats);
                   8926:         if (@cats > 0) {
                   8927:             my $itemcount = 0;
                   8928:             if (ref($cats[0]) eq 'ARRAY') {
                   8929:                 $output = &Apache::loncommon::start_data_table();
                   8930:                 my @currcategories;
                   8931:                 if ($currcat ne '') {
                   8932:                     @currcategories = split('&',$currcat);
                   8933:                 }
                   8934:                 for (my $i=0; $i<@{$cats[0]}; $i++) {
                   8935:                     my $parent = $cats[0][$i];
                   8936:                     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   8937:                     next if ($parent eq 'instcode');
                   8938:                     my $item = &escape($parent).'::0';
                   8939:                     my $checked = '';
                   8940:                     if (@currcategories > 0) {
                   8941:                         if (grep(/^\Q$item\E$/,@currcategories)) {
                   8942:                             $checked = ' checked="checked" ';
                   8943:                         }
                   8944:                     }
1.675     raeburn  8945:                     $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
                   8946:                                '<input type="checkbox" name="usecategory" value="'.
                   8947:                                $item.'"'.$checked.' />'.$parent.'</span>'.
                   8948:                                '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663     raeburn  8949:                     my $depth = 1;
                   8950:                     push(@path,$parent);
                   8951:                     $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
                   8952:                     pop(@path);
                   8953:                     $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   8954:                     $itemcount ++;
                   8955:                 }
                   8956:                 $output .= &Apache::loncommon::end_data_table();
                   8957:             }
                   8958:         }
                   8959:     }
                   8960:     return $output;
                   8961: }
                   8962: 
                   8963: =pod
                   8964: 
                   8965: =item *&assign_category_rows()
                   8966: 
                   8967: Create a datatable row for display of nested categories in a domain,
                   8968: with checkboxes to allow a course to be categorized,called recursively.
                   8969: 
                   8970: Inputs:
                   8971: 
                   8972: itemcount - track row number for alternating colors
                   8973: 
                   8974: cats - reference to array of arrays/hashes which encapsulates hierarchy of
                   8975:       categories and subcategories.
                   8976: 
                   8977: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
                   8978: 
                   8979: parent - parent of current category item
                   8980: 
                   8981: path - Array containing all categories back up through the hierarchy from the
                   8982:        current category to the top level.
                   8983: 
                   8984: currcategories - reference to array of current categories assigned to the course
                   8985: 
                   8986: Returns: $output (markup to be displayed).
                   8987: 
                   8988: =cut
                   8989: 
                   8990: sub assign_category_rows {
                   8991:     my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
                   8992:     my ($text,$name,$item,$chgstr);
                   8993:     if (ref($cats) eq 'ARRAY') {
                   8994:         my $maxdepth = scalar(@{$cats});
                   8995:         if (ref($cats->[$depth]) eq 'HASH') {
                   8996:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   8997:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   8998:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   8999:                 $text .= '<td><table class="LC_datatable">';
                   9000:                 for (my $j=0; $j<$numchildren; $j++) {
                   9001:                     $name = $cats->[$depth]{$parent}[$j];
                   9002:                     $item = &escape($name).':'.&escape($parent).':'.$depth;
                   9003:                     my $deeper = $depth+1;
                   9004:                     my $checked = '';
                   9005:                     if (ref($currcategories) eq 'ARRAY') {
                   9006:                         if (@{$currcategories} > 0) {
                   9007:                             if (grep(/^\Q$item\E$/,@{$currcategories})) {
                   9008:                                 $checked = ' checked="checked" ';
                   9009:                             }
                   9010:                         }
                   9011:                     }
1.664     raeburn  9012:                     $text .= '<tr><td><span class="LC_nobreak"><label>'.
                   9013:                              '<input type="checkbox" name="usecategory" value="'.
1.675     raeburn  9014:                              $item.'"'.$checked.' />'.$name.'</label></span>'.
                   9015:                              '<input type="hidden" name="catname" value="'.$name.'" />'.
                   9016:                              '</td><td>';
1.663     raeburn  9017:                     if (ref($path) eq 'ARRAY') {
                   9018:                         push(@{$path},$name);
                   9019:                         $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
                   9020:                         pop(@{$path});
                   9021:                     }
                   9022:                     $text .= '</td></tr>';
                   9023:                 }
                   9024:                 $text .= '</table></td>';
                   9025:             }
                   9026:         }
                   9027:     }
                   9028:     return $text;
                   9029: }
                   9030: 
1.655     raeburn  9031: ############################################################
                   9032: ############################################################
                   9033: 
                   9034: 
1.443     albertel 9035: sub commit_customrole {
1.664     raeburn  9036:     my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630     raeburn  9037:     my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443     albertel 9038:                          ($start?', '.&mt('starting').' '.localtime($start):'').
                   9039:                          ($end?', ending '.localtime($end):'').': <b>'.
                   9040:               &Apache::lonnet::assigncustomrole(
1.664     raeburn  9041:                  $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443     albertel 9042:                  '</b><br />';
                   9043:     return $output;
                   9044: }
                   9045: 
                   9046: sub commit_standardrole {
1.541     raeburn  9047:     my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
                   9048:     my ($output,$logmsg,$linefeed);
                   9049:     if ($context eq 'auto') {
                   9050:         $linefeed = "\n";
                   9051:     } else {
                   9052:         $linefeed = "<br />\n";
                   9053:     }  
1.443     albertel 9054:     if ($three eq 'st') {
1.541     raeburn  9055:         my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
                   9056:                                          $one,$two,$sec,$context);
                   9057:         if (($result =~ /^error/) || ($result eq 'not_in_class') || 
1.626     raeburn  9058:             ($result eq 'unknown_course') || ($result eq 'refused')) {
                   9059:             $output = $logmsg.' '.&mt('Error: ').$result."\n"; 
1.443     albertel 9060:         } else {
1.541     raeburn  9061:             $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443     albertel 9062:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  9063:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
                   9064:             if ($context eq 'auto') {
                   9065:                 $output .= $result.$linefeed.&mt('Add to classlist').': ok';
                   9066:             } else {
                   9067:                $output .= '<b>'.$result.'</b>'.$linefeed.
                   9068:                &mt('Add to classlist').': <b>ok</b>';
                   9069:             }
                   9070:             $output .= $linefeed;
1.443     albertel 9071:         }
                   9072:     } else {
                   9073:         $output = &mt('Assigning').' '.$three.' in '.$url.
                   9074:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  9075:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652     raeburn  9076:         my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541     raeburn  9077:         if ($context eq 'auto') {
                   9078:             $output .= $result.$linefeed;
                   9079:         } else {
                   9080:             $output .= '<b>'.$result.'</b>'.$linefeed;
                   9081:         }
1.443     albertel 9082:     }
                   9083:     return $output;
                   9084: }
                   9085: 
                   9086: sub commit_studentrole {
1.541     raeburn  9087:     my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626     raeburn  9088:     my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541     raeburn  9089:     if ($context eq 'auto') {
                   9090:         $linefeed = "\n";
                   9091:     } else {
                   9092:         $linefeed = '<br />'."\n";
                   9093:     }
1.443     albertel 9094:     if (defined($one) && defined($two)) {
                   9095:         my $cid=$one.'_'.$two;
                   9096:         my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
                   9097:         my $secchange = 0;
                   9098:         my $expire_role_result;
                   9099:         my $modify_section_result;
1.628     raeburn  9100:         if ($oldsec ne '-1') { 
                   9101:             if ($oldsec ne $sec) {
1.443     albertel 9102:                 $secchange = 1;
1.628     raeburn  9103:                 my $now = time;
1.443     albertel 9104:                 my $uurl='/'.$cid;
                   9105:                 $uurl=~s/\_/\//g;
                   9106:                 if ($oldsec) {
                   9107:                     $uurl.='/'.$oldsec;
                   9108:                 }
1.626     raeburn  9109:                 $oldsecurl = $uurl;
1.628     raeburn  9110:                 $expire_role_result = 
1.652     raeburn  9111:                     &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628     raeburn  9112:                 if ($env{'request.course.sec'} ne '') { 
                   9113:                     if ($expire_role_result eq 'refused') {
                   9114:                         my @roles = ('st');
                   9115:                         my @statuses = ('previous');
                   9116:                         my @roledoms = ($one);
                   9117:                         my $withsec = 1;
                   9118:                         my %roleshash = 
                   9119:                             &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
                   9120:                                               \@statuses,\@roles,\@roledoms,$withsec);
                   9121:                         if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
                   9122:                             my ($oldstart,$oldend) = 
                   9123:                                 split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
                   9124:                             if ($oldend > 0 && $oldend <= $now) {
                   9125:                                 $expire_role_result = 'ok';
                   9126:                             }
                   9127:                         }
                   9128:                     }
                   9129:                 }
1.443     albertel 9130:                 $result = $expire_role_result;
                   9131:             }
                   9132:         }
                   9133:         if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652     raeburn  9134:             $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443     albertel 9135:             if ($modify_section_result =~ /^ok/) {
                   9136:                 if ($secchange == 1) {
1.628     raeburn  9137:                     if ($sec eq '') {
                   9138:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
                   9139:                     } else {
                   9140:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
                   9141:                     }
1.443     albertel 9142:                 } elsif ($oldsec eq '-1') {
1.628     raeburn  9143:                     if ($sec eq '') {
                   9144:                         $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
                   9145:                     } else {
                   9146:                         $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   9147:                     }
1.443     albertel 9148:                 } else {
1.628     raeburn  9149:                     if ($sec eq '') {
                   9150:                         $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
                   9151:                     } else {
                   9152:                         $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   9153:                     }
1.443     albertel 9154:                 }
                   9155:             } else {
1.628     raeburn  9156:                 if ($secchange) {       
                   9157:                     $$logmsg .= &mt('Error when attempting section change for [_1] from old section "[_2]" to new section: "[_3]" in course [_4] -error:',$uname,$oldsec,$sec,$cid).' '.$modify_section_result.$linefeed;
                   9158:                 } else {
                   9159:                     $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
                   9160:                 }
1.443     albertel 9161:             }
                   9162:             $result = $modify_section_result;
                   9163:         } elsif ($secchange == 1) {
1.628     raeburn  9164:             if ($oldsec eq '') {
                   9165:                 $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
                   9166:             } else {
                   9167:                 $$logmsg .= &mt('Error when attempting to expire existing role for [_1] in section [_2] in course [_3] -error: ',$uname,$oldsec,$cid).' '.$expire_role_result.$linefeed;
                   9168:             }
1.626     raeburn  9169:             if ($expire_role_result eq 'refused') {
                   9170:                 my $newsecurl = '/'.$cid;
                   9171:                 $newsecurl =~ s/\_/\//g;
                   9172:                 if ($sec ne '') {
                   9173:                     $newsecurl.='/'.$sec;
                   9174:                 }
                   9175:                 if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
                   9176:                     if ($sec eq '') {
                   9177:                         $$logmsg .= &mt('Although your current role has privileges to add students to section "[_1]", you do not have privileges to modify existing enrollments unaffiliated with any section.',$sec).$linefeed;
                   9178:                     } else {
                   9179:                         $$logmsg .= &mt('Although your current role has privileges to add students to section "[_1]", you do not have privileges to modify existing enrollments in other sections.',$sec).$linefeed;
                   9180:                     }
                   9181:                 }
                   9182:             }
1.443     albertel 9183:         }
                   9184:     } else {
1.626     raeburn  9185:         $$logmsg .= &mt('Incomplete course id defined.').$linefeed.&mt('Addition of user [_1] from domain [_2] to course [_3], section [_4] not completed.',$uname,$udom,$one.'_'.$two,$sec).$linefeed;
1.443     albertel 9186:         $result = "error: incomplete course id\n";
                   9187:     }
                   9188:     return $result;
                   9189: }
                   9190: 
                   9191: ############################################################
                   9192: ############################################################
                   9193: 
1.566     albertel 9194: sub check_clone {
1.578     raeburn  9195:     my ($args,$linefeed) = @_;
1.566     albertel 9196:     my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
                   9197:     my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
                   9198:     my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
                   9199:     my $clonemsg;
                   9200:     my $can_clone = 0;
                   9201: 
                   9202:     if ($clonehome eq 'no_host') {
1.578     raeburn  9203:         $clonemsg = &mt('No new course created.').$linefeed.&mt('A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});     
1.566     albertel 9204:     } else {
                   9205: 	my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568     albertel 9206: 	if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566     albertel 9207: 	    $can_clone = 1;
                   9208: 	} else {
                   9209: 	    my %clonehash = &Apache::lonnet::get('environment',['cloners'],
                   9210: 						 $args->{'clonedomain'},$args->{'clonecourse'});
                   9211: 	    my @cloners = split(/,/,$clonehash{'cloners'});
1.578     raeburn  9212:             if (grep(/^\*$/,@cloners)) {
                   9213:                 $can_clone = 1;
                   9214:             } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
                   9215:                 $can_clone = 1;
                   9216:             } else {
                   9217: 	        my %roleshash =
                   9218: 		    &Apache::lonnet::get_my_roles($args->{'ccuname'},
                   9219: 					 $args->{'ccdomain'},
                   9220:                                          'userroles',['active'],['cc'],
                   9221: 					 [$args->{'clonedomain'}]);
                   9222: 	        if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
                   9223: 		    $can_clone = 1;
                   9224: 	        } else {
                   9225:                     $clonemsg = &mt('No new course created.').$linefeed.&mt('The new course could not be cloned from the existing course because the new course owner ([_1]) does not have cloning rights in the existing course ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'});
                   9226: 	        }
1.566     albertel 9227: 	    }
1.578     raeburn  9228:         }
1.566     albertel 9229:     }
                   9230:     return ($can_clone, $clonemsg, $cloneid, $clonehome);
                   9231: }
                   9232: 
1.444     albertel 9233: sub construct_course {
1.541     raeburn  9234:     my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444     albertel 9235:     my $outcome;
1.541     raeburn  9236:     my $linefeed =  '<br />'."\n";
                   9237:     if ($context eq 'auto') {
                   9238:         $linefeed = "\n";
                   9239:     }
1.566     albertel 9240: 
                   9241: #
                   9242: # Are we cloning?
                   9243: #
                   9244:     my ($can_clone, $clonemsg, $cloneid, $clonehome);
                   9245:     if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578     raeburn  9246: 	($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566     albertel 9247: 	if ($context ne 'auto') {
1.578     raeburn  9248:             if ($clonemsg ne '') {
                   9249: 	        $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
                   9250:             }
1.566     albertel 9251: 	}
                   9252: 	$outcome .= $clonemsg.$linefeed;
                   9253: 
                   9254:         if (!$can_clone) {
                   9255: 	    return (0,$outcome);
                   9256: 	}
                   9257:     }
                   9258: 
1.444     albertel 9259: #
                   9260: # Open course
                   9261: #
                   9262:     my $crstype = lc($args->{'crstype'});
                   9263:     my %cenv=();
                   9264:     $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
                   9265:                                              $args->{'cdescr'},
                   9266:                                              $args->{'curl'},
                   9267:                                              $args->{'course_home'},
                   9268:                                              $args->{'nonstandard'},
                   9269:                                              $args->{'crscode'},
                   9270:                                              $args->{'ccuname'}.':'.
                   9271:                                              $args->{'ccdomain'},
                   9272:                                              $args->{'crstype'});
                   9273: 
                   9274:     # Note: The testing routines depend on this being output; see 
                   9275:     # Utils::Course. This needs to at least be output as a comment
                   9276:     # if anyone ever decides to not show this, and Utils::Course::new
                   9277:     # will need to be suitably modified.
1.541     raeburn  9278:     $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444     albertel 9279: #
                   9280: # Check if created correctly
                   9281: #
1.479     albertel 9282:     ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444     albertel 9283:     my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541     raeburn  9284:     $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566     albertel 9285: 
1.444     albertel 9286: #
1.566     albertel 9287: # Do the cloning
                   9288: #   
                   9289:     if ($can_clone && $cloneid) {
                   9290: 	$clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
                   9291: 	if ($context ne 'auto') {
                   9292: 	    $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
                   9293: 	}
                   9294: 	$outcome .= $clonemsg.$linefeed;
                   9295: 	my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444     albertel 9296: # Copy all files
1.637     www      9297: 	&Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444     albertel 9298: # Restore URL
1.566     albertel 9299: 	$cenv{'url'}=$oldcenv{'url'};
1.444     albertel 9300: # Restore title
1.566     albertel 9301: 	$cenv{'description'}=$oldcenv{'description'};
1.444     albertel 9302: # Mark as cloned
1.566     albertel 9303: 	$cenv{'clonedfrom'}=$cloneid;
1.638     www      9304: # Need to clone grading mode
                   9305:         my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
                   9306:         $cenv{'grading'}=$newenv{'grading'};
                   9307: # Do not clone these environment entries
                   9308:         &Apache::lonnet::del('environment',
                   9309:                   ['default_enrollment_start_date',
                   9310:                    'default_enrollment_end_date',
                   9311:                    'question.email',
                   9312:                    'policy.email',
                   9313:                    'comment.email',
                   9314:                    'pch.users.denied',
                   9315:                    'plc.users.denied'],
                   9316:                    $$crsudom,$$crsunum);
1.444     albertel 9317:     }
1.566     albertel 9318: 
1.444     albertel 9319: #
                   9320: # Set environment (will override cloned, if existing)
                   9321: #
                   9322:     my @sections = ();
                   9323:     my @xlists = ();
                   9324:     if ($args->{'crstype'}) {
                   9325:         $cenv{'type'}=$args->{'crstype'};
                   9326:     }
                   9327:     if ($args->{'crsid'}) {
                   9328:         $cenv{'courseid'}=$args->{'crsid'};
                   9329:     }
                   9330:     if ($args->{'crscode'}) {
                   9331:         $cenv{'internal.coursecode'}=$args->{'crscode'};
                   9332:     }
                   9333:     if ($args->{'crsquota'} ne '') {
                   9334:         $cenv{'internal.coursequota'}=$args->{'crsquota'};
                   9335:     } else {
                   9336:         $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
                   9337:     }
                   9338:     if ($args->{'ccuname'}) {
                   9339:         $cenv{'internal.courseowner'} = $args->{'ccuname'}.
                   9340:                                         ':'.$args->{'ccdomain'};
                   9341:     } else {
                   9342:         $cenv{'internal.courseowner'} = $args->{'curruser'};
                   9343:     }
                   9344:     my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
                   9345:     if ($args->{'crssections'}) {
                   9346:         $cenv{'internal.sectionnums'} = '';
                   9347:         if ($args->{'crssections'} =~ m/,/) {
                   9348:             @sections = split/,/,$args->{'crssections'};
                   9349:         } else {
                   9350:             $sections[0] = $args->{'crssections'};
                   9351:         }
                   9352:         if (@sections > 0) {
                   9353:             foreach my $item (@sections) {
                   9354:                 my ($sec,$gp) = split/:/,$item;
                   9355:                 my $class = $args->{'crscode'}.$sec;
                   9356:                 my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
                   9357:                 $cenv{'internal.sectionnums'} .= $item.',';
                   9358:                 unless ($addcheck eq 'ok') {
                   9359:                     push @badclasses, $class;
                   9360:                 }
                   9361:             }
                   9362:             $cenv{'internal.sectionnums'} =~ s/,$//;
                   9363:         }
                   9364:     }
                   9365: # do not hide course coordinator from staff listing, 
                   9366: # even if privileged
                   9367:     $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   9368: # add crosslistings
                   9369:     if ($args->{'crsxlist'}) {
                   9370:         $cenv{'internal.crosslistings'}='';
                   9371:         if ($args->{'crsxlist'} =~ m/,/) {
                   9372:             @xlists = split/,/,$args->{'crsxlist'};
                   9373:         } else {
                   9374:             $xlists[0] = $args->{'crsxlist'};
                   9375:         }
                   9376:         if (@xlists > 0) {
                   9377:             foreach my $item (@xlists) {
                   9378:                 my ($xl,$gp) = split/:/,$item;
                   9379:                 my $addcheck =  &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
                   9380:                 $cenv{'internal.crosslistings'} .= $item.',';
                   9381:                 unless ($addcheck eq 'ok') {
                   9382:                     push @badclasses, $xl;
                   9383:                 }
                   9384:             }
                   9385:             $cenv{'internal.crosslistings'} =~ s/,$//;
                   9386:         }
                   9387:     }
                   9388:     if ($args->{'autoadds'}) {
                   9389:         $cenv{'internal.autoadds'}=$args->{'autoadds'};
                   9390:     }
                   9391:     if ($args->{'autodrops'}) {
                   9392:         $cenv{'internal.autodrops'}=$args->{'autodrops'};
                   9393:     }
                   9394: # check for notification of enrollment changes
                   9395:     my @notified = ();
                   9396:     if ($args->{'notify_owner'}) {
                   9397:         if ($args->{'ccuname'} ne '') {
                   9398:             push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
                   9399:         }
                   9400:     }
                   9401:     if ($args->{'notify_dc'}) {
                   9402:         if ($uname ne '') { 
1.630     raeburn  9403:             push(@notified,$uname.':'.$udom);
1.444     albertel 9404:         }
                   9405:     }
                   9406:     if (@notified > 0) {
                   9407:         my $notifylist;
                   9408:         if (@notified > 1) {
                   9409:             $notifylist = join(',',@notified);
                   9410:         } else {
                   9411:             $notifylist = $notified[0];
                   9412:         }
                   9413:         $cenv{'internal.notifylist'} = $notifylist;
                   9414:     }
                   9415:     if (@badclasses > 0) {
                   9416:         my %lt=&Apache::lonlocal::texthash(
                   9417:                 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.  However, if automated course roster updates are enabled for this class, these particular sections/crosslistings will not contribute towards enrollment, because the user identified as the course owner for this LON-CAPA course',
                   9418:                 'dnhr' => 'does not have rights to access enrollment in these classes',
                   9419:                 'adby' => 'as determined by the policies of your institution on access to official classlists'
                   9420:         );
1.541     raeburn  9421:         my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
                   9422:                            ' ('.$lt{'adby'}.')';
                   9423:         if ($context eq 'auto') {
                   9424:             $outcome .= $badclass_msg.$linefeed;
1.566     albertel 9425:             $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541     raeburn  9426:             foreach my $item (@badclasses) {
                   9427:                 if ($context eq 'auto') {
                   9428:                     $outcome .= " - $item\n";
                   9429:                 } else {
                   9430:                     $outcome .= "<li>$item</li>\n";
                   9431:                 }
                   9432:             }
                   9433:             if ($context eq 'auto') {
                   9434:                 $outcome .= $linefeed;
                   9435:             } else {
1.566     albertel 9436:                 $outcome .= "</ul><br /><br /></div>\n";
1.541     raeburn  9437:             }
                   9438:         } 
1.444     albertel 9439:     }
                   9440:     if ($args->{'no_end_date'}) {
                   9441:         $args->{'endaccess'} = 0;
                   9442:     }
                   9443:     $cenv{'internal.autostart'}=$args->{'enrollstart'};
                   9444:     $cenv{'internal.autoend'}=$args->{'enrollend'};
                   9445:     $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
                   9446:     $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
                   9447:     if ($args->{'showphotos'}) {
                   9448:       $cenv{'internal.showphotos'}=$args->{'showphotos'};
                   9449:     }
                   9450:     $cenv{'internal.authtype'} = $args->{'authtype'};
                   9451:     $cenv{'internal.autharg'} = $args->{'autharg'}; 
                   9452:     if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
                   9453:         if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'}  eq '') {
1.541     raeburn  9454:             my $krb_msg = &mt('As you did not include the default Kerberos domain to be used for authentication in this class, the institutional data used by the automated enrollment process must include the Kerberos domain for each new student'); 
                   9455:             if ($context eq 'auto') {
                   9456:                 $outcome .= $krb_msg;
                   9457:             } else {
1.566     albertel 9458:                 $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541     raeburn  9459:             }
                   9460:             $outcome .= $linefeed;
1.444     albertel 9461:         }
                   9462:     }
                   9463:     if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
                   9464:        if ($args->{'setpolicy'}) {
                   9465:            $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   9466:        }
                   9467:        if ($args->{'setcontent'}) {
                   9468:            $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   9469:        }
                   9470:     }
                   9471:     if ($args->{'reshome'}) {
                   9472: 	$cenv{'reshome'}=$args->{'reshome'}.'/';
                   9473: 	$cenv{'reshome'}=~s/\/+$/\//;
                   9474:     }
                   9475: #
                   9476: # course has keyed access
                   9477: #
                   9478:     if ($args->{'setkeys'}) {
                   9479:        $cenv{'keyaccess'}='yes';
                   9480:     }
                   9481: # if specified, key authority is not course, but user
                   9482: # only active if keyaccess is yes
                   9483:     if ($args->{'keyauth'}) {
1.487     albertel 9484: 	my ($user,$domain) = split(':',$args->{'keyauth'});
                   9485: 	$user = &LONCAPA::clean_username($user);
                   9486: 	$domain = &LONCAPA::clean_username($domain);
1.488     foxr     9487: 	if ($user ne '' && $domain ne '') {
1.487     albertel 9488: 	    $cenv{'keyauth'}=$user.':'.$domain;
1.444     albertel 9489: 	}
                   9490:     }
                   9491: 
                   9492:     if ($args->{'disresdis'}) {
                   9493:         $cenv{'pch.roles.denied'}='st';
                   9494:     }
                   9495:     if ($args->{'disablechat'}) {
                   9496:         $cenv{'plc.roles.denied'}='st';
                   9497:     }
                   9498: 
                   9499:     # Record we've not yet viewed the Course Initialization Helper for this 
                   9500:     # course
                   9501:     $cenv{'course.helper.not.run'} = 1;
                   9502:     #
                   9503:     # Use new Randomseed
                   9504:     #
                   9505:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
                   9506:     $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
                   9507:     #
                   9508:     # The encryption code and receipt prefix for this course
                   9509:     #
                   9510:     $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
                   9511:     $cenv{'internal.encpref'}=100+int(9*rand(99));
                   9512:     #
                   9513:     # By default, use standard grading
                   9514:     if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
                   9515: 
1.541     raeburn  9516:     $outcome .= $linefeed.&mt('Setting environment').': '.                 
                   9517:           &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 9518: #
                   9519: # Open all assignments
                   9520: #
                   9521:     if ($args->{'openall'}) {
                   9522:        my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
                   9523:        my %storecontent = ($storeunder         => time,
                   9524:                            $storeunder.'.type' => 'date_start');
                   9525:        
                   9526:        $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541     raeburn  9527:                  ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 9528:    }
                   9529: #
                   9530: # Set first page
                   9531: #
                   9532:     unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
                   9533: 	    || ($cloneid)) {
1.445     albertel 9534: 	use LONCAPA::map;
1.444     albertel 9535: 	$outcome .= &mt('Setting first resource').': ';
1.445     albertel 9536: 
                   9537: 	my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
                   9538:         my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
                   9539: 
1.444     albertel 9540:         $outcome .= ($fatal?$errtext:'read ok').' - ';
                   9541:         my $title; my $url;
                   9542:         if ($args->{'firstres'} eq 'syl') {
1.690     bisitz   9543: 	    $title=&mt('Syllabus');
1.444     albertel 9544:             $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
                   9545:         } else {
1.690     bisitz   9546:             $title=&mt('Navigate Contents');
1.444     albertel 9547:             $url='/adm/navmaps';
                   9548:         }
1.445     albertel 9549: 
                   9550:         $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
                   9551: 	(my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
                   9552: 
                   9553: 	if ($errtext) { $fatal=2; }
1.541     raeburn  9554:         $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444     albertel 9555:     }
1.566     albertel 9556: 
                   9557:     return (1,$outcome);
1.444     albertel 9558: }
                   9559: 
                   9560: ############################################################
                   9561: ############################################################
                   9562: 
1.378     raeburn  9563: sub course_type {
                   9564:     my ($cid) = @_;
                   9565:     if (!defined($cid)) {
                   9566:         $cid = $env{'request.course.id'};
                   9567:     }
1.404     albertel 9568:     if (defined($env{'course.'.$cid.'.type'})) {
                   9569:         return $env{'course.'.$cid.'.type'};
1.378     raeburn  9570:     } else {
                   9571:         return 'Course';
1.377     raeburn  9572:     }
                   9573: }
1.156     albertel 9574: 
1.406     raeburn  9575: sub group_term {
                   9576:     my $crstype = &course_type();
                   9577:     my %names = (
                   9578:                   'Course' => 'group',
                   9579:                   'Group' => 'team',
                   9580:                 );
                   9581:     return $names{$crstype};
                   9582: }
                   9583: 
1.156     albertel 9584: sub icon {
                   9585:     my ($file)=@_;
1.505     albertel 9586:     my $curfext = lc((split(/\./,$file))[-1]);
1.168     albertel 9587:     my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156     albertel 9588:     my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168     albertel 9589:     if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
                   9590: 	if (-e  $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
                   9591: 	          $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   9592: 	            $curfext.".gif") {
                   9593: 	    $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   9594: 		$curfext.".gif";
                   9595: 	}
                   9596:     }
1.249     albertel 9597:     return &lonhttpdurl($iconname);
1.154     albertel 9598: } 
1.84      albertel 9599: 
1.575     albertel 9600: sub lonhttpdurl {
1.692     www      9601: #
                   9602: # Had been used for "small fry" static images on separate port 8080.
                   9603: # Modify here if lightweight http functionality desired again.
                   9604: # Currently eliminated due to increasing firewall issues.
                   9605: #
1.575     albertel 9606:     my ($url)=@_;
1.692     www      9607:     return $url;
1.215     albertel 9608: }
                   9609: 
1.213     albertel 9610: sub connection_aborted {
                   9611:     my ($r)=@_;
                   9612:     $r->print(" ");$r->rflush();
                   9613:     my $c = $r->connection;
                   9614:     return $c->aborted();
                   9615: }
                   9616: 
1.221     foxr     9617: #    Escapes strings that may have embedded 's that will be put into
1.222     foxr     9618: #    strings as 'strings'.
                   9619: sub escape_single {
1.221     foxr     9620:     my ($input) = @_;
1.223     albertel 9621:     $input =~ s/\\/\\\\/g;	# Escape the \'s..(must be first)>
1.221     foxr     9622:     $input =~ s/\'/\\\'/g;	# Esacpe the 's....
                   9623:     return $input;
                   9624: }
1.223     albertel 9625: 
1.222     foxr     9626: #  Same as escape_single, but escape's "'s  This 
                   9627: #  can be used for  "strings"
                   9628: sub escape_double {
                   9629:     my ($input) = @_;
                   9630:     $input =~ s/\\/\\\\/g;	# Escape the /'s..(must be first)>
                   9631:     $input =~ s/\"/\\\"/g;	# Esacpe the "s....
                   9632:     return $input;
                   9633: }
1.223     albertel 9634:  
1.222     foxr     9635: #   Escapes the last element of a full URL.
                   9636: sub escape_url {
                   9637:     my ($url)   = @_;
1.238     raeburn  9638:     my @urlslices = split(/\//, $url,-1);
1.369     www      9639:     my $lastitem = &escape(pop(@urlslices));
1.223     albertel 9640:     return join('/',@urlslices).'/'.$lastitem;
1.222     foxr     9641: }
1.462     albertel 9642: 
                   9643: # -------------------------------------------------------- Initliaze user login
                   9644: sub init_user_environment {
1.463     albertel 9645:     my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462     albertel 9646:     my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
                   9647: 
                   9648:     my $public=($username eq 'public' && $domain eq 'public');
                   9649: 
                   9650: # See if old ID present, if so, remove
                   9651: 
                   9652:     my ($filename,$cookie,$userroles);
                   9653:     my $now=time;
                   9654: 
                   9655:     if ($public) {
                   9656: 	my $max_public=100;
                   9657: 	my $oldest;
                   9658: 	my $oldest_time=0;
                   9659: 	for(my $next=1;$next<=$max_public;$next++) {
                   9660: 	    if (-e $lonids."/publicuser_$next.id") {
                   9661: 		my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
                   9662: 		if ($mtime<$oldest_time || !$oldest_time) {
                   9663: 		    $oldest_time=$mtime;
                   9664: 		    $oldest=$next;
                   9665: 		}
                   9666: 	    } else {
                   9667: 		$cookie="publicuser_$next";
                   9668: 		last;
                   9669: 	    }
                   9670: 	}
                   9671: 	if (!$cookie) { $cookie="publicuser_$oldest"; }
                   9672:     } else {
1.463     albertel 9673: 	# if this isn't a robot, kill any existing non-robot sessions
                   9674: 	if (!$args->{'robot'}) {
                   9675: 	    opendir(DIR,$lonids);
                   9676: 	    while ($filename=readdir(DIR)) {
                   9677: 		if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
                   9678: 		    unlink($lonids.'/'.$filename);
                   9679: 		}
1.462     albertel 9680: 	    }
1.463     albertel 9681: 	    closedir(DIR);
1.462     albertel 9682: 	}
                   9683: # Give them a new cookie
1.463     albertel 9684: 	my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684     www      9685: 		                   : $now.$$.int(rand(10000)));
1.463     albertel 9686: 	$cookie="$username\_$id\_$domain\_$authhost";
1.462     albertel 9687:     
                   9688: # Initialize roles
                   9689: 
                   9690: 	$userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
                   9691:     }
                   9692: # ------------------------------------ Check browser type and MathML capability
                   9693: 
                   9694:     my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   9695:         $clientunicode,$clientos) = &decode_user_agent($r);
                   9696: 
                   9697: # -------------------------------------- Any accessibility options to remember?
                   9698:     if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
                   9699: 	foreach my $option ('imagesuppress','appletsuppress',
                   9700: 			    'embedsuppress','fontenhance','blackwhite') {
                   9701: 	    if ($form->{$option} eq 'true') {
                   9702: 		&Apache::lonnet::put('environment',{$option => 'on'},
                   9703: 				     $domain,$username);
                   9704: 	    } else {
                   9705: 		&Apache::lonnet::del('environment',[$option],
                   9706: 				     $domain,$username);
                   9707: 	    }
                   9708: 	}
                   9709:     }
                   9710: # ------------------------------------------------------------- Get environment
                   9711: 
                   9712:     my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
                   9713:     my ($tmp) = keys(%userenv);
                   9714:     if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   9715: 	# default remote control to off
                   9716: 	if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
                   9717:     } else {
                   9718: 	undef(%userenv);
                   9719:     }
                   9720:     if (($userenv{'interface'}) && (!$form->{'interface'})) {
                   9721: 	$form->{'interface'}=$userenv{'interface'};
                   9722:     }
                   9723:     $env{'environment.remote'}=$userenv{'remote'};
                   9724:     if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
                   9725: 
                   9726: # --------------- Do not trust query string to be put directly into environment
                   9727:     foreach my $option ('imagesuppress','appletsuppress',
                   9728: 			'embedsuppress','fontenhance','blackwhite',
                   9729: 			'interface','localpath','localres') {
                   9730: 	$form->{$option}=~s/[\n\r\=]//gs;
                   9731:     }
                   9732: # --------------------------------------------------------- Write first profile
                   9733: 
                   9734:     {
                   9735: 	my %initial_env = 
                   9736: 	    ("user.name"          => $username,
                   9737: 	     "user.domain"        => $domain,
                   9738: 	     "user.home"          => $authhost,
                   9739: 	     "browser.type"       => $clientbrowser,
                   9740: 	     "browser.version"    => $clientversion,
                   9741: 	     "browser.mathml"     => $clientmathml,
                   9742: 	     "browser.unicode"    => $clientunicode,
                   9743: 	     "browser.os"         => $clientos,
                   9744: 	     "server.domain"      => $Apache::lonnet::perlvar{'lonDefDomain'},
                   9745: 	     "request.course.fn"  => '',
                   9746: 	     "request.course.uri" => '',
                   9747: 	     "request.course.sec" => '',
                   9748: 	     "request.role"       => 'cm',
                   9749: 	     "request.role.adv"   => $env{'user.adv'},
                   9750: 	     "request.host"       => $ENV{'REMOTE_ADDR'},);
                   9751: 
                   9752:         if ($form->{'localpath'}) {
                   9753: 	    $initial_env{"browser.localpath"}  = $form->{'localpath'};
                   9754: 	    $initial_env{"browser.localres"}   = $form->{'localres'};
                   9755:         }
                   9756: 	
                   9757: 	if ($public) {
                   9758: 	    $initial_env{"environment.remote"} = "off";
                   9759: 	}
                   9760: 	if ($form->{'interface'}) {
                   9761: 	    $form->{'interface'}=~s/\W//gs;
                   9762: 	    $initial_env{"browser.interface"} = $form->{'interface'};
                   9763: 	    $env{'browser.interface'}=$form->{'interface'};
                   9764: 	    foreach my $option ('imagesuppress','appletsuppress',
                   9765: 				'embedsuppress','fontenhance','blackwhite') {
                   9766: 		if (($form->{$option} eq 'true') ||
                   9767: 		    ($userenv{$option} eq 'on')) {
                   9768: 		    $initial_env{"browser.$option"} = "on";
                   9769: 		}
                   9770: 	    }
                   9771: 	}
                   9772: 
                   9773: 	$env{'user.environment'} = "$lonids/$cookie.id";
                   9774: 	
                   9775: 	if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
                   9776: 		 &GDBM_WRCREAT(),0640)) {
                   9777: 	    &_add_to_env(\%disk_env,\%initial_env);
                   9778: 	    &_add_to_env(\%disk_env,\%userenv,'environment.');
                   9779: 	    &_add_to_env(\%disk_env,$userroles);
1.463     albertel 9780: 	    if (ref($args->{'extra_env'})) {
                   9781: 		&_add_to_env(\%disk_env,$args->{'extra_env'});
                   9782: 	    }
1.462     albertel 9783: 	    untie(%disk_env);
                   9784: 	} else {
1.705     tempelho 9785: 	    &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
                   9786: 			   'Could not create environment storage in lonauth: '.$!.'</span>');
1.462     albertel 9787: 	    return 'error: '.$!;
                   9788: 	}
                   9789:     }
                   9790:     $env{'request.role'}='cm';
                   9791:     $env{'request.role.adv'}=$env{'user.adv'};
                   9792:     $env{'browser.type'}=$clientbrowser;
                   9793: 
                   9794:     return $cookie;
                   9795: 
                   9796: }
                   9797: 
                   9798: sub _add_to_env {
                   9799:     my ($idf,$env_data,$prefix) = @_;
1.676     raeburn  9800:     if (ref($env_data) eq 'HASH') {
                   9801:         while (my ($key,$value) = each(%$env_data)) {
                   9802: 	    $idf->{$prefix.$key} = $value;
                   9803: 	    $env{$prefix.$key}   = $value;
                   9804:         }
1.462     albertel 9805:     }
                   9806: }
                   9807: 
1.685     tempelho 9808: # --- Get the symbolic name of a problem and the url
                   9809: sub get_symb {
                   9810:     my ($request,$silent) = @_;
                   9811:     (my $url=$env{'form.url'}) =~ s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
                   9812:     my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
                   9813:     if ($symb eq '') {
                   9814:         if (!$silent) {
                   9815:             $request->print("Unable to handle ambiguous references:$url:.");
                   9816:             return ();
                   9817:         }
                   9818:     }
                   9819:     &Apache::lonenc::check_decrypt(\$symb);
                   9820:     return ($symb);
                   9821: }
                   9822: 
                   9823: # --------------------------------------------------------------Get annotation
                   9824: 
                   9825: sub get_annotation {
                   9826:     my ($symb,$enc) = @_;
                   9827: 
                   9828:     my $key = $symb;
                   9829:     if (!$enc) {
                   9830:         $key =
                   9831:             &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
                   9832:     }
                   9833:     my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
                   9834:     return $annotation{$key};
                   9835: }
                   9836: 
                   9837: sub clean_symb {
                   9838:     my ($symb) = @_;
                   9839: 
                   9840:     &Apache::lonenc::check_decrypt(\$symb);
                   9841:     my $enc = $env{'request.enc'};
                   9842:     delete($env{'request.enc'});
                   9843: 
                   9844:     return ($symb,$enc);
                   9845: }
1.462     albertel 9846: 
1.41      ng       9847: =pod
                   9848: 
                   9849: =back
                   9850: 
1.112     bowersj2 9851: =cut
1.41      ng       9852: 
1.112     bowersj2 9853: 1;
                   9854: __END__;
1.41      ng       9855: 

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