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

1.10      albertel    1: # The LearningOnline Network with CAPA
1.1       albertel    2: # a pile of common routines
1.10      albertel    3: #
1.1075.2.52! raeburn     4: # $Id: loncommon.pm,v 1.1075.2.51 2013/09/07 00:46:18 raeburn 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.1075.2.25  raeburn    70: use Apache::lonuserutils();
1.1075.2.27  raeburn    71: use Apache::lonuserstate();
1.479     albertel   72: use LONCAPA qw(:DEFAULT :match);
1.657     raeburn    73: use DateTime::TimeZone;
1.687     raeburn    74: use DateTime::Locale::Catalog;
1.1075.2.14  raeburn    75: use Authen::Captcha;
                     76: use Captcha::reCAPTCHA;
1.117     www        77: 
1.517     raeburn    78: # ---------------------------------------------- Designs
                     79: use vars qw(%defaultdesign);
                     80: 
1.22      www        81: my $readit;
                     82: 
1.517     raeburn    83: 
1.157     matthew    84: ##
                     85: ## Global Variables
                     86: ##
1.46      matthew    87: 
1.643     foxr       88: 
                     89: # ----------------------------------------------- SSI with retries:
                     90: #
                     91: 
                     92: =pod
                     93: 
1.648     raeburn    94: =head1 Server Side include with retries:
1.643     foxr       95: 
                     96: =over 4
                     97: 
1.648     raeburn    98: =item * &ssi_with_retries(resource,retries form)
1.643     foxr       99: 
                    100: Performs an ssi with some number of retries.  Retries continue either
                    101: until the result is ok or until the retry count supplied by the
                    102: caller is exhausted.  
                    103: 
                    104: Inputs:
1.648     raeburn   105: 
                    106: =over 4
                    107: 
1.643     foxr      108: resource   - Identifies the resource to insert.
1.648     raeburn   109: 
1.643     foxr      110: retries    - Count of the number of retries allowed.
1.648     raeburn   111: 
1.643     foxr      112: form       - Hash that identifies the rendering options.
                    113: 
1.648     raeburn   114: =back
                    115: 
                    116: Returns:
                    117: 
                    118: =over 4
                    119: 
1.643     foxr      120: content    - The content of the response.  If retries were exhausted this is empty.
1.648     raeburn   121: 
1.643     foxr      122: response   - The response from the last attempt (which may or may not have been successful.
                    123: 
1.648     raeburn   124: =back
                    125: 
                    126: =back
                    127: 
1.643     foxr      128: =cut
                    129: 
                    130: sub ssi_with_retries {
                    131:     my ($resource, $retries, %form) = @_;
                    132: 
                    133: 
                    134:     my $ok = 0;			# True if we got a good response.
                    135:     my $content;
                    136:     my $response;
                    137: 
                    138:     # Try to get the ssi done. within the retries count:
                    139: 
                    140:     do {
                    141: 	($content, $response) = &Apache::lonnet::ssi($resource, %form);
                    142: 	$ok      = $response->is_success;
1.650     www       143:         if (!$ok) {
                    144:             &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
                    145:         }
1.643     foxr      146: 	$retries--;
                    147:     } while (!$ok && ($retries > 0));
                    148: 
                    149:     if (!$ok) {
                    150: 	$content = '';		# On error return an empty content.
                    151:     }
                    152:     return ($content, $response);
                    153: 
                    154: }
                    155: 
                    156: 
                    157: 
1.20      www       158: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12      harris41  159: my %language;
1.124     www       160: my %supported_language;
1.1048    foxr      161: my %latex_language;		# For choosing hyphenation in <transl..>
                    162: my %latex_language_bykey;	# for choosing hyphenation from metadata
1.12      harris41  163: my %cprtag;
1.192     taceyjo1  164: my %scprtag;
1.351     www       165: my %fe; my %fd; my %fm;
1.41      ng        166: my %category_extensions;
1.12      harris41  167: 
1.46      matthew   168: # ---------------------------------------------- Thesaurus variables
1.144     matthew   169: #
                    170: # %Keywords:
                    171: #      A hash used by &keyword to determine if a word is considered a keyword.
                    172: # $thesaurus_db_file 
                    173: #      Scalar containing the full path to the thesaurus database.
1.46      matthew   174: 
                    175: my %Keywords;
                    176: my $thesaurus_db_file;
                    177: 
1.144     matthew   178: #
                    179: # Initialize values from language.tab, copyright.tab, filetypes.tab,
                    180: # thesaurus.tab, and filecategories.tab.
                    181: #
1.18      www       182: BEGIN {
1.46      matthew   183:     # Variable initialization
                    184:     $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
                    185:     #
1.22      www       186:     unless ($readit) {
1.12      harris41  187: # ------------------------------------------------------------------- languages
                    188:     {
1.158     raeburn   189:         my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    190:                                    '/language.tab';
                    191:         if ( open(my $fh,"<$langtabfile") ) {
1.356     albertel  192:             while (my $line = <$fh>) {
                    193:                 next if ($line=~/^\#/);
                    194:                 chomp($line);
1.1048    foxr      195:                 my ($key,$two,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158     raeburn   196:                 $language{$key}=$val.' - '.$enc;
                    197:                 if ($sup) {
                    198:                     $supported_language{$key}=$sup;
                    199:                 }
1.1048    foxr      200: 		if ($latex) {
                    201: 		    $latex_language_bykey{$key} = $latex;
                    202: 		    $latex_language{$two} = $latex;
                    203: 		}
1.158     raeburn   204:             }
                    205:             close($fh);
                    206:         }
1.12      harris41  207:     }
                    208: # ------------------------------------------------------------------ copyrights
                    209:     {
1.158     raeburn   210:         my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
                    211:                                   '/copyright.tab';
                    212:         if ( open (my $fh,"<$copyrightfile") ) {
1.356     albertel  213:             while (my $line = <$fh>) {
                    214:                 next if ($line=~/^\#/);
                    215:                 chomp($line);
                    216:                 my ($key,$val)=(split(/\s+/,$line,2));
1.158     raeburn   217:                 $cprtag{$key}=$val;
                    218:             }
                    219:             close($fh);
                    220:         }
1.12      harris41  221:     }
1.351     www       222: # ----------------------------------------------------------- source copyrights
1.192     taceyjo1  223:     {
                    224:         my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
                    225:                                   '/source_copyright.tab';
                    226:         if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356     albertel  227:             while (my $line = <$fh>) {
                    228:                 next if ($line =~ /^\#/);
                    229:                 chomp($line);
                    230:                 my ($key,$val)=(split(/\s+/,$line,2));
1.192     taceyjo1  231:                 $scprtag{$key}=$val;
                    232:             }
                    233:             close($fh);
                    234:         }
                    235:     }
1.63      www       236: 
1.517     raeburn   237: # -------------------------------------------------------------- default domain designs
1.63      www       238:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517     raeburn   239:     my $designfile = $designdir.'/default.tab';
                    240:     if ( open (my $fh,"<$designfile") ) {
                    241:         while (my $line = <$fh>) {
                    242:             next if ($line =~ /^\#/);
                    243:             chomp($line);
                    244:             my ($key,$val)=(split(/\=/,$line));
                    245:             if ($val) { $defaultdesign{$key}=$val; }
                    246:         }
                    247:         close($fh);
1.63      www       248:     }
                    249: 
1.15      harris41  250: # ------------------------------------------------------------- file categories
                    251:     {
1.158     raeburn   252:         my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    253:                                   '/filecategories.tab';
                    254:         if ( open (my $fh,"<$categoryfile") ) {
1.356     albertel  255: 	    while (my $line = <$fh>) {
                    256: 		next if ($line =~ /^\#/);
                    257: 		chomp($line);
                    258:                 my ($extension,$category)=(split(/\s+/,$line,2));
1.158     raeburn   259:                 push @{$category_extensions{lc($category)}},$extension;
                    260:             }
                    261:             close($fh);
                    262:         }
                    263: 
1.15      harris41  264:     }
1.12      harris41  265: # ------------------------------------------------------------------ file types
                    266:     {
1.158     raeburn   267:         my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    268:                '/filetypes.tab';
                    269:         if ( open (my $fh,"<$typesfile") ) {
1.356     albertel  270:             while (my $line = <$fh>) {
                    271: 		next if ($line =~ /^\#/);
                    272: 		chomp($line);
                    273:                 my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158     raeburn   274:                 if ($descr ne '') {
                    275:                     $fe{$ending}=lc($emb);
                    276:                     $fd{$ending}=$descr;
1.351     www       277:                     if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158     raeburn   278:                 }
                    279:             }
                    280:             close($fh);
                    281:         }
1.12      harris41  282:     }
1.22      www       283:     &Apache::lonnet::logthis(
1.705     tempelho  284:              "<span style='color:yellow;'>INFO: Read file types</span>");
1.22      www       285:     $readit=1;
1.46      matthew   286:     }  # end of unless($readit) 
1.32      matthew   287:     
                    288: }
1.112     bowersj2  289: 
1.42      matthew   290: ###############################################################
                    291: ##           HTML and Javascript Helper Functions            ##
                    292: ###############################################################
                    293: 
                    294: =pod 
                    295: 
1.112     bowersj2  296: =head1 HTML and Javascript Functions
1.42      matthew   297: 
1.112     bowersj2  298: =over 4
                    299: 
1.648     raeburn   300: =item * &browser_and_searcher_javascript()
1.112     bowersj2  301: 
                    302: X<browsing, javascript>X<searching, javascript>Returns a string
                    303: containing javascript with two functions, C<openbrowser> and
                    304: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
                    305: tags.
1.42      matthew   306: 
1.648     raeburn   307: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42      matthew   308: 
                    309: inputs: formname, elementname, only, omit
                    310: 
                    311: formname and elementname indicate the name of the html form and name of
                    312: the element that the results of the browsing selection are to be placed in. 
                    313: 
                    314: Specifying 'only' will restrict the browser to displaying only files
1.185     www       315: with the given extension.  Can be a comma separated list.
1.42      matthew   316: 
                    317: Specifying 'omit' will restrict the browser to NOT displaying files
1.185     www       318: with the given extension.  Can be a comma separated list.
1.42      matthew   319: 
1.648     raeburn   320: =item * &opensearcher(formname,elementname) [javascript]
1.42      matthew   321: 
                    322: Inputs: formname, elementname
                    323: 
                    324: formname and elementname specify the name of the html form and the name
                    325: of the element the selection from the search results will be placed in.
1.542     raeburn   326: 
1.42      matthew   327: =cut
                    328: 
                    329: sub browser_and_searcher_javascript {
1.199     albertel  330:     my ($mode)=@_;
                    331:     if (!defined($mode)) { $mode='edit'; }
1.453     albertel  332:     my $resurl=&escape_single(&lastresurl());
1.42      matthew   333:     return <<END;
1.219     albertel  334: // <!-- BEGIN LON-CAPA Internal
1.50      matthew   335:     var editbrowser = null;
1.135     albertel  336:     function openbrowser(formname,elementname,only,omit,titleelement) {
1.170     www       337:         var url = '$resurl/?';
1.42      matthew   338:         if (editbrowser == null) {
                    339:             url += 'launch=1&';
                    340:         }
                    341:         url += 'catalogmode=interactive&';
1.199     albertel  342:         url += 'mode=$mode&';
1.611     albertel  343:         url += 'inhibitmenu=yes&';
1.42      matthew   344:         url += 'form=' + formname + '&';
                    345:         if (only != null) {
                    346:             url += 'only=' + only + '&';
1.217     albertel  347:         } else {
                    348:             url += 'only=&';
                    349: 	}
1.42      matthew   350:         if (omit != null) {
                    351:             url += 'omit=' + omit + '&';
1.217     albertel  352:         } else {
                    353:             url += 'omit=&';
                    354: 	}
1.135     albertel  355:         if (titleelement != null) {
                    356:             url += 'titleelement=' + titleelement + '&';
1.217     albertel  357:         } else {
                    358: 	    url += 'titleelement=&';
                    359: 	}
1.42      matthew   360:         url += 'element=' + elementname + '';
                    361:         var title = 'Browser';
1.435     albertel  362:         var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42      matthew   363:         options += ',width=700,height=600';
                    364:         editbrowser = open(url,title,options,'1');
                    365:         editbrowser.focus();
                    366:     }
                    367:     var editsearcher;
1.135     albertel  368:     function opensearcher(formname,elementname,titleelement) {
1.42      matthew   369:         var url = '/adm/searchcat?';
                    370:         if (editsearcher == null) {
                    371:             url += 'launch=1&';
                    372:         }
                    373:         url += 'catalogmode=interactive&';
1.199     albertel  374:         url += 'mode=$mode&';
1.42      matthew   375:         url += 'form=' + formname + '&';
1.135     albertel  376:         if (titleelement != null) {
                    377:             url += 'titleelement=' + titleelement + '&';
1.217     albertel  378:         } else {
                    379: 	    url += 'titleelement=&';
                    380: 	}
1.42      matthew   381:         url += 'element=' + elementname + '';
                    382:         var title = 'Search';
1.435     albertel  383:         var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42      matthew   384:         options += ',width=700,height=600';
                    385:         editsearcher = open(url,title,options,'1');
                    386:         editsearcher.focus();
                    387:     }
1.219     albertel  388: // END LON-CAPA Internal -->
1.42      matthew   389: END
1.170     www       390: }
                    391: 
                    392: sub lastresurl {
1.258     albertel  393:     if ($env{'environment.lastresurl'}) {
                    394: 	return $env{'environment.lastresurl'}
1.170     www       395:     } else {
                    396: 	return '/res';
                    397:     }
                    398: }
                    399: 
                    400: sub storeresurl {
                    401:     my $resurl=&Apache::lonnet::clutter(shift);
                    402:     unless ($resurl=~/^\/res/) { return 0; }
                    403:     $resurl=~s/\/$//;
                    404:     &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646     raeburn   405:     &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170     www       406:     return 1;
1.42      matthew   407: }
                    408: 
1.74      www       409: sub studentbrowser_javascript {
1.111     www       410:    unless (
1.258     albertel  411:             (($env{'request.course.id'}) && 
1.302     albertel  412:              (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    413: 	      || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                    414: 					  '/'.$env{'request.course.sec'})
                    415: 	      ))
1.258     albertel  416:          || ($env{'request.role'}=~/^(au|dc|su)/)
1.111     www       417:           ) { return ''; }  
1.74      www       418:    return (<<'ENDSTDBRW');
1.776     bisitz    419: <script type="text/javascript" language="Javascript">
1.824     bisitz    420: // <![CDATA[
1.74      www       421:     var stdeditbrowser;
1.999     www       422:     function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
1.74      www       423:         var url = '/adm/pickstudent?';
                    424:         var filter;
1.558     albertel  425: 	if (!ignorefilter) {
                    426: 	    eval('filter=document.'+formname+'.'+uname+'.value;');
                    427: 	}
1.74      www       428:         if (filter != null) {
                    429:            if (filter != '') {
                    430:                url += 'filter='+filter+'&';
                    431: 	   }
                    432:         }
                    433:         url += 'form=' + formname + '&unameelement='+uname+
1.999     www       434:                                     '&udomelement='+udom+
                    435:                                     '&clicker='+clicker;
1.111     www       436: 	if (roleflag) { url+="&roles=1"; }
1.793     raeburn   437:         if (courseadvonly) { url+="&courseadvonly=1"; }
1.102     www       438:         var title = 'Student_Browser';
1.74      www       439:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    440:         options += ',width=700,height=600';
                    441:         stdeditbrowser = open(url,title,options,'1');
                    442:         stdeditbrowser.focus();
                    443:     }
1.824     bisitz    444: // ]]>
1.74      www       445: </script>
                    446: ENDSTDBRW
                    447: }
1.42      matthew   448: 
1.1003    www       449: sub resourcebrowser_javascript {
                    450:    unless ($env{'request.course.id'}) { return ''; }
1.1004    www       451:    return (<<'ENDRESBRW');
1.1003    www       452: <script type="text/javascript" language="Javascript">
                    453: // <![CDATA[
                    454:     var reseditbrowser;
1.1004    www       455:     function openresbrowser(formname,reslink) {
1.1005    www       456:         var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003    www       457:         var title = 'Resource_Browser';
                    458:         var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005    www       459:         options += ',width=700,height=500';
1.1004    www       460:         reseditbrowser = open(url,title,options,'1');
                    461:         reseditbrowser.focus();
1.1003    www       462:     }
                    463: // ]]>
                    464: </script>
1.1004    www       465: ENDRESBRW
1.1003    www       466: }
                    467: 
1.74      www       468: sub selectstudent_link {
1.999     www       469:    my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
                    470:    my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
                    471:                       &Apache::lonhtmlcommon::entity_encode($unameele)."','".
                    472:                       &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258     albertel  473:    if ($env{'request.course.id'}) {  
1.302     albertel  474:        if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    475: 	   && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                    476: 					'/'.$env{'request.course.sec'})) {
1.111     www       477: 	   return '';
                    478:        }
1.999     www       479:        $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793     raeburn   480:        if ($courseadvonly)  {
                    481:            $callargs .= ",'',1,1";
                    482:        }
                    483:        return '<span class="LC_nobreak">'.
                    484:               '<a href="javascript:openstdbrowser('.$callargs.');">'.
                    485:               &mt('Select User').'</a></span>';
1.74      www       486:    }
1.258     albertel  487:    if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012    www       488:        $callargs .= ",'',1"; 
1.793     raeburn   489:        return '<span class="LC_nobreak">'.
                    490:               '<a href="javascript:openstdbrowser('.$callargs.');">'.
                    491:               &mt('Select User').'</a></span>';
1.111     www       492:    }
                    493:    return '';
1.91      www       494: }
                    495: 
1.1004    www       496: sub selectresource_link {
                    497:    my ($form,$reslink,$arg)=@_;
                    498:    
                    499:    my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
                    500:                       &Apache::lonhtmlcommon::entity_encode($reslink)."'";
                    501:    unless ($env{'request.course.id'}) { return $arg; }
                    502:    return '<span class="LC_nobreak">'.
                    503:               '<a href="javascript:openresbrowser('.$callargs.');">'.
                    504:               $arg.'</a></span>';
                    505: }
                    506: 
                    507: 
                    508: 
1.653     raeburn   509: sub authorbrowser_javascript {
                    510:     return <<"ENDAUTHORBRW";
1.776     bisitz    511: <script type="text/javascript" language="JavaScript">
1.824     bisitz    512: // <![CDATA[
1.653     raeburn   513: var stdeditbrowser;
                    514: 
                    515: function openauthorbrowser(formname,udom) {
                    516:     var url = '/adm/pickauthor?';
                    517:     url += 'form='+formname+'&roledom='+udom;
                    518:     var title = 'Author_Browser';
                    519:     var options = 'scrollbars=1,resizable=1,menubar=0';
                    520:     options += ',width=700,height=600';
                    521:     stdeditbrowser = open(url,title,options,'1');
                    522:     stdeditbrowser.focus();
                    523: }
                    524: 
1.824     bisitz    525: // ]]>
1.653     raeburn   526: </script>
                    527: ENDAUTHORBRW
                    528: }
                    529: 
1.91      www       530: sub coursebrowser_javascript {
1.1075.2.31  raeburn   531:     my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
                    532:         $credits_element) = @_;
1.932     raeburn   533:     my $wintitle = 'Course_Browser';
1.931     raeburn   534:     if ($crstype eq 'Community') {
1.932     raeburn   535:         $wintitle = 'Community_Browser';
1.909     raeburn   536:     }
1.876     raeburn   537:     my $id_functions = &javascript_index_functions();
                    538:     my $output = '
1.776     bisitz    539: <script type="text/javascript" language="JavaScript">
1.824     bisitz    540: // <![CDATA[
1.468     raeburn   541:     var stdeditbrowser;'."\n";
1.876     raeburn   542: 
                    543:     $output .= <<"ENDSTDBRW";
1.909     raeburn   544:     function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91      www       545:         var url = '/adm/pickcourse?';
1.895     raeburn   546:         var formid = getFormIdByName(formname);
1.876     raeburn   547:         var domainfilter = getDomainFromSelectbox(formname,udom);
1.128     albertel  548:         if (domainfilter != null) {
                    549:            if (domainfilter != '') {
                    550:                url += 'domainfilter='+domainfilter+'&';
                    551: 	   }
                    552:         }
1.91      www       553:         url += 'form=' + formname + '&cnumelement='+uname+
1.187     albertel  554: 	                            '&cdomelement='+udom+
                    555:                                     '&cnameelement='+desc;
1.468     raeburn   556:         if (extra_element !=null && extra_element != '') {
1.594     raeburn   557:             if (formname == 'rolechoice' || formname == 'studentform') {
1.468     raeburn   558:                 url += '&roleelement='+extra_element;
                    559:                 if (domainfilter == null || domainfilter == '') {
                    560:                     url += '&domainfilter='+extra_element;
                    561:                 }
1.234     raeburn   562:             }
1.468     raeburn   563:             else {
                    564:                 if (formname == 'portform') {
                    565:                     url += '&setroles='+extra_element;
1.800     raeburn   566:                 } else {
                    567:                     if (formname == 'rules') {
                    568:                         url += '&fixeddom='+extra_element; 
                    569:                     }
1.468     raeburn   570:                 }
                    571:             }     
1.230     raeburn   572:         }
1.909     raeburn   573:         if (type != null && type != '') {
                    574:             url += '&type='+type;
                    575:         }
                    576:         if (type_elem != null && type_elem != '') {
                    577:             url += '&typeelement='+type_elem;
                    578:         }
1.872     raeburn   579:         if (formname == 'ccrs') {
                    580:             var ownername = document.forms[formid].ccuname.value;
                    581:             var ownerdom =  document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
                    582:             url += '&cloner='+ownername+':'+ownerdom;
                    583:         }
1.293     raeburn   584:         if (multflag !=null && multflag != '') {
                    585:             url += '&multiple='+multflag;
                    586:         }
1.909     raeburn   587:         var title = '$wintitle';
1.91      www       588:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    589:         options += ',width=700,height=600';
                    590:         stdeditbrowser = open(url,title,options,'1');
                    591:         stdeditbrowser.focus();
                    592:     }
1.876     raeburn   593: $id_functions
                    594: ENDSTDBRW
1.1075.2.31  raeburn   595:     if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
                    596:         $output .= &setsec_javascript($sec_element,$formname,$role_element,
                    597:                                       $credits_element);
1.876     raeburn   598:     }
                    599:     $output .= '
                    600: // ]]>
                    601: </script>';
                    602:     return $output;
                    603: }
                    604: 
                    605: sub javascript_index_functions {
                    606:     return <<"ENDJS";
                    607: 
                    608: function getFormIdByName(formname) {
                    609:     for (var i=0;i<document.forms.length;i++) {
                    610:         if (document.forms[i].name == formname) {
                    611:             return i;
                    612:         }
                    613:     }
                    614:     return -1;
                    615: }
                    616: 
                    617: function getIndexByName(formid,item) {
                    618:     for (var i=0;i<document.forms[formid].elements.length;i++) {
                    619:         if (document.forms[formid].elements[i].name == item) {
                    620:             return i;
                    621:         }
                    622:     }
                    623:     return -1;
                    624: }
1.468     raeburn   625: 
1.876     raeburn   626: function getDomainFromSelectbox(formname,udom) {
                    627:     var userdom;
                    628:     var formid = getFormIdByName(formname);
                    629:     if (formid > -1) {
                    630:         var domid = getIndexByName(formid,udom);
                    631:         if (domid > -1) {
                    632:             if (document.forms[formid].elements[domid].type == 'select-one') {
                    633:                 userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
                    634:             }
                    635:             if (document.forms[formid].elements[domid].type == 'hidden') {
                    636:                 userdom=document.forms[formid].elements[domid].value;
1.468     raeburn   637:             }
                    638:         }
                    639:     }
1.876     raeburn   640:     return userdom;
                    641: }
                    642: 
                    643: ENDJS
1.468     raeburn   644: 
1.876     raeburn   645: }
                    646: 
1.1017    raeburn   647: sub javascript_array_indexof {
1.1018    raeburn   648:     return <<ENDJS;
1.1017    raeburn   649: <script type="text/javascript" language="JavaScript">
                    650: // <![CDATA[
                    651: 
                    652: if (!Array.prototype.indexOf) {
                    653:     Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
                    654:         "use strict";
                    655:         if (this === void 0 || this === null) {
                    656:             throw new TypeError();
                    657:         }
                    658:         var t = Object(this);
                    659:         var len = t.length >>> 0;
                    660:         if (len === 0) {
                    661:             return -1;
                    662:         }
                    663:         var n = 0;
                    664:         if (arguments.length > 0) {
                    665:             n = Number(arguments[1]);
                    666:             if (n !== n) { // shortcut for verifying if it's NaN
                    667:                 n = 0;
                    668:             } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
                    669:                 n = (n > 0 || -1) * Math.floor(Math.abs(n));
                    670:             }
                    671:         }
                    672:         if (n >= len) {
                    673:             return -1;
                    674:         }
                    675:         var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
                    676:         for (; k < len; k++) {
                    677:             if (k in t && t[k] === searchElement) {
                    678:                 return k;
                    679:             }
                    680:         }
                    681:         return -1;
                    682:     }
                    683: }
                    684: 
                    685: // ]]>
                    686: </script>
                    687: 
                    688: ENDJS
                    689: 
                    690: }
                    691: 
1.876     raeburn   692: sub userbrowser_javascript {
                    693:     my $id_functions = &javascript_index_functions();
                    694:     return <<"ENDUSERBRW";
                    695: 
1.888     raeburn   696: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876     raeburn   697:     var url = '/adm/pickuser?';
                    698:     var userdom = getDomainFromSelectbox(formname,udom);
                    699:     if (userdom != null) {
                    700:        if (userdom != '') {
                    701:            url += 'srchdom='+userdom+'&';
                    702:        }
                    703:     }
                    704:     url += 'form=' + formname + '&unameelement='+uname+
                    705:                                 '&udomelement='+udom+
                    706:                                 '&ulastelement='+ulast+
                    707:                                 '&ufirstelement='+ufirst+
                    708:                                 '&uemailelement='+uemail+
1.881     raeburn   709:                                 '&hideudomelement='+hideudom+
                    710:                                 '&coursedom='+crsdom;
1.888     raeburn   711:     if ((caller != null) && (caller != undefined)) {
                    712:         url += '&caller='+caller;
                    713:     }
1.876     raeburn   714:     var title = 'User_Browser';
                    715:     var options = 'scrollbars=1,resizable=1,menubar=0';
                    716:     options += ',width=700,height=600';
                    717:     var stdeditbrowser = open(url,title,options,'1');
                    718:     stdeditbrowser.focus();
                    719: }
                    720: 
1.888     raeburn   721: function fix_domain (formname,udom,origdom,uname) {
1.876     raeburn   722:     var formid = getFormIdByName(formname);
                    723:     if (formid > -1) {
1.888     raeburn   724:         var unameid = getIndexByName(formid,uname);
1.876     raeburn   725:         var domid = getIndexByName(formid,udom);
                    726:         var hidedomid = getIndexByName(formid,origdom);
                    727:         if (hidedomid > -1) {
                    728:             var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888     raeburn   729:             var unameval = document.forms[formid].elements[unameid].value;
                    730:             if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
                    731:                 if (domid > -1) {
                    732:                     var slct = document.forms[formid].elements[domid];
                    733:                     if (slct.type == 'select-one') {
                    734:                         var i;
                    735:                         for (i=0;i<slct.length;i++) {
                    736:                             if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
                    737:                         }
                    738:                     }
                    739:                     if (slct.type == 'hidden') {
                    740:                         slct.value = fixeddom;
1.876     raeburn   741:                     }
                    742:                 }
1.468     raeburn   743:             }
                    744:         }
                    745:     }
1.876     raeburn   746:     return;
                    747: }
                    748: 
                    749: $id_functions
                    750: ENDUSERBRW
1.468     raeburn   751: }
                    752: 
                    753: sub setsec_javascript {
1.1075.2.31  raeburn   754:     my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905     raeburn   755:     my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
                    756:         $communityrolestr);
                    757:     if ($role_element ne '') {
                    758:         my @allroles = ('st','ta','ep','in','ad');
                    759:         foreach my $crstype ('Course','Community') {
                    760:             if ($crstype eq 'Community') {
                    761:                 foreach my $role (@allroles) {
                    762:                     push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
                    763:                 }
                    764:                 push(@communityrolenames,&Apache::lonnet::plaintext('co'));
                    765:             } else {
                    766:                 foreach my $role (@allroles) {
                    767:                     push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
                    768:                 }
                    769:                 push(@courserolenames,&Apache::lonnet::plaintext('cc'));
                    770:             }
                    771:         }
                    772:         $rolestr = '"'.join('","',@allroles).'"';
                    773:         $courserolestr = '"'.join('","',@courserolenames).'"';
                    774:         $communityrolestr = '"'.join('","',@communityrolenames).'"';
                    775:     }
1.468     raeburn   776:     my $setsections = qq|
                    777: function setSect(sectionlist) {
1.629     raeburn   778:     var sectionsArray = new Array();
                    779:     if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
                    780:         sectionsArray = sectionlist.split(",");
                    781:     }
1.468     raeburn   782:     var numSections = sectionsArray.length;
                    783:     document.$formname.$sec_element.length = 0;
                    784:     if (numSections == 0) {
                    785:         document.$formname.$sec_element.multiple=false;
                    786:         document.$formname.$sec_element.size=1;
                    787:         document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
                    788:     } else {
                    789:         if (numSections == 1) {
                    790:             document.$formname.$sec_element.multiple=false;
                    791:             document.$formname.$sec_element.size=1;
                    792:             document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
                    793:             document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
                    794:             document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
                    795:         } else {
                    796:             for (var i=0; i<numSections; i++) {
                    797:                 document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
                    798:             }
                    799:             document.$formname.$sec_element.multiple=true
                    800:             if (numSections < 3) {
                    801:                 document.$formname.$sec_element.size=numSections;
                    802:             } else {
                    803:                 document.$formname.$sec_element.size=3;
                    804:             }
                    805:             document.$formname.$sec_element.options[0].selected = false
                    806:         }
                    807:     }
1.91      www       808: }
1.905     raeburn   809: 
                    810: function setRole(crstype) {
1.468     raeburn   811: |;
1.905     raeburn   812:     if ($role_element eq '') {
                    813:         $setsections .= '    return;
                    814: }
                    815: ';
                    816:     } else {
                    817:         $setsections .= qq|
                    818:     var elementLength = document.$formname.$role_element.length;
                    819:     var allroles = Array($rolestr);
                    820:     var courserolenames = Array($courserolestr);
                    821:     var communityrolenames = Array($communityrolestr);
                    822:     if (elementLength != undefined) {
                    823:         if (document.$formname.$role_element.options[5].value == 'cc') {
                    824:             if (crstype == 'Course') {
                    825:                 return;
                    826:             } else {
                    827:                 allroles[5] = 'co';
                    828:                 for (var i=0; i<6; i++) {
                    829:                     document.$formname.$role_element.options[i].value = allroles[i];
                    830:                     document.$formname.$role_element.options[i].text = communityrolenames[i];
                    831:                 }
                    832:             }
                    833:         } else {
                    834:             if (crstype == 'Community') {
                    835:                 return;
                    836:             } else {
                    837:                 allroles[5] = 'cc';
                    838:                 for (var i=0; i<6; i++) {
                    839:                     document.$formname.$role_element.options[i].value = allroles[i];
                    840:                     document.$formname.$role_element.options[i].text = courserolenames[i];
                    841:                 }
                    842:             }
                    843:         }
                    844:     }
                    845:     return;
                    846: }
                    847: |;
                    848:     }
1.1075.2.31  raeburn   849:     if ($credits_element) {
                    850:         $setsections .= qq|
                    851: function setCredits(defaultcredits) {
                    852:     document.$formname.$credits_element.value = defaultcredits;
                    853:     return;
                    854: }
                    855: |;
                    856:     }
1.468     raeburn   857:     return $setsections;
                    858: }
                    859: 
1.91      www       860: sub selectcourse_link {
1.909     raeburn   861:    my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
                    862:        $typeelement) = @_;
                    863:    my $type = $selecttype;
1.871     raeburn   864:    my $linktext = &mt('Select Course');
                    865:    if ($selecttype eq 'Community') {
1.909     raeburn   866:        $linktext = &mt('Select Community');
1.906     raeburn   867:    } elsif ($selecttype eq 'Course/Community') {
                    868:        $linktext = &mt('Select Course/Community');
1.909     raeburn   869:        $type = '';
1.1019    raeburn   870:    } elsif ($selecttype eq 'Select') {
                    871:        $linktext = &mt('Select');
                    872:        $type = '';
1.871     raeburn   873:    }
1.787     bisitz    874:    return '<span class="LC_nobreak">'
                    875:          ."<a href='"
                    876:          .'javascript:opencrsbrowser("'.$form.'","'.$unameele
                    877:          .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909     raeburn   878:          .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871     raeburn   879:          ."'>".$linktext.'</a>'
1.787     bisitz    880:          .'</span>';
1.74      www       881: }
1.42      matthew   882: 
1.653     raeburn   883: sub selectauthor_link {
                    884:    my ($form,$udom)=@_;
                    885:    return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
                    886:           &mt('Select Author').'</a>';
                    887: }
                    888: 
1.876     raeburn   889: sub selectuser_link {
1.881     raeburn   890:     my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888     raeburn   891:         $coursedom,$linktext,$caller) = @_;
1.876     raeburn   892:     return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888     raeburn   893:            "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881     raeburn   894:            ');">'.$linktext.'</a>';
1.876     raeburn   895: }
                    896: 
1.273     raeburn   897: sub check_uncheck_jscript {
                    898:     my $jscript = <<"ENDSCRT";
                    899: function checkAll(field) {
                    900:     if (field.length > 0) {
                    901:         for (i = 0; i < field.length; i++) {
1.1075.2.14  raeburn   902:             if (!field[i].disabled) {
                    903:                 field[i].checked = true;
                    904:             }
1.273     raeburn   905:         }
                    906:     } else {
1.1075.2.14  raeburn   907:         if (!field.disabled) {
                    908:             field.checked = true;
                    909:         }
1.273     raeburn   910:     }
                    911: }
                    912:  
                    913: function uncheckAll(field) {
                    914:     if (field.length > 0) {
                    915:         for (i = 0; i < field.length; i++) {
                    916:             field[i].checked = false ;
1.543     albertel  917:         }
                    918:     } else {
1.273     raeburn   919:         field.checked = false ;
                    920:     }
                    921: }
                    922: ENDSCRT
                    923:     return $jscript;
                    924: }
                    925: 
1.656     www       926: sub select_timezone {
1.659     raeburn   927:    my ($name,$selected,$onchange,$includeempty)=@_;
                    928:    my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    929:    if ($includeempty) {
                    930:        $output .= '<option value=""';
                    931:        if (($selected eq '') || ($selected eq 'local')) {
                    932:            $output .= ' selected="selected" ';
                    933:        }
                    934:        $output .= '> </option>';
                    935:    }
1.657     raeburn   936:    my @timezones = DateTime::TimeZone->all_names;
                    937:    foreach my $tzone (@timezones) {
                    938:        $output.= '<option value="'.$tzone.'"';
                    939:        if ($tzone eq $selected) {
                    940:            $output.=' selected="selected"';
                    941:        }
                    942:        $output.=">$tzone</option>\n";
1.656     www       943:    }
                    944:    $output.="</select>";
                    945:    return $output;
                    946: }
1.273     raeburn   947: 
1.687     raeburn   948: sub select_datelocale {
                    949:     my ($name,$selected,$onchange,$includeempty)=@_;
                    950:     my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    951:     if ($includeempty) {
                    952:         $output .= '<option value=""';
                    953:         if ($selected eq '') {
                    954:             $output .= ' selected="selected" ';
                    955:         }
                    956:         $output .= '> </option>';
                    957:     }
                    958:     my (@possibles,%locale_names);
                    959:     my @locales = DateTime::Locale::Catalog::Locales;
                    960:     foreach my $locale (@locales) {
                    961:         if (ref($locale) eq 'HASH') {
                    962:             my $id = $locale->{'id'};
                    963:             if ($id ne '') {
                    964:                 my $en_terr = $locale->{'en_territory'};
                    965:                 my $native_terr = $locale->{'native_territory'};
1.695     raeburn   966:                 my @languages = &Apache::lonlocal::preferred_languages();
1.687     raeburn   967:                 if (grep(/^en$/,@languages) || !@languages) {
                    968:                     if ($en_terr ne '') {
                    969:                         $locale_names{$id} = '('.$en_terr.')';
                    970:                     } elsif ($native_terr ne '') {
                    971:                         $locale_names{$id} = $native_terr;
                    972:                     }
                    973:                 } else {
                    974:                     if ($native_terr ne '') {
                    975:                         $locale_names{$id} = $native_terr.' ';
                    976:                     } elsif ($en_terr ne '') {
                    977:                         $locale_names{$id} = '('.$en_terr.')';
                    978:                     }
                    979:                 }
                    980:                 push (@possibles,$id);
                    981:             }
                    982:         }
                    983:     }
                    984:     foreach my $item (sort(@possibles)) {
                    985:         $output.= '<option value="'.$item.'"';
                    986:         if ($item eq $selected) {
                    987:             $output.=' selected="selected"';
                    988:         }
                    989:         $output.=">$item";
                    990:         if ($locale_names{$item} ne '') {
                    991:             $output.="  $locale_names{$item}</option>\n";
                    992:         }
                    993:         $output.="</option>\n";
                    994:     }
                    995:     $output.="</select>";
                    996:     return $output;
                    997: }
                    998: 
1.792     raeburn   999: sub select_language {
                   1000:     my ($name,$selected,$includeempty) = @_;
                   1001:     my %langchoices;
                   1002:     if ($includeempty) {
1.1075.2.32  raeburn  1003:         %langchoices = ('' => 'No language preference');
1.792     raeburn  1004:     }
                   1005:     foreach my $id (&languageids()) {
                   1006:         my $code = &supportedlanguagecode($id);
                   1007:         if ($code) {
                   1008:             $langchoices{$code} = &plainlanguagedescription($id);
                   1009:         }
                   1010:     }
1.1075.2.32  raeburn  1011:     %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.970     raeburn  1012:     return &select_form($selected,$name,\%langchoices);
1.792     raeburn  1013: }
                   1014: 
1.42      matthew  1015: =pod
1.36      matthew  1016: 
1.648     raeburn  1017: =item * &linked_select_forms(...)
1.36      matthew  1018: 
                   1019: linked_select_forms returns a string containing a <script></script> block
                   1020: and html for two <select> menus.  The select menus will be linked in that
                   1021: changing the value of the first menu will result in new values being placed
                   1022: in the second menu.  The values in the select menu will appear in alphabetical
1.609     raeburn  1023: order unless a defined order is provided.
1.36      matthew  1024: 
                   1025: linked_select_forms takes the following ordered inputs:
                   1026: 
                   1027: =over 4
                   1028: 
1.112     bowersj2 1029: =item * $formname, the name of the <form> tag
1.36      matthew  1030: 
1.112     bowersj2 1031: =item * $middletext, the text which appears between the <select> tags
1.36      matthew  1032: 
1.112     bowersj2 1033: =item * $firstdefault, the default value for the first menu
1.36      matthew  1034: 
1.112     bowersj2 1035: =item * $firstselectname, the name of the first <select> tag
1.36      matthew  1036: 
1.112     bowersj2 1037: =item * $secondselectname, the name of the second <select> tag
1.36      matthew  1038: 
1.112     bowersj2 1039: =item * $hashref, a reference to a hash containing the data for the menus.
1.36      matthew  1040: 
1.609     raeburn  1041: =item * $menuorder, the order of values in the first menu
                   1042: 
1.1075.2.31  raeburn  1043: =item * $onchangefirst, additional javascript call to execute for an onchange
                   1044:         event for the first <select> tag
                   1045: 
                   1046: =item * $onchangesecond, additional javascript call to execute for an onchange
                   1047:         event for the second <select> tag
                   1048: 
1.41      ng       1049: =back 
                   1050: 
1.36      matthew  1051: Below is an example of such a hash.  Only the 'text', 'default', and 
                   1052: 'select2' keys must appear as stated.  keys(%menu) are the possible 
                   1053: values for the first select menu.  The text that coincides with the 
1.41      ng       1054: first menu value is given in $menu{$choice1}->{'text'}.  The values 
1.36      matthew  1055: and text for the second menu are given in the hash pointed to by 
                   1056: $menu{$choice1}->{'select2'}.  
                   1057: 
1.112     bowersj2 1058:  my %menu = ( A1 => { text =>"Choice A1" ,
                   1059:                        default => "B3",
                   1060:                        select2 => { 
                   1061:                            B1 => "Choice B1",
                   1062:                            B2 => "Choice B2",
                   1063:                            B3 => "Choice B3",
                   1064:                            B4 => "Choice B4"
1.609     raeburn  1065:                            },
                   1066:                        order => ['B4','B3','B1','B2'],
1.112     bowersj2 1067:                    },
                   1068:                A2 => { text =>"Choice A2" ,
                   1069:                        default => "C2",
                   1070:                        select2 => { 
                   1071:                            C1 => "Choice C1",
                   1072:                            C2 => "Choice C2",
                   1073:                            C3 => "Choice C3"
1.609     raeburn  1074:                            },
                   1075:                        order => ['C2','C1','C3'],
1.112     bowersj2 1076:                    },
                   1077:                A3 => { text =>"Choice A3" ,
                   1078:                        default => "D6",
                   1079:                        select2 => { 
                   1080:                            D1 => "Choice D1",
                   1081:                            D2 => "Choice D2",
                   1082:                            D3 => "Choice D3",
                   1083:                            D4 => "Choice D4",
                   1084:                            D5 => "Choice D5",
                   1085:                            D6 => "Choice D6",
                   1086:                            D7 => "Choice D7"
1.609     raeburn  1087:                            },
                   1088:                        order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112     bowersj2 1089:                    }
                   1090:                );
1.36      matthew  1091: 
                   1092: =cut
                   1093: 
                   1094: sub linked_select_forms {
                   1095:     my ($formname,
                   1096:         $middletext,
                   1097:         $firstdefault,
                   1098:         $firstselectname,
                   1099:         $secondselectname, 
1.609     raeburn  1100:         $hashref,
                   1101:         $menuorder,
1.1075.2.31  raeburn  1102:         $onchangefirst,
                   1103:         $onchangesecond
1.36      matthew  1104:         ) = @_;
                   1105:     my $second = "document.$formname.$secondselectname";
                   1106:     my $first = "document.$formname.$firstselectname";
                   1107:     # output the javascript to do the changing
                   1108:     my $result = '';
1.776     bisitz   1109:     $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824     bisitz   1110:     $result.="// <![CDATA[\n";
1.36      matthew  1111:     $result.="var select2data = new Object();\n";
                   1112:     $" = '","';
                   1113:     my $debug = '';
                   1114:     foreach my $s1 (sort(keys(%$hashref))) {
                   1115:         $result.="select2data.d_$s1 = new Object();\n";        
                   1116:         $result.="select2data.d_$s1.def = new String('".
                   1117:             $hashref->{$s1}->{'default'}."');\n";
1.609     raeburn  1118:         $result.="select2data.d_$s1.values = new Array(";
1.36      matthew  1119:         my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609     raeburn  1120:         if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
                   1121:             @s2values = @{$hashref->{$s1}->{'order'}};
                   1122:         }
1.36      matthew  1123:         $result.="\"@s2values\");\n";
                   1124:         $result.="select2data.d_$s1.texts = new Array(";        
                   1125:         my @s2texts;
                   1126:         foreach my $value (@s2values) {
                   1127:             push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
                   1128:         }
                   1129:         $result.="\"@s2texts\");\n";
                   1130:     }
                   1131:     $"=' ';
                   1132:     $result.= <<"END";
                   1133: 
                   1134: function select1_changed() {
                   1135:     // Determine new choice
                   1136:     var newvalue = "d_" + $first.value;
                   1137:     // update select2
                   1138:     var values     = select2data[newvalue].values;
                   1139:     var texts      = select2data[newvalue].texts;
                   1140:     var select2def = select2data[newvalue].def;
                   1141:     var i;
                   1142:     // out with the old
                   1143:     for (i = 0; i < $second.options.length; i++) {
                   1144:         $second.options[i] = null;
                   1145:     }
                   1146:     // in with the nuclear
                   1147:     for (i=0;i<values.length; i++) {
                   1148:         $second.options[i] = new Option(values[i]);
1.143     matthew  1149:         $second.options[i].value = values[i];
1.36      matthew  1150:         $second.options[i].text = texts[i];
                   1151:         if (values[i] == select2def) {
                   1152:             $second.options[i].selected = true;
                   1153:         }
                   1154:     }
                   1155: }
1.824     bisitz   1156: // ]]>
1.36      matthew  1157: </script>
                   1158: END
                   1159:     # output the initial values for the selection lists
1.1075.2.31  raeburn  1160:     $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed();$onchangefirst\">\n";
1.609     raeburn  1161:     my @order = sort(keys(%{$hashref}));
                   1162:     if (ref($menuorder) eq 'ARRAY') {
                   1163:         @order = @{$menuorder};
                   1164:     }
                   1165:     foreach my $value (@order) {
1.36      matthew  1166:         $result.="    <option value=\"$value\" ";
1.253     albertel 1167:         $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119     www      1168:         $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36      matthew  1169:     }
                   1170:     $result .= "</select>\n";
                   1171:     my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
                   1172:     $result .= $middletext;
1.1075.2.31  raeburn  1173:     $result .= "<select size=\"1\" name=\"$secondselectname\"";
                   1174:     if ($onchangesecond) {
                   1175:         $result .= ' onchange="'.$onchangesecond.'"';
                   1176:     }
                   1177:     $result .= ">\n";
1.36      matthew  1178:     my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609     raeburn  1179:     
                   1180:     my @secondorder = sort(keys(%select2));
                   1181:     if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
                   1182:         @secondorder = @{$hashref->{$firstdefault}->{'order'}};
                   1183:     }
                   1184:     foreach my $value (@secondorder) {
1.36      matthew  1185:         $result.="    <option value=\"$value\" ";        
1.253     albertel 1186:         $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119     www      1187:         $result.=">".&mt($select2{$value})."</option>\n";
1.36      matthew  1188:     }
                   1189:     $result .= "</select>\n";
                   1190:     #    return $debug;
                   1191:     return $result;
                   1192: }   #  end of sub linked_select_forms {
                   1193: 
1.45      matthew  1194: =pod
1.44      bowersj2 1195: 
1.973     raeburn  1196: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44      bowersj2 1197: 
1.112     bowersj2 1198: Returns a string corresponding to an HTML link to the given help
                   1199: $topic, where $topic corresponds to the name of a .tex file in
                   1200: /home/httpd/html/adm/help/tex, with underscores replaced by
                   1201: spaces. 
                   1202: 
                   1203: $text will optionally be linked to the same topic, allowing you to
                   1204: link text in addition to the graphic. If you do not want to link
                   1205: text, but wish to specify one of the later parameters, pass an
                   1206: empty string. 
                   1207: 
                   1208: $stayOnPage is a value that will be interpreted as a boolean. If true,
                   1209: the link will not open a new window. If false, the link will open
                   1210: a new window using Javascript. (Default is false.) 
                   1211: 
                   1212: $width and $height are optional numerical parameters that will
                   1213: override the width and height of the popped up window, which may
1.973     raeburn  1214: be useful for certain help topics with big pictures included.
                   1215: 
                   1216: $imgid is the id of the img tag used for the help icon. This may be
                   1217: used in a javascript call to switch the image src.  See 
                   1218: lonhtmlcommon::htmlareaselectactive() for an example.
1.44      bowersj2 1219: 
                   1220: =cut
                   1221: 
                   1222: sub help_open_topic {
1.973     raeburn  1223:     my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48      bowersj2 1224:     $text = "" if (not defined $text);
1.44      bowersj2 1225:     $stayOnPage = 0 if (not defined $stayOnPage);
1.1033    www      1226:     $width = 500 if (not defined $width);
1.44      bowersj2 1227:     $height = 400 if (not defined $height);
                   1228:     my $filename = $topic;
                   1229:     $filename =~ s/ /_/g;
                   1230: 
1.48      bowersj2 1231:     my $template = "";
                   1232:     my $link;
1.572     banghart 1233:     
1.159     www      1234:     $topic=~s/\W/\_/g;
1.44      bowersj2 1235: 
1.572     banghart 1236:     if (!$stayOnPage) {
1.1075.2.50  raeburn  1237:         if ($env{'browser.mobile'}) {
                   1238: 	    $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
                   1239:         } else {
                   1240:             $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1241:         }
1.1037    www      1242:     } elsif ($stayOnPage eq 'popup') {
                   1243:         $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 1244:     } else {
1.48      bowersj2 1245: 	$link = "/adm/help/${filename}.hlp";
                   1246:     }
                   1247: 
                   1248:     # Add the text
1.755     neumanie 1249:     if ($text ne "") {	
1.763     bisitz   1250: 	$template.='<span class="LC_help_open_topic">'
                   1251:                   .'<a target="_top" href="'.$link.'">'
                   1252:                   .$text.'</a>';
1.48      bowersj2 1253:     }
                   1254: 
1.763     bisitz   1255:     # (Always) Add the graphic
1.179     matthew  1256:     my $title = &mt('Online Help');
1.667     raeburn  1257:     my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973     raeburn  1258:     if ($imgid ne '') {
                   1259:         $imgid = ' id="'.$imgid.'"';
                   1260:     }
1.763     bisitz   1261:     $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
                   1262:               .'<img src="'.$helpicon.'" border="0"'
                   1263:               .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973     raeburn  1264:               .' title="'.$title.'" style="vertical-align:middle;"'.$imgid 
1.763     bisitz   1265:               .' /></a>';
                   1266:     if ($text ne "") {	
                   1267:         $template.='</span>';
                   1268:     }
1.44      bowersj2 1269:     return $template;
                   1270: 
1.106     bowersj2 1271: }
                   1272: 
                   1273: # This is a quicky function for Latex cheatsheet editing, since it 
                   1274: # appears in at least four places
                   1275: sub helpLatexCheatsheet {
1.1037    www      1276:     my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732     raeburn  1277:     my $out;
1.106     bowersj2 1278:     my $addOther = '';
1.732     raeburn  1279:     if ($topic) {
1.1037    www      1280: 	$addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763     bisitz   1281:     }
                   1282:     $out = '<span>' # Start cheatsheet
                   1283: 	  .$addOther
                   1284:           .'<span>'
1.1037    www      1285: 	  .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763     bisitz   1286: 	  .'</span> <span>'
1.1037    www      1287: 	  .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763     bisitz   1288: 	  .'</span>';
1.732     raeburn  1289:     unless ($not_author) {
1.763     bisitz   1290:         $out .= ' <span>'
1.1037    www      1291: 	       .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1.763     bisitz   1292: 	       .'</span>';
1.732     raeburn  1293:     }
1.763     bisitz   1294:     $out .= '</span>'; # End cheatsheet
1.732     raeburn  1295:     return $out;
1.172     www      1296: }
                   1297: 
1.430     albertel 1298: sub general_help {
                   1299:     my $helptopic='Student_Intro';
                   1300:     if ($env{'request.role'}=~/^(ca|au)/) {
                   1301: 	$helptopic='Authoring_Intro';
1.907     raeburn  1302:     } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430     albertel 1303: 	$helptopic='Course_Coordination_Intro';
1.672     raeburn  1304:     } elsif ($env{'request.role'}=~/^dc/) {
                   1305:         $helptopic='Domain_Coordination_Intro';
1.430     albertel 1306:     }
                   1307:     return $helptopic;
                   1308: }
                   1309: 
                   1310: sub update_help_link {
                   1311:     my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
                   1312:     my $origurl = $ENV{'REQUEST_URI'};
                   1313:     $origurl=~s|^/~|/priv/|;
                   1314:     my $timestamp = time;
                   1315:     foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
                   1316:         $$datum = &escape($$datum);
                   1317:     }
                   1318: 
                   1319:     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";
                   1320:     my $output .= <<"ENDOUTPUT";
                   1321: <script type="text/javascript">
1.824     bisitz   1322: // <![CDATA[
1.430     albertel 1323: banner_link = '$banner_link';
1.824     bisitz   1324: // ]]>
1.430     albertel 1325: </script>
                   1326: ENDOUTPUT
                   1327:     return $output;
                   1328: }
                   1329: 
                   1330: # now just updates the help link and generates a blue icon
1.193     raeburn  1331: sub help_open_menu {
1.430     albertel 1332:     my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text) 
1.552     banghart 1333: 	= @_;    
1.949     droeschl 1334:     $stayOnPage = 1;
1.430     albertel 1335:     my $output;
                   1336:     if ($component_help) {
                   1337: 	if (!$text) {
                   1338: 	    $output=&help_open_topic($component_help,undef,$stayOnPage,
                   1339: 				       $width,$height);
                   1340: 	} else {
                   1341: 	    my $help_text;
                   1342: 	    $help_text=&unescape($topic);
                   1343: 	    $output='<table><tr><td>'.
                   1344: 		&help_open_topic($component_help,$help_text,$stayOnPage,
                   1345: 				 $width,$height).'</td></tr></table>';
                   1346: 	}
                   1347:     }
                   1348:     my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
                   1349:     return $output.$banner_link;
                   1350: }
                   1351: 
                   1352: sub top_nav_help {
                   1353:     my ($text) = @_;
1.436     albertel 1354:     $text = &mt($text);
1.949     droeschl 1355:     my $stay_on_page = 1;
                   1356: 
1.572     banghart 1357:     my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436     albertel 1358: 	                     : "javascript:helpMenu('open')";
1.572     banghart 1359:     my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436     albertel 1360: 
1.201     raeburn  1361:     my $title = &mt('Get help');
1.436     albertel 1362: 
                   1363:     return <<"END";
                   1364: $banner_link
                   1365:  <a href="$link" title="$title">$text</a>
                   1366: END
                   1367: }
                   1368: 
                   1369: sub help_menu_js {
1.1075.2.52! raeburn  1370:     my ($httphost) = @_;
1.949     droeschl 1371:     my $stayOnPage = 1;
1.436     albertel 1372:     my $width = 620;
                   1373:     my $height = 600;
1.430     albertel 1374:     my $helptopic=&general_help();
1.1075.2.52! raeburn  1375:     my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261     albertel 1376:     my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331     albertel 1377:     my $start_page =
                   1378:         &Apache::loncommon::start_page('Help Menu', undef,
                   1379: 				       {'frameset'    => 1,
                   1380: 					'js_ready'    => 1,
1.1075.2.52! raeburn  1381:                                         'use_absolute' => $httphost, 
1.331     albertel 1382: 					'add_entries' => {
                   1383: 					    'border' => '0',
1.579     raeburn  1384: 					    'rows'   => "110,*",},});
1.331     albertel 1385:     my $end_page =
                   1386:         &Apache::loncommon::end_page({'frameset' => 1,
                   1387: 				      'js_ready' => 1,});
                   1388: 
1.436     albertel 1389:     my $template .= <<"ENDTEMPLATE";
                   1390: <script type="text/javascript">
1.877     bisitz   1391: // <![CDATA[
1.253     albertel 1392: // <!-- BEGIN LON-CAPA Internal
1.430     albertel 1393: var banner_link = '';
1.243     raeburn  1394: function helpMenu(target) {
                   1395:     var caller = this;
                   1396:     if (target == 'open') {
                   1397:         var newWindow = null;
                   1398:         try {
1.262     albertel 1399:             newWindow =  window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243     raeburn  1400:         }
                   1401:         catch(error) {
                   1402:             writeHelp(caller);
                   1403:             return;
                   1404:         }
                   1405:         if (newWindow) {
                   1406:             caller = newWindow;
                   1407:         }
1.193     raeburn  1408:     }
1.243     raeburn  1409:     writeHelp(caller);
                   1410:     return;
                   1411: }
                   1412: function writeHelp(caller) {
1.1072    raeburn  1413:     caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" />\\n<frame name="bodyframe" src="$details_link" />\\n$end_page')
1.243     raeburn  1414:     caller.document.close()
                   1415:     caller.focus()
1.193     raeburn  1416: }
1.877     bisitz   1417: // END LON-CAPA Internal -->
1.253     albertel 1418: // ]]>
1.436     albertel 1419: </script>
1.193     raeburn  1420: ENDTEMPLATE
                   1421:     return $template;
                   1422: }
                   1423: 
1.172     www      1424: sub help_open_bug {
                   1425:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1426:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1427:     unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
                   1428:     $text = "" if (not defined $text);
                   1429: 	$stayOnPage=1;
1.184     albertel 1430:     $width = 600 if (not defined $width);
                   1431:     $height = 600 if (not defined $height);
1.172     www      1432: 
                   1433:     $topic=~s/\W+/\+/g;
                   1434:     my $link='';
                   1435:     my $template='';
1.379     albertel 1436:     my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&amp;bug_file_loc='.
                   1437: 	&escape($ENV{'REQUEST_URI'}).'&amp;component='.$topic;
1.172     www      1438:     if (!$stayOnPage)
                   1439:     {
                   1440: 	$link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1441:     }
                   1442:     else
                   1443:     {
                   1444: 	$link = $url;
                   1445:     }
                   1446:     # Add the text
                   1447:     if ($text ne "")
                   1448:     {
                   1449: 	$template .= 
                   1450:   "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1451:   "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172     www      1452:     }
                   1453: 
                   1454:     # Add the graphic
1.179     matthew  1455:     my $title = &mt('Report a Bug');
1.215     albertel 1456:     my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172     www      1457:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1458:  <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172     www      1459: ENDTEMPLATE
                   1460:     if ($text ne '') { $template.='</td></tr></table>' };
                   1461:     return $template;
                   1462: 
                   1463: }
                   1464: 
                   1465: sub help_open_faq {
                   1466:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1467:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1468:     unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
                   1469:     $text = "" if (not defined $text);
                   1470: 	$stayOnPage=1;
                   1471:     $width = 350 if (not defined $width);
                   1472:     $height = 400 if (not defined $height);
                   1473: 
                   1474:     $topic=~s/\W+/\+/g;
                   1475:     my $link='';
                   1476:     my $template='';
                   1477:     my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
                   1478:     if (!$stayOnPage)
                   1479:     {
                   1480: 	$link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1481:     }
                   1482:     else
                   1483:     {
                   1484: 	$link = $url;
                   1485:     }
                   1486: 
                   1487:     # Add the text
                   1488:     if ($text ne "")
                   1489:     {
                   1490: 	$template .= 
1.173     www      1491:   "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1492:   "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172     www      1493:     }
                   1494: 
                   1495:     # Add the graphic
1.179     matthew  1496:     my $title = &mt('View the FAQ');
1.215     albertel 1497:     my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172     www      1498:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1499:  <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172     www      1500: ENDTEMPLATE
                   1501:     if ($text ne '') { $template.='</td></tr></table>' };
                   1502:     return $template;
                   1503: 
1.44      bowersj2 1504: }
1.37      matthew  1505: 
1.180     matthew  1506: ###############################################################
                   1507: ###############################################################
                   1508: 
1.45      matthew  1509: =pod
                   1510: 
1.648     raeburn  1511: =item * &change_content_javascript():
1.256     matthew  1512: 
                   1513: This and the next function allow you to create small sections of an
                   1514: otherwise static HTML page that you can update on the fly with
                   1515: Javascript, even in Netscape 4.
                   1516: 
                   1517: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
                   1518: must be written to the HTML page once. It will prove the Javascript
                   1519: function "change(name, content)". Calling the change function with the
                   1520: name of the section 
                   1521: you want to update, matching the name passed to C<changable_area>, and
                   1522: the new content you want to put in there, will put the content into
                   1523: that area.
                   1524: 
                   1525: B<Note>: Netscape 4 only reserves enough space for the changable area
                   1526: to contain room for the original contents. You need to "make space"
                   1527: for whatever changes you wish to make, and be B<sure> to check your
                   1528: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
                   1529: it's adequate for updating a one-line status display, but little more.
                   1530: This script will set the space to 100% width, so you only need to
                   1531: worry about height in Netscape 4.
                   1532: 
                   1533: Modern browsers are much less limiting, and if you can commit to the
                   1534: user not using Netscape 4, this feature may be used freely with
                   1535: pretty much any HTML.
                   1536: 
                   1537: =cut
                   1538: 
                   1539: sub change_content_javascript {
                   1540:     # If we're on Netscape 4, we need to use Layer-based code
1.258     albertel 1541:     if ($env{'browser.type'} eq 'netscape' &&
                   1542: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1543: 	return (<<NETSCAPE4);
                   1544: 	function change(name, content) {
                   1545: 	    doc = document.layers[name+"___escape"].layers[0].document;
                   1546: 	    doc.open();
                   1547: 	    doc.write(content);
                   1548: 	    doc.close();
                   1549: 	}
                   1550: NETSCAPE4
                   1551:     } else {
                   1552: 	# Otherwise, we need to use semi-standards-compliant code
                   1553: 	# (technically, "innerHTML" isn't standard but the equivalent
                   1554: 	# is really scary, and every useful browser supports it
                   1555: 	return (<<DOMBASED);
                   1556: 	function change(name, content) {
                   1557: 	    element = document.getElementById(name);
                   1558: 	    element.innerHTML = content;
                   1559: 	}
                   1560: DOMBASED
                   1561:     }
                   1562: }
                   1563: 
                   1564: =pod
                   1565: 
1.648     raeburn  1566: =item * &changable_area($name,$origContent):
1.256     matthew  1567: 
                   1568: This provides a "changable area" that can be modified on the fly via
                   1569: the Javascript code provided in C<change_content_javascript>. $name is
                   1570: the name you will use to reference the area later; do not repeat the
                   1571: same name on a given HTML page more then once. $origContent is what
                   1572: the area will originally contain, which can be left blank.
                   1573: 
                   1574: =cut
                   1575: 
                   1576: sub changable_area {
                   1577:     my ($name, $origContent) = @_;
                   1578: 
1.258     albertel 1579:     if ($env{'browser.type'} eq 'netscape' &&
                   1580: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1581: 	# If this is netscape 4, we need to use the Layer tag
                   1582: 	return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
                   1583:     } else {
                   1584: 	return "<span id='$name'>$origContent</span>";
                   1585:     }
                   1586: }
                   1587: 
                   1588: =pod
                   1589: 
1.648     raeburn  1590: =item * &viewport_geometry_js 
1.590     raeburn  1591: 
                   1592: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
                   1593: 
                   1594: =cut
                   1595: 
                   1596: 
                   1597: sub viewport_geometry_js { 
                   1598:     return <<"GEOMETRY";
                   1599: var Geometry = {};
                   1600: function init_geometry() {
                   1601:     if (Geometry.init) { return };
                   1602:     Geometry.init=1;
                   1603:     if (window.innerHeight) {
                   1604:         Geometry.getViewportHeight   = function() { return window.innerHeight; };
                   1605:         Geometry.getViewportWidth   = function() { return window.innerWidth; };
                   1606:         Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
                   1607:         Geometry.getVerticalScroll   = function() { return window.pageYOffset; };
                   1608:     }
                   1609:     else if (document.documentElement && document.documentElement.clientHeight) {
                   1610:         Geometry.getViewportHeight =
                   1611:             function() { return document.documentElement.clientHeight; };
                   1612:         Geometry.getViewportWidth =
                   1613:             function() { return document.documentElement.clientWidth; };
                   1614: 
                   1615:         Geometry.getHorizontalScroll =
                   1616:             function() { return document.documentElement.scrollLeft; };
                   1617:         Geometry.getVerticalScroll =
                   1618:             function() { return document.documentElement.scrollTop; };
                   1619:     }
                   1620:     else if (document.body.clientHeight) {
                   1621:         Geometry.getViewportHeight =
                   1622:             function() { return document.body.clientHeight; };
                   1623:         Geometry.getViewportWidth =
                   1624:             function() { return document.body.clientWidth; };
                   1625:         Geometry.getHorizontalScroll =
                   1626:             function() { return document.body.scrollLeft; };
                   1627:         Geometry.getVerticalScroll =
                   1628:             function() { return document.body.scrollTop; };
                   1629:     }
                   1630: }
                   1631: 
                   1632: GEOMETRY
                   1633: }
                   1634: 
                   1635: =pod
                   1636: 
1.648     raeburn  1637: =item * &viewport_size_js()
1.590     raeburn  1638: 
                   1639: 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. 
                   1640: 
                   1641: =cut
                   1642: 
                   1643: sub viewport_size_js {
                   1644:     my $geometry = &viewport_geometry_js();
                   1645:     return <<"DIMS";
                   1646: 
                   1647: $geometry
                   1648: 
                   1649: function getViewportDims(width,height) {
                   1650:     init_geometry();
                   1651:     width.value = Geometry.getViewportWidth();
                   1652:     height.value = Geometry.getViewportHeight();
                   1653:     return;
                   1654: }
                   1655: 
                   1656: DIMS
                   1657: }
                   1658: 
                   1659: =pod
                   1660: 
1.648     raeburn  1661: =item * &resize_textarea_js()
1.565     albertel 1662: 
                   1663: emits the needed javascript to resize a textarea to be as big as possible
                   1664: 
                   1665: creates a function resize_textrea that takes two IDs first should be
                   1666: the id of the element to resize, second should be the id of a div that
                   1667: surrounds everything that comes after the textarea, this routine needs
                   1668: to be attached to the <body> for the onload and onresize events.
                   1669: 
1.648     raeburn  1670: =back
1.565     albertel 1671: 
                   1672: =cut
                   1673: 
                   1674: sub resize_textarea_js {
1.590     raeburn  1675:     my $geometry = &viewport_geometry_js();
1.565     albertel 1676:     return <<"RESIZE";
                   1677:     <script type="text/javascript">
1.824     bisitz   1678: // <![CDATA[
1.590     raeburn  1679: $geometry
1.565     albertel 1680: 
1.588     albertel 1681: function getX(element) {
                   1682:     var x = 0;
                   1683:     while (element) {
                   1684: 	x += element.offsetLeft;
                   1685: 	element = element.offsetParent;
                   1686:     }
                   1687:     return x;
                   1688: }
                   1689: function getY(element) {
                   1690:     var y = 0;
                   1691:     while (element) {
                   1692: 	y += element.offsetTop;
                   1693: 	element = element.offsetParent;
                   1694:     }
                   1695:     return y;
                   1696: }
                   1697: 
                   1698: 
1.565     albertel 1699: function resize_textarea(textarea_id,bottom_id) {
                   1700:     init_geometry();
                   1701:     var textarea        = document.getElementById(textarea_id);
                   1702:     //alert(textarea);
                   1703: 
1.588     albertel 1704:     var textarea_top    = getY(textarea);
1.565     albertel 1705:     var textarea_height = textarea.offsetHeight;
                   1706:     var bottom          = document.getElementById(bottom_id);
1.588     albertel 1707:     var bottom_top      = getY(bottom);
1.565     albertel 1708:     var bottom_height   = bottom.offsetHeight;
                   1709:     var window_height   = Geometry.getViewportHeight();
1.588     albertel 1710:     var fudge           = 23;
1.565     albertel 1711:     var new_height      = window_height-fudge-textarea_top-bottom_height;
                   1712:     if (new_height < 300) {
                   1713: 	new_height = 300;
                   1714:     }
                   1715:     textarea.style.height=new_height+'px';
                   1716: }
1.824     bisitz   1717: // ]]>
1.565     albertel 1718: </script>
                   1719: RESIZE
                   1720: 
                   1721: }
                   1722: 
                   1723: =pod
                   1724: 
1.256     matthew  1725: =head1 Excel and CSV file utility routines
                   1726: 
                   1727: =over 4
                   1728: 
                   1729: =cut
                   1730: 
                   1731: ###############################################################
                   1732: ###############################################################
                   1733: 
                   1734: =pod
                   1735: 
1.648     raeburn  1736: =item * &csv_translate($text) 
1.37      matthew  1737: 
1.185     www      1738: Translate $text to allow it to be output as a 'comma separated values' 
1.37      matthew  1739: format.
                   1740: 
                   1741: =cut
                   1742: 
1.180     matthew  1743: ###############################################################
                   1744: ###############################################################
1.37      matthew  1745: sub csv_translate {
                   1746:     my $text = shift;
                   1747:     $text =~ s/\"/\"\"/g;
1.209     albertel 1748:     $text =~ s/\n/ /g;
1.37      matthew  1749:     return $text;
                   1750: }
1.180     matthew  1751: 
                   1752: ###############################################################
                   1753: ###############################################################
                   1754: 
                   1755: =pod
                   1756: 
1.648     raeburn  1757: =item * &define_excel_formats()
1.180     matthew  1758: 
                   1759: Define some commonly used Excel cell formats.
                   1760: 
                   1761: Currently supported formats:
                   1762: 
                   1763: =over 4
                   1764: 
                   1765: =item header
                   1766: 
                   1767: =item bold
                   1768: 
                   1769: =item h1
                   1770: 
                   1771: =item h2
                   1772: 
                   1773: =item h3
                   1774: 
1.256     matthew  1775: =item h4
                   1776: 
                   1777: =item i
                   1778: 
1.180     matthew  1779: =item date
                   1780: 
                   1781: =back
                   1782: 
                   1783: Inputs: $workbook
                   1784: 
                   1785: Returns: $format, a hash reference.
                   1786: 
1.1057    foxr     1787: 
1.180     matthew  1788: =cut
                   1789: 
                   1790: ###############################################################
                   1791: ###############################################################
                   1792: sub define_excel_formats {
                   1793:     my ($workbook) = @_;
                   1794:     my $format;
                   1795:     $format->{'header'} = $workbook->add_format(bold      => 1, 
                   1796:                                                 bottom    => 1,
                   1797:                                                 align     => 'center');
                   1798:     $format->{'bold'} = $workbook->add_format(bold=>1);
                   1799:     $format->{'h1'}   = $workbook->add_format(bold=>1, size=>18);
                   1800:     $format->{'h2'}   = $workbook->add_format(bold=>1, size=>16);
                   1801:     $format->{'h3'}   = $workbook->add_format(bold=>1, size=>14);
1.255     matthew  1802:     $format->{'h4'}   = $workbook->add_format(bold=>1, size=>12);
1.246     matthew  1803:     $format->{'i'}    = $workbook->add_format(italic=>1);
1.180     matthew  1804:     $format->{'date'} = $workbook->add_format(num_format=>
1.207     matthew  1805:                                             'mm/dd/yyyy hh:mm:ss');
1.180     matthew  1806:     return $format;
                   1807: }
                   1808: 
                   1809: ###############################################################
                   1810: ###############################################################
1.113     bowersj2 1811: 
                   1812: =pod
                   1813: 
1.648     raeburn  1814: =item * &create_workbook()
1.255     matthew  1815: 
                   1816: Create an Excel worksheet.  If it fails, output message on the
                   1817: request object and return undefs.
                   1818: 
                   1819: Inputs: Apache request object
                   1820: 
                   1821: Returns (undef) on failure, 
                   1822:     Excel worksheet object, scalar with filename, and formats 
                   1823:     from &Apache::loncommon::define_excel_formats on success
                   1824: 
                   1825: =cut
                   1826: 
                   1827: ###############################################################
                   1828: ###############################################################
                   1829: sub create_workbook {
                   1830:     my ($r) = @_;
                   1831:         #
                   1832:     # Create the excel spreadsheet
                   1833:     my $filename = '/prtspool/'.
1.258     albertel 1834:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255     matthew  1835:         time.'_'.rand(1000000000).'.xls';
                   1836:     my $workbook  = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
                   1837:     if (! defined($workbook)) {
                   1838:         $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928     bisitz   1839:         $r->print(
                   1840:             '<p class="LC_error">'
                   1841:            .&mt('Problems occurred in creating the new Excel file.')
                   1842:            .' '.&mt('This error has been logged.')
                   1843:            .' '.&mt('Please alert your LON-CAPA administrator.')
                   1844:            .'</p>'
                   1845:         );
1.255     matthew  1846:         return (undef);
                   1847:     }
                   1848:     #
1.1014    foxr     1849:     $workbook->set_tempdir(LONCAPA::tempdir());
1.255     matthew  1850:     #
                   1851:     my $format = &Apache::loncommon::define_excel_formats($workbook);
                   1852:     return ($workbook,$filename,$format);
                   1853: }
                   1854: 
                   1855: ###############################################################
                   1856: ###############################################################
                   1857: 
                   1858: =pod
                   1859: 
1.648     raeburn  1860: =item * &create_text_file()
1.113     bowersj2 1861: 
1.542     raeburn  1862: Create a file to write to and eventually make available to the user.
1.256     matthew  1863: If file creation fails, outputs an error message on the request object and 
                   1864: return undefs.
1.113     bowersj2 1865: 
1.256     matthew  1866: Inputs: Apache request object, and file suffix
1.113     bowersj2 1867: 
1.256     matthew  1868: Returns (undef) on failure, 
                   1869:     Filehandle and filename on success.
1.113     bowersj2 1870: 
                   1871: =cut
                   1872: 
1.256     matthew  1873: ###############################################################
                   1874: ###############################################################
                   1875: sub create_text_file {
                   1876:     my ($r,$suffix) = @_;
                   1877:     if (! defined($suffix)) { $suffix = 'txt'; };
                   1878:     my $fh;
                   1879:     my $filename = '/prtspool/'.
1.258     albertel 1880:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256     matthew  1881:         time.'_'.rand(1000000000).'.'.$suffix;
                   1882:     $fh = Apache::File->new('>/home/httpd'.$filename);
                   1883:     if (! defined($fh)) {
                   1884:         $r->log_error("Couldn't open $filename for output $!");
1.928     bisitz   1885:         $r->print(
                   1886:             '<p class="LC_error">'
                   1887:            .&mt('Problems occurred in creating the output file.')
                   1888:            .' '.&mt('This error has been logged.')
                   1889:            .' '.&mt('Please alert your LON-CAPA administrator.')
                   1890:            .'</p>'
                   1891:         );
1.113     bowersj2 1892:     }
1.256     matthew  1893:     return ($fh,$filename)
1.113     bowersj2 1894: }
                   1895: 
                   1896: 
1.256     matthew  1897: =pod 
1.113     bowersj2 1898: 
                   1899: =back
                   1900: 
                   1901: =cut
1.37      matthew  1902: 
                   1903: ###############################################################
1.33      matthew  1904: ##        Home server <option> list generating code          ##
                   1905: ###############################################################
1.35      matthew  1906: 
1.169     www      1907: # ------------------------------------------
                   1908: 
                   1909: sub domain_select {
                   1910:     my ($name,$value,$multiple)=@_;
                   1911:     my %domains=map { 
1.514     albertel 1912: 	$_ => $_.' '. &Apache::lonnet::domain($_,'description') 
1.512     albertel 1913:     } &Apache::lonnet::all_domains();
1.169     www      1914:     if ($multiple) {
                   1915: 	$domains{''}=&mt('Any domain');
1.550     albertel 1916: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287     albertel 1917: 	return &multiple_select_form($name,$value,4,\%domains);
1.169     www      1918:     } else {
1.550     albertel 1919: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970     raeburn  1920: 	return &select_form($name,$value,\%domains);
1.169     www      1921:     }
                   1922: }
                   1923: 
1.282     albertel 1924: #-------------------------------------------
                   1925: 
                   1926: =pod
                   1927: 
1.519     raeburn  1928: =head1 Routines for form select boxes
                   1929: 
                   1930: =over 4
                   1931: 
1.648     raeburn  1932: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282     albertel 1933: 
                   1934: Returns a string containing a <select> element int multiple mode
                   1935: 
                   1936: 
                   1937: Args:
                   1938:   $name - name of the <select> element
1.506     raeburn  1939:   $value - scalar or array ref of values that should already be selected
1.282     albertel 1940:   $size - number of rows long the select element is
1.283     albertel 1941:   $hash - the elements should be 'option' => 'shown text'
1.282     albertel 1942:           (shown text should already have been &mt())
1.506     raeburn  1943:   $order - (optional) array ref of the order to show the elements in
1.283     albertel 1944: 
1.282     albertel 1945: =cut
                   1946: 
                   1947: #-------------------------------------------
1.169     www      1948: sub multiple_select_form {
1.284     albertel 1949:     my ($name,$value,$size,$hash,$order)=@_;
1.169     www      1950:     my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
                   1951:     my $output='';
1.191     matthew  1952:     if (! defined($size)) {
                   1953:         $size = 4;
1.283     albertel 1954:         if (scalar(keys(%$hash))<4) {
                   1955:             $size = scalar(keys(%$hash));
1.191     matthew  1956:         }
                   1957:     }
1.734     bisitz   1958:     $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501     banghart 1959:     my @order;
1.506     raeburn  1960:     if (ref($order) eq 'ARRAY')  {
                   1961:         @order = @{$order};
                   1962:     } else {
                   1963:         @order = sort(keys(%$hash));
1.501     banghart 1964:     }
                   1965:     if (exists($$hash{'select_form_order'})) {
                   1966:         @order = @{$$hash{'select_form_order'}};
                   1967:     }
                   1968:         
1.284     albertel 1969:     foreach my $key (@order) {
1.356     albertel 1970:         $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284     albertel 1971:         $output.='selected="selected" ' if ($selected{$key});
                   1972:         $output.='>'.$hash->{$key}."</option>\n";
1.169     www      1973:     }
                   1974:     $output.="</select>\n";
                   1975:     return $output;
                   1976: }
                   1977: 
1.88      www      1978: #-------------------------------------------
                   1979: 
                   1980: =pod
                   1981: 
1.970     raeburn  1982: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88      www      1983: 
                   1984: Returns a string containing a <select name='$name' size='1'> form to 
1.970     raeburn  1985: allow a user to select options from a ref to a hash containing:
                   1986: option_name => displayed text. An optional $onchange can include
                   1987: a javascript onchange item, e.g., onchange="this.form.submit();"  
                   1988: 
1.88      www      1989: See lonrights.pm for an example invocation and use.
                   1990: 
                   1991: =cut
                   1992: 
                   1993: #-------------------------------------------
                   1994: sub select_form {
1.970     raeburn  1995:     my ($def,$name,$hashref,$onchange) = @_;
                   1996:     return unless (ref($hashref) eq 'HASH');
                   1997:     if ($onchange) {
                   1998:         $onchange = ' onchange="'.$onchange.'"';
                   1999:     }
                   2000:     my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128     albertel 2001:     my @keys;
1.970     raeburn  2002:     if (exists($hashref->{'select_form_order'})) {
                   2003: 	@keys=@{$hashref->{'select_form_order'}};
1.128     albertel 2004:     } else {
1.970     raeburn  2005: 	@keys=sort(keys(%{$hashref}));
1.128     albertel 2006:     }
1.356     albertel 2007:     foreach my $key (@keys) {
                   2008:         $selectform.=
                   2009: 	    '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
                   2010:             ($key eq $def ? 'selected="selected" ' : '').
1.970     raeburn  2011:                 ">".$hashref->{$key}."</option>\n";
1.88      www      2012:     }
                   2013:     $selectform.="</select>";
                   2014:     return $selectform;
                   2015: }
                   2016: 
1.475     www      2017: # For display filters
                   2018: 
                   2019: sub display_filter {
1.1074    raeburn  2020:     my ($context) = @_;
1.475     www      2021:     if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477     www      2022:     if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074    raeburn  2023:     my $phraseinput = 'hidden';
                   2024:     my $includeinput = 'hidden';
                   2025:     my ($checked,$includetypestext);
                   2026:     if ($env{'form.displayfilter'} eq 'containing') {
                   2027:         $phraseinput = 'text'; 
                   2028:         if ($context eq 'parmslog') {
                   2029:             $includeinput = 'checkbox';
                   2030:             if ($env{'form.includetypes'}) {
                   2031:                 $checked = ' checked="checked"';
                   2032:             }
                   2033:             $includetypestext = &mt('Include parameter types');
                   2034:         }
                   2035:     } else {
                   2036:         $includetypestext = '&nbsp;';
                   2037:     }
                   2038:     my ($additional,$secondid,$thirdid);
                   2039:     if ($context eq 'parmslog') {
                   2040:         $additional = 
                   2041:             '<label><input type="'.$includeinput.'" name="includetypes"'. 
                   2042:             $checked.' name="includetypes" value="1" id="includetypes" />'.
                   2043:             '&nbsp;<span id="includetypestext">'.$includetypestext.'</span>'.
                   2044:             '</label>';
                   2045:         $secondid = 'includetypes';
                   2046:         $thirdid = 'includetypestext';
                   2047:     }
                   2048:     my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
                   2049:                                                     '$secondid','$thirdid')";
                   2050:     return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475     www      2051: 			       &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
                   2052: 							   (&mt('all'),10,20,50,100,1000,10000))).
1.714     bisitz   2053: 	   '</label></span> <span class="LC_nobreak">'.
1.1074    raeburn  2054:            &mt('Filter: [_1]',
1.477     www      2055: 	   &select_form($env{'form.displayfilter'},
                   2056: 			'displayfilter',
1.970     raeburn  2057: 			{'currentfolder' => 'Current folder/page',
1.477     www      2058: 			 'containing' => 'Containing phrase',
1.1074    raeburn  2059: 			 'none' => 'None'},$onchange)).'&nbsp;'.
                   2060: 			 '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
                   2061:                          &HTML::Entities::encode($env{'form.containingphrase'}).
                   2062:                          '" />'.$additional;
                   2063: }
                   2064: 
                   2065: sub display_filter_js {
                   2066:     my $includetext = &mt('Include parameter types');
                   2067:     return <<"ENDJS";
                   2068:   
                   2069: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
                   2070:     var firstType = 'hidden';
                   2071:     if (setter.options[setter.selectedIndex].value == 'containing') {
                   2072:         firstType = 'text';
                   2073:     }
                   2074:     firstObject = document.getElementById(firstid);
                   2075:     if (typeof(firstObject) == 'object') {
                   2076:         if (firstObject.type != firstType) {
                   2077:             changeInputType(firstObject,firstType);
                   2078:         }
                   2079:     }
                   2080:     if (context == 'parmslog') {
                   2081:         var secondType = 'hidden';
                   2082:         if (firstType == 'text') {
                   2083:             secondType = 'checkbox';
                   2084:         }
                   2085:         secondObject = document.getElementById(secondid);  
                   2086:         if (typeof(secondObject) == 'object') {
                   2087:             if (secondObject.type != secondType) {
                   2088:                 changeInputType(secondObject,secondType);
                   2089:             }
                   2090:         }
                   2091:         var textItem = document.getElementById(thirdid);
                   2092:         var currtext = textItem.innerHTML;
                   2093:         var newtext;
                   2094:         if (firstType == 'text') {
                   2095:             newtext = '$includetext';
                   2096:         } else {
                   2097:             newtext = '&nbsp;';
                   2098:         }
                   2099:         if (currtext != newtext) {
                   2100:             textItem.innerHTML = newtext;
                   2101:         }
                   2102:     }
                   2103:     return;
                   2104: }
                   2105: 
                   2106: function changeInputType(oldObject,newType) {
                   2107:     var newObject = document.createElement('input');
                   2108:     newObject.type = newType;
                   2109:     if (oldObject.size) {
                   2110:         newObject.size = oldObject.size;
                   2111:     }
                   2112:     if (oldObject.value) {
                   2113:         newObject.value = oldObject.value;
                   2114:     }
                   2115:     if (oldObject.name) {
                   2116:         newObject.name = oldObject.name;
                   2117:     }
                   2118:     if (oldObject.id) {
                   2119:         newObject.id = oldObject.id;
                   2120:     }
                   2121:     oldObject.parentNode.replaceChild(newObject,oldObject);
                   2122:     return;
                   2123: }
                   2124: 
                   2125: ENDJS
1.475     www      2126: }
                   2127: 
1.167     www      2128: sub gradeleveldescription {
                   2129:     my $gradelevel=shift;
                   2130:     my %gradelevels=(0 => 'Not specified',
                   2131: 		     1 => 'Grade 1',
                   2132: 		     2 => 'Grade 2',
                   2133: 		     3 => 'Grade 3',
                   2134: 		     4 => 'Grade 4',
                   2135: 		     5 => 'Grade 5',
                   2136: 		     6 => 'Grade 6',
                   2137: 		     7 => 'Grade 7',
                   2138: 		     8 => 'Grade 8',
                   2139: 		     9 => 'Grade 9',
                   2140: 		     10 => 'Grade 10',
                   2141: 		     11 => 'Grade 11',
                   2142: 		     12 => 'Grade 12',
                   2143: 		     13 => 'Grade 13',
                   2144: 		     14 => '100 Level',
                   2145: 		     15 => '200 Level',
                   2146: 		     16 => '300 Level',
                   2147: 		     17 => '400 Level',
                   2148: 		     18 => 'Graduate Level');
                   2149:     return &mt($gradelevels{$gradelevel});
                   2150: }
                   2151: 
1.163     www      2152: sub select_level_form {
                   2153:     my ($deflevel,$name)=@_;
                   2154:     unless ($deflevel) { $deflevel=0; }
1.167     www      2155:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
                   2156:     for (my $i=0; $i<=18; $i++) {
                   2157:         $selectform.="<option value=\"$i\" ".
1.253     albertel 2158:             ($i==$deflevel ? 'selected="selected" ' : '').
1.167     www      2159:                 ">".&gradeleveldescription($i)."</option>\n";
                   2160:     }
                   2161:     $selectform.="</select>";
                   2162:     return $selectform;
1.163     www      2163: }
1.167     www      2164: 
1.35      matthew  2165: #-------------------------------------------
                   2166: 
1.45      matthew  2167: =pod
                   2168: 
1.1075.2.42  raeburn  2169: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms)
1.35      matthew  2170: 
                   2171: Returns a string containing a <select name='$name' size='1'> form to 
                   2172: allow a user to select the domain to preform an operation in.  
                   2173: See loncreateuser.pm for an example invocation and use.
                   2174: 
1.90      www      2175: If the $includeempty flag is set, it also includes an empty choice ("no domain
                   2176: selected");
                   2177: 
1.743     raeburn  2178: If the $showdomdesc flag is set, the domain name is followed by the domain description.
                   2179: 
1.910     raeburn  2180: The optional $onchange argument specifies what should occur if the domain selector is changed, e.g., 'this.form.submit()' if the form is to be automatically submitted.
                   2181: 
1.1075.2.36  raeburn  2182: The optional $incdoms is a reference to an array of domains which will be the only available options.
                   2183: 
                   2184: The optional $excdoms is a reference to an array of domains which will be excluded from the available options. 
1.563     raeburn  2185: 
1.35      matthew  2186: =cut
                   2187: 
                   2188: #-------------------------------------------
1.34      matthew  2189: sub select_dom_form {
1.1075.2.36  raeburn  2190:     my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms) = @_;
1.872     raeburn  2191:     if ($onchange) {
1.874     raeburn  2192:         $onchange = ' onchange="'.$onchange.'"';
1.743     raeburn  2193:     }
1.1075.2.36  raeburn  2194:     my (@domains,%exclude);
1.910     raeburn  2195:     if (ref($incdoms) eq 'ARRAY') {
                   2196:         @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
                   2197:     } else {
                   2198:         @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
                   2199:     }
1.90      www      2200:     if ($includeempty) { @domains=('',@domains); }
1.1075.2.36  raeburn  2201:     if (ref($excdoms) eq 'ARRAY') {
                   2202:         map { $exclude{$_} = 1; } @{$excdoms};
                   2203:     }
1.743     raeburn  2204:     my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356     albertel 2205:     foreach my $dom (@domains) {
1.1075.2.36  raeburn  2206:         next if ($exclude{$dom});
1.356     albertel 2207:         $selectdomain.="<option value=\"$dom\" ".
1.563     raeburn  2208:             ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
                   2209:         if ($showdomdesc) {
                   2210:             if ($dom ne '') {
                   2211:                 my $domdesc = &Apache::lonnet::domain($dom,'description');
                   2212:                 if ($domdesc ne '') {
                   2213:                     $selectdomain .= ' ('.$domdesc.')';
                   2214:                 }
                   2215:             } 
                   2216:         }
                   2217:         $selectdomain .= "</option>\n";
1.34      matthew  2218:     }
                   2219:     $selectdomain.="</select>";
                   2220:     return $selectdomain;
                   2221: }
                   2222: 
1.35      matthew  2223: #-------------------------------------------
                   2224: 
1.45      matthew  2225: =pod
                   2226: 
1.648     raeburn  2227: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35      matthew  2228: 
1.586     raeburn  2229: input: 4 arguments (two required, two optional) - 
                   2230:     $domain - domain of new user
                   2231:     $name - name of form element
                   2232:     $default - Value of 'default' causes a default item to be first 
                   2233:                             option, and selected by default. 
                   2234:     $hide - Value of 'hide' causes hiding of the name of the server, 
                   2235:                             if 1 server found, or default, if 0 found.
1.594     raeburn  2236: output: returns 2 items: 
1.586     raeburn  2237: (a) form element which contains either:
                   2238:    (i) <select name="$name">
                   2239:         <option value="$hostid1">$hostid $servers{$hostid}</option>
                   2240:         <option value="$hostid2">$hostid $servers{$hostid}</option>       
                   2241:        </select>
                   2242:        form item if there are multiple library servers in $domain, or
                   2243:    (ii) an <input type="hidden" name="$name" value="$hostid" /> form item 
                   2244:        if there is only one library server in $domain.
                   2245: 
                   2246: (b) number of library servers found.
                   2247: 
                   2248: See loncreateuser.pm for example of use.
1.35      matthew  2249: 
                   2250: =cut
                   2251: 
                   2252: #-------------------------------------------
1.586     raeburn  2253: sub home_server_form_item {
                   2254:     my ($domain,$name,$default,$hide) = @_;
1.513     albertel 2255:     my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586     raeburn  2256:     my $result;
                   2257:     my $numlib = keys(%servers);
                   2258:     if ($numlib > 1) {
                   2259:         $result .= '<select name="'.$name.'" />'."\n";
                   2260:         if ($default) {
1.804     bisitz   2261:             $result .= '<option value="default" selected="selected">'.&mt('default').
1.586     raeburn  2262:                        '</option>'."\n";
                   2263:         }
                   2264:         foreach my $hostid (sort(keys(%servers))) {
                   2265:             $result.= '<option value="'.$hostid.'">'.
                   2266: 	              $hostid.' '.$servers{$hostid}."</option>\n";
                   2267:         }
                   2268:         $result .= '</select>'."\n";
                   2269:     } elsif ($numlib == 1) {
                   2270:         my $hostid;
                   2271:         foreach my $item (keys(%servers)) {
                   2272:             $hostid = $item;
                   2273:         }
                   2274:         $result .= '<input type="hidden" name="'.$name.'" value="'.
                   2275:                    $hostid.'" />';
                   2276:                    if (!$hide) {
                   2277:                        $result .= $hostid.' '.$servers{$hostid};
                   2278:                    }
                   2279:                    $result .= "\n";
                   2280:     } elsif ($default) {
                   2281:         $result .= '<input type="hidden" name="'.$name.
                   2282:                    '" value="default" />';
                   2283:                    if (!$hide) {
                   2284:                        $result .= &mt('default');
                   2285:                    }
                   2286:                    $result .= "\n";
1.33      matthew  2287:     }
1.586     raeburn  2288:     return ($result,$numlib);
1.33      matthew  2289: }
1.112     bowersj2 2290: 
                   2291: =pod
                   2292: 
1.534     albertel 2293: =back 
                   2294: 
1.112     bowersj2 2295: =cut
1.87      matthew  2296: 
                   2297: ###############################################################
1.112     bowersj2 2298: ##                  Decoding User Agent                      ##
1.87      matthew  2299: ###############################################################
                   2300: 
                   2301: =pod
                   2302: 
1.112     bowersj2 2303: =head1 Decoding the User Agent
                   2304: 
                   2305: =over 4
                   2306: 
                   2307: =item * &decode_user_agent()
1.87      matthew  2308: 
                   2309: Inputs: $r
                   2310: 
                   2311: Outputs:
                   2312: 
                   2313: =over 4
                   2314: 
1.112     bowersj2 2315: =item * $httpbrowser
1.87      matthew  2316: 
1.112     bowersj2 2317: =item * $clientbrowser
1.87      matthew  2318: 
1.112     bowersj2 2319: =item * $clientversion
1.87      matthew  2320: 
1.112     bowersj2 2321: =item * $clientmathml
1.87      matthew  2322: 
1.112     bowersj2 2323: =item * $clientunicode
1.87      matthew  2324: 
1.112     bowersj2 2325: =item * $clientos
1.87      matthew  2326: 
1.1075.2.42  raeburn  2327: =item * $clientmobile
                   2328: 
                   2329: =item * $clientinfo
                   2330: 
1.87      matthew  2331: =back
                   2332: 
1.157     matthew  2333: =back 
                   2334: 
1.87      matthew  2335: =cut
                   2336: 
                   2337: ###############################################################
                   2338: ###############################################################
                   2339: sub decode_user_agent {
1.247     albertel 2340:     my ($r)=@_;
1.87      matthew  2341:     my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
                   2342:     my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
                   2343:     my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247     albertel 2344:     if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87      matthew  2345:     my $clientbrowser='unknown';
                   2346:     my $clientversion='0';
                   2347:     my $clientmathml='';
                   2348:     my $clientunicode='0';
1.1075.2.42  raeburn  2349:     my $clientmobile=0;
1.87      matthew  2350:     for (my $i=0;$i<=$#browsertype;$i++) {
                   2351:         my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
                   2352: 	if (($httpbrowser=~/$match/i)  && ($httpbrowser!~/$notmatch/i)) {
                   2353: 	    $clientbrowser=$bname;
                   2354:             $httpbrowser=~/$vreg/i;
                   2355: 	    $clientversion=$1;
                   2356:             $clientmathml=($clientversion>=$minv);
                   2357:             $clientunicode=($clientversion>=$univ);
                   2358: 	}
                   2359:     }
                   2360:     my $clientos='unknown';
1.1075.2.42  raeburn  2361:     my $clientinfo;
1.87      matthew  2362:     if (($httpbrowser=~/linux/i) ||
                   2363:         ($httpbrowser=~/unix/i) ||
                   2364:         ($httpbrowser=~/ux/i) ||
                   2365:         ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
                   2366:     if (($httpbrowser=~/vax/i) ||
                   2367:         ($httpbrowser=~/vms/i)) { $clientos='vms'; }
                   2368:     if ($httpbrowser=~/next/i) { $clientos='next'; }
                   2369:     if (($httpbrowser=~/mac/i) ||
                   2370:         ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
                   2371:     if ($httpbrowser=~/win/i) { $clientos='win'; }
                   2372:     if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1075.2.42  raeburn  2373:     if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
                   2374:         $clientmobile=lc($1);
                   2375:     }
                   2376:     if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
                   2377:         $clientinfo = 'firefox-'.$1;
                   2378:     } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
                   2379:         $clientinfo = 'chromeframe-'.$1;
                   2380:     }
1.87      matthew  2381:     return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1075.2.42  raeburn  2382:             $clientunicode,$clientos,$clientmobile,$clientinfo);
1.87      matthew  2383: }
                   2384: 
1.32      matthew  2385: ###############################################################
                   2386: ##    Authentication changing form generation subroutines    ##
                   2387: ###############################################################
                   2388: ##
                   2389: ## All of the authform_xxxxxxx subroutines take their inputs in a
                   2390: ## hash, and have reasonable default values.
                   2391: ##
                   2392: ##    formname = the name given in the <form> tag.
1.35      matthew  2393: #-------------------------------------------
                   2394: 
1.45      matthew  2395: =pod
                   2396: 
1.112     bowersj2 2397: =head1 Authentication Routines
                   2398: 
                   2399: =over 4
                   2400: 
1.648     raeburn  2401: =item * &authform_xxxxxx()
1.35      matthew  2402: 
                   2403: The authform_xxxxxx subroutines provide javascript and html forms which 
                   2404: handle some of the conveniences required for authentication forms.  
                   2405: This is not an optimal method, but it works.  
                   2406: 
                   2407: =over 4
                   2408: 
1.112     bowersj2 2409: =item * authform_header
1.35      matthew  2410: 
1.112     bowersj2 2411: =item * authform_authorwarning
1.35      matthew  2412: 
1.112     bowersj2 2413: =item * authform_nochange
1.35      matthew  2414: 
1.112     bowersj2 2415: =item * authform_kerberos
1.35      matthew  2416: 
1.112     bowersj2 2417: =item * authform_internal
1.35      matthew  2418: 
1.112     bowersj2 2419: =item * authform_filesystem
1.35      matthew  2420: 
                   2421: =back
                   2422: 
1.648     raeburn  2423: See loncreateuser.pm for invocation and use examples.
1.157     matthew  2424: 
1.35      matthew  2425: =cut
                   2426: 
                   2427: #-------------------------------------------
1.32      matthew  2428: sub authform_header{  
                   2429:     my %in = (
                   2430:         formname => 'cu',
1.80      albertel 2431:         kerb_def_dom => '',
1.32      matthew  2432:         @_,
                   2433:     );
                   2434:     $in{'formname'} = 'document.' . $in{'formname'};
                   2435:     my $result='';
1.80      albertel 2436: 
                   2437: #---------------------------------------------- Code for upper case translation
                   2438:     my $Javascript_toUpperCase;
                   2439:     unless ($in{kerb_def_dom}) {
                   2440:         $Javascript_toUpperCase =<<"END";
                   2441:         switch (choice) {
                   2442:            case 'krb': currentform.elements[choicearg].value =
                   2443:                currentform.elements[choicearg].value.toUpperCase();
                   2444:                break;
                   2445:            default:
                   2446:         }
                   2447: END
                   2448:     } else {
                   2449:         $Javascript_toUpperCase = "";
                   2450:     }
                   2451: 
1.165     raeburn  2452:     my $radioval = "'nochange'";
1.591     raeburn  2453:     if (defined($in{'curr_authtype'})) {
                   2454:         if ($in{'curr_authtype'} ne '') {
                   2455:             $radioval = "'".$in{'curr_authtype'}."arg'";
                   2456:         }
1.174     matthew  2457:     }
1.165     raeburn  2458:     my $argfield = 'null';
1.591     raeburn  2459:     if (defined($in{'mode'})) {
1.165     raeburn  2460:         if ($in{'mode'} eq 'modifycourse')  {
1.591     raeburn  2461:             if (defined($in{'curr_autharg'})) {
                   2462:                 if ($in{'curr_autharg'} ne '') {
1.165     raeburn  2463:                     $argfield = "'$in{'curr_autharg'}'";
                   2464:                 }
                   2465:             }
                   2466:         }
                   2467:     }
                   2468: 
1.32      matthew  2469:     $result.=<<"END";
                   2470: var current = new Object();
1.165     raeburn  2471: current.radiovalue = $radioval;
                   2472: current.argfield = $argfield;
1.32      matthew  2473: 
                   2474: function changed_radio(choice,currentform) {
                   2475:     var choicearg = choice + 'arg';
                   2476:     // If a radio button in changed, we need to change the argfield
                   2477:     if (current.radiovalue != choice) {
                   2478:         current.radiovalue = choice;
                   2479:         if (current.argfield != null) {
                   2480:             currentform.elements[current.argfield].value = '';
                   2481:         }
                   2482:         if (choice == 'nochange') {
                   2483:             current.argfield = null;
                   2484:         } else {
                   2485:             current.argfield = choicearg;
                   2486:             switch(choice) {
                   2487:                 case 'krb': 
                   2488:                     currentform.elements[current.argfield].value = 
                   2489:                         "$in{'kerb_def_dom'}";
                   2490:                 break;
                   2491:               default:
                   2492:                 break;
                   2493:             }
                   2494:         }
                   2495:     }
                   2496:     return;
                   2497: }
1.22      www      2498: 
1.32      matthew  2499: function changed_text(choice,currentform) {
                   2500:     var choicearg = choice + 'arg';
                   2501:     if (currentform.elements[choicearg].value !='') {
1.80      albertel 2502:         $Javascript_toUpperCase
1.32      matthew  2503:         // clear old field
                   2504:         if ((current.argfield != choicearg) && (current.argfield != null)) {
                   2505:             currentform.elements[current.argfield].value = '';
                   2506:         }
                   2507:         current.argfield = choicearg;
                   2508:     }
                   2509:     set_auth_radio_buttons(choice,currentform);
                   2510:     return;
1.20      www      2511: }
1.32      matthew  2512: 
                   2513: function set_auth_radio_buttons(newvalue,currentform) {
1.986     raeburn  2514:     var numauthchoices = currentform.login.length;
                   2515:     if (typeof numauthchoices  == "undefined") {
                   2516:         return;
                   2517:     } 
1.32      matthew  2518:     var i=0;
1.986     raeburn  2519:     while (i < numauthchoices) {
1.32      matthew  2520:         if (currentform.login[i].value == newvalue) { break; }
                   2521:         i++;
                   2522:     }
1.986     raeburn  2523:     if (i == numauthchoices) {
1.32      matthew  2524:         return;
                   2525:     }
                   2526:     current.radiovalue = newvalue;
                   2527:     currentform.login[i].checked = true;
                   2528:     return;
                   2529: }
                   2530: END
                   2531:     return $result;
                   2532: }
                   2533: 
1.1075.2.20  raeburn  2534: sub authform_authorwarning {
1.32      matthew  2535:     my $result='';
1.144     matthew  2536:     $result='<i>'.
                   2537:         &mt('As a general rule, only authors or co-authors should be '.
                   2538:             'filesystem authenticated '.
                   2539:             '(which allows access to the server filesystem).')."</i>\n";
1.32      matthew  2540:     return $result;
                   2541: }
                   2542: 
1.1075.2.20  raeburn  2543: sub authform_nochange {
1.32      matthew  2544:     my %in = (
                   2545:               formname => 'document.cu',
                   2546:               kerb_def_dom => 'MSU.EDU',
                   2547:               @_,
                   2548:           );
1.1075.2.20  raeburn  2549:     my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'}); 
1.586     raeburn  2550:     my $result;
1.1075.2.20  raeburn  2551:     if (!$authnum) {
                   2552:         $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586     raeburn  2553:     } else {
                   2554:         $result = '<label>'.&mt('[_1] Do not change login data',
                   2555:                   '<input type="radio" name="login" value="nochange" '.
                   2556:                   'checked="checked" onclick="'.
1.281     albertel 2557:             "javascript:changed_radio('nochange',$in{'formname'});".'" />').
                   2558: 	    '</label>';
1.586     raeburn  2559:     }
1.32      matthew  2560:     return $result;
                   2561: }
                   2562: 
1.591     raeburn  2563: sub authform_kerberos {
1.32      matthew  2564:     my %in = (
                   2565:               formname => 'document.cu',
                   2566:               kerb_def_dom => 'MSU.EDU',
1.80      albertel 2567:               kerb_def_auth => 'krb4',
1.32      matthew  2568:               @_,
                   2569:               );
1.586     raeburn  2570:     my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
                   2571:         $autharg,$jscall);
1.1075.2.20  raeburn  2572:     my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80      albertel 2573:     if ($in{'kerb_def_auth'} eq 'krb5') {
1.772     bisitz   2574:        $check5 = ' checked="checked"';
1.80      albertel 2575:     } else {
1.772     bisitz   2576:        $check4 = ' checked="checked"';
1.80      albertel 2577:     }
1.165     raeburn  2578:     $krbarg = $in{'kerb_def_dom'};
1.591     raeburn  2579:     if (defined($in{'curr_authtype'})) {
                   2580:         if ($in{'curr_authtype'} eq 'krb') {
1.772     bisitz   2581:             $krbcheck = ' checked="checked"';
1.623     raeburn  2582:             if (defined($in{'mode'})) {
                   2583:                 if ($in{'mode'} eq 'modifyuser') {
                   2584:                     $krbcheck = '';
                   2585:                 }
                   2586:             }
1.591     raeburn  2587:             if (defined($in{'curr_kerb_ver'})) {
                   2588:                 if ($in{'curr_krb_ver'} eq '5') {
1.772     bisitz   2589:                     $check5 = ' checked="checked"';
1.591     raeburn  2590:                     $check4 = '';
                   2591:                 } else {
1.772     bisitz   2592:                     $check4 = ' checked="checked"';
1.591     raeburn  2593:                     $check5 = '';
                   2594:                 }
1.586     raeburn  2595:             }
1.591     raeburn  2596:             if (defined($in{'curr_autharg'})) {
1.165     raeburn  2597:                 $krbarg = $in{'curr_autharg'};
                   2598:             }
1.586     raeburn  2599:             if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591     raeburn  2600:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2601:                     $result = 
                   2602:     &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
                   2603:         $in{'curr_autharg'},$krbver);
                   2604:                 } else {
                   2605:                     $result =
                   2606:     &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
                   2607:                 }
                   2608:                 return $result; 
                   2609:             }
                   2610:         }
                   2611:     } else {
                   2612:         if ($authnum == 1) {
1.784     bisitz   2613:             $authtype = '<input type="hidden" name="login" value="krb" />';
1.165     raeburn  2614:         }
                   2615:     }
1.586     raeburn  2616:     if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
                   2617:         return;
1.587     raeburn  2618:     } elsif ($authtype eq '') {
1.591     raeburn  2619:         if (defined($in{'mode'})) {
1.587     raeburn  2620:             if ($in{'mode'} eq 'modifycourse') {
                   2621:                 if ($authnum == 1) {
1.1075.2.20  raeburn  2622:                     $authtype = '<input type="radio" name="login" value="krb" />';
1.587     raeburn  2623:                 }
                   2624:             }
                   2625:         }
1.586     raeburn  2626:     }
                   2627:     $jscall = "javascript:changed_radio('krb',$in{'formname'});";
                   2628:     if ($authtype eq '') {
                   2629:         $authtype = '<input type="radio" name="login" value="krb" '.
                   2630:                     'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
                   2631:                     $krbcheck.' />';
                   2632:     }
                   2633:     if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1075.2.20  raeburn  2634:         ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586     raeburn  2635:          $in{'curr_authtype'} eq 'krb5') ||
1.1075.2.20  raeburn  2636:         (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586     raeburn  2637:          $in{'curr_authtype'} eq 'krb4')) {
                   2638:         $result .= &mt
1.144     matthew  2639:         ('[_1] Kerberos authenticated with domain [_2] '.
1.281     albertel 2640:          '[_3] Version 4 [_4] Version 5 [_5]',
1.586     raeburn  2641:          '<label>'.$authtype,
1.281     albertel 2642:          '</label><input type="text" size="10" name="krbarg" '.
1.165     raeburn  2643:              'value="'.$krbarg.'" '.
1.144     matthew  2644:              'onchange="'.$jscall.'" />',
1.281     albertel 2645:          '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
                   2646:          '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
                   2647: 	 '</label>');
1.586     raeburn  2648:     } elsif ($can_assign{'krb4'}) {
                   2649:         $result .= &mt
                   2650:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2651:          '[_3] Version 4 [_4]',
                   2652:          '<label>'.$authtype,
                   2653:          '</label><input type="text" size="10" name="krbarg" '.
                   2654:              'value="'.$krbarg.'" '.
                   2655:              'onchange="'.$jscall.'" />',
                   2656:          '<label><input type="hidden" name="krbver" value="4" />',
                   2657:          '</label>');
                   2658:     } elsif ($can_assign{'krb5'}) {
                   2659:         $result .= &mt
                   2660:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2661:          '[_3] Version 5 [_4]',
                   2662:          '<label>'.$authtype,
                   2663:          '</label><input type="text" size="10" name="krbarg" '.
                   2664:              'value="'.$krbarg.'" '.
                   2665:              'onchange="'.$jscall.'" />',
                   2666:          '<label><input type="hidden" name="krbver" value="5" />',
                   2667:          '</label>');
                   2668:     }
1.32      matthew  2669:     return $result;
                   2670: }
                   2671: 
1.1075.2.20  raeburn  2672: sub authform_internal {
1.586     raeburn  2673:     my %in = (
1.32      matthew  2674:                 formname => 'document.cu',
                   2675:                 kerb_def_dom => 'MSU.EDU',
                   2676:                 @_,
                   2677:                 );
1.586     raeburn  2678:     my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
1.1075.2.20  raeburn  2679:     my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591     raeburn  2680:     if (defined($in{'curr_authtype'})) {
                   2681:         if ($in{'curr_authtype'} eq 'int') {
1.586     raeburn  2682:             if ($can_assign{'int'}) {
1.772     bisitz   2683:                 $intcheck = 'checked="checked" ';
1.623     raeburn  2684:                 if (defined($in{'mode'})) {
                   2685:                     if ($in{'mode'} eq 'modifyuser') {
                   2686:                         $intcheck = '';
                   2687:                     }
                   2688:                 }
1.591     raeburn  2689:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2690:                     $intarg = $in{'curr_autharg'};
                   2691:                 }
                   2692:             } else {
                   2693:                 $result = &mt('Currently internally authenticated.');
                   2694:                 return $result;
1.165     raeburn  2695:             }
                   2696:         }
1.586     raeburn  2697:     } else {
                   2698:         if ($authnum == 1) {
1.784     bisitz   2699:             $authtype = '<input type="hidden" name="login" value="int" />';
1.586     raeburn  2700:         }
                   2701:     }
                   2702:     if (!$can_assign{'int'}) {
                   2703:         return;
1.587     raeburn  2704:     } elsif ($authtype eq '') {
1.591     raeburn  2705:         if (defined($in{'mode'})) {
1.587     raeburn  2706:             if ($in{'mode'} eq 'modifycourse') {
                   2707:                 if ($authnum == 1) {
1.1075.2.20  raeburn  2708:                     $authtype = '<input type="radio" name="login" value="int" />';
1.587     raeburn  2709:                 }
                   2710:             }
                   2711:         }
1.165     raeburn  2712:     }
1.586     raeburn  2713:     $jscall = "javascript:changed_radio('int',$in{'formname'});";
                   2714:     if ($authtype eq '') {
                   2715:         $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
                   2716:                     ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
                   2717:     }
1.605     bisitz   2718:     $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586     raeburn  2719:                $intarg.'" onchange="'.$jscall.'" />';
                   2720:     $result = &mt
1.144     matthew  2721:         ('[_1] Internally authenticated (with initial password [_2])',
1.586     raeburn  2722:          '<label>'.$authtype,'</label>'.$autharg);
1.824     bisitz   2723:     $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  2724:     return $result;
                   2725: }
                   2726: 
1.1075.2.20  raeburn  2727: sub authform_local {
1.32      matthew  2728:     my %in = (
                   2729:               formname => 'document.cu',
                   2730:               kerb_def_dom => 'MSU.EDU',
                   2731:               @_,
                   2732:               );
1.586     raeburn  2733:     my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
1.1075.2.20  raeburn  2734:     my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591     raeburn  2735:     if (defined($in{'curr_authtype'})) {
                   2736:         if ($in{'curr_authtype'} eq 'loc') {
1.586     raeburn  2737:             if ($can_assign{'loc'}) {
1.772     bisitz   2738:                 $loccheck = 'checked="checked" ';
1.623     raeburn  2739:                 if (defined($in{'mode'})) {
                   2740:                     if ($in{'mode'} eq 'modifyuser') {
                   2741:                         $loccheck = '';
                   2742:                     }
                   2743:                 }
1.591     raeburn  2744:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2745:                     $locarg = $in{'curr_autharg'};
                   2746:                 }
                   2747:             } else {
                   2748:                 $result = &mt('Currently using local (institutional) authentication.');
                   2749:                 return $result;
1.165     raeburn  2750:             }
                   2751:         }
1.586     raeburn  2752:     } else {
                   2753:         if ($authnum == 1) {
1.784     bisitz   2754:             $authtype = '<input type="hidden" name="login" value="loc" />';
1.586     raeburn  2755:         }
                   2756:     }
                   2757:     if (!$can_assign{'loc'}) {
                   2758:         return;
1.587     raeburn  2759:     } elsif ($authtype eq '') {
1.591     raeburn  2760:         if (defined($in{'mode'})) {
1.587     raeburn  2761:             if ($in{'mode'} eq 'modifycourse') {
                   2762:                 if ($authnum == 1) {
1.1075.2.20  raeburn  2763:                     $authtype = '<input type="radio" name="login" value="loc" />';
1.587     raeburn  2764:                 }
                   2765:             }
                   2766:         }
1.165     raeburn  2767:     }
1.586     raeburn  2768:     $jscall = "javascript:changed_radio('loc',$in{'formname'});";
                   2769:     if ($authtype eq '') {
                   2770:         $authtype = '<input type="radio" name="login" value="loc" '.
                   2771:                     $loccheck.' onchange="'.$jscall.'" onclick="'.
                   2772:                     $jscall.'" />';
                   2773:     }
                   2774:     $autharg = '<input type="text" size="10" name="locarg" value="'.
                   2775:                $locarg.'" onchange="'.$jscall.'" />';
                   2776:     $result = &mt('[_1] Local Authentication with argument [_2]',
                   2777:                   '<label>'.$authtype,'</label>'.$autharg);
1.32      matthew  2778:     return $result;
                   2779: }
                   2780: 
1.1075.2.20  raeburn  2781: sub authform_filesystem {
1.32      matthew  2782:     my %in = (
                   2783:               formname => 'document.cu',
                   2784:               kerb_def_dom => 'MSU.EDU',
                   2785:               @_,
                   2786:               );
1.586     raeburn  2787:     my ($fsyscheck,$result,$authtype,$autharg,$jscall);
1.1075.2.20  raeburn  2788:     my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591     raeburn  2789:     if (defined($in{'curr_authtype'})) {
                   2790:         if ($in{'curr_authtype'} eq 'fsys') {
1.586     raeburn  2791:             if ($can_assign{'fsys'}) {
1.772     bisitz   2792:                 $fsyscheck = 'checked="checked" ';
1.623     raeburn  2793:                 if (defined($in{'mode'})) {
                   2794:                     if ($in{'mode'} eq 'modifyuser') {
                   2795:                         $fsyscheck = '';
                   2796:                     }
                   2797:                 }
1.586     raeburn  2798:             } else {
                   2799:                 $result = &mt('Currently Filesystem Authenticated.');
                   2800:                 return $result;
                   2801:             }           
                   2802:         }
                   2803:     } else {
                   2804:         if ($authnum == 1) {
1.784     bisitz   2805:             $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586     raeburn  2806:         }
                   2807:     }
                   2808:     if (!$can_assign{'fsys'}) {
                   2809:         return;
1.587     raeburn  2810:     } elsif ($authtype eq '') {
1.591     raeburn  2811:         if (defined($in{'mode'})) {
1.587     raeburn  2812:             if ($in{'mode'} eq 'modifycourse') {
                   2813:                 if ($authnum == 1) {
1.1075.2.20  raeburn  2814:                     $authtype = '<input type="radio" name="login" value="fsys" />';
1.587     raeburn  2815:                 }
                   2816:             }
                   2817:         }
1.586     raeburn  2818:     }
                   2819:     $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
                   2820:     if ($authtype eq '') {
                   2821:         $authtype = '<input type="radio" name="login" value="fsys" '.
                   2822:                     $fsyscheck.' onchange="'.$jscall.'" onclick="'.
                   2823:                     $jscall.'" />';
                   2824:     }
                   2825:     $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
                   2826:                ' onchange="'.$jscall.'" />';
                   2827:     $result = &mt
1.144     matthew  2828:         ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281     albertel 2829:          '<label><input type="radio" name="login" value="fsys" '.
1.586     raeburn  2830:          $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605     bisitz   2831:          '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144     matthew  2832:                   'onchange="'.$jscall.'" />');
1.32      matthew  2833:     return $result;
                   2834: }
                   2835: 
1.586     raeburn  2836: sub get_assignable_auth {
                   2837:     my ($dom) = @_;
                   2838:     if ($dom eq '') {
                   2839:         $dom = $env{'request.role.domain'};
                   2840:     }
                   2841:     my %can_assign = (
                   2842:                           krb4 => 1,
                   2843:                           krb5 => 1,
                   2844:                           int  => 1,
                   2845:                           loc  => 1,
                   2846:                      );
                   2847:     my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
                   2848:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   2849:         if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
                   2850:             my $authhash = $domconfig{'usercreation'}{'authtypes'};
                   2851:             my $context;
                   2852:             if ($env{'request.role'} =~ /^au/) {
                   2853:                 $context = 'author';
                   2854:             } elsif ($env{'request.role'} =~ /^dc/) {
                   2855:                 $context = 'domain';
                   2856:             } elsif ($env{'request.course.id'}) {
                   2857:                 $context = 'course';
                   2858:             }
                   2859:             if ($context) {
                   2860:                 if (ref($authhash->{$context}) eq 'HASH') {
                   2861:                    %can_assign = %{$authhash->{$context}}; 
                   2862:                 }
                   2863:             }
                   2864:         }
                   2865:     }
                   2866:     my $authnum = 0;
                   2867:     foreach my $key (keys(%can_assign)) {
                   2868:         if ($can_assign{$key}) {
                   2869:             $authnum ++;
                   2870:         }
                   2871:     }
                   2872:     if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
                   2873:         $authnum --;
                   2874:     }
                   2875:     return ($authnum,%can_assign);
                   2876: }
                   2877: 
1.80      albertel 2878: ###############################################################
                   2879: ##    Get Kerberos Defaults for Domain                 ##
                   2880: ###############################################################
                   2881: ##
                   2882: ## Returns default kerberos version and an associated argument
                   2883: ## as listed in file domain.tab. If not listed, provides
                   2884: ## appropriate default domain and kerberos version.
                   2885: ##
                   2886: #-------------------------------------------
                   2887: 
                   2888: =pod
                   2889: 
1.648     raeburn  2890: =item * &get_kerberos_defaults()
1.80      albertel 2891: 
                   2892: get_kerberos_defaults($target_domain) returns the default kerberos
1.641     raeburn  2893: version and domain. If not found, it defaults to version 4 and the 
                   2894: domain of the server.
1.80      albertel 2895: 
1.648     raeburn  2896: =over 4
                   2897: 
1.80      albertel 2898: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
                   2899: 
1.648     raeburn  2900: =back
                   2901: 
                   2902: =back
                   2903: 
1.80      albertel 2904: =cut
                   2905: 
                   2906: #-------------------------------------------
                   2907: sub get_kerberos_defaults {
                   2908:     my $domain=shift;
1.641     raeburn  2909:     my ($krbdef,$krbdefdom);
                   2910:     my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
                   2911:     if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
                   2912:         $krbdef = $domdefaults{'auth_def'};
                   2913:         $krbdefdom = $domdefaults{'auth_arg_def'};
                   2914:     } else {
1.80      albertel 2915:         $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
                   2916:         my $krbdefdom=$1;
                   2917:         $krbdefdom=~tr/a-z/A-Z/;
                   2918:         $krbdef = "krb4";
                   2919:     }
                   2920:     return ($krbdef,$krbdefdom);
                   2921: }
1.112     bowersj2 2922: 
1.32      matthew  2923: 
1.46      matthew  2924: ###############################################################
                   2925: ##                Thesaurus Functions                        ##
                   2926: ###############################################################
1.20      www      2927: 
1.46      matthew  2928: =pod
1.20      www      2929: 
1.112     bowersj2 2930: =head1 Thesaurus Functions
                   2931: 
                   2932: =over 4
                   2933: 
1.648     raeburn  2934: =item * &initialize_keywords()
1.46      matthew  2935: 
                   2936: Initializes the package variable %Keywords if it is empty.  Uses the
                   2937: package variable $thesaurus_db_file.
                   2938: 
                   2939: =cut
                   2940: 
                   2941: ###################################################
                   2942: 
                   2943: sub initialize_keywords {
                   2944:     return 1 if (scalar keys(%Keywords));
                   2945:     # If we are here, %Keywords is empty, so fill it up
                   2946:     #   Make sure the file we need exists...
                   2947:     if (! -e $thesaurus_db_file) {
                   2948:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
                   2949:                                  " failed because it does not exist");
                   2950:         return 0;
                   2951:     }
                   2952:     #   Set up the hash as a database
                   2953:     my %thesaurus_db;
                   2954:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2955:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2956:         &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
                   2957:                                  $thesaurus_db_file);
                   2958:         return 0;
                   2959:     } 
                   2960:     #  Get the average number of appearances of a word.
                   2961:     my $avecount = $thesaurus_db{'average.count'};
                   2962:     #  Put keywords (those that appear > average) into %Keywords
                   2963:     while (my ($word,$data)=each (%thesaurus_db)) {
                   2964:         my ($count,undef) = split /:/,$data;
                   2965:         $Keywords{$word}++ if ($count > $avecount);
                   2966:     }
                   2967:     untie %thesaurus_db;
                   2968:     # Remove special values from %Keywords.
1.356     albertel 2969:     foreach my $value ('total.count','average.count') {
                   2970:         delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586     raeburn  2971:   }
1.46      matthew  2972:     return 1;
                   2973: }
                   2974: 
                   2975: ###################################################
                   2976: 
                   2977: =pod
                   2978: 
1.648     raeburn  2979: =item * &keyword($word)
1.46      matthew  2980: 
                   2981: Returns true if $word is a keyword.  A keyword is a word that appears more 
                   2982: than the average number of times in the thesaurus database.  Calls 
                   2983: &initialize_keywords
                   2984: 
                   2985: =cut
                   2986: 
                   2987: ###################################################
1.20      www      2988: 
                   2989: sub keyword {
1.46      matthew  2990:     return if (!&initialize_keywords());
                   2991:     my $word=lc(shift());
                   2992:     $word=~s/\W//g;
                   2993:     return exists($Keywords{$word});
1.20      www      2994: }
1.46      matthew  2995: 
                   2996: ###############################################################
                   2997: 
                   2998: =pod 
1.20      www      2999: 
1.648     raeburn  3000: =item * &get_related_words()
1.46      matthew  3001: 
1.160     matthew  3002: Look up a word in the thesaurus.  Takes a scalar argument and returns
1.46      matthew  3003: an array of words.  If the keyword is not in the thesaurus, an empty array
                   3004: will be returned.  The order of the words returned is determined by the
                   3005: database which holds them.
                   3006: 
                   3007: Uses global $thesaurus_db_file.
                   3008: 
1.1057    foxr     3009: 
1.46      matthew  3010: =cut
                   3011: 
                   3012: ###############################################################
                   3013: sub get_related_words {
                   3014:     my $keyword = shift;
                   3015:     my %thesaurus_db;
                   3016:     if (! -e $thesaurus_db_file) {
                   3017:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
                   3018:                                  "failed because the file does not exist");
                   3019:         return ();
                   3020:     }
                   3021:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 3022:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  3023:         return ();
                   3024:     } 
                   3025:     my @Words=();
1.429     www      3026:     my $count=0;
1.46      matthew  3027:     if (exists($thesaurus_db{$keyword})) {
1.356     albertel 3028: 	# The first element is the number of times
                   3029: 	# the word appears.  We do not need it now.
1.429     www      3030: 	my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
                   3031: 	my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
                   3032: 	my $threshold=$mostfrequentcount/10;
                   3033:         foreach my $possibleword (@RelatedWords) {
                   3034:             my ($word,$wordcount)=split(/\,/,$possibleword);
                   3035:             if ($wordcount>$threshold) {
                   3036: 		push(@Words,$word);
                   3037:                 $count++;
                   3038:                 if ($count>10) { last; }
                   3039: 	    }
1.20      www      3040:         }
                   3041:     }
1.46      matthew  3042:     untie %thesaurus_db;
                   3043:     return @Words;
1.14      harris41 3044: }
1.46      matthew  3045: 
1.112     bowersj2 3046: =pod
                   3047: 
                   3048: =back
                   3049: 
                   3050: =cut
1.61      www      3051: 
                   3052: # -------------------------------------------------------------- Plaintext name
1.81      albertel 3053: =pod
                   3054: 
1.112     bowersj2 3055: =head1 User Name Functions
                   3056: 
                   3057: =over 4
                   3058: 
1.648     raeburn  3059: =item * &plainname($uname,$udom,$first)
1.81      albertel 3060: 
1.112     bowersj2 3061: Takes a users logon name and returns it as a string in
1.226     albertel 3062: "first middle last generation" form 
                   3063: if $first is set to 'lastname' then it returns it as
                   3064: 'lastname generation, firstname middlename' if their is a lastname
1.81      albertel 3065: 
                   3066: =cut
1.61      www      3067: 
1.295     www      3068: 
1.81      albertel 3069: ###############################################################
1.61      www      3070: sub plainname {
1.226     albertel 3071:     my ($uname,$udom,$first)=@_;
1.537     albertel 3072:     return if (!defined($uname) || !defined($udom));
1.295     www      3073:     my %names=&getnames($uname,$udom);
1.226     albertel 3074:     my $name=&Apache::lonnet::format_name($names{'firstname'},
                   3075: 					  $names{'middlename'},
                   3076: 					  $names{'lastname'},
                   3077: 					  $names{'generation'},$first);
                   3078:     $name=~s/^\s+//;
1.62      www      3079:     $name=~s/\s+$//;
                   3080:     $name=~s/\s+/ /g;
1.353     albertel 3081:     if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62      www      3082:     return $name;
1.61      www      3083: }
1.66      www      3084: 
                   3085: # -------------------------------------------------------------------- Nickname
1.81      albertel 3086: =pod
                   3087: 
1.648     raeburn  3088: =item * &nickname($uname,$udom)
1.81      albertel 3089: 
                   3090: Gets a users name and returns it as a string as
                   3091: 
                   3092: "&quot;nickname&quot;"
1.66      www      3093: 
1.81      albertel 3094: if the user has a nickname or
                   3095: 
                   3096: "first middle last generation"
                   3097: 
                   3098: if the user does not
                   3099: 
                   3100: =cut
1.66      www      3101: 
                   3102: sub nickname {
                   3103:     my ($uname,$udom)=@_;
1.537     albertel 3104:     return if (!defined($uname) || !defined($udom));
1.295     www      3105:     my %names=&getnames($uname,$udom);
1.68      albertel 3106:     my $name=$names{'nickname'};
1.66      www      3107:     if ($name) {
                   3108:        $name='&quot;'.$name.'&quot;'; 
                   3109:     } else {
                   3110:        $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
                   3111: 	     $names{'lastname'}.' '.$names{'generation'};
                   3112:        $name=~s/\s+$//;
                   3113:        $name=~s/\s+/ /g;
                   3114:     }
                   3115:     return $name;
                   3116: }
                   3117: 
1.295     www      3118: sub getnames {
                   3119:     my ($uname,$udom)=@_;
1.537     albertel 3120:     return if (!defined($uname) || !defined($udom));
1.433     albertel 3121:     if ($udom eq 'public' && $uname eq 'public') {
                   3122: 	return ('lastname' => &mt('Public'));
                   3123:     }
1.295     www      3124:     my $id=$uname.':'.$udom;
                   3125:     my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
                   3126:     if ($cached) {
                   3127: 	return %{$names};
                   3128:     } else {
                   3129: 	my %loadnames=&Apache::lonnet::get('environment',
                   3130:                     ['firstname','middlename','lastname','generation','nickname'],
                   3131: 					 $udom,$uname);
                   3132: 	&Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
                   3133: 	return %loadnames;
                   3134:     }
                   3135: }
1.61      www      3136: 
1.542     raeburn  3137: # -------------------------------------------------------------------- getemails
1.648     raeburn  3138: 
1.542     raeburn  3139: =pod
                   3140: 
1.648     raeburn  3141: =item * &getemails($uname,$udom)
1.542     raeburn  3142: 
                   3143: Gets a user's email information and returns it as a hash with keys:
                   3144: notification, critnotification, permanentemail
                   3145: 
                   3146: For notification and critnotification, values are comma-separated lists 
1.648     raeburn  3147: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542     raeburn  3148:  
1.648     raeburn  3149: 
1.542     raeburn  3150: =cut
                   3151: 
1.648     raeburn  3152: 
1.466     albertel 3153: sub getemails {
                   3154:     my ($uname,$udom)=@_;
                   3155:     if ($udom eq 'public' && $uname eq 'public') {
                   3156: 	return;
                   3157:     }
1.467     www      3158:     if (!$udom) { $udom=$env{'user.domain'}; }
                   3159:     if (!$uname) { $uname=$env{'user.name'}; }
1.466     albertel 3160:     my $id=$uname.':'.$udom;
                   3161:     my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
                   3162:     if ($cached) {
                   3163: 	return %{$names};
                   3164:     } else {
                   3165: 	my %loadnames=&Apache::lonnet::get('environment',
                   3166:                     			   ['notification','critnotification',
                   3167: 					    'permanentemail'],
                   3168: 					   $udom,$uname);
                   3169: 	&Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
                   3170: 	return %loadnames;
                   3171:     }
                   3172: }
                   3173: 
1.551     albertel 3174: sub flush_email_cache {
                   3175:     my ($uname,$udom)=@_;
                   3176:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   3177:     if (!$uname) { $uname=$env{'user.name'};   }
                   3178:     return if ($udom eq 'public' && $uname eq 'public');
                   3179:     my $id=$uname.':'.$udom;
                   3180:     &Apache::lonnet::devalidate_cache_new('emailscache',$id);
                   3181: }
                   3182: 
1.728     raeburn  3183: # -------------------------------------------------------------------- getlangs
                   3184: 
                   3185: =pod
                   3186: 
                   3187: =item * &getlangs($uname,$udom)
                   3188: 
                   3189: Gets a user's language preference and returns it as a hash with key:
                   3190: language.
                   3191: 
                   3192: =cut
                   3193: 
                   3194: 
                   3195: sub getlangs {
                   3196:     my ($uname,$udom) = @_;
                   3197:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   3198:     if (!$uname) { $uname=$env{'user.name'};   }
                   3199:     my $id=$uname.':'.$udom;
                   3200:     my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
                   3201:     if ($cached) {
                   3202:         return %{$langs};
                   3203:     } else {
                   3204:         my %loadlangs=&Apache::lonnet::get('environment',['languages'],
                   3205:                                            $udom,$uname);
                   3206:         &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
                   3207:         return %loadlangs;
                   3208:     }
                   3209: }
                   3210: 
                   3211: sub flush_langs_cache {
                   3212:     my ($uname,$udom)=@_;
                   3213:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   3214:     if (!$uname) { $uname=$env{'user.name'};   }
                   3215:     return if ($udom eq 'public' && $uname eq 'public');
                   3216:     my $id=$uname.':'.$udom;
                   3217:     &Apache::lonnet::devalidate_cache_new('userlangs',$id);
                   3218: }
                   3219: 
1.61      www      3220: # ------------------------------------------------------------------ Screenname
1.81      albertel 3221: 
                   3222: =pod
                   3223: 
1.648     raeburn  3224: =item * &screenname($uname,$udom)
1.81      albertel 3225: 
                   3226: Gets a users screenname and returns it as a string
                   3227: 
                   3228: =cut
1.61      www      3229: 
                   3230: sub screenname {
                   3231:     my ($uname,$udom)=@_;
1.258     albertel 3232:     if ($uname eq $env{'user.name'} &&
                   3233: 	$udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212     albertel 3234:     my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68      albertel 3235:     return $names{'screenname'};
1.62      www      3236: }
                   3237: 
1.212     albertel 3238: 
1.802     bisitz   3239: # ------------------------------------------------------------- Confirm Wrapper
                   3240: =pod
                   3241: 
1.1075.2.42  raeburn  3242: =item * &confirmwrapper($message)
1.802     bisitz   3243: 
                   3244: Wrap messages about completion of operation in box
                   3245: 
                   3246: =cut
                   3247: 
                   3248: sub confirmwrapper {
                   3249:     my ($message)=@_;
                   3250:     if ($message) {
                   3251:         return "\n".'<div class="LC_confirm_box">'."\n"
                   3252:                .$message."\n"
                   3253:                .'</div>'."\n";
                   3254:     } else {
                   3255:         return $message;
                   3256:     }
                   3257: }
                   3258: 
1.62      www      3259: # ------------------------------------------------------------- Message Wrapper
                   3260: 
                   3261: sub messagewrapper {
1.369     www      3262:     my ($link,$username,$domain,$subject,$text)=@_;
1.62      www      3263:     return 
1.441     albertel 3264:         '<a href="/adm/email?compose=individual&amp;'.
                   3265:         'recname='.$username.'&amp;recdom='.$domain.
                   3266: 	'&amp;subject='.&escape($subject).'&amp;text='.&escape($text).'" '.
1.200     matthew  3267:         'title="'.&mt('Send message').'">'.$link.'</a>';
1.74      www      3268: }
1.802     bisitz   3269: 
1.74      www      3270: # --------------------------------------------------------------- Notes Wrapper
                   3271: 
                   3272: sub noteswrapper {
                   3273:     my ($link,$un,$do)=@_;
                   3274:     return 
1.896     amueller 3275: "<a href='/adm/email?recordftf=retrieve&amp;recname=$un&amp;recdom=$do'>$link</a>";
1.62      www      3276: }
1.802     bisitz   3277: 
1.62      www      3278: # ------------------------------------------------------------- Aboutme Wrapper
                   3279: 
                   3280: sub aboutmewrapper {
1.1070    raeburn  3281:     my ($link,$username,$domain,$target,$class)=@_;
1.447     raeburn  3282:     if (!defined($username)  && !defined($domain)) {
                   3283:         return;
                   3284:     }
1.1075.2.15  raeburn  3285:     return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070    raeburn  3286: 	($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62      www      3287: }
                   3288: 
                   3289: # ------------------------------------------------------------ Syllabus Wrapper
                   3290: 
                   3291: sub syllabuswrapper {
1.707     bisitz   3292:     my ($linktext,$coursedir,$domain)=@_;
1.208     matthew  3293:     return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61      www      3294: }
1.14      harris41 3295: 
1.802     bisitz   3296: # -----------------------------------------------------------------------------
                   3297: 
1.208     matthew  3298: sub track_student_link {
1.887     raeburn  3299:     my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268     albertel 3300:     my $link ="/adm/trackstudent?";
1.208     matthew  3301:     my $title = 'View recent activity';
                   3302:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   3303:         defined($sdom)  && $sdom  !~ /^\s*$/) {
1.268     albertel 3304:         $link .= "selected_student=$sname:$sdom";
1.208     matthew  3305:         $title .= ' of this student';
1.268     albertel 3306:     } 
1.208     matthew  3307:     if (defined($target) && $target !~ /^\s*$/) {
                   3308:         $target = qq{target="$target"};
                   3309:     } else {
                   3310:         $target = '';
                   3311:     }
1.268     albertel 3312:     if ($start) { $link.='&amp;start='.$start; }
1.887     raeburn  3313:     if ($only_body) { $link .= '&amp;only_body=1'; }
1.554     albertel 3314:     $title = &mt($title);
                   3315:     $linktext = &mt($linktext);
1.448     albertel 3316:     return qq{<a href="$link" title="$title" $target>$linktext</a>}.
                   3317: 	&help_open_topic('View_recent_activity');
1.208     matthew  3318: }
                   3319: 
1.781     raeburn  3320: sub slot_reservations_link {
                   3321:     my ($linktext,$sname,$sdom,$target) = @_;
                   3322:     my $link ="/adm/slotrequest?command=showresv&amp;origin=aboutme";
                   3323:     my $title = 'View slot reservation history';
                   3324:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   3325:         defined($sdom)  && $sdom  !~ /^\s*$/) {
                   3326:         $link .= "&amp;uname=$sname&amp;udom=$sdom";
                   3327:         $title .= ' of this student';
                   3328:     }
                   3329:     if (defined($target) && $target !~ /^\s*$/) {
                   3330:         $target = qq{target="$target"};
                   3331:     } else {
                   3332:         $target = '';
                   3333:     }
                   3334:     $title = &mt($title);
                   3335:     $linktext = &mt($linktext);
                   3336:     return qq{<a href="$link" title="$title" $target>$linktext</a>};
                   3337: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
                   3338: 
                   3339: }
                   3340: 
1.508     www      3341: # ===================================================== Display a student photo
                   3342: 
                   3343: 
1.509     albertel 3344: sub student_image_tag {
1.508     www      3345:     my ($domain,$user)=@_;
                   3346:     my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
                   3347:     if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
                   3348: 	return '<img src="'.$imgsrc.'" align="right" />';
                   3349:     } else {
                   3350: 	return '';
                   3351:     }
                   3352: }
                   3353: 
1.112     bowersj2 3354: =pod
                   3355: 
                   3356: =back
                   3357: 
                   3358: =head1 Access .tab File Data
                   3359: 
                   3360: =over 4
                   3361: 
1.648     raeburn  3362: =item * &languageids() 
1.112     bowersj2 3363: 
                   3364: returns list of all language ids
                   3365: 
                   3366: =cut
                   3367: 
1.14      harris41 3368: sub languageids {
1.16      harris41 3369:     return sort(keys(%language));
1.14      harris41 3370: }
                   3371: 
1.112     bowersj2 3372: =pod
                   3373: 
1.648     raeburn  3374: =item * &languagedescription() 
1.112     bowersj2 3375: 
                   3376: returns description of a specified language id
                   3377: 
                   3378: =cut
                   3379: 
1.14      harris41 3380: sub languagedescription {
1.125     www      3381:     my $code=shift;
                   3382:     return  ($supported_language{$code}?'* ':'').
                   3383:             $language{$code}.
1.126     www      3384: 	    ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145     www      3385: }
                   3386: 
1.1048    foxr     3387: =pod
                   3388: 
                   3389: =item * &plainlanguagedescription
                   3390: 
                   3391: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
                   3392: and the language character encoding (e.g. ISO) separated by a ' - ' string.
                   3393: 
                   3394: =cut
                   3395: 
1.145     www      3396: sub plainlanguagedescription {
                   3397:     my $code=shift;
                   3398:     return $language{$code};
                   3399: }
                   3400: 
1.1048    foxr     3401: =pod
                   3402: 
                   3403: =item * &supportedlanguagecode
                   3404: 
                   3405: Returns the supported language code (e.g. sptutf maps to pt) given a language
                   3406: code.
                   3407: 
                   3408: =cut
                   3409: 
1.145     www      3410: sub supportedlanguagecode {
                   3411:     my $code=shift;
                   3412:     return $supported_language{$code};
1.97      www      3413: }
                   3414: 
1.112     bowersj2 3415: =pod
                   3416: 
1.1048    foxr     3417: =item * &latexlanguage()
                   3418: 
                   3419: Given a language key code returns the correspondnig language to use
                   3420: to select the correct hyphenation on LaTeX printouts.  This is undef if there
                   3421: is no supported hyphenation for the language code.
                   3422: 
                   3423: =cut
                   3424: 
                   3425: sub latexlanguage {
                   3426:     my $code = shift;
                   3427:     return $latex_language{$code};
                   3428: }
                   3429: 
                   3430: =pod
                   3431: 
                   3432: =item * &latexhyphenation()
                   3433: 
                   3434: Same as above but what's supplied is the language as it might be stored
                   3435: in the metadata.
                   3436: 
                   3437: =cut
                   3438: 
                   3439: sub latexhyphenation {
                   3440:     my $key = shift;
                   3441:     return $latex_language_bykey{$key};
                   3442: }
                   3443: 
                   3444: =pod
                   3445: 
1.648     raeburn  3446: =item * &copyrightids() 
1.112     bowersj2 3447: 
                   3448: returns list of all copyrights
                   3449: 
                   3450: =cut
                   3451: 
                   3452: sub copyrightids {
                   3453:     return sort(keys(%cprtag));
                   3454: }
                   3455: 
                   3456: =pod
                   3457: 
1.648     raeburn  3458: =item * &copyrightdescription() 
1.112     bowersj2 3459: 
                   3460: returns description of a specified copyright id
                   3461: 
                   3462: =cut
                   3463: 
                   3464: sub copyrightdescription {
1.166     www      3465:     return &mt($cprtag{shift(@_)});
1.112     bowersj2 3466: }
1.197     matthew  3467: 
                   3468: =pod
                   3469: 
1.648     raeburn  3470: =item * &source_copyrightids() 
1.192     taceyjo1 3471: 
                   3472: returns list of all source copyrights
                   3473: 
                   3474: =cut
                   3475: 
                   3476: sub source_copyrightids {
                   3477:     return sort(keys(%scprtag));
                   3478: }
                   3479: 
                   3480: =pod
                   3481: 
1.648     raeburn  3482: =item * &source_copyrightdescription() 
1.192     taceyjo1 3483: 
                   3484: returns description of a specified source copyright id
                   3485: 
                   3486: =cut
                   3487: 
                   3488: sub source_copyrightdescription {
                   3489:     return &mt($scprtag{shift(@_)});
                   3490: }
1.112     bowersj2 3491: 
                   3492: =pod
                   3493: 
1.648     raeburn  3494: =item * &filecategories() 
1.112     bowersj2 3495: 
                   3496: returns list of all file categories
                   3497: 
                   3498: =cut
                   3499: 
                   3500: sub filecategories {
                   3501:     return sort(keys(%category_extensions));
                   3502: }
                   3503: 
                   3504: =pod
                   3505: 
1.648     raeburn  3506: =item * &filecategorytypes() 
1.112     bowersj2 3507: 
                   3508: returns list of file types belonging to a given file
                   3509: category
                   3510: 
                   3511: =cut
                   3512: 
                   3513: sub filecategorytypes {
1.356     albertel 3514:     my ($cat) = @_;
                   3515:     return @{$category_extensions{lc($cat)}};
1.112     bowersj2 3516: }
                   3517: 
                   3518: =pod
                   3519: 
1.648     raeburn  3520: =item * &fileembstyle() 
1.112     bowersj2 3521: 
                   3522: returns embedding style for a specified file type
                   3523: 
                   3524: =cut
                   3525: 
                   3526: sub fileembstyle {
                   3527:     return $fe{lc(shift(@_))};
1.169     www      3528: }
                   3529: 
1.351     www      3530: sub filemimetype {
                   3531:     return $fm{lc(shift(@_))};
                   3532: }
                   3533: 
1.169     www      3534: 
                   3535: sub filecategoryselect {
                   3536:     my ($name,$value)=@_;
1.189     matthew  3537:     return &select_form($value,$name,
1.970     raeburn  3538:                         {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112     bowersj2 3539: }
                   3540: 
                   3541: =pod
                   3542: 
1.648     raeburn  3543: =item * &filedescription() 
1.112     bowersj2 3544: 
                   3545: returns description for a specified file type
                   3546: 
                   3547: =cut
                   3548: 
                   3549: sub filedescription {
1.188     matthew  3550:     my $file_description = $fd{lc(shift())};
                   3551:     $file_description =~ s:([\[\]]):~$1:g;
                   3552:     return &mt($file_description);
1.112     bowersj2 3553: }
                   3554: 
                   3555: =pod
                   3556: 
1.648     raeburn  3557: =item * &filedescriptionex() 
1.112     bowersj2 3558: 
                   3559: returns description for a specified file type with
                   3560: extra formatting
                   3561: 
                   3562: =cut
                   3563: 
                   3564: sub filedescriptionex {
                   3565:     my $ex=shift;
1.188     matthew  3566:     my $file_description = $fd{lc($ex)};
                   3567:     $file_description =~ s:([\[\]]):~$1:g;
                   3568:     return '.'.$ex.' '.&mt($file_description);
1.112     bowersj2 3569: }
                   3570: 
                   3571: # End of .tab access
                   3572: =pod
                   3573: 
                   3574: =back
                   3575: 
                   3576: =cut
                   3577: 
                   3578: # ------------------------------------------------------------------ File Types
                   3579: sub fileextensions {
                   3580:     return sort(keys(%fe));
                   3581: }
                   3582: 
1.97      www      3583: # ----------------------------------------------------------- Display Languages
                   3584: # returns a hash with all desired display languages
                   3585: #
                   3586: 
                   3587: sub display_languages {
                   3588:     my %languages=();
1.695     raeburn  3589:     foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356     albertel 3590: 	$languages{$lang}=1;
1.97      www      3591:     }
                   3592:     &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258     albertel 3593:     if ($env{'form.displaylanguage'}) {
1.356     albertel 3594: 	foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
                   3595: 	    $languages{$lang}=1;
1.97      www      3596:         }
                   3597:     }
                   3598:     return %languages;
1.14      harris41 3599: }
                   3600: 
1.582     albertel 3601: sub languages {
                   3602:     my ($possible_langs) = @_;
1.695     raeburn  3603:     my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582     albertel 3604:     if (!ref($possible_langs)) {
                   3605: 	if( wantarray ) {
                   3606: 	    return @preferred_langs;
                   3607: 	} else {
                   3608: 	    return $preferred_langs[0];
                   3609: 	}
                   3610:     }
                   3611:     my %possibilities = map { $_ => 1 } (@$possible_langs);
                   3612:     my @preferred_possibilities;
                   3613:     foreach my $preferred_lang (@preferred_langs) {
                   3614: 	if (exists($possibilities{$preferred_lang})) {
                   3615: 	    push(@preferred_possibilities, $preferred_lang);
                   3616: 	}
                   3617:     }
                   3618:     if( wantarray ) {
                   3619: 	return @preferred_possibilities;
                   3620:     }
                   3621:     return $preferred_possibilities[0];
                   3622: }
                   3623: 
1.742     raeburn  3624: sub user_lang {
                   3625:     my ($touname,$toudom,$fromcid) = @_;
                   3626:     my @userlangs;
                   3627:     if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
                   3628:         @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
                   3629:                     $env{'course.'.$fromcid.'.languages'}));
                   3630:     } else {
                   3631:         my %langhash = &getlangs($touname,$toudom);
                   3632:         if ($langhash{'languages'} ne '') {
                   3633:             @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
                   3634:         } else {
                   3635:             my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
                   3636:             if ($domdefs{'lang_def'} ne '') {
                   3637:                 @userlangs = ($domdefs{'lang_def'});
                   3638:             }
                   3639:         }
                   3640:     }
                   3641:     my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
                   3642:     my $user_lh = Apache::localize->get_handle(@languages);
                   3643:     return $user_lh;
                   3644: }
                   3645: 
                   3646: 
1.112     bowersj2 3647: ###############################################################
                   3648: ##               Student Answer Attempts                     ##
                   3649: ###############################################################
                   3650: 
                   3651: =pod
                   3652: 
                   3653: =head1 Alternate Problem Views
                   3654: 
                   3655: =over 4
                   3656: 
1.648     raeburn  3657: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112     bowersj2 3658:     $getattempt, $regexp, $gradesub)
                   3659: 
                   3660: Return string with previous attempt on problem. Arguments:
                   3661: 
                   3662: =over 4
                   3663: 
                   3664: =item * $symb: Problem, including path
                   3665: 
                   3666: =item * $username: username of the desired student
                   3667: 
                   3668: =item * $domain: domain of the desired student
1.14      harris41 3669: 
1.112     bowersj2 3670: =item * $course: Course ID
1.14      harris41 3671: 
1.112     bowersj2 3672: =item * $getattempt: Leave blank for all attempts, otherwise put
                   3673:     something
1.14      harris41 3674: 
1.112     bowersj2 3675: =item * $regexp: if string matches this regexp, the string will be
                   3676:     sent to $gradesub
1.14      harris41 3677: 
1.112     bowersj2 3678: =item * $gradesub: routine that processes the string if it matches $regexp
1.14      harris41 3679: 
1.112     bowersj2 3680: =back
1.14      harris41 3681: 
1.112     bowersj2 3682: The output string is a table containing all desired attempts, if any.
1.16      harris41 3683: 
1.112     bowersj2 3684: =cut
1.1       albertel 3685: 
                   3686: sub get_previous_attempt {
1.43      ng       3687:   my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1       albertel 3688:   my $prevattempts='';
1.43      ng       3689:   no strict 'refs';
1.1       albertel 3690:   if ($symb) {
1.3       albertel 3691:     my (%returnhash)=
                   3692:       &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1       albertel 3693:     if ($returnhash{'version'}) {
                   3694:       my %lasthash=();
                   3695:       my $version;
                   3696:       for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356     albertel 3697:         foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
                   3698: 	  $lasthash{$key}=$returnhash{$version.':'.$key};
1.19      harris41 3699:         }
1.1       albertel 3700:       }
1.596     albertel 3701:       $prevattempts=&start_data_table().&start_data_table_header_row();
                   3702:       $prevattempts.='<th>'.&mt('History').'</th>';
1.978     raeburn  3703:       my (%typeparts,%lasthidden);
1.945     raeburn  3704:       my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356     albertel 3705:       foreach my $key (sort(keys(%lasthash))) {
                   3706: 	my ($ign,@parts) = split(/\./,$key);
1.41      ng       3707: 	if ($#parts > 0) {
1.31      albertel 3708: 	  my $data=$parts[-1];
1.989     raeburn  3709:           next if ($data eq 'foilorder');
1.31      albertel 3710: 	  pop(@parts);
1.1010    www      3711:           $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.'&nbsp;</th>';
1.945     raeburn  3712:           if ($data eq 'type') {
                   3713:               unless ($showsurv) {
                   3714:                   my $id = join(',',@parts);
                   3715:                   $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978     raeburn  3716:                   if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
                   3717:                       $lasthidden{$ign.'.'.$id} = 1;
                   3718:                   }
1.945     raeburn  3719:               }
1.1010    www      3720:           } 
1.31      albertel 3721: 	} else {
1.41      ng       3722: 	  if ($#parts == 0) {
                   3723: 	    $prevattempts.='<th>'.$parts[0].'</th>';
                   3724: 	  } else {
                   3725: 	    $prevattempts.='<th>'.$ign.'</th>';
                   3726: 	  }
1.31      albertel 3727: 	}
1.16      harris41 3728:       }
1.596     albertel 3729:       $prevattempts.=&end_data_table_header_row();
1.40      ng       3730:       if ($getattempt eq '') {
                   3731: 	for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945     raeburn  3732:             my @hidden;
                   3733:             if (%typeparts) {
                   3734:                 foreach my $id (keys(%typeparts)) {
                   3735:                     if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
                   3736:                         push(@hidden,$id);
                   3737:                     }
                   3738:                 }
                   3739:             }
                   3740:             $prevattempts.=&start_data_table_row().
                   3741:                            '<td>'.&mt('Transaction [_1]',$version).'</td>';
                   3742:             if (@hidden) {
                   3743:                 foreach my $key (sort(keys(%lasthash))) {
1.989     raeburn  3744:                     next if ($key =~ /\.foilorder$/);
1.945     raeburn  3745:                     my $hide;
                   3746:                     foreach my $id (@hidden) {
                   3747:                         if ($key =~ /^\Q$id\E/) {
                   3748:                             $hide = 1;
                   3749:                             last;
                   3750:                         }
                   3751:                     }
                   3752:                     if ($hide) {
                   3753:                         my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
                   3754:                         if (($data eq 'award') || ($data eq 'awarddetail')) {
                   3755:                             my $value = &format_previous_attempt_value($key,
                   3756:                                              $returnhash{$version.':'.$key});
                   3757:                             $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3758:                         } else {
                   3759:                             $prevattempts.='<td>&nbsp;</td>';
                   3760:                         }
                   3761:                     } else {
                   3762:                         if ($key =~ /\./) {
                   3763:                             my $value = &format_previous_attempt_value($key,
                   3764:                                               $returnhash{$version.':'.$key});
                   3765:                             $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3766:                         } else {
                   3767:                             $prevattempts.='<td>&nbsp;</td>';
                   3768:                         }
                   3769:                     }
                   3770:                 }
                   3771:             } else {
                   3772: 	        foreach my $key (sort(keys(%lasthash))) {
1.989     raeburn  3773:                     next if ($key =~ /\.foilorder$/);
1.945     raeburn  3774: 		    my $value = &format_previous_attempt_value($key,
                   3775: 			            $returnhash{$version.':'.$key});
                   3776: 		    $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3777: 	        }
                   3778:             }
                   3779: 	    $prevattempts.=&end_data_table_row();
1.40      ng       3780: 	 }
1.1       albertel 3781:       }
1.945     raeburn  3782:       my @currhidden = keys(%lasthidden);
1.596     albertel 3783:       $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356     albertel 3784:       foreach my $key (sort(keys(%lasthash))) {
1.989     raeburn  3785:           next if ($key =~ /\.foilorder$/);
1.945     raeburn  3786:           if (%typeparts) {
                   3787:               my $hidden;
                   3788:               foreach my $id (@currhidden) {
                   3789:                   if ($key =~ /^\Q$id\E/) {
                   3790:                       $hidden = 1;
                   3791:                       last;
                   3792:                   }
                   3793:               }
                   3794:               if ($hidden) {
                   3795:                   my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
                   3796:                   if (($data eq 'award') || ($data eq 'awarddetail')) {
                   3797:                       my $value = &format_previous_attempt_value($key,$lasthash{$key});
                   3798:                       if ($key =~/$regexp$/ && (defined &$gradesub)) {
                   3799:                           $value = &$gradesub($value);
                   3800:                       }
                   3801:                       $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3802:                   } else {
                   3803:                       $prevattempts.='<td>&nbsp;</td>';
                   3804:                   }
                   3805:               } else {
                   3806:                   my $value = &format_previous_attempt_value($key,$lasthash{$key});
                   3807:                   if ($key =~/$regexp$/ && (defined &$gradesub)) {
                   3808:                       $value = &$gradesub($value);
                   3809:                   }
                   3810:                   $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3811:               }
                   3812:           } else {
                   3813: 	      my $value = &format_previous_attempt_value($key,$lasthash{$key});
                   3814: 	      if ($key =~/$regexp$/ && (defined &$gradesub)) {
                   3815:                   $value = &$gradesub($value);
                   3816:               }
                   3817: 	      $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3818:           }
1.16      harris41 3819:       }
1.596     albertel 3820:       $prevattempts.= &end_data_table_row().&end_data_table();
1.1       albertel 3821:     } else {
1.596     albertel 3822:       $prevattempts=
                   3823: 	  &start_data_table().&start_data_table_row().
                   3824: 	  '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
                   3825: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3826:     }
                   3827:   } else {
1.596     albertel 3828:     $prevattempts=
                   3829: 	  &start_data_table().&start_data_table_row().
                   3830: 	  '<td>'.&mt('No data.').'</td>'.
                   3831: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3832:   }
1.10      albertel 3833: }
                   3834: 
1.581     albertel 3835: sub format_previous_attempt_value {
                   3836:     my ($key,$value) = @_;
1.1011    www      3837:     if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581     albertel 3838: 	$value = &Apache::lonlocal::locallocaltime($value);
                   3839:     } elsif (ref($value) eq 'ARRAY') {
                   3840: 	$value = '('.join(', ', @{ $value }).')';
1.988     raeburn  3841:     } elsif ($key =~ /answerstring$/) {
                   3842:         my %answers = &Apache::lonnet::str2hash($value);
                   3843:         my @anskeys = sort(keys(%answers));
                   3844:         if (@anskeys == 1) {
                   3845:             my $answer = $answers{$anskeys[0]};
1.1001    raeburn  3846:             if ($answer =~ m{\0}) {
                   3847:                 $answer =~ s{\0}{,}g;
1.988     raeburn  3848:             }
                   3849:             my $tag_internal_answer_name = 'INTERNAL';
                   3850:             if ($anskeys[0] eq $tag_internal_answer_name) {
                   3851:                 $value = $answer; 
                   3852:             } else {
                   3853:                 $value = $anskeys[0].'='.$answer;
                   3854:             }
                   3855:         } else {
                   3856:             foreach my $ans (@anskeys) {
                   3857:                 my $answer = $answers{$ans};
1.1001    raeburn  3858:                 if ($answer =~ m{\0}) {
                   3859:                     $answer =~ s{\0}{,}g;
1.988     raeburn  3860:                 }
                   3861:                 $value .=  $ans.'='.$answer.'<br />';;
                   3862:             } 
                   3863:         }
1.581     albertel 3864:     } else {
                   3865: 	$value = &unescape($value);
                   3866:     }
                   3867:     return $value;
                   3868: }
                   3869: 
                   3870: 
1.107     albertel 3871: sub relative_to_absolute {
                   3872:     my ($url,$output)=@_;
                   3873:     my $parser=HTML::TokeParser->new(\$output);
                   3874:     my $token;
                   3875:     my $thisdir=$url;
                   3876:     my @rlinks=();
                   3877:     while ($token=$parser->get_token) {
                   3878: 	if ($token->[0] eq 'S') {
                   3879: 	    if ($token->[1] eq 'a') {
                   3880: 		if ($token->[2]->{'href'}) {
                   3881: 		    $rlinks[$#rlinks+1]=$token->[2]->{'href'};
                   3882: 		}
                   3883: 	    } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
                   3884: 		$rlinks[$#rlinks+1]=$token->[2]->{'src'};
                   3885: 	    } elsif ($token->[1] eq 'base') {
                   3886: 		$thisdir=$token->[2]->{'href'};
                   3887: 	    }
                   3888: 	}
                   3889:     }
                   3890:     $thisdir=~s-/[^/]*$--;
1.356     albertel 3891:     foreach my $link (@rlinks) {
1.726     raeburn  3892: 	unless (($link=~/^https?\:\/\//i) ||
1.356     albertel 3893: 		($link=~/^\//) ||
                   3894: 		($link=~/^javascript:/i) ||
                   3895: 		($link=~/^mailto:/i) ||
                   3896: 		($link=~/^\#/)) {
                   3897: 	    my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
                   3898: 	    $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107     albertel 3899: 	}
                   3900:     }
                   3901: # -------------------------------------------------- Deal with Applet codebases
                   3902:     $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
                   3903:     return $output;
                   3904: }
                   3905: 
1.112     bowersj2 3906: =pod
                   3907: 
1.648     raeburn  3908: =item * &get_student_view()
1.112     bowersj2 3909: 
                   3910: show a snapshot of what student was looking at
                   3911: 
                   3912: =cut
                   3913: 
1.10      albertel 3914: sub get_student_view {
1.186     albertel 3915:   my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114     www      3916:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3917:   my (%form);
1.10      albertel 3918:   my @elements=('symb','courseid','domain','username');
                   3919:   foreach my $element (@elements) {
1.186     albertel 3920:       $form{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3921:   }
1.186     albertel 3922:   if (defined($moreenv)) {
                   3923:       %form=(%form,%{$moreenv});
                   3924:   }
1.236     albertel 3925:   if (defined($target)) { $form{'grade_target'} = $target; }
1.107     albertel 3926:   $feedurl=&Apache::lonnet::clutter($feedurl);
1.650     www      3927:   my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11      albertel 3928:   $userview=~s/\<body[^\>]*\>//gi;
                   3929:   $userview=~s/\<\/body\>//gi;
                   3930:   $userview=~s/\<html\>//gi;
                   3931:   $userview=~s/\<\/html\>//gi;
                   3932:   $userview=~s/\<head\>//gi;
                   3933:   $userview=~s/\<\/head\>//gi;
                   3934:   $userview=~s/action\s*\=/would_be_action\=/gi;
1.107     albertel 3935:   $userview=&relative_to_absolute($feedurl,$userview);
1.650     www      3936:   if (wantarray) {
                   3937:      return ($userview,$response);
                   3938:   } else {
                   3939:      return $userview;
                   3940:   }
                   3941: }
                   3942: 
                   3943: sub get_student_view_with_retries {
                   3944:   my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
                   3945: 
                   3946:     my $ok = 0;                 # True if we got a good response.
                   3947:     my $content;
                   3948:     my $response;
                   3949: 
                   3950:     # Try to get the student_view done. within the retries count:
                   3951:     
                   3952:     do {
                   3953:          ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
                   3954:          $ok      = $response->is_success;
                   3955:          if (!$ok) {
                   3956:             &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
                   3957:          }
                   3958:          $retries--;
                   3959:     } while (!$ok && ($retries > 0));
                   3960:     
                   3961:     if (!$ok) {
                   3962:        $content = '';          # On error return an empty content.
                   3963:     }
1.651     www      3964:     if (wantarray) {
                   3965:        return ($content, $response);
                   3966:     } else {
                   3967:        return $content;
                   3968:     }
1.11      albertel 3969: }
                   3970: 
1.112     bowersj2 3971: =pod
                   3972: 
1.648     raeburn  3973: =item * &get_student_answers() 
1.112     bowersj2 3974: 
                   3975: show a snapshot of how student was answering problem
                   3976: 
                   3977: =cut
                   3978: 
1.11      albertel 3979: sub get_student_answers {
1.100     sakharuk 3980:   my ($symb,$username,$domain,$courseid,%form) = @_;
1.114     www      3981:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3982:   my (%moreenv);
1.11      albertel 3983:   my @elements=('symb','courseid','domain','username');
                   3984:   foreach my $element (@elements) {
1.186     albertel 3985:     $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3986:   }
1.186     albertel 3987:   $moreenv{'grade_target'}='answer';
                   3988:   %moreenv=(%form,%moreenv);
1.497     raeburn  3989:   $feedurl = &Apache::lonnet::clutter($feedurl);
                   3990:   my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10      albertel 3991:   return $userview;
1.1       albertel 3992: }
1.116     albertel 3993: 
                   3994: =pod
                   3995: 
                   3996: =item * &submlink()
                   3997: 
1.242     albertel 3998: Inputs: $text $uname $udom $symb $target
1.116     albertel 3999: 
                   4000: Returns: A link to grades.pm such as to see the SUBM view of a student
                   4001: 
                   4002: =cut
                   4003: 
                   4004: ###############################################
                   4005: sub submlink {
1.242     albertel 4006:     my ($text,$uname,$udom,$symb,$target)=@_;
1.116     albertel 4007:     if (!($uname && $udom)) {
                   4008: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 4009: 	    &Apache::lonnet::whichuser($symb);
1.116     albertel 4010: 	if (!$symb) { $symb=$cursymb; }
                   4011:     }
1.254     matthew  4012:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      4013:     $symb=&escape($symb);
1.960     bisitz   4014:     if ($target) { $target=" target=\"$target\""; }
                   4015:     return
                   4016:         '<a href="/adm/grades?command=submission'.
                   4017:         '&amp;symb='.$symb.
                   4018:         '&amp;student='.$uname.
                   4019:         '&amp;userdom='.$udom.'"'.
                   4020:         $target.'>'.$text.'</a>';
1.242     albertel 4021: }
                   4022: ##############################################
                   4023: 
                   4024: =pod
                   4025: 
                   4026: =item * &pgrdlink()
                   4027: 
                   4028: Inputs: $text $uname $udom $symb $target
                   4029: 
                   4030: Returns: A link to grades.pm such as to see the PGRD view of a student
                   4031: 
                   4032: =cut
                   4033: 
                   4034: ###############################################
                   4035: sub pgrdlink {
                   4036:     my $link=&submlink(@_);
                   4037:     $link=~s/(&command=submission)/$1&showgrading=yes/;
                   4038:     return $link;
                   4039: }
                   4040: ##############################################
                   4041: 
                   4042: =pod
                   4043: 
                   4044: =item * &pprmlink()
                   4045: 
                   4046: Inputs: $text $uname $udom $symb $target
                   4047: 
                   4048: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283     albertel 4049: student and a specific resource
1.242     albertel 4050: 
                   4051: =cut
                   4052: 
                   4053: ###############################################
                   4054: sub pprmlink {
                   4055:     my ($text,$uname,$udom,$symb,$target)=@_;
                   4056:     if (!($uname && $udom)) {
                   4057: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 4058: 	    &Apache::lonnet::whichuser($symb);
1.242     albertel 4059: 	if (!$symb) { $symb=$cursymb; }
                   4060:     }
1.254     matthew  4061:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      4062:     $symb=&escape($symb);
1.242     albertel 4063:     if ($target) { $target="target=\"$target\""; }
1.595     albertel 4064:     return '<a href="/adm/parmset?command=set&amp;'.
                   4065: 	'symb='.$symb.'&amp;uname='.$uname.
                   4066: 	'&amp;udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116     albertel 4067: }
                   4068: ##############################################
1.37      matthew  4069: 
1.112     bowersj2 4070: =pod
                   4071: 
                   4072: =back
                   4073: 
                   4074: =cut
                   4075: 
1.37      matthew  4076: ###############################################
1.51      www      4077: 
                   4078: 
                   4079: sub timehash {
1.687     raeburn  4080:     my ($thistime) = @_;
                   4081:     my $timezone = &Apache::lonlocal::gettimezone();
                   4082:     my $dt = DateTime->from_epoch(epoch => $thistime)
                   4083:                      ->set_time_zone($timezone);
                   4084:     my $wday = $dt->day_of_week();
                   4085:     if ($wday == 7) { $wday = 0; }
                   4086:     return ( 'second' => $dt->second(),
                   4087:              'minute' => $dt->minute(),
                   4088:              'hour'   => $dt->hour(),
                   4089:              'day'     => $dt->day_of_month(),
                   4090:              'month'   => $dt->month(),
                   4091:              'year'    => $dt->year(),
                   4092:              'weekday' => $wday,
                   4093:              'dayyear' => $dt->day_of_year(),
                   4094:              'dlsav'   => $dt->is_dst() );
1.51      www      4095: }
                   4096: 
1.370     www      4097: sub utc_string {
                   4098:     my ($date)=@_;
1.371     www      4099:     return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370     www      4100: }
                   4101: 
1.51      www      4102: sub maketime {
                   4103:     my %th=@_;
1.687     raeburn  4104:     my ($epoch_time,$timezone,$dt);
                   4105:     $timezone = &Apache::lonlocal::gettimezone();
                   4106:     eval {
                   4107:         $dt = DateTime->new( year   => $th{'year'},
                   4108:                              month  => $th{'month'},
                   4109:                              day    => $th{'day'},
                   4110:                              hour   => $th{'hour'},
                   4111:                              minute => $th{'minute'},
                   4112:                              second => $th{'second'},
                   4113:                              time_zone => $timezone,
                   4114:                          );
                   4115:     };
                   4116:     if (!$@) {
                   4117:         $epoch_time = $dt->epoch;
                   4118:         if ($epoch_time) {
                   4119:             return $epoch_time;
                   4120:         }
                   4121:     }
1.51      www      4122:     return POSIX::mktime(
                   4123:         ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210     www      4124:          $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70      www      4125: }
                   4126: 
                   4127: #########################################
1.51      www      4128: 
                   4129: sub findallcourses {
1.482     raeburn  4130:     my ($roles,$uname,$udom) = @_;
1.355     albertel 4131:     my %roles;
                   4132:     if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348     albertel 4133:     my %courses;
1.51      www      4134:     my $now=time;
1.482     raeburn  4135:     if (!defined($uname)) {
                   4136:         $uname = $env{'user.name'};
                   4137:     }
                   4138:     if (!defined($udom)) {
                   4139:         $udom = $env{'user.domain'};
                   4140:     }
                   4141:     if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073    raeburn  4142:         my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482     raeburn  4143:         if (!%roles) {
                   4144:             %roles = (
                   4145:                        cc => 1,
1.907     raeburn  4146:                        co => 1,
1.482     raeburn  4147:                        in => 1,
                   4148:                        ep => 1,
                   4149:                        ta => 1,
                   4150:                        cr => 1,
                   4151:                        st => 1,
                   4152:              );
                   4153:         }
                   4154:         foreach my $entry (keys(%roleshash)) {
                   4155:             my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
                   4156:             if ($trole =~ /^cr/) { 
                   4157:                 next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
                   4158:             } else {
                   4159:                 next if (!exists($roles{$trole}));
                   4160:             }
                   4161:             if ($tend) {
                   4162:                 next if ($tend < $now);
                   4163:             }
                   4164:             if ($tstart) {
                   4165:                 next if ($tstart > $now);
                   4166:             }
1.1058    raeburn  4167:             my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482     raeburn  4168:             (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058    raeburn  4169:             my $value = $trole.'/'.$cdom.'/';
1.482     raeburn  4170:             if ($secpart eq '') {
                   4171:                 ($cnum,$role) = split(/_/,$cnumpart); 
                   4172:                 $sec = 'none';
1.1058    raeburn  4173:                 $value .= $cnum.'/';
1.482     raeburn  4174:             } else {
                   4175:                 $cnum = $cnumpart;
                   4176:                 ($sec,$role) = split(/_/,$secpart);
1.1058    raeburn  4177:                 $value .= $cnum.'/'.$sec;
                   4178:             }
                   4179:             if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
                   4180:                 unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
                   4181:                     push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
                   4182:                 }
                   4183:             } else {
                   4184:                 @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490     raeburn  4185:             }
1.482     raeburn  4186:         }
                   4187:     } else {
                   4188:         foreach my $key (keys(%env)) {
1.483     albertel 4189: 	    if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
                   4190:                  $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482     raeburn  4191: 	        my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
                   4192: 	        next if ($role eq 'ca' || $role eq 'aa');
                   4193: 	        next if (%roles && !exists($roles{$role}));
                   4194: 	        my ($starttime,$endtime)=split(/\./,$env{$key});
                   4195:                 my $active=1;
                   4196:                 if ($starttime) {
                   4197: 		    if ($now<$starttime) { $active=0; }
                   4198:                 }
                   4199:                 if ($endtime) {
                   4200:                     if ($now>$endtime) { $active=0; }
                   4201:                 }
                   4202:                 if ($active) {
1.1058    raeburn  4203:                     my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482     raeburn  4204:                     if ($sec eq '') {
                   4205:                         $sec = 'none';
1.1058    raeburn  4206:                     } else {
                   4207:                         $value .= $sec;
                   4208:                     }
                   4209:                     if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
                   4210:                         unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
                   4211:                             push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
                   4212:                         }
                   4213:                     } else {
                   4214:                         @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482     raeburn  4215:                     }
1.474     raeburn  4216:                 }
                   4217:             }
1.51      www      4218:         }
                   4219:     }
1.474     raeburn  4220:     return %courses;
1.51      www      4221: }
1.37      matthew  4222: 
1.54      www      4223: ###############################################
1.474     raeburn  4224: 
                   4225: sub blockcheck {
1.1062    raeburn  4226:     my ($setters,$activity,$uname,$udom,$url) = @_;
1.490     raeburn  4227: 
                   4228:     if (!defined($udom)) {
                   4229:         $udom = $env{'user.domain'};
                   4230:     }
                   4231:     if (!defined($uname)) {
                   4232:         $uname = $env{'user.name'};
                   4233:     }
                   4234: 
                   4235:     # If uname and udom are for a course, check for blocks in the course.
                   4236: 
                   4237:     if (&Apache::lonnet::is_course($udom,$uname)) {
1.1062    raeburn  4238:         my ($startblock,$endblock,$triggerblock) = 
                   4239:             &get_blocks($setters,$activity,$udom,$uname,$url);
                   4240:         return ($startblock,$endblock,$triggerblock);
1.490     raeburn  4241:     }
1.474     raeburn  4242: 
1.502     raeburn  4243:     my $startblock = 0;
                   4244:     my $endblock = 0;
1.1062    raeburn  4245:     my $triggerblock = '';
1.482     raeburn  4246:     my %live_courses = &findallcourses(undef,$uname,$udom);
1.474     raeburn  4247: 
1.490     raeburn  4248:     # If uname is for a user, and activity is course-specific, i.e.,
                   4249:     # boards, chat or groups, check for blocking in current course only.
1.474     raeburn  4250: 
1.490     raeburn  4251:     if (($activity eq 'boards' || $activity eq 'chat' ||
                   4252:          $activity eq 'groups') && ($env{'request.course.id'})) {
                   4253:         foreach my $key (keys(%live_courses)) {
                   4254:             if ($key ne $env{'request.course.id'}) {
                   4255:                 delete($live_courses{$key});
                   4256:             }
                   4257:         }
                   4258:     }
                   4259: 
                   4260:     my $otheruser = 0;
                   4261:     my %own_courses;
                   4262:     if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
                   4263:         # Resource belongs to user other than current user.
                   4264:         $otheruser = 1;
                   4265:         # Gather courses for current user
                   4266:         %own_courses = 
                   4267:             &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
                   4268:     }
                   4269: 
                   4270:     # Gather active course roles - course coordinator, instructor, 
                   4271:     # exam proctor, ta, student, or custom role.
1.474     raeburn  4272: 
                   4273:     foreach my $course (keys(%live_courses)) {
1.482     raeburn  4274:         my ($cdom,$cnum);
                   4275:         if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
                   4276:             $cdom = $env{'course.'.$course.'.domain'};
                   4277:             $cnum = $env{'course.'.$course.'.num'};
                   4278:         } else {
1.490     raeburn  4279:             ($cdom,$cnum) = split(/_/,$course); 
1.482     raeburn  4280:         }
                   4281:         my $no_ownblock = 0;
                   4282:         my $no_userblock = 0;
1.533     raeburn  4283:         if ($otheruser && $activity ne 'com') {
1.490     raeburn  4284:             # Check if current user has 'evb' priv for this
                   4285:             if (defined($own_courses{$course})) {
                   4286:                 foreach my $sec (keys(%{$own_courses{$course}})) {
                   4287:                     my $checkrole = 'cm./'.$cdom.'/'.$cnum;
                   4288:                     if ($sec ne 'none') {
                   4289:                         $checkrole .= '/'.$sec;
                   4290:                     }
                   4291:                     if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   4292:                         $no_ownblock = 1;
                   4293:                         last;
                   4294:                     }
                   4295:                 }
                   4296:             }
                   4297:             # if they have 'evb' priv and are currently not playing student
                   4298:             next if (($no_ownblock) &&
                   4299:                  ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
                   4300:         }
1.474     raeburn  4301:         foreach my $sec (keys(%{$live_courses{$course}})) {
1.482     raeburn  4302:             my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474     raeburn  4303:             if ($sec ne 'none') {
1.482     raeburn  4304:                 $checkrole .= '/'.$sec;
1.474     raeburn  4305:             }
1.490     raeburn  4306:             if ($otheruser) {
                   4307:                 # Resource belongs to user other than current user.
                   4308:                 # Assemble privs for that user, and check for 'evb' priv.
1.1058    raeburn  4309:                 my (%allroles,%userroles);
                   4310:                 if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
                   4311:                     foreach my $entry (@{$live_courses{$course}{$sec}}) { 
                   4312:                         my ($trole,$tdom,$tnum,$tsec);
                   4313:                         if ($entry =~ /^cr/) {
                   4314:                             ($trole,$tdom,$tnum,$tsec) = 
                   4315:                                 ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
                   4316:                         } else {
                   4317:                            ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
                   4318:                         }
                   4319:                         my ($spec,$area,$trest);
                   4320:                         $area = '/'.$tdom.'/'.$tnum;
                   4321:                         $trest = $tnum;
                   4322:                         if ($tsec ne '') {
                   4323:                             $area .= '/'.$tsec;
                   4324:                             $trest .= '/'.$tsec;
                   4325:                         }
                   4326:                         $spec = $trole.'.'.$area;
                   4327:                         if ($trole =~ /^cr/) {
                   4328:                             &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
                   4329:                                                               $tdom,$spec,$trest,$area);
                   4330:                         } else {
                   4331:                             &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
                   4332:                                                                 $tdom,$spec,$trest,$area);
                   4333:                         }
                   4334:                     }
                   4335:                     my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
                   4336:                     if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
                   4337:                         if ($1) {
                   4338:                             $no_userblock = 1;
                   4339:                             last;
                   4340:                         }
1.486     raeburn  4341:                     }
                   4342:                 }
1.490     raeburn  4343:             } else {
                   4344:                 # Resource belongs to current user
                   4345:                 # Check for 'evb' priv via lonnet::allowed().
1.482     raeburn  4346:                 if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   4347:                     $no_ownblock = 1;
                   4348:                     last;
                   4349:                 }
1.474     raeburn  4350:             }
                   4351:         }
                   4352:         # if they have the evb priv and are currently not playing student
1.482     raeburn  4353:         next if (($no_ownblock) &&
1.491     albertel 4354:                  ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482     raeburn  4355:         next if ($no_userblock);
1.474     raeburn  4356: 
1.866     kalberla 4357:         # Retrieve blocking times and identity of locker for course
1.490     raeburn  4358:         # of specified user, unless user has 'evb' privilege.
1.502     raeburn  4359:         
1.1062    raeburn  4360:         my ($start,$end,$trigger) = 
                   4361:             &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502     raeburn  4362:         if (($start != 0) && 
                   4363:             (($startblock == 0) || ($startblock > $start))) {
                   4364:             $startblock = $start;
1.1062    raeburn  4365:             if ($trigger ne '') {
                   4366:                 $triggerblock = $trigger;
                   4367:             }
1.502     raeburn  4368:         }
                   4369:         if (($end != 0)  &&
                   4370:             (($endblock == 0) || ($endblock < $end))) {
                   4371:             $endblock = $end;
1.1062    raeburn  4372:             if ($trigger ne '') {
                   4373:                 $triggerblock = $trigger;
                   4374:             }
1.502     raeburn  4375:         }
1.490     raeburn  4376:     }
1.1062    raeburn  4377:     return ($startblock,$endblock,$triggerblock);
1.490     raeburn  4378: }
                   4379: 
                   4380: sub get_blocks {
1.1062    raeburn  4381:     my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490     raeburn  4382:     my $startblock = 0;
                   4383:     my $endblock = 0;
1.1062    raeburn  4384:     my $triggerblock = '';
1.490     raeburn  4385:     my $course = $cdom.'_'.$cnum;
                   4386:     $setters->{$course} = {};
                   4387:     $setters->{$course}{'staff'} = [];
                   4388:     $setters->{$course}{'times'} = [];
1.1062    raeburn  4389:     $setters->{$course}{'triggers'} = [];
                   4390:     my (@blockers,%triggered);
                   4391:     my $now = time;
                   4392:     my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
                   4393:     if ($activity eq 'docs') {
                   4394:         @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
                   4395:         foreach my $block (@blockers) {
                   4396:             if ($block =~ /^firstaccess____(.+)$/) {
                   4397:                 my $item = $1;
                   4398:                 my $type = 'map';
                   4399:                 my $timersymb = $item;
                   4400:                 if ($item eq 'course') {
                   4401:                     $type = 'course';
                   4402:                 } elsif ($item =~ /___\d+___/) {
                   4403:                     $type = 'resource';
                   4404:                 } else {
                   4405:                     $timersymb = &Apache::lonnet::symbread($item);
                   4406:                 }
                   4407:                 my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
                   4408:                 my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
                   4409:                 $triggered{$block} = {
                   4410:                                        start => $start,
                   4411:                                        end   => $end,
                   4412:                                        type  => $type,
                   4413:                                      };
                   4414:             }
                   4415:         }
                   4416:     } else {
                   4417:         foreach my $block (keys(%commblocks)) {
                   4418:             if ($block =~ m/^(\d+)____(\d+)$/) { 
                   4419:                 my ($start,$end) = ($1,$2);
                   4420:                 if ($start <= time && $end >= time) {
                   4421:                     if (ref($commblocks{$block}) eq 'HASH') {
                   4422:                         if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
                   4423:                             if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
                   4424:                                 unless(grep(/^\Q$block\E$/,@blockers)) {
                   4425:                                     push(@blockers,$block);
                   4426:                                 }
                   4427:                             }
                   4428:                         }
                   4429:                     }
                   4430:                 }
                   4431:             } elsif ($block =~ /^firstaccess____(.+)$/) {
                   4432:                 my $item = $1;
                   4433:                 my $timersymb = $item; 
                   4434:                 my $type = 'map';
                   4435:                 if ($item eq 'course') {
                   4436:                     $type = 'course';
                   4437:                 } elsif ($item =~ /___\d+___/) {
                   4438:                     $type = 'resource';
                   4439:                 } else {
                   4440:                     $timersymb = &Apache::lonnet::symbread($item);
                   4441:                 }
                   4442:                 my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
                   4443:                 my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb}; 
                   4444:                 if ($start && $end) {
                   4445:                     if (($start <= time) && ($end >= time)) {
                   4446:                         unless (grep(/^\Q$block\E$/,@blockers)) {
                   4447:                             push(@blockers,$block);
                   4448:                             $triggered{$block} = {
                   4449:                                                    start => $start,
                   4450:                                                    end   => $end,
                   4451:                                                    type  => $type,
                   4452:                                                  };
                   4453:                         }
                   4454:                     }
1.490     raeburn  4455:                 }
1.1062    raeburn  4456:             }
                   4457:         }
                   4458:     }
                   4459:     foreach my $blocker (@blockers) {
                   4460:         my ($staff_name,$staff_dom,$title,$blocks) =
                   4461:             &parse_block_record($commblocks{$blocker});
                   4462:         push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
                   4463:         my ($start,$end,$triggertype);
                   4464:         if ($blocker =~ m/^(\d+)____(\d+)$/) {
                   4465:             ($start,$end) = ($1,$2);
                   4466:         } elsif (ref($triggered{$blocker}) eq 'HASH') {
                   4467:             $start = $triggered{$blocker}{'start'};
                   4468:             $end = $triggered{$blocker}{'end'};
                   4469:             $triggertype = $triggered{$blocker}{'type'};
                   4470:         }
                   4471:         if ($start) {
                   4472:             push(@{$$setters{$course}{'times'}}, [$start,$end]);
                   4473:             if ($triggertype) {
                   4474:                 push(@{$$setters{$course}{'triggers'}},$triggertype);
                   4475:             } else {
                   4476:                 push(@{$$setters{$course}{'triggers'}},0);
                   4477:             }
                   4478:             if ( ($startblock == 0) || ($startblock > $start) ) {
                   4479:                 $startblock = $start;
                   4480:                 if ($triggertype) {
                   4481:                     $triggerblock = $blocker;
1.474     raeburn  4482:                 }
                   4483:             }
1.1062    raeburn  4484:             if ( ($endblock == 0) || ($endblock < $end) ) {
                   4485:                $endblock = $end;
                   4486:                if ($triggertype) {
                   4487:                    $triggerblock = $blocker;
                   4488:                }
                   4489:             }
1.474     raeburn  4490:         }
                   4491:     }
1.1062    raeburn  4492:     return ($startblock,$endblock,$triggerblock);
1.474     raeburn  4493: }
                   4494: 
                   4495: sub parse_block_record {
                   4496:     my ($record) = @_;
                   4497:     my ($setuname,$setudom,$title,$blocks);
                   4498:     if (ref($record) eq 'HASH') {
                   4499:         ($setuname,$setudom) = split(/:/,$record->{'setter'});
                   4500:         $title = &unescape($record->{'event'});
                   4501:         $blocks = $record->{'blocks'};
                   4502:     } else {
                   4503:         my @data = split(/:/,$record,3);
                   4504:         if (scalar(@data) eq 2) {
                   4505:             $title = $data[1];
                   4506:             ($setuname,$setudom) = split(/@/,$data[0]);
                   4507:         } else {
                   4508:             ($setuname,$setudom,$title) = @data;
                   4509:         }
                   4510:         $blocks = { 'com' => 'on' };
                   4511:     }
                   4512:     return ($setuname,$setudom,$title,$blocks);
                   4513: }
                   4514: 
1.854     kalberla 4515: sub blocking_status {
1.1062    raeburn  4516:     my ($activity,$uname,$udom,$url) = @_;
1.1061    raeburn  4517:     my %setters;
1.890     droeschl 4518: 
1.1061    raeburn  4519: # check for active blocking
1.1062    raeburn  4520:     my ($startblock,$endblock,$triggerblock) = 
                   4521:         &blockcheck(\%setters,$activity,$uname,$udom,$url);
                   4522:     my $blocked = 0;
                   4523:     if ($startblock && $endblock) {
                   4524:         $blocked = 1;
                   4525:     }
1.890     droeschl 4526: 
1.1061    raeburn  4527: # caller just wants to know whether a block is active
                   4528:     if (!wantarray) { return $blocked; }
                   4529: 
                   4530: # build a link to a popup window containing the details
                   4531:     my $querystring  = "?activity=$activity";
                   4532: # $uname and $udom decide whose portfolio the user is trying to look at
1.1062    raeburn  4533:     if ($activity eq 'port') {
                   4534:         $querystring .= "&amp;udom=$udom"      if $udom;
                   4535:         $querystring .= "&amp;uname=$uname"    if $uname;
                   4536:     } elsif ($activity eq 'docs') {
                   4537:         $querystring .= '&amp;url='.&HTML::Entities::encode($url,'&"');
                   4538:     }
1.1061    raeburn  4539: 
                   4540:     my $output .= <<'END_MYBLOCK';
                   4541: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
                   4542:     var options = "width=" + w + ",height=" + h + ",";
                   4543:     options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
                   4544:     options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
                   4545:     var newWin = window.open(url, wdwName, options);
                   4546:     newWin.focus();
                   4547: }
1.890     droeschl 4548: END_MYBLOCK
1.854     kalberla 4549: 
1.1061    raeburn  4550:     $output = Apache::lonhtmlcommon::scripttag($output);
1.890     droeschl 4551:   
1.1061    raeburn  4552:     my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062    raeburn  4553:     my $text = &mt('Communication Blocked');
                   4554:     if ($activity eq 'docs') {
                   4555:         $text = &mt('Content Access Blocked');
1.1063    raeburn  4556:     } elsif ($activity eq 'printout') {
                   4557:         $text = &mt('Printing Blocked');
1.1062    raeburn  4558:     }
1.1061    raeburn  4559:     $output .= <<"END_BLOCK";
1.867     kalberla 4560: <div class='LC_comblock'>
1.869     kalberla 4561:   <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890     droeschl 4562:   title='$text'>
                   4563:   <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869     kalberla 4564:   <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring' 
1.890     droeschl 4565:   title='$text'>$text</a>
1.867     kalberla 4566: </div>
                   4567: 
                   4568: END_BLOCK
1.474     raeburn  4569: 
1.1061    raeburn  4570:     return ($blocked, $output);
1.854     kalberla 4571: }
1.490     raeburn  4572: 
1.60      matthew  4573: ###############################################
                   4574: 
1.682     raeburn  4575: sub check_ip_acc {
                   4576:     my ($acc)=@_;
                   4577:     &Apache::lonxml::debug("acc is $acc");
                   4578:     if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
                   4579:         return 1;
                   4580:     }
                   4581:     my $allowed=0;
                   4582:     my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
                   4583: 
                   4584:     my $name;
                   4585:     foreach my $pattern (split(',',$acc)) {
                   4586:         $pattern =~ s/^\s*//;
                   4587:         $pattern =~ s/\s*$//;
                   4588:         if ($pattern =~ /\*$/) {
                   4589:             #35.8.*
                   4590:             $pattern=~s/\*//;
                   4591:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   4592:         } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
                   4593:             #35.8.3.[34-56]
                   4594:             my $low=$2;
                   4595:             my $high=$3;
                   4596:             $pattern=$1;
                   4597:             if ($ip =~ /^\Q$pattern\E/) {
                   4598:                 my $last=(split(/\./,$ip))[3];
                   4599:                 if ($last <=$high && $last >=$low) { $allowed=1; }
                   4600:             }
                   4601:         } elsif ($pattern =~ /^\*/) {
                   4602:             #*.msu.edu
                   4603:             $pattern=~s/\*//;
                   4604:             if (!defined($name)) {
                   4605:                 use Socket;
                   4606:                 my $netaddr=inet_aton($ip);
                   4607:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   4608:             }
                   4609:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   4610:         } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
                   4611:             #127.0.0.1
                   4612:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   4613:         } else {
                   4614:             #some.name.com
                   4615:             if (!defined($name)) {
                   4616:                 use Socket;
                   4617:                 my $netaddr=inet_aton($ip);
                   4618:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   4619:             }
                   4620:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   4621:         }
                   4622:         if ($allowed) { last; }
                   4623:     }
                   4624:     return $allowed;
                   4625: }
                   4626: 
                   4627: ###############################################
                   4628: 
1.60      matthew  4629: =pod
                   4630: 
1.112     bowersj2 4631: =head1 Domain Template Functions
                   4632: 
                   4633: =over 4
                   4634: 
                   4635: =item * &determinedomain()
1.60      matthew  4636: 
                   4637: Inputs: $domain (usually will be undef)
                   4638: 
1.63      www      4639: Returns: Determines which domain should be used for designs
1.60      matthew  4640: 
                   4641: =cut
1.54      www      4642: 
1.60      matthew  4643: ###############################################
1.63      www      4644: sub determinedomain {
                   4645:     my $domain=shift;
1.531     albertel 4646:     if (! $domain) {
1.60      matthew  4647:         # Determine domain if we have not been given one
1.893     raeburn  4648:         $domain = &Apache::lonnet::default_login_domain();
1.258     albertel 4649:         if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
                   4650:         if ($env{'request.role.domain'}) { 
                   4651:             $domain=$env{'request.role.domain'}; 
1.60      matthew  4652:         }
                   4653:     }
1.63      www      4654:     return $domain;
                   4655: }
                   4656: ###############################################
1.517     raeburn  4657: 
1.518     albertel 4658: sub devalidate_domconfig_cache {
                   4659:     my ($udom)=@_;
                   4660:     &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
                   4661: }
                   4662: 
                   4663: # ---------------------- Get domain configuration for a domain
                   4664: sub get_domainconf {
                   4665:     my ($udom) = @_;
                   4666:     my $cachetime=1800;
                   4667:     my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
                   4668:     if (defined($cached)) { return %{$result}; }
                   4669: 
                   4670:     my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948     raeburn  4671: 					     ['login','rolecolors','autoenroll'],$udom);
1.632     raeburn  4672:     my (%designhash,%legacy);
1.518     albertel 4673:     if (keys(%domconfig) > 0) {
                   4674:         if (ref($domconfig{'login'}) eq 'HASH') {
1.632     raeburn  4675:             if (keys(%{$domconfig{'login'}})) {
                   4676:                 foreach my $key (keys(%{$domconfig{'login'}})) {
1.699     raeburn  4677:                     if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946     raeburn  4678:                         if ($key eq 'loginvia') {
                   4679:                             if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
1.1013    raeburn  4680:                                 foreach my $hostname (keys(%{$domconfig{'login'}{'loginvia'}})) {
1.948     raeburn  4681:                                     if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
                   4682:                                         if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
                   4683:                                             my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
                   4684:                                             $designhash{$udom.'.login.loginvia'} = $server;
                   4685:                                             if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
                   4686: 
                   4687:                                                 $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
                   4688:                                             } else {
1.1013    raeburn  4689:                                                 $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
1.948     raeburn  4690:                                             }
                   4691:                                             if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
                   4692:                                                 $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
                   4693:                                             }
1.946     raeburn  4694:                                         }
                   4695:                                     }
                   4696:                                 }
                   4697:                             }
                   4698:                         } else {
                   4699:                             foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
                   4700:                                 $designhash{$udom.'.login.'.$key.'_'.$img} = 
                   4701:                                     $domconfig{'login'}{$key}{$img};
                   4702:                             }
1.699     raeburn  4703:                         }
                   4704:                     } else {
                   4705:                         $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
                   4706:                     }
1.632     raeburn  4707:                 }
                   4708:             } else {
                   4709:                 $legacy{'login'} = 1;
1.518     albertel 4710:             }
1.632     raeburn  4711:         } else {
                   4712:             $legacy{'login'} = 1;
1.518     albertel 4713:         }
                   4714:         if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632     raeburn  4715:             if (keys(%{$domconfig{'rolecolors'}})) {
                   4716:                 foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
                   4717:                     if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
                   4718:                         foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
                   4719:                             $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
                   4720:                         }
1.518     albertel 4721:                     }
                   4722:                 }
1.632     raeburn  4723:             } else {
                   4724:                 $legacy{'rolecolors'} = 1;
1.518     albertel 4725:             }
1.632     raeburn  4726:         } else {
                   4727:             $legacy{'rolecolors'} = 1;
1.518     albertel 4728:         }
1.948     raeburn  4729:         if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   4730:             if ($domconfig{'autoenroll'}{'co-owners'}) {
                   4731:                 $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
                   4732:             }
                   4733:         }
1.632     raeburn  4734:         if (keys(%legacy) > 0) {
                   4735:             my %legacyhash = &get_legacy_domconf($udom);
                   4736:             foreach my $item (keys(%legacyhash)) {
                   4737:                 if ($item =~ /^\Q$udom\E\.login/) {
                   4738:                     if ($legacy{'login'}) { 
                   4739:                         $designhash{$item} = $legacyhash{$item};
                   4740:                     }
                   4741:                 } else {
                   4742:                     if ($legacy{'rolecolors'}) {
                   4743:                         $designhash{$item} = $legacyhash{$item};
                   4744:                     }
1.518     albertel 4745:                 }
                   4746:             }
                   4747:         }
1.632     raeburn  4748:     } else {
                   4749:         %designhash = &get_legacy_domconf($udom); 
1.518     albertel 4750:     }
                   4751:     &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
                   4752: 				  $cachetime);
                   4753:     return %designhash;
                   4754: }
                   4755: 
1.632     raeburn  4756: sub get_legacy_domconf {
                   4757:     my ($udom) = @_;
                   4758:     my %legacyhash;
                   4759:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
                   4760:     my $designfile =  $designdir.'/'.$udom.'.tab';
                   4761:     if (-e $designfile) {
                   4762:         if ( open (my $fh,"<$designfile") ) {
                   4763:             while (my $line = <$fh>) {
                   4764:                 next if ($line =~ /^\#/);
                   4765:                 chomp($line);
                   4766:                 my ($key,$val)=(split(/\=/,$line));
                   4767:                 if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
                   4768:             }
                   4769:             close($fh);
                   4770:         }
                   4771:     }
1.1026    raeburn  4772:     if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632     raeburn  4773:         $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
                   4774:     }
                   4775:     return %legacyhash;
                   4776: }
                   4777: 
1.63      www      4778: =pod
                   4779: 
1.112     bowersj2 4780: =item * &domainlogo()
1.63      www      4781: 
                   4782: Inputs: $domain (usually will be undef)
                   4783: 
                   4784: Returns: A link to a domain logo, if the domain logo exists.
                   4785: If the domain logo does not exist, a description of the domain.
                   4786: 
                   4787: =cut
1.112     bowersj2 4788: 
1.63      www      4789: ###############################################
                   4790: sub domainlogo {
1.517     raeburn  4791:     my $domain = &determinedomain(shift);
1.518     albertel 4792:     my %designhash = &get_domainconf($domain);    
1.517     raeburn  4793:     # See if there is a logo
                   4794:     if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519     raeburn  4795:         my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538     albertel 4796:         if ($imgsrc =~ m{^/(adm|res)/}) {
                   4797: 	    if ($imgsrc =~ m{^/res/}) {
                   4798: 		my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
                   4799: 		&Apache::lonnet::repcopy($local_name);
                   4800: 	    }
                   4801: 	   $imgsrc = &lonhttpdurl($imgsrc);
1.519     raeburn  4802:         } 
                   4803:         return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514     albertel 4804:     } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
                   4805:         return &Apache::lonnet::domain($domain,'description');
1.59      www      4806:     } else {
1.60      matthew  4807:         return '';
1.59      www      4808:     }
                   4809: }
1.63      www      4810: ##############################################
                   4811: 
                   4812: =pod
                   4813: 
1.112     bowersj2 4814: =item * &designparm()
1.63      www      4815: 
                   4816: Inputs: $which parameter; $domain (usually will be undef)
                   4817: 
                   4818: Returns: value of designparamter $which
                   4819: 
                   4820: =cut
1.112     bowersj2 4821: 
1.397     albertel 4822: 
1.400     albertel 4823: ##############################################
1.397     albertel 4824: sub designparm {
                   4825:     my ($which,$domain)=@_;
                   4826:     if (exists($env{'environment.color.'.$which})) {
1.817     bisitz   4827:         return $env{'environment.color.'.$which};
1.96      www      4828:     }
1.63      www      4829:     $domain=&determinedomain($domain);
1.1016    raeburn  4830:     my %domdesign;
                   4831:     unless ($domain eq 'public') {
                   4832:         %domdesign = &get_domainconf($domain);
                   4833:     }
1.520     raeburn  4834:     my $output;
1.517     raeburn  4835:     if ($domdesign{$domain.'.'.$which} ne '') {
1.817     bisitz   4836:         $output = $domdesign{$domain.'.'.$which};
1.63      www      4837:     } else {
1.520     raeburn  4838:         $output = $defaultdesign{$which};
                   4839:     }
                   4840:     if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635     raeburn  4841:         ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538     albertel 4842:         if ($output =~ m{^/(adm|res)/}) {
1.817     bisitz   4843:             if ($output =~ m{^/res/}) {
                   4844:                 my $local_name = &Apache::lonnet::filelocation('',$output);
                   4845:                 &Apache::lonnet::repcopy($local_name);
                   4846:             }
1.520     raeburn  4847:             $output = &lonhttpdurl($output);
                   4848:         }
1.63      www      4849:     }
1.520     raeburn  4850:     return $output;
1.63      www      4851: }
1.59      www      4852: 
1.822     bisitz   4853: ##############################################
                   4854: =pod
                   4855: 
1.832     bisitz   4856: =item * &authorspace()
                   4857: 
1.1028    raeburn  4858: Inputs: $url (usually will be undef).
1.832     bisitz   4859: 
1.1075.2.40  raeburn  4860: Returns: Path to Authoring Space containing the resource or 
1.1028    raeburn  4861:          directory being viewed (or for which action is being taken). 
                   4862:          If $url is provided, and begins /priv/<domain>/<uname>
                   4863:          the path will be that portion of the $context argument.
                   4864:          Otherwise the path will be for the author space of the current
                   4865:          user when the current role is author, or for that of the 
                   4866:          co-author/assistant co-author space when the current role 
                   4867:          is co-author or assistant co-author.
1.832     bisitz   4868: 
                   4869: =cut
                   4870: 
                   4871: sub authorspace {
1.1028    raeburn  4872:     my ($url) = @_;
                   4873:     if ($url ne '') {
                   4874:         if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
                   4875:            return $1;
                   4876:         }
                   4877:     }
1.832     bisitz   4878:     my $caname = '';
1.1024    www      4879:     my $cadom = '';
1.1028    raeburn  4880:     if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024    www      4881:         ($cadom,$caname) =
1.832     bisitz   4882:             ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028    raeburn  4883:     } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832     bisitz   4884:         $caname = $env{'user.name'};
1.1024    www      4885:         $cadom = $env{'user.domain'};
1.832     bisitz   4886:     }
1.1028    raeburn  4887:     if (($caname ne '') && ($cadom ne '')) {
                   4888:         return "/priv/$cadom/$caname/";
                   4889:     }
                   4890:     return;
1.832     bisitz   4891: }
                   4892: 
                   4893: ##############################################
                   4894: =pod
                   4895: 
1.822     bisitz   4896: =item * &head_subbox()
                   4897: 
                   4898: Inputs: $content (contains HTML code with page functions, etc.)
                   4899: 
                   4900: Returns: HTML div with $content
                   4901:          To be included in page header
                   4902: 
                   4903: =cut
                   4904: 
                   4905: sub head_subbox {
                   4906:     my ($content)=@_;
                   4907:     my $output =
1.993     raeburn  4908:         '<div class="LC_head_subbox">'
1.822     bisitz   4909:        .$content
                   4910:        .'</div>'
                   4911: }
                   4912: 
                   4913: ##############################################
                   4914: =pod
                   4915: 
                   4916: =item * &CSTR_pageheader()
                   4917: 
1.1026    raeburn  4918: Input: (optional) filename from which breadcrumb trail is built.
                   4919:        In most cases no input as needed, as $env{'request.filename'}
                   4920:        is appropriate for use in building the breadcrumb trail.
1.822     bisitz   4921: 
                   4922: Returns: HTML div with CSTR path and recent box
1.1075.2.40  raeburn  4923:          To be included on Authoring Space pages
1.822     bisitz   4924: 
                   4925: =cut
                   4926: 
                   4927: sub CSTR_pageheader {
1.1026    raeburn  4928:     my ($trailfile) = @_;
                   4929:     if ($trailfile eq '') {
                   4930:         $trailfile = $env{'request.filename'};
                   4931:     }
                   4932: 
                   4933: # this is for resources; directories have customtitle, and crumbs
                   4934: # and select recent are created in lonpubdir.pm
                   4935: 
                   4936:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022    www      4937:     my ($udom,$uname,$thisdisfn)=
1.1075.2.29  raeburn  4938:         ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026    raeburn  4939:     my $formaction = "/priv/$udom/$uname/$thisdisfn";
                   4940:     $formaction =~ s{/+}{/}g;
1.822     bisitz   4941: 
                   4942:     my $parentpath = '';
                   4943:     my $lastitem = '';
                   4944:     if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
                   4945:         $parentpath = $1;
                   4946:         $lastitem = $2;
                   4947:     } else {
                   4948:         $lastitem = $thisdisfn;
                   4949:     }
1.921     bisitz   4950: 
                   4951:     my $output =
1.822     bisitz   4952:          '<div>'
                   4953:         .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1075.2.40  raeburn  4954:         .'<b>'.&mt('Authoring Space:').'</b> '
1.822     bisitz   4955:         .'<form name="dirs" method="post" action="'.$formaction
1.921     bisitz   4956:         .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024    www      4957:         .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921     bisitz   4958: 
                   4959:     if ($lastitem) {
                   4960:         $output .=
                   4961:              '<span class="LC_filename">'
                   4962:             .$lastitem
                   4963:             .'</span>';
                   4964:     }
                   4965:     $output .=
                   4966:          '<br />'
1.822     bisitz   4967:         #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
                   4968:         .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
                   4969:         .'</form>'
                   4970:         .&Apache::lonmenu::constspaceform()
                   4971:         .'</div>';
1.921     bisitz   4972: 
                   4973:     return $output;
1.822     bisitz   4974: }
                   4975: 
1.60      matthew  4976: ###############################################
                   4977: ###############################################
                   4978: 
                   4979: =pod
                   4980: 
1.112     bowersj2 4981: =back
                   4982: 
1.549     albertel 4983: =head1 HTML Helpers
1.112     bowersj2 4984: 
                   4985: =over 4
                   4986: 
                   4987: =item * &bodytag()
1.60      matthew  4988: 
                   4989: Returns a uniform header for LON-CAPA web pages.
                   4990: 
                   4991: Inputs: 
                   4992: 
1.112     bowersj2 4993: =over 4
                   4994: 
                   4995: =item * $title, A title to be displayed on the page.
                   4996: 
                   4997: =item * $function, the current role (can be undef).
                   4998: 
                   4999: =item * $addentries, extra parameters for the <body> tag.
                   5000: 
                   5001: =item * $bodyonly, if defined, only return the <body> tag.
                   5002: 
                   5003: =item * $domain, if defined, force a given domain.
                   5004: 
                   5005: =item * $forcereg, if page should register as content page (relevant for 
1.86      www      5006:             text interface only)
1.60      matthew  5007: 
1.814     bisitz   5008: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
                   5009:                      navigational links
1.317     albertel 5010: 
1.338     albertel 5011: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
                   5012: 
1.1075.2.12  raeburn  5013: =item * $no_inline_link, if true and in remote mode, don't show the
                   5014:          'Switch To Inline Menu' link
                   5015: 
1.460     albertel 5016: =item * $args, optional argument valid values are
                   5017:             no_auto_mt_title -> prevents &mt()ing the title arg
1.562     albertel 5018:             inherit_jsmath -> when creating popup window in a page,
                   5019:                               should it have jsmath forced on by the
                   5020:                               current page
1.460     albertel 5021: 
1.1075.2.15  raeburn  5022: =item * $advtoolsref, optional argument, ref to an array containing
                   5023:             inlineremote items to be added in "Functions" menu below
                   5024:             breadcrumbs.
                   5025: 
1.112     bowersj2 5026: =back
                   5027: 
1.60      matthew  5028: Returns: A uniform header for LON-CAPA web pages.  
                   5029: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
                   5030: If $bodyonly is undef or zero, an html string containing a <body> tag and 
                   5031: other decorations will be returned.
                   5032: 
                   5033: =cut
                   5034: 
1.54      www      5035: sub bodytag {
1.831     bisitz   5036:     my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.15  raeburn  5037:         $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref)=@_;
1.339     albertel 5038: 
1.954     raeburn  5039:     my $public;
                   5040:     if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
                   5041:         || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
                   5042:         $public = 1;
                   5043:     }
1.460     albertel 5044:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.52! raeburn  5045:     my $httphost = $args->{'use_absolute'};
1.339     albertel 5046: 
1.183     matthew  5047:     $function = &get_users_function() if (!$function);
1.339     albertel 5048:     my $img =    &designparm($function.'.img',$domain);
                   5049:     my $font =   &designparm($function.'.font',$domain);
                   5050:     my $pgbg   = $bgcolor || &designparm($function.'.pgbg',$domain);
                   5051: 
1.803     bisitz   5052:     my %design = ( 'style'   => 'margin-top: 0',
1.535     albertel 5053: 		   'bgcolor' => $pgbg,
1.339     albertel 5054: 		   'text'    => $font,
                   5055:                    'alink'   => &designparm($function.'.alink',$domain),
                   5056: 		   'vlink'   => &designparm($function.'.vlink',$domain),
                   5057: 		   'link'    => &designparm($function.'.link',$domain),);
1.438     albertel 5058:     @design{keys(%$addentries)} = @$addentries{keys(%$addentries)}; 
1.339     albertel 5059: 
1.63      www      5060:  # role and realm
1.378     raeburn  5061:     my ($role,$realm) = split(/\./,$env{'request.role'},2);
                   5062:     if ($role  eq 'ca') {
1.479     albertel 5063:         my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500     albertel 5064:         $realm = &plainname($rname,$rdom);
1.378     raeburn  5065:     } 
1.55      www      5066: # realm
1.258     albertel 5067:     if ($env{'request.course.id'}) {
1.378     raeburn  5068:         if ($env{'request.role'} !~ /^cr/) {
                   5069:             $role = &Apache::lonnet::plaintext($role,&course_type());
                   5070:         }
1.898     raeburn  5071:         if ($env{'request.course.sec'}) {
                   5072:             $role .= ('&nbsp;'x2).'-&nbsp;'.&mt('section:').'&nbsp;'.$env{'request.course.sec'};
                   5073:         }   
1.359     albertel 5074: 	$realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378     raeburn  5075:     } else {
                   5076:         $role = &Apache::lonnet::plaintext($role);
1.54      www      5077:     }
1.433     albertel 5078: 
1.359     albertel 5079:     if (!$realm) { $realm='&nbsp;'; }
1.330     albertel 5080: 
1.438     albertel 5081:     my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329     albertel 5082: 
1.101     www      5083: # construct main body tag
1.359     albertel 5084:     my $bodytag = "<body $extra_body_attr>".
1.562     albertel 5085: 	&Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252     albertel 5086: 
1.1075.2.38  raeburn  5087:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   5088: 
                   5089:     if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60      matthew  5090:         return $bodytag;
1.1075.2.38  raeburn  5091:     }
1.359     albertel 5092: 
1.954     raeburn  5093:     if ($public) {
1.433     albertel 5094: 	undef($role);
                   5095:     }
1.359     albertel 5096:     
1.762     bisitz   5097:     my $titleinfo = '<h1>'.$title.'</h1>';
1.359     albertel 5098:     #
                   5099:     # Extra info if you are the DC
                   5100:     my $dc_info = '';
                   5101:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
                   5102:                         $env{'course.'.$env{'request.course.id'}.
                   5103:                                  '.domain'}.'/'})) {
                   5104:         my $cid = $env{'request.course.id'};
1.917     raeburn  5105:         $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380     www      5106:         $dc_info =~ s/\s+$//;
1.359     albertel 5107:     }
                   5108: 
1.898     raeburn  5109:     $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.903     droeschl 5110: 
1.1075.2.13  raeburn  5111:     if ($env{'request.state'} eq 'construct') { $forcereg=1; }
                   5112: 
1.1075.2.38  raeburn  5113: 
                   5114: 
1.1075.2.21  raeburn  5115:     my $funclist;
                   5116:     if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
1.1075.2.52! raeburn  5117:         $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions($httphost), 'start')."\n".
1.1075.2.21  raeburn  5118:                     Apache::lonmenu::serverform();
                   5119:         my $forbodytag;
                   5120:         &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
                   5121:                                             $forcereg,$args->{'group'},
                   5122:                                             $args->{'bread_crumbs'},
                   5123:                                             $advtoolsref,'',\$forbodytag);
                   5124:         unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
                   5125:             $funclist = $forbodytag;
                   5126:         }
                   5127:     } else {
1.903     droeschl 5128: 
                   5129:         #    if ($env{'request.state'} eq 'construct') {
                   5130:         #        $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
                   5131:         #    }
                   5132: 
1.1075.2.38  raeburn  5133:         $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1075.2.52! raeburn  5134:             Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359     albertel 5135: 
1.1075.2.38  raeburn  5136:         my ($left,$right) = Apache::lonmenu::primary_menu();
1.1075.2.2  raeburn  5137: 
1.916     droeschl 5138:         if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.1075.2.22  raeburn  5139:             if ($dc_info) {
                   5140:                  $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
1.1075.2.1  raeburn  5141:             }
1.1075.2.38  raeburn  5142:             $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.1075.2.22  raeburn  5143:                            <em>$realm</em> $dc_info</div>|;
1.903     droeschl 5144:             return $bodytag;
                   5145:         }
1.894     droeschl 5146: 
1.927     raeburn  5147:         unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1075.2.38  raeburn  5148:             $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927     raeburn  5149:         }
1.916     droeschl 5150: 
1.1075.2.38  raeburn  5151:         $bodytag .= $right;
1.852     droeschl 5152: 
1.917     raeburn  5153:         if ($dc_info) {
                   5154:             $dc_info = &dc_courseid_toggle($dc_info);
                   5155:         }
                   5156:         $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916     droeschl 5157: 
1.903     droeschl 5158:         #don't show menus for public users
1.954     raeburn  5159:         if (!$public){
1.1075.2.52! raeburn  5160:             $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903     droeschl 5161:             $bodytag .= Apache::lonmenu::serverform();
1.920     raeburn  5162:             $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
                   5163:             if ($env{'request.state'} eq 'construct') {
1.962     droeschl 5164:                 $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920     raeburn  5165:                                 $args->{'bread_crumbs'});
                   5166:             } elsif ($forcereg) { 
1.1075.2.22  raeburn  5167:                 $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
                   5168:                                                             $args->{'group'});
1.1075.2.15  raeburn  5169:             } else {
1.1075.2.21  raeburn  5170:                 my $forbodytag;
                   5171:                 &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
                   5172:                                                     $forcereg,$args->{'group'},
                   5173:                                                     $args->{'bread_crumbs'},
                   5174:                                                     $advtoolsref,'',\$forbodytag);
                   5175:                 unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
                   5176:                     $bodytag .= $forbodytag;
                   5177:                 }
1.920     raeburn  5178:             }
1.903     droeschl 5179:         }else{
                   5180:             # this is to seperate menu from content when there's no secondary
                   5181:             # menu. Especially needed for public accessible ressources.
                   5182:             $bodytag .= '<hr style="clear:both" />';
                   5183:             $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end'); 
1.235     raeburn  5184:         }
1.903     droeschl 5185: 
1.235     raeburn  5186:         return $bodytag;
1.1075.2.12  raeburn  5187:     }
                   5188: 
                   5189: #
                   5190: # Top frame rendering, Remote is up
                   5191: #
                   5192: 
                   5193:     my $imgsrc = $img;
                   5194:     if ($img =~ /^\/adm/) {
                   5195:         $imgsrc = &lonhttpdurl($img);
                   5196:     }
                   5197:     my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
                   5198: 
                   5199:     # Explicit link to get inline menu
                   5200:     my $menu= ($no_inline_link?''
                   5201:                :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
                   5202: 
                   5203:     if ($dc_info) {
                   5204:         $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
                   5205:     }
                   5206: 
1.1075.2.38  raeburn  5207:     my $name = &plainname($env{'user.name'},$env{'user.domain'});
                   5208:     unless ($public) {
                   5209:         $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
                   5210:                                 undef,'LC_menubuttons_link');
                   5211:     }
                   5212: 
1.1075.2.12  raeburn  5213:     unless ($env{'form.inhibitmenu'}) {
                   5214:         $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.1075.2.38  raeburn  5215:                        <ol class="LC_primary_menu LC_floatright LC_right">
1.1075.2.12  raeburn  5216:                        <li>$menu</li>
                   5217:                        </ol><div id="LC_realm"> $realm $dc_info</div>|;
                   5218:     }
1.1075.2.13  raeburn  5219:     if ($env{'request.state'} eq 'construct') {
                   5220:         if (!$public){
                   5221:             if ($env{'request.state'} eq 'construct') {
                   5222:                 $funclist = &Apache::lonhtmlcommon::scripttag(
1.1075.2.52! raeburn  5223:                                 &Apache::lonmenu::utilityfunctions($httphost), 'start').
1.1075.2.13  raeburn  5224:                             &Apache::lonhtmlcommon::scripttag('','end').
                   5225:                             &Apache::lonmenu::innerregister($forcereg,
                   5226:                                                             $args->{'bread_crumbs'});
                   5227:             }
                   5228:         }
                   5229:     }
1.1075.2.21  raeburn  5230:     return $bodytag."\n".$funclist;
1.182     matthew  5231: }
                   5232: 
1.917     raeburn  5233: sub dc_courseid_toggle {
                   5234:     my ($dc_info) = @_;
1.980     raeburn  5235:     return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069    raeburn  5236:            '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917     raeburn  5237:            &mt('(More ...)').'</a></span>'.
                   5238:            '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
                   5239: }
                   5240: 
1.330     albertel 5241: sub make_attr_string {
                   5242:     my ($register,$attr_ref) = @_;
                   5243: 
                   5244:     if ($attr_ref && !ref($attr_ref)) {
                   5245: 	die("addentries Must be a hash ref ".
                   5246: 	    join(':',caller(1))." ".
                   5247: 	    join(':',caller(0))." ");
                   5248:     }
                   5249: 
                   5250:     if ($register) {
1.339     albertel 5251: 	my ($on_load,$on_unload);
                   5252: 	foreach my $key (keys(%{$attr_ref})) {
                   5253: 	    if      (lc($key) eq 'onload') {
                   5254: 		$on_load.=$attr_ref->{$key}.';';
                   5255: 		delete($attr_ref->{$key});
                   5256: 
                   5257: 	    } elsif (lc($key) eq 'onunload') {
                   5258: 		$on_unload.=$attr_ref->{$key}.';';
                   5259: 		delete($attr_ref->{$key});
                   5260: 	    }
                   5261: 	}
1.1075.2.12  raeburn  5262:         if ($env{'environment.remote'} eq 'on') {
                   5263:             $attr_ref->{'onload'}  =
                   5264:                 &Apache::lonmenu::loadevents().  $on_load;
                   5265:             $attr_ref->{'onunload'}=
                   5266:                 &Apache::lonmenu::unloadevents().$on_unload;
                   5267:         } else {  
                   5268: 	    $attr_ref->{'onload'}  = $on_load;
                   5269: 	    $attr_ref->{'onunload'}= $on_unload;
                   5270:         }
1.330     albertel 5271:     }
1.339     albertel 5272: 
1.330     albertel 5273:     my $attr_string;
                   5274:     foreach my $attr (keys(%$attr_ref)) {
                   5275: 	$attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
                   5276:     }
                   5277:     return $attr_string;
                   5278: }
                   5279: 
                   5280: 
1.182     matthew  5281: ###############################################
1.251     albertel 5282: ###############################################
                   5283: 
                   5284: =pod
                   5285: 
                   5286: =item * &endbodytag()
                   5287: 
                   5288: Returns a uniform footer for LON-CAPA web pages.
                   5289: 
1.635     raeburn  5290: Inputs: 1 - optional reference to an args hash
                   5291: If in the hash, key for noredirectlink has a value which evaluates to true,
                   5292: a 'Continue' link is not displayed if the page contains an
                   5293: internal redirect in the <head></head> section,
                   5294: i.e., $env{'internal.head.redirect'} exists   
1.251     albertel 5295: 
                   5296: =cut
                   5297: 
                   5298: sub endbodytag {
1.635     raeburn  5299:     my ($args) = @_;
1.1075.2.6  raeburn  5300:     my $endbodytag;
                   5301:     unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
                   5302:         $endbodytag='</body>';
                   5303:     }
1.269     albertel 5304:     $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315     albertel 5305:     if ( exists( $env{'internal.head.redirect'} ) ) {
1.635     raeburn  5306:         if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
                   5307: 	    $endbodytag=
                   5308: 	        "<br /><a href=\"$env{'internal.head.redirect'}\">".
                   5309: 	        &mt('Continue').'</a>'.
                   5310: 	        $endbodytag;
                   5311:         }
1.315     albertel 5312:     }
1.251     albertel 5313:     return $endbodytag;
                   5314: }
                   5315: 
1.352     albertel 5316: =pod
                   5317: 
                   5318: =item * &standard_css()
                   5319: 
                   5320: Returns a style sheet
                   5321: 
                   5322: Inputs: (all optional)
                   5323:             domain         -> force to color decorate a page for a specific
                   5324:                                domain
                   5325:             function       -> force usage of a specific rolish color scheme
                   5326:             bgcolor        -> override the default page bgcolor
                   5327: 
                   5328: =cut
                   5329: 
1.343     albertel 5330: sub standard_css {
1.345     albertel 5331:     my ($function,$domain,$bgcolor) = @_;
1.352     albertel 5332:     $function  = &get_users_function() if (!$function);
                   5333:     my $img    = &designparm($function.'.img',   $domain);
                   5334:     my $tabbg  = &designparm($function.'.tabbg', $domain);
                   5335:     my $font   = &designparm($function.'.font',  $domain);
1.801     tempelho 5336:     my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791     tempelho 5337: #second colour for later usage
1.345     albertel 5338:     my $sidebg = &designparm($function.'.sidebg',$domain);
1.382     albertel 5339:     my $pgbg_or_bgcolor =
                   5340: 	         $bgcolor ||
1.352     albertel 5341: 	         &designparm($function.'.pgbg',  $domain);
1.382     albertel 5342:     my $pgbg   = &designparm($function.'.pgbg',  $domain);
1.352     albertel 5343:     my $alink  = &designparm($function.'.alink', $domain);
                   5344:     my $vlink  = &designparm($function.'.vlink', $domain);
                   5345:     my $link   = &designparm($function.'.link',  $domain);
                   5346: 
1.602     albertel 5347:     my $sans                 = 'Verdana,Arial,Helvetica,sans-serif';
1.395     albertel 5348:     my $mono                 = 'monospace';
1.850     bisitz   5349:     my $data_table_head      = $sidebg;
                   5350:     my $data_table_light     = '#FAFAFA';
1.1060    bisitz   5351:     my $data_table_dark      = '#E0E0E0';
1.470     banghart 5352:     my $data_table_darker    = '#CCCCCC';
1.349     albertel 5353:     my $data_table_highlight = '#FFFF00';
1.352     albertel 5354:     my $mail_new             = '#FFBB77';
                   5355:     my $mail_new_hover       = '#DD9955';
                   5356:     my $mail_read            = '#BBBB77';
                   5357:     my $mail_read_hover      = '#999944';
                   5358:     my $mail_replied         = '#AAAA88';
                   5359:     my $mail_replied_hover   = '#888855';
                   5360:     my $mail_other           = '#99BBBB';
                   5361:     my $mail_other_hover     = '#669999';
1.391     albertel 5362:     my $table_header         = '#DDDDDD';
1.489     raeburn  5363:     my $feedback_link_bg     = '#BBBBBB';
1.911     bisitz   5364:     my $lg_border_color      = '#C8C8C8';
1.952     onken    5365:     my $button_hover         = '#BF2317';
1.392     albertel 5366: 
1.608     albertel 5367:     my $border = ($env{'browser.type'} eq 'explorer' ||
1.911     bisitz   5368:       $env{'browser.type'} eq 'safari'     ) ? '0 2px 0 2px'
                   5369:                                              : '0 3px 0 4px';
1.448     albertel 5370: 
1.523     albertel 5371: 
1.343     albertel 5372:     return <<END;
1.947     droeschl 5373: 
                   5374: /* needed for iframe to allow 100% height in FF */
                   5375: body, html { 
                   5376:     margin: 0;
                   5377:     padding: 0 0.5%;
                   5378:     height: 99%; /* to avoid scrollbars */
                   5379: }
                   5380: 
1.795     www      5381: body {
1.911     bisitz   5382:   font-family: $sans;
                   5383:   line-height:130%;
                   5384:   font-size:0.83em;
                   5385:   color:$font;
1.795     www      5386: }
                   5387: 
1.959     onken    5388: a:focus,
                   5389: a:focus img {
1.795     www      5390:   color: red;
                   5391: }
1.698     harmsja  5392: 
1.911     bisitz   5393: form, .inline {
                   5394:   display: inline;
1.795     www      5395: }
1.721     harmsja  5396: 
1.795     www      5397: .LC_right {
1.911     bisitz   5398:   text-align:right;
1.795     www      5399: }
                   5400: 
                   5401: .LC_middle {
1.911     bisitz   5402:   vertical-align:middle;
1.795     www      5403: }
1.721     harmsja  5404: 
1.1075.2.38  raeburn  5405: .LC_floatleft {
                   5406:   float: left;
                   5407: }
                   5408: 
                   5409: .LC_floatright {
                   5410:   float: right;
                   5411: }
                   5412: 
1.911     bisitz   5413: .LC_400Box {
                   5414:   width:400px;
                   5415: }
1.721     harmsja  5416: 
1.947     droeschl 5417: .LC_iframecontainer {
                   5418:     width: 98%;
                   5419:     margin: 0;
                   5420:     position: fixed;
                   5421:     top: 8.5em;
                   5422:     bottom: 0;
                   5423: }
                   5424: 
                   5425: .LC_iframecontainer iframe{
                   5426:     border: none;
                   5427:     width: 100%;
                   5428:     height: 100%;
                   5429: }
                   5430: 
1.778     bisitz   5431: .LC_filename {
                   5432:   font-family: $mono;
                   5433:   white-space:pre;
1.921     bisitz   5434:   font-size: 120%;
1.778     bisitz   5435: }
                   5436: 
                   5437: .LC_fileicon {
                   5438:   border: none;
                   5439:   height: 1.3em;
                   5440:   vertical-align: text-bottom;
                   5441:   margin-right: 0.3em;
                   5442:   text-decoration:none;
                   5443: }
                   5444: 
1.1008    www      5445: .LC_setting {
                   5446:   text-decoration:underline;
                   5447: }
                   5448: 
1.350     albertel 5449: .LC_error {
                   5450:   color: red;
                   5451: }
1.795     www      5452: 
1.1075.2.15  raeburn  5453: .LC_warning {
                   5454:   color: darkorange;
                   5455: }
                   5456: 
1.457     albertel 5457: .LC_diff_removed {
1.733     bisitz   5458:   color: red;
1.394     albertel 5459: }
1.532     albertel 5460: 
                   5461: .LC_info,
1.457     albertel 5462: .LC_success,
                   5463: .LC_diff_added {
1.350     albertel 5464:   color: green;
                   5465: }
1.795     www      5466: 
1.802     bisitz   5467: div.LC_confirm_box {
                   5468:   background-color: #FAFAFA;
                   5469:   border: 1px solid $lg_border_color;
                   5470:   margin-right: 0;
                   5471:   padding: 5px;
                   5472: }
                   5473: 
                   5474: div.LC_confirm_box .LC_error img,
                   5475: div.LC_confirm_box .LC_success img {
                   5476:   vertical-align: middle;
                   5477: }
                   5478: 
1.440     albertel 5479: .LC_icon {
1.771     droeschl 5480:   border: none;
1.790     droeschl 5481:   vertical-align: middle;
1.771     droeschl 5482: }
                   5483: 
1.543     albertel 5484: .LC_docs_spacer {
                   5485:   width: 25px;
                   5486:   height: 1px;
1.771     droeschl 5487:   border: none;
1.543     albertel 5488: }
1.346     albertel 5489: 
1.532     albertel 5490: .LC_internal_info {
1.735     bisitz   5491:   color: #999999;
1.532     albertel 5492: }
                   5493: 
1.794     www      5494: .LC_discussion {
1.1050    www      5495:   background: $data_table_dark;
1.911     bisitz   5496:   border: 1px solid black;
                   5497:   margin: 2px;
1.794     www      5498: }
                   5499: 
                   5500: .LC_disc_action_left {
1.1050    www      5501:   background: $sidebg;
1.911     bisitz   5502:   text-align: left;
1.1050    www      5503:   padding: 4px;
                   5504:   margin: 2px;
1.794     www      5505: }
                   5506: 
                   5507: .LC_disc_action_right {
1.1050    www      5508:   background: $sidebg;
1.911     bisitz   5509:   text-align: right;
1.1050    www      5510:   padding: 4px;
                   5511:   margin: 2px;
1.794     www      5512: }
                   5513: 
                   5514: .LC_disc_new_item {
1.911     bisitz   5515:   background: white;
                   5516:   border: 2px solid red;
1.1050    www      5517:   margin: 4px;
                   5518:   padding: 4px;
1.794     www      5519: }
                   5520: 
                   5521: .LC_disc_old_item {
1.911     bisitz   5522:   background: white;
1.1050    www      5523:   margin: 4px;
                   5524:   padding: 4px;
1.794     www      5525: }
                   5526: 
1.458     albertel 5527: table.LC_pastsubmission {
                   5528:   border: 1px solid black;
                   5529:   margin: 2px;
                   5530: }
                   5531: 
1.924     bisitz   5532: table#LC_menubuttons {
1.345     albertel 5533:   width: 100%;
                   5534:   background: $pgbg;
1.392     albertel 5535:   border: 2px;
1.402     albertel 5536:   border-collapse: separate;
1.803     bisitz   5537:   padding: 0;
1.345     albertel 5538: }
1.392     albertel 5539: 
1.801     tempelho 5540: table#LC_title_bar a {
                   5541:   color: $fontmenu;
                   5542: }
1.836     bisitz   5543: 
1.807     droeschl 5544: table#LC_title_bar {
1.819     tempelho 5545:   clear: both;
1.836     bisitz   5546:   display: none;
1.807     droeschl 5547: }
                   5548: 
1.795     www      5549: table#LC_title_bar,
1.933     droeschl 5550: table.LC_breadcrumbs, /* obsolete? */
1.393     albertel 5551: table#LC_title_bar.LC_with_remote {
1.359     albertel 5552:   width: 100%;
1.392     albertel 5553:   border-color: $pgbg;
                   5554:   border-style: solid;
                   5555:   border-width: $border;
1.379     albertel 5556:   background: $pgbg;
1.801     tempelho 5557:   color: $fontmenu;
1.392     albertel 5558:   border-collapse: collapse;
1.803     bisitz   5559:   padding: 0;
1.819     tempelho 5560:   margin: 0;
1.359     albertel 5561: }
1.795     www      5562: 
1.933     droeschl 5563: ul.LC_breadcrumb_tools_outerlist {
1.913     droeschl 5564:     margin: 0;
                   5565:     padding: 0;
1.933     droeschl 5566:     position: relative;
                   5567:     list-style: none;
1.913     droeschl 5568: }
1.933     droeschl 5569: ul.LC_breadcrumb_tools_outerlist li {
1.913     droeschl 5570:     display: inline;
                   5571: }
1.933     droeschl 5572: 
                   5573: .LC_breadcrumb_tools_navigation {
1.913     droeschl 5574:     padding: 0;
1.933     droeschl 5575:     margin: 0;
                   5576:     float: left;
1.913     droeschl 5577: }
1.933     droeschl 5578: .LC_breadcrumb_tools_tools {
                   5579:     padding: 0;
                   5580:     margin: 0;
1.913     droeschl 5581:     float: right;
                   5582: }
                   5583: 
1.359     albertel 5584: table#LC_title_bar td {
                   5585:   background: $tabbg;
                   5586: }
1.795     www      5587: 
1.911     bisitz   5588: table#LC_menubuttons img {
1.803     bisitz   5589:   border: none;
1.346     albertel 5590: }
1.795     www      5591: 
1.842     droeschl 5592: .LC_breadcrumbs_component {
1.911     bisitz   5593:   float: right;
                   5594:   margin: 0 1em;
1.357     albertel 5595: }
1.842     droeschl 5596: .LC_breadcrumbs_component img {
1.911     bisitz   5597:   vertical-align: middle;
1.777     tempelho 5598: }
1.795     www      5599: 
1.383     albertel 5600: td.LC_table_cell_checkbox {
                   5601:   text-align: center;
                   5602: }
1.795     www      5603: 
                   5604: .LC_fontsize_small {
1.911     bisitz   5605:   font-size: 70%;
1.705     tempelho 5606: }
                   5607: 
1.844     bisitz   5608: #LC_breadcrumbs {
1.911     bisitz   5609:   clear:both;
                   5610:   background: $sidebg;
                   5611:   border-bottom: 1px solid $lg_border_color;
                   5612:   line-height: 2.5em;
1.933     droeschl 5613:   overflow: hidden;
1.911     bisitz   5614:   margin: 0;
                   5615:   padding: 0;
1.995     raeburn  5616:   text-align: left;
1.819     tempelho 5617: }
1.862     bisitz   5618: 
1.1075.2.16  raeburn  5619: .LC_head_subbox, .LC_actionbox {
1.911     bisitz   5620:   clear:both;
                   5621:   background: #F8F8F8; /* $sidebg; */
1.915     droeschl 5622:   border: 1px solid $sidebg;
1.1075.2.16  raeburn  5623:   margin: 0 0 10px 0;
1.966     bisitz   5624:   padding: 3px;
1.995     raeburn  5625:   text-align: left;
1.822     bisitz   5626: }
                   5627: 
1.795     www      5628: .LC_fontsize_medium {
1.911     bisitz   5629:   font-size: 85%;
1.705     tempelho 5630: }
                   5631: 
1.795     www      5632: .LC_fontsize_large {
1.911     bisitz   5633:   font-size: 120%;
1.705     tempelho 5634: }
                   5635: 
1.346     albertel 5636: .LC_menubuttons_inline_text {
                   5637:   color: $font;
1.698     harmsja  5638:   font-size: 90%;
1.701     harmsja  5639:   padding-left:3px;
1.346     albertel 5640: }
                   5641: 
1.934     droeschl 5642: .LC_menubuttons_inline_text img{
                   5643:   vertical-align: middle;
                   5644: }
                   5645: 
1.1051    www      5646: li.LC_menubuttons_inline_text img {
1.951     onken    5647:   cursor:pointer;
1.1002    droeschl 5648:   text-decoration: none;
1.951     onken    5649: }
                   5650: 
1.526     www      5651: .LC_menubuttons_link {
                   5652:   text-decoration: none;
                   5653: }
1.795     www      5654: 
1.522     albertel 5655: .LC_menubuttons_category {
1.521     www      5656:   color: $font;
1.526     www      5657:   background: $pgbg;
1.521     www      5658:   font-size: larger;
                   5659:   font-weight: bold;
                   5660: }
                   5661: 
1.346     albertel 5662: td.LC_menubuttons_text {
1.911     bisitz   5663:   color: $font;
1.346     albertel 5664: }
1.706     harmsja  5665: 
1.346     albertel 5666: .LC_current_location {
                   5667:   background: $tabbg;
                   5668: }
1.795     www      5669: 
1.938     bisitz   5670: table.LC_data_table {
1.347     albertel 5671:   border: 1px solid #000000;
1.402     albertel 5672:   border-collapse: separate;
1.426     albertel 5673:   border-spacing: 1px;
1.610     albertel 5674:   background: $pgbg;
1.347     albertel 5675: }
1.795     www      5676: 
1.422     albertel 5677: .LC_data_table_dense {
                   5678:   font-size: small;
                   5679: }
1.795     www      5680: 
1.507     raeburn  5681: table.LC_nested_outer {
                   5682:   border: 1px solid #000000;
1.589     raeburn  5683:   border-collapse: collapse;
1.803     bisitz   5684:   border-spacing: 0;
1.507     raeburn  5685:   width: 100%;
                   5686: }
1.795     www      5687: 
1.879     raeburn  5688: table.LC_innerpickbox,
1.507     raeburn  5689: table.LC_nested {
1.803     bisitz   5690:   border: none;
1.589     raeburn  5691:   border-collapse: collapse;
1.803     bisitz   5692:   border-spacing: 0;
1.507     raeburn  5693:   width: 100%;
                   5694: }
1.795     www      5695: 
1.911     bisitz   5696: table.LC_data_table tr th,
                   5697: table.LC_calendar tr th,
1.879     raeburn  5698: table.LC_prior_tries tr th,
                   5699: table.LC_innerpickbox tr th {
1.349     albertel 5700:   font-weight: bold;
                   5701:   background-color: $data_table_head;
1.801     tempelho 5702:   color:$fontmenu;
1.701     harmsja  5703:   font-size:90%;
1.347     albertel 5704: }
1.795     www      5705: 
1.879     raeburn  5706: table.LC_innerpickbox tr th,
                   5707: table.LC_innerpickbox tr td {
                   5708:   vertical-align: top;
                   5709: }
                   5710: 
1.711     raeburn  5711: table.LC_data_table tr.LC_info_row > td {
1.735     bisitz   5712:   background-color: #CCCCCC;
1.711     raeburn  5713:   font-weight: bold;
                   5714:   text-align: left;
                   5715: }
1.795     www      5716: 
1.912     bisitz   5717: table.LC_data_table tr.LC_odd_row > td {
                   5718:   background-color: $data_table_light;
                   5719:   padding: 2px;
                   5720:   vertical-align: top;
                   5721: }
                   5722: 
1.809     bisitz   5723: table.LC_pick_box tr > td.LC_odd_row {
1.349     albertel 5724:   background-color: $data_table_light;
1.912     bisitz   5725:   vertical-align: top;
                   5726: }
                   5727: 
                   5728: table.LC_data_table tr.LC_even_row > td {
                   5729:   background-color: $data_table_dark;
1.425     albertel 5730:   padding: 2px;
1.900     bisitz   5731:   vertical-align: top;
1.347     albertel 5732: }
1.795     www      5733: 
1.809     bisitz   5734: table.LC_pick_box tr > td.LC_even_row {
1.349     albertel 5735:   background-color: $data_table_dark;
1.900     bisitz   5736:   vertical-align: top;
1.347     albertel 5737: }
1.795     www      5738: 
1.425     albertel 5739: table.LC_data_table tr.LC_data_table_highlight td {
                   5740:   background-color: $data_table_darker;
                   5741: }
1.795     www      5742: 
1.639     raeburn  5743: table.LC_data_table tr td.LC_leftcol_header {
                   5744:   background-color: $data_table_head;
                   5745:   font-weight: bold;
                   5746: }
1.795     www      5747: 
1.451     albertel 5748: table.LC_data_table tr.LC_empty_row td,
1.507     raeburn  5749: table.LC_nested tr.LC_empty_row td {
1.421     albertel 5750:   font-weight: bold;
                   5751:   font-style: italic;
                   5752:   text-align: center;
                   5753:   padding: 8px;
1.347     albertel 5754: }
1.795     www      5755: 
1.1075.2.30  raeburn  5756: table.LC_data_table tr.LC_empty_row td,
                   5757: table.LC_data_table tr.LC_footer_row td {
1.940     bisitz   5758:   background-color: $sidebg;
                   5759: }
                   5760: 
                   5761: table.LC_nested tr.LC_empty_row td {
                   5762:   background-color: #FFFFFF;
                   5763: }
                   5764: 
1.890     droeschl 5765: table.LC_caption {
                   5766: }
                   5767: 
1.507     raeburn  5768: table.LC_nested tr.LC_empty_row td {
1.465     albertel 5769:   padding: 4ex
                   5770: }
1.795     www      5771: 
1.507     raeburn  5772: table.LC_nested_outer tr th {
                   5773:   font-weight: bold;
1.801     tempelho 5774:   color:$fontmenu;
1.507     raeburn  5775:   background-color: $data_table_head;
1.701     harmsja  5776:   font-size: small;
1.507     raeburn  5777:   border-bottom: 1px solid #000000;
                   5778: }
1.795     www      5779: 
1.507     raeburn  5780: table.LC_nested_outer tr td.LC_subheader {
                   5781:   background-color: $data_table_head;
                   5782:   font-weight: bold;
                   5783:   font-size: small;
                   5784:   border-bottom: 1px solid #000000;
                   5785:   text-align: right;
1.451     albertel 5786: }
1.795     www      5787: 
1.507     raeburn  5788: table.LC_nested tr.LC_info_row td {
1.735     bisitz   5789:   background-color: #CCCCCC;
1.451     albertel 5790:   font-weight: bold;
                   5791:   font-size: small;
1.507     raeburn  5792:   text-align: center;
                   5793: }
1.795     www      5794: 
1.589     raeburn  5795: table.LC_nested tr.LC_info_row td.LC_left_item,
                   5796: table.LC_nested_outer tr th.LC_left_item {
1.507     raeburn  5797:   text-align: left;
1.451     albertel 5798: }
1.795     www      5799: 
1.507     raeburn  5800: table.LC_nested td {
1.735     bisitz   5801:   background-color: #FFFFFF;
1.451     albertel 5802:   font-size: small;
1.507     raeburn  5803: }
1.795     www      5804: 
1.507     raeburn  5805: table.LC_nested_outer tr th.LC_right_item,
                   5806: table.LC_nested tr.LC_info_row td.LC_right_item,
                   5807: table.LC_nested tr.LC_odd_row td.LC_right_item,
                   5808: table.LC_nested tr td.LC_right_item {
1.451     albertel 5809:   text-align: right;
                   5810: }
                   5811: 
1.507     raeburn  5812: table.LC_nested tr.LC_odd_row td {
1.735     bisitz   5813:   background-color: #EEEEEE;
1.451     albertel 5814: }
                   5815: 
1.473     raeburn  5816: table.LC_createuser {
                   5817: }
                   5818: 
                   5819: table.LC_createuser tr.LC_section_row td {
1.701     harmsja  5820:   font-size: small;
1.473     raeburn  5821: }
                   5822: 
                   5823: table.LC_createuser tr.LC_info_row td  {
1.735     bisitz   5824:   background-color: #CCCCCC;
1.473     raeburn  5825:   font-weight: bold;
                   5826:   text-align: center;
                   5827: }
                   5828: 
1.349     albertel 5829: table.LC_calendar {
                   5830:   border: 1px solid #000000;
                   5831:   border-collapse: collapse;
1.917     raeburn  5832:   width: 98%;
1.349     albertel 5833: }
1.795     www      5834: 
1.349     albertel 5835: table.LC_calendar_pickdate {
                   5836:   font-size: xx-small;
                   5837: }
1.795     www      5838: 
1.349     albertel 5839: table.LC_calendar tr td {
                   5840:   border: 1px solid #000000;
                   5841:   vertical-align: top;
1.917     raeburn  5842:   width: 14%;
1.349     albertel 5843: }
1.795     www      5844: 
1.349     albertel 5845: table.LC_calendar tr td.LC_calendar_day_empty {
                   5846:   background-color: $data_table_dark;
                   5847: }
1.795     www      5848: 
1.779     bisitz   5849: table.LC_calendar tr td.LC_calendar_day_current {
                   5850:   background-color: $data_table_highlight;
1.777     tempelho 5851: }
1.795     www      5852: 
1.938     bisitz   5853: table.LC_data_table tr td.LC_mail_new {
1.349     albertel 5854:   background-color: $mail_new;
                   5855: }
1.795     www      5856: 
1.938     bisitz   5857: table.LC_data_table tr.LC_mail_new:hover {
1.349     albertel 5858:   background-color: $mail_new_hover;
                   5859: }
1.795     www      5860: 
1.938     bisitz   5861: table.LC_data_table tr td.LC_mail_read {
1.349     albertel 5862:   background-color: $mail_read;
                   5863: }
1.795     www      5864: 
1.938     bisitz   5865: /*
                   5866: table.LC_data_table tr.LC_mail_read:hover {
1.349     albertel 5867:   background-color: $mail_read_hover;
                   5868: }
1.938     bisitz   5869: */
1.795     www      5870: 
1.938     bisitz   5871: table.LC_data_table tr td.LC_mail_replied {
1.349     albertel 5872:   background-color: $mail_replied;
                   5873: }
1.795     www      5874: 
1.938     bisitz   5875: /*
                   5876: table.LC_data_table tr.LC_mail_replied:hover {
1.349     albertel 5877:   background-color: $mail_replied_hover;
                   5878: }
1.938     bisitz   5879: */
1.795     www      5880: 
1.938     bisitz   5881: table.LC_data_table tr td.LC_mail_other {
1.349     albertel 5882:   background-color: $mail_other;
                   5883: }
1.795     www      5884: 
1.938     bisitz   5885: /*
                   5886: table.LC_data_table tr.LC_mail_other:hover {
1.349     albertel 5887:   background-color: $mail_other_hover;
                   5888: }
1.938     bisitz   5889: */
1.494     raeburn  5890: 
1.777     tempelho 5891: table.LC_data_table tr > td.LC_browser_file,
                   5892: table.LC_data_table tr > td.LC_browser_file_published {
1.899     bisitz   5893:   background: #AAEE77;
1.389     albertel 5894: }
1.795     www      5895: 
1.777     tempelho 5896: table.LC_data_table tr > td.LC_browser_file_locked,
                   5897: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389     albertel 5898:   background: #FFAA99;
1.387     albertel 5899: }
1.795     www      5900: 
1.777     tempelho 5901: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899     bisitz   5902:   background: #888888;
1.779     bisitz   5903: }
1.795     www      5904: 
1.777     tempelho 5905: table.LC_data_table tr > td.LC_browser_file_modified,
1.779     bisitz   5906: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899     bisitz   5907:   background: #F8F866;
1.777     tempelho 5908: }
1.795     www      5909: 
1.696     bisitz   5910: table.LC_data_table tr.LC_browser_folder > td {
1.899     bisitz   5911:   background: #E0E8FF;
1.387     albertel 5912: }
1.696     bisitz   5913: 
1.707     bisitz   5914: table.LC_data_table tr > td.LC_roles_is {
1.911     bisitz   5915:   /* background: #77FF77; */
1.707     bisitz   5916: }
1.795     www      5917: 
1.707     bisitz   5918: table.LC_data_table tr > td.LC_roles_future {
1.939     bisitz   5919:   border-right: 8px solid #FFFF77;
1.707     bisitz   5920: }
1.795     www      5921: 
1.707     bisitz   5922: table.LC_data_table tr > td.LC_roles_will {
1.939     bisitz   5923:   border-right: 8px solid #FFAA77;
1.707     bisitz   5924: }
1.795     www      5925: 
1.707     bisitz   5926: table.LC_data_table tr > td.LC_roles_expired {
1.939     bisitz   5927:   border-right: 8px solid #FF7777;
1.707     bisitz   5928: }
1.795     www      5929: 
1.707     bisitz   5930: table.LC_data_table tr > td.LC_roles_will_not {
1.939     bisitz   5931:   border-right: 8px solid #AAFF77;
1.707     bisitz   5932: }
1.795     www      5933: 
1.707     bisitz   5934: table.LC_data_table tr > td.LC_roles_selected {
1.939     bisitz   5935:   border-right: 8px solid #11CC55;
1.707     bisitz   5936: }
                   5937: 
1.388     albertel 5938: span.LC_current_location {
1.701     harmsja  5939:   font-size:larger;
1.388     albertel 5940:   background: $pgbg;
                   5941: }
1.387     albertel 5942: 
1.1029    www      5943: span.LC_current_nav_location {
                   5944:   font-weight:bold;
                   5945:   background: $sidebg;
                   5946: }
                   5947: 
1.395     albertel 5948: span.LC_parm_menu_item {
                   5949:   font-size: larger;
                   5950: }
1.795     www      5951: 
1.395     albertel 5952: span.LC_parm_scope_all {
                   5953:   color: red;
                   5954: }
1.795     www      5955: 
1.395     albertel 5956: span.LC_parm_scope_folder {
                   5957:   color: green;
                   5958: }
1.795     www      5959: 
1.395     albertel 5960: span.LC_parm_scope_resource {
                   5961:   color: orange;
                   5962: }
1.795     www      5963: 
1.395     albertel 5964: span.LC_parm_part {
                   5965:   color: blue;
                   5966: }
1.795     www      5967: 
1.911     bisitz   5968: span.LC_parm_folder,
                   5969: span.LC_parm_symb {
1.395     albertel 5970:   font-size: x-small;
                   5971:   font-family: $mono;
                   5972:   color: #AAAAAA;
                   5973: }
                   5974: 
1.977     bisitz   5975: ul.LC_parm_parmlist li {
                   5976:   display: inline-block;
                   5977:   padding: 0.3em 0.8em;
                   5978:   vertical-align: top;
                   5979:   width: 150px;
                   5980:   border-top:1px solid $lg_border_color;
                   5981: }
                   5982: 
1.795     www      5983: td.LC_parm_overview_level_menu,
                   5984: td.LC_parm_overview_map_menu,
                   5985: td.LC_parm_overview_parm_selectors,
                   5986: td.LC_parm_overview_restrictions  {
1.396     albertel 5987:   border: 1px solid black;
                   5988:   border-collapse: collapse;
                   5989: }
1.795     www      5990: 
1.396     albertel 5991: table.LC_parm_overview_restrictions td {
                   5992:   border-width: 1px 4px 1px 4px;
                   5993:   border-style: solid;
                   5994:   border-color: $pgbg;
                   5995:   text-align: center;
                   5996: }
1.795     www      5997: 
1.396     albertel 5998: table.LC_parm_overview_restrictions th {
                   5999:   background: $tabbg;
                   6000:   border-width: 1px 4px 1px 4px;
                   6001:   border-style: solid;
                   6002:   border-color: $pgbg;
                   6003: }
1.795     www      6004: 
1.398     albertel 6005: table#LC_helpmenu {
1.803     bisitz   6006:   border: none;
1.398     albertel 6007:   height: 55px;
1.803     bisitz   6008:   border-spacing: 0;
1.398     albertel 6009: }
                   6010: 
                   6011: table#LC_helpmenu fieldset legend {
                   6012:   font-size: larger;
                   6013: }
1.795     www      6014: 
1.397     albertel 6015: table#LC_helpmenu_links {
                   6016:   width: 100%;
                   6017:   border: 1px solid black;
                   6018:   background: $pgbg;
1.803     bisitz   6019:   padding: 0;
1.397     albertel 6020:   border-spacing: 1px;
                   6021: }
1.795     www      6022: 
1.397     albertel 6023: table#LC_helpmenu_links tr td {
                   6024:   padding: 1px;
                   6025:   background: $tabbg;
1.399     albertel 6026:   text-align: center;
                   6027:   font-weight: bold;
1.397     albertel 6028: }
1.396     albertel 6029: 
1.795     www      6030: table#LC_helpmenu_links a:link,
                   6031: table#LC_helpmenu_links a:visited,
1.397     albertel 6032: table#LC_helpmenu_links a:active {
                   6033:   text-decoration: none;
                   6034:   color: $font;
                   6035: }
1.795     www      6036: 
1.397     albertel 6037: table#LC_helpmenu_links a:hover {
                   6038:   text-decoration: underline;
                   6039:   color: $vlink;
                   6040: }
1.396     albertel 6041: 
1.417     albertel 6042: .LC_chrt_popup_exists {
                   6043:   border: 1px solid #339933;
                   6044:   margin: -1px;
                   6045: }
1.795     www      6046: 
1.417     albertel 6047: .LC_chrt_popup_up {
                   6048:   border: 1px solid yellow;
                   6049:   margin: -1px;
                   6050: }
1.795     www      6051: 
1.417     albertel 6052: .LC_chrt_popup {
                   6053:   border: 1px solid #8888FF;
                   6054:   background: #CCCCFF;
                   6055: }
1.795     www      6056: 
1.421     albertel 6057: table.LC_pick_box {
                   6058:   border-collapse: separate;
                   6059:   background: white;
                   6060:   border: 1px solid black;
                   6061:   border-spacing: 1px;
                   6062: }
1.795     www      6063: 
1.421     albertel 6064: table.LC_pick_box td.LC_pick_box_title {
1.850     bisitz   6065:   background: $sidebg;
1.421     albertel 6066:   font-weight: bold;
1.900     bisitz   6067:   text-align: left;
1.740     bisitz   6068:   vertical-align: top;
1.421     albertel 6069:   width: 184px;
                   6070:   padding: 8px;
                   6071: }
1.795     www      6072: 
1.579     raeburn  6073: table.LC_pick_box td.LC_pick_box_value {
                   6074:   text-align: left;
                   6075:   padding: 8px;
                   6076: }
1.795     www      6077: 
1.579     raeburn  6078: table.LC_pick_box td.LC_pick_box_select {
                   6079:   text-align: left;
                   6080:   padding: 8px;
                   6081: }
1.795     www      6082: 
1.424     albertel 6083: table.LC_pick_box td.LC_pick_box_separator {
1.803     bisitz   6084:   padding: 0;
1.421     albertel 6085:   height: 1px;
                   6086:   background: black;
                   6087: }
1.795     www      6088: 
1.421     albertel 6089: table.LC_pick_box td.LC_pick_box_submit {
                   6090:   text-align: right;
                   6091: }
1.795     www      6092: 
1.579     raeburn  6093: table.LC_pick_box td.LC_evenrow_value {
                   6094:   text-align: left;
                   6095:   padding: 8px;
                   6096:   background-color: $data_table_light;
                   6097: }
1.795     www      6098: 
1.579     raeburn  6099: table.LC_pick_box td.LC_oddrow_value {
                   6100:   text-align: left;
                   6101:   padding: 8px;
                   6102:   background-color: $data_table_light;
                   6103: }
1.795     www      6104: 
1.579     raeburn  6105: span.LC_helpform_receipt_cat {
                   6106:   font-weight: bold;
                   6107: }
1.795     www      6108: 
1.424     albertel 6109: table.LC_group_priv_box {
                   6110:   background: white;
                   6111:   border: 1px solid black;
                   6112:   border-spacing: 1px;
                   6113: }
1.795     www      6114: 
1.424     albertel 6115: table.LC_group_priv_box td.LC_pick_box_title {
                   6116:   background: $tabbg;
                   6117:   font-weight: bold;
                   6118:   text-align: right;
                   6119:   width: 184px;
                   6120: }
1.795     www      6121: 
1.424     albertel 6122: table.LC_group_priv_box td.LC_groups_fixed {
                   6123:   background: $data_table_light;
                   6124:   text-align: center;
                   6125: }
1.795     www      6126: 
1.424     albertel 6127: table.LC_group_priv_box td.LC_groups_optional {
                   6128:   background: $data_table_dark;
                   6129:   text-align: center;
                   6130: }
1.795     www      6131: 
1.424     albertel 6132: table.LC_group_priv_box td.LC_groups_functionality {
                   6133:   background: $data_table_darker;
                   6134:   text-align: center;
                   6135:   font-weight: bold;
                   6136: }
1.795     www      6137: 
1.424     albertel 6138: table.LC_group_priv td {
                   6139:   text-align: left;
1.803     bisitz   6140:   padding: 0;
1.424     albertel 6141: }
                   6142: 
                   6143: .LC_navbuttons {
                   6144:   margin: 2ex 0ex 2ex 0ex;
                   6145: }
1.795     www      6146: 
1.423     albertel 6147: .LC_topic_bar {
                   6148:   font-weight: bold;
                   6149:   background: $tabbg;
1.918     wenzelju 6150:   margin: 1em 0em 1em 2em;
1.805     bisitz   6151:   padding: 3px;
1.918     wenzelju 6152:   font-size: 1.2em;
1.423     albertel 6153: }
1.795     www      6154: 
1.423     albertel 6155: .LC_topic_bar span {
1.918     wenzelju 6156:   left: 0.5em;
                   6157:   position: absolute;
1.423     albertel 6158:   vertical-align: middle;
1.918     wenzelju 6159:   font-size: 1.2em;
1.423     albertel 6160: }
1.795     www      6161: 
1.423     albertel 6162: table.LC_course_group_status {
                   6163:   margin: 20px;
                   6164: }
1.795     www      6165: 
1.423     albertel 6166: table.LC_status_selector td {
                   6167:   vertical-align: top;
                   6168:   text-align: center;
1.424     albertel 6169:   padding: 4px;
                   6170: }
1.795     www      6171: 
1.599     albertel 6172: div.LC_feedback_link {
1.616     albertel 6173:   clear: both;
1.829     kalberla 6174:   background: $sidebg;
1.779     bisitz   6175:   width: 100%;
1.829     kalberla 6176:   padding-bottom: 10px;
                   6177:   border: 1px $tabbg solid;
1.833     kalberla 6178:   height: 22px;
                   6179:   line-height: 22px;
                   6180:   padding-top: 5px;
                   6181: }
                   6182: 
                   6183: div.LC_feedback_link img {
                   6184:   height: 22px;
1.867     kalberla 6185:   vertical-align:middle;
1.829     kalberla 6186: }
                   6187: 
1.911     bisitz   6188: div.LC_feedback_link a {
1.829     kalberla 6189:   text-decoration: none;
1.489     raeburn  6190: }
1.795     www      6191: 
1.867     kalberla 6192: div.LC_comblock {
1.911     bisitz   6193:   display:inline;
1.867     kalberla 6194:   color:$font;
                   6195:   font-size:90%;
                   6196: }
                   6197: 
                   6198: div.LC_feedback_link div.LC_comblock {
                   6199:   padding-left:5px;
                   6200: }
                   6201: 
                   6202: div.LC_feedback_link div.LC_comblock a {
                   6203:   color:$font;
                   6204: }
                   6205: 
1.489     raeburn  6206: span.LC_feedback_link {
1.858     bisitz   6207:   /* background: $feedback_link_bg; */
1.599     albertel 6208:   font-size: larger;
                   6209: }
1.795     www      6210: 
1.599     albertel 6211: span.LC_message_link {
1.858     bisitz   6212:   /* background: $feedback_link_bg; */
1.599     albertel 6213:   font-size: larger;
                   6214:   position: absolute;
                   6215:   right: 1em;
1.489     raeburn  6216: }
1.421     albertel 6217: 
1.515     albertel 6218: table.LC_prior_tries {
1.524     albertel 6219:   border: 1px solid #000000;
                   6220:   border-collapse: separate;
                   6221:   border-spacing: 1px;
1.515     albertel 6222: }
1.523     albertel 6223: 
1.515     albertel 6224: table.LC_prior_tries td {
1.524     albertel 6225:   padding: 2px;
1.515     albertel 6226: }
1.523     albertel 6227: 
                   6228: .LC_answer_correct {
1.795     www      6229:   background: lightgreen;
                   6230:   color: darkgreen;
                   6231:   padding: 6px;
1.523     albertel 6232: }
1.795     www      6233: 
1.523     albertel 6234: .LC_answer_charged_try {
1.797     www      6235:   background: #FFAAAA;
1.795     www      6236:   color: darkred;
                   6237:   padding: 6px;
1.523     albertel 6238: }
1.795     www      6239: 
1.779     bisitz   6240: .LC_answer_not_charged_try,
1.523     albertel 6241: .LC_answer_no_grade,
                   6242: .LC_answer_late {
1.795     www      6243:   background: lightyellow;
1.523     albertel 6244:   color: black;
1.795     www      6245:   padding: 6px;
1.523     albertel 6246: }
1.795     www      6247: 
1.523     albertel 6248: .LC_answer_previous {
1.795     www      6249:   background: lightblue;
                   6250:   color: darkblue;
                   6251:   padding: 6px;
1.523     albertel 6252: }
1.795     www      6253: 
1.779     bisitz   6254: .LC_answer_no_message {
1.777     tempelho 6255:   background: #FFFFFF;
                   6256:   color: black;
1.795     www      6257:   padding: 6px;
1.779     bisitz   6258: }
1.795     www      6259: 
1.779     bisitz   6260: .LC_answer_unknown {
                   6261:   background: orange;
                   6262:   color: black;
1.795     www      6263:   padding: 6px;
1.777     tempelho 6264: }
1.795     www      6265: 
1.529     albertel 6266: span.LC_prior_numerical,
                   6267: span.LC_prior_string,
                   6268: span.LC_prior_custom,
                   6269: span.LC_prior_reaction,
                   6270: span.LC_prior_math {
1.925     bisitz   6271:   font-family: $mono;
1.523     albertel 6272:   white-space: pre;
                   6273: }
                   6274: 
1.525     albertel 6275: span.LC_prior_string {
1.925     bisitz   6276:   font-family: $mono;
1.525     albertel 6277:   white-space: pre;
                   6278: }
                   6279: 
1.523     albertel 6280: table.LC_prior_option {
                   6281:   width: 100%;
                   6282:   border-collapse: collapse;
                   6283: }
1.795     www      6284: 
1.911     bisitz   6285: table.LC_prior_rank,
1.795     www      6286: table.LC_prior_match {
1.528     albertel 6287:   border-collapse: collapse;
                   6288: }
1.795     www      6289: 
1.528     albertel 6290: table.LC_prior_option tr td,
                   6291: table.LC_prior_rank tr td,
                   6292: table.LC_prior_match tr td {
1.524     albertel 6293:   border: 1px solid #000000;
1.515     albertel 6294: }
                   6295: 
1.855     bisitz   6296: .LC_nobreak {
1.544     albertel 6297:   white-space: nowrap;
1.519     raeburn  6298: }
                   6299: 
1.576     raeburn  6300: span.LC_cusr_emph {
                   6301:   font-style: italic;
                   6302: }
                   6303: 
1.633     raeburn  6304: span.LC_cusr_subheading {
                   6305:   font-weight: normal;
                   6306:   font-size: 85%;
                   6307: }
                   6308: 
1.861     bisitz   6309: div.LC_docs_entry_move {
1.859     bisitz   6310:   border: 1px solid #BBBBBB;
1.545     albertel 6311:   background: #DDDDDD;
1.861     bisitz   6312:   width: 22px;
1.859     bisitz   6313:   padding: 1px;
                   6314:   margin: 0;
1.545     albertel 6315: }
                   6316: 
1.861     bisitz   6317: table.LC_data_table tr > td.LC_docs_entry_commands,
                   6318: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545     albertel 6319:   font-size: x-small;
                   6320: }
1.795     www      6321: 
1.861     bisitz   6322: .LC_docs_entry_parameter {
                   6323:   white-space: nowrap;
                   6324: }
                   6325: 
1.544     albertel 6326: .LC_docs_copy {
1.545     albertel 6327:   color: #000099;
1.544     albertel 6328: }
1.795     www      6329: 
1.544     albertel 6330: .LC_docs_cut {
1.545     albertel 6331:   color: #550044;
1.544     albertel 6332: }
1.795     www      6333: 
1.544     albertel 6334: .LC_docs_rename {
1.545     albertel 6335:   color: #009900;
1.544     albertel 6336: }
1.795     www      6337: 
1.544     albertel 6338: .LC_docs_remove {
1.545     albertel 6339:   color: #990000;
                   6340: }
                   6341: 
1.547     albertel 6342: .LC_docs_reinit_warn,
                   6343: .LC_docs_ext_edit {
                   6344:   font-size: x-small;
                   6345: }
                   6346: 
1.545     albertel 6347: table.LC_docs_adddocs td,
                   6348: table.LC_docs_adddocs th {
                   6349:   border: 1px solid #BBBBBB;
                   6350:   padding: 4px;
                   6351:   background: #DDDDDD;
1.543     albertel 6352: }
                   6353: 
1.584     albertel 6354: table.LC_sty_begin {
                   6355:   background: #BBFFBB;
                   6356: }
1.795     www      6357: 
1.584     albertel 6358: table.LC_sty_end {
                   6359:   background: #FFBBBB;
                   6360: }
                   6361: 
1.589     raeburn  6362: table.LC_double_column {
1.803     bisitz   6363:   border-width: 0;
1.589     raeburn  6364:   border-collapse: collapse;
                   6365:   width: 100%;
                   6366:   padding: 2px;
                   6367: }
                   6368: 
                   6369: table.LC_double_column tr td.LC_left_col {
1.590     raeburn  6370:   top: 2px;
1.589     raeburn  6371:   left: 2px;
                   6372:   width: 47%;
                   6373:   vertical-align: top;
                   6374: }
                   6375: 
                   6376: table.LC_double_column tr td.LC_right_col {
                   6377:   top: 2px;
1.779     bisitz   6378:   right: 2px;
1.589     raeburn  6379:   width: 47%;
                   6380:   vertical-align: top;
                   6381: }
                   6382: 
1.591     raeburn  6383: div.LC_left_float {
                   6384:   float: left;
                   6385:   padding-right: 5%;
1.597     albertel 6386:   padding-bottom: 4px;
1.591     raeburn  6387: }
                   6388: 
                   6389: div.LC_clear_float_header {
1.597     albertel 6390:   padding-bottom: 2px;
1.591     raeburn  6391: }
                   6392: 
                   6393: div.LC_clear_float_footer {
1.597     albertel 6394:   padding-top: 10px;
1.591     raeburn  6395:   clear: both;
                   6396: }
                   6397: 
1.597     albertel 6398: div.LC_grade_show_user {
1.941     bisitz   6399: /*  border-left: 5px solid $sidebg; */
                   6400:   border-top: 5px solid #000000;
                   6401:   margin: 50px 0 0 0;
1.936     bisitz   6402:   padding: 15px 0 5px 10px;
1.597     albertel 6403: }
1.795     www      6404: 
1.936     bisitz   6405: div.LC_grade_show_user_odd_row {
1.941     bisitz   6406: /*  border-left: 5px solid #000000; */
                   6407: }
                   6408: 
                   6409: div.LC_grade_show_user div.LC_Box {
                   6410:   margin-right: 50px;
1.597     albertel 6411: }
                   6412: 
                   6413: div.LC_grade_submissions,
                   6414: div.LC_grade_message_center,
1.936     bisitz   6415: div.LC_grade_info_links {
1.597     albertel 6416:   margin: 5px;
                   6417:   width: 99%;
                   6418:   background: #FFFFFF;
                   6419: }
1.795     www      6420: 
1.597     albertel 6421: div.LC_grade_submissions_header,
1.936     bisitz   6422: div.LC_grade_message_center_header {
1.705     tempelho 6423:   font-weight: bold;
                   6424:   font-size: large;
1.597     albertel 6425: }
1.795     www      6426: 
1.597     albertel 6427: div.LC_grade_submissions_body,
1.936     bisitz   6428: div.LC_grade_message_center_body {
1.597     albertel 6429:   border: 1px solid black;
                   6430:   width: 99%;
                   6431:   background: #FFFFFF;
                   6432: }
1.795     www      6433: 
1.613     albertel 6434: table.LC_scantron_action {
                   6435:   width: 100%;
                   6436: }
1.795     www      6437: 
1.613     albertel 6438: table.LC_scantron_action tr th {
1.698     harmsja  6439:   font-weight:bold;
                   6440:   font-style:normal;
1.613     albertel 6441: }
1.795     www      6442: 
1.779     bisitz   6443: .LC_edit_problem_header,
1.614     albertel 6444: div.LC_edit_problem_footer {
1.705     tempelho 6445:   font-weight: normal;
                   6446:   font-size:  medium;
1.602     albertel 6447:   margin: 2px;
1.1060    bisitz   6448:   background-color: $sidebg;
1.600     albertel 6449: }
1.795     www      6450: 
1.600     albertel 6451: div.LC_edit_problem_header,
1.602     albertel 6452: div.LC_edit_problem_header div,
1.614     albertel 6453: div.LC_edit_problem_footer,
                   6454: div.LC_edit_problem_footer div,
1.602     albertel 6455: div.LC_edit_problem_editxml_header,
                   6456: div.LC_edit_problem_editxml_header div {
1.600     albertel 6457:   margin-top: 5px;
                   6458: }
1.795     www      6459: 
1.600     albertel 6460: div.LC_edit_problem_header_title {
1.705     tempelho 6461:   font-weight: bold;
                   6462:   font-size: larger;
1.602     albertel 6463:   background: $tabbg;
                   6464:   padding: 3px;
1.1060    bisitz   6465:   margin: 0 0 5px 0;
1.602     albertel 6466: }
1.795     www      6467: 
1.602     albertel 6468: table.LC_edit_problem_header_title {
                   6469:   width: 100%;
1.600     albertel 6470:   background: $tabbg;
1.602     albertel 6471: }
                   6472: 
                   6473: div.LC_edit_problem_discards {
                   6474:   float: left;
                   6475:   padding-bottom: 5px;
                   6476: }
1.795     www      6477: 
1.602     albertel 6478: div.LC_edit_problem_saves {
                   6479:   float: right;
                   6480:   padding-bottom: 5px;
1.600     albertel 6481: }
1.795     www      6482: 
1.1075.2.34  raeburn  6483: .LC_edit_opt {
                   6484:   padding-left: 1em;
                   6485:   white-space: nowrap;
                   6486: }
                   6487: 
1.911     bisitz   6488: img.stift {
1.803     bisitz   6489:   border-width: 0;
                   6490:   vertical-align: middle;
1.677     riegler  6491: }
1.680     riegler  6492: 
1.923     bisitz   6493: table td.LC_mainmenu_col_fieldset {
1.680     riegler  6494:   vertical-align: top;
1.777     tempelho 6495: }
1.795     www      6496: 
1.716     raeburn  6497: div.LC_createcourse {
1.911     bisitz   6498:   margin: 10px 10px 10px 10px;
1.716     raeburn  6499: }
                   6500: 
1.917     raeburn  6501: .LC_dccid {
1.1075.2.38  raeburn  6502:   float: right;
1.917     raeburn  6503:   margin: 0.2em 0 0 0;
                   6504:   padding: 0;
                   6505:   font-size: 90%;
                   6506:   display:none;
                   6507: }
                   6508: 
1.897     wenzelju 6509: ol.LC_primary_menu a:hover,
1.721     harmsja  6510: ol#LC_MenuBreadcrumbs a:hover,
                   6511: ol#LC_PathBreadcrumbs a:hover,
1.897     wenzelju 6512: ul#LC_secondary_menu a:hover,
1.721     harmsja  6513: .LC_FormSectionClearButton input:hover
1.795     www      6514: ul.LC_TabContent   li:hover a {
1.952     onken    6515:   color:$button_hover;
1.911     bisitz   6516:   text-decoration:none;
1.693     droeschl 6517: }
                   6518: 
1.779     bisitz   6519: h1 {
1.911     bisitz   6520:   padding: 0;
                   6521:   line-height:130%;
1.693     droeschl 6522: }
1.698     harmsja  6523: 
1.911     bisitz   6524: h2,
                   6525: h3,
                   6526: h4,
                   6527: h5,
                   6528: h6 {
                   6529:   margin: 5px 0 5px 0;
                   6530:   padding: 0;
                   6531:   line-height:130%;
1.693     droeschl 6532: }
1.795     www      6533: 
                   6534: .LC_hcell {
1.911     bisitz   6535:   padding:3px 15px 3px 15px;
                   6536:   margin: 0;
                   6537:   background-color:$tabbg;
                   6538:   color:$fontmenu;
                   6539:   border-bottom:solid 1px $lg_border_color;
1.693     droeschl 6540: }
1.795     www      6541: 
1.840     bisitz   6542: .LC_Box > .LC_hcell {
1.911     bisitz   6543:   margin: 0 -10px 10px -10px;
1.835     bisitz   6544: }
                   6545: 
1.721     harmsja  6546: .LC_noBorder {
1.911     bisitz   6547:   border: 0;
1.698     harmsja  6548: }
1.693     droeschl 6549: 
1.721     harmsja  6550: .LC_FormSectionClearButton input {
1.911     bisitz   6551:   background-color:transparent;
                   6552:   border: none;
                   6553:   cursor:pointer;
                   6554:   text-decoration:underline;
1.693     droeschl 6555: }
1.763     bisitz   6556: 
                   6557: .LC_help_open_topic {
1.911     bisitz   6558:   color: #FFFFFF;
                   6559:   background-color: #EEEEFF;
                   6560:   margin: 1px;
                   6561:   padding: 4px;
                   6562:   border: 1px solid #000033;
                   6563:   white-space: nowrap;
                   6564:   /* vertical-align: middle; */
1.759     neumanie 6565: }
1.693     droeschl 6566: 
1.911     bisitz   6567: dl,
                   6568: ul,
                   6569: div,
                   6570: fieldset {
                   6571:   margin: 10px 10px 10px 0;
                   6572:   /* overflow: hidden; */
1.693     droeschl 6573: }
1.795     www      6574: 
1.838     bisitz   6575: fieldset > legend {
1.911     bisitz   6576:   font-weight: bold;
                   6577:   padding: 0 5px 0 5px;
1.838     bisitz   6578: }
                   6579: 
1.813     bisitz   6580: #LC_nav_bar {
1.911     bisitz   6581:   float: left;
1.995     raeburn  6582:   background-color: $pgbg_or_bgcolor;
1.966     bisitz   6583:   margin: 0 0 2px 0;
1.807     droeschl 6584: }
                   6585: 
1.916     droeschl 6586: #LC_realm {
                   6587:   margin: 0.2em 0 0 0;
                   6588:   padding: 0;
                   6589:   font-weight: bold;
                   6590:   text-align: center;
1.995     raeburn  6591:   background-color: $pgbg_or_bgcolor;
1.916     droeschl 6592: }
                   6593: 
1.911     bisitz   6594: #LC_nav_bar em {
                   6595:   font-weight: bold;
                   6596:   font-style: normal;
1.807     droeschl 6597: }
                   6598: 
1.897     wenzelju 6599: ol.LC_primary_menu {
1.934     droeschl 6600:   margin: 0;
1.1075.2.2  raeburn  6601:   padding: 0;
1.995     raeburn  6602:   background-color: $pgbg_or_bgcolor;
1.807     droeschl 6603: }
                   6604: 
1.852     droeschl 6605: ol#LC_PathBreadcrumbs {
1.911     bisitz   6606:   margin: 0;
1.693     droeschl 6607: }
                   6608: 
1.897     wenzelju 6609: ol.LC_primary_menu li {
1.1075.2.2  raeburn  6610:   color: RGB(80, 80, 80);
                   6611:   vertical-align: middle;
                   6612:   text-align: left;
                   6613:   list-style: none;
                   6614:   float: left;
                   6615: }
                   6616: 
                   6617: ol.LC_primary_menu li a {
                   6618:   display: block;
                   6619:   margin: 0;
                   6620:   padding: 0 5px 0 10px;
                   6621:   text-decoration: none;
                   6622: }
                   6623: 
                   6624: ol.LC_primary_menu li ul {
                   6625:   display: none;
                   6626:   width: 10em;
                   6627:   background-color: $data_table_light;
                   6628: }
                   6629: 
                   6630: ol.LC_primary_menu li:hover ul, ol.LC_primary_menu li.hover ul {
                   6631:   display: block;
                   6632:   position: absolute;
                   6633:   margin: 0;
                   6634:   padding: 0;
1.1075.2.5  raeburn  6635:   z-index: 2;
1.1075.2.2  raeburn  6636: }
                   6637: 
                   6638: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
                   6639:   font-size: 90%;
1.911     bisitz   6640:   vertical-align: top;
1.1075.2.2  raeburn  6641:   float: none;
1.1075.2.5  raeburn  6642:   border-left: 1px solid black;
                   6643:   border-right: 1px solid black;
1.1075.2.2  raeburn  6644: }
                   6645: 
                   6646: ol.LC_primary_menu li:hover li a, ol.LC_primary_menu li.hover li a {
1.1075.2.5  raeburn  6647:   background-color:$data_table_light;
1.1075.2.2  raeburn  6648: }
                   6649: 
                   6650: ol.LC_primary_menu li li a:hover {
                   6651:    color:$button_hover;
                   6652:    background-color:$data_table_dark;
1.693     droeschl 6653: }
                   6654: 
1.897     wenzelju 6655: ol.LC_primary_menu li img {
1.911     bisitz   6656:   vertical-align: bottom;
1.934     droeschl 6657:   height: 1.1em;
1.1075.2.3  raeburn  6658:   margin: 0.2em 0 0 0;
1.693     droeschl 6659: }
                   6660: 
1.897     wenzelju 6661: ol.LC_primary_menu a {
1.911     bisitz   6662:   color: RGB(80, 80, 80);
                   6663:   text-decoration: none;
1.693     droeschl 6664: }
1.795     www      6665: 
1.949     droeschl 6666: ol.LC_primary_menu a.LC_new_message {
                   6667:   font-weight:bold;
                   6668:   color: darkred;
                   6669: }
                   6670: 
1.975     raeburn  6671: ol.LC_docs_parameters {
                   6672:   margin-left: 0;
                   6673:   padding: 0;
                   6674:   list-style: none;
                   6675: }
                   6676: 
                   6677: ol.LC_docs_parameters li {
                   6678:   margin: 0;
                   6679:   padding-right: 20px;
                   6680:   display: inline;
                   6681: }
                   6682: 
1.976     raeburn  6683: ol.LC_docs_parameters li:before {
                   6684:   content: "\\002022 \\0020";
                   6685: }
                   6686: 
                   6687: li.LC_docs_parameters_title {
                   6688:   font-weight: bold;
                   6689: }
                   6690: 
                   6691: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
                   6692:   content: "";
                   6693: }
                   6694: 
1.897     wenzelju 6695: ul#LC_secondary_menu {
1.1075.2.23  raeburn  6696:   clear: right;
1.911     bisitz   6697:   color: $fontmenu;
                   6698:   background: $tabbg;
                   6699:   list-style: none;
                   6700:   padding: 0;
                   6701:   margin: 0;
                   6702:   width: 100%;
1.995     raeburn  6703:   text-align: left;
1.1075.2.4  raeburn  6704:   float: left;
1.808     droeschl 6705: }
                   6706: 
1.897     wenzelju 6707: ul#LC_secondary_menu li {
1.911     bisitz   6708:   font-weight: bold;
                   6709:   line-height: 1.8em;
                   6710:   border-right: 1px solid black;
                   6711:   vertical-align: middle;
1.1075.2.4  raeburn  6712:   float: left;
                   6713: }
                   6714: 
                   6715: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
                   6716:   background-color: $data_table_light;
                   6717: }
                   6718: 
                   6719: ul#LC_secondary_menu li a {
                   6720:   padding: 0 0.8em;
                   6721: }
                   6722: 
                   6723: ul#LC_secondary_menu li ul {
                   6724:   display: none;
                   6725: }
                   6726: 
                   6727: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
                   6728:   display: block;
                   6729:   position: absolute;
                   6730:   margin: 0;
                   6731:   padding: 0;
                   6732:   list-style:none;
                   6733:   float: none;
                   6734:   background-color: $data_table_light;
1.1075.2.5  raeburn  6735:   z-index: 2;
1.1075.2.10  raeburn  6736:   margin-left: -1px;
1.1075.2.4  raeburn  6737: }
                   6738: 
                   6739: ul#LC_secondary_menu li ul li {
                   6740:   font-size: 90%;
                   6741:   vertical-align: top;
                   6742:   border-left: 1px solid black;
                   6743:   border-right: 1px solid black;
1.1075.2.33  raeburn  6744:   background-color: $data_table_light;
1.1075.2.4  raeburn  6745:   list-style:none;
                   6746:   float: none;
                   6747: }
                   6748: 
                   6749: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
                   6750:   background-color: $data_table_dark;
1.807     droeschl 6751: }
                   6752: 
1.847     tempelho 6753: ul.LC_TabContent {
1.911     bisitz   6754:   display:block;
                   6755:   background: $sidebg;
                   6756:   border-bottom: solid 1px $lg_border_color;
                   6757:   list-style:none;
1.1020    raeburn  6758:   margin: -1px -10px 0 -10px;
1.911     bisitz   6759:   padding: 0;
1.693     droeschl 6760: }
                   6761: 
1.795     www      6762: ul.LC_TabContent li,
                   6763: ul.LC_TabContentBigger li {
1.911     bisitz   6764:   float:left;
1.741     harmsja  6765: }
1.795     www      6766: 
1.897     wenzelju 6767: ul#LC_secondary_menu li a {
1.911     bisitz   6768:   color: $fontmenu;
                   6769:   text-decoration: none;
1.693     droeschl 6770: }
1.795     www      6771: 
1.721     harmsja  6772: ul.LC_TabContent {
1.952     onken    6773:   min-height:20px;
1.721     harmsja  6774: }
1.795     www      6775: 
                   6776: ul.LC_TabContent li {
1.911     bisitz   6777:   vertical-align:middle;
1.959     onken    6778:   padding: 0 16px 0 10px;
1.911     bisitz   6779:   background-color:$tabbg;
                   6780:   border-bottom:solid 1px $lg_border_color;
1.1020    raeburn  6781:   border-left: solid 1px $font;
1.721     harmsja  6782: }
1.795     www      6783: 
1.847     tempelho 6784: ul.LC_TabContent .right {
1.911     bisitz   6785:   float:right;
1.847     tempelho 6786: }
                   6787: 
1.911     bisitz   6788: ul.LC_TabContent li a,
                   6789: ul.LC_TabContent li {
                   6790:   color:rgb(47,47,47);
                   6791:   text-decoration:none;
                   6792:   font-size:95%;
                   6793:   font-weight:bold;
1.952     onken    6794:   min-height:20px;
                   6795: }
                   6796: 
1.959     onken    6797: ul.LC_TabContent li a:hover,
                   6798: ul.LC_TabContent li a:focus {
1.952     onken    6799:   color: $button_hover;
1.959     onken    6800:   background:none;
                   6801:   outline:none;
1.952     onken    6802: }
                   6803: 
                   6804: ul.LC_TabContent li:hover {
                   6805:   color: $button_hover;
                   6806:   cursor:pointer;
1.721     harmsja  6807: }
1.795     www      6808: 
1.911     bisitz   6809: ul.LC_TabContent li.active {
1.952     onken    6810:   color: $font;
1.911     bisitz   6811:   background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952     onken    6812:   border-bottom:solid 1px #FFFFFF;
                   6813:   cursor: default;
1.744     ehlerst  6814: }
1.795     www      6815: 
1.959     onken    6816: ul.LC_TabContent li.active a {
                   6817:   color:$font;
                   6818:   background:#FFFFFF;
                   6819:   outline: none;
                   6820: }
1.1047    raeburn  6821: 
                   6822: ul.LC_TabContent li.goback {
                   6823:   float: left;
                   6824:   border-left: none;
                   6825: }
                   6826: 
1.870     tempelho 6827: #maincoursedoc {
1.911     bisitz   6828:   clear:both;
1.870     tempelho 6829: }
                   6830: 
                   6831: ul.LC_TabContentBigger {
1.911     bisitz   6832:   display:block;
                   6833:   list-style:none;
                   6834:   padding: 0;
1.870     tempelho 6835: }
                   6836: 
1.795     www      6837: ul.LC_TabContentBigger li {
1.911     bisitz   6838:   vertical-align:bottom;
                   6839:   height: 30px;
                   6840:   font-size:110%;
                   6841:   font-weight:bold;
                   6842:   color: #737373;
1.841     tempelho 6843: }
                   6844: 
1.957     onken    6845: ul.LC_TabContentBigger li.active {
                   6846:   position: relative;
                   6847:   top: 1px;
                   6848: }
                   6849: 
1.870     tempelho 6850: ul.LC_TabContentBigger li a {
1.911     bisitz   6851:   background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
                   6852:   height: 30px;
                   6853:   line-height: 30px;
                   6854:   text-align: center;
                   6855:   display: block;
                   6856:   text-decoration: none;
1.958     onken    6857:   outline: none;  
1.741     harmsja  6858: }
1.795     www      6859: 
1.870     tempelho 6860: ul.LC_TabContentBigger li.active a {
1.911     bisitz   6861:   background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
                   6862:   color:$font;
1.744     ehlerst  6863: }
1.795     www      6864: 
1.870     tempelho 6865: ul.LC_TabContentBigger li b {
1.911     bisitz   6866:   background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
                   6867:   display: block;
                   6868:   float: left;
                   6869:   padding: 0 30px;
1.957     onken    6870:   border-bottom: 1px solid $lg_border_color;
1.870     tempelho 6871: }
                   6872: 
1.956     onken    6873: ul.LC_TabContentBigger li:hover b {
                   6874:   color:$button_hover;
                   6875: }
                   6876: 
1.870     tempelho 6877: ul.LC_TabContentBigger li.active b {
1.911     bisitz   6878:   background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
                   6879:   color:$font;
1.957     onken    6880:   border: 0;
1.741     harmsja  6881: }
1.693     droeschl 6882: 
1.870     tempelho 6883: 
1.862     bisitz   6884: ul.LC_CourseBreadcrumbs {
                   6885:   background: $sidebg;
1.1020    raeburn  6886:   height: 2em;
1.862     bisitz   6887:   padding-left: 10px;
1.1020    raeburn  6888:   margin: 0;
1.862     bisitz   6889:   list-style-position: inside;
                   6890: }
                   6891: 
1.911     bisitz   6892: ol#LC_MenuBreadcrumbs,
1.862     bisitz   6893: ol#LC_PathBreadcrumbs {
1.911     bisitz   6894:   padding-left: 10px;
                   6895:   margin: 0;
1.933     droeschl 6896:   height: 2.5em;  /* equal to #LC_breadcrumbs line-height */
1.693     droeschl 6897: }
                   6898: 
1.911     bisitz   6899: ol#LC_MenuBreadcrumbs li,
                   6900: ol#LC_PathBreadcrumbs li,
1.862     bisitz   6901: ul.LC_CourseBreadcrumbs li {
1.911     bisitz   6902:   display: inline;
1.933     droeschl 6903:   white-space: normal;  
1.693     droeschl 6904: }
                   6905: 
1.823     bisitz   6906: ol#LC_MenuBreadcrumbs li a,
1.862     bisitz   6907: ul.LC_CourseBreadcrumbs li a {
1.911     bisitz   6908:   text-decoration: none;
                   6909:   font-size:90%;
1.693     droeschl 6910: }
1.795     www      6911: 
1.969     droeschl 6912: ol#LC_MenuBreadcrumbs h1 {
                   6913:   display: inline;
                   6914:   font-size: 90%;
                   6915:   line-height: 2.5em;
                   6916:   margin: 0;
                   6917:   padding: 0;
                   6918: }
                   6919: 
1.795     www      6920: ol#LC_PathBreadcrumbs li a {
1.911     bisitz   6921:   text-decoration:none;
                   6922:   font-size:100%;
                   6923:   font-weight:bold;
1.693     droeschl 6924: }
1.795     www      6925: 
1.840     bisitz   6926: .LC_Box {
1.911     bisitz   6927:   border: solid 1px $lg_border_color;
                   6928:   padding: 0 10px 10px 10px;
1.746     neumanie 6929: }
1.795     www      6930: 
1.1020    raeburn  6931: .LC_DocsBox {
                   6932:   border: solid 1px $lg_border_color;
                   6933:   padding: 0 0 10px 10px;
                   6934: }
                   6935: 
1.795     www      6936: .LC_AboutMe_Image {
1.911     bisitz   6937:   float:left;
                   6938:   margin-right:10px;
1.747     neumanie 6939: }
1.795     www      6940: 
                   6941: .LC_Clear_AboutMe_Image {
1.911     bisitz   6942:   clear:left;
1.747     neumanie 6943: }
1.795     www      6944: 
1.721     harmsja  6945: dl.LC_ListStyleClean dt {
1.911     bisitz   6946:   padding-right: 5px;
                   6947:   display: table-header-group;
1.693     droeschl 6948: }
                   6949: 
1.721     harmsja  6950: dl.LC_ListStyleClean dd {
1.911     bisitz   6951:   display: table-row;
1.693     droeschl 6952: }
                   6953: 
1.721     harmsja  6954: .LC_ListStyleClean,
                   6955: .LC_ListStyleSimple,
                   6956: .LC_ListStyleNormal,
1.795     www      6957: .LC_ListStyleSpecial {
1.911     bisitz   6958:   /* display:block; */
                   6959:   list-style-position: inside;
                   6960:   list-style-type: none;
                   6961:   overflow: hidden;
                   6962:   padding: 0;
1.693     droeschl 6963: }
                   6964: 
1.721     harmsja  6965: .LC_ListStyleSimple li,
                   6966: .LC_ListStyleSimple dd,
                   6967: .LC_ListStyleNormal li,
                   6968: .LC_ListStyleNormal dd,
                   6969: .LC_ListStyleSpecial li,
1.795     www      6970: .LC_ListStyleSpecial dd {
1.911     bisitz   6971:   margin: 0;
                   6972:   padding: 5px 5px 5px 10px;
                   6973:   clear: both;
1.693     droeschl 6974: }
                   6975: 
1.721     harmsja  6976: .LC_ListStyleClean li,
                   6977: .LC_ListStyleClean dd {
1.911     bisitz   6978:   padding-top: 0;
                   6979:   padding-bottom: 0;
1.693     droeschl 6980: }
                   6981: 
1.721     harmsja  6982: .LC_ListStyleSimple dd,
1.795     www      6983: .LC_ListStyleSimple li {
1.911     bisitz   6984:   border-bottom: solid 1px $lg_border_color;
1.693     droeschl 6985: }
                   6986: 
1.721     harmsja  6987: .LC_ListStyleSpecial li,
                   6988: .LC_ListStyleSpecial dd {
1.911     bisitz   6989:   list-style-type: none;
                   6990:   background-color: RGB(220, 220, 220);
                   6991:   margin-bottom: 4px;
1.693     droeschl 6992: }
                   6993: 
1.721     harmsja  6994: table.LC_SimpleTable {
1.911     bisitz   6995:   margin:5px;
                   6996:   border:solid 1px $lg_border_color;
1.795     www      6997: }
1.693     droeschl 6998: 
1.721     harmsja  6999: table.LC_SimpleTable tr {
1.911     bisitz   7000:   padding: 0;
                   7001:   border:solid 1px $lg_border_color;
1.693     droeschl 7002: }
1.795     www      7003: 
                   7004: table.LC_SimpleTable thead {
1.911     bisitz   7005:   background:rgb(220,220,220);
1.693     droeschl 7006: }
                   7007: 
1.721     harmsja  7008: div.LC_columnSection {
1.911     bisitz   7009:   display: block;
                   7010:   clear: both;
                   7011:   overflow: hidden;
                   7012:   margin: 0;
1.693     droeschl 7013: }
                   7014: 
1.721     harmsja  7015: div.LC_columnSection>* {
1.911     bisitz   7016:   float: left;
                   7017:   margin: 10px 20px 10px 0;
                   7018:   overflow:hidden;
1.693     droeschl 7019: }
1.721     harmsja  7020: 
1.795     www      7021: table em {
1.911     bisitz   7022:   font-weight: bold;
                   7023:   font-style: normal;
1.748     schulted 7024: }
1.795     www      7025: 
1.779     bisitz   7026: table.LC_tableBrowseRes,
1.795     www      7027: table.LC_tableOfContent {
1.911     bisitz   7028:   border:none;
                   7029:   border-spacing: 1px;
                   7030:   padding: 3px;
                   7031:   background-color: #FFFFFF;
                   7032:   font-size: 90%;
1.753     droeschl 7033: }
1.789     droeschl 7034: 
1.911     bisitz   7035: table.LC_tableOfContent {
                   7036:   border-collapse: collapse;
1.789     droeschl 7037: }
                   7038: 
1.771     droeschl 7039: table.LC_tableBrowseRes a,
1.768     schulted 7040: table.LC_tableOfContent a {
1.911     bisitz   7041:   background-color: transparent;
                   7042:   text-decoration: none;
1.753     droeschl 7043: }
                   7044: 
1.795     www      7045: table.LC_tableOfContent img {
1.911     bisitz   7046:   border: none;
                   7047:   height: 1.3em;
                   7048:   vertical-align: text-bottom;
                   7049:   margin-right: 0.3em;
1.753     droeschl 7050: }
1.757     schulted 7051: 
1.795     www      7052: a#LC_content_toolbar_firsthomework {
1.911     bisitz   7053:   background-image:url(/res/adm/pages/open-first-problem.gif);
1.774     ehlerst  7054: }
                   7055: 
1.795     www      7056: a#LC_content_toolbar_everything {
1.911     bisitz   7057:   background-image:url(/res/adm/pages/show-all.gif);
1.774     ehlerst  7058: }
                   7059: 
1.795     www      7060: a#LC_content_toolbar_uncompleted {
1.911     bisitz   7061:   background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774     ehlerst  7062: }
                   7063: 
1.795     www      7064: #LC_content_toolbar_clearbubbles {
1.911     bisitz   7065:   background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774     ehlerst  7066: }
                   7067: 
1.795     www      7068: a#LC_content_toolbar_changefolder {
1.911     bisitz   7069:   background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757     schulted 7070: }
                   7071: 
1.795     www      7072: a#LC_content_toolbar_changefolder_toggled {
1.911     bisitz   7073:   background-image:url(/res/adm/pages/open-all-folders.gif);
1.757     schulted 7074: }
                   7075: 
1.1043    raeburn  7076: a#LC_content_toolbar_edittoplevel {
                   7077:   background-image:url(/res/adm/pages/edittoplevel.gif);
                   7078: }
                   7079: 
1.795     www      7080: ul#LC_toolbar li a:hover {
1.911     bisitz   7081:   background-position: bottom center;
1.757     schulted 7082: }
                   7083: 
1.795     www      7084: ul#LC_toolbar {
1.911     bisitz   7085:   padding: 0;
                   7086:   margin: 2px;
                   7087:   list-style:none;
                   7088:   position:relative;
                   7089:   background-color:white;
1.1075.2.9  raeburn  7090:   overflow: auto;
1.757     schulted 7091: }
                   7092: 
1.795     www      7093: ul#LC_toolbar li {
1.911     bisitz   7094:   border:1px solid white;
                   7095:   padding: 0;
                   7096:   margin: 0;
                   7097:   float: left;
                   7098:   display:inline;
                   7099:   vertical-align:middle;
1.1075.2.9  raeburn  7100:   white-space: nowrap;
1.911     bisitz   7101: }
1.757     schulted 7102: 
1.783     amueller 7103: 
1.795     www      7104: a.LC_toolbarItem {
1.911     bisitz   7105:   display:block;
                   7106:   padding: 0;
                   7107:   margin: 0;
                   7108:   height: 32px;
                   7109:   width: 32px;
                   7110:   color:white;
                   7111:   border: none;
                   7112:   background-repeat:no-repeat;
                   7113:   background-color:transparent;
1.757     schulted 7114: }
                   7115: 
1.915     droeschl 7116: ul.LC_funclist {
                   7117:     margin: 0;
                   7118:     padding: 0.5em 1em 0.5em 0;
                   7119: }
                   7120: 
1.933     droeschl 7121: ul.LC_funclist > li:first-child {
                   7122:     font-weight:bold; 
                   7123:     margin-left:0.8em;
                   7124: }
                   7125: 
1.915     droeschl 7126: ul.LC_funclist + ul.LC_funclist {
                   7127:     /* 
                   7128:        left border as a seperator if we have more than
                   7129:        one list 
                   7130:     */
                   7131:     border-left: 1px solid $sidebg;
                   7132:     /* 
                   7133:        this hides the left border behind the border of the 
                   7134:        outer box if element is wrapped to the next 'line' 
                   7135:     */
                   7136:     margin-left: -1px;
                   7137: }
                   7138: 
1.843     bisitz   7139: ul.LC_funclist li {
1.915     droeschl 7140:   display: inline;
1.782     bisitz   7141:   white-space: nowrap;
1.915     droeschl 7142:   margin: 0 0 0 25px;
                   7143:   line-height: 150%;
1.782     bisitz   7144: }
                   7145: 
1.974     wenzelju 7146: .LC_hidden {
                   7147:   display: none;
                   7148: }
                   7149: 
1.1030    www      7150: .LCmodal-overlay {
                   7151: 		position:fixed;
                   7152: 		top:0;
                   7153: 		right:0;
                   7154: 		bottom:0;
                   7155: 		left:0;
                   7156: 		height:100%;
                   7157: 		width:100%;
                   7158: 		margin:0;
                   7159: 		padding:0;
                   7160: 		background:#999;
                   7161: 		opacity:.75;
                   7162: 		filter: alpha(opacity=75);
                   7163: 		-moz-opacity: 0.75;
                   7164: 		z-index:101;
                   7165: }
                   7166: 
                   7167: * html .LCmodal-overlay {   
                   7168: 		position: absolute;
                   7169: 		height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
                   7170: }
                   7171: 
                   7172: .LCmodal-window {
                   7173: 		position:fixed;
                   7174: 		top:50%;
                   7175: 		left:50%;
                   7176: 		margin:0;
                   7177: 		padding:0;
                   7178: 		z-index:102;
                   7179: 	}
                   7180: 
                   7181: * html .LCmodal-window {
                   7182: 		position:absolute;
                   7183: }
                   7184: 
                   7185: .LCclose-window {
                   7186: 		position:absolute;
                   7187: 		width:32px;
                   7188: 		height:32px;
                   7189: 		right:8px;
                   7190: 		top:8px;
                   7191: 		background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
                   7192: 		text-indent:-99999px;
                   7193: 		overflow:hidden;
                   7194: 		cursor:pointer;
                   7195: }
                   7196: 
1.1075.2.17  raeburn  7197: /*
                   7198:   styles used by TTH when "Default set of options to pass to tth/m
                   7199:   when converting TeX" in course settings has been set
                   7200: 
                   7201:   option passed: -t
                   7202: 
                   7203: */
                   7204: 
                   7205: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
                   7206: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
                   7207: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
                   7208: td div.norm {line-height:normal;}
                   7209: 
                   7210: /*
                   7211:   option passed -y3
                   7212: */
                   7213: 
                   7214: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
                   7215: span.overacc2 {position: relative;  left: .8em; top: -1.2ex;}
                   7216: span.overacc1 {position: relative;  left: .6em; top: -1.2ex;}
                   7217: 
1.343     albertel 7218: END
                   7219: }
                   7220: 
1.306     albertel 7221: =pod
                   7222: 
                   7223: =item * &headtag()
                   7224: 
                   7225: Returns a uniform footer for LON-CAPA web pages.
                   7226: 
1.307     albertel 7227: Inputs: $title - optional title for the head
                   7228:         $head_extra - optional extra HTML to put inside the <head>
1.315     albertel 7229:         $args - optional arguments
1.319     albertel 7230:             force_register - if is true call registerurl so the remote is 
                   7231:                              informed
1.415     albertel 7232:             redirect       -> array ref of
                   7233:                                    1- seconds before redirect occurs
                   7234:                                    2- url to redirect to
                   7235:                                    3- whether the side effect should occur
1.315     albertel 7236:                            (side effect of setting 
                   7237:                                $env{'internal.head.redirect'} to the url 
                   7238:                                redirected too)
1.352     albertel 7239:             domain         -> force to color decorate a page for a specific
                   7240:                                domain
                   7241:             function       -> force usage of a specific rolish color scheme
                   7242:             bgcolor        -> override the default page bgcolor
1.460     albertel 7243:             no_auto_mt_title
                   7244:                            -> prevent &mt()ing the title arg
1.464     albertel 7245: 
1.306     albertel 7246: =cut
                   7247: 
                   7248: sub headtag {
1.313     albertel 7249:     my ($title,$head_extra,$args) = @_;
1.306     albertel 7250:     
1.363     albertel 7251:     my $function = $args->{'function'} || &get_users_function();
                   7252:     my $domain   = $args->{'domain'}   || &determinedomain();
                   7253:     my $bgcolor  = $args->{'bgcolor'}  || &designparm($function.'.pgbg',$domain);
1.1075.2.52! raeburn  7254:     my $httphost = $args->{'use_absolute'};
1.418     albertel 7255:     my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458     albertel 7256: 		   $Apache::lonnet::perlvar{'lonVersion'},
1.531     albertel 7257: 		   #time(),
1.418     albertel 7258: 		   $env{'environment.color.timestamp'},
1.363     albertel 7259: 		   $function,$domain,$bgcolor);
                   7260: 
1.369     www      7261:     $url = '/adm/css/'.&escape($url).'.css';
1.363     albertel 7262: 
1.308     albertel 7263:     my $result =
                   7264: 	'<head>'.
1.461     albertel 7265: 	&font_settings();
1.319     albertel 7266: 
1.1064    raeburn  7267:     my $inhibitprint = &print_suppression();
                   7268: 
1.461     albertel 7269:     if (!$args->{'frameset'}) {
                   7270: 	$result .= &Apache::lonhtmlcommon::htmlareaheaders();
                   7271:     }
1.1075.2.12  raeburn  7272:     if ($args->{'force_register'}) {
                   7273:         $result .= &Apache::lonmenu::registerurl(1);
1.319     albertel 7274:     }
1.436     albertel 7275:     if (!$args->{'no_nav_bar'} 
                   7276: 	&& !$args->{'only_body'}
                   7277: 	&& !$args->{'frameset'}) {
1.1075.2.52! raeburn  7278: 	$result .= &help_menu_js($httphost);
1.1032    www      7279:         $result.=&modal_window();
1.1038    www      7280:         $result.=&togglebox_script();
1.1034    www      7281:         $result.=&wishlist_window();
1.1041    www      7282:         $result.=&LCprogressbarUpdate_script();
1.1034    www      7283:     } else {
                   7284:         if ($args->{'add_modal'}) {
                   7285:            $result.=&modal_window();
                   7286:         }
                   7287:         if ($args->{'add_wishlist'}) {
                   7288:            $result.=&wishlist_window();
                   7289:         }
1.1038    www      7290:         if ($args->{'add_togglebox'}) {
                   7291:            $result.=&togglebox_script();
                   7292:         }
1.1041    www      7293:         if ($args->{'add_progressbar'}) {
                   7294:            $result.=&LCprogressbarUpdate_script();
                   7295:         }
1.436     albertel 7296:     }
1.314     albertel 7297:     if (ref($args->{'redirect'})) {
1.414     albertel 7298: 	my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315     albertel 7299: 	$url = &Apache::lonenc::check_encrypt($url);
1.414     albertel 7300: 	if (!$inhibit_continue) {
                   7301: 	    $env{'internal.head.redirect'} = $url;
                   7302: 	}
1.313     albertel 7303: 	$result.=<<ADDMETA
                   7304: <meta http-equiv="pragma" content="no-cache" />
1.344     albertel 7305: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313     albertel 7306: ADDMETA
                   7307:     }
1.306     albertel 7308:     if (!defined($title)) {
                   7309: 	$title = 'The LearningOnline Network with CAPA';
                   7310:     }
1.460     albertel 7311:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
                   7312:     $result .= '<title> LON-CAPA '.$title.'</title>'
1.414     albertel 7313: 	.'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
1.1064    raeburn  7314:         .$inhibitprint
1.414     albertel 7315: 	.$head_extra;
1.1075.2.42  raeburn  7316:     if ($env{'browser.mobile'}) {
                   7317:         $result .= '
                   7318: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
                   7319: <meta name="apple-mobile-web-app-capable" content="yes" />';
                   7320:     }
1.962     droeschl 7321:     return $result.'</head>';
1.306     albertel 7322: }
                   7323: 
                   7324: =pod
                   7325: 
1.340     albertel 7326: =item * &font_settings()
                   7327: 
                   7328: Returns neccessary <meta> to set the proper encoding
                   7329: 
                   7330: Inputs: none
                   7331: 
                   7332: =cut
                   7333: 
                   7334: sub font_settings {
                   7335:     my $headerstring='';
1.647     www      7336:     if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340     albertel 7337: 	$headerstring.=
                   7338: 	    '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
                   7339:     }
                   7340:     return $headerstring;
                   7341: }
                   7342: 
1.341     albertel 7343: =pod
                   7344: 
1.1064    raeburn  7345: =item * &print_suppression()
                   7346: 
                   7347: In course context returns css which causes the body to be blank when media="print",
                   7348: if printout generation is unavailable for the current resource.
                   7349: 
                   7350: This could be because:
                   7351: 
                   7352: (a) printstartdate is in the future
                   7353: 
                   7354: (b) printenddate is in the past
                   7355: 
                   7356: (c) there is an active exam block with "printout"
                   7357: functionality blocked
                   7358: 
                   7359: Users with pav, pfo or evb privileges are exempt.
                   7360: 
                   7361: Inputs: none
                   7362: 
                   7363: =cut
                   7364: 
                   7365: 
                   7366: sub print_suppression {
                   7367:     my $noprint;
                   7368:     if ($env{'request.course.id'}) {
                   7369:         my $scope = $env{'request.course.id'};
                   7370:         if ((&Apache::lonnet::allowed('pav',$scope)) ||
                   7371:             (&Apache::lonnet::allowed('pfo',$scope))) {
                   7372:             return;
                   7373:         }
                   7374:         if ($env{'request.course.sec'} ne '') {
                   7375:             $scope .= "/$env{'request.course.sec'}";
                   7376:             if ((&Apache::lonnet::allowed('pav',$scope)) ||
                   7377:                 (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065    raeburn  7378:                 return;
1.1064    raeburn  7379:             }
                   7380:         }
                   7381:         my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   7382:         my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1065    raeburn  7383:         my $blocked = &blocking_status('printout',$cnum,$cdom);
1.1064    raeburn  7384:         if ($blocked) {
                   7385:             my $checkrole = "cm./$cdom/$cnum";
                   7386:             if ($env{'request.course.sec'} ne '') {
                   7387:                 $checkrole .= "/$env{'request.course.sec'}";
                   7388:             }
                   7389:             unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
                   7390:                     ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
                   7391:                 $noprint = 1;
                   7392:             }
                   7393:         }
                   7394:         unless ($noprint) {
                   7395:             my $symb = &Apache::lonnet::symbread();
                   7396:             if ($symb ne '') {
                   7397:                 my $navmap = Apache::lonnavmaps::navmap->new();
                   7398:                 if (ref($navmap)) {
                   7399:                     my $res = $navmap->getBySymb($symb);
                   7400:                     if (ref($res)) {
                   7401:                         if (!$res->resprintable()) {
                   7402:                             $noprint = 1;
                   7403:                         }
                   7404:                     }
                   7405:                 }
                   7406:             }
                   7407:         }
                   7408:         if ($noprint) {
                   7409:             return <<"ENDSTYLE";
                   7410: <style type="text/css" media="print">
                   7411:     body { display:none }
                   7412: </style>
                   7413: ENDSTYLE
                   7414:         }
                   7415:     }
                   7416:     return;
                   7417: }
                   7418: 
                   7419: =pod
                   7420: 
1.341     albertel 7421: =item * &xml_begin()
                   7422: 
                   7423: Returns the needed doctype and <html>
                   7424: 
                   7425: Inputs: none
                   7426: 
                   7427: =cut
                   7428: 
                   7429: sub xml_begin {
                   7430:     my $output='';
                   7431: 
                   7432:     if ($env{'browser.mathml'}) {
                   7433: 	$output='<?xml version="1.0"?>'
                   7434:             #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
                   7435: #            .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
                   7436:             
                   7437: #	    .'<!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">] >'
                   7438: 	    .'<!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">'
                   7439:             .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" ' 
                   7440: 	    .'xmlns="http://www.w3.org/1999/xhtml">';
                   7441:     } else {
1.849     bisitz   7442: 	$output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
                   7443:            .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341     albertel 7444:     }
                   7445:     return $output;
                   7446: }
1.340     albertel 7447: 
                   7448: =pod
                   7449: 
1.306     albertel 7450: =item * &start_page()
                   7451: 
                   7452: Returns a complete <html> .. <body> section for LON-CAPA web pages.
                   7453: 
1.648     raeburn  7454: Inputs:
                   7455: 
                   7456: =over 4
                   7457: 
                   7458: $title - optional title for the page
                   7459: 
                   7460: $head_extra - optional extra HTML to incude inside the <head>
                   7461: 
                   7462: $args - additional optional args supported are:
                   7463: 
                   7464: =over 8
                   7465: 
                   7466:              only_body      -> is true will set &bodytag() onlybodytag
1.317     albertel 7467:                                     arg on
1.814     bisitz   7468:              no_nav_bar     -> is true will set &bodytag() no_nav_bar arg on
1.648     raeburn  7469:              add_entries    -> additional attributes to add to the  <body>
                   7470:              domain         -> force to color decorate a page for a 
1.317     albertel 7471:                                     specific domain
1.648     raeburn  7472:              function       -> force usage of a specific rolish color
1.317     albertel 7473:                                     scheme
1.648     raeburn  7474:              redirect       -> see &headtag()
                   7475:              bgcolor        -> override the default page bg color
                   7476:              js_ready       -> return a string ready for being used in 
1.317     albertel 7477:                                     a javascript writeln
1.648     raeburn  7478:              html_encode    -> return a string ready for being used in 
1.320     albertel 7479:                                     a html attribute
1.648     raeburn  7480:              force_register -> if is true will turn on the &bodytag()
1.317     albertel 7481:                                     $forcereg arg
1.648     raeburn  7482:              frameset       -> if true will start with a <frameset>
1.330     albertel 7483:                                     rather than <body>
1.648     raeburn  7484:              skip_phases    -> hash ref of 
1.338     albertel 7485:                                     head -> skip the <html><head> generation
                   7486:                                     body -> skip all <body> generation
1.1075.2.12  raeburn  7487:              no_inline_link -> if true and in remote mode, don't show the
                   7488:                                     'Switch To Inline Menu' link
1.648     raeburn  7489:              no_auto_mt_title -> prevent &mt()ing the title arg
                   7490:              inherit_jsmath -> when creating popup window in a page,
                   7491:                                     should it have jsmath forced on by the
                   7492:                                     current page
1.867     kalberla 7493:              bread_crumbs ->             Array containing breadcrumbs
1.983     raeburn  7494:              bread_crumbs_component ->  if exists show it as headline else show only the breadcrumbs
1.1075.2.15  raeburn  7495:              group          -> includes the current group, if page is for a
                   7496:                                specific group
1.361     albertel 7497: 
1.648     raeburn  7498: =back
1.460     albertel 7499: 
1.648     raeburn  7500: =back
1.562     albertel 7501: 
1.306     albertel 7502: =cut
                   7503: 
                   7504: sub start_page {
1.309     albertel 7505:     my ($title,$head_extra,$args) = @_;
1.318     albertel 7506:     #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319     albertel 7507: 
1.315     albertel 7508:     $env{'internal.start_page'}++;
1.1075.2.15  raeburn  7509:     my ($result,@advtools);
1.964     droeschl 7510: 
1.338     albertel 7511:     if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1030    www      7512:         $result .= &xml_begin() . &headtag($title, $head_extra, $args);
1.338     albertel 7513:     }
                   7514:     
                   7515:     if (! exists($args->{'skip_phases'}{'body'}) ) {
                   7516: 	if ($args->{'frameset'}) {
                   7517: 	    my $attr_string = &make_attr_string($args->{'force_register'},
                   7518: 						$args->{'add_entries'});
                   7519: 	    $result .= "\n<frameset $attr_string>\n";
1.831     bisitz   7520:         } else {
                   7521:             $result .=
                   7522:                 &bodytag($title, 
                   7523:                          $args->{'function'},       $args->{'add_entries'},
                   7524:                          $args->{'only_body'},      $args->{'domain'},
                   7525:                          $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12  raeburn  7526:                          $args->{'bgcolor'},        $args->{'no_inline_link'},
1.1075.2.15  raeburn  7527:                          $args,                     \@advtools);
1.831     bisitz   7528:         }
1.330     albertel 7529:     }
1.338     albertel 7530: 
1.315     albertel 7531:     if ($args->{'js_ready'}) {
1.713     kaisler  7532: 		$result = &js_ready($result);
1.315     albertel 7533:     }
1.320     albertel 7534:     if ($args->{'html_encode'}) {
1.713     kaisler  7535: 		$result = &html_encode($result);
                   7536:     }
                   7537: 
1.813     bisitz   7538:     # Preparation for new and consistent functionlist at top of screen
                   7539:     # if ($args->{'functionlist'}) {
                   7540:     #            $result .= &build_functionlist();
                   7541:     #}
                   7542: 
1.964     droeschl 7543:     # Don't add anything more if only_body wanted or in const space
                   7544:     return $result if    $args->{'only_body'} 
                   7545:                       || $env{'request.state'} eq 'construct';
1.813     bisitz   7546: 
                   7547:     #Breadcrumbs
1.758     kaisler  7548:     if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
                   7549: 		&Apache::lonhtmlcommon::clear_breadcrumbs();
                   7550: 		#if any br links exists, add them to the breadcrumbs
                   7551: 		if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {         
                   7552: 			foreach my $crumb (@{$args->{'bread_crumbs'}}){
                   7553: 				&Apache::lonhtmlcommon::add_breadcrumb($crumb);
                   7554: 			}
                   7555: 		}
1.1075.2.19  raeburn  7556:                 # if @advtools array contains items add then to the breadcrumbs
                   7557:                 if (@advtools > 0) {
                   7558:                     &Apache::lonmenu::advtools_crumbs(@advtools);
                   7559:                 }
1.758     kaisler  7560: 
                   7561: 		#if bread_crumbs_component exists show it as headline else show only the breadcrumbs
                   7562: 		if(exists($args->{'bread_crumbs_component'})){
                   7563: 			$result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
                   7564: 		}else{
                   7565: 			$result .= &Apache::lonhtmlcommon::breadcrumbs();
                   7566: 		}
1.1075.2.24  raeburn  7567:     } elsif (($env{'environment.remote'} eq 'on') &&
                   7568:              ($env{'form.inhibitmenu'} ne 'yes') &&
                   7569:              ($env{'request.noversionuri'} =~ m{^/res/}) &&
                   7570:              ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21  raeburn  7571:         $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320     albertel 7572:     }
1.315     albertel 7573:     return $result;
1.306     albertel 7574: }
                   7575: 
                   7576: sub end_page {
1.315     albertel 7577:     my ($args) = @_;
                   7578:     $env{'internal.end_page'}++;
1.330     albertel 7579:     my $result;
1.335     albertel 7580:     if ($args->{'discussion'}) {
                   7581: 	my ($target,$parser);
                   7582: 	if (ref($args->{'discussion'})) {
                   7583: 	    ($target,$parser) =($args->{'discussion'}{'target'},
                   7584: 				$args->{'discussion'}{'parser'});
                   7585: 	}
                   7586: 	$result .= &Apache::lonxml::xmlend($target,$parser);
                   7587:     }
1.330     albertel 7588:     if ($args->{'frameset'}) {
                   7589: 	$result .= '</frameset>';
                   7590:     } else {
1.635     raeburn  7591: 	$result .= &endbodytag($args);
1.330     albertel 7592:     }
1.1075.2.6  raeburn  7593:     unless ($args->{'notbody'}) {
                   7594:         $result .= "\n</html>";
                   7595:     }
1.330     albertel 7596: 
1.315     albertel 7597:     if ($args->{'js_ready'}) {
1.317     albertel 7598: 	$result = &js_ready($result);
1.315     albertel 7599:     }
1.335     albertel 7600: 
1.320     albertel 7601:     if ($args->{'html_encode'}) {
                   7602: 	$result = &html_encode($result);
                   7603:     }
1.335     albertel 7604: 
1.315     albertel 7605:     return $result;
                   7606: }
                   7607: 
1.1034    www      7608: sub wishlist_window {
                   7609:     return(<<'ENDWISHLIST');
1.1046    raeburn  7610: <script type="text/javascript">
1.1034    www      7611: // <![CDATA[
                   7612: // <!-- BEGIN LON-CAPA Internal
                   7613: function set_wishlistlink(title, path) {
                   7614:     if (!title) {
                   7615:         title = document.title;
                   7616:         title = title.replace(/^LON-CAPA /,'');
                   7617:     }
                   7618:     if (!path) {
                   7619:         path = location.pathname;
                   7620:     }
                   7621:     Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
                   7622:                       'wishlistNewLink','width=560,height=350,scrollbars=0');
                   7623: }
                   7624: // END LON-CAPA Internal -->
                   7625: // ]]>
                   7626: </script>
                   7627: ENDWISHLIST
                   7628: }
                   7629: 
1.1030    www      7630: sub modal_window {
                   7631:     return(<<'ENDMODAL');
1.1046    raeburn  7632: <script type="text/javascript">
1.1030    www      7633: // <![CDATA[
                   7634: // <!-- BEGIN LON-CAPA Internal
                   7635: var modalWindow = {
                   7636: 	parent:"body",
                   7637: 	windowId:null,
                   7638: 	content:null,
                   7639: 	width:null,
                   7640: 	height:null,
                   7641: 	close:function()
                   7642: 	{
                   7643: 	        $(".LCmodal-window").remove();
                   7644: 	        $(".LCmodal-overlay").remove();
                   7645: 	},
                   7646: 	open:function()
                   7647: 	{
                   7648: 		var modal = "";
                   7649: 		modal += "<div class=\"LCmodal-overlay\"></div>";
                   7650: 		modal += "<div id=\"" + this.windowId + "\" class=\"LCmodal-window\" style=\"width:" + this.width + "px; height:" + this.height + "px; margin-top:-" + (this.height / 2) + "px; margin-left:-" + (this.width / 2) + "px;\">";
                   7651: 		modal += this.content;
                   7652: 		modal += "</div>";	
                   7653: 
                   7654: 		$(this.parent).append(modal);
                   7655: 
                   7656: 		$(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
                   7657: 		$(".LCclose-window").click(function(){modalWindow.close();});
                   7658: 		$(".LCmodal-overlay").click(function(){modalWindow.close();});
                   7659: 	}
                   7660: };
1.1075.2.42  raeburn  7661: 	var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030    www      7662: 	{
                   7663: 		modalWindow.windowId = "myModal";
                   7664: 		modalWindow.width = width;
                   7665: 		modalWindow.height = height;
1.1075.2.42  raeburn  7666: 		modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'>&lt/iframe>";
1.1030    www      7667: 		modalWindow.open();
                   7668: 	};	
                   7669: // END LON-CAPA Internal -->
                   7670: // ]]>
                   7671: </script>
                   7672: ENDMODAL
                   7673: }
                   7674: 
                   7675: sub modal_link {
1.1075.2.42  raeburn  7676:     my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030    www      7677:     unless ($width) { $width=480; }
                   7678:     unless ($height) { $height=400; }
1.1031    www      7679:     unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42  raeburn  7680:     unless ($transparency) { $transparency='true'; }
                   7681: 
1.1074    raeburn  7682:     my $target_attr;
                   7683:     if (defined($target)) {
                   7684:         $target_attr = 'target="'.$target.'"';
                   7685:     }
                   7686:     return <<"ENDLINK";
1.1075.2.42  raeburn  7687: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074    raeburn  7688:            $linktext</a>
                   7689: ENDLINK
1.1030    www      7690: }
                   7691: 
1.1032    www      7692: sub modal_adhoc_script {
                   7693:     my ($funcname,$width,$height,$content)=@_;
                   7694:     return (<<ENDADHOC);
1.1046    raeburn  7695: <script type="text/javascript">
1.1032    www      7696: // <![CDATA[
                   7697:         var $funcname = function()
                   7698:         {
                   7699:                 modalWindow.windowId = "myModal";
                   7700:                 modalWindow.width = $width;
                   7701:                 modalWindow.height = $height;
                   7702:                 modalWindow.content = '$content';
                   7703:                 modalWindow.open();
                   7704:         };  
                   7705: // ]]>
                   7706: </script>
                   7707: ENDADHOC
                   7708: }
                   7709: 
1.1041    www      7710: sub modal_adhoc_inner {
                   7711:     my ($funcname,$width,$height,$content)=@_;
                   7712:     my $innerwidth=$width-20;
                   7713:     $content=&js_ready(
1.1042    www      7714:                &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42  raeburn  7715:                  &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
                   7716:                  $content.
1.1041    www      7717:                  &end_scrollbox().
1.1075.2.42  raeburn  7718:                  &end_page()
1.1041    www      7719:              );
                   7720:     return &modal_adhoc_script($funcname,$width,$height,$content);
                   7721: }
                   7722: 
                   7723: sub modal_adhoc_window {
                   7724:     my ($funcname,$width,$height,$content,$linktext)=@_;
                   7725:     return &modal_adhoc_inner($funcname,$width,$height,$content).
                   7726:            "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
                   7727: }
                   7728: 
                   7729: sub modal_adhoc_launch {
                   7730:     my ($funcname,$width,$height,$content)=@_;
                   7731:     return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
                   7732: <script type="text/javascript">
                   7733: // <![CDATA[
                   7734: $funcname();
                   7735: // ]]>
                   7736: </script>
                   7737: ENDLAUNCH
                   7738: }
                   7739: 
                   7740: sub modal_adhoc_close {
                   7741:     return (<<ENDCLOSE);
                   7742: <script type="text/javascript">
                   7743: // <![CDATA[
                   7744: modalWindow.close();
                   7745: // ]]>
                   7746: </script>
                   7747: ENDCLOSE
                   7748: }
                   7749: 
1.1038    www      7750: sub togglebox_script {
                   7751:    return(<<ENDTOGGLE);
                   7752: <script type="text/javascript"> 
                   7753: // <![CDATA[
                   7754: function LCtoggleDisplay(id,hidetext,showtext) {
                   7755:    link = document.getElementById(id + "link").childNodes[0];
                   7756:    with (document.getElementById(id).style) {
                   7757:       if (display == "none" ) {
                   7758:           display = "inline";
                   7759:           link.nodeValue = hidetext;
                   7760:         } else {
                   7761:           display = "none";
                   7762:           link.nodeValue = showtext;
                   7763:        }
                   7764:    }
                   7765: }
                   7766: // ]]>
                   7767: </script>
                   7768: ENDTOGGLE
                   7769: }
                   7770: 
1.1039    www      7771: sub start_togglebox {
                   7772:     my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
                   7773:     unless ($heading) { $heading=''; } else { $heading.=' '; }
                   7774:     unless ($showtext) { $showtext=&mt('show'); }
                   7775:     unless ($hidetext) { $hidetext=&mt('hide'); }
                   7776:     unless ($headerbg) { $headerbg='#FFFFFF'; }
                   7777:     return &start_data_table().
                   7778:            &start_data_table_header_row().
                   7779:            '<td bgcolor="'.$headerbg.'">'.$heading.
                   7780:            '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
                   7781:            $showtext.'\')">'.$showtext.'</a>]</td>'.
                   7782:            &end_data_table_header_row().
                   7783:            '<tr id="'.$id.'" style="display:none""><td>';
                   7784: }
                   7785: 
                   7786: sub end_togglebox {
                   7787:     return '</td></tr>'.&end_data_table();
                   7788: }
                   7789: 
1.1041    www      7790: sub LCprogressbar_script {
1.1045    www      7791:    my ($id)=@_;
1.1041    www      7792:    return(<<ENDPROGRESS);
                   7793: <script type="text/javascript">
                   7794: // <![CDATA[
1.1045    www      7795: \$('#progressbar$id').progressbar({
1.1041    www      7796:   value: 0,
                   7797:   change: function(event, ui) {
                   7798:     var newVal = \$(this).progressbar('option', 'value');
                   7799:     \$('.pblabel', this).text(LCprogressTxt);
                   7800:   }
                   7801: });
                   7802: // ]]>
                   7803: </script>
                   7804: ENDPROGRESS
                   7805: }
                   7806: 
                   7807: sub LCprogressbarUpdate_script {
                   7808:    return(<<ENDPROGRESSUPDATE);
                   7809: <style type="text/css">
                   7810: .ui-progressbar { position:relative; }
                   7811: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
                   7812: </style>
                   7813: <script type="text/javascript">
                   7814: // <![CDATA[
1.1045    www      7815: var LCprogressTxt='---';
                   7816: 
                   7817: function LCupdateProgress(percent,progresstext,id) {
1.1041    www      7818:    LCprogressTxt=progresstext;
1.1045    www      7819:    \$('#progressbar'+id).progressbar('value',percent);
1.1041    www      7820: }
                   7821: // ]]>
                   7822: </script>
                   7823: ENDPROGRESSUPDATE
                   7824: }
                   7825: 
1.1042    www      7826: my $LClastpercent;
1.1045    www      7827: my $LCidcnt;
                   7828: my $LCcurrentid;
1.1042    www      7829: 
1.1041    www      7830: sub LCprogressbar {
1.1042    www      7831:     my ($r)=(@_);
                   7832:     $LClastpercent=0;
1.1045    www      7833:     $LCidcnt++;
                   7834:     $LCcurrentid=$$.'_'.$LCidcnt;
1.1041    www      7835:     my $starting=&mt('Starting');
                   7836:     my $content=(<<ENDPROGBAR);
1.1045    www      7837:   <div id="progressbar$LCcurrentid">
1.1041    www      7838:     <span class="pblabel">$starting</span>
                   7839:   </div>
                   7840: ENDPROGBAR
1.1045    www      7841:     &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041    www      7842: }
                   7843: 
                   7844: sub LCprogressbarUpdate {
1.1042    www      7845:     my ($r,$val,$text)=@_;
                   7846:     unless ($val) { 
                   7847:        if ($LClastpercent) {
                   7848:            $val=$LClastpercent;
                   7849:        } else {
                   7850:            $val=0;
                   7851:        }
                   7852:     }
1.1041    www      7853:     if ($val<0) { $val=0; }
                   7854:     if ($val>100) { $val=0; }
1.1042    www      7855:     $LClastpercent=$val;
1.1041    www      7856:     unless ($text) { $text=$val.'%'; }
                   7857:     $text=&js_ready($text);
1.1044    www      7858:     &r_print($r,<<ENDUPDATE);
1.1041    www      7859: <script type="text/javascript">
                   7860: // <![CDATA[
1.1045    www      7861: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041    www      7862: // ]]>
                   7863: </script>
                   7864: ENDUPDATE
1.1035    www      7865: }
                   7866: 
1.1042    www      7867: sub LCprogressbarClose {
                   7868:     my ($r)=@_;
                   7869:     $LClastpercent=0;
1.1044    www      7870:     &r_print($r,<<ENDCLOSE);
1.1042    www      7871: <script type="text/javascript">
                   7872: // <![CDATA[
1.1045    www      7873: \$("#progressbar$LCcurrentid").hide('slow'); 
1.1042    www      7874: // ]]>
                   7875: </script>
                   7876: ENDCLOSE
1.1044    www      7877: }
                   7878: 
                   7879: sub r_print {
                   7880:     my ($r,$to_print)=@_;
                   7881:     if ($r) {
                   7882:       $r->print($to_print);
                   7883:       $r->rflush();
                   7884:     } else {
                   7885:       print($to_print);
                   7886:     }
1.1042    www      7887: }
                   7888: 
1.320     albertel 7889: sub html_encode {
                   7890:     my ($result) = @_;
                   7891: 
1.322     albertel 7892:     $result = &HTML::Entities::encode($result,'<>&"');
1.320     albertel 7893:     
                   7894:     return $result;
                   7895: }
1.1044    www      7896: 
1.317     albertel 7897: sub js_ready {
                   7898:     my ($result) = @_;
                   7899: 
1.323     albertel 7900:     $result =~ s/[\n\r]/ /xmsg;
                   7901:     $result =~ s/\\/\\\\/xmsg;
                   7902:     $result =~ s/'/\\'/xmsg;
1.372     albertel 7903:     $result =~ s{</}{<\\/}xmsg;
1.317     albertel 7904:     
                   7905:     return $result;
                   7906: }
                   7907: 
1.315     albertel 7908: sub validate_page {
                   7909:     if (  exists($env{'internal.start_page'})
1.316     albertel 7910: 	  &&     $env{'internal.start_page'} > 1) {
                   7911: 	&Apache::lonnet::logthis('start_page called multiple times '.
1.318     albertel 7912: 				 $env{'internal.start_page'}.' '.
1.316     albertel 7913: 				 $ENV{'request.filename'});
1.315     albertel 7914:     }
                   7915:     if (  exists($env{'internal.end_page'})
1.316     albertel 7916: 	  &&     $env{'internal.end_page'} > 1) {
                   7917: 	&Apache::lonnet::logthis('end_page called multiple times '.
1.318     albertel 7918: 				 $env{'internal.end_page'}.' '.
1.316     albertel 7919: 				 $env{'request.filename'});
1.315     albertel 7920:     }
                   7921:     if (     exists($env{'internal.start_page'})
                   7922: 	&& ! exists($env{'internal.end_page'})) {
1.316     albertel 7923: 	&Apache::lonnet::logthis('start_page called without end_page '.
                   7924: 				 $env{'request.filename'});
1.315     albertel 7925:     }
                   7926:     if (   ! exists($env{'internal.start_page'})
                   7927: 	&&   exists($env{'internal.end_page'})) {
1.316     albertel 7928: 	&Apache::lonnet::logthis('end_page called without start_page'.
                   7929: 				 $env{'request.filename'});
1.315     albertel 7930:     }
1.306     albertel 7931: }
1.315     albertel 7932: 
1.996     www      7933: 
                   7934: sub start_scrollbox {
1.1075.2.42  raeburn  7935:     my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready)=@_;
1.998     raeburn  7936:     unless ($outerwidth) { $outerwidth='520px'; }
                   7937:     unless ($width) { $width='500px'; }
                   7938:     unless ($height) { $height='200px'; }
1.1075    raeburn  7939:     my ($table_id,$div_id,$tdcol);
1.1018    raeburn  7940:     if ($id ne '') {
1.1075.2.42  raeburn  7941:         $table_id = ' id="table_'.$id.'"';
                   7942:         $div_id = ' id="div_'.$id.'"';
1.1018    raeburn  7943:     }
1.1075    raeburn  7944:     if ($bgcolor ne '') {
                   7945:         $tdcol = "background-color: $bgcolor;";
                   7946:     }
1.1075.2.42  raeburn  7947:     my $nicescroll_js;
                   7948:     if ($env{'browser.mobile'}) {
                   7949:         $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
                   7950:     }
1.1075    raeburn  7951:     return <<"END";
1.1075.2.42  raeburn  7952: $nicescroll_js
                   7953: 
                   7954: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
                   7955: <div style="overflow:auto; width:$width; height: $height;"$div_id>
1.1075    raeburn  7956: END
1.996     www      7957: }
                   7958: 
                   7959: sub end_scrollbox {
1.1036    www      7960:     return '</div></td></tr></table>';
1.996     www      7961: }
                   7962: 
1.1075.2.42  raeburn  7963: sub nicescroll_javascript {
                   7964:     my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
                   7965:     my %options;
                   7966:     if (ref($cursor) eq 'HASH') {
                   7967:         %options = %{$cursor};
                   7968:     }
                   7969:     unless ($options{'railalign'} =~ /^left|right$/) {
                   7970:         $options{'railalign'} = 'left';
                   7971:     }
                   7972:     unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
                   7973:         my $function  = &get_users_function();
                   7974:         $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
                   7975:         unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
                   7976:             $options{'cursorcolor'} = '#00F';
                   7977:         }
                   7978:     }
                   7979:     if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
                   7980:         unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
                   7981:             $options{'cursoropacity'}='1.0';
                   7982:         }
                   7983:     } else {
                   7984:         $options{'cursoropacity'}='1.0';
                   7985:     }
                   7986:     if ($options{'cursorfixedheight'} eq 'none') {
                   7987:         delete($options{'cursorfixedheight'});
                   7988:     } else {
                   7989:         unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
                   7990:     }
                   7991:     unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
                   7992:         delete($options{'railoffset'});
                   7993:     }
                   7994:     my @niceoptions;
                   7995:     while (my($key,$value) = each(%options)) {
                   7996:         if ($value =~ /^\{.+\}$/) {
                   7997:             push(@niceoptions,$key.':'.$value);
                   7998:         } else {
                   7999:             push(@niceoptions,$key.':"'.$value.'"');
                   8000:         }
                   8001:     }
                   8002:     my $nicescroll_js = '
                   8003: $(document).ready(
                   8004:       function() {
                   8005:           $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
                   8006:       }
                   8007: );
                   8008: ';
                   8009:     if ($framecheck) {
                   8010:         $nicescroll_js .= '
                   8011: function expand_div(caller) {
                   8012:     if (top === self) {
                   8013:         document.getElementById("'.$id.'").style.width = "auto";
                   8014:         document.getElementById("'.$id.'").style.height = "auto";
                   8015:     } else {
                   8016:         try {
                   8017:             if (parent.frames) {
                   8018:                 if (parent.frames.length > 1) {
                   8019:                     var framesrc = parent.frames[1].location.href;
                   8020:                     var currsrc = framesrc.replace(/\#.*$/,"");
                   8021:                     if ((caller == "search") || (currsrc == "'.$location.'")) {
                   8022:                         document.getElementById("'.$id.'").style.width = "auto";
                   8023:                         document.getElementById("'.$id.'").style.height = "auto";
                   8024:                     }
                   8025:                 }
                   8026:             }
                   8027:         } catch (e) {
                   8028:             return;
                   8029:         }
                   8030:     }
                   8031:     return;
                   8032: }
                   8033: ';
                   8034:     }
                   8035:     if ($needjsready) {
                   8036:         $nicescroll_js = '
                   8037: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
                   8038:     } else {
                   8039:         $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
                   8040:     }
                   8041:     return $nicescroll_js;
                   8042: }
                   8043: 
1.318     albertel 8044: sub simple_error_page {
1.1075.2.49  raeburn  8045:     my ($r,$title,$msg,$args) = @_;
                   8046:     if (ref($args) eq 'HASH') {
                   8047:         if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
                   8048:     } else {
                   8049:         $msg = &mt($msg);
                   8050:     }
                   8051: 
1.318     albertel 8052:     my $page =
                   8053: 	&Apache::loncommon::start_page($title).
1.1075.2.49  raeburn  8054: 	'<p class="LC_error">'.$msg.'</p>'.
1.318     albertel 8055: 	&Apache::loncommon::end_page();
                   8056:     if (ref($r)) {
                   8057: 	$r->print($page);
1.327     albertel 8058: 	return;
1.318     albertel 8059:     }
                   8060:     return $page;
                   8061: }
1.347     albertel 8062: 
                   8063: {
1.610     albertel 8064:     my @row_count;
1.961     onken    8065: 
                   8066:     sub start_data_table_count {
                   8067:         unshift(@row_count, 0);
                   8068:         return;
                   8069:     }
                   8070: 
                   8071:     sub end_data_table_count {
                   8072:         shift(@row_count);
                   8073:         return;
                   8074:     }
                   8075: 
1.347     albertel 8076:     sub start_data_table {
1.1018    raeburn  8077: 	my ($add_class,$id) = @_;
1.422     albertel 8078: 	my $css_class = (join(' ','LC_data_table',$add_class));
1.1018    raeburn  8079:         my $table_id;
                   8080:         if (defined($id)) {
                   8081:             $table_id = ' id="'.$id.'"';
                   8082:         }
1.961     onken    8083: 	&start_data_table_count();
1.1018    raeburn  8084: 	return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347     albertel 8085:     }
                   8086: 
                   8087:     sub end_data_table {
1.961     onken    8088: 	&end_data_table_count();
1.389     albertel 8089: 	return '</table>'."\n";;
1.347     albertel 8090:     }
                   8091: 
                   8092:     sub start_data_table_row {
1.974     wenzelju 8093: 	my ($add_class, $id) = @_;
1.610     albertel 8094: 	$row_count[0]++;
                   8095: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900     bisitz   8096: 	$css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974     wenzelju 8097:         $id = (' id="'.$id.'"') unless ($id eq '');
                   8098:         return  '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347     albertel 8099:     }
1.471     banghart 8100:     
                   8101:     sub continue_data_table_row {
1.974     wenzelju 8102: 	my ($add_class, $id) = @_;
1.610     albertel 8103: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974     wenzelju 8104: 	$css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
                   8105:         $id = (' id="'.$id.'"') unless ($id eq '');
                   8106:         return  '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471     banghart 8107:     }
1.347     albertel 8108: 
                   8109:     sub end_data_table_row {
1.389     albertel 8110: 	return '</tr>'."\n";;
1.347     albertel 8111:     }
1.367     www      8112: 
1.421     albertel 8113:     sub start_data_table_empty_row {
1.707     bisitz   8114: #	$row_count[0]++;
1.421     albertel 8115: 	return  '<tr class="LC_empty_row" >'."\n";;
                   8116:     }
                   8117: 
                   8118:     sub end_data_table_empty_row {
                   8119: 	return '</tr>'."\n";;
                   8120:     }
                   8121: 
1.367     www      8122:     sub start_data_table_header_row {
1.389     albertel 8123: 	return  '<tr class="LC_header_row">'."\n";;
1.367     www      8124:     }
                   8125: 
                   8126:     sub end_data_table_header_row {
1.389     albertel 8127: 	return '</tr>'."\n";;
1.367     www      8128:     }
1.890     droeschl 8129: 
                   8130:     sub data_table_caption {
                   8131:         my $caption = shift;
                   8132:         return "<caption class=\"LC_caption\">$caption</caption>";
                   8133:     }
1.347     albertel 8134: }
                   8135: 
1.548     albertel 8136: =pod
                   8137: 
                   8138: =item * &inhibit_menu_check($arg)
                   8139: 
                   8140: Checks for a inhibitmenu state and generates output to preserve it
                   8141: 
                   8142: Inputs:         $arg - can be any of
                   8143:                      - undef - in which case the return value is a string 
                   8144:                                to add  into arguments list of a uri
                   8145:                      - 'input' - in which case the return value is a HTML
                   8146:                                  <form> <input> field of type hidden to
                   8147:                                  preserve the value
                   8148:                      - a url - in which case the return value is the url with
                   8149:                                the neccesary cgi args added to preserve the
                   8150:                                inhibitmenu state
                   8151:                      - a ref to a url - no return value, but the string is
                   8152:                                         updated to include the neccessary cgi
                   8153:                                         args to preserve the inhibitmenu state
                   8154: 
                   8155: =cut
                   8156: 
                   8157: sub inhibit_menu_check {
                   8158:     my ($arg) = @_;
                   8159:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   8160:     if ($arg eq 'input') {
                   8161: 	if ($env{'form.inhibitmenu'}) {
                   8162: 	    return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
                   8163: 	} else {
                   8164: 	    return
                   8165: 	}
                   8166:     }
                   8167:     if ($env{'form.inhibitmenu'}) {
                   8168: 	if (ref($arg)) {
                   8169: 	    $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   8170: 	} elsif ($arg eq '') {
                   8171: 	    $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
                   8172: 	} else {
                   8173: 	    $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   8174: 	}
                   8175:     }
                   8176:     if (!ref($arg)) {
                   8177: 	return $arg;
                   8178:     }
                   8179: }
                   8180: 
1.251     albertel 8181: ###############################################
1.182     matthew  8182: 
                   8183: =pod
                   8184: 
1.549     albertel 8185: =back
                   8186: 
                   8187: =head1 User Information Routines
                   8188: 
                   8189: =over 4
                   8190: 
1.405     albertel 8191: =item * &get_users_function()
1.182     matthew  8192: 
                   8193: Used by &bodytag to determine the current users primary role.
                   8194: Returns either 'student','coordinator','admin', or 'author'.
                   8195: 
                   8196: =cut
                   8197: 
                   8198: ###############################################
                   8199: sub get_users_function {
1.815     tempelho 8200:     my $function = 'norole';
1.818     tempelho 8201:     if ($env{'request.role'}=~/^(st)/) {
                   8202:         $function='student';
                   8203:     }
1.907     raeburn  8204:     if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182     matthew  8205:         $function='coordinator';
                   8206:     }
1.258     albertel 8207:     if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182     matthew  8208:         $function='admin';
                   8209:     }
1.826     bisitz   8210:     if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025    raeburn  8211:         ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182     matthew  8212:         $function='author';
                   8213:     }
                   8214:     return $function;
1.54      www      8215: }
1.99      www      8216: 
                   8217: ###############################################
                   8218: 
1.233     raeburn  8219: =pod
                   8220: 
1.821     raeburn  8221: =item * &show_course()
                   8222: 
                   8223: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
                   8224: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
                   8225: 
                   8226: Inputs:
                   8227: None
                   8228: 
                   8229: Outputs:
                   8230: Scalar: 1 if 'Course' to be used, 0 otherwise.
                   8231: 
                   8232: =cut
                   8233: 
                   8234: ###############################################
                   8235: sub show_course {
                   8236:     my $course = !$env{'user.adv'};
                   8237:     if (!$env{'user.adv'}) {
                   8238:         foreach my $env (keys(%env)) {
                   8239:             next if ($env !~ m/^user\.priv\./);
                   8240:             if ($env !~ m/^user\.priv\.(?:st|cm)/) {
                   8241:                 $course = 0;
                   8242:                 last;
                   8243:             }
                   8244:         }
                   8245:     }
                   8246:     return $course;
                   8247: }
                   8248: 
                   8249: ###############################################
                   8250: 
                   8251: =pod
                   8252: 
1.542     raeburn  8253: =item * &check_user_status()
1.274     raeburn  8254: 
                   8255: Determines current status of supplied role for a
                   8256: specific user. Roles can be active, previous or future.
                   8257: 
                   8258: Inputs: 
                   8259: user's domain, user's username, course's domain,
1.375     raeburn  8260: course's number, optional section ID.
1.274     raeburn  8261: 
                   8262: Outputs:
                   8263: role status: active, previous or future. 
                   8264: 
                   8265: =cut
                   8266: 
                   8267: sub check_user_status {
1.412     raeburn  8268:     my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073    raeburn  8269:     my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.274     raeburn  8270:     my @uroles = keys %userinfo;
                   8271:     my $srchstr;
                   8272:     my $active_chk = 'none';
1.412     raeburn  8273:     my $now = time;
1.274     raeburn  8274:     if (@uroles > 0) {
1.908     raeburn  8275:         if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274     raeburn  8276:             $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
                   8277:         } else {
1.412     raeburn  8278:             $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
                   8279:         }
                   8280:         if (grep/^\Q$srchstr\E$/,@uroles) {
1.274     raeburn  8281:             my $role_end = 0;
                   8282:             my $role_start = 0;
                   8283:             $active_chk = 'active';
1.412     raeburn  8284:             if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
                   8285:                 $role_end = $1;
                   8286:                 if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
                   8287:                     $role_start = $1;
1.274     raeburn  8288:                 }
                   8289:             }
                   8290:             if ($role_start > 0) {
1.412     raeburn  8291:                 if ($now < $role_start) {
1.274     raeburn  8292:                     $active_chk = 'future';
                   8293:                 }
                   8294:             }
                   8295:             if ($role_end > 0) {
1.412     raeburn  8296:                 if ($now > $role_end) {
1.274     raeburn  8297:                     $active_chk = 'previous';
                   8298:                 }
                   8299:             }
                   8300:         }
                   8301:     }
                   8302:     return $active_chk;
                   8303: }
                   8304: 
                   8305: ###############################################
                   8306: 
                   8307: =pod
                   8308: 
1.405     albertel 8309: =item * &get_sections()
1.233     raeburn  8310: 
                   8311: Determines all the sections for a course including
                   8312: sections with students and sections containing other roles.
1.419     raeburn  8313: Incoming parameters: 
                   8314: 
                   8315: 1. domain
                   8316: 2. course number 
                   8317: 3. reference to array containing roles for which sections should 
                   8318: be gathered (optional).
                   8319: 4. reference to array containing status types for which sections 
                   8320: should be gathered (optional).
                   8321: 
                   8322: If the third argument is undefined, sections are gathered for any role. 
                   8323: If the fourth argument is undefined, sections are gathered for any status.
                   8324: Permissible values are 'active' or 'future' or 'previous'.
1.233     raeburn  8325:  
1.374     raeburn  8326: Returns section hash (keys are section IDs, values are
                   8327: number of users in each section), subject to the
1.419     raeburn  8328: optional roles filter, optional status filter 
1.233     raeburn  8329: 
                   8330: =cut
                   8331: 
                   8332: ###############################################
                   8333: sub get_sections {
1.419     raeburn  8334:     my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366     albertel 8335:     if (!defined($cdom) || !defined($cnum)) {
                   8336:         my $cid =  $env{'request.course.id'};
                   8337: 
                   8338: 	return if (!defined($cid));
                   8339: 
                   8340:         $cdom = $env{'course.'.$cid.'.domain'};
                   8341:         $cnum = $env{'course.'.$cid.'.num'};
                   8342:     }
                   8343: 
                   8344:     my %sectioncount;
1.419     raeburn  8345:     my $now = time;
1.240     albertel 8346: 
1.1075.2.33  raeburn  8347:     my $check_students = 1;
                   8348:     my $only_students = 0;
                   8349:     if (ref($possible_roles) eq 'ARRAY') {
                   8350:         if (grep(/^st$/,@{$possible_roles})) {
                   8351:             if (@{$possible_roles} == 1) {
                   8352:                 $only_students = 1;
                   8353:             }
                   8354:         } else {
                   8355:             $check_students = 0;
                   8356:         }
                   8357:     }
                   8358: 
                   8359:     if ($check_students) {
1.276     albertel 8360: 	my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240     albertel 8361: 	my $sec_index = &Apache::loncoursedata::CL_SECTION();
                   8362: 	my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419     raeburn  8363:         my $start_index = &Apache::loncoursedata::CL_START();
                   8364:         my $end_index = &Apache::loncoursedata::CL_END();
                   8365:         my $status;
1.366     albertel 8366: 	while (my ($student,$data) = each(%$classlist)) {
1.419     raeburn  8367: 	    my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
                   8368: 				                     $data->[$status_index],
                   8369:                                                      $data->[$start_index],
                   8370:                                                      $data->[$end_index]);
                   8371:             if ($stu_status eq 'Active') {
                   8372:                 $status = 'active';
                   8373:             } elsif ($end < $now) {
                   8374:                 $status = 'previous';
                   8375:             } elsif ($start > $now) {
                   8376:                 $status = 'future';
                   8377:             } 
                   8378: 	    if ($section ne '-1' && $section !~ /^\s*$/) {
                   8379:                 if ((!defined($possible_status)) || (($status ne '') && 
                   8380:                     (grep/^\Q$status\E$/,@{$possible_status}))) { 
                   8381: 		    $sectioncount{$section}++;
                   8382:                 }
1.240     albertel 8383: 	    }
                   8384: 	}
                   8385:     }
1.1075.2.33  raeburn  8386:     if ($only_students) {
                   8387:         return %sectioncount;
                   8388:     }
1.240     albertel 8389:     my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   8390:     foreach my $user (sort(keys(%courseroles))) {
                   8391: 	if ($user !~ /^(\w{2})/) { next; }
                   8392: 	my ($role) = ($user =~ /^(\w{2})/);
                   8393: 	if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419     raeburn  8394: 	my ($section,$status);
1.240     albertel 8395: 	if ($role eq 'cr' &&
                   8396: 	    $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
                   8397: 	    $section=$1;
                   8398: 	}
                   8399: 	if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
                   8400: 	if (!defined($section) || $section eq '-1') { next; }
1.419     raeburn  8401:         my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
                   8402:         if ($end == -1 && $start == -1) {
                   8403:             next; #deleted role
                   8404:         }
                   8405:         if (!defined($possible_status)) { 
                   8406:             $sectioncount{$section}++;
                   8407:         } else {
                   8408:             if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
                   8409:                 $status = 'active';
                   8410:             } elsif ($end < $now) {
                   8411:                 $status = 'future';
                   8412:             } elsif ($start > $now) {
                   8413:                 $status = 'previous';
                   8414:             }
                   8415:             if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
                   8416:                 $sectioncount{$section}++;
                   8417:             }
                   8418:         }
1.233     raeburn  8419:     }
1.366     albertel 8420:     return %sectioncount;
1.233     raeburn  8421: }
                   8422: 
1.274     raeburn  8423: ###############################################
1.294     raeburn  8424: 
                   8425: =pod
1.405     albertel 8426: 
                   8427: =item * &get_course_users()
                   8428: 
1.275     raeburn  8429: Retrieves usernames:domains for users in the specified course
                   8430: with specific role(s), and access status. 
                   8431: 
                   8432: Incoming parameters:
1.277     albertel 8433: 1. course domain
                   8434: 2. course number
                   8435: 3. access status: users must have - either active, 
1.275     raeburn  8436: previous, future, or all.
1.277     albertel 8437: 4. reference to array of permissible roles
1.288     raeburn  8438: 5. reference to array of section restrictions (optional)
                   8439: 6. reference to results object (hash of hashes).
                   8440: 7. reference to optional userdata hash
1.609     raeburn  8441: 8. reference to optional statushash
1.630     raeburn  8442: 9. flag if privileged users (except those set to unhide in
                   8443:    course settings) should be excluded    
1.609     raeburn  8444: Keys of top level results hash are roles.
1.275     raeburn  8445: Keys of inner hashes are username:domain, with 
                   8446: values set to access type.
1.288     raeburn  8447: Optional userdata hash returns an array with arguments in the 
                   8448: same order as loncoursedata::get_classlist() for student data.
                   8449: 
1.609     raeburn  8450: Optional statushash returns
                   8451: 
1.288     raeburn  8452: Entries for end, start, section and status are blank because
                   8453: of the possibility of multiple values for non-student roles.
                   8454: 
1.275     raeburn  8455: =cut
1.405     albertel 8456: 
1.275     raeburn  8457: ###############################################
1.405     albertel 8458: 
1.275     raeburn  8459: sub get_course_users {
1.630     raeburn  8460:     my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288     raeburn  8461:     my %idx = ();
1.419     raeburn  8462:     my %seclists;
1.288     raeburn  8463: 
                   8464:     $idx{udom} = &Apache::loncoursedata::CL_SDOM();
                   8465:     $idx{uname} =  &Apache::loncoursedata::CL_SNAME();
                   8466:     $idx{end} = &Apache::loncoursedata::CL_END();
                   8467:     $idx{start} = &Apache::loncoursedata::CL_START();
                   8468:     $idx{id} = &Apache::loncoursedata::CL_ID();
                   8469:     $idx{section} = &Apache::loncoursedata::CL_SECTION();
                   8470:     $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
                   8471:     $idx{status} = &Apache::loncoursedata::CL_STATUS();
                   8472: 
1.290     albertel 8473:     if (grep(/^st$/,@{$roles})) {
1.276     albertel 8474:         my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278     raeburn  8475:         my $now = time;
1.277     albertel 8476:         foreach my $student (keys(%{$classlist})) {
1.288     raeburn  8477:             my $match = 0;
1.412     raeburn  8478:             my $secmatch = 0;
1.419     raeburn  8479:             my $section = $$classlist{$student}[$idx{section}];
1.609     raeburn  8480:             my $status = $$classlist{$student}[$idx{status}];
1.419     raeburn  8481:             if ($section eq '') {
                   8482:                 $section = 'none';
                   8483:             }
1.291     albertel 8484:             if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 8485:                 if (grep(/^all$/,@{$sections})) {
1.412     raeburn  8486:                     $secmatch = 1;
                   8487:                 } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420     albertel 8488:                     if (grep(/^none$/,@{$sections})) {
1.412     raeburn  8489:                         $secmatch = 1;
                   8490:                     }
                   8491:                 } else {  
1.419     raeburn  8492: 		    if (grep(/^\Q$section\E$/,@{$sections})) {
1.412     raeburn  8493: 		        $secmatch = 1;
                   8494:                     }
1.290     albertel 8495: 		}
1.412     raeburn  8496:                 if (!$secmatch) {
                   8497:                     next;
                   8498:                 }
1.419     raeburn  8499:             }
1.275     raeburn  8500:             if (defined($$types{'active'})) {
1.288     raeburn  8501:                 if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275     raeburn  8502:                     push(@{$$users{st}{$student}},'active');
1.288     raeburn  8503:                     $match = 1;
1.275     raeburn  8504:                 }
                   8505:             }
                   8506:             if (defined($$types{'previous'})) {
1.609     raeburn  8507:                 if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275     raeburn  8508:                     push(@{$$users{st}{$student}},'previous');
1.288     raeburn  8509:                     $match = 1;
1.275     raeburn  8510:                 }
                   8511:             }
                   8512:             if (defined($$types{'future'})) {
1.609     raeburn  8513:                 if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275     raeburn  8514:                     push(@{$$users{st}{$student}},'future');
1.288     raeburn  8515:                     $match = 1;
1.275     raeburn  8516:                 }
                   8517:             }
1.609     raeburn  8518:             if ($match) {
                   8519:                 push(@{$seclists{$student}},$section);
                   8520:                 if (ref($userdata) eq 'HASH') {
                   8521:                     $$userdata{$student} = $$classlist{$student};
                   8522:                 }
                   8523:                 if (ref($statushash) eq 'HASH') {
                   8524:                     $statushash->{$student}{'st'}{$section} = $status;
                   8525:                 }
1.288     raeburn  8526:             }
1.275     raeburn  8527:         }
                   8528:     }
1.412     raeburn  8529:     if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439     raeburn  8530:         my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   8531:         my $now = time;
1.609     raeburn  8532:         my %displaystatus = ( previous => 'Expired',
                   8533:                               active   => 'Active',
                   8534:                               future   => 'Future',
                   8535:                             );
1.1075.2.36  raeburn  8536:         my (%nothide,@possdoms);
1.630     raeburn  8537:         if ($hidepriv) {
                   8538:             my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
                   8539:             foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
                   8540:                 if ($user !~ /:/) {
                   8541:                     $nothide{join(':',split(/[\@]/,$user))}=1;
                   8542:                 } else {
                   8543:                     $nothide{$user} = 1;
                   8544:                 }
                   8545:             }
1.1075.2.36  raeburn  8546:             my @possdoms = ($cdom);
                   8547:             if ($coursehash{'checkforpriv'}) {
                   8548:                 push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
                   8549:             }
1.630     raeburn  8550:         }
1.439     raeburn  8551:         foreach my $person (sort(keys(%coursepersonnel))) {
1.288     raeburn  8552:             my $match = 0;
1.412     raeburn  8553:             my $secmatch = 0;
1.439     raeburn  8554:             my $status;
1.412     raeburn  8555:             my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275     raeburn  8556:             $user =~ s/:$//;
1.439     raeburn  8557:             my ($end,$start) = split(/:/,$coursepersonnel{$person});
                   8558:             if ($end == -1 || $start == -1) {
                   8559:                 next;
                   8560:             }
                   8561:             if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
                   8562:                 (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412     raeburn  8563:                 my ($uname,$udom) = split(/:/,$user);
                   8564:                 if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 8565:                     if (grep(/^all$/,@{$sections})) {
1.412     raeburn  8566:                         $secmatch = 1;
                   8567:                     } elsif ($usec eq '') {
1.420     albertel 8568:                         if (grep(/^none$/,@{$sections})) {
1.412     raeburn  8569:                             $secmatch = 1;
                   8570:                         }
                   8571:                     } else {
                   8572:                         if (grep(/^\Q$usec\E$/,@{$sections})) {
                   8573:                             $secmatch = 1;
                   8574:                         }
                   8575:                     }
                   8576:                     if (!$secmatch) {
                   8577:                         next;
                   8578:                     }
1.288     raeburn  8579:                 }
1.419     raeburn  8580:                 if ($usec eq '') {
                   8581:                     $usec = 'none';
                   8582:                 }
1.275     raeburn  8583:                 if ($uname ne '' && $udom ne '') {
1.630     raeburn  8584:                     if ($hidepriv) {
1.1075.2.36  raeburn  8585:                         if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630     raeburn  8586:                             (!$nothide{$uname.':'.$udom})) {
                   8587:                             next;
                   8588:                         }
                   8589:                     }
1.503     raeburn  8590:                     if ($end > 0 && $end < $now) {
1.439     raeburn  8591:                         $status = 'previous';
                   8592:                     } elsif ($start > $now) {
                   8593:                         $status = 'future';
                   8594:                     } else {
                   8595:                         $status = 'active';
                   8596:                     }
1.277     albertel 8597:                     foreach my $type (keys(%{$types})) { 
1.275     raeburn  8598:                         if ($status eq $type) {
1.420     albertel 8599:                             if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419     raeburn  8600:                                 push(@{$$users{$role}{$user}},$type);
                   8601:                             }
1.288     raeburn  8602:                             $match = 1;
                   8603:                         }
                   8604:                     }
1.419     raeburn  8605:                     if (($match) && (ref($userdata) eq 'HASH')) {
                   8606:                         if (!exists($$userdata{$uname.':'.$udom})) {
                   8607: 			    &get_user_info($udom,$uname,\%idx,$userdata);
                   8608:                         }
1.420     albertel 8609:                         if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419     raeburn  8610:                             push(@{$seclists{$uname.':'.$udom}},$usec);
                   8611:                         }
1.609     raeburn  8612:                         if (ref($statushash) eq 'HASH') {
                   8613:                             $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
                   8614:                         }
1.275     raeburn  8615:                     }
                   8616:                 }
                   8617:             }
                   8618:         }
1.290     albertel 8619:         if (grep(/^ow$/,@{$roles})) {
1.279     raeburn  8620:             if ((defined($cdom)) && (defined($cnum))) {
                   8621:                 my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
                   8622:                 if ( defined($csettings{'internal.courseowner'}) ) {
                   8623:                     my $owner = $csettings{'internal.courseowner'};
1.609     raeburn  8624:                     next if ($owner eq '');
                   8625:                     my ($ownername,$ownerdom);
                   8626:                     if ($owner =~ /^([^:]+):([^:]+)$/) {
                   8627:                         $ownername = $1;
                   8628:                         $ownerdom = $2;
                   8629:                     } else {
                   8630:                         $ownername = $owner;
                   8631:                         $ownerdom = $cdom;
                   8632:                         $owner = $ownername.':'.$ownerdom;
1.439     raeburn  8633:                     }
                   8634:                     @{$$users{'ow'}{$owner}} = 'any';
1.290     albertel 8635:                     if (defined($userdata) && 
1.609     raeburn  8636: 			!exists($$userdata{$owner})) {
                   8637: 			&get_user_info($ownerdom,$ownername,\%idx,$userdata);
                   8638:                         if (!grep(/^none$/,@{$seclists{$owner}})) {
                   8639:                             push(@{$seclists{$owner}},'none');
                   8640:                         }
                   8641:                         if (ref($statushash) eq 'HASH') {
                   8642:                             $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419     raeburn  8643:                         }
1.290     albertel 8644: 		    }
1.279     raeburn  8645:                 }
                   8646:             }
                   8647:         }
1.419     raeburn  8648:         foreach my $user (keys(%seclists)) {
                   8649:             @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
                   8650:             $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
                   8651:         }
1.275     raeburn  8652:     }
                   8653:     return;
                   8654: }
                   8655: 
1.288     raeburn  8656: sub get_user_info {
                   8657:     my ($udom,$uname,$idx,$userdata) = @_;
1.289     albertel 8658:     $$userdata{$uname.':'.$udom}[$$idx{fullname}] = 
                   8659: 	&plainname($uname,$udom,'lastname');
1.291     albertel 8660:     $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297     raeburn  8661:     $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609     raeburn  8662:     my %idhash =  &Apache::lonnet::idrget($udom,($uname));
                   8663:     $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname}; 
1.288     raeburn  8664:     return;
                   8665: }
1.275     raeburn  8666: 
1.472     raeburn  8667: ###############################################
                   8668: 
                   8669: =pod
                   8670: 
                   8671: =item * &get_user_quota()
                   8672: 
1.1075.2.41  raeburn  8673: Retrieves quota assigned for storage of user files.
                   8674: Default is to report quota for portfolio files.
1.472     raeburn  8675: 
                   8676: Incoming parameters:
                   8677: 1. user's username
                   8678: 2. user's domain
1.1075.2.41  raeburn  8679: 3. quota name - portfolio, author, or course
                   8680:    (if no quota name provided, defaults to portfolio).
1.1075.2.42  raeburn  8681: 4. crstype - official, unofficial or community, if quota name is
                   8682:    course
1.472     raeburn  8683: 
                   8684: Returns:
1.536     raeburn  8685: 1. Disk quota (in Mb) assigned to student.
                   8686: 2. (Optional) Type of setting: custom or default
                   8687:    (individually assigned or default for user's 
                   8688:    institutional status).
                   8689: 3. (Optional) - User's institutional status (e.g., faculty, staff
                   8690:    or student - types as defined in localenroll::inst_usertypes 
                   8691:    for user's domain, which determines default quota for user.
                   8692: 4. (Optional) - Default quota which would apply to the user.
1.472     raeburn  8693: 
                   8694: If a value has been stored in the user's environment, 
1.536     raeburn  8695: it will return that, otherwise it returns the maximal default
1.1075.2.41  raeburn  8696: defined for the user's institutional status(es) in the domain.
1.472     raeburn  8697: 
                   8698: =cut
                   8699: 
                   8700: ###############################################
                   8701: 
                   8702: 
                   8703: sub get_user_quota {
1.1075.2.42  raeburn  8704:     my ($uname,$udom,$quotaname,$crstype) = @_;
1.536     raeburn  8705:     my ($quota,$quotatype,$settingstatus,$defquota);
1.472     raeburn  8706:     if (!defined($udom)) {
                   8707:         $udom = $env{'user.domain'};
                   8708:     }
                   8709:     if (!defined($uname)) {
                   8710:         $uname = $env{'user.name'};
                   8711:     }
                   8712:     if (($udom eq '' || $uname eq '') ||
                   8713:         ($udom eq 'public') && ($uname eq 'public')) {
                   8714:         $quota = 0;
1.536     raeburn  8715:         $quotatype = 'default';
                   8716:         $defquota = 0; 
1.472     raeburn  8717:     } else {
1.536     raeburn  8718:         my $inststatus;
1.1075.2.41  raeburn  8719:         if ($quotaname eq 'course') {
                   8720:             if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
                   8721:                 ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
                   8722:                 $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
                   8723:             } else {
                   8724:                 my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
                   8725:                 $quota = $cenv{'internal.uploadquota'};
                   8726:             }
1.536     raeburn  8727:         } else {
1.1075.2.41  raeburn  8728:             if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
                   8729:                 if ($quotaname eq 'author') {
                   8730:                     $quota = $env{'environment.authorquota'};
                   8731:                 } else {
                   8732:                     $quota = $env{'environment.portfolioquota'};
                   8733:                 }
                   8734:                 $inststatus = $env{'environment.inststatus'};
                   8735:             } else {
                   8736:                 my %userenv = 
                   8737:                     &Apache::lonnet::get('environment',['portfolioquota',
                   8738:                                          'authorquota','inststatus'],$udom,$uname);
                   8739:                 my ($tmp) = keys(%userenv);
                   8740:                 if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   8741:                     if ($quotaname eq 'author') {
                   8742:                         $quota = $userenv{'authorquota'};
                   8743:                     } else {
                   8744:                         $quota = $userenv{'portfolioquota'};
                   8745:                     }
                   8746:                     $inststatus = $userenv{'inststatus'};
                   8747:                 } else {
                   8748:                     undef(%userenv);
                   8749:                 }
                   8750:             }
                   8751:         }
                   8752:         if ($quota eq '' || wantarray) {
                   8753:             if ($quotaname eq 'course') {
                   8754:                 my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.42  raeburn  8755:                 if (($crstype eq 'official') || ($crstype eq 'unofficial') || ($crstype eq 'community')) {
                   8756:                     $defquota = $domdefs{$crstype.'quota'};
                   8757:                 }
                   8758:                 if ($defquota eq '') {
                   8759:                     $defquota = 500;
                   8760:                 }
1.1075.2.41  raeburn  8761:             } else {
                   8762:                 ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
                   8763:             }
                   8764:             if ($quota eq '') {
                   8765:                 $quota = $defquota;
                   8766:                 $quotatype = 'default';
                   8767:             } else {
                   8768:                 $quotatype = 'custom';
                   8769:             }
1.472     raeburn  8770:         }
                   8771:     }
1.536     raeburn  8772:     if (wantarray) {
                   8773:         return ($quota,$quotatype,$settingstatus,$defquota);
                   8774:     } else {
                   8775:         return $quota;
                   8776:     }
1.472     raeburn  8777: }
                   8778: 
                   8779: ###############################################
                   8780: 
                   8781: =pod
                   8782: 
                   8783: =item * &default_quota()
                   8784: 
1.536     raeburn  8785: Retrieves default quota assigned for storage of user portfolio files,
                   8786: given an (optional) user's institutional status.
1.472     raeburn  8787: 
                   8788: Incoming parameters:
1.1075.2.42  raeburn  8789: 
1.472     raeburn  8790: 1. domain
1.536     raeburn  8791: 2. (Optional) institutional status(es).  This is a : separated list of 
                   8792:    status types (e.g., faculty, staff, student etc.)
                   8793:    which apply to the user for whom the default is being retrieved.
                   8794:    If the institutional status string in undefined, the domain
1.1075.2.41  raeburn  8795:    default quota will be returned.
                   8796: 3.  quota name - portfolio, author, or course
                   8797:    (if no quota name provided, defaults to portfolio).
1.472     raeburn  8798: 
                   8799: Returns:
1.1075.2.42  raeburn  8800: 
1.472     raeburn  8801: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536     raeburn  8802: 2. (Optional) institutional type which determined the value of the
                   8803:    default quota.
1.472     raeburn  8804: 
                   8805: If a value has been stored in the domain's configuration db,
                   8806: it will return that, otherwise it returns 20 (for backwards 
                   8807: compatibility with domains which have not set up a configuration
                   8808: db file; the original statically defined portfolio quota was 20 Mb). 
                   8809: 
1.536     raeburn  8810: If the user's status includes multiple types (e.g., staff and student),
                   8811: the largest default quota which applies to the user determines the
                   8812: default quota returned.
                   8813: 
1.472     raeburn  8814: =cut
                   8815: 
                   8816: ###############################################
                   8817: 
                   8818: 
                   8819: sub default_quota {
1.1075.2.41  raeburn  8820:     my ($udom,$inststatus,$quotaname) = @_;
1.536     raeburn  8821:     my ($defquota,$settingstatus);
                   8822:     my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622     raeburn  8823:                                             ['quotas'],$udom);
1.1075.2.41  raeburn  8824:     my $key = 'defaultquota';
                   8825:     if ($quotaname eq 'author') {
                   8826:         $key = 'authorquota';
                   8827:     }
1.622     raeburn  8828:     if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536     raeburn  8829:         if ($inststatus ne '') {
1.765     raeburn  8830:             my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536     raeburn  8831:             foreach my $item (@statuses) {
1.1075.2.41  raeburn  8832:                 if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
                   8833:                     if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711     raeburn  8834:                         if ($defquota eq '') {
1.1075.2.41  raeburn  8835:                             $defquota = $quotahash{'quotas'}{$key}{$item};
1.711     raeburn  8836:                             $settingstatus = $item;
1.1075.2.41  raeburn  8837:                         } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
                   8838:                             $defquota = $quotahash{'quotas'}{$key}{$item};
1.711     raeburn  8839:                             $settingstatus = $item;
                   8840:                         }
                   8841:                     }
1.1075.2.41  raeburn  8842:                 } elsif ($key eq 'defaultquota') {
1.711     raeburn  8843:                     if ($quotahash{'quotas'}{$item} ne '') {
                   8844:                         if ($defquota eq '') {
                   8845:                             $defquota = $quotahash{'quotas'}{$item};
                   8846:                             $settingstatus = $item;
                   8847:                         } elsif ($quotahash{'quotas'}{$item} > $defquota) {
                   8848:                             $defquota = $quotahash{'quotas'}{$item};
                   8849:                             $settingstatus = $item;
                   8850:                         }
1.536     raeburn  8851:                     }
                   8852:                 }
                   8853:             }
                   8854:         }
                   8855:         if ($defquota eq '') {
1.1075.2.41  raeburn  8856:             if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
                   8857:                 $defquota = $quotahash{'quotas'}{$key}{'default'};
                   8858:             } elsif ($key eq 'defaultquota') {
1.711     raeburn  8859:                 $defquota = $quotahash{'quotas'}{'default'};
                   8860:             }
1.536     raeburn  8861:             $settingstatus = 'default';
1.1075.2.42  raeburn  8862:             if ($defquota eq '') {
                   8863:                 if ($quotaname eq 'author') {
                   8864:                     $defquota = 500;
                   8865:                 }
                   8866:             }
1.536     raeburn  8867:         }
                   8868:     } else {
                   8869:         $settingstatus = 'default';
1.1075.2.41  raeburn  8870:         if ($quotaname eq 'author') {
                   8871:             $defquota = 500;
                   8872:         } else {
                   8873:             $defquota = 20;
                   8874:         }
1.536     raeburn  8875:     }
                   8876:     if (wantarray) {
                   8877:         return ($defquota,$settingstatus);
1.472     raeburn  8878:     } else {
1.536     raeburn  8879:         return $defquota;
1.472     raeburn  8880:     }
                   8881: }
                   8882: 
1.1075.2.41  raeburn  8883: ###############################################
                   8884: 
                   8885: =pod
                   8886: 
1.1075.2.42  raeburn  8887: =item * &excess_filesize_warning()
1.1075.2.41  raeburn  8888: 
                   8889: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42  raeburn  8890: of existing file within authoring space will cause quota for the authoring
                   8891: space to be exceeded.
                   8892: 
                   8893: Same, if upload of a file directly to a course/community via Course Editor
                   8894: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41  raeburn  8895: 
                   8896: Inputs: 6
1.1075.2.42  raeburn  8897: 1. username or coursenum
1.1075.2.41  raeburn  8898: 2. domain
1.1075.2.42  raeburn  8899: 3. context ('author' or 'course')
1.1075.2.41  raeburn  8900: 4. filename of file for which action is being requested
                   8901: 5. filesize (kB) of file
                   8902: 6. action being taken: copy or upload.
                   8903: 
                   8904: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
                   8905:          otherwise return null.
                   8906: 
1.1075.2.42  raeburn  8907: =back
                   8908: 
1.1075.2.41  raeburn  8909: =cut
                   8910: 
1.1075.2.42  raeburn  8911: sub excess_filesize_warning {
                   8912:     my ($uname,$udom,$context,$filename,$filesize,$action) = @_;
                   8913:     my $current_disk_usage = 0;
                   8914:     my $disk_quota = &get_user_quota($uname,$udom,$context); #expressed in MB
                   8915:     if ($context eq 'author') {
                   8916:         my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
                   8917:         $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
                   8918:     } else {
                   8919:         foreach my $subdir ('docs','supplemental') {
                   8920:             $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
                   8921:         }
                   8922:     }
1.1075.2.41  raeburn  8923:     $disk_quota = int($disk_quota * 1000);
                   8924:     if (($current_disk_usage + $filesize) > $disk_quota) {
                   8925:         return '<p><span class="LC_warning">'.
                   8926:                 &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
                   8927:                     '<span class="LC_filename">'.$filename.'</span>',$filesize).'</span>'.
                   8928:                '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
                   8929:                             $disk_quota,$current_disk_usage).
                   8930:                '</p>';
                   8931:     }
                   8932:     return;
                   8933: }
                   8934: 
                   8935: ###############################################
                   8936: 
                   8937: 
1.384     raeburn  8938: sub get_secgrprole_info {
                   8939:     my ($cdom,$cnum,$needroles,$type)  = @_;
                   8940:     my %sections_count = &get_sections($cdom,$cnum);
                   8941:     my @sections =  (sort {$a <=> $b} keys(%sections_count));
                   8942:     my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
                   8943:     my @groups = sort(keys(%curr_groups));
                   8944:     my $allroles = [];
                   8945:     my $rolehash;
                   8946:     my $accesshash = {
                   8947:                      active => 'Currently has access',
                   8948:                      future => 'Will have future access',
                   8949:                      previous => 'Previously had access',
                   8950:                   };
                   8951:     if ($needroles) {
                   8952:         $rolehash = {'all' => 'all'};
1.385     albertel 8953:         my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   8954: 	if (&Apache::lonnet::error(%user_roles)) {
                   8955: 	    undef(%user_roles);
                   8956: 	}
                   8957:         foreach my $item (keys(%user_roles)) {
1.384     raeburn  8958:             my ($role)=split(/\:/,$item,2);
                   8959:             if ($role eq 'cr') { next; }
                   8960:             if ($role =~ /^cr/) {
                   8961:                 $$rolehash{$role} = (split('/',$role))[3];
                   8962:             } else {
                   8963:                 $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
                   8964:             }
                   8965:         }
                   8966:         foreach my $key (sort(keys(%{$rolehash}))) {
                   8967:             push(@{$allroles},$key);
                   8968:         }
                   8969:         push (@{$allroles},'st');
                   8970:         $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
                   8971:     }
                   8972:     return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
                   8973: }
                   8974: 
1.555     raeburn  8975: sub user_picker {
1.994     raeburn  8976:     my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555     raeburn  8977:     my $currdom = $dom;
                   8978:     my %curr_selected = (
                   8979:                         srchin => 'dom',
1.580     raeburn  8980:                         srchby => 'lastname',
1.555     raeburn  8981:                       );
                   8982:     my $srchterm;
1.625     raeburn  8983:     if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555     raeburn  8984:         if ($srch->{'srchby'} ne '') {
                   8985:             $curr_selected{'srchby'} = $srch->{'srchby'};
                   8986:         }
                   8987:         if ($srch->{'srchin'} ne '') {
                   8988:             $curr_selected{'srchin'} = $srch->{'srchin'};
                   8989:         }
                   8990:         if ($srch->{'srchtype'} ne '') {
                   8991:             $curr_selected{'srchtype'} = $srch->{'srchtype'};
                   8992:         }
                   8993:         if ($srch->{'srchdomain'} ne '') {
                   8994:             $currdom = $srch->{'srchdomain'};
                   8995:         }
                   8996:         $srchterm = $srch->{'srchterm'};
                   8997:     }
                   8998:     my %lt=&Apache::lonlocal::texthash(
1.573     raeburn  8999:                     'usr'       => 'Search criteria',
1.563     raeburn  9000:                     'doma'      => 'Domain/institution to search',
1.558     albertel 9001:                     'uname'     => 'username',
                   9002:                     'lastname'  => 'last name',
1.555     raeburn  9003:                     'lastfirst' => 'last name, first name',
1.558     albertel 9004:                     'crs'       => 'in this course',
1.576     raeburn  9005:                     'dom'       => 'in selected LON-CAPA domain', 
1.558     albertel 9006:                     'alc'       => 'all LON-CAPA',
1.573     raeburn  9007:                     'instd'     => 'in institutional directory for selected domain',
1.558     albertel 9008:                     'exact'     => 'is',
                   9009:                     'contains'  => 'contains',
1.569     raeburn  9010:                     'begins'    => 'begins with',
1.571     raeburn  9011:                     'youm'      => "You must include some text to search for.",
                   9012:                     'thte'      => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
                   9013:                     'thet'      => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
                   9014:                     'yomc'      => "You must choose a domain when using an institutional directory search.",
                   9015:                     'ymcd'      => "You must choose a domain when using a domain search.",
                   9016:                     'whus'      => "When using searching by last,first you must include a comma as separator between last name and first name.",
                   9017:                     'whse'      => "When searching by last,first you must include at least one character in the first name.",
                   9018:                      'thfo'     => "The following need to be corrected before the search can be run:",
1.555     raeburn  9019:                                        );
1.563     raeburn  9020:     my $domform = &select_dom_form($currdom,'srchdomain',1,1);
                   9021:     my $srchinsel = ' <select name="srchin">';
1.555     raeburn  9022: 
                   9023:     my @srchins = ('crs','dom','alc','instd');
                   9024: 
                   9025:     foreach my $option (@srchins) {
                   9026:         # FIXME 'alc' option unavailable until 
                   9027:         #       loncreateuser::print_user_query_page()
                   9028:         #       has been completed.
                   9029:         next if ($option eq 'alc');
1.880     raeburn  9030:         next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));  
1.555     raeburn  9031:         next if ($option eq 'crs' && !$env{'request.course.id'});
1.563     raeburn  9032:         if ($curr_selected{'srchin'} eq $option) {
                   9033:             $srchinsel .= ' 
                   9034:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   9035:         } else {
                   9036:             $srchinsel .= '
                   9037:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   9038:         }
1.555     raeburn  9039:     }
1.563     raeburn  9040:     $srchinsel .= "\n  </select>\n";
1.555     raeburn  9041: 
                   9042:     my $srchbysel =  ' <select name="srchby">';
1.580     raeburn  9043:     foreach my $option ('lastname','lastfirst','uname') {
1.555     raeburn  9044:         if ($curr_selected{'srchby'} eq $option) {
                   9045:             $srchbysel .= '
                   9046:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   9047:         } else {
                   9048:             $srchbysel .= '
                   9049:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   9050:          }
                   9051:     }
                   9052:     $srchbysel .= "\n  </select>\n";
                   9053: 
                   9054:     my $srchtypesel = ' <select name="srchtype">';
1.580     raeburn  9055:     foreach my $option ('begins','contains','exact') {
1.555     raeburn  9056:         if ($curr_selected{'srchtype'} eq $option) {
                   9057:             $srchtypesel .= '
                   9058:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   9059:         } else {
                   9060:             $srchtypesel .= '
                   9061:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   9062:         }
                   9063:     }
                   9064:     $srchtypesel .= "\n  </select>\n";
                   9065: 
1.558     albertel 9066:     my ($newuserscript,$new_user_create);
1.994     raeburn  9067:     my $context_dom = $env{'request.role.domain'};
                   9068:     if ($context eq 'requestcrs') {
                   9069:         if ($env{'form.coursedom'} ne '') { 
                   9070:             $context_dom = $env{'form.coursedom'};
                   9071:         }
                   9072:     }
1.556     raeburn  9073:     if ($forcenewuser) {
1.576     raeburn  9074:         if (ref($srch) eq 'HASH') {
1.994     raeburn  9075:             if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627     raeburn  9076:                 if ($cancreate) {
                   9077:                     $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>';
                   9078:                 } else {
1.799     bisitz   9079:                     my $helplink = 'javascript:helpMenu('."'display'".')';
1.627     raeburn  9080:                     my %usertypetext = (
                   9081:                         official   => 'institutional',
                   9082:                         unofficial => 'non-institutional',
                   9083:                     );
1.799     bisitz   9084:                     $new_user_create = '<p class="LC_warning">'
                   9085:                                       .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
                   9086:                                       .' '
                   9087:                                       .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
                   9088:                                           ,'<a href="'.$helplink.'">','</a>')
                   9089:                                       .'</p><br />';
1.627     raeburn  9090:                 }
1.576     raeburn  9091:             }
                   9092:         }
                   9093: 
1.556     raeburn  9094:         $newuserscript = <<"ENDSCRIPT";
                   9095: 
1.570     raeburn  9096: function setSearch(createnew,callingForm) {
1.556     raeburn  9097:     if (createnew == 1) {
1.570     raeburn  9098:         for (var i=0; i<callingForm.srchby.length; i++) {
                   9099:             if (callingForm.srchby.options[i].value == 'uname') {
                   9100:                 callingForm.srchby.selectedIndex = i;
1.556     raeburn  9101:             }
                   9102:         }
1.570     raeburn  9103:         for (var i=0; i<callingForm.srchin.length; i++) {
                   9104:             if ( callingForm.srchin.options[i].value == 'dom') {
                   9105: 		callingForm.srchin.selectedIndex = i;
1.556     raeburn  9106:             }
                   9107:         }
1.570     raeburn  9108:         for (var i=0; i<callingForm.srchtype.length; i++) {
                   9109:             if (callingForm.srchtype.options[i].value == 'exact') {
                   9110:                 callingForm.srchtype.selectedIndex = i;
1.556     raeburn  9111:             }
                   9112:         }
1.570     raeburn  9113:         for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994     raeburn  9114:             if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570     raeburn  9115:                 callingForm.srchdomain.selectedIndex = i;
1.556     raeburn  9116:             }
                   9117:         }
                   9118:     }
                   9119: }
                   9120: ENDSCRIPT
1.558     albertel 9121: 
1.556     raeburn  9122:     }
                   9123: 
1.555     raeburn  9124:     my $output = <<"END_BLOCK";
1.556     raeburn  9125: <script type="text/javascript">
1.824     bisitz   9126: // <![CDATA[
1.570     raeburn  9127: function validateEntry(callingForm) {
1.558     albertel 9128: 
1.556     raeburn  9129:     var checkok = 1;
1.558     albertel 9130:     var srchin;
1.570     raeburn  9131:     for (var i=0; i<callingForm.srchin.length; i++) {
                   9132: 	if ( callingForm.srchin[i].checked ) {
                   9133: 	    srchin = callingForm.srchin[i].value;
1.558     albertel 9134: 	}
                   9135:     }
                   9136: 
1.570     raeburn  9137:     var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
                   9138:     var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
                   9139:     var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
                   9140:     var srchterm =  callingForm.srchterm.value;
                   9141:     var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556     raeburn  9142:     var msg = "";
                   9143: 
                   9144:     if (srchterm == "") {
                   9145:         checkok = 0;
1.571     raeburn  9146:         msg += "$lt{'youm'}\\n";
1.556     raeburn  9147:     }
                   9148: 
1.569     raeburn  9149:     if (srchtype== 'begins') {
                   9150:         if (srchterm.length < 2) {
                   9151:             checkok = 0;
1.571     raeburn  9152:             msg += "$lt{'thte'}\\n";
1.569     raeburn  9153:         }
                   9154:     }
                   9155: 
1.556     raeburn  9156:     if (srchtype== 'contains') {
                   9157:         if (srchterm.length < 3) {
                   9158:             checkok = 0;
1.571     raeburn  9159:             msg += "$lt{'thet'}\\n";
1.556     raeburn  9160:         }
                   9161:     }
                   9162:     if (srchin == 'instd') {
                   9163:         if (srchdomain == '') {
                   9164:             checkok = 0;
1.571     raeburn  9165:             msg += "$lt{'yomc'}\\n";
1.556     raeburn  9166:         }
                   9167:     }
                   9168:     if (srchin == 'dom') {
                   9169:         if (srchdomain == '') {
                   9170:             checkok = 0;
1.571     raeburn  9171:             msg += "$lt{'ymcd'}\\n";
1.556     raeburn  9172:         }
                   9173:     }
                   9174:     if (srchby == 'lastfirst') {
                   9175:         if (srchterm.indexOf(",") == -1) {
                   9176:             checkok = 0;
1.571     raeburn  9177:             msg += "$lt{'whus'}\\n";
1.556     raeburn  9178:         }
                   9179:         if (srchterm.indexOf(",") == srchterm.length -1) {
                   9180:             checkok = 0;
1.571     raeburn  9181:             msg += "$lt{'whse'}\\n";
1.556     raeburn  9182:         }
                   9183:     }
                   9184:     if (checkok == 0) {
1.571     raeburn  9185:         alert("$lt{'thfo'}\\n"+msg);
1.556     raeburn  9186:         return;
                   9187:     }
                   9188:     if (checkok == 1) {
1.570     raeburn  9189:         callingForm.submit();
1.556     raeburn  9190:     }
                   9191: }
                   9192: 
                   9193: $newuserscript
                   9194: 
1.824     bisitz   9195: // ]]>
1.556     raeburn  9196: </script>
1.558     albertel 9197: 
                   9198: $new_user_create
                   9199: 
1.555     raeburn  9200: END_BLOCK
1.558     albertel 9201: 
1.876     raeburn  9202:     $output .= &Apache::lonhtmlcommon::start_pick_box().
                   9203:                &Apache::lonhtmlcommon::row_title($lt{'doma'}).
                   9204:                $domform.
                   9205:                &Apache::lonhtmlcommon::row_closure().
                   9206:                &Apache::lonhtmlcommon::row_title($lt{'usr'}).
                   9207:                $srchbysel.
                   9208:                $srchtypesel. 
                   9209:                '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
                   9210:                $srchinsel.
                   9211:                &Apache::lonhtmlcommon::row_closure(1). 
                   9212:                &Apache::lonhtmlcommon::end_pick_box().
                   9213:                '<br />';
1.555     raeburn  9214:     return $output;
                   9215: }
                   9216: 
1.612     raeburn  9217: sub user_rule_check {
1.615     raeburn  9218:     my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612     raeburn  9219:     my $response;
                   9220:     if (ref($usershash) eq 'HASH') {
                   9221:         foreach my $user (keys(%{$usershash})) {
                   9222:             my ($uname,$udom) = split(/:/,$user);
                   9223:             next if ($udom eq '' || $uname eq '');
1.615     raeburn  9224:             my ($id,$newuser);
1.612     raeburn  9225:             if (ref($usershash->{$user}) eq 'HASH') {
1.615     raeburn  9226:                 $newuser = $usershash->{$user}->{'newuser'};
1.612     raeburn  9227:                 $id = $usershash->{$user}->{'id'};
                   9228:             }
                   9229:             my $inst_response;
                   9230:             if (ref($checks) eq 'HASH') {
                   9231:                 if (defined($checks->{'username'})) {
1.615     raeburn  9232:                     ($inst_response,%{$inst_results->{$user}}) = 
1.612     raeburn  9233:                         &Apache::lonnet::get_instuser($udom,$uname);
                   9234:                 } elsif (defined($checks->{'id'})) {
1.615     raeburn  9235:                     ($inst_response,%{$inst_results->{$user}}) =
1.612     raeburn  9236:                         &Apache::lonnet::get_instuser($udom,undef,$id);
                   9237:                 }
1.615     raeburn  9238:             } else {
                   9239:                 ($inst_response,%{$inst_results->{$user}}) =
                   9240:                     &Apache::lonnet::get_instuser($udom,$uname);
                   9241:                 return;
1.612     raeburn  9242:             }
1.615     raeburn  9243:             if (!$got_rules->{$udom}) {
1.612     raeburn  9244:                 my %domconfig = &Apache::lonnet::get_dom('configuration',
                   9245:                                                   ['usercreation'],$udom);
                   9246:                 if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615     raeburn  9247:                     foreach my $item ('username','id') {
1.612     raeburn  9248:                         if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
                   9249:                             $$curr_rules{$udom}{$item} = 
                   9250:                                 $domconfig{'usercreation'}{$item.'_rule'};
1.585     raeburn  9251:                         }
                   9252:                     }
                   9253:                 }
1.615     raeburn  9254:                 $got_rules->{$udom} = 1;  
1.585     raeburn  9255:             }
1.612     raeburn  9256:             foreach my $item (keys(%{$checks})) {
                   9257:                 if (ref($$curr_rules{$udom}) eq 'HASH') {
                   9258:                     if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
                   9259:                         if (@{$$curr_rules{$udom}{$item}} > 0) {
                   9260:                             my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
                   9261:                             foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
                   9262:                                 if ($rule_check{$rule}) {
                   9263:                                     $$rulematch{$user}{$item} = $rule;
                   9264:                                     if ($inst_response eq 'ok') {
1.615     raeburn  9265:                                         if (ref($inst_results) eq 'HASH') {
                   9266:                                             if (ref($inst_results->{$user}) eq 'HASH') {
                   9267:                                                 if (keys(%{$inst_results->{$user}}) == 0) {
                   9268:                                                     $$alerts{$item}{$udom}{$uname} = 1;
                   9269:                                                 }
1.612     raeburn  9270:                                             }
                   9271:                                         }
1.615     raeburn  9272:                                     }
                   9273:                                     last;
1.585     raeburn  9274:                                 }
                   9275:                             }
                   9276:                         }
                   9277:                     }
                   9278:                 }
                   9279:             }
                   9280:         }
                   9281:     }
1.612     raeburn  9282:     return;
                   9283: }
                   9284: 
                   9285: sub user_rule_formats {
                   9286:     my ($domain,$domdesc,$curr_rules,$check) = @_;
                   9287:     my %text = ( 
                   9288:                  'username' => 'Usernames',
                   9289:                  'id'       => 'IDs',
                   9290:                );
                   9291:     my $output;
                   9292:     my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
                   9293:     if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
                   9294:         if (@{$ruleorder} > 0) {
1.1075.2.20  raeburn  9295:             $output = '<br />'.
                   9296:                       &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
                   9297:                           '<span class="LC_cusr_emph">','</span>',$domdesc).
                   9298:                       ' <ul>';
1.612     raeburn  9299:             foreach my $rule (@{$ruleorder}) {
                   9300:                 if (ref($curr_rules) eq 'ARRAY') {
                   9301:                     if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
                   9302:                         if (ref($rules->{$rule}) eq 'HASH') {
                   9303:                             $output .= '<li>'.$rules->{$rule}{'name'}.': '.
                   9304:                                         $rules->{$rule}{'desc'}.'</li>';
                   9305:                         }
                   9306:                     }
                   9307:                 }
                   9308:             }
                   9309:             $output .= '</ul>';
                   9310:         }
                   9311:     }
                   9312:     return $output;
                   9313: }
                   9314: 
                   9315: sub instrule_disallow_msg {
1.615     raeburn  9316:     my ($checkitem,$domdesc,$count,$mode) = @_;
1.612     raeburn  9317:     my $response;
                   9318:     my %text = (
                   9319:                   item   => 'username',
                   9320:                   items  => 'usernames',
                   9321:                   match  => 'matches',
                   9322:                   do     => 'does',
                   9323:                   action => 'a username',
                   9324:                   one    => 'one',
                   9325:                );
                   9326:     if ($count > 1) {
                   9327:         $text{'item'} = 'usernames';
                   9328:         $text{'match'} ='match';
                   9329:         $text{'do'} = 'do';
                   9330:         $text{'action'} = 'usernames',
                   9331:         $text{'one'} = 'ones';
                   9332:     }
                   9333:     if ($checkitem eq 'id') {
                   9334:         $text{'items'} = 'IDs';
                   9335:         $text{'item'} = 'ID';
                   9336:         $text{'action'} = 'an ID';
1.615     raeburn  9337:         if ($count > 1) {
                   9338:             $text{'item'} = 'IDs';
                   9339:             $text{'action'} = 'IDs';
                   9340:         }
1.612     raeburn  9341:     }
1.674     bisitz   9342:     $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  9343:     if ($mode eq 'upload') {
                   9344:         if ($checkitem eq 'username') {
                   9345:             $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'}.");
                   9346:         } elsif ($checkitem eq 'id') {
1.674     bisitz   9347:             $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  9348:         }
1.669     raeburn  9349:     } elsif ($mode eq 'selfcreate') {
                   9350:         if ($checkitem eq 'id') {
                   9351:             $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.");
                   9352:         }
1.615     raeburn  9353:     } else {
                   9354:         if ($checkitem eq 'username') {
                   9355:             $response .= &mt("You must choose $text{'action'} with a different format --  $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
                   9356:         } elsif ($checkitem eq 'id') {
                   9357:             $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.");
                   9358:         }
1.612     raeburn  9359:     }
                   9360:     return $response;
1.585     raeburn  9361: }
                   9362: 
1.624     raeburn  9363: sub personal_data_fieldtitles {
                   9364:     my %fieldtitles = &Apache::lonlocal::texthash (
                   9365:                         id => 'Student/Employee ID',
                   9366:                         permanentemail => 'E-mail address',
                   9367:                         lastname => 'Last Name',
                   9368:                         firstname => 'First Name',
                   9369:                         middlename => 'Middle Name',
                   9370:                         generation => 'Generation',
                   9371:                         gen => 'Generation',
1.765     raeburn  9372:                         inststatus => 'Affiliation',
1.624     raeburn  9373:                    );
                   9374:     return %fieldtitles;
                   9375: }
                   9376: 
1.642     raeburn  9377: sub sorted_inst_types {
                   9378:     my ($dom) = @_;
                   9379:     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
                   9380:     my $othertitle = &mt('All users');
                   9381:     if ($env{'request.course.id'}) {
1.668     raeburn  9382:         $othertitle  = &mt('Any users');
1.642     raeburn  9383:     }
                   9384:     my @types;
                   9385:     if (ref($order) eq 'ARRAY') {
                   9386:         @types = @{$order};
                   9387:     }
                   9388:     if (@types == 0) {
                   9389:         if (ref($usertypes) eq 'HASH') {
                   9390:             @types = sort(keys(%{$usertypes}));
                   9391:         }
                   9392:     }
                   9393:     if (keys(%{$usertypes}) > 0) {
                   9394:         $othertitle = &mt('Other users');
                   9395:     }
                   9396:     return ($othertitle,$usertypes,\@types);
                   9397: }
                   9398: 
1.645     raeburn  9399: sub get_institutional_codes {
                   9400:     my ($settings,$allcourses,$LC_code) = @_;
                   9401: # Get complete list of course sections to update
                   9402:     my @currsections = ();
                   9403:     my @currxlists = ();
                   9404:     my $coursecode = $$settings{'internal.coursecode'};
                   9405: 
                   9406:     if ($$settings{'internal.sectionnums'} ne '') {
                   9407:         @currsections = split(/,/,$$settings{'internal.sectionnums'});
                   9408:     }
                   9409: 
                   9410:     if ($$settings{'internal.crosslistings'} ne '') {
                   9411:         @currxlists = split(/,/,$$settings{'internal.crosslistings'});
                   9412:     }
                   9413: 
                   9414:     if (@currxlists > 0) {
                   9415:         foreach (@currxlists) {
                   9416:             if (m/^([^:]+):(\w*)$/) {
                   9417:                 unless (grep/^$1$/,@{$allcourses}) {
                   9418:                     push @{$allcourses},$1;
                   9419:                     $$LC_code{$1} = $2;
                   9420:                 }
                   9421:             }
                   9422:         }
                   9423:     }
                   9424:  
                   9425:     if (@currsections > 0) {
                   9426:         foreach (@currsections) {
                   9427:             if (m/^(\w+):(\w*)$/) {
                   9428:                 my $sec = $coursecode.$1;
                   9429:                 my $lc_sec = $2;
                   9430:                 unless (grep/^$sec$/,@{$allcourses}) {
                   9431:                     push @{$allcourses},$sec;
                   9432:                     $$LC_code{$sec} = $lc_sec;
                   9433:                 }
                   9434:             }
                   9435:         }
                   9436:     }
                   9437:     return;
                   9438: }
                   9439: 
1.971     raeburn  9440: sub get_standard_codeitems {
                   9441:     return ('Year','Semester','Department','Number','Section');
                   9442: }
                   9443: 
1.112     bowersj2 9444: =pod
                   9445: 
1.780     raeburn  9446: =head1 Slot Helpers
                   9447: 
                   9448: =over 4
                   9449: 
                   9450: =item * sorted_slots()
                   9451: 
1.1040    raeburn  9452: Sorts an array of slot names in order of an optional sort key,
                   9453: default sort is by slot start time (earliest first). 
1.780     raeburn  9454: 
                   9455: Inputs:
                   9456: 
                   9457: =over 4
                   9458: 
                   9459: slotsarr  - Reference to array of unsorted slot names.
                   9460: 
                   9461: slots     - Reference to hash of hash, where outer hash keys are slot names.
                   9462: 
1.1040    raeburn  9463: sortkey   - Name of key in inner hash to be sorted on (e.g., starttime).
                   9464: 
1.549     albertel 9465: =back
                   9466: 
1.780     raeburn  9467: Returns:
                   9468: 
                   9469: =over 4
                   9470: 
1.1040    raeburn  9471: sorted   - An array of slot names sorted by a specified sort key 
                   9472:            (default sort key is start time of the slot).
1.780     raeburn  9473: 
                   9474: =back
                   9475: 
                   9476: =cut
                   9477: 
                   9478: 
                   9479: sub sorted_slots {
1.1040    raeburn  9480:     my ($slotsarr,$slots,$sortkey) = @_;
                   9481:     if ($sortkey eq '') {
                   9482:         $sortkey = 'starttime';
                   9483:     }
1.780     raeburn  9484:     my @sorted;
                   9485:     if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
                   9486:         @sorted =
                   9487:             sort {
                   9488:                      if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040    raeburn  9489:                          return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780     raeburn  9490:                      }
                   9491:                      if (ref($slots->{$a})) { return -1;}
                   9492:                      if (ref($slots->{$b})) { return 1;}
                   9493:                      return 0;
                   9494:                  } @{$slotsarr};
                   9495:     }
                   9496:     return @sorted;
                   9497: }
                   9498: 
1.1040    raeburn  9499: =pod
                   9500: 
                   9501: =item * get_future_slots()
                   9502: 
                   9503: Inputs:
                   9504: 
                   9505: =over 4
                   9506: 
                   9507: cnum - course number
                   9508: 
                   9509: cdom - course domain
                   9510: 
                   9511: now - current UNIX time
                   9512: 
                   9513: symb - optional symb
                   9514: 
                   9515: =back
                   9516: 
                   9517: Returns:
                   9518: 
                   9519: =over 4
                   9520: 
                   9521: sorted_reservable - ref to array of student_schedulable slots currently 
                   9522:                     reservable, ordered by end date of reservation period.
                   9523: 
                   9524: reservable_now - ref to hash of student_schedulable slots currently
                   9525:                  reservable.
                   9526: 
                   9527:     Keys in inner hash are:
                   9528:     (a) symb: either blank or symb to which slot use is restricted.
                   9529:     (b) endreserve: end date of reservation period. 
                   9530: 
                   9531: sorted_future - ref to array of student_schedulable slots reservable in
                   9532:                 the future, ordered by start date of reservation period.
                   9533: 
                   9534: future_reservable - ref to hash of student_schedulable slots reservable
                   9535:                     in the future.
                   9536: 
                   9537:     Keys in inner hash are:
                   9538:     (a) symb: either blank or symb to which slot use is restricted.
                   9539:     (b) startreserve:  start date of reservation period.
                   9540: 
                   9541: =back
                   9542: 
                   9543: =cut
                   9544: 
                   9545: sub get_future_slots {
                   9546:     my ($cnum,$cdom,$now,$symb) = @_;
                   9547:     my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
                   9548:     my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
                   9549:     foreach my $slot (keys(%slots)) {
                   9550:         next unless($slots{$slot}->{'type'} eq 'schedulable_student');
                   9551:         if ($symb) {
                   9552:             next if (($slots{$slot}->{'symb'} ne '') && 
                   9553:                      ($slots{$slot}->{'symb'} ne $symb));
                   9554:         }
                   9555:         if (($slots{$slot}->{'starttime'} > $now) &&
                   9556:             ($slots{$slot}->{'endtime'} > $now)) {
                   9557:             if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
                   9558:                 my $userallowed = 0;
                   9559:                 if ($slots{$slot}->{'allowedsections'}) {
                   9560:                     my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
                   9561:                     if (!defined($env{'request.role.sec'})
                   9562:                         && grep(/^No section assigned$/,@allowed_sec)) {
                   9563:                         $userallowed=1;
                   9564:                     } else {
                   9565:                         if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
                   9566:                             $userallowed=1;
                   9567:                         }
                   9568:                     }
                   9569:                     unless ($userallowed) {
                   9570:                         if (defined($env{'request.course.groups'})) {
                   9571:                             my @groups = split(/:/,$env{'request.course.groups'});
                   9572:                             foreach my $group (@groups) {
                   9573:                                 if (grep(/^\Q$group\E$/,@allowed_sec)) {
                   9574:                                     $userallowed=1;
                   9575:                                     last;
                   9576:                                 }
                   9577:                             }
                   9578:                         }
                   9579:                     }
                   9580:                 }
                   9581:                 if ($slots{$slot}->{'allowedusers'}) {
                   9582:                     my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
                   9583:                     my $user = $env{'user.name'}.':'.$env{'user.domain'};
                   9584:                     if (grep(/^\Q$user\E$/,@allowed_users)) {
                   9585:                         $userallowed = 1;
                   9586:                     }
                   9587:                 }
                   9588:                 next unless($userallowed);
                   9589:             }
                   9590:             my $startreserve = $slots{$slot}->{'startreserve'};
                   9591:             my $endreserve = $slots{$slot}->{'endreserve'};
                   9592:             my $symb = $slots{$slot}->{'symb'};
                   9593:             if (($startreserve < $now) &&
                   9594:                 (!$endreserve || $endreserve > $now)) {
                   9595:                 my $lastres = $endreserve;
                   9596:                 if (!$lastres) {
                   9597:                     $lastres = $slots{$slot}->{'starttime'};
                   9598:                 }
                   9599:                 $reservable_now{$slot} = {
                   9600:                                            symb       => $symb,
                   9601:                                            endreserve => $lastres
                   9602:                                          };
                   9603:             } elsif (($startreserve > $now) &&
                   9604:                      (!$endreserve || $endreserve > $startreserve)) {
                   9605:                 $future_reservable{$slot} = {
                   9606:                                               symb         => $symb,
                   9607:                                               startreserve => $startreserve
                   9608:                                             };
                   9609:             }
                   9610:         }
                   9611:     }
                   9612:     my @unsorted_reservable = keys(%reservable_now);
                   9613:     if (@unsorted_reservable > 0) {
                   9614:         @sorted_reservable = 
                   9615:             &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
                   9616:     }
                   9617:     my @unsorted_future = keys(%future_reservable);
                   9618:     if (@unsorted_future > 0) {
                   9619:         @sorted_future =
                   9620:             &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
                   9621:     }
                   9622:     return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
                   9623: }
1.780     raeburn  9624: 
                   9625: =pod
                   9626: 
1.1057    foxr     9627: =back
                   9628: 
1.549     albertel 9629: =head1 HTTP Helpers
                   9630: 
                   9631: =over 4
                   9632: 
1.648     raeburn  9633: =item * &get_unprocessed_cgi($query,$possible_names)
1.112     bowersj2 9634: 
1.258     albertel 9635: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112     bowersj2 9636: $query.  The parameters listed in $possible_names (an array reference),
1.258     albertel 9637: will be set in $env{'form.name'} if they do not already exist.
1.112     bowersj2 9638: 
                   9639: Typically called with $ENV{'QUERY_STRING'} as the first parameter.  
                   9640: $possible_names is an ref to an array of form element names.  As an example:
                   9641: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258     albertel 9642: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112     bowersj2 9643: 
                   9644: =cut
1.1       albertel 9645: 
1.6       albertel 9646: sub get_unprocessed_cgi {
1.25      albertel 9647:   my ($query,$possible_names)= @_;
1.26      matthew  9648:   # $Apache::lonxml::debug=1;
1.356     albertel 9649:   foreach my $pair (split(/&/,$query)) {
                   9650:     my ($name, $value) = split(/=/,$pair);
1.369     www      9651:     $name = &unescape($name);
1.25      albertel 9652:     if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
                   9653:       $value =~ tr/+/ /;
                   9654:       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258     albertel 9655:       unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25      albertel 9656:     }
1.16      harris41 9657:   }
1.6       albertel 9658: }
                   9659: 
1.112     bowersj2 9660: =pod
                   9661: 
1.648     raeburn  9662: =item * &cacheheader() 
1.112     bowersj2 9663: 
                   9664: returns cache-controlling header code
                   9665: 
                   9666: =cut
                   9667: 
1.7       albertel 9668: sub cacheheader {
1.258     albertel 9669:     unless ($env{'request.method'} eq 'GET') { return ''; }
1.216     albertel 9670:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
                   9671:     my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7       albertel 9672:                 <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
                   9673:                 <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216     albertel 9674:     return $output;
1.7       albertel 9675: }
                   9676: 
1.112     bowersj2 9677: =pod
                   9678: 
1.648     raeburn  9679: =item * &no_cache($r) 
1.112     bowersj2 9680: 
                   9681: specifies header code to not have cache
                   9682: 
                   9683: =cut
                   9684: 
1.9       albertel 9685: sub no_cache {
1.216     albertel 9686:     my ($r) = @_;
                   9687:     if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258     albertel 9688: 	$env{'request.method'} ne 'GET') { return ''; }
1.216     albertel 9689:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
                   9690:     $r->no_cache(1);
                   9691:     $r->header_out("Expires" => $date);
                   9692:     $r->header_out("Pragma" => "no-cache");
1.123     www      9693: }
                   9694: 
                   9695: sub content_type {
1.181     albertel 9696:     my ($r,$type,$charset) = @_;
1.299     foxr     9697:     if ($r) {
                   9698: 	#  Note that printout.pl calls this with undef for $r.
                   9699: 	&no_cache($r);
                   9700:     }
1.258     albertel 9701:     if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181     albertel 9702:     unless ($charset) {
                   9703: 	$charset=&Apache::lonlocal::current_encoding;
                   9704:     }
                   9705:     if ($charset) { $type.='; charset='.$charset; }
                   9706:     if ($r) {
                   9707: 	$r->content_type($type);
                   9708:     } else {
                   9709: 	print("Content-type: $type\n\n");
                   9710:     }
1.9       albertel 9711: }
1.25      albertel 9712: 
1.112     bowersj2 9713: =pod
                   9714: 
1.648     raeburn  9715: =item * &add_to_env($name,$value) 
1.112     bowersj2 9716: 
1.258     albertel 9717: adds $name to the %env hash with value
1.112     bowersj2 9718: $value, if $name already exists, the entry is converted to an array
                   9719: reference and $value is added to the array.
                   9720: 
                   9721: =cut
                   9722: 
1.25      albertel 9723: sub add_to_env {
                   9724:   my ($name,$value)=@_;
1.258     albertel 9725:   if (defined($env{$name})) {
                   9726:     if (ref($env{$name})) {
1.25      albertel 9727:       #already have multiple values
1.258     albertel 9728:       push(@{ $env{$name} },$value);
1.25      albertel 9729:     } else {
                   9730:       #first time seeing multiple values, convert hash entry to an arrayref
1.258     albertel 9731:       my $first=$env{$name};
                   9732:       undef($env{$name});
                   9733:       push(@{ $env{$name} },$first,$value);
1.25      albertel 9734:     }
                   9735:   } else {
1.258     albertel 9736:     $env{$name}=$value;
1.25      albertel 9737:   }
1.31      albertel 9738: }
1.149     albertel 9739: 
                   9740: =pod
                   9741: 
1.648     raeburn  9742: =item * &get_env_multiple($name) 
1.149     albertel 9743: 
1.258     albertel 9744: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149     albertel 9745: values may be defined and end up as an array ref.
                   9746: 
                   9747: returns an array of values
                   9748: 
                   9749: =cut
                   9750: 
                   9751: sub get_env_multiple {
                   9752:     my ($name) = @_;
                   9753:     my @values;
1.258     albertel 9754:     if (defined($env{$name})) {
1.149     albertel 9755:         # exists is it an array
1.258     albertel 9756:         if (ref($env{$name})) {
                   9757:             @values=@{ $env{$name} };
1.149     albertel 9758:         } else {
1.258     albertel 9759:             $values[0]=$env{$name};
1.149     albertel 9760:         }
                   9761:     }
                   9762:     return(@values);
                   9763: }
                   9764: 
1.660     raeburn  9765: sub ask_for_embedded_content {
                   9766:     my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071    raeburn  9767:     my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11  raeburn  9768:         %currsubfile,%unused,$rem);
1.1071    raeburn  9769:     my $counter = 0;
                   9770:     my $numnew = 0;
1.987     raeburn  9771:     my $numremref = 0;
                   9772:     my $numinvalid = 0;
                   9773:     my $numpathchg = 0;
                   9774:     my $numexisting = 0;
1.1071    raeburn  9775:     my $numunused = 0;
                   9776:     my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
                   9777:         $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path);
                   9778:     my $heading = &mt('Upload embedded files');
                   9779:     my $buttontext = &mt('Upload');
                   9780: 
1.1075.2.35  raeburn  9781:     my ($navmap,$cdom,$cnum);
1.1075.2.11  raeburn  9782:     if ($env{'request.course.id'}) {
1.1075.2.35  raeburn  9783:         if ($actionurl eq '/adm/dependencies') {
                   9784:             $navmap = Apache::lonnavmaps::navmap->new();
                   9785:         }
                   9786:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   9787:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11  raeburn  9788:     }
1.1075.2.35  raeburn  9789:     if (($actionurl eq '/adm/portfolio') ||
                   9790:         ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984     raeburn  9791:         my $current_path='/';
                   9792:         if ($env{'form.currentpath'}) {
                   9793:             $current_path = $env{'form.currentpath'};
                   9794:         }
                   9795:         if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35  raeburn  9796:             $udom = $cdom;
                   9797:             $uname = $cnum;
1.984     raeburn  9798:             $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
                   9799:         } else {
                   9800:             $udom = $env{'user.domain'};
                   9801:             $uname = $env{'user.name'};
                   9802:             $url = '/userfiles/portfolio';
                   9803:         }
1.987     raeburn  9804:         $toplevel = $url.'/';
1.984     raeburn  9805:         $url .= $current_path;
                   9806:         $getpropath = 1;
1.987     raeburn  9807:     } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
                   9808:              ($actionurl eq '/adm/imsimport')) { 
1.1022    www      9809:         my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026    raeburn  9810:         $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987     raeburn  9811:         $toplevel = $url;
1.984     raeburn  9812:         if ($rest ne '') {
1.987     raeburn  9813:             $url .= $rest;
                   9814:         }
                   9815:     } elsif ($actionurl eq '/adm/coursedocs') {
                   9816:         if (ref($args) eq 'HASH') {
1.1071    raeburn  9817:             $url = $args->{'docs_url'};
                   9818:             $toplevel = $url;
1.1075.2.11  raeburn  9819:             if ($args->{'context'} eq 'paste') {
                   9820:                 ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
                   9821:                 ($path) =
                   9822:                     ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
                   9823:                 $fileloc = &Apache::lonnet::filelocation('',$toplevel);
                   9824:                 $fileloc =~ s{^/}{};
                   9825:             }
1.1071    raeburn  9826:         }
                   9827:     } elsif ($actionurl eq '/adm/dependencies') {
                   9828:         if ($env{'request.course.id'} ne '') {
                   9829:             if (ref($args) eq 'HASH') {
                   9830:                 $url = $args->{'docs_url'};
                   9831:                 $title = $args->{'docs_title'};
1.1075.2.35  raeburn  9832:                 $toplevel = $url;
                   9833:                 unless ($toplevel =~ m{^/}) {
                   9834:                     $toplevel = "/$url";
                   9835:                 }
1.1075.2.11  raeburn  9836:                 ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35  raeburn  9837:                 if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
                   9838:                     $path = $1;
                   9839:                 } else {
                   9840:                     ($path) =
                   9841:                         ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
                   9842:                 }
1.1071    raeburn  9843:                 $fileloc = &Apache::lonnet::filelocation('',$toplevel);
                   9844:                 $fileloc =~ s{^/}{};
                   9845:                 ($filename) = ($fileloc =~ m{.+/([^/]+)$});
                   9846:                 $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
                   9847:             }
1.987     raeburn  9848:         }
1.1075.2.35  raeburn  9849:     } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
                   9850:         $udom = $cdom;
                   9851:         $uname = $cnum;
                   9852:         $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
                   9853:         $toplevel = $url;
                   9854:         $path = $url;
                   9855:         $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
                   9856:         $fileloc =~ s{^/}{};
                   9857:     }
                   9858:     foreach my $file (keys(%{$allfiles})) {
                   9859:         my $embed_file;
                   9860:         if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
                   9861:             $embed_file = $1;
                   9862:         } else {
                   9863:             $embed_file = $file;
                   9864:         }
1.987     raeburn  9865:         my $absolutepath;
1.1075.2.47  raeburn  9866:         my $cleaned_file = &clean_path($embed_file);
                   9867:         if ($cleaned_file =~ m{^\w+://}) {
                   9868:             $newfiles{$cleaned_file} = 1;
                   9869:             $mapping{$cleaned_file} = $embed_file;
1.987     raeburn  9870:         } else {
                   9871:             if ($embed_file =~ m{^/}) {
                   9872:                 $absolutepath = $embed_file;
                   9873:             }
1.1075.2.47  raeburn  9874:             if ($cleaned_file =~ m{/}) {
                   9875:                 my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987     raeburn  9876:                 $path = &check_for_traversal($path,$url,$toplevel);
                   9877:                 my $item = $fname;
                   9878:                 if ($path ne '') {
                   9879:                     $item = $path.'/'.$fname;
                   9880:                     $subdependencies{$path}{$fname} = 1;
                   9881:                 } else {
                   9882:                     $dependencies{$item} = 1;
                   9883:                 }
                   9884:                 if ($absolutepath) {
                   9885:                     $mapping{$item} = $absolutepath;
                   9886:                 } else {
                   9887:                     $mapping{$item} = $embed_file;
                   9888:                 }
                   9889:             } else {
                   9890:                 $dependencies{$embed_file} = 1;
                   9891:                 if ($absolutepath) {
1.1075.2.47  raeburn  9892:                     $mapping{$cleaned_file} = $absolutepath;
1.987     raeburn  9893:                 } else {
1.1075.2.47  raeburn  9894:                     $mapping{$cleaned_file} = $embed_file;
1.987     raeburn  9895:                 }
                   9896:             }
1.984     raeburn  9897:         }
                   9898:     }
1.1071    raeburn  9899:     my $dirptr = 16384;
1.984     raeburn  9900:     foreach my $path (keys(%subdependencies)) {
1.1071    raeburn  9901:         $currsubfile{$path} = {};
1.1075.2.35  raeburn  9902:         if (($actionurl eq '/adm/portfolio') ||
                   9903:             ($actionurl eq '/adm/coursegrp_portfolio')) { 
1.1021    raeburn  9904:             my ($sublistref,$listerror) =
                   9905:                 &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
                   9906:             if (ref($sublistref) eq 'ARRAY') {
                   9907:                 foreach my $line (@{$sublistref}) {
                   9908:                     my ($file_name,$rest) = split(/\&/,$line,2);
1.1071    raeburn  9909:                     $currsubfile{$path}{$file_name} = 1;
1.1021    raeburn  9910:                 }
1.984     raeburn  9911:             }
1.987     raeburn  9912:         } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984     raeburn  9913:             if (opendir(my $dir,$url.'/'.$path)) {
                   9914:                 my @subdir_list = grep(!/^\./,readdir($dir));
1.1071    raeburn  9915:                 map {$currsubfile{$path}{$_} = 1;} @subdir_list;
                   9916:             }
1.1075.2.11  raeburn  9917:         } elsif (($actionurl eq '/adm/dependencies') ||
                   9918:                  (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35  raeburn  9919:                   ($args->{'context'} eq 'paste')) ||
                   9920:                  ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071    raeburn  9921:             if ($env{'request.course.id'} ne '') {
1.1075.2.35  raeburn  9922:                 my $dir;
                   9923:                 if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
                   9924:                     $dir = $fileloc;
                   9925:                 } else {
                   9926:                     ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
                   9927:                 }
1.1071    raeburn  9928:                 if ($dir ne '') {
                   9929:                     my ($sublistref,$listerror) =
                   9930:                         &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
                   9931:                     if (ref($sublistref) eq 'ARRAY') {
                   9932:                         foreach my $line (@{$sublistref}) {
                   9933:                             my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
                   9934:                                 undef,$mtime)=split(/\&/,$line,12);
                   9935:                             unless (($testdir&$dirptr) ||
                   9936:                                     ($file_name =~ /^\.\.?$/)) {
                   9937:                                 $currsubfile{$path}{$file_name} = [$size,$mtime];
                   9938:                             }
                   9939:                         }
                   9940:                     }
                   9941:                 }
1.984     raeburn  9942:             }
                   9943:         }
                   9944:         foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071    raeburn  9945:             if (exists($currsubfile{$path}{$file})) {
1.987     raeburn  9946:                 my $item = $path.'/'.$file;
                   9947:                 unless ($mapping{$item} eq $item) {
                   9948:                     $pathchanges{$item} = 1;
                   9949:                 }
                   9950:                 $existing{$item} = 1;
                   9951:                 $numexisting ++;
                   9952:             } else {
                   9953:                 $newfiles{$path.'/'.$file} = 1;
1.984     raeburn  9954:             }
                   9955:         }
1.1071    raeburn  9956:         if ($actionurl eq '/adm/dependencies') {
                   9957:             foreach my $path (keys(%currsubfile)) {
                   9958:                 if (ref($currsubfile{$path}) eq 'HASH') {
                   9959:                     foreach my $file (keys(%{$currsubfile{$path}})) {
                   9960:                          unless ($subdependencies{$path}{$file}) {
1.1075.2.11  raeburn  9961:                              next if (($rem ne '') &&
                   9962:                                       (($env{"httpref.$rem"."$path/$file"} ne '') ||
                   9963:                                        (ref($navmap) &&
                   9964:                                        (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
                   9965:                                         (($file =~ /^(.*\.s?html?)\.bak$/i) &&
                   9966:                                          ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071    raeburn  9967:                              $unused{$path.'/'.$file} = 1; 
                   9968:                          }
                   9969:                     }
                   9970:                 }
                   9971:             }
                   9972:         }
1.984     raeburn  9973:     }
1.987     raeburn  9974:     my %currfile;
1.1075.2.35  raeburn  9975:     if (($actionurl eq '/adm/portfolio') ||
                   9976:         ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021    raeburn  9977:         my ($dirlistref,$listerror) =
                   9978:             &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
                   9979:         if (ref($dirlistref) eq 'ARRAY') {
                   9980:             foreach my $line (@{$dirlistref}) {
                   9981:                 my ($file_name,$rest) = split(/\&/,$line,2);
                   9982:                 $currfile{$file_name} = 1;
                   9983:             }
1.984     raeburn  9984:         }
1.987     raeburn  9985:     } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984     raeburn  9986:         if (opendir(my $dir,$url)) {
1.987     raeburn  9987:             my @dir_list = grep(!/^\./,readdir($dir));
1.984     raeburn  9988:             map {$currfile{$_} = 1;} @dir_list;
                   9989:         }
1.1075.2.11  raeburn  9990:     } elsif (($actionurl eq '/adm/dependencies') ||
                   9991:              (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35  raeburn  9992:               ($args->{'context'} eq 'paste')) ||
                   9993:              ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071    raeburn  9994:         if ($env{'request.course.id'} ne '') {
                   9995:             my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
                   9996:             if ($dir ne '') {
                   9997:                 my ($dirlistref,$listerror) =
                   9998:                     &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
                   9999:                 if (ref($dirlistref) eq 'ARRAY') {
                   10000:                     foreach my $line (@{$dirlistref}) {
                   10001:                         my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
                   10002:                             $size,undef,$mtime)=split(/\&/,$line,12);
                   10003:                         unless (($testdir&$dirptr) ||
                   10004:                                 ($file_name =~ /^\.\.?$/)) {
                   10005:                             $currfile{$file_name} = [$size,$mtime];
                   10006:                         }
                   10007:                     }
                   10008:                 }
                   10009:             }
                   10010:         }
1.984     raeburn  10011:     }
                   10012:     foreach my $file (keys(%dependencies)) {
1.1071    raeburn  10013:         if (exists($currfile{$file})) {
1.987     raeburn  10014:             unless ($mapping{$file} eq $file) {
                   10015:                 $pathchanges{$file} = 1;
                   10016:             }
                   10017:             $existing{$file} = 1;
                   10018:             $numexisting ++;
                   10019:         } else {
1.984     raeburn  10020:             $newfiles{$file} = 1;
                   10021:         }
                   10022:     }
1.1071    raeburn  10023:     foreach my $file (keys(%currfile)) {
                   10024:         unless (($file eq $filename) ||
                   10025:                 ($file eq $filename.'.bak') ||
                   10026:                 ($dependencies{$file})) {
1.1075.2.11  raeburn  10027:             if ($actionurl eq '/adm/dependencies') {
1.1075.2.35  raeburn  10028:                 unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
                   10029:                     next if (($rem ne '') &&
                   10030:                              (($env{"httpref.$rem".$file} ne '') ||
                   10031:                               (ref($navmap) &&
                   10032:                               (($navmap->getResourceByUrl($rem.$file) ne '') ||
                   10033:                                (($file =~ /^(.*\.s?html?)\.bak$/i) &&
                   10034:                                 ($navmap->getResourceByUrl($rem.$1)))))));
                   10035:                 }
1.1075.2.11  raeburn  10036:             }
1.1071    raeburn  10037:             $unused{$file} = 1;
                   10038:         }
                   10039:     }
1.1075.2.11  raeburn  10040:     if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
                   10041:         ($args->{'context'} eq 'paste')) {
                   10042:         $counter = scalar(keys(%existing));
                   10043:         $numpathchg = scalar(keys(%pathchanges));
                   10044:         return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35  raeburn  10045:     } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
                   10046:              (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
                   10047:         $counter = scalar(keys(%existing));
                   10048:         $numpathchg = scalar(keys(%pathchanges));
                   10049:         return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11  raeburn  10050:     }
1.984     raeburn  10051:     foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071    raeburn  10052:         if ($actionurl eq '/adm/dependencies') {
                   10053:             next if ($embed_file =~ m{^\w+://});
                   10054:         }
1.660     raeburn  10055:         $upload_output .= &start_data_table_row().
1.1075.2.35  raeburn  10056:                           '<td valign="top"><img src="'.&icon($embed_file).'" />&nbsp;'.
1.1071    raeburn  10057:                           '<span class="LC_filename">'.$embed_file.'</span>';
1.987     raeburn  10058:         unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35  raeburn  10059:             $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
                   10060:                               &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987     raeburn  10061:         }
1.1075.2.35  raeburn  10062:         $upload_output .= '</td>';
1.1071    raeburn  10063:         if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) { 
1.1075.2.35  raeburn  10064:             $upload_output.='<td align="right">'.
                   10065:                             '<span class="LC_info LC_fontsize_medium">'.
                   10066:                             &mt("URL points to web address").'</span>';
1.987     raeburn  10067:             $numremref++;
1.660     raeburn  10068:         } elsif ($args->{'error_on_invalid_names'}
                   10069:             && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35  raeburn  10070:             $upload_output.='<td align="right"><span class="LC_warning">'.
                   10071:                             &mt('Invalid characters').'</span>';
1.987     raeburn  10072:             $numinvalid++;
1.660     raeburn  10073:         } else {
1.1075.2.35  raeburn  10074:             $upload_output .= '<td>'.
                   10075:                               &embedded_file_element('upload_embedded',$counter,
1.987     raeburn  10076:                                                      $embed_file,\%mapping,
1.1071    raeburn  10077:                                                      $allfiles,$codebase,'upload');
                   10078:             $counter ++;
                   10079:             $numnew ++;
1.987     raeburn  10080:         }
                   10081:         $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
                   10082:     }
                   10083:     foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071    raeburn  10084:         if ($actionurl eq '/adm/dependencies') {
                   10085:             my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
                   10086:             $modify_output .= &start_data_table_row().
                   10087:                               '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
                   10088:                               '<img src="'.&icon($embed_file).'" border="0" />'.
                   10089:                               '&nbsp;<span class="LC_filename">'.$embed_file.'</span></a></td>'.
                   10090:                               '<td>'.$size.'</td>'.
                   10091:                               '<td>'.$mtime.'</td>'.
                   10092:                               '<td><label><input type="checkbox" name="mod_upload_dep" '.
                   10093:                               'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
                   10094:                               $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
                   10095:                               '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
                   10096:                               &embedded_file_element('upload_embedded',$counter,
                   10097:                                                      $embed_file,\%mapping,
                   10098:                                                      $allfiles,$codebase,'modify').
                   10099:                               '</div></td>'.
                   10100:                               &end_data_table_row()."\n";
                   10101:             $counter ++;
                   10102:         } else {
                   10103:             $upload_output .= &start_data_table_row().
1.1075.2.35  raeburn  10104:                               '<td valign="top"><img src="'.&icon($embed_file).'" />&nbsp;'.
                   10105:                               '<span class="LC_filename">'.$embed_file.'</span></td>'.
                   10106:                               '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071    raeburn  10107:                               &Apache::loncommon::end_data_table_row()."\n";
                   10108:         }
                   10109:     }
                   10110:     my $delidx = $counter;
                   10111:     foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
                   10112:         my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
                   10113:         $delete_output .= &start_data_table_row().
                   10114:                           '<td><img src="'.&icon($oldfile).'" />'.
                   10115:                           '&nbsp;<span class="LC_filename">'.$oldfile.'</span></td>'.
                   10116:                           '<td>'.$size.'</td>'.
                   10117:                           '<td>'.$mtime.'</td>'.
                   10118:                           '<td><label><input type="checkbox" name="del_upload_dep" '.
                   10119:                           ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
                   10120:                           &embedded_file_element('upload_embedded',$delidx,
                   10121:                                                  $oldfile,\%mapping,$allfiles,
                   10122:                                                  $codebase,'delete').'</td>'.
                   10123:                           &end_data_table_row()."\n"; 
                   10124:         $numunused ++;
                   10125:         $delidx ++;
1.987     raeburn  10126:     }
                   10127:     if ($upload_output) {
                   10128:         $upload_output = &start_data_table().
                   10129:                          $upload_output.
                   10130:                          &end_data_table()."\n";
                   10131:     }
1.1071    raeburn  10132:     if ($modify_output) {
                   10133:         $modify_output = &start_data_table().
                   10134:                          &start_data_table_header_row().
                   10135:                          '<th>'.&mt('File').'</th>'.
                   10136:                          '<th>'.&mt('Size (KB)').'</th>'.
                   10137:                          '<th>'.&mt('Modified').'</th>'.
                   10138:                          '<th>'.&mt('Upload replacement?').'</th>'.
                   10139:                          &end_data_table_header_row().
                   10140:                          $modify_output.
                   10141:                          &end_data_table()."\n";
                   10142:     }
                   10143:     if ($delete_output) {
                   10144:         $delete_output = &start_data_table().
                   10145:                          &start_data_table_header_row().
                   10146:                          '<th>'.&mt('File').'</th>'.
                   10147:                          '<th>'.&mt('Size (KB)').'</th>'.
                   10148:                          '<th>'.&mt('Modified').'</th>'.
                   10149:                          '<th>'.&mt('Delete?').'</th>'.
                   10150:                          &end_data_table_header_row().
                   10151:                          $delete_output.
                   10152:                          &end_data_table()."\n";
                   10153:     }
1.987     raeburn  10154:     my $applies = 0;
                   10155:     if ($numremref) {
                   10156:         $applies ++;
                   10157:     }
                   10158:     if ($numinvalid) {
                   10159:         $applies ++;
                   10160:     }
                   10161:     if ($numexisting) {
                   10162:         $applies ++;
                   10163:     }
1.1071    raeburn  10164:     if ($counter || $numunused) {
1.987     raeburn  10165:         $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
                   10166:                   ' method="post" enctype="multipart/form-data">'."\n".
1.1071    raeburn  10167:                   $state.'<h3>'.$heading.'</h3>'; 
                   10168:         if ($actionurl eq '/adm/dependencies') {
                   10169:             if ($numnew) {
                   10170:                 $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
                   10171:                            '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
                   10172:                            $upload_output.'<br />'."\n";
                   10173:             }
                   10174:             if ($numexisting) {
                   10175:                 $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
                   10176:                            '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
                   10177:                            $modify_output.'<br />'."\n";
                   10178:                            $buttontext = &mt('Save changes');
                   10179:             }
                   10180:             if ($numunused) {
                   10181:                 $output .= '<h4>'.&mt('Unused files').'</h4>'.
                   10182:                            '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
                   10183:                            $delete_output.'<br />'."\n";
                   10184:                            $buttontext = &mt('Save changes');
                   10185:             }
                   10186:         } else {
                   10187:             $output .= $upload_output.'<br />'."\n";
                   10188:         }
                   10189:         $output .= '<input type ="hidden" name="number_embedded_items" value="'.
                   10190:                    $counter.'" />'."\n";
                   10191:         if ($actionurl eq '/adm/dependencies') { 
                   10192:             $output .= '<input type ="hidden" name="number_newemb_items" value="'.
                   10193:                        $numnew.'" />'."\n";
                   10194:         } elsif ($actionurl eq '') {
1.987     raeburn  10195:             $output .=  '<input type="hidden" name="phase" value="three" />';
                   10196:         }
                   10197:     } elsif ($applies) {
                   10198:         $output = '<b>'.&mt('Referenced files').'</b>:<br />';
                   10199:         if ($applies > 1) {
                   10200:             $output .=  
1.1075.2.35  raeburn  10201:                 &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987     raeburn  10202:             if ($numremref) {
                   10203:                 $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
                   10204:             }
                   10205:             if ($numinvalid) {
                   10206:                 $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
                   10207:             }
                   10208:             if ($numexisting) {
                   10209:                 $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
                   10210:             }
                   10211:             $output .= '</ul><br />';
                   10212:         } elsif ($numremref) {
                   10213:             $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
                   10214:         } elsif ($numinvalid) {
                   10215:             $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
                   10216:         } elsif ($numexisting) {
                   10217:             $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
                   10218:         }
                   10219:         $output .= $upload_output.'<br />';
                   10220:     }
                   10221:     my ($pathchange_output,$chgcount);
1.1071    raeburn  10222:     $chgcount = $counter;
1.987     raeburn  10223:     if (keys(%pathchanges) > 0) {
                   10224:         foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071    raeburn  10225:             if ($counter) {
1.987     raeburn  10226:                 $output .= &embedded_file_element('pathchange',$chgcount,
                   10227:                                                   $embed_file,\%mapping,
1.1071    raeburn  10228:                                                   $allfiles,$codebase,'change');
1.987     raeburn  10229:             } else {
                   10230:                 $pathchange_output .= 
                   10231:                     &start_data_table_row().
                   10232:                     '<td><input type ="checkbox" name="namechange" value="'.
                   10233:                     $chgcount.'" checked="checked" /></td>'.
                   10234:                     '<td>'.$mapping{$embed_file}.'</td>'.
                   10235:                     '<td>'.$embed_file.
                   10236:                     &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071    raeburn  10237:                                            \%mapping,$allfiles,$codebase,'change').
1.987     raeburn  10238:                     '</td>'.&end_data_table_row();
1.660     raeburn  10239:             }
1.987     raeburn  10240:             $numpathchg ++;
                   10241:             $chgcount ++;
1.660     raeburn  10242:         }
                   10243:     }
1.1075.2.35  raeburn  10244:     if (($counter) || ($numunused)) {
1.987     raeburn  10245:         if ($numpathchg) {
                   10246:             $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
                   10247:                        $numpathchg.'" />'."\n";
                   10248:         }
                   10249:         if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') || 
                   10250:             ($actionurl eq '/adm/imsimport')) {
                   10251:             $output .= '<input type="hidden" name="phase" value="three" />'."\n";
                   10252:         } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
                   10253:             $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071    raeburn  10254:         } elsif ($actionurl eq '/adm/dependencies') {
                   10255:             $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987     raeburn  10256:         }
1.1075.2.35  raeburn  10257:         $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987     raeburn  10258:     } elsif ($numpathchg) {
                   10259:         my %pathchange = ();
                   10260:         $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
                   10261:         if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
                   10262:             $output .= '<p>'.&mt('or').'</p>'; 
1.1075.2.35  raeburn  10263:         }
1.987     raeburn  10264:     }
1.1071    raeburn  10265:     return ($output,$counter,$numpathchg);
1.987     raeburn  10266: }
                   10267: 
1.1075.2.47  raeburn  10268: 
                   10269: =pod
                   10270: 
                   10271: =item * clean_path($name)
                   10272: 
                   10273: Performs clean-up of directories, subdirectories and filename in an
                   10274: embedded object, referenced in an HTML file which is being uploaded
                   10275: to a course or portfolio, where
                   10276: "Upload embedded images/multimedia files if HTML file" checkbox was
                   10277: checked.
                   10278: 
                   10279: Clean-up is similar to replacements in lonnet::clean_filename()
                   10280: except each / between sub-directory and next level is preserved.
                   10281: 
                   10282: =cut
                   10283: 
                   10284: sub clean_path {
                   10285:     my ($embed_file) = @_;
                   10286:     $embed_file =~s{^/+}{};
                   10287:     my @contents;
                   10288:     if ($embed_file =~ m{/}) {
                   10289:         @contents = split(/\//,$embed_file);
                   10290:     } else {
                   10291:         @contents = ($embed_file);
                   10292:     }
                   10293:     my $lastidx = scalar(@contents)-1;
                   10294:     for (my $i=0; $i<=$lastidx; $i++) {
                   10295:         $contents[$i]=~s{\\}{/}g;
                   10296:         $contents[$i]=~s/\s+/\_/g;
                   10297:         $contents[$i]=~s{[^/\w\.\-]}{}g;
                   10298:         if ($i == $lastidx) {
                   10299:             $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
                   10300:         }
                   10301:     }
                   10302:     if ($lastidx > 0) {
                   10303:         return join('/',@contents);
                   10304:     } else {
                   10305:         return $contents[0];
                   10306:     }
                   10307: }
                   10308: 
1.987     raeburn  10309: sub embedded_file_element {
1.1071    raeburn  10310:     my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987     raeburn  10311:     return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
                   10312:                    (ref($codebase) eq 'HASH'));
                   10313:     my $output;
1.1071    raeburn  10314:     if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987     raeburn  10315:        $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
                   10316:     }
                   10317:     $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
                   10318:                &escape($embed_file).'" />';
                   10319:     unless (($context eq 'upload_embedded') && 
                   10320:             ($mapping->{$embed_file} eq $embed_file)) {
                   10321:         $output .='
                   10322:         <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
                   10323:     }
                   10324:     my $attrib;
                   10325:     if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
                   10326:         $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
                   10327:     }
                   10328:     $output .=
                   10329:         "\n\t\t".
                   10330:         '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
                   10331:         $attrib.'" />';
                   10332:     if (exists($codebase->{$mapping->{$embed_file}})) {
                   10333:         $output .=
                   10334:             "\n\t\t".
                   10335:             '<input name="codebase_'.$num.'" type="hidden" value="'.
                   10336:             &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984     raeburn  10337:     }
1.987     raeburn  10338:     return $output;
1.660     raeburn  10339: }
                   10340: 
1.1071    raeburn  10341: sub get_dependency_details {
                   10342:     my ($currfile,$currsubfile,$embed_file) = @_;
                   10343:     my ($size,$mtime,$showsize,$showmtime);
                   10344:     if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
                   10345:         if ($embed_file =~ m{/}) {
                   10346:             my ($path,$fname) = split(/\//,$embed_file);
                   10347:             if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
                   10348:                 ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
                   10349:             }
                   10350:         } else {
                   10351:             if (ref($currfile->{$embed_file}) eq 'ARRAY') {
                   10352:                 ($size,$mtime) = @{$currfile->{$embed_file}};
                   10353:             }
                   10354:         }
                   10355:         $showsize = $size/1024.0;
                   10356:         $showsize = sprintf("%.1f",$showsize);
                   10357:         if ($mtime > 0) {
                   10358:             $showmtime = &Apache::lonlocal::locallocaltime($mtime);
                   10359:         }
                   10360:     }
                   10361:     return ($showsize,$showmtime);
                   10362: }
                   10363: 
                   10364: sub ask_embedded_js {
                   10365:     return <<"END";
                   10366: <script type="text/javascript"">
                   10367: // <![CDATA[
                   10368: function toggleBrowse(counter) {
                   10369:     var chkboxid = document.getElementById('mod_upload_dep_'+counter);
                   10370:     var fileid = document.getElementById('embedded_item_'+counter);
                   10371:     var uploaddivid = document.getElementById('moduploaddep_'+counter);
                   10372:     if (chkboxid.checked == true) {
                   10373:         uploaddivid.style.display='block';
                   10374:     } else {
                   10375:         uploaddivid.style.display='none';
                   10376:         fileid.value = '';
                   10377:     }
                   10378: }
                   10379: // ]]>
                   10380: </script>
                   10381: 
                   10382: END
                   10383: }
                   10384: 
1.661     raeburn  10385: sub upload_embedded {
                   10386:     my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987     raeburn  10387:         $current_disk_usage,$hiddenstate,$actionurl) = @_;
                   10388:     my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661     raeburn  10389:     for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
                   10390:         next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
                   10391:         my $orig_uploaded_filename =
                   10392:             $env{'form.embedded_item_'.$i.'.filename'};
1.987     raeburn  10393:         foreach my $type ('orig','ref','attrib','codebase') {
                   10394:             if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
                   10395:                 $env{'form.embedded_'.$type.'_'.$i} =
                   10396:                     &unescape($env{'form.embedded_'.$type.'_'.$i});
                   10397:             }
                   10398:         }
1.661     raeburn  10399:         my ($path,$fname) =
                   10400:             ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
                   10401:         # no path, whole string is fname
                   10402:         if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
                   10403:         $fname = &Apache::lonnet::clean_filename($fname);
                   10404:         # See if there is anything left
                   10405:         next if ($fname eq '');
                   10406: 
                   10407:         # Check if file already exists as a file or directory.
                   10408:         my ($state,$msg);
                   10409:         if ($context eq 'portfolio') {
                   10410:             my $port_path = $dirpath;
                   10411:             if ($group ne '') {
                   10412:                 $port_path = "groups/$group/$port_path";
                   10413:             }
1.987     raeburn  10414:             ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
                   10415:                                               $fname,$group,'embedded_item_'.$i,
1.661     raeburn  10416:                                               $dir_root,$port_path,$disk_quota,
                   10417:                                               $current_disk_usage,$uname,$udom);
                   10418:             if ($state eq 'will_exceed_quota'
1.984     raeburn  10419:                 || $state eq 'file_locked') {
1.661     raeburn  10420:                 $output .= $msg;
                   10421:                 next;
                   10422:             }
                   10423:         } elsif (($context eq 'author') || ($context eq 'testbank')) {
                   10424:             ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
                   10425:             if ($state eq 'exists') {
                   10426:                 $output .= $msg;
                   10427:                 next;
                   10428:             }
                   10429:         }
                   10430:         # Check if extension is valid
                   10431:         if (($fname =~ /\.(\w+)$/) &&
                   10432:             (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.987     raeburn  10433:             $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1).'<br />';
1.661     raeburn  10434:             next;
                   10435:         } elsif (($fname =~ /\.(\w+)$/) &&
                   10436:                  (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987     raeburn  10437:             $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661     raeburn  10438:             next;
                   10439:         } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34  raeburn  10440:             $output .= &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2).'<br />';
1.661     raeburn  10441:             next;
                   10442:         }
                   10443:         $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35  raeburn  10444:         my $subdir = $path;
                   10445:         $subdir =~ s{/+$}{};
1.661     raeburn  10446:         if ($context eq 'portfolio') {
1.984     raeburn  10447:             my $result;
                   10448:             if ($state eq 'existingfile') {
                   10449:                 $result=
                   10450:                     &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35  raeburn  10451:                                                     $dirpath.$env{'form.currentpath'}.$subdir);
1.661     raeburn  10452:             } else {
1.984     raeburn  10453:                 $result=
                   10454:                     &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987     raeburn  10455:                                                     $dirpath.
1.1075.2.35  raeburn  10456:                                                     $env{'form.currentpath'}.$subdir);
1.984     raeburn  10457:                 if ($result !~ m|^/uploaded/|) {
                   10458:                     $output .= '<span class="LC_error">'
                   10459:                                .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
                   10460:                                ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
                   10461:                                .'</span><br />';
                   10462:                     next;
                   10463:                 } else {
1.987     raeburn  10464:                     $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
                   10465:                                $path.$fname.'</span>').'<br />';     
1.984     raeburn  10466:                 }
1.661     raeburn  10467:             }
1.1075.2.35  raeburn  10468:         } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
                   10469:             my $extendedsubdir = $dirpath.'/'.$subdir;
                   10470:             $extendedsubdir =~ s{/+$}{};
1.987     raeburn  10471:             my $result =
1.1075.2.35  raeburn  10472:                 &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987     raeburn  10473:             if ($result !~ m|^/uploaded/|) {
                   10474:                 $output .= '<span class="LC_error">'
                   10475:                            .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
                   10476:                            ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
                   10477:                            .'</span><br />';
                   10478:                     next;
                   10479:             } else {
                   10480:                 $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
                   10481:                            $path.$fname.'</span>').'<br />';
1.1075.2.35  raeburn  10482:                 if ($context eq 'syllabus') {
                   10483:                     &Apache::lonnet::make_public_indefinitely($result);
                   10484:                 }
1.987     raeburn  10485:             }
1.661     raeburn  10486:         } else {
                   10487: # Save the file
                   10488:             my $target = $env{'form.embedded_item_'.$i};
                   10489:             my $fullpath = $dir_root.$dirpath.'/'.$path;
                   10490:             my $dest = $fullpath.$fname;
                   10491:             my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027    raeburn  10492:             my @parts=split(/\//,"$dirpath/$path");
1.661     raeburn  10493:             my $count;
                   10494:             my $filepath = $dir_root;
1.1027    raeburn  10495:             foreach my $subdir (@parts) {
                   10496:                 $filepath .= "/$subdir";
                   10497:                 if (!-e $filepath) {
1.661     raeburn  10498:                     mkdir($filepath,0770);
                   10499:                 }
                   10500:             }
                   10501:             my $fh;
                   10502:             if (!open($fh,'>'.$dest)) {
                   10503:                 &Apache::lonnet::logthis('Failed to create '.$dest);
                   10504:                 $output .= '<span class="LC_error">'.
1.1071    raeburn  10505:                            &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
                   10506:                                $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661     raeburn  10507:                            '</span><br />';
                   10508:             } else {
                   10509:                 if (!print $fh $env{'form.embedded_item_'.$i}) {
                   10510:                     &Apache::lonnet::logthis('Failed to write to '.$dest);
                   10511:                     $output .= '<span class="LC_error">'.
1.1071    raeburn  10512:                               &mt('An error occurred while writing the file [_1] for embedded element [_2].',
                   10513:                                   $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661     raeburn  10514:                               '</span><br />';
                   10515:                 } else {
1.987     raeburn  10516:                     $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
                   10517:                                $url.'</span>').'<br />';
                   10518:                     unless ($context eq 'testbank') {
                   10519:                         $footer .= &mt('View embedded file: [_1]',
                   10520:                                        '<a href="'.$url.'">'.$fname.'</a>').'<br />';
                   10521:                     }
                   10522:                 }
                   10523:                 close($fh);
                   10524:             }
                   10525:         }
                   10526:         if ($env{'form.embedded_ref_'.$i}) {
                   10527:             $pathchange{$i} = 1;
                   10528:         }
                   10529:     }
                   10530:     if ($output) {
                   10531:         $output = '<p>'.$output.'</p>';
                   10532:     }
                   10533:     $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
                   10534:     $returnflag = 'ok';
1.1071    raeburn  10535:     my $numpathchgs = scalar(keys(%pathchange));
                   10536:     if ($numpathchgs > 0) {
1.987     raeburn  10537:         if ($context eq 'portfolio') {
                   10538:             $output .= '<p>'.&mt('or').'</p>';
                   10539:         } elsif ($context eq 'testbank') {
1.1071    raeburn  10540:             $output .=  '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
                   10541:                                   '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987     raeburn  10542:             $returnflag = 'modify_orightml';
                   10543:         }
                   10544:     }
1.1071    raeburn  10545:     return ($output.$footer,$returnflag,$numpathchgs);
1.987     raeburn  10546: }
                   10547: 
                   10548: sub modify_html_form {
                   10549:     my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
                   10550:     my $end = 0;
                   10551:     my $modifyform;
                   10552:     if ($context eq 'upload_embedded') {
                   10553:         return unless (ref($pathchange) eq 'HASH');
                   10554:         if ($env{'form.number_embedded_items'}) {
                   10555:             $end += $env{'form.number_embedded_items'};
                   10556:         }
                   10557:         if ($env{'form.number_pathchange_items'}) {
                   10558:             $end += $env{'form.number_pathchange_items'};
                   10559:         }
                   10560:         if ($end) {
                   10561:             for (my $i=0; $i<$end; $i++) {
                   10562:                 if ($i < $env{'form.number_embedded_items'}) {
                   10563:                     next unless($pathchange->{$i});
                   10564:                 }
                   10565:                 $modifyform .=
                   10566:                     &start_data_table_row().
                   10567:                     '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
                   10568:                     'checked="checked" /></td>'.
                   10569:                     '<td>'.$env{'form.embedded_ref_'.$i}.
                   10570:                     '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
                   10571:                     &escape($env{'form.embedded_ref_'.$i}).'" />'.
                   10572:                     '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
                   10573:                     &escape($env{'form.embedded_codebase_'.$i}).'" />'.
                   10574:                     '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
                   10575:                     &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
                   10576:                     '<td>'.$env{'form.embedded_orig_'.$i}.
                   10577:                     '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
                   10578:                     &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
                   10579:                     &end_data_table_row();
1.1071    raeburn  10580:             }
1.987     raeburn  10581:         }
                   10582:     } else {
                   10583:         $modifyform = $pathchgtable;
                   10584:         if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
                   10585:             $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
                   10586:         } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
                   10587:             $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
                   10588:         }
                   10589:     }
                   10590:     if ($modifyform) {
1.1071    raeburn  10591:         if ($actionurl eq '/adm/dependencies') {
                   10592:             $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
                   10593:         }
1.987     raeburn  10594:         return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
                   10595:                '<p>'.&mt('Changes need to be made to the reference(s) used for one or more of the dependencies, if your HTML file is to work correctly:').'<ol>'."\n".
                   10596:                '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
                   10597:                '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
                   10598:                '</ol></p>'."\n".'<p>'.
                   10599:                &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
                   10600:                '<form method="post" name="refchanger" action="'.$actionurl.'">'.
                   10601:                &start_data_table()."\n".
                   10602:                &start_data_table_header_row().
                   10603:                '<th>'.&mt('Change?').'</th>'.
                   10604:                '<th>'.&mt('Current reference').'</th>'.
                   10605:                '<th>'.&mt('Required reference').'</th>'.
                   10606:                &end_data_table_header_row()."\n".
                   10607:                $modifyform.
                   10608:                &end_data_table().'<br />'."\n".$hiddenstate.
                   10609:                '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
                   10610:                '</form>'."\n";
                   10611:     }
                   10612:     return;
                   10613: }
                   10614: 
                   10615: sub modify_html_refs {
1.1075.2.35  raeburn  10616:     my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987     raeburn  10617:     my $container;
                   10618:     if ($context eq 'portfolio') {
                   10619:         $container = $env{'form.container'};
                   10620:     } elsif ($context eq 'coursedoc') {
                   10621:         $container = $env{'form.primaryurl'};
1.1071    raeburn  10622:     } elsif ($context eq 'manage_dependencies') {
                   10623:         (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
                   10624:         $container = "/$container";
1.1075.2.35  raeburn  10625:     } elsif ($context eq 'syllabus') {
                   10626:         $container = $url;
1.987     raeburn  10627:     } else {
1.1027    raeburn  10628:         $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987     raeburn  10629:     }
                   10630:     my (%allfiles,%codebase,$output,$content);
                   10631:     my @changes = &get_env_multiple('form.namechange');
1.1075.2.35  raeburn  10632:     unless ((@changes > 0)  || ($context eq 'syllabus')) {
1.1071    raeburn  10633:         if (wantarray) {
                   10634:             return ('',0,0); 
                   10635:         } else {
                   10636:             return;
                   10637:         }
                   10638:     }
                   10639:     if (($context eq 'portfolio') || ($context eq 'coursedoc') || 
1.1075.2.35  raeburn  10640:         ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071    raeburn  10641:         unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
                   10642:             if (wantarray) {
                   10643:                 return ('',0,0);
                   10644:             } else {
                   10645:                 return;
                   10646:             }
                   10647:         } 
1.987     raeburn  10648:         $content = &Apache::lonnet::getfile($container);
1.1071    raeburn  10649:         if ($content eq '-1') {
                   10650:             if (wantarray) {
                   10651:                 return ('',0,0);
                   10652:             } else {
                   10653:                 return;
                   10654:             }
                   10655:         }
1.987     raeburn  10656:     } else {
1.1071    raeburn  10657:         unless ($container =~ /^\Q$dir_root\E/) {
                   10658:             if (wantarray) {
                   10659:                 return ('',0,0);
                   10660:             } else {
                   10661:                 return;
                   10662:             }
                   10663:         } 
1.987     raeburn  10664:         if (open(my $fh,"<$container")) {
                   10665:             $content = join('', <$fh>);
                   10666:             close($fh);
                   10667:         } else {
1.1071    raeburn  10668:             if (wantarray) {
                   10669:                 return ('',0,0);
                   10670:             } else {
                   10671:                 return;
                   10672:             }
1.987     raeburn  10673:         }
                   10674:     }
                   10675:     my ($count,$codebasecount) = (0,0);
                   10676:     my $mm = new File::MMagic;
                   10677:     my $mime_type = $mm->checktype_contents($content);
                   10678:     if ($mime_type eq 'text/html') {
                   10679:         my $parse_result = 
                   10680:             &Apache::lonnet::extract_embedded_items($container,\%allfiles,
                   10681:                                                     \%codebase,\$content);
                   10682:         if ($parse_result eq 'ok') {
                   10683:             foreach my $i (@changes) {
                   10684:                 my $orig = &unescape($env{'form.embedded_orig_'.$i});
                   10685:                 my $ref = &unescape($env{'form.embedded_ref_'.$i});
                   10686:                 if ($allfiles{$ref}) {
                   10687:                     my $newname =  $orig;
                   10688:                     my ($attrib_regexp,$codebase);
1.1006    raeburn  10689:                     $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987     raeburn  10690:                     if ($attrib_regexp =~ /:/) {
                   10691:                         $attrib_regexp =~ s/\:/|/g;
                   10692:                     }
                   10693:                     if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
                   10694:                         my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
                   10695:                         $count += $numchg;
1.1075.2.35  raeburn  10696:                         $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48  raeburn  10697:                         delete($allfiles{$ref});
1.987     raeburn  10698:                     }
                   10699:                     if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006    raeburn  10700:                         $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987     raeburn  10701:                         my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
                   10702:                         $codebasecount ++;
                   10703:                     }
                   10704:                 }
                   10705:             }
1.1075.2.35  raeburn  10706:             my $skiprewrites;
1.987     raeburn  10707:             if ($count || $codebasecount) {
                   10708:                 my $saveresult;
1.1071    raeburn  10709:                 if (($context eq 'portfolio') || ($context eq 'coursedoc') || 
1.1075.2.35  raeburn  10710:                     ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987     raeburn  10711:                     my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
                   10712:                     if ($url eq $container) {
                   10713:                         my ($fname) = ($container =~ m{/([^/]+)$});
                   10714:                         $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
                   10715:                                             $count,'<span class="LC_filename">'.
1.1071    raeburn  10716:                                             $fname.'</span>').'</p>';
1.987     raeburn  10717:                     } else {
                   10718:                          $output = '<p class="LC_error">'.
                   10719:                                    &mt('Error: update failed for: [_1].',
                   10720:                                    '<span class="LC_filename">'.
                   10721:                                    $container.'</span>').'</p>';
                   10722:                     }
1.1075.2.35  raeburn  10723:                     if ($context eq 'syllabus') {
                   10724:                         unless ($saveresult eq 'ok') {
                   10725:                             $skiprewrites = 1;
                   10726:                         }
                   10727:                     }
1.987     raeburn  10728:                 } else {
                   10729:                     if (open(my $fh,">$container")) {
                   10730:                         print $fh $content;
                   10731:                         close($fh);
                   10732:                         $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
                   10733:                                   $count,'<span class="LC_filename">'.
                   10734:                                   $container.'</span>').'</p>';
1.661     raeburn  10735:                     } else {
1.987     raeburn  10736:                          $output = '<p class="LC_error">'.
                   10737:                                    &mt('Error: could not update [_1].',
                   10738:                                    '<span class="LC_filename">'.
                   10739:                                    $container.'</span>').'</p>';
1.661     raeburn  10740:                     }
                   10741:                 }
                   10742:             }
1.1075.2.35  raeburn  10743:             if (($context eq 'syllabus') && (!$skiprewrites)) {
                   10744:                 my ($actionurl,$state);
                   10745:                 $actionurl = "/public/$udom/$uname/syllabus";
                   10746:                 my ($ignore,$num,$numpathchanges,$existing,$mapping) =
                   10747:                     &ask_for_embedded_content($actionurl,$state,\%allfiles,
                   10748:                                               \%codebase,
                   10749:                                               {'context' => 'rewrites',
                   10750:                                                'ignore_remote_references' => 1,});
                   10751:                 if (ref($mapping) eq 'HASH') {
                   10752:                     my $rewrites = 0;
                   10753:                     foreach my $key (keys(%{$mapping})) {
                   10754:                         next if ($key =~ m{^https?://});
                   10755:                         my $ref = $mapping->{$key};
                   10756:                         my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
                   10757:                         my $attrib;
                   10758:                         if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
                   10759:                             $attrib = join('|',@{$allfiles{$mapping->{$key}}});
                   10760:                         }
                   10761:                         if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
                   10762:                             my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
                   10763:                             $rewrites += $numchg;
                   10764:                         }
                   10765:                     }
                   10766:                     if ($rewrites) {
                   10767:                         my $saveresult;
                   10768:                         my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
                   10769:                         if ($url eq $container) {
                   10770:                             my ($fname) = ($container =~ m{/([^/]+)$});
                   10771:                             $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
                   10772:                                             $count,'<span class="LC_filename">'.
                   10773:                                             $fname.'</span>').'</p>';
                   10774:                         } else {
                   10775:                             $output .= '<p class="LC_error">'.
                   10776:                                        &mt('Error: could not update links in [_1].',
                   10777:                                        '<span class="LC_filename">'.
                   10778:                                        $container.'</span>').'</p>';
                   10779: 
                   10780:                         }
                   10781:                     }
                   10782:                 }
                   10783:             }
1.987     raeburn  10784:         } else {
                   10785:             &logthis('Failed to parse '.$container.
                   10786:                      ' to modify references: '.$parse_result);
1.661     raeburn  10787:         }
                   10788:     }
1.1071    raeburn  10789:     if (wantarray) {
                   10790:         return ($output,$count,$codebasecount);
                   10791:     } else {
                   10792:         return $output;
                   10793:     }
1.661     raeburn  10794: }
                   10795: 
                   10796: sub check_for_existing {
                   10797:     my ($path,$fname,$element) = @_;
                   10798:     my ($state,$msg);
                   10799:     if (-d $path.'/'.$fname) {
                   10800:         $state = 'exists';
                   10801:         $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   10802:     } elsif (-e $path.'/'.$fname) {
                   10803:         $state = 'exists';
                   10804:         $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   10805:     }
                   10806:     if ($state eq 'exists') {
                   10807:         $msg = '<span class="LC_error">'.$msg.'</span><br />';
                   10808:     }
                   10809:     return ($state,$msg);
                   10810: }
                   10811: 
                   10812: sub check_for_upload {
                   10813:     my ($path,$fname,$group,$element,$portfolio_root,$port_path,
                   10814:         $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985     raeburn  10815:     my $filesize = length($env{'form.'.$element});
                   10816:     if (!$filesize) {
                   10817:         my $msg = '<span class="LC_error">'.
                   10818:                   &mt('Unable to upload [_1]. (size = [_2] bytes)', 
                   10819:                       '<span class="LC_filename">'.$fname.'</span>',
                   10820:                       $filesize).'<br />'.
1.1007    raeburn  10821:                   &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985     raeburn  10822:                   '</span>';
                   10823:         return ('zero_bytes',$msg);
                   10824:     }
                   10825:     $filesize =  $filesize/1000; #express in k (1024?)
1.661     raeburn  10826:     my $getpropath = 1;
1.1021    raeburn  10827:     my ($dirlistref,$listerror) =
                   10828:          &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661     raeburn  10829:     my $found_file = 0;
                   10830:     my $locked_file = 0;
1.991     raeburn  10831:     my @lockers;
                   10832:     my $navmap;
                   10833:     if ($env{'request.course.id'}) {
                   10834:         $navmap = Apache::lonnavmaps::navmap->new();
                   10835:     }
1.1021    raeburn  10836:     if (ref($dirlistref) eq 'ARRAY') {
                   10837:         foreach my $line (@{$dirlistref}) {
                   10838:             my ($file_name,$rest)=split(/\&/,$line,2);
                   10839:             if ($file_name eq $fname){
                   10840:                 $file_name = $path.$file_name;
                   10841:                 if ($group ne '') {
                   10842:                     $file_name = $group.$file_name;
                   10843:                 }
                   10844:                 $found_file = 1;
                   10845:                 if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
                   10846:                     foreach my $lock (@lockers) {
                   10847:                         if (ref($lock) eq 'ARRAY') {
                   10848:                             my ($symb,$crsid) = @{$lock};
                   10849:                             if ($crsid eq $env{'request.course.id'}) {
                   10850:                                 if (ref($navmap)) {
                   10851:                                     my $res = $navmap->getBySymb($symb);
                   10852:                                     foreach my $part (@{$res->parts()}) { 
                   10853:                                         my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
                   10854:                                         unless (($slot_status == $res->RESERVED) ||
                   10855:                                                 ($slot_status == $res->RESERVED_LOCATION)) {
                   10856:                                             $locked_file = 1;
                   10857:                                         }
1.991     raeburn  10858:                                     }
1.1021    raeburn  10859:                                 } else {
                   10860:                                     $locked_file = 1;
1.991     raeburn  10861:                                 }
                   10862:                             } else {
                   10863:                                 $locked_file = 1;
                   10864:                             }
                   10865:                         }
1.1021    raeburn  10866:                    }
                   10867:                 } else {
                   10868:                     my @info = split(/\&/,$rest);
                   10869:                     my $currsize = $info[6]/1000;
                   10870:                     if ($currsize < $filesize) {
                   10871:                         my $extra = $filesize - $currsize;
                   10872:                         if (($current_disk_usage + $extra) > $disk_quota) {
                   10873:                             my $msg = '<span class="LC_error">'.
                   10874:                                       &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded if existing (smaller) file with same name (size = [_3] kilobytes) is replaced.',
                   10875:                                           '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</span>'.
                   10876:                                       '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
                   10877:                                                    $disk_quota,$current_disk_usage);
                   10878:                             return ('will_exceed_quota',$msg);
                   10879:                         }
1.984     raeburn  10880:                     }
                   10881:                 }
1.661     raeburn  10882:             }
                   10883:         }
                   10884:     }
                   10885:     if (($current_disk_usage + $filesize) > $disk_quota){
                   10886:         my $msg = '<span class="LC_error">'.
                   10887:                 &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
                   10888:                   '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
                   10889:         return ('will_exceed_quota',$msg);
                   10890:     } elsif ($found_file) {
                   10891:         if ($locked_file) {
                   10892:             my $msg = '<span class="LC_error">';
                   10893:             $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>');
                   10894:             $msg .= '</span><br />';
                   10895:             $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
                   10896:             return ('file_locked',$msg);
                   10897:         } else {
                   10898:             my $msg = '<span class="LC_error">';
1.984     raeburn  10899:             $msg .= &mt(' A file by that name: [_1] was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
1.661     raeburn  10900:             $msg .= '</span>';
1.984     raeburn  10901:             return ('existingfile',$msg);
1.661     raeburn  10902:         }
                   10903:     }
                   10904: }
                   10905: 
1.987     raeburn  10906: sub check_for_traversal {
                   10907:     my ($path,$url,$toplevel) = @_;
                   10908:     my @parts=split(/\//,$path);
                   10909:     my $cleanpath;
                   10910:     my $fullpath = $url;
                   10911:     for (my $i=0;$i<@parts;$i++) {
                   10912:         next if ($parts[$i] eq '.');
                   10913:         if ($parts[$i] eq '..') {
                   10914:             $fullpath =~ s{([^/]+/)$}{};
                   10915:         } else {
                   10916:             $fullpath .= $parts[$i].'/';
                   10917:         }
                   10918:     }
                   10919:     if ($fullpath =~ /^\Q$url\E(.*)$/) {
                   10920:         $cleanpath = $1;
                   10921:     } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
                   10922:         my $curr_toprel = $1;
                   10923:         my @parts = split(/\//,$curr_toprel);
                   10924:         my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
                   10925:         my @urlparts = split(/\//,$url_toprel);
                   10926:         my $doubledots;
                   10927:         my $startdiff = -1;
                   10928:         for (my $i=0; $i<@urlparts; $i++) {
                   10929:             if ($startdiff == -1) {
                   10930:                 unless ($urlparts[$i] eq $parts[$i]) {
                   10931:                     $startdiff = $i;
                   10932:                     $doubledots .= '../';
                   10933:                 }
                   10934:             } else {
                   10935:                 $doubledots .= '../';
                   10936:             }
                   10937:         }
                   10938:         if ($startdiff > -1) {
                   10939:             $cleanpath = $doubledots;
                   10940:             for (my $i=$startdiff; $i<@parts; $i++) {
                   10941:                 $cleanpath .= $parts[$i].'/';
                   10942:             }
                   10943:         }
                   10944:     }
                   10945:     $cleanpath =~ s{(/)$}{};
                   10946:     return $cleanpath;
                   10947: }
1.31      albertel 10948: 
1.1053    raeburn  10949: sub is_archive_file {
                   10950:     my ($mimetype) = @_;
                   10951:     if (($mimetype eq 'application/octet-stream') ||
                   10952:         ($mimetype eq 'application/x-stuffit') ||
                   10953:         ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
                   10954:         return 1;
                   10955:     }
                   10956:     return;
                   10957: }
                   10958: 
                   10959: sub decompress_form {
1.1065    raeburn  10960:     my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053    raeburn  10961:     my %lt = &Apache::lonlocal::texthash (
                   10962:         this => 'This file is an archive file.',
1.1067    raeburn  10963:         camt => 'This file is a Camtasia archive file.',
1.1065    raeburn  10964:         itsc => 'Its contents are as follows:',
1.1053    raeburn  10965:         youm => 'You may wish to extract its contents.',
                   10966:         extr => 'Extract contents',
1.1067    raeburn  10967:         auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
                   10968:         proa => 'Process automatically?',
1.1053    raeburn  10969:         yes  => 'Yes',
                   10970:         no   => 'No',
1.1067    raeburn  10971:         fold => 'Title for folder containing movie',
                   10972:         movi => 'Title for page containing embedded movie', 
1.1053    raeburn  10973:     );
1.1065    raeburn  10974:     my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067    raeburn  10975:     my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065    raeburn  10976:     my $info = &list_archive_contents($fileloc,\@paths);
                   10977:     if (@paths) {
                   10978:         foreach my $path (@paths) {
                   10979:             $path =~ s{^/}{};
1.1067    raeburn  10980:             if ($path =~ m{^([^/]+)/$}) {
                   10981:                 $topdir = $1;
                   10982:             }
1.1065    raeburn  10983:             if ($path =~ m{^([^/]+)/}) {
                   10984:                 $toplevel{$1} = $path;
                   10985:             } else {
                   10986:                 $toplevel{$path} = $path;
                   10987:             }
                   10988:         }
                   10989:     }
1.1067    raeburn  10990:     if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
                   10991:         my @camtasia = ("$topdir/","$topdir/index.html",
                   10992:                         "$topdir/media/",
                   10993:                         "$topdir/media/$topdir.mp4",
                   10994:                         "$topdir/media/FirstFrame.png",
                   10995:                         "$topdir/media/player.swf",
                   10996:                         "$topdir/media/swfobject.js",
                   10997:                         "$topdir/media/expressInstall.swf");
                   10998:         my @diffs = &compare_arrays(\@paths,\@camtasia);
                   10999:         if (@diffs == 0) {
                   11000:             $is_camtasia = 1;
                   11001:         }
                   11002:     }
                   11003:     my $output;
                   11004:     if ($is_camtasia) {
                   11005:         $output = <<"ENDCAM";
                   11006: <script type="text/javascript" language="Javascript">
                   11007: // <![CDATA[
                   11008: 
                   11009: function camtasiaToggle() {
                   11010:     for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
                   11011:         if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
                   11012:             if (document.uploaded_decompress.autoextract_camtasia[i].value == 1) {
                   11013: 
                   11014:                 document.getElementById('camtasia_titles').style.display='block';
                   11015:             } else {
                   11016:                 document.getElementById('camtasia_titles').style.display='none';
                   11017:             }
                   11018:         }
                   11019:     }
                   11020:     return;
                   11021: }
                   11022: 
                   11023: // ]]>
                   11024: </script>
                   11025: <p>$lt{'camt'}</p>
                   11026: ENDCAM
1.1065    raeburn  11027:     } else {
1.1067    raeburn  11028:         $output = '<p>'.$lt{'this'};
                   11029:         if ($info eq '') {
                   11030:             $output .= ' '.$lt{'youm'}.'</p>'."\n";
                   11031:         } else {
                   11032:             $output .= ' '.$lt{'itsc'}.'</p>'."\n".
                   11033:                        '<div><pre>'.$info.'</pre></div>';
                   11034:         }
1.1065    raeburn  11035:     }
1.1067    raeburn  11036:     $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065    raeburn  11037:     my $duplicates;
                   11038:     my $num = 0;
                   11039:     if (ref($dirlist) eq 'ARRAY') {
                   11040:         foreach my $item (@{$dirlist}) {
                   11041:             if (ref($item) eq 'ARRAY') {
                   11042:                 if (exists($toplevel{$item->[0]})) {
                   11043:                     $duplicates .= 
                   11044:                         &start_data_table_row().
                   11045:                         '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
                   11046:                         'value="0" checked="checked" />'.&mt('No').'</label>'.
                   11047:                         '&nbsp;<label><input type="radio" name="archive_overwrite_'.$num.'" '.
                   11048:                         'value="1" />'.&mt('Yes').'</label>'.
                   11049:                         '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
                   11050:                         '<td>'.$item->[0].'</td>';
                   11051:                     if ($item->[2]) {
                   11052:                         $duplicates .= '<td>'.&mt('Directory').'</td>';
                   11053:                     } else {
                   11054:                         $duplicates .= '<td>'.&mt('File').'</td>';
                   11055:                     }
                   11056:                     $duplicates .= '<td>'.$item->[3].'</td>'.
                   11057:                                    '<td>'.
                   11058:                                    &Apache::lonlocal::locallocaltime($item->[4]).
                   11059:                                    '</td>'.
                   11060:                                    &end_data_table_row();
                   11061:                     $num ++;
                   11062:                 }
                   11063:             }
                   11064:         }
                   11065:     }
                   11066:     my $itemcount;
                   11067:     if (@paths > 0) {
                   11068:         $itemcount = scalar(@paths);
                   11069:     } else {
                   11070:         $itemcount = 1;
                   11071:     }
1.1067    raeburn  11072:     if ($is_camtasia) {
                   11073:         $output .= $lt{'auto'}.'<br />'.
                   11074:                    '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
                   11075:                    '<input type="radio" name="autoextract_camtasia" value="1" onclick="javascript:camtasiaToggle();" checked="checked" />'.
                   11076:                    $lt{'yes'}.'</label>&nbsp;<label>'.
                   11077:                    '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
                   11078:                    $lt{'no'}.'</label></span><br />'.
                   11079:                    '<div id="camtasia_titles" style="display:block">'.
                   11080:                    &Apache::lonhtmlcommon::start_pick_box().
                   11081:                    &Apache::lonhtmlcommon::row_title($lt{'fold'}).
                   11082:                    '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
                   11083:                    &Apache::lonhtmlcommon::row_closure().
                   11084:                    &Apache::lonhtmlcommon::row_title($lt{'movi'}).
                   11085:                    '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
                   11086:                    &Apache::lonhtmlcommon::row_closure(1).
                   11087:                    &Apache::lonhtmlcommon::end_pick_box().
                   11088:                    '</div>';
                   11089:     }
1.1065    raeburn  11090:     $output .= 
                   11091:         '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067    raeburn  11092:         '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
                   11093:         "\n";
1.1065    raeburn  11094:     if ($duplicates ne '') {
                   11095:         $output .= '<p><span class="LC_warning">'.
                   11096:                    &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.  
                   11097:                    &start_data_table().
                   11098:                    &start_data_table_header_row().
                   11099:                    '<th>'.&mt('Overwrite?').'</th>'.
                   11100:                    '<th>'.&mt('Name').'</th>'.
                   11101:                    '<th>'.&mt('Type').'</th>'.
                   11102:                    '<th>'.&mt('Size').'</th>'.
                   11103:                    '<th>'.&mt('Last modified').'</th>'.
                   11104:                    &end_data_table_header_row().
                   11105:                    $duplicates.
                   11106:                    &end_data_table().
                   11107:                    '</p>';
                   11108:     }
1.1067    raeburn  11109:     $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053    raeburn  11110:     if (ref($hiddenelements) eq 'HASH') {
                   11111:         foreach my $hidden (sort(keys(%{$hiddenelements}))) {
                   11112:             $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
                   11113:         }
                   11114:     }
                   11115:     $output .= <<"END";
1.1067    raeburn  11116: <br />
1.1053    raeburn  11117: <input type="submit" name="decompress" value="$lt{'extr'}" />
                   11118: </form>
                   11119: $noextract
                   11120: END
                   11121:     return $output;
                   11122: }
                   11123: 
1.1065    raeburn  11124: sub decompression_utility {
                   11125:     my ($program) = @_;
                   11126:     my @utilities = ('tar','gunzip','bunzip2','unzip'); 
                   11127:     my $location;
                   11128:     if (grep(/^\Q$program\E$/,@utilities)) { 
                   11129:         foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
                   11130:                          '/usr/sbin/') {
                   11131:             if (-x $dir.$program) {
                   11132:                 $location = $dir.$program;
                   11133:                 last;
                   11134:             }
                   11135:         }
                   11136:     }
                   11137:     return $location;
                   11138: }
                   11139: 
                   11140: sub list_archive_contents {
                   11141:     my ($file,$pathsref) = @_;
                   11142:     my (@cmd,$output);
                   11143:     my $needsregexp;
                   11144:     if ($file =~ /\.zip$/) {
                   11145:         @cmd = (&decompression_utility('unzip'),"-l");
                   11146:         $needsregexp = 1;
                   11147:     } elsif (($file =~ m/\.tar\.gz$/) ||
                   11148:              ($file =~ /\.tgz$/)) {
                   11149:         @cmd = (&decompression_utility('tar'),"-ztf");
                   11150:     } elsif ($file =~ /\.tar\.bz2$/) {
                   11151:         @cmd = (&decompression_utility('tar'),"-jtf");
                   11152:     } elsif ($file =~ m|\.tar$|) {
                   11153:         @cmd = (&decompression_utility('tar'),"-tf");
                   11154:     }
                   11155:     if (@cmd) {
                   11156:         undef($!);
                   11157:         undef($@);
                   11158:         if (open(my $fh,"-|", @cmd, $file)) {
                   11159:             while (my $line = <$fh>) {
                   11160:                 $output .= $line;
                   11161:                 chomp($line);
                   11162:                 my $item;
                   11163:                 if ($needsregexp) {
                   11164:                     ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/); 
                   11165:                 } else {
                   11166:                     $item = $line;
                   11167:                 }
                   11168:                 if ($item ne '') {
                   11169:                     unless (grep(/^\Q$item\E$/,@{$pathsref})) {
                   11170:                         push(@{$pathsref},$item);
                   11171:                     } 
                   11172:                 }
                   11173:             }
                   11174:             close($fh);
                   11175:         }
                   11176:     }
                   11177:     return $output;
                   11178: }
                   11179: 
1.1053    raeburn  11180: sub decompress_uploaded_file {
                   11181:     my ($file,$dir) = @_;
                   11182:     &Apache::lonnet::appenv({'cgi.file' => $file});
                   11183:     &Apache::lonnet::appenv({'cgi.dir' => $dir});
                   11184:     my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
                   11185:     my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
                   11186:     my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
                   11187:     &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
                   11188:     my $decompressed = $env{'cgi.decompressed'};
                   11189:     &Apache::lonnet::delenv('cgi.file');
                   11190:     &Apache::lonnet::delenv('cgi.dir');
                   11191:     &Apache::lonnet::delenv('cgi.decompressed');
                   11192:     return ($decompressed,$result);
                   11193: }
                   11194: 
1.1055    raeburn  11195: sub process_decompression {
                   11196:     my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
                   11197:     my ($dir,$error,$warning,$output);
                   11198:     if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
1.1075.2.34  raeburn  11199:         $error = &mt('Filename not a supported archive file type.').
                   11200:                  '<br />'.&mt('Filename should end with one of: [_1].',
1.1055    raeburn  11201:                               '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
                   11202:     } else {
                   11203:         my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
                   11204:         if ($docuhome eq 'no_host') {
                   11205:             $error = &mt('Could not determine home server for course.');
                   11206:         } else {
                   11207:             my @ids=&Apache::lonnet::current_machine_ids();
                   11208:             my $currdir = "$dir_root/$destination";
                   11209:             if (grep(/^\Q$docuhome\E$/,@ids)) {
                   11210:                 $dir = &LONCAPA::propath($docudom,$docuname).
                   11211:                        "$dir_root/$destination";
                   11212:             } else {
                   11213:                 $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
                   11214:                        "$dir_root/$docudom/$docuname/$destination";
                   11215:                 unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
                   11216:                     $error = &mt('Archive file not found.');
                   11217:                 }
                   11218:             }
1.1065    raeburn  11219:             my (@to_overwrite,@to_skip);
                   11220:             if ($env{'form.archive_overwrite_total'} > 0) {
                   11221:                 my $total = $env{'form.archive_overwrite_total'};
                   11222:                 for (my $i=0; $i<$total; $i++) {
                   11223:                     if ($env{'form.archive_overwrite_'.$i} == 1) {
                   11224:                         push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
                   11225:                     } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
                   11226:                         push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
                   11227:                     }
                   11228:                 }
                   11229:             }
                   11230:             my $numskip = scalar(@to_skip);
                   11231:             if (($numskip > 0) && 
                   11232:                 ($numskip == $env{'form.archive_itemcount'})) {
                   11233:                 $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');         
                   11234:             } elsif ($dir eq '') {
1.1055    raeburn  11235:                 $error = &mt('Directory containing archive file unavailable.');
                   11236:             } elsif (!$error) {
1.1065    raeburn  11237:                 my ($decompressed,$display);
                   11238:                 if ($numskip > 0) {
                   11239:                     my $tempdir = time.'_'.$$.int(rand(10000));
                   11240:                     mkdir("$dir/$tempdir",0755);
                   11241:                     system("mv $dir/$file $dir/$tempdir/$file");
                   11242:                     ($decompressed,$display) = 
                   11243:                         &decompress_uploaded_file($file,"$dir/$tempdir");
                   11244:                     foreach my $item (@to_skip) {
                   11245:                         if (($item ne '') && ($item !~ /\.\./)) {
                   11246:                             if (-f "$dir/$tempdir/$item") { 
                   11247:                                 unlink("$dir/$tempdir/$item");
                   11248:                             } elsif (-d "$dir/$tempdir/$item") {
                   11249:                                 system("rm -rf $dir/$tempdir/$item");
                   11250:                             }
                   11251:                         }
                   11252:                     }
                   11253:                     system("mv $dir/$tempdir/* $dir");
                   11254:                     rmdir("$dir/$tempdir");   
                   11255:                 } else {
                   11256:                     ($decompressed,$display) = 
                   11257:                         &decompress_uploaded_file($file,$dir);
                   11258:                 }
1.1055    raeburn  11259:                 if ($decompressed eq 'ok') {
1.1065    raeburn  11260:                     $output = '<p class="LC_info">'.
                   11261:                               &mt('Files extracted successfully from archive.').
                   11262:                               '</p>'."\n";
1.1055    raeburn  11263:                     my ($warning,$result,@contents);
                   11264:                     my ($newdirlistref,$newlisterror) =
                   11265:                         &Apache::lonnet::dirlist($currdir,$docudom,
                   11266:                                                  $docuname,1);
                   11267:                     my (%is_dir,%changes,@newitems);
                   11268:                     my $dirptr = 16384;
1.1065    raeburn  11269:                     if (ref($newdirlistref) eq 'ARRAY') {
1.1055    raeburn  11270:                         foreach my $dir_line (@{$newdirlistref}) {
                   11271:                             my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065    raeburn  11272:                             unless (($item =~ /^\.+$/) || ($item eq $file) || 
                   11273:                                     ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055    raeburn  11274:                                 push(@newitems,$item);
                   11275:                                 if ($dirptr&$testdir) {
                   11276:                                     $is_dir{$item} = 1;
                   11277:                                 }
                   11278:                                 $changes{$item} = 1;
                   11279:                             }
                   11280:                         }
                   11281:                     }
                   11282:                     if (keys(%changes) > 0) {
                   11283:                         foreach my $item (sort(@newitems)) {
                   11284:                             if ($changes{$item}) {
                   11285:                                 push(@contents,$item);
                   11286:                             }
                   11287:                         }
                   11288:                     }
                   11289:                     if (@contents > 0) {
1.1067    raeburn  11290:                         my $wantform;
                   11291:                         unless ($env{'form.autoextract_camtasia'}) {
                   11292:                             $wantform = 1;
                   11293:                         }
1.1056    raeburn  11294:                         my (%children,%parent,%dirorder,%titles);
1.1055    raeburn  11295:                         my ($count,$datatable) = &get_extracted($docudom,$docuname,
                   11296:                                                                 $currdir,\%is_dir,
                   11297:                                                                 \%children,\%parent,
1.1056    raeburn  11298:                                                                 \@contents,\%dirorder,
                   11299:                                                                 \%titles,$wantform);
1.1055    raeburn  11300:                         if ($datatable ne '') {
                   11301:                             $output .= &archive_options_form('decompressed',$datatable,
                   11302:                                                              $count,$hiddenelem);
1.1065    raeburn  11303:                             my $startcount = 6;
1.1055    raeburn  11304:                             $output .= &archive_javascript($startcount,$count,
1.1056    raeburn  11305:                                                            \%titles,\%children);
1.1055    raeburn  11306:                         }
1.1067    raeburn  11307:                         if ($env{'form.autoextract_camtasia'}) {
                   11308:                             my %displayed;
                   11309:                             my $total = 1;
                   11310:                             $env{'form.archive_directory'} = [];
                   11311:                             foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
                   11312:                                 my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
                   11313:                                 $path =~ s{/$}{};
                   11314:                                 my $item;
                   11315:                                 if ($path ne '') {
                   11316:                                     $item = "$path/$titles{$i}";
                   11317:                                 } else {
                   11318:                                     $item = $titles{$i};
                   11319:                                 }
                   11320:                                 $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
                   11321:                                 if ($item eq $contents[0]) {
                   11322:                                     push(@{$env{'form.archive_directory'}},$i);
                   11323:                                     $env{'form.archive_'.$i} = 'display';
                   11324:                                     $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
                   11325:                                     $displayed{'folder'} = $i;
                   11326:                                 } elsif ($item eq "$contents[0]/index.html") {
                   11327:                                     $env{'form.archive_'.$i} = 'display';
                   11328:                                     $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
                   11329:                                     $displayed{'web'} = $i;
                   11330:                                 } else {
                   11331:                                     if ($item eq "$contents[0]/media") {
                   11332:                                         push(@{$env{'form.archive_directory'}},$i);
                   11333:                                     }
                   11334:                                     $env{'form.archive_'.$i} = 'dependency';
                   11335:                                 }
                   11336:                                 $total ++;
                   11337:                             }
                   11338:                             for (my $i=1; $i<$total; $i++) {
                   11339:                                 next if ($i == $displayed{'web'});
                   11340:                                 next if ($i == $displayed{'folder'});
                   11341:                                 $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
                   11342:                             }
                   11343:                             $env{'form.phase'} = 'decompress_cleanup';
                   11344:                             $env{'form.archivedelete'} = 1;
                   11345:                             $env{'form.archive_count'} = $total-1;
                   11346:                             $output .=
                   11347:                                 &process_extracted_files('coursedocs',$docudom,
                   11348:                                                          $docuname,$destination,
                   11349:                                                          $dir_root,$hiddenelem);
                   11350:                         }
1.1055    raeburn  11351:                     } else {
                   11352:                         $warning = &mt('No new items extracted from archive file.');
                   11353:                     }
                   11354:                 } else {
                   11355:                     $output = $display;
                   11356:                     $error = &mt('An error occurred during extraction from the archive file.');
                   11357:                 }
                   11358:             }
                   11359:         }
                   11360:     }
                   11361:     if ($error) {
                   11362:         $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
                   11363:                    $error.'</p>'."\n";
                   11364:     }
                   11365:     if ($warning) {
                   11366:         $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
                   11367:     }
                   11368:     return $output;
                   11369: }
                   11370: 
                   11371: sub get_extracted {
1.1056    raeburn  11372:     my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
                   11373:         $titles,$wantform) = @_;
1.1055    raeburn  11374:     my $count = 0;
                   11375:     my $depth = 0;
                   11376:     my $datatable;
1.1056    raeburn  11377:     my @hierarchy;
1.1055    raeburn  11378:     return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056    raeburn  11379:                    (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
                   11380:                    (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055    raeburn  11381:     foreach my $item (@{$contents}) {
                   11382:         $count ++;
1.1056    raeburn  11383:         @{$dirorder->{$count}} = @hierarchy;
                   11384:         $titles->{$count} = $item;
1.1055    raeburn  11385:         &archive_hierarchy($depth,$count,$parent,$children);
                   11386:         if ($wantform) {
                   11387:             $datatable .= &archive_row($is_dir->{$item},$item,
                   11388:                                        $currdir,$depth,$count);
                   11389:         }
                   11390:         if ($is_dir->{$item}) {
                   11391:             $depth ++;
1.1056    raeburn  11392:             push(@hierarchy,$count);
                   11393:             $parent->{$depth} = $count;
1.1055    raeburn  11394:             $datatable .=
                   11395:                 &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056    raeburn  11396:                                            \$depth,\$count,\@hierarchy,$dirorder,
                   11397:                                            $children,$parent,$titles,$wantform);
1.1055    raeburn  11398:             $depth --;
1.1056    raeburn  11399:             pop(@hierarchy);
1.1055    raeburn  11400:         }
                   11401:     }
                   11402:     return ($count,$datatable);
                   11403: }
                   11404: 
                   11405: sub recurse_extracted_archive {
1.1056    raeburn  11406:     my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
                   11407:         $children,$parent,$titles,$wantform) = @_;
1.1055    raeburn  11408:     my $result='';
1.1056    raeburn  11409:     unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
                   11410:             (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
                   11411:             (ref($dirorder) eq 'HASH')) {
1.1055    raeburn  11412:         return $result;
                   11413:     }
                   11414:     my $dirptr = 16384;
                   11415:     my ($newdirlistref,$newlisterror) =
                   11416:         &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
                   11417:     if (ref($newdirlistref) eq 'ARRAY') {
                   11418:         foreach my $dir_line (@{$newdirlistref}) {
                   11419:             my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
                   11420:             unless ($item =~ /^\.+$/) {
                   11421:                 $$count ++;
1.1056    raeburn  11422:                 @{$dirorder->{$$count}} = @{$hierarchy};
                   11423:                 $titles->{$$count} = $item;
1.1055    raeburn  11424:                 &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056    raeburn  11425: 
1.1055    raeburn  11426:                 my $is_dir;
                   11427:                 if ($dirptr&$testdir) {
                   11428:                     $is_dir = 1;
                   11429:                 }
                   11430:                 if ($wantform) {
                   11431:                     $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
                   11432:                 }
                   11433:                 if ($is_dir) {
                   11434:                     $$depth ++;
1.1056    raeburn  11435:                     push(@{$hierarchy},$$count);
                   11436:                     $parent->{$$depth} = $$count;
1.1055    raeburn  11437:                     $result .=
                   11438:                         &recurse_extracted_archive("$currdir/$item",$docudom,
                   11439:                                                    $docuname,$depth,$count,
1.1056    raeburn  11440:                                                    $hierarchy,$dirorder,$children,
                   11441:                                                    $parent,$titles,$wantform);
1.1055    raeburn  11442:                     $$depth --;
1.1056    raeburn  11443:                     pop(@{$hierarchy});
1.1055    raeburn  11444:                 }
                   11445:             }
                   11446:         }
                   11447:     }
                   11448:     return $result;
                   11449: }
                   11450: 
                   11451: sub archive_hierarchy {
                   11452:     my ($depth,$count,$parent,$children) =@_;
                   11453:     if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
                   11454:         if (exists($parent->{$depth})) {
                   11455:              $children->{$parent->{$depth}} .= $count.':';
                   11456:         }
                   11457:     }
                   11458:     return;
                   11459: }
                   11460: 
                   11461: sub archive_row {
                   11462:     my ($is_dir,$item,$currdir,$depth,$count) = @_;
                   11463:     my ($name) = ($item =~ m{([^/]+)$});
                   11464:     my %choices = &Apache::lonlocal::texthash (
1.1059    raeburn  11465:                                        'display'    => 'Add as file',
1.1055    raeburn  11466:                                        'dependency' => 'Include as dependency',
                   11467:                                        'discard'    => 'Discard',
                   11468:                                       );
                   11469:     if ($is_dir) {
1.1059    raeburn  11470:         $choices{'display'} = &mt('Add as folder'); 
1.1055    raeburn  11471:     }
1.1056    raeburn  11472:     my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
                   11473:     my $offset = 0;
1.1055    raeburn  11474:     foreach my $action ('display','dependency','discard') {
1.1056    raeburn  11475:         $offset ++;
1.1065    raeburn  11476:         if ($action ne 'display') {
                   11477:             $offset ++;
                   11478:         }  
1.1055    raeburn  11479:         $output .= '<td><span class="LC_nobreak">'.
                   11480:                    '<label><input type="radio" name="archive_'.$count.
                   11481:                    '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
                   11482:         my $text = $choices{$action};
                   11483:         if ($is_dir) {
                   11484:             $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
                   11485:             if ($action eq 'display') {
1.1059    raeburn  11486:                 $text = &mt('Add as folder');
1.1055    raeburn  11487:             }
1.1056    raeburn  11488:         } else {
                   11489:             $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
                   11490: 
                   11491:         }
                   11492:         $output .= ' />&nbsp;'.$choices{$action}.'</label></span>';
                   11493:         if ($action eq 'dependency') {
                   11494:             $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
                   11495:                        &mt('Used by:').'&nbsp;<select name="archive_dependent_on_'.$count.'" '.
                   11496:                        'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
                   11497:                        '<option value=""></option>'."\n".
                   11498:                        '</select>'."\n".
                   11499:                        '</div>';
1.1059    raeburn  11500:         } elsif ($action eq 'display') {
                   11501:             $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
                   11502:                        &mt('Title:').'&nbsp;<input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
                   11503:                        '</div>';
1.1055    raeburn  11504:         }
1.1056    raeburn  11505:         $output .= '</td>';
1.1055    raeburn  11506:     }
                   11507:     $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
                   11508:                &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.('&nbsp;' x 2);
                   11509:     for (my $i=0; $i<$depth; $i++) {
                   11510:         $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
                   11511:     }
                   11512:     if ($is_dir) {
                   11513:         $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" />&nbsp;'."\n".
                   11514:                    '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
                   11515:     } else {
                   11516:         $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
                   11517:     }
                   11518:     $output .= '&nbsp;'.$name.'</td>'."\n".
                   11519:                &end_data_table_row();
                   11520:     return $output;
                   11521: }
                   11522: 
                   11523: sub archive_options_form {
1.1065    raeburn  11524:     my ($form,$display,$count,$hiddenelem) = @_;
                   11525:     my %lt = &Apache::lonlocal::texthash(
                   11526:                perm => 'Permanently remove archive file?',
                   11527:                hows => 'How should each extracted item be incorporated in the course?',
                   11528:                cont => 'Content actions for all',
                   11529:                addf => 'Add as folder/file',
                   11530:                incd => 'Include as dependency for a displayed file',
                   11531:                disc => 'Discard',
                   11532:                no   => 'No',
                   11533:                yes  => 'Yes',
                   11534:                save => 'Save',
                   11535:     );
                   11536:     my $output = <<"END";
                   11537: <form name="$form" method="post" action="">
                   11538: <p><span class="LC_nobreak">$lt{'perm'}&nbsp;
                   11539: <label>
                   11540:   <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
                   11541: </label>
                   11542: &nbsp;
                   11543: <label>
                   11544:   <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
                   11545: </span>
                   11546: </p>
                   11547: <input type="hidden" name="phase" value="decompress_cleanup" />
                   11548: <br />$lt{'hows'}
                   11549: <div class="LC_columnSection">
                   11550:   <fieldset>
                   11551:     <legend>$lt{'cont'}</legend>
                   11552:     <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" /> 
                   11553:     &nbsp;&nbsp;<input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
                   11554:     &nbsp;&nbsp;<input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
                   11555:   </fieldset>
                   11556: </div>
                   11557: END
                   11558:     return $output.
1.1055    raeburn  11559:            &start_data_table()."\n".
1.1065    raeburn  11560:            $display."\n".
1.1055    raeburn  11561:            &end_data_table()."\n".
                   11562:            '<input type="hidden" name="archive_count" value="'.$count.'" />'.
                   11563:            $hiddenelem.
1.1065    raeburn  11564:            '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055    raeburn  11565:            '</form>';
                   11566: }
                   11567: 
                   11568: sub archive_javascript {
1.1056    raeburn  11569:     my ($startcount,$numitems,$titles,$children) = @_;
                   11570:     return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059    raeburn  11571:     my $maintitle = $env{'form.comment'};
1.1055    raeburn  11572:     my $scripttag = <<START;
                   11573: <script type="text/javascript">
                   11574: // <![CDATA[
                   11575: 
                   11576: function checkAll(form,prefix) {
                   11577:     var idstr =  new RegExp("^archive_"+prefix+"_\\\\d+\$");
                   11578:     for (var i=0; i < form.elements.length; i++) {
                   11579:         var id = form.elements[i].id;
                   11580:         if ((id != '') && (id != undefined)) {
                   11581:             if (idstr.test(id)) {
                   11582:                 if (form.elements[i].type == 'radio') {
                   11583:                     form.elements[i].checked = true;
1.1056    raeburn  11584:                     var nostart = i-$startcount;
1.1059    raeburn  11585:                     var offset = nostart%7;
                   11586:                     var count = (nostart-offset)/7;    
1.1056    raeburn  11587:                     dependencyCheck(form,count,offset);
1.1055    raeburn  11588:                 }
                   11589:             }
                   11590:         }
                   11591:     }
                   11592: }
                   11593: 
                   11594: function propagateCheck(form,count) {
                   11595:     if (count > 0) {
1.1059    raeburn  11596:         var startelement = $startcount + ((count-1) * 7);
                   11597:         for (var j=1; j<6; j++) {
                   11598:             if ((j != 2) && (j != 4)) {
1.1056    raeburn  11599:                 var item = startelement + j; 
                   11600:                 if (form.elements[item].type == 'radio') {
                   11601:                     if (form.elements[item].checked) {
                   11602:                         containerCheck(form,count,j);
                   11603:                         break;
                   11604:                     }
1.1055    raeburn  11605:                 }
                   11606:             }
                   11607:         }
                   11608:     }
                   11609: }
                   11610: 
                   11611: numitems = $numitems
1.1056    raeburn  11612: var titles = new Array(numitems);
                   11613: var parents = new Array(numitems);
1.1055    raeburn  11614: for (var i=0; i<numitems; i++) {
1.1056    raeburn  11615:     parents[i] = new Array;
1.1055    raeburn  11616: }
1.1059    raeburn  11617: var maintitle = '$maintitle';
1.1055    raeburn  11618: 
                   11619: START
                   11620: 
1.1056    raeburn  11621:     foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
                   11622:         my @contents = split(/:/,$children->{$container});
1.1055    raeburn  11623:         for (my $i=0; $i<@contents; $i ++) {
                   11624:             $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
                   11625:         }
                   11626:     }
                   11627: 
1.1056    raeburn  11628:     foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
                   11629:         $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
                   11630:     }
                   11631: 
1.1055    raeburn  11632:     $scripttag .= <<END;
                   11633: 
                   11634: function containerCheck(form,count,offset) {
                   11635:     if (count > 0) {
1.1056    raeburn  11636:         dependencyCheck(form,count,offset);
1.1059    raeburn  11637:         var item = (offset+$startcount)+7*(count-1);
1.1055    raeburn  11638:         form.elements[item].checked = true;
                   11639:         if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
                   11640:             if (parents[count].length > 0) {
                   11641:                 for (var j=0; j<parents[count].length; j++) {
1.1056    raeburn  11642:                     containerCheck(form,parents[count][j],offset);
                   11643:                 }
                   11644:             }
                   11645:         }
                   11646:     }
                   11647: }
                   11648: 
                   11649: function dependencyCheck(form,count,offset) {
                   11650:     if (count > 0) {
1.1059    raeburn  11651:         var chosen = (offset+$startcount)+7*(count-1);
                   11652:         var depitem = $startcount + ((count-1) * 7) + 4;
1.1056    raeburn  11653:         var currtype = form.elements[depitem].type;
                   11654:         if (form.elements[chosen].value == 'dependency') {
                   11655:             document.getElementById('arc_depon_'+count).style.display='block'; 
                   11656:             form.elements[depitem].options.length = 0;
                   11657:             form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11  raeburn  11658:             for (var i=1; i<=numitems; i++) {
                   11659:                 if (i == count) {
                   11660:                     continue;
                   11661:                 }
1.1059    raeburn  11662:                 var startelement = $startcount + (i-1) * 7;
                   11663:                 for (var j=1; j<6; j++) {
                   11664:                     if ((j != 2) && (j!= 4)) {
1.1056    raeburn  11665:                         var item = startelement + j;
                   11666:                         if (form.elements[item].type == 'radio') {
                   11667:                             if (form.elements[item].checked) {
                   11668:                                 if (form.elements[item].value == 'display') {
                   11669:                                     var n = form.elements[depitem].options.length;
                   11670:                                     form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
                   11671:                                 }
                   11672:                             }
                   11673:                         }
                   11674:                     }
                   11675:                 }
                   11676:             }
                   11677:         } else {
                   11678:             document.getElementById('arc_depon_'+count).style.display='none';
                   11679:             form.elements[depitem].options.length = 0;
                   11680:             form.elements[depitem].options[0] = new Option('Select','',true,true);
                   11681:         }
1.1059    raeburn  11682:         titleCheck(form,count,offset);
1.1056    raeburn  11683:     }
                   11684: }
                   11685: 
                   11686: function propagateSelect(form,count,offset) {
                   11687:     if (count > 0) {
1.1065    raeburn  11688:         var item = (1+offset+$startcount)+7*(count-1);
1.1056    raeburn  11689:         var picked = form.elements[item].options[form.elements[item].selectedIndex].value; 
                   11690:         if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
                   11691:             if (parents[count].length > 0) {
                   11692:                 for (var j=0; j<parents[count].length; j++) {
                   11693:                     containerSelect(form,parents[count][j],offset,picked);
1.1055    raeburn  11694:                 }
                   11695:             }
                   11696:         }
                   11697:     }
                   11698: }
1.1056    raeburn  11699: 
                   11700: function containerSelect(form,count,offset,picked) {
                   11701:     if (count > 0) {
1.1065    raeburn  11702:         var item = (offset+$startcount)+7*(count-1);
1.1056    raeburn  11703:         if (form.elements[item].type == 'radio') {
                   11704:             if (form.elements[item].value == 'dependency') {
                   11705:                 if (form.elements[item+1].type == 'select-one') {
                   11706:                     for (var i=0; i<form.elements[item+1].options.length; i++) {
                   11707:                         if (form.elements[item+1].options[i].value == picked) {
                   11708:                             form.elements[item+1].selectedIndex = i;
                   11709:                             break;
                   11710:                         }
                   11711:                     }
                   11712:                 }
                   11713:                 if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
                   11714:                     if (parents[count].length > 0) {
                   11715:                         for (var j=0; j<parents[count].length; j++) {
                   11716:                             containerSelect(form,parents[count][j],offset,picked);
                   11717:                         }
                   11718:                     }
                   11719:                 }
                   11720:             }
                   11721:         }
                   11722:     }
                   11723: }
                   11724: 
1.1059    raeburn  11725: function titleCheck(form,count,offset) {
                   11726:     if (count > 0) {
                   11727:         var chosen = (offset+$startcount)+7*(count-1);
                   11728:         var depitem = $startcount + ((count-1) * 7) + 2;
                   11729:         var currtype = form.elements[depitem].type;
                   11730:         if (form.elements[chosen].value == 'display') {
                   11731:             document.getElementById('arc_title_'+count).style.display='block';
                   11732:             if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
                   11733:                 document.getElementById('archive_title_'+count).value=maintitle;
                   11734:             }
                   11735:         } else {
                   11736:             document.getElementById('arc_title_'+count).style.display='none';
                   11737:             if (currtype == 'text') { 
                   11738:                 document.getElementById('archive_title_'+count).value='';
                   11739:             }
                   11740:         }
                   11741:     }
                   11742:     return;
                   11743: }
                   11744: 
1.1055    raeburn  11745: // ]]>
                   11746: </script>
                   11747: END
                   11748:     return $scripttag;
                   11749: }
                   11750: 
                   11751: sub process_extracted_files {
1.1067    raeburn  11752:     my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055    raeburn  11753:     my $numitems = $env{'form.archive_count'};
                   11754:     return unless ($numitems);
                   11755:     my @ids=&Apache::lonnet::current_machine_ids();
                   11756:     my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067    raeburn  11757:         %folders,%containers,%mapinner,%prompttofetch);
1.1055    raeburn  11758:     my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
                   11759:     if (grep(/^\Q$docuhome\E$/,@ids)) {
                   11760:         $prefix = &LONCAPA::propath($docudom,$docuname);
                   11761:         $pathtocheck = "$dir_root/$destination";
                   11762:         $dir = $dir_root;
                   11763:         $ishome = 1;
                   11764:     } else {
                   11765:         $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
                   11766:         $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
                   11767:         $dir = "$dir_root/$docudom/$docuname";    
                   11768:     }
                   11769:     my $currdir = "$dir_root/$destination";
                   11770:     (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
                   11771:     if ($env{'form.folderpath'}) {
                   11772:         my @items = split('&',$env{'form.folderpath'});
                   11773:         $folders{'0'} = $items[-2];
1.1075.2.17  raeburn  11774:         if ($env{'form.folderpath'} =~ /\:1$/) {
                   11775:             $containers{'0'}='page';
                   11776:         } else {
                   11777:             $containers{'0'}='sequence';
                   11778:         }
1.1055    raeburn  11779:     }
                   11780:     my @archdirs = &get_env_multiple('form.archive_directory');
                   11781:     if ($numitems) {
                   11782:         for (my $i=1; $i<=$numitems; $i++) {
                   11783:             my $path = $env{'form.archive_content_'.$i};
                   11784:             if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
                   11785:                 my $item = $1;
                   11786:                 $toplevelitems{$item} = $i;
                   11787:                 if (grep(/^\Q$i\E$/,@archdirs)) {
                   11788:                     $is_dir{$item} = 1;
                   11789:                 }
                   11790:             }
                   11791:         }
                   11792:     }
1.1067    raeburn  11793:     my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055    raeburn  11794:     if (keys(%toplevelitems) > 0) {
                   11795:         my @contents = sort(keys(%toplevelitems));
1.1056    raeburn  11796:         (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
                   11797:                                            \%parent,\@contents,\%dirorder,\%titles);
1.1055    raeburn  11798:     }
1.1066    raeburn  11799:     my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055    raeburn  11800:     if ($numitems) {
                   11801:         for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11  raeburn  11802:             next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055    raeburn  11803:             my $path = $env{'form.archive_content_'.$i};
                   11804:             if ($path =~ /^\Q$pathtocheck\E/) {
                   11805:                 if ($env{'form.archive_'.$i} eq 'discard') {
                   11806:                     if ($prefix ne '' && $path ne '') {
                   11807:                         if (-e $prefix.$path) {
1.1066    raeburn  11808:                             if ((@archdirs > 0) && 
                   11809:                                 (grep(/^\Q$i\E$/,@archdirs))) {
                   11810:                                 $todeletedir{$prefix.$path} = 1;
                   11811:                             } else {
                   11812:                                 $todelete{$prefix.$path} = 1;
                   11813:                             }
1.1055    raeburn  11814:                         }
                   11815:                     }
                   11816:                 } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059    raeburn  11817:                     my ($docstitle,$title,$url,$outer);
1.1055    raeburn  11818:                     ($title) = ($path =~ m{/([^/]+)$});
1.1059    raeburn  11819:                     $docstitle = $env{'form.archive_title_'.$i};
                   11820:                     if ($docstitle eq '') {
                   11821:                         $docstitle = $title;
                   11822:                     }
1.1055    raeburn  11823:                     $outer = 0;
1.1056    raeburn  11824:                     if (ref($dirorder{$i}) eq 'ARRAY') {
                   11825:                         if (@{$dirorder{$i}} > 0) {
                   11826:                             foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055    raeburn  11827:                                 if ($env{'form.archive_'.$item} eq 'display') {
                   11828:                                     $outer = $item;
                   11829:                                     last;
                   11830:                                 }
                   11831:                             }
                   11832:                         }
                   11833:                     }
                   11834:                     my ($errtext,$fatal) = 
                   11835:                         &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
                   11836:                                                '/'.$folders{$outer}.'.'.
                   11837:                                                $containers{$outer});
                   11838:                     next if ($fatal);
                   11839:                     if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
                   11840:                         if ($context eq 'coursedocs') {
1.1056    raeburn  11841:                             $mapinner{$i} = time;
1.1055    raeburn  11842:                             $folders{$i} = 'default_'.$mapinner{$i};
                   11843:                             $containers{$i} = 'sequence';
                   11844:                             my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
                   11845:                                       $folders{$i}.'.'.$containers{$i};
                   11846:                             my $newidx = &LONCAPA::map::getresidx();
                   11847:                             $LONCAPA::map::resources[$newidx]=
1.1059    raeburn  11848:                                 $docstitle.':'.$url.':false:normal:res';
1.1055    raeburn  11849:                             push(@LONCAPA::map::order,$newidx);
                   11850:                             my ($outtext,$errtext) =
                   11851:                                 &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
                   11852:                                                         $docuname.'/'.$folders{$outer}.
1.1075.2.11  raeburn  11853:                                                         '.'.$containers{$outer},1,1);
1.1056    raeburn  11854:                             $newseqid{$i} = $newidx;
1.1067    raeburn  11855:                             unless ($errtext) {
                   11856:                                 $result .=  '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
                   11857:                             }
1.1055    raeburn  11858:                         }
                   11859:                     } else {
                   11860:                         if ($context eq 'coursedocs') {
                   11861:                             my $newidx=&LONCAPA::map::getresidx();
                   11862:                             my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
                   11863:                                       $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
                   11864:                                       $title;
                   11865:                             if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
                   11866:                                 mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
                   11867:                             }
                   11868:                             if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
                   11869:                                 mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
                   11870:                             }
                   11871:                             if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
                   11872:                                 system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056    raeburn  11873:                                 $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067    raeburn  11874:                                 unless ($ishome) {
                   11875:                                     my $fetch = "$newdest{$i}/$title";
                   11876:                                     $fetch =~ s/^\Q$prefix$dir\E//;
                   11877:                                     $prompttofetch{$fetch} = 1;
                   11878:                                 }
1.1055    raeburn  11879:                             }
                   11880:                             $LONCAPA::map::resources[$newidx]=
1.1059    raeburn  11881:                                 $docstitle.':'.$url.':false:normal:res';
1.1055    raeburn  11882:                             push(@LONCAPA::map::order, $newidx);
                   11883:                             my ($outtext,$errtext)=
                   11884:                                 &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
                   11885:                                                         $docuname.'/'.$folders{$outer}.
1.1075.2.11  raeburn  11886:                                                         '.'.$containers{$outer},1,1);
1.1067    raeburn  11887:                             unless ($errtext) {
                   11888:                                 if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
                   11889:                                     $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
                   11890:                                 }
                   11891:                             }
1.1055    raeburn  11892:                         }
                   11893:                     }
1.1075.2.11  raeburn  11894:                 }
                   11895:             } else {
                   11896:                 $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
                   11897:             }
                   11898:         }
                   11899:         for (my $i=1; $i<=$numitems; $i++) {
                   11900:             next unless ($env{'form.archive_'.$i} eq 'dependency');
                   11901:             my $path = $env{'form.archive_content_'.$i};
                   11902:             if ($path =~ /^\Q$pathtocheck\E/) {
                   11903:                 my ($title) = ($path =~ m{/([^/]+)$});
                   11904:                 $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
                   11905:                 if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
                   11906:                     if (ref($dirorder{$i}) eq 'ARRAY') {
                   11907:                         my ($itemidx,$fullpath,$relpath);
                   11908:                         if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
                   11909:                             my $container = $dirorder{$referrer{$i}}->[-1];
1.1056    raeburn  11910:                             for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11  raeburn  11911:                                 if ($dirorder{$i}->[$j] eq $container) {
                   11912:                                     $itemidx = $j;
1.1056    raeburn  11913:                                 }
                   11914:                             }
1.1075.2.11  raeburn  11915:                         }
                   11916:                         if ($itemidx eq '') {
                   11917:                             $itemidx =  0;
                   11918:                         }
                   11919:                         if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
                   11920:                             if ($mapinner{$referrer{$i}}) {
                   11921:                                 $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
                   11922:                                 for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
                   11923:                                     if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
                   11924:                                         unless (defined($newseqid{$dirorder{$i}->[$j]})) {
                   11925:                                             $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
                   11926:                                             $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
                   11927:                                             if (!-e $fullpath) {
                   11928:                                                 mkdir($fullpath,0755);
1.1056    raeburn  11929:                                             }
                   11930:                                         }
1.1075.2.11  raeburn  11931:                                     } else {
                   11932:                                         last;
1.1056    raeburn  11933:                                     }
1.1075.2.11  raeburn  11934:                                 }
                   11935:                             }
                   11936:                         } elsif ($newdest{$referrer{$i}}) {
                   11937:                             $fullpath = $newdest{$referrer{$i}};
                   11938:                             for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
                   11939:                                 if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
                   11940:                                     $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
                   11941:                                     last;
                   11942:                                 } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
                   11943:                                     unless (defined($newseqid{$dirorder{$i}->[$j]})) {
                   11944:                                         $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
                   11945:                                         $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
                   11946:                                         if (!-e $fullpath) {
                   11947:                                             mkdir($fullpath,0755);
1.1056    raeburn  11948:                                         }
                   11949:                                     }
1.1075.2.11  raeburn  11950:                                 } else {
                   11951:                                     last;
1.1056    raeburn  11952:                                 }
1.1075.2.11  raeburn  11953:                             }
                   11954:                         }
                   11955:                         if ($fullpath ne '') {
                   11956:                             if (-e "$prefix$path") {
                   11957:                                 system("mv $prefix$path $fullpath/$title");
                   11958:                             }
                   11959:                             if (-e "$fullpath/$title") {
                   11960:                                 my $showpath;
                   11961:                                 if ($relpath ne '') {
                   11962:                                     $showpath = "$relpath/$title";
                   11963:                                 } else {
                   11964:                                     $showpath = "/$title";
1.1056    raeburn  11965:                                 }
1.1075.2.11  raeburn  11966:                                 $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
                   11967:                             }
                   11968:                             unless ($ishome) {
                   11969:                                 my $fetch = "$fullpath/$title";
                   11970:                                 $fetch =~ s/^\Q$prefix$dir\E//;
                   11971:                                 $prompttofetch{$fetch} = 1;
1.1055    raeburn  11972:                             }
                   11973:                         }
                   11974:                     }
1.1075.2.11  raeburn  11975:                 } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
                   11976:                     $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
                   11977:                                     $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055    raeburn  11978:                 }
                   11979:             } else {
1.1075.2.11  raeburn  11980:                 $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
1.1055    raeburn  11981:             }
                   11982:         }
                   11983:         if (keys(%todelete)) {
                   11984:             foreach my $key (keys(%todelete)) {
                   11985:                 unlink($key);
1.1066    raeburn  11986:             }
                   11987:         }
                   11988:         if (keys(%todeletedir)) {
                   11989:             foreach my $key (keys(%todeletedir)) {
                   11990:                 rmdir($key);
                   11991:             }
                   11992:         }
                   11993:         foreach my $dir (sort(keys(%is_dir))) {
                   11994:             if (($pathtocheck ne '') && ($dir ne ''))  {
                   11995:                 &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055    raeburn  11996:             }
                   11997:         }
1.1067    raeburn  11998:         if ($result ne '') {
                   11999:             $output .= '<ul>'."\n".
                   12000:                        $result."\n".
                   12001:                        '</ul>';
                   12002:         }
                   12003:         unless ($ishome) {
                   12004:             my $replicationfail;
                   12005:             foreach my $item (keys(%prompttofetch)) {
                   12006:                 my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
                   12007:                 unless ($fetchresult eq 'ok') {
                   12008:                     $replicationfail .= '<li>'.$item.'</li>'."\n";
                   12009:                 }
                   12010:             }
                   12011:             if ($replicationfail) {
                   12012:                 $output .= '<p class="LC_error">'.
                   12013:                            &mt('Course home server failed to retrieve:').'<ul>'.
                   12014:                            $replicationfail.
                   12015:                            '</ul></p>';
                   12016:             }
                   12017:         }
1.1055    raeburn  12018:     } else {
                   12019:         $warning = &mt('No items found in archive.');
                   12020:     }
                   12021:     if ($error) {
                   12022:         $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
                   12023:                    $error.'</p>'."\n";
                   12024:     }
                   12025:     if ($warning) {
                   12026:         $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
                   12027:     }
                   12028:     return $output;
                   12029: }
                   12030: 
1.1066    raeburn  12031: sub cleanup_empty_dirs {
                   12032:     my ($path) = @_;
                   12033:     if (($path ne '') && (-d $path)) {
                   12034:         if (opendir(my $dirh,$path)) {
                   12035:             my @dircontents = grep(!/^\./,readdir($dirh));
                   12036:             my $numitems = 0;
                   12037:             foreach my $item (@dircontents) {
                   12038:                 if (-d "$path/$item") {
1.1075.2.28  raeburn  12039:                     &cleanup_empty_dirs("$path/$item");
1.1066    raeburn  12040:                     if (-e "$path/$item") {
                   12041:                         $numitems ++;
                   12042:                     }
                   12043:                 } else {
                   12044:                     $numitems ++;
                   12045:                 }
                   12046:             }
                   12047:             if ($numitems == 0) {
                   12048:                 rmdir($path);
                   12049:             }
                   12050:             closedir($dirh);
                   12051:         }
                   12052:     }
                   12053:     return;
                   12054: }
                   12055: 
1.41      ng       12056: =pod
1.45      matthew  12057: 
1.1068    raeburn  12058: =item &get_folder_hierarchy()
                   12059: 
                   12060: Provides hierarchy of names of folders/sub-folders containing the current
                   12061: item,
                   12062: 
                   12063: Inputs: 3
                   12064:      - $navmap - navmaps object
                   12065: 
                   12066:      - $map - url for map (either the trigger itself, or map containing
                   12067:                            the resource, which is the trigger).
                   12068: 
                   12069:      - $showitem - 1 => show title for map itself; 0 => do not show.
                   12070: 
                   12071: Outputs: 1 @pathitems - array of folder/subfolder names.
                   12072: 
                   12073: =cut
                   12074: 
                   12075: sub get_folder_hierarchy {
                   12076:     my ($navmap,$map,$showitem) = @_;
                   12077:     my @pathitems;
                   12078:     if (ref($navmap)) {
                   12079:         my $mapres = $navmap->getResourceByUrl($map);
                   12080:         if (ref($mapres)) {
                   12081:             my $pcslist = $mapres->map_hierarchy();
                   12082:             if ($pcslist ne '') {
                   12083:                 my @pcs = split(/,/,$pcslist);
                   12084:                 foreach my $pc (@pcs) {
                   12085:                     if ($pc == 1) {
1.1075.2.38  raeburn  12086:                         push(@pathitems,&mt('Main Content'));
1.1068    raeburn  12087:                     } else {
                   12088:                         my $res = $navmap->getByMapPc($pc);
                   12089:                         if (ref($res)) {
                   12090:                             my $title = $res->compTitle();
                   12091:                             $title =~ s/\W+/_/g;
                   12092:                             if ($title ne '') {
                   12093:                                 push(@pathitems,$title);
                   12094:                             }
                   12095:                         }
                   12096:                     }
                   12097:                 }
                   12098:             }
1.1071    raeburn  12099:             if ($showitem) {
                   12100:                 if ($mapres->{ID} eq '0.0') {
1.1075.2.38  raeburn  12101:                     push(@pathitems,&mt('Main Content'));
1.1071    raeburn  12102:                 } else {
                   12103:                     my $maptitle = $mapres->compTitle();
                   12104:                     $maptitle =~ s/\W+/_/g;
                   12105:                     if ($maptitle ne '') {
                   12106:                         push(@pathitems,$maptitle);
                   12107:                     }
1.1068    raeburn  12108:                 }
                   12109:             }
                   12110:         }
                   12111:     }
                   12112:     return @pathitems;
                   12113: }
                   12114: 
                   12115: =pod
                   12116: 
1.1015    raeburn  12117: =item * &get_turnedin_filepath()
                   12118: 
                   12119: Determines path in a user's portfolio file for storage of files uploaded
                   12120: to a specific essayresponse or dropbox item.
                   12121: 
                   12122: Inputs: 3 required + 1 optional.
                   12123: $symb is symb for resource, $uname and $udom are for current user (required).
                   12124: $caller is optional (can be "submission", if routine is called when storing
                   12125: an upoaded file when "Submit Answer" button was pressed).
                   12126: 
                   12127: Returns array containing $path and $multiresp. 
                   12128: $path is path in portfolio.  $multiresp is 1 if this resource contains more
                   12129: than one file upload item.  Callers of routine should append partid as a 
                   12130: subdirectory to $path in cases where $multiresp is 1.
                   12131: 
                   12132: Called by: homework/essayresponse.pm and homework/structuretags.pm
                   12133: 
                   12134: =cut
                   12135: 
                   12136: sub get_turnedin_filepath {
                   12137:     my ($symb,$uname,$udom,$caller) = @_;
                   12138:     my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
                   12139:     my $turnindir;
                   12140:     my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
                   12141:     $turnindir = $userhash{'turnindir'};
                   12142:     my ($path,$multiresp);
                   12143:     if ($turnindir eq '') {
                   12144:         if ($caller eq 'submission') {
                   12145:             $turnindir = &mt('turned in');
                   12146:             $turnindir =~ s/\W+/_/g;
                   12147:             my %newhash = (
                   12148:                             'turnindir' => $turnindir,
                   12149:                           );
                   12150:             &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
                   12151:         }
                   12152:     }
                   12153:     if ($turnindir ne '') {
                   12154:         $path = '/'.$turnindir.'/';
                   12155:         my ($multipart,$turnin,@pathitems);
                   12156:         my $navmap = Apache::lonnavmaps::navmap->new();
                   12157:         if (defined($navmap)) {
                   12158:             my $mapres = $navmap->getResourceByUrl($map);
                   12159:             if (ref($mapres)) {
                   12160:                 my $pcslist = $mapres->map_hierarchy();
                   12161:                 if ($pcslist ne '') {
                   12162:                     foreach my $pc (split(/,/,$pcslist)) {
                   12163:                         my $res = $navmap->getByMapPc($pc);
                   12164:                         if (ref($res)) {
                   12165:                             my $title = $res->compTitle();
                   12166:                             $title =~ s/\W+/_/g;
                   12167:                             if ($title ne '') {
1.1075.2.48  raeburn  12168:                                 if (($pc > 1) && (length($title) > 12)) {
                   12169:                                     $title = substr($title,0,12);
                   12170:                                 }
1.1015    raeburn  12171:                                 push(@pathitems,$title);
                   12172:                             }
                   12173:                         }
                   12174:                     }
                   12175:                 }
                   12176:                 my $maptitle = $mapres->compTitle();
                   12177:                 $maptitle =~ s/\W+/_/g;
                   12178:                 if ($maptitle ne '') {
1.1075.2.48  raeburn  12179:                     if (length($maptitle) > 12) {
                   12180:                         $maptitle = substr($maptitle,0,12);
                   12181:                     }
1.1015    raeburn  12182:                     push(@pathitems,$maptitle);
                   12183:                 }
                   12184:                 unless ($env{'request.state'} eq 'construct') {
                   12185:                     my $res = $navmap->getBySymb($symb);
                   12186:                     if (ref($res)) {
                   12187:                         my $partlist = $res->parts();
                   12188:                         my $totaluploads = 0;
                   12189:                         if (ref($partlist) eq 'ARRAY') {
                   12190:                             foreach my $part (@{$partlist}) {
                   12191:                                 my @types = $res->responseType($part);
                   12192:                                 my @ids = $res->responseIds($part);
                   12193:                                 for (my $i=0; $i < scalar(@ids); $i++) {
                   12194:                                     if ($types[$i] eq 'essay') {
                   12195:                                         my $partid = $part.'_'.$ids[$i];
                   12196:                                         if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
                   12197:                                             $totaluploads ++;
                   12198:                                         }
                   12199:                                     }
                   12200:                                 }
                   12201:                             }
                   12202:                             if ($totaluploads > 1) {
                   12203:                                 $multiresp = 1;
                   12204:                             }
                   12205:                         }
                   12206:                     }
                   12207:                 }
                   12208:             } else {
                   12209:                 return;
                   12210:             }
                   12211:         } else {
                   12212:             return;
                   12213:         }
                   12214:         my $restitle=&Apache::lonnet::gettitle($symb);
                   12215:         $restitle =~ s/\W+/_/g;
                   12216:         if ($restitle eq '') {
                   12217:             $restitle = ($resurl =~ m{/[^/]+$});
                   12218:             if ($restitle eq '') {
                   12219:                 $restitle = time;
                   12220:             }
                   12221:         }
1.1075.2.48  raeburn  12222:         if (length($restitle) > 12) {
                   12223:             $restitle = substr($restitle,0,12);
                   12224:         }
1.1015    raeburn  12225:         push(@pathitems,$restitle);
                   12226:         $path .= join('/',@pathitems);
                   12227:     }
                   12228:     return ($path,$multiresp);
                   12229: }
                   12230: 
                   12231: =pod
                   12232: 
1.464     albertel 12233: =back
1.41      ng       12234: 
1.112     bowersj2 12235: =head1 CSV Upload/Handling functions
1.38      albertel 12236: 
1.41      ng       12237: =over 4
                   12238: 
1.648     raeburn  12239: =item * &upfile_store($r)
1.41      ng       12240: 
                   12241: Store uploaded file, $r should be the HTTP Request object,
1.258     albertel 12242: needs $env{'form.upfile'}
1.41      ng       12243: returns $datatoken to be put into hidden field
                   12244: 
                   12245: =cut
1.31      albertel 12246: 
                   12247: sub upfile_store {
                   12248:     my $r=shift;
1.258     albertel 12249:     $env{'form.upfile'}=~s/\r/\n/gs;
                   12250:     $env{'form.upfile'}=~s/\f/\n/gs;
                   12251:     $env{'form.upfile'}=~s/\n+/\n/gs;
                   12252:     $env{'form.upfile'}=~s/\n+$//gs;
1.31      albertel 12253: 
1.258     albertel 12254:     my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
                   12255: 	'_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31      albertel 12256:     {
1.158     raeburn  12257:         my $datafile = $r->dir_config('lonDaemons').
                   12258:                            '/tmp/'.$datatoken.'.tmp';
                   12259:         if ( open(my $fh,">$datafile") ) {
1.258     albertel 12260:             print $fh $env{'form.upfile'};
1.158     raeburn  12261:             close($fh);
                   12262:         }
1.31      albertel 12263:     }
                   12264:     return $datatoken;
                   12265: }
                   12266: 
1.56      matthew  12267: =pod
                   12268: 
1.648     raeburn  12269: =item * &load_tmp_file($r)
1.41      ng       12270: 
                   12271: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258     albertel 12272: needs $env{'form.datatoken'},
                   12273: sets $env{'form.upfile'} to the contents of the file
1.41      ng       12274: 
                   12275: =cut
1.31      albertel 12276: 
                   12277: sub load_tmp_file {
                   12278:     my $r=shift;
                   12279:     my @studentdata=();
                   12280:     {
1.158     raeburn  12281:         my $studentfile = $r->dir_config('lonDaemons').
1.258     albertel 12282:                               '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158     raeburn  12283:         if ( open(my $fh,"<$studentfile") ) {
                   12284:             @studentdata=<$fh>;
                   12285:             close($fh);
                   12286:         }
1.31      albertel 12287:     }
1.258     albertel 12288:     $env{'form.upfile'}=join('',@studentdata);
1.31      albertel 12289: }
                   12290: 
1.56      matthew  12291: =pod
                   12292: 
1.648     raeburn  12293: =item * &upfile_record_sep()
1.41      ng       12294: 
                   12295: Separate uploaded file into records
                   12296: returns array of records,
1.258     albertel 12297: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41      ng       12298: 
                   12299: =cut
1.31      albertel 12300: 
                   12301: sub upfile_record_sep {
1.258     albertel 12302:     if ($env{'form.upfiletype'} eq 'xml') {
1.31      albertel 12303:     } else {
1.248     albertel 12304: 	my @records;
1.258     albertel 12305: 	foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248     albertel 12306: 	    if ($line=~/^\s*$/) { next; }
                   12307: 	    push(@records,$line);
                   12308: 	}
                   12309: 	return @records;
1.31      albertel 12310:     }
                   12311: }
                   12312: 
1.56      matthew  12313: =pod
                   12314: 
1.648     raeburn  12315: =item * &record_sep($record)
1.41      ng       12316: 
1.258     albertel 12317: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41      ng       12318: 
                   12319: =cut
                   12320: 
1.263     www      12321: sub takeleft {
                   12322:     my $index=shift;
                   12323:     return substr('0000'.$index,-4,4);
                   12324: }
                   12325: 
1.31      albertel 12326: sub record_sep {
                   12327:     my $record=shift;
                   12328:     my %components=();
1.258     albertel 12329:     if ($env{'form.upfiletype'} eq 'xml') {
                   12330:     } elsif ($env{'form.upfiletype'} eq 'space') {
1.31      albertel 12331:         my $i=0;
1.356     albertel 12332:         foreach my $field (split(/\s+/,$record)) {
1.31      albertel 12333:             $field=~s/^(\"|\')//;
                   12334:             $field=~s/(\"|\')$//;
1.263     www      12335:             $components{&takeleft($i)}=$field;
1.31      albertel 12336:             $i++;
                   12337:         }
1.258     albertel 12338:     } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31      albertel 12339:         my $i=0;
1.356     albertel 12340:         foreach my $field (split(/\t/,$record)) {
1.31      albertel 12341:             $field=~s/^(\"|\')//;
                   12342:             $field=~s/(\"|\')$//;
1.263     www      12343:             $components{&takeleft($i)}=$field;
1.31      albertel 12344:             $i++;
                   12345:         }
                   12346:     } else {
1.561     www      12347:         my $separator=',';
1.480     banghart 12348:         if ($env{'form.upfiletype'} eq 'semisv') {
1.561     www      12349:             $separator=';';
1.480     banghart 12350:         }
1.31      albertel 12351:         my $i=0;
1.561     www      12352: # the character we are looking for to indicate the end of a quote or a record 
                   12353:         my $looking_for=$separator;
                   12354: # do not add the characters to the fields
                   12355:         my $ignore=0;
                   12356: # we just encountered a separator (or the beginning of the record)
                   12357:         my $just_found_separator=1;
                   12358: # store the field we are working on here
                   12359:         my $field='';
                   12360: # work our way through all characters in record
                   12361:         foreach my $character ($record=~/(.)/g) {
                   12362:             if ($character eq $looking_for) {
                   12363:                if ($character ne $separator) {
                   12364: # Found the end of a quote, again looking for separator
                   12365:                   $looking_for=$separator;
                   12366:                   $ignore=1;
                   12367:                } else {
                   12368: # Found a separator, store away what we got
                   12369:                   $components{&takeleft($i)}=$field;
                   12370: 	          $i++;
                   12371:                   $just_found_separator=1;
                   12372:                   $ignore=0;
                   12373:                   $field='';
                   12374:                }
                   12375:                next;
                   12376:             }
                   12377: # single or double quotation marks after a separator indicate beginning of a quote
                   12378: # we are now looking for the end of the quote and need to ignore separators
                   12379:             if ((($character eq '"') || ($character eq "'")) && ($just_found_separator))  {
                   12380:                $looking_for=$character;
                   12381:                next;
                   12382:             }
                   12383: # ignore would be true after we reached the end of a quote
                   12384:             if ($ignore) { next; }
                   12385:             if (($just_found_separator) && ($character=~/\s/)) { next; }
                   12386:             $field.=$character;
                   12387:             $just_found_separator=0; 
1.31      albertel 12388:         }
1.561     www      12389: # catch the very last entry, since we never encountered the separator
                   12390:         $components{&takeleft($i)}=$field;
1.31      albertel 12391:     }
                   12392:     return %components;
                   12393: }
                   12394: 
1.144     matthew  12395: ######################################################
                   12396: ######################################################
                   12397: 
1.56      matthew  12398: =pod
                   12399: 
1.648     raeburn  12400: =item * &upfile_select_html()
1.41      ng       12401: 
1.144     matthew  12402: Return HTML code to select a file from the users machine and specify 
                   12403: the file type.
1.41      ng       12404: 
                   12405: =cut
                   12406: 
1.144     matthew  12407: ######################################################
                   12408: ######################################################
1.31      albertel 12409: sub upfile_select_html {
1.144     matthew  12410:     my %Types = (
                   12411:                  csv   => &mt('CSV (comma separated values, spreadsheet)'),
1.480     banghart 12412:                  semisv => &mt('Semicolon separated values'),
1.144     matthew  12413:                  space => &mt('Space separated'),
                   12414:                  tab   => &mt('Tabulator separated'),
                   12415: #                 xml   => &mt('HTML/XML'),
                   12416:                  );
                   12417:     my $Str = '<input type="file" name="upfile" size="50" />'.
1.727     riegler  12418:         '<br />'.&mt('Type').': <select name="upfiletype">';
1.144     matthew  12419:     foreach my $type (sort(keys(%Types))) {
                   12420:         $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
                   12421:     }
                   12422:     $Str .= "</select>\n";
                   12423:     return $Str;
1.31      albertel 12424: }
                   12425: 
1.301     albertel 12426: sub get_samples {
                   12427:     my ($records,$toget) = @_;
                   12428:     my @samples=({});
                   12429:     my $got=0;
                   12430:     foreach my $rec (@$records) {
                   12431: 	my %temp = &record_sep($rec);
                   12432: 	if (! grep(/\S/, values(%temp))) { next; }
                   12433: 	if (%temp) {
                   12434: 	    $samples[$got]=\%temp;
                   12435: 	    $got++;
                   12436: 	    if ($got == $toget) { last; }
                   12437: 	}
                   12438:     }
                   12439:     return \@samples;
                   12440: }
                   12441: 
1.144     matthew  12442: ######################################################
                   12443: ######################################################
                   12444: 
1.56      matthew  12445: =pod
                   12446: 
1.648     raeburn  12447: =item * &csv_print_samples($r,$records)
1.41      ng       12448: 
                   12449: Prints a table of sample values from each column uploaded $r is an
                   12450: Apache Request ref, $records is an arrayref from
                   12451: &Apache::loncommon::upfile_record_sep
                   12452: 
                   12453: =cut
                   12454: 
1.144     matthew  12455: ######################################################
                   12456: ######################################################
1.31      albertel 12457: sub csv_print_samples {
                   12458:     my ($r,$records) = @_;
1.662     bisitz   12459:     my $samples = &get_samples($records,5);
1.301     albertel 12460: 
1.594     raeburn  12461:     $r->print(&mt('Samples').'<br />'.&start_data_table().
                   12462:               &start_data_table_header_row());
1.356     albertel 12463:     foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) { 
1.845     bisitz   12464:         $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594     raeburn  12465:     $r->print(&end_data_table_header_row());
1.301     albertel 12466:     foreach my $hash (@$samples) {
1.594     raeburn  12467: 	$r->print(&start_data_table_row());
1.356     albertel 12468: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31      albertel 12469: 	    $r->print('<td>');
1.356     albertel 12470: 	    if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31      albertel 12471: 	    $r->print('</td>');
                   12472: 	}
1.594     raeburn  12473: 	$r->print(&end_data_table_row());
1.31      albertel 12474:     }
1.594     raeburn  12475:     $r->print(&end_data_table().'<br />'."\n");
1.31      albertel 12476: }
                   12477: 
1.144     matthew  12478: ######################################################
                   12479: ######################################################
                   12480: 
1.56      matthew  12481: =pod
                   12482: 
1.648     raeburn  12483: =item * &csv_print_select_table($r,$records,$d)
1.41      ng       12484: 
                   12485: Prints a table to create associations between values and table columns.
1.144     matthew  12486: 
1.41      ng       12487: $r is an Apache Request ref,
                   12488: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174     matthew  12489: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41      ng       12490: 
                   12491: =cut
                   12492: 
1.144     matthew  12493: ######################################################
                   12494: ######################################################
1.31      albertel 12495: sub csv_print_select_table {
                   12496:     my ($r,$records,$d) = @_;
1.301     albertel 12497:     my $i=0;
                   12498:     my $samples = &get_samples($records,1);
1.144     matthew  12499:     $r->print(&mt('Associate columns with student attributes.')."\n".
1.594     raeburn  12500: 	      &start_data_table().&start_data_table_header_row().
1.144     matthew  12501:               '<th>'.&mt('Attribute').'</th>'.
1.594     raeburn  12502:               '<th>'.&mt('Column').'</th>'.
                   12503:               &end_data_table_header_row()."\n");
1.356     albertel 12504:     foreach my $array_ref (@$d) {
                   12505: 	my ($value,$display,$defaultcol)=@{ $array_ref };
1.729     raeburn  12506: 	$r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31      albertel 12507: 
1.875     bisitz   12508: 	$r->print('<td><select name="f'.$i.'"'.
1.32      matthew  12509: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.31      albertel 12510: 	$r->print('<option value="none"></option>');
1.356     albertel 12511: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
                   12512: 	    $r->print('<option value="'.$sample.'"'.
                   12513:                       ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662     bisitz   12514:                       '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31      albertel 12515: 	}
1.594     raeburn  12516: 	$r->print('</select></td>'.&end_data_table_row()."\n");
1.31      albertel 12517: 	$i++;
                   12518:     }
1.594     raeburn  12519:     $r->print(&end_data_table());
1.31      albertel 12520:     $i--;
                   12521:     return $i;
                   12522: }
1.56      matthew  12523: 
1.144     matthew  12524: ######################################################
                   12525: ######################################################
                   12526: 
1.56      matthew  12527: =pod
1.31      albertel 12528: 
1.648     raeburn  12529: =item * &csv_samples_select_table($r,$records,$d)
1.41      ng       12530: 
                   12531: Prints a table of sample values from the upload and can make associate samples to internal names.
                   12532: 
                   12533: $r is an Apache Request ref,
                   12534: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
                   12535: $d is an array of 2 element arrays (internal name, displayed name)
                   12536: 
                   12537: =cut
                   12538: 
1.144     matthew  12539: ######################################################
                   12540: ######################################################
1.31      albertel 12541: sub csv_samples_select_table {
                   12542:     my ($r,$records,$d) = @_;
                   12543:     my $i=0;
1.144     matthew  12544:     #
1.662     bisitz   12545:     my $max_samples = 5;
                   12546:     my $samples = &get_samples($records,$max_samples);
1.594     raeburn  12547:     $r->print(&start_data_table().
                   12548:               &start_data_table_header_row().'<th>'.
                   12549:               &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
                   12550:               &end_data_table_header_row());
1.301     albertel 12551: 
                   12552:     foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594     raeburn  12553: 	$r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32      matthew  12554: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.301     albertel 12555: 	foreach my $option (@$d) {
                   12556: 	    my ($value,$display,$defaultcol)=@{ $option };
1.174     matthew  12557: 	    $r->print('<option value="'.$value.'"'.
1.253     albertel 12558:                       ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174     matthew  12559:                       $display.'</option>');
1.31      albertel 12560: 	}
                   12561: 	$r->print('</select></td><td>');
1.662     bisitz   12562: 	foreach my $line (0..($max_samples-1)) {
1.301     albertel 12563: 	    if (defined($samples->[$line]{$key})) { 
                   12564: 		$r->print($samples->[$line]{$key}."<br />\n"); 
                   12565: 	    }
                   12566: 	}
1.594     raeburn  12567: 	$r->print('</td>'.&end_data_table_row());
1.31      albertel 12568: 	$i++;
                   12569:     }
1.594     raeburn  12570:     $r->print(&end_data_table());
1.31      albertel 12571:     $i--;
                   12572:     return($i);
1.115     matthew  12573: }
                   12574: 
1.144     matthew  12575: ######################################################
                   12576: ######################################################
                   12577: 
1.115     matthew  12578: =pod
                   12579: 
1.648     raeburn  12580: =item * &clean_excel_name($name)
1.115     matthew  12581: 
                   12582: Returns a replacement for $name which does not contain any illegal characters.
                   12583: 
                   12584: =cut
                   12585: 
1.144     matthew  12586: ######################################################
                   12587: ######################################################
1.115     matthew  12588: sub clean_excel_name {
                   12589:     my ($name) = @_;
                   12590:     $name =~ s/[:\*\?\/\\]//g;
                   12591:     if (length($name) > 31) {
                   12592:         $name = substr($name,0,31);
                   12593:     }
                   12594:     return $name;
1.25      albertel 12595: }
1.84      albertel 12596: 
1.85      albertel 12597: =pod
                   12598: 
1.648     raeburn  12599: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85      albertel 12600: 
                   12601: Returns either 1 or undef
                   12602: 
                   12603: 1 if the part is to be hidden, undef if it is to be shown
                   12604: 
                   12605: Arguments are:
                   12606: 
                   12607: $id the id of the part to be checked
                   12608: $symb, optional the symb of the resource to check
                   12609: $udom, optional the domain of the user to check for
                   12610: $uname, optional the username of the user to check for
                   12611: 
                   12612: =cut
1.84      albertel 12613: 
                   12614: sub check_if_partid_hidden {
                   12615:     my ($id,$symb,$udom,$uname) = @_;
1.133     albertel 12616:     my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84      albertel 12617: 					 $symb,$udom,$uname);
1.141     albertel 12618:     my $truth=1;
                   12619:     #if the string starts with !, then the list is the list to show not hide
                   12620:     if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84      albertel 12621:     my @hiddenlist=split(/,/,$hiddenparts);
                   12622:     foreach my $checkid (@hiddenlist) {
1.141     albertel 12623: 	if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84      albertel 12624:     }
1.141     albertel 12625:     return !$truth;
1.84      albertel 12626: }
1.127     matthew  12627: 
1.138     matthew  12628: 
                   12629: ############################################################
                   12630: ############################################################
                   12631: 
                   12632: =pod
                   12633: 
1.157     matthew  12634: =back 
                   12635: 
1.138     matthew  12636: =head1 cgi-bin script and graphing routines
                   12637: 
1.157     matthew  12638: =over 4
                   12639: 
1.648     raeburn  12640: =item * &get_cgi_id()
1.138     matthew  12641: 
                   12642: Inputs: none
                   12643: 
                   12644: Returns an id which can be used to pass environment variables
                   12645: to various cgi-bin scripts.  These environment variables will
                   12646: be removed from the users environment after a given time by
                   12647: the routine &Apache::lonnet::transfer_profile_to_env.
                   12648: 
                   12649: =cut
                   12650: 
                   12651: ############################################################
                   12652: ############################################################
1.152     albertel 12653: my $uniq=0;
1.136     matthew  12654: sub get_cgi_id {
1.154     albertel 12655:     $uniq=($uniq+1)%100000;
1.280     albertel 12656:     return (time.'_'.$$.'_'.$uniq);
1.136     matthew  12657: }
                   12658: 
1.127     matthew  12659: ############################################################
                   12660: ############################################################
                   12661: 
                   12662: =pod
                   12663: 
1.648     raeburn  12664: =item * &DrawBarGraph()
1.127     matthew  12665: 
1.138     matthew  12666: Facilitates the plotting of data in a (stacked) bar graph.
                   12667: Puts plot definition data into the users environment in order for 
                   12668: graph.png to plot it.  Returns an <img> tag for the plot.
                   12669: The bars on the plot are labeled '1','2',...,'n'.
                   12670: 
                   12671: Inputs:
                   12672: 
                   12673: =over 4
                   12674: 
                   12675: =item $Title: string, the title of the plot
                   12676: 
                   12677: =item $xlabel: string, text describing the X-axis of the plot
                   12678: 
                   12679: =item $ylabel: string, text describing the Y-axis of the plot
                   12680: 
                   12681: =item $Max: scalar, the maximum Y value to use in the plot
                   12682: If $Max is < any data point, the graph will not be rendered.
                   12683: 
1.140     matthew  12684: =item $colors: array ref holding the colors to be used for the data sets when
1.138     matthew  12685: they are plotted.  If undefined, default values will be used.
                   12686: 
1.178     matthew  12687: =item $labels: array ref holding the labels to use on the x-axis for the bars.
                   12688: 
1.138     matthew  12689: =item @Values: An array of array references.  Each array reference holds data
                   12690: to be plotted in a stacked bar chart.
                   12691: 
1.239     matthew  12692: =item If the final element of @Values is a hash reference the key/value
                   12693: pairs will be added to the graph definition.
                   12694: 
1.138     matthew  12695: =back
                   12696: 
                   12697: Returns:
                   12698: 
                   12699: An <img> tag which references graph.png and the appropriate identifying
                   12700: information for the plot.
                   12701: 
1.127     matthew  12702: =cut
                   12703: 
                   12704: ############################################################
                   12705: ############################################################
1.134     matthew  12706: sub DrawBarGraph {
1.178     matthew  12707:     my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134     matthew  12708:     #
                   12709:     if (! defined($colors)) {
                   12710:         $colors = ['#33ff00', 
                   12711:                   '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
                   12712:                   '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
                   12713:                   ]; 
                   12714:     }
1.228     matthew  12715:     my $extra_settings = {};
                   12716:     if (ref($Values[-1]) eq 'HASH') {
                   12717:         $extra_settings = pop(@Values);
                   12718:     }
1.127     matthew  12719:     #
1.136     matthew  12720:     my $identifier = &get_cgi_id();
                   12721:     my $id = 'cgi.'.$identifier;        
1.129     matthew  12722:     if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127     matthew  12723:         return '';
                   12724:     }
1.225     matthew  12725:     #
                   12726:     my @Labels;
                   12727:     if (defined($labels)) {
                   12728:         @Labels = @$labels;
                   12729:     } else {
                   12730:         for (my $i=0;$i<@{$Values[0]};$i++) {
                   12731:             push (@Labels,$i+1);
                   12732:         }
                   12733:     }
                   12734:     #
1.129     matthew  12735:     my $NumBars = scalar(@{$Values[0]});
1.225     matthew  12736:     if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129     matthew  12737:     my %ValuesHash;
                   12738:     my $NumSets=1;
                   12739:     foreach my $array (@Values) {
                   12740:         next if (! ref($array));
1.136     matthew  12741:         $ValuesHash{$id.'.data.'.$NumSets++} = 
1.132     matthew  12742:             join(',',@$array);
1.129     matthew  12743:     }
1.127     matthew  12744:     #
1.136     matthew  12745:     my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225     matthew  12746:     if ($NumBars < 3) {
                   12747:         $width = 120+$NumBars*32;
1.220     matthew  12748:         $xskip = 1;
1.225     matthew  12749:         $bar_width = 30;
                   12750:     } elsif ($NumBars < 5) {
                   12751:         $width = 120+$NumBars*20;
                   12752:         $xskip = 1;
                   12753:         $bar_width = 20;
1.220     matthew  12754:     } elsif ($NumBars < 10) {
1.136     matthew  12755:         $width = 120+$NumBars*15;
                   12756:         $xskip = 1;
                   12757:         $bar_width = 15;
                   12758:     } elsif ($NumBars <= 25) {
                   12759:         $width = 120+$NumBars*11;
                   12760:         $xskip = 5;
                   12761:         $bar_width = 8;
                   12762:     } elsif ($NumBars <= 50) {
                   12763:         $width = 120+$NumBars*8;
                   12764:         $xskip = 5;
                   12765:         $bar_width = 4;
                   12766:     } else {
                   12767:         $width = 120+$NumBars*8;
                   12768:         $xskip = 5;
                   12769:         $bar_width = 4;
                   12770:     }
                   12771:     #
1.137     matthew  12772:     $Max = 1 if ($Max < 1);
                   12773:     if ( int($Max) < $Max ) {
                   12774:         $Max++;
                   12775:         $Max = int($Max);
                   12776:     }
1.127     matthew  12777:     $Title  = '' if (! defined($Title));
                   12778:     $xlabel = '' if (! defined($xlabel));
                   12779:     $ylabel = '' if (! defined($ylabel));
1.369     www      12780:     $ValuesHash{$id.'.title'}    = &escape($Title);
                   12781:     $ValuesHash{$id.'.xlabel'}   = &escape($xlabel);
                   12782:     $ValuesHash{$id.'.ylabel'}   = &escape($ylabel);
1.137     matthew  12783:     $ValuesHash{$id.'.y_max_value'} = $Max;
1.136     matthew  12784:     $ValuesHash{$id.'.NumBars'}  = $NumBars;
                   12785:     $ValuesHash{$id.'.NumSets'}  = $NumSets;
                   12786:     $ValuesHash{$id.'.PlotType'} = 'bar';
                   12787:     $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   12788:     $ValuesHash{$id.'.height'}   = $height;
                   12789:     $ValuesHash{$id.'.width'}    = $width;
                   12790:     $ValuesHash{$id.'.xskip'}    = $xskip;
                   12791:     $ValuesHash{$id.'.bar_width'} = $bar_width;
                   12792:     $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127     matthew  12793:     #
1.228     matthew  12794:     # Deal with other parameters
                   12795:     while (my ($key,$value) = each(%$extra_settings)) {
                   12796:         $ValuesHash{$id.'.'.$key} = $value;
                   12797:     }
                   12798:     #
1.646     raeburn  12799:     &Apache::lonnet::appenv(\%ValuesHash);
1.137     matthew  12800:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   12801: }
                   12802: 
                   12803: ############################################################
                   12804: ############################################################
                   12805: 
                   12806: =pod
                   12807: 
1.648     raeburn  12808: =item * &DrawXYGraph()
1.137     matthew  12809: 
1.138     matthew  12810: Facilitates the plotting of data in an XY graph.
                   12811: Puts plot definition data into the users environment in order for 
                   12812: graph.png to plot it.  Returns an <img> tag for the plot.
                   12813: 
                   12814: Inputs:
                   12815: 
                   12816: =over 4
                   12817: 
                   12818: =item $Title: string, the title of the plot
                   12819: 
                   12820: =item $xlabel: string, text describing the X-axis of the plot
                   12821: 
                   12822: =item $ylabel: string, text describing the Y-axis of the plot
                   12823: 
                   12824: =item $Max: scalar, the maximum Y value to use in the plot
                   12825: If $Max is < any data point, the graph will not be rendered.
                   12826: 
                   12827: =item $colors: Array ref containing the hex color codes for the data to be 
                   12828: plotted in.  If undefined, default values will be used.
                   12829: 
                   12830: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   12831: 
                   12832: =item $Ydata: Array ref containing Array refs.  
1.185     www      12833: Each of the contained arrays will be plotted as a separate curve.
1.138     matthew  12834: 
                   12835: =item %Values: hash indicating or overriding any default values which are 
                   12836: passed to graph.png.  
                   12837: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   12838: 
                   12839: =back
                   12840: 
                   12841: Returns:
                   12842: 
                   12843: An <img> tag which references graph.png and the appropriate identifying
                   12844: information for the plot.
                   12845: 
1.137     matthew  12846: =cut
                   12847: 
                   12848: ############################################################
                   12849: ############################################################
                   12850: sub DrawXYGraph {
                   12851:     my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
                   12852:     #
                   12853:     # Create the identifier for the graph
                   12854:     my $identifier = &get_cgi_id();
                   12855:     my $id = 'cgi.'.$identifier;
                   12856:     #
                   12857:     $Title  = '' if (! defined($Title));
                   12858:     $xlabel = '' if (! defined($xlabel));
                   12859:     $ylabel = '' if (! defined($ylabel));
                   12860:     my %ValuesHash = 
                   12861:         (
1.369     www      12862:          $id.'.title'  => &escape($Title),
                   12863:          $id.'.xlabel' => &escape($xlabel),
                   12864:          $id.'.ylabel' => &escape($ylabel),
1.137     matthew  12865:          $id.'.y_max_value'=> $Max,
                   12866:          $id.'.labels'     => join(',',@$Xlabels),
                   12867:          $id.'.PlotType'   => 'XY',
                   12868:          );
                   12869:     #
                   12870:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   12871:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   12872:     }
                   12873:     #
                   12874:     if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
                   12875:         return '';
                   12876:     }
                   12877:     my $NumSets=1;
1.138     matthew  12878:     foreach my $array (@{$Ydata}){
1.137     matthew  12879:         next if (! ref($array));
                   12880:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
                   12881:     }
1.138     matthew  12882:     $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137     matthew  12883:     #
                   12884:     # Deal with other parameters
                   12885:     while (my ($key,$value) = each(%Values)) {
                   12886:         $ValuesHash{$id.'.'.$key} = $value;
1.127     matthew  12887:     }
                   12888:     #
1.646     raeburn  12889:     &Apache::lonnet::appenv(\%ValuesHash);
1.136     matthew  12890:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   12891: }
                   12892: 
                   12893: ############################################################
                   12894: ############################################################
                   12895: 
                   12896: =pod
                   12897: 
1.648     raeburn  12898: =item * &DrawXYYGraph()
1.138     matthew  12899: 
                   12900: Facilitates the plotting of data in an XY graph with two Y axes.
                   12901: Puts plot definition data into the users environment in order for 
                   12902: graph.png to plot it.  Returns an <img> tag for the plot.
                   12903: 
                   12904: Inputs:
                   12905: 
                   12906: =over 4
                   12907: 
                   12908: =item $Title: string, the title of the plot
                   12909: 
                   12910: =item $xlabel: string, text describing the X-axis of the plot
                   12911: 
                   12912: =item $ylabel: string, text describing the Y-axis of the plot
                   12913: 
                   12914: =item $colors: Array ref containing the hex color codes for the data to be 
                   12915: plotted in.  If undefined, default values will be used.
                   12916: 
                   12917: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   12918: 
                   12919: =item $Ydata1: The first data set
                   12920: 
                   12921: =item $Min1: The minimum value of the left Y-axis
                   12922: 
                   12923: =item $Max1: The maximum value of the left Y-axis
                   12924: 
                   12925: =item $Ydata2: The second data set
                   12926: 
                   12927: =item $Min2: The minimum value of the right Y-axis
                   12928: 
                   12929: =item $Max2: The maximum value of the left Y-axis
                   12930: 
                   12931: =item %Values: hash indicating or overriding any default values which are 
                   12932: passed to graph.png.  
                   12933: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   12934: 
                   12935: =back
                   12936: 
                   12937: Returns:
                   12938: 
                   12939: An <img> tag which references graph.png and the appropriate identifying
                   12940: information for the plot.
1.136     matthew  12941: 
                   12942: =cut
                   12943: 
                   12944: ############################################################
                   12945: ############################################################
1.137     matthew  12946: sub DrawXYYGraph {
                   12947:     my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
                   12948:                                         $Ydata2,$Min2,$Max2,%Values)=@_;
1.136     matthew  12949:     #
                   12950:     # Create the identifier for the graph
                   12951:     my $identifier = &get_cgi_id();
                   12952:     my $id = 'cgi.'.$identifier;
                   12953:     #
                   12954:     $Title  = '' if (! defined($Title));
                   12955:     $xlabel = '' if (! defined($xlabel));
                   12956:     $ylabel = '' if (! defined($ylabel));
                   12957:     my %ValuesHash = 
                   12958:         (
1.369     www      12959:          $id.'.title'  => &escape($Title),
                   12960:          $id.'.xlabel' => &escape($xlabel),
                   12961:          $id.'.ylabel' => &escape($ylabel),
1.136     matthew  12962:          $id.'.labels' => join(',',@$Xlabels),
                   12963:          $id.'.PlotType' => 'XY',
                   12964:          $id.'.NumSets' => 2,
1.137     matthew  12965:          $id.'.two_axes' => 1,
                   12966:          $id.'.y1_max_value' => $Max1,
                   12967:          $id.'.y1_min_value' => $Min1,
                   12968:          $id.'.y2_max_value' => $Max2,
                   12969:          $id.'.y2_min_value' => $Min2,
1.136     matthew  12970:          );
                   12971:     #
1.137     matthew  12972:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   12973:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   12974:     }
                   12975:     #
                   12976:     if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
                   12977:         ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136     matthew  12978:         return '';
                   12979:     }
                   12980:     my $NumSets=1;
1.137     matthew  12981:     foreach my $array ($Ydata1,$Ydata2){
1.136     matthew  12982:         next if (! ref($array));
                   12983:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137     matthew  12984:     }
                   12985:     #
                   12986:     # Deal with other parameters
                   12987:     while (my ($key,$value) = each(%Values)) {
                   12988:         $ValuesHash{$id.'.'.$key} = $value;
1.136     matthew  12989:     }
                   12990:     #
1.646     raeburn  12991:     &Apache::lonnet::appenv(\%ValuesHash);
1.130     albertel 12992:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139     matthew  12993: }
                   12994: 
                   12995: ############################################################
                   12996: ############################################################
                   12997: 
                   12998: =pod
                   12999: 
1.157     matthew  13000: =back 
                   13001: 
1.139     matthew  13002: =head1 Statistics helper routines?  
                   13003: 
                   13004: Bad place for them but what the hell.
                   13005: 
1.157     matthew  13006: =over 4
                   13007: 
1.648     raeburn  13008: =item * &chartlink()
1.139     matthew  13009: 
                   13010: Returns a link to the chart for a specific student.  
                   13011: 
                   13012: Inputs:
                   13013: 
                   13014: =over 4
                   13015: 
                   13016: =item $linktext: The text of the link
                   13017: 
                   13018: =item $sname: The students username
                   13019: 
                   13020: =item $sdomain: The students domain
                   13021: 
                   13022: =back
                   13023: 
1.157     matthew  13024: =back
                   13025: 
1.139     matthew  13026: =cut
                   13027: 
                   13028: ############################################################
                   13029: ############################################################
                   13030: sub chartlink {
                   13031:     my ($linktext, $sname, $sdomain) = @_;
                   13032:     my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369     www      13033:         '&amp;SelectedStudent='.&escape($sname.':'.$sdomain).
1.219     albertel 13034:         '&amp;chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139     matthew  13035:        '">'.$linktext.'</a>';
1.153     matthew  13036: }
                   13037: 
                   13038: #######################################################
                   13039: #######################################################
                   13040: 
                   13041: =pod
                   13042: 
                   13043: =head1 Course Environment Routines
1.157     matthew  13044: 
                   13045: =over 4
1.153     matthew  13046: 
1.648     raeburn  13047: =item * &restore_course_settings()
1.153     matthew  13048: 
1.648     raeburn  13049: =item * &store_course_settings()
1.153     matthew  13050: 
                   13051: Restores/Store indicated form parameters from the course environment.
                   13052: Will not overwrite existing values of the form parameters.
                   13053: 
                   13054: Inputs: 
                   13055: a scalar describing the data (e.g. 'chart', 'problem_analysis')
                   13056: 
                   13057: a hash ref describing the data to be stored.  For example:
                   13058:    
                   13059: %Save_Parameters = ('Status' => 'scalar',
                   13060:     'chartoutputmode' => 'scalar',
                   13061:     'chartoutputdata' => 'scalar',
                   13062:     'Section' => 'array',
1.373     raeburn  13063:     'Group' => 'array',
1.153     matthew  13064:     'StudentData' => 'array',
                   13065:     'Maps' => 'array');
                   13066: 
                   13067: Returns: both routines return nothing
                   13068: 
1.631     raeburn  13069: =back
                   13070: 
1.153     matthew  13071: =cut
                   13072: 
                   13073: #######################################################
                   13074: #######################################################
                   13075: sub store_course_settings {
1.496     albertel 13076:     return &store_settings($env{'request.course.id'},@_);
                   13077: }
                   13078: 
                   13079: sub store_settings {
1.153     matthew  13080:     # save to the environment
                   13081:     # appenv the same items, just to be safe
1.300     albertel 13082:     my $udom  = $env{'user.domain'};
                   13083:     my $uname = $env{'user.name'};
1.496     albertel 13084:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  13085:     my %SaveHash;
                   13086:     my %AppHash;
                   13087:     while (my ($setting,$type) = each(%$Settings)) {
1.496     albertel 13088:         my $basename = join('.','internal',$context,$prefix,$setting);
1.300     albertel 13089:         my $envname = 'environment.'.$basename;
1.258     albertel 13090:         if (exists($env{'form.'.$setting})) {
1.153     matthew  13091:             # Save this value away
                   13092:             if ($type eq 'scalar' &&
1.258     albertel 13093:                 (! exists($env{$envname}) || 
                   13094:                  $env{$envname} ne $env{'form.'.$setting})) {
                   13095:                 $SaveHash{$basename} = $env{'form.'.$setting};
                   13096:                 $AppHash{$envname}   = $env{'form.'.$setting};
1.153     matthew  13097:             } elsif ($type eq 'array') {
                   13098:                 my $stored_form;
1.258     albertel 13099:                 if (ref($env{'form.'.$setting})) {
1.153     matthew  13100:                     $stored_form = join(',',
                   13101:                                         map {
1.369     www      13102:                                             &escape($_);
1.258     albertel 13103:                                         } sort(@{$env{'form.'.$setting}}));
1.153     matthew  13104:                 } else {
                   13105:                     $stored_form = 
1.369     www      13106:                         &escape($env{'form.'.$setting});
1.153     matthew  13107:                 }
                   13108:                 # Determine if the array contents are the same.
1.258     albertel 13109:                 if ($stored_form ne $env{$envname}) {
1.153     matthew  13110:                     $SaveHash{$basename} = $stored_form;
                   13111:                     $AppHash{$envname}   = $stored_form;
                   13112:                 }
                   13113:             }
                   13114:         }
                   13115:     }
                   13116:     my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300     albertel 13117:                                           $udom,$uname);
1.153     matthew  13118:     if ($put_result !~ /^(ok|delayed)/) {
                   13119:         &Apache::lonnet::logthis('unable to save form parameters, '.
                   13120:                                  'got error:'.$put_result);
                   13121:     }
                   13122:     # Make sure these settings stick around in this session, too
1.646     raeburn  13123:     &Apache::lonnet::appenv(\%AppHash);
1.153     matthew  13124:     return;
                   13125: }
                   13126: 
                   13127: sub restore_course_settings {
1.499     albertel 13128:     return &restore_settings($env{'request.course.id'},@_);
1.496     albertel 13129: }
                   13130: 
                   13131: sub restore_settings {
                   13132:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  13133:     while (my ($setting,$type) = each(%$Settings)) {
1.258     albertel 13134:         next if (exists($env{'form.'.$setting}));
1.496     albertel 13135:         my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153     matthew  13136:             '.'.$setting;
1.258     albertel 13137:         if (exists($env{$envname})) {
1.153     matthew  13138:             if ($type eq 'scalar') {
1.258     albertel 13139:                 $env{'form.'.$setting} = $env{$envname};
1.153     matthew  13140:             } elsif ($type eq 'array') {
1.258     albertel 13141:                 $env{'form.'.$setting} = [ 
1.153     matthew  13142:                                            map { 
1.369     www      13143:                                                &unescape($_); 
1.258     albertel 13144:                                            } split(',',$env{$envname})
1.153     matthew  13145:                                            ];
                   13146:             }
                   13147:         }
                   13148:     }
1.127     matthew  13149: }
                   13150: 
1.618     raeburn  13151: #######################################################
                   13152: #######################################################
                   13153: 
                   13154: =pod
                   13155: 
                   13156: =head1 Domain E-mail Routines  
                   13157: 
                   13158: =over 4
                   13159: 
1.648     raeburn  13160: =item * &build_recipient_list()
1.618     raeburn  13161: 
1.1075.2.44  raeburn  13162: Build recipient lists for following types of e-mail:
1.766     raeburn  13163: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44  raeburn  13164: (d) Help requests, (e) Course requests needing approval, (f) loncapa
                   13165: module change checking, student/employee ID conflict checks, as
                   13166: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
                   13167: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618     raeburn  13168: 
                   13169: Inputs:
1.1075.2.44  raeburn  13170: defmail (scalar - email address of default recipient),
                   13171: mailing type (scalar: errormail, packagesmail, helpdeskmail,
                   13172: requestsmail, updatesmail, or idconflictsmail).
                   13173: 
1.619     raeburn  13174: defdom (domain for which to retrieve configuration settings),
1.1075.2.44  raeburn  13175: 
                   13176: origmail (scalar - email address of recipient from loncapa.conf,
                   13177: i.e., predates configuration by DC via domainprefs.pm
1.618     raeburn  13178: 
1.655     raeburn  13179: Returns: comma separated list of addresses to which to send e-mail.
                   13180: 
                   13181: =back
1.618     raeburn  13182: 
                   13183: =cut
                   13184: 
                   13185: ############################################################
                   13186: ############################################################
                   13187: sub build_recipient_list {
1.619     raeburn  13188:     my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618     raeburn  13189:     my @recipients;
                   13190:     my $otheremails;
                   13191:     my %domconfig =
                   13192:          &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
                   13193:     if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766     raeburn  13194:         if (exists($domconfig{'contacts'}{$mailing})) {
                   13195:             if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
                   13196:                 my @contacts = ('adminemail','supportemail');
                   13197:                 foreach my $item (@contacts) {
                   13198:                     if ($domconfig{'contacts'}{$mailing}{$item}) {
                   13199:                         my $addr = $domconfig{'contacts'}{$item}; 
                   13200:                         if (!grep(/^\Q$addr\E$/,@recipients)) {
                   13201:                             push(@recipients,$addr);
                   13202:                         }
1.619     raeburn  13203:                     }
1.766     raeburn  13204:                     $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618     raeburn  13205:                 }
                   13206:             }
1.766     raeburn  13207:         } elsif ($origmail ne '') {
                   13208:             push(@recipients,$origmail);
1.618     raeburn  13209:         }
1.619     raeburn  13210:     } elsif ($origmail ne '') {
                   13211:         push(@recipients,$origmail);
1.618     raeburn  13212:     }
1.688     raeburn  13213:     if (defined($defmail)) {
                   13214:         if ($defmail ne '') {
                   13215:             push(@recipients,$defmail);
                   13216:         }
1.618     raeburn  13217:     }
                   13218:     if ($otheremails) {
1.619     raeburn  13219:         my @others;
                   13220:         if ($otheremails =~ /,/) {
                   13221:             @others = split(/,/,$otheremails);
1.618     raeburn  13222:         } else {
1.619     raeburn  13223:             push(@others,$otheremails);
                   13224:         }
                   13225:         foreach my $addr (@others) {
                   13226:             if (!grep(/^\Q$addr\E$/,@recipients)) {
                   13227:                 push(@recipients,$addr);
                   13228:             }
1.618     raeburn  13229:         }
                   13230:     }
1.619     raeburn  13231:     my $recipientlist = join(',',@recipients); 
1.618     raeburn  13232:     return $recipientlist;
                   13233: }
                   13234: 
1.127     matthew  13235: ############################################################
                   13236: ############################################################
1.154     albertel 13237: 
1.655     raeburn  13238: =pod
                   13239: 
                   13240: =head1 Course Catalog Routines
                   13241: 
                   13242: =over 4
                   13243: 
                   13244: =item * &gather_categories()
                   13245: 
                   13246: Converts category definitions - keys of categories hash stored in  
                   13247: coursecategories in configuration.db on the primary library server in a 
                   13248: domain - to an array.  Also generates javascript and idx hash used to 
                   13249: generate Domain Coordinator interface for editing Course Categories.
                   13250: 
                   13251: Inputs:
1.663     raeburn  13252: 
1.655     raeburn  13253: categories (reference to hash of category definitions).
1.663     raeburn  13254: 
1.655     raeburn  13255: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   13256:       categories and subcategories).
1.663     raeburn  13257: 
1.655     raeburn  13258: idx (reference to hash of counters used in Domain Coordinator interface for 
                   13259:       editing Course Categories).
1.663     raeburn  13260: 
1.655     raeburn  13261: jsarray (reference to array of categories used to create Javascript arrays for
                   13262:          Domain Coordinator interface for editing Course Categories).
                   13263: 
                   13264: Returns: nothing
                   13265: 
                   13266: Side effects: populates cats, idx and jsarray. 
                   13267: 
                   13268: =cut
                   13269: 
                   13270: sub gather_categories {
                   13271:     my ($categories,$cats,$idx,$jsarray) = @_;
                   13272:     my %counters;
                   13273:     my $num = 0;
                   13274:     foreach my $item (keys(%{$categories})) {
                   13275:         my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   13276:         if ($container eq '' && $depth == 0) {
                   13277:             $cats->[$depth][$categories->{$item}] = $cat;
                   13278:         } else {
                   13279:             $cats->[$depth]{$container}[$categories->{$item}] = $cat;
                   13280:         }
                   13281:         my ($escitem,$tail) = split(/:/,$item,2);
                   13282:         if ($counters{$tail} eq '') {
                   13283:             $counters{$tail} = $num;
                   13284:             $num ++;
                   13285:         }
                   13286:         if (ref($idx) eq 'HASH') {
                   13287:             $idx->{$item} = $counters{$tail};
                   13288:         }
                   13289:         if (ref($jsarray) eq 'ARRAY') {
                   13290:             push(@{$jsarray->[$counters{$tail}]},$item);
                   13291:         }
                   13292:     }
                   13293:     return;
                   13294: }
                   13295: 
                   13296: =pod
                   13297: 
                   13298: =item * &extract_categories()
                   13299: 
                   13300: Used to generate breadcrumb trails for course categories.
                   13301: 
                   13302: Inputs:
1.663     raeburn  13303: 
1.655     raeburn  13304: categories (reference to hash of category definitions).
1.663     raeburn  13305: 
1.655     raeburn  13306: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   13307:       categories and subcategories).
1.663     raeburn  13308: 
1.655     raeburn  13309: trails (reference to array of breacrumb trails for each category).
1.663     raeburn  13310: 
1.655     raeburn  13311: allitems (reference to hash - key is category key 
                   13312:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  13313: 
1.655     raeburn  13314: idx (reference to hash of counters used in Domain Coordinator interface for
                   13315:       editing Course Categories).
1.663     raeburn  13316: 
1.655     raeburn  13317: jsarray (reference to array of categories used to create Javascript arrays for
                   13318:          Domain Coordinator interface for editing Course Categories).
                   13319: 
1.665     raeburn  13320: subcats (reference to hash of arrays containing all subcategories within each 
                   13321:          category, -recursive)
                   13322: 
1.655     raeburn  13323: Returns: nothing
                   13324: 
                   13325: Side effects: populates trails and allitems hash references.
                   13326: 
                   13327: =cut
                   13328: 
                   13329: sub extract_categories {
1.665     raeburn  13330:     my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655     raeburn  13331:     if (ref($categories) eq 'HASH') {
                   13332:         &gather_categories($categories,$cats,$idx,$jsarray);
                   13333:         if (ref($cats->[0]) eq 'ARRAY') {
                   13334:             for (my $i=0; $i<@{$cats->[0]}; $i++) {
                   13335:                 my $name = $cats->[0][$i];
                   13336:                 my $item = &escape($name).'::0';
                   13337:                 my $trailstr;
                   13338:                 if ($name eq 'instcode') {
                   13339:                     $trailstr = &mt('Official courses (with institutional codes)');
1.919     raeburn  13340:                 } elsif ($name eq 'communities') {
                   13341:                     $trailstr = &mt('Communities');
1.655     raeburn  13342:                 } else {
                   13343:                     $trailstr = $name;
                   13344:                 }
                   13345:                 if ($allitems->{$item} eq '') {
                   13346:                     push(@{$trails},$trailstr);
                   13347:                     $allitems->{$item} = scalar(@{$trails})-1;
                   13348:                 }
                   13349:                 my @parents = ($name);
                   13350:                 if (ref($cats->[1]{$name}) eq 'ARRAY') {
                   13351:                     for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
                   13352:                         my $category = $cats->[1]{$name}[$j];
1.665     raeburn  13353:                         if (ref($subcats) eq 'HASH') {
                   13354:                             push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
                   13355:                         }
                   13356:                         &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
                   13357:                     }
                   13358:                 } else {
                   13359:                     if (ref($subcats) eq 'HASH') {
                   13360:                         $subcats->{$item} = [];
1.655     raeburn  13361:                     }
                   13362:                 }
                   13363:             }
                   13364:         }
                   13365:     }
                   13366:     return;
                   13367: }
                   13368: 
                   13369: =pod
                   13370: 
                   13371: =item *&recurse_categories()
                   13372: 
                   13373: Recursively used to generate breadcrumb trails for course categories.
                   13374: 
                   13375: Inputs:
1.663     raeburn  13376: 
1.655     raeburn  13377: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   13378:       categories and subcategories).
1.663     raeburn  13379: 
1.655     raeburn  13380: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663     raeburn  13381: 
                   13382: category (current course category, for which breadcrumb trail is being generated).
                   13383: 
                   13384: trails (reference to array of breadcrumb trails for each category).
                   13385: 
1.655     raeburn  13386: allitems (reference to hash - key is category key
                   13387:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  13388: 
1.655     raeburn  13389: parents (array containing containers directories for current category, 
                   13390:          back to top level). 
                   13391: 
                   13392: Returns: nothing
                   13393: 
                   13394: Side effects: populates trails and allitems hash references
                   13395: 
                   13396: =cut
                   13397: 
                   13398: sub recurse_categories {
1.665     raeburn  13399:     my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655     raeburn  13400:     my $shallower = $depth - 1;
                   13401:     if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
                   13402:         for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
                   13403:             my $name = $cats->[$depth]{$category}[$k];
                   13404:             my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   13405:             my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   13406:             if ($allitems->{$item} eq '') {
                   13407:                 push(@{$trails},$trailstr);
                   13408:                 $allitems->{$item} = scalar(@{$trails})-1;
                   13409:             }
                   13410:             my $deeper = $depth+1;
                   13411:             push(@{$parents},$category);
1.665     raeburn  13412:             if (ref($subcats) eq 'HASH') {
                   13413:                 my $subcat = &escape($name).':'.$category.':'.$depth;
                   13414:                 for (my $j=@{$parents}; $j>=0; $j--) {
                   13415:                     my $higher;
                   13416:                     if ($j > 0) {
                   13417:                         $higher = &escape($parents->[$j]).':'.
                   13418:                                   &escape($parents->[$j-1]).':'.$j;
                   13419:                     } else {
                   13420:                         $higher = &escape($parents->[$j]).'::'.$j;
                   13421:                     }
                   13422:                     push(@{$subcats->{$higher}},$subcat);
                   13423:                 }
                   13424:             }
                   13425:             &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
                   13426:                                 $subcats);
1.655     raeburn  13427:             pop(@{$parents});
                   13428:         }
                   13429:     } else {
                   13430:         my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   13431:         my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   13432:         if ($allitems->{$item} eq '') {
                   13433:             push(@{$trails},$trailstr);
                   13434:             $allitems->{$item} = scalar(@{$trails})-1;
                   13435:         }
                   13436:     }
                   13437:     return;
                   13438: }
                   13439: 
1.663     raeburn  13440: =pod
                   13441: 
                   13442: =item *&assign_categories_table()
                   13443: 
                   13444: Create a datatable for display of hierarchical categories in a domain,
                   13445: with checkboxes to allow a course to be categorized. 
                   13446: 
                   13447: Inputs:
                   13448: 
                   13449: cathash - reference to hash of categories defined for the domain (from
                   13450:           configuration.db)
                   13451: 
                   13452: currcat - scalar with an & separated list of categories assigned to a course. 
                   13453: 
1.919     raeburn  13454: type    - scalar contains course type (Course or Community).
                   13455: 
1.663     raeburn  13456: Returns: $output (markup to be displayed) 
                   13457: 
                   13458: =cut
                   13459: 
                   13460: sub assign_categories_table {
1.919     raeburn  13461:     my ($cathash,$currcat,$type) = @_;
1.663     raeburn  13462:     my $output;
                   13463:     if (ref($cathash) eq 'HASH') {
                   13464:         my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
                   13465:         &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
                   13466:         $maxdepth = scalar(@cats);
                   13467:         if (@cats > 0) {
                   13468:             my $itemcount = 0;
                   13469:             if (ref($cats[0]) eq 'ARRAY') {
                   13470:                 my @currcategories;
                   13471:                 if ($currcat ne '') {
                   13472:                     @currcategories = split('&',$currcat);
                   13473:                 }
1.919     raeburn  13474:                 my $table;
1.663     raeburn  13475:                 for (my $i=0; $i<@{$cats[0]}; $i++) {
                   13476:                     my $parent = $cats[0][$i];
1.919     raeburn  13477:                     next if ($parent eq 'instcode');
                   13478:                     if ($type eq 'Community') {
                   13479:                         next unless ($parent eq 'communities');
                   13480:                     } else {
                   13481:                         next if ($parent eq 'communities');
                   13482:                     }
1.663     raeburn  13483:                     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   13484:                     my $item = &escape($parent).'::0';
                   13485:                     my $checked = '';
                   13486:                     if (@currcategories > 0) {
                   13487:                         if (grep(/^\Q$item\E$/,@currcategories)) {
1.772     bisitz   13488:                             $checked = ' checked="checked"';
1.663     raeburn  13489:                         }
                   13490:                     }
1.919     raeburn  13491:                     my $parent_title = $parent;
                   13492:                     if ($parent eq 'communities') {
                   13493:                         $parent_title = &mt('Communities');
                   13494:                     }
                   13495:                     $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
                   13496:                               '<input type="checkbox" name="usecategory" value="'.
                   13497:                               $item.'"'.$checked.' />'.$parent_title.'</span>'.
                   13498:                               '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663     raeburn  13499:                     my $depth = 1;
                   13500:                     push(@path,$parent);
1.919     raeburn  13501:                     $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663     raeburn  13502:                     pop(@path);
1.919     raeburn  13503:                     $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663     raeburn  13504:                     $itemcount ++;
                   13505:                 }
1.919     raeburn  13506:                 if ($itemcount) {
                   13507:                     $output = &Apache::loncommon::start_data_table().
                   13508:                               $table.
                   13509:                               &Apache::loncommon::end_data_table();
                   13510:                 }
1.663     raeburn  13511:             }
                   13512:         }
                   13513:     }
                   13514:     return $output;
                   13515: }
                   13516: 
                   13517: =pod
                   13518: 
                   13519: =item *&assign_category_rows()
                   13520: 
                   13521: Create a datatable row for display of nested categories in a domain,
                   13522: with checkboxes to allow a course to be categorized,called recursively.
                   13523: 
                   13524: Inputs:
                   13525: 
                   13526: itemcount - track row number for alternating colors
                   13527: 
                   13528: cats - reference to array of arrays/hashes which encapsulates hierarchy of
                   13529:       categories and subcategories.
                   13530: 
                   13531: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
                   13532: 
                   13533: parent - parent of current category item
                   13534: 
                   13535: path - Array containing all categories back up through the hierarchy from the
                   13536:        current category to the top level.
                   13537: 
                   13538: currcategories - reference to array of current categories assigned to the course
                   13539: 
                   13540: Returns: $output (markup to be displayed).
                   13541: 
                   13542: =cut
                   13543: 
                   13544: sub assign_category_rows {
                   13545:     my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
                   13546:     my ($text,$name,$item,$chgstr);
                   13547:     if (ref($cats) eq 'ARRAY') {
                   13548:         my $maxdepth = scalar(@{$cats});
                   13549:         if (ref($cats->[$depth]) eq 'HASH') {
                   13550:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   13551:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   13552:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45  raeburn  13553:                 $text .= '<td><table class="LC_data_table">';
1.663     raeburn  13554:                 for (my $j=0; $j<$numchildren; $j++) {
                   13555:                     $name = $cats->[$depth]{$parent}[$j];
                   13556:                     $item = &escape($name).':'.&escape($parent).':'.$depth;
                   13557:                     my $deeper = $depth+1;
                   13558:                     my $checked = '';
                   13559:                     if (ref($currcategories) eq 'ARRAY') {
                   13560:                         if (@{$currcategories} > 0) {
                   13561:                             if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772     bisitz   13562:                                 $checked = ' checked="checked"';
1.663     raeburn  13563:                             }
                   13564:                         }
                   13565:                     }
1.664     raeburn  13566:                     $text .= '<tr><td><span class="LC_nobreak"><label>'.
                   13567:                              '<input type="checkbox" name="usecategory" value="'.
1.675     raeburn  13568:                              $item.'"'.$checked.' />'.$name.'</label></span>'.
                   13569:                              '<input type="hidden" name="catname" value="'.$name.'" />'.
                   13570:                              '</td><td>';
1.663     raeburn  13571:                     if (ref($path) eq 'ARRAY') {
                   13572:                         push(@{$path},$name);
                   13573:                         $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
                   13574:                         pop(@{$path});
                   13575:                     }
                   13576:                     $text .= '</td></tr>';
                   13577:                 }
                   13578:                 $text .= '</table></td>';
                   13579:             }
                   13580:         }
                   13581:     }
                   13582:     return $text;
                   13583: }
                   13584: 
1.655     raeburn  13585: ############################################################
                   13586: ############################################################
                   13587: 
                   13588: 
1.443     albertel 13589: sub commit_customrole {
1.664     raeburn  13590:     my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630     raeburn  13591:     my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443     albertel 13592:                          ($start?', '.&mt('starting').' '.localtime($start):'').
                   13593:                          ($end?', ending '.localtime($end):'').': <b>'.
                   13594:               &Apache::lonnet::assigncustomrole(
1.664     raeburn  13595:                  $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443     albertel 13596:                  '</b><br />';
                   13597:     return $output;
                   13598: }
                   13599: 
                   13600: sub commit_standardrole {
1.1075.2.31  raeburn  13601:     my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541     raeburn  13602:     my ($output,$logmsg,$linefeed);
                   13603:     if ($context eq 'auto') {
                   13604:         $linefeed = "\n";
                   13605:     } else {
                   13606:         $linefeed = "<br />\n";
                   13607:     }  
1.443     albertel 13608:     if ($three eq 'st') {
1.541     raeburn  13609:         my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31  raeburn  13610:                                          $one,$two,$sec,$context,$credits);
1.541     raeburn  13611:         if (($result =~ /^error/) || ($result eq 'not_in_class') || 
1.626     raeburn  13612:             ($result eq 'unknown_course') || ($result eq 'refused')) {
                   13613:             $output = $logmsg.' '.&mt('Error: ').$result."\n"; 
1.443     albertel 13614:         } else {
1.541     raeburn  13615:             $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443     albertel 13616:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  13617:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
                   13618:             if ($context eq 'auto') {
                   13619:                 $output .= $result.$linefeed.&mt('Add to classlist').': ok';
                   13620:             } else {
                   13621:                $output .= '<b>'.$result.'</b>'.$linefeed.
                   13622:                &mt('Add to classlist').': <b>ok</b>';
                   13623:             }
                   13624:             $output .= $linefeed;
1.443     albertel 13625:         }
                   13626:     } else {
                   13627:         $output = &mt('Assigning').' '.$three.' in '.$url.
                   13628:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  13629:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652     raeburn  13630:         my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541     raeburn  13631:         if ($context eq 'auto') {
                   13632:             $output .= $result.$linefeed;
                   13633:         } else {
                   13634:             $output .= '<b>'.$result.'</b>'.$linefeed;
                   13635:         }
1.443     albertel 13636:     }
                   13637:     return $output;
                   13638: }
                   13639: 
                   13640: sub commit_studentrole {
1.1075.2.31  raeburn  13641:     my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
                   13642:         $credits) = @_;
1.626     raeburn  13643:     my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541     raeburn  13644:     if ($context eq 'auto') {
                   13645:         $linefeed = "\n";
                   13646:     } else {
                   13647:         $linefeed = '<br />'."\n";
                   13648:     }
1.443     albertel 13649:     if (defined($one) && defined($two)) {
                   13650:         my $cid=$one.'_'.$two;
                   13651:         my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
                   13652:         my $secchange = 0;
                   13653:         my $expire_role_result;
                   13654:         my $modify_section_result;
1.628     raeburn  13655:         if ($oldsec ne '-1') { 
                   13656:             if ($oldsec ne $sec) {
1.443     albertel 13657:                 $secchange = 1;
1.628     raeburn  13658:                 my $now = time;
1.443     albertel 13659:                 my $uurl='/'.$cid;
                   13660:                 $uurl=~s/\_/\//g;
                   13661:                 if ($oldsec) {
                   13662:                     $uurl.='/'.$oldsec;
                   13663:                 }
1.626     raeburn  13664:                 $oldsecurl = $uurl;
1.628     raeburn  13665:                 $expire_role_result = 
1.652     raeburn  13666:                     &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628     raeburn  13667:                 if ($env{'request.course.sec'} ne '') { 
                   13668:                     if ($expire_role_result eq 'refused') {
                   13669:                         my @roles = ('st');
                   13670:                         my @statuses = ('previous');
                   13671:                         my @roledoms = ($one);
                   13672:                         my $withsec = 1;
                   13673:                         my %roleshash = 
                   13674:                             &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
                   13675:                                               \@statuses,\@roles,\@roledoms,$withsec);
                   13676:                         if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
                   13677:                             my ($oldstart,$oldend) = 
                   13678:                                 split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
                   13679:                             if ($oldend > 0 && $oldend <= $now) {
                   13680:                                 $expire_role_result = 'ok';
                   13681:                             }
                   13682:                         }
                   13683:                     }
                   13684:                 }
1.443     albertel 13685:                 $result = $expire_role_result;
                   13686:             }
                   13687:         }
                   13688:         if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31  raeburn  13689:             $modify_section_result = 
                   13690:                 &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
                   13691:                                                            undef,undef,undef,$sec,
                   13692:                                                            $end,$start,'','',$cid,
                   13693:                                                            '',$context,$credits);
1.443     albertel 13694:             if ($modify_section_result =~ /^ok/) {
                   13695:                 if ($secchange == 1) {
1.628     raeburn  13696:                     if ($sec eq '') {
                   13697:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
                   13698:                     } else {
                   13699:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
                   13700:                     }
1.443     albertel 13701:                 } elsif ($oldsec eq '-1') {
1.628     raeburn  13702:                     if ($sec eq '') {
                   13703:                         $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
                   13704:                     } else {
                   13705:                         $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   13706:                     }
1.443     albertel 13707:                 } else {
1.628     raeburn  13708:                     if ($sec eq '') {
                   13709:                         $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
                   13710:                     } else {
                   13711:                         $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   13712:                     }
1.443     albertel 13713:                 }
                   13714:             } else {
1.628     raeburn  13715:                 if ($secchange) {       
                   13716:                     $$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;
                   13717:                 } else {
                   13718:                     $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
                   13719:                 }
1.443     albertel 13720:             }
                   13721:             $result = $modify_section_result;
                   13722:         } elsif ($secchange == 1) {
1.628     raeburn  13723:             if ($oldsec eq '') {
1.1075.2.20  raeburn  13724:                 $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_2] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
1.628     raeburn  13725:             } else {
                   13726:                 $$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;
                   13727:             }
1.626     raeburn  13728:             if ($expire_role_result eq 'refused') {
                   13729:                 my $newsecurl = '/'.$cid;
                   13730:                 $newsecurl =~ s/\_/\//g;
                   13731:                 if ($sec ne '') {
                   13732:                     $newsecurl.='/'.$sec;
                   13733:                 }
                   13734:                 if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
                   13735:                     if ($sec eq '') {
                   13736:                         $$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;
                   13737:                     } else {
                   13738:                         $$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;
                   13739:                     }
                   13740:                 }
                   13741:             }
1.443     albertel 13742:         }
                   13743:     } else {
1.626     raeburn  13744:         $$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 13745:         $result = "error: incomplete course id\n";
                   13746:     }
                   13747:     return $result;
                   13748: }
                   13749: 
1.1075.2.25  raeburn  13750: sub show_role_extent {
                   13751:     my ($scope,$context,$role) = @_;
                   13752:     $scope =~ s{^/}{};
                   13753:     my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
                   13754:     push(@courseroles,'co');
                   13755:     my @authorroles = &Apache::lonuserutils::roles_by_context('author');
                   13756:     if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
                   13757:         $scope =~ s{/}{_};
                   13758:         return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
                   13759:     } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
                   13760:         my ($audom,$auname) = split(/\//,$scope);
                   13761:         return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
                   13762:                    &Apache::loncommon::plainname($auname,$audom).'</span>');
                   13763:     } else {
                   13764:         $scope =~ s{/$}{};
                   13765:         return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
                   13766:                    &Apache::lonnet::domain($scope,'description').'</span>');
                   13767:     }
                   13768: }
                   13769: 
1.443     albertel 13770: ############################################################
                   13771: ############################################################
                   13772: 
1.566     albertel 13773: sub check_clone {
1.578     raeburn  13774:     my ($args,$linefeed) = @_;
1.566     albertel 13775:     my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
                   13776:     my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
                   13777:     my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
                   13778:     my $clonemsg;
                   13779:     my $can_clone = 0;
1.944     raeburn  13780:     my $lctype = lc($args->{'crstype'});
1.908     raeburn  13781:     if ($lctype ne 'community') {
                   13782:         $lctype = 'course';
                   13783:     }
1.566     albertel 13784:     if ($clonehome eq 'no_host') {
1.944     raeburn  13785:         if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  13786:             $clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
                   13787:         } else {
                   13788:             $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'});
                   13789:         }     
1.566     albertel 13790:     } else {
                   13791: 	my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944     raeburn  13792:         if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  13793:             if ($clonedesc{'type'} ne 'Community') {
                   13794:                  $clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
                   13795:                 return ($can_clone, $clonemsg, $cloneid, $clonehome);
                   13796:             }
                   13797:         }
1.882     raeburn  13798: 	if (($env{'request.role.domain'} eq $args->{'clonedomain'}) && 
                   13799:             (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566     albertel 13800: 	    $can_clone = 1;
                   13801: 	} else {
                   13802: 	    my %clonehash = &Apache::lonnet::get('environment',['cloners'],
                   13803: 						 $args->{'clonedomain'},$args->{'clonecourse'});
                   13804: 	    my @cloners = split(/,/,$clonehash{'cloners'});
1.578     raeburn  13805:             if (grep(/^\*$/,@cloners)) {
                   13806:                 $can_clone = 1;
                   13807:             } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
                   13808:                 $can_clone = 1;
                   13809:             } else {
1.908     raeburn  13810:                 my $ccrole = 'cc';
1.944     raeburn  13811:                 if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  13812:                     $ccrole = 'co';
                   13813:                 }
1.578     raeburn  13814: 	        my %roleshash =
                   13815: 		    &Apache::lonnet::get_my_roles($args->{'ccuname'},
                   13816: 					 $args->{'ccdomain'},
1.908     raeburn  13817:                                          'userroles',['active'],[$ccrole],
1.578     raeburn  13818: 					 [$args->{'clonedomain'}]);
1.908     raeburn  13819: 	        if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942     raeburn  13820:                     $can_clone = 1;
                   13821:                 } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
                   13822:                     $can_clone = 1;
                   13823:                 } else {
1.944     raeburn  13824:                     if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  13825:                         $clonemsg = &mt('No new community created.').$linefeed.&mt('The new community could not be cloned from the existing community because the new community owner ([_1]) does not have cloning rights in the existing community ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'});
                   13826:                     } else {
                   13827:                         $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'});
                   13828:                     }
1.578     raeburn  13829: 	        }
1.566     albertel 13830: 	    }
1.578     raeburn  13831:         }
1.566     albertel 13832:     }
                   13833:     return ($can_clone, $clonemsg, $cloneid, $clonehome);
                   13834: }
                   13835: 
1.444     albertel 13836: sub construct_course {
1.885     raeburn  13837:     my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444     albertel 13838:     my $outcome;
1.541     raeburn  13839:     my $linefeed =  '<br />'."\n";
                   13840:     if ($context eq 'auto') {
                   13841:         $linefeed = "\n";
                   13842:     }
1.566     albertel 13843: 
                   13844: #
                   13845: # Are we cloning?
                   13846: #
                   13847:     my ($can_clone, $clonemsg, $cloneid, $clonehome);
                   13848:     if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578     raeburn  13849: 	($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566     albertel 13850: 	if ($context ne 'auto') {
1.578     raeburn  13851:             if ($clonemsg ne '') {
                   13852: 	        $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
                   13853:             }
1.566     albertel 13854: 	}
                   13855: 	$outcome .= $clonemsg.$linefeed;
                   13856: 
                   13857:         if (!$can_clone) {
                   13858: 	    return (0,$outcome);
                   13859: 	}
                   13860:     }
                   13861: 
1.444     albertel 13862: #
                   13863: # Open course
                   13864: #
                   13865:     my $crstype = lc($args->{'crstype'});
                   13866:     my %cenv=();
                   13867:     $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
                   13868:                                              $args->{'cdescr'},
                   13869:                                              $args->{'curl'},
                   13870:                                              $args->{'course_home'},
                   13871:                                              $args->{'nonstandard'},
                   13872:                                              $args->{'crscode'},
                   13873:                                              $args->{'ccuname'}.':'.
                   13874:                                              $args->{'ccdomain'},
1.882     raeburn  13875:                                              $args->{'crstype'},
1.885     raeburn  13876:                                              $cnum,$context,$category);
1.444     albertel 13877: 
                   13878:     # Note: The testing routines depend on this being output; see 
                   13879:     # Utils::Course. This needs to at least be output as a comment
                   13880:     # if anyone ever decides to not show this, and Utils::Course::new
                   13881:     # will need to be suitably modified.
1.541     raeburn  13882:     $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943     raeburn  13883:     if ($$courseid =~ /^error:/) {
                   13884:         return (0,$outcome);
                   13885:     }
                   13886: 
1.444     albertel 13887: #
                   13888: # Check if created correctly
                   13889: #
1.479     albertel 13890:     ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444     albertel 13891:     my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943     raeburn  13892:     if ($crsuhome eq 'no_host') {
                   13893:         $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
                   13894:         return (0,$outcome);
                   13895:     }
1.541     raeburn  13896:     $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566     albertel 13897: 
1.444     albertel 13898: #
1.566     albertel 13899: # Do the cloning
                   13900: #   
                   13901:     if ($can_clone && $cloneid) {
                   13902: 	$clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
                   13903: 	if ($context ne 'auto') {
                   13904: 	    $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
                   13905: 	}
                   13906: 	$outcome .= $clonemsg.$linefeed;
                   13907: 	my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444     albertel 13908: # Copy all files
1.637     www      13909: 	&Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444     albertel 13910: # Restore URL
1.566     albertel 13911: 	$cenv{'url'}=$oldcenv{'url'};
1.444     albertel 13912: # Restore title
1.566     albertel 13913: 	$cenv{'description'}=$oldcenv{'description'};
1.955     raeburn  13914: # Restore creation date, creator and creation context.
                   13915:         $cenv{'internal.created'}=$oldcenv{'internal.created'};
                   13916:         $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
                   13917:         $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444     albertel 13918: # Mark as cloned
1.566     albertel 13919: 	$cenv{'clonedfrom'}=$cloneid;
1.638     www      13920: # Need to clone grading mode
                   13921:         my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
                   13922:         $cenv{'grading'}=$newenv{'grading'};
                   13923: # Do not clone these environment entries
                   13924:         &Apache::lonnet::del('environment',
                   13925:                   ['default_enrollment_start_date',
                   13926:                    'default_enrollment_end_date',
                   13927:                    'question.email',
                   13928:                    'policy.email',
                   13929:                    'comment.email',
                   13930:                    'pch.users.denied',
1.725     raeburn  13931:                    'plc.users.denied',
                   13932:                    'hidefromcat',
1.1075.2.36  raeburn  13933:                    'checkforpriv',
1.725     raeburn  13934:                    'categories'],
1.638     www      13935:                    $$crsudom,$$crsunum);
1.444     albertel 13936:     }
1.566     albertel 13937: 
1.444     albertel 13938: #
                   13939: # Set environment (will override cloned, if existing)
                   13940: #
                   13941:     my @sections = ();
                   13942:     my @xlists = ();
                   13943:     if ($args->{'crstype'}) {
                   13944:         $cenv{'type'}=$args->{'crstype'};
                   13945:     }
                   13946:     if ($args->{'crsid'}) {
                   13947:         $cenv{'courseid'}=$args->{'crsid'};
                   13948:     }
                   13949:     if ($args->{'crscode'}) {
                   13950:         $cenv{'internal.coursecode'}=$args->{'crscode'};
                   13951:     }
                   13952:     if ($args->{'crsquota'} ne '') {
                   13953:         $cenv{'internal.coursequota'}=$args->{'crsquota'};
                   13954:     } else {
                   13955:         $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
                   13956:     }
                   13957:     if ($args->{'ccuname'}) {
                   13958:         $cenv{'internal.courseowner'} = $args->{'ccuname'}.
                   13959:                                         ':'.$args->{'ccdomain'};
                   13960:     } else {
                   13961:         $cenv{'internal.courseowner'} = $args->{'curruser'};
                   13962:     }
1.1075.2.31  raeburn  13963:     if ($args->{'defaultcredits'}) {
                   13964:         $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
                   13965:     }
1.444     albertel 13966:     my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
                   13967:     if ($args->{'crssections'}) {
                   13968:         $cenv{'internal.sectionnums'} = '';
                   13969:         if ($args->{'crssections'} =~ m/,/) {
                   13970:             @sections = split/,/,$args->{'crssections'};
                   13971:         } else {
                   13972:             $sections[0] = $args->{'crssections'};
                   13973:         }
                   13974:         if (@sections > 0) {
                   13975:             foreach my $item (@sections) {
                   13976:                 my ($sec,$gp) = split/:/,$item;
                   13977:                 my $class = $args->{'crscode'}.$sec;
                   13978:                 my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
                   13979:                 $cenv{'internal.sectionnums'} .= $item.',';
                   13980:                 unless ($addcheck eq 'ok') {
                   13981:                     push @badclasses, $class;
                   13982:                 }
                   13983:             }
                   13984:             $cenv{'internal.sectionnums'} =~ s/,$//;
                   13985:         }
                   13986:     }
                   13987: # do not hide course coordinator from staff listing, 
                   13988: # even if privileged
                   13989:     $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36  raeburn  13990: # add course coordinator's domain to domains to check for privileged users
                   13991: # if different to course domain
                   13992:     if ($$crsudom ne $args->{'ccdomain'}) {
                   13993:         $cenv{'checkforpriv'} = $args->{'ccdomain'};
                   13994:     }
1.444     albertel 13995: # add crosslistings
                   13996:     if ($args->{'crsxlist'}) {
                   13997:         $cenv{'internal.crosslistings'}='';
                   13998:         if ($args->{'crsxlist'} =~ m/,/) {
                   13999:             @xlists = split/,/,$args->{'crsxlist'};
                   14000:         } else {
                   14001:             $xlists[0] = $args->{'crsxlist'};
                   14002:         }
                   14003:         if (@xlists > 0) {
                   14004:             foreach my $item (@xlists) {
                   14005:                 my ($xl,$gp) = split/:/,$item;
                   14006:                 my $addcheck =  &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
                   14007:                 $cenv{'internal.crosslistings'} .= $item.',';
                   14008:                 unless ($addcheck eq 'ok') {
                   14009:                     push @badclasses, $xl;
                   14010:                 }
                   14011:             }
                   14012:             $cenv{'internal.crosslistings'} =~ s/,$//;
                   14013:         }
                   14014:     }
                   14015:     if ($args->{'autoadds'}) {
                   14016:         $cenv{'internal.autoadds'}=$args->{'autoadds'};
                   14017:     }
                   14018:     if ($args->{'autodrops'}) {
                   14019:         $cenv{'internal.autodrops'}=$args->{'autodrops'};
                   14020:     }
                   14021: # check for notification of enrollment changes
                   14022:     my @notified = ();
                   14023:     if ($args->{'notify_owner'}) {
                   14024:         if ($args->{'ccuname'} ne '') {
                   14025:             push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
                   14026:         }
                   14027:     }
                   14028:     if ($args->{'notify_dc'}) {
                   14029:         if ($uname ne '') { 
1.630     raeburn  14030:             push(@notified,$uname.':'.$udom);
1.444     albertel 14031:         }
                   14032:     }
                   14033:     if (@notified > 0) {
                   14034:         my $notifylist;
                   14035:         if (@notified > 1) {
                   14036:             $notifylist = join(',',@notified);
                   14037:         } else {
                   14038:             $notifylist = $notified[0];
                   14039:         }
                   14040:         $cenv{'internal.notifylist'} = $notifylist;
                   14041:     }
                   14042:     if (@badclasses > 0) {
                   14043:         my %lt=&Apache::lonlocal::texthash(
                   14044:                 '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',
                   14045:                 'dnhr' => 'does not have rights to access enrollment in these classes',
                   14046:                 'adby' => 'as determined by the policies of your institution on access to official classlists'
                   14047:         );
1.541     raeburn  14048:         my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
                   14049:                            ' ('.$lt{'adby'}.')';
                   14050:         if ($context eq 'auto') {
                   14051:             $outcome .= $badclass_msg.$linefeed;
1.566     albertel 14052:             $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541     raeburn  14053:             foreach my $item (@badclasses) {
                   14054:                 if ($context eq 'auto') {
                   14055:                     $outcome .= " - $item\n";
                   14056:                 } else {
                   14057:                     $outcome .= "<li>$item</li>\n";
                   14058:                 }
                   14059:             }
                   14060:             if ($context eq 'auto') {
                   14061:                 $outcome .= $linefeed;
                   14062:             } else {
1.566     albertel 14063:                 $outcome .= "</ul><br /><br /></div>\n";
1.541     raeburn  14064:             }
                   14065:         } 
1.444     albertel 14066:     }
                   14067:     if ($args->{'no_end_date'}) {
                   14068:         $args->{'endaccess'} = 0;
                   14069:     }
                   14070:     $cenv{'internal.autostart'}=$args->{'enrollstart'};
                   14071:     $cenv{'internal.autoend'}=$args->{'enrollend'};
                   14072:     $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
                   14073:     $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
                   14074:     if ($args->{'showphotos'}) {
                   14075:       $cenv{'internal.showphotos'}=$args->{'showphotos'};
                   14076:     }
                   14077:     $cenv{'internal.authtype'} = $args->{'authtype'};
                   14078:     $cenv{'internal.autharg'} = $args->{'autharg'}; 
                   14079:     if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
                   14080:         if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'}  eq '') {
1.541     raeburn  14081:             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'); 
                   14082:             if ($context eq 'auto') {
                   14083:                 $outcome .= $krb_msg;
                   14084:             } else {
1.566     albertel 14085:                 $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541     raeburn  14086:             }
                   14087:             $outcome .= $linefeed;
1.444     albertel 14088:         }
                   14089:     }
                   14090:     if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
                   14091:        if ($args->{'setpolicy'}) {
                   14092:            $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   14093:        }
                   14094:        if ($args->{'setcontent'}) {
                   14095:            $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   14096:        }
                   14097:     }
                   14098:     if ($args->{'reshome'}) {
                   14099: 	$cenv{'reshome'}=$args->{'reshome'}.'/';
                   14100: 	$cenv{'reshome'}=~s/\/+$/\//;
                   14101:     }
                   14102: #
                   14103: # course has keyed access
                   14104: #
                   14105:     if ($args->{'setkeys'}) {
                   14106:        $cenv{'keyaccess'}='yes';
                   14107:     }
                   14108: # if specified, key authority is not course, but user
                   14109: # only active if keyaccess is yes
                   14110:     if ($args->{'keyauth'}) {
1.487     albertel 14111: 	my ($user,$domain) = split(':',$args->{'keyauth'});
                   14112: 	$user = &LONCAPA::clean_username($user);
                   14113: 	$domain = &LONCAPA::clean_username($domain);
1.488     foxr     14114: 	if ($user ne '' && $domain ne '') {
1.487     albertel 14115: 	    $cenv{'keyauth'}=$user.':'.$domain;
1.444     albertel 14116: 	}
                   14117:     }
                   14118: 
                   14119:     if ($args->{'disresdis'}) {
                   14120:         $cenv{'pch.roles.denied'}='st';
                   14121:     }
                   14122:     if ($args->{'disablechat'}) {
                   14123:         $cenv{'plc.roles.denied'}='st';
                   14124:     }
                   14125: 
                   14126:     # Record we've not yet viewed the Course Initialization Helper for this 
                   14127:     # course
                   14128:     $cenv{'course.helper.not.run'} = 1;
                   14129:     #
                   14130:     # Use new Randomseed
                   14131:     #
                   14132:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
                   14133:     $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
                   14134:     #
                   14135:     # The encryption code and receipt prefix for this course
                   14136:     #
                   14137:     $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
                   14138:     $cenv{'internal.encpref'}=100+int(9*rand(99));
                   14139:     #
                   14140:     # By default, use standard grading
                   14141:     if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
                   14142: 
1.541     raeburn  14143:     $outcome .= $linefeed.&mt('Setting environment').': '.                 
                   14144:           &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 14145: #
                   14146: # Open all assignments
                   14147: #
                   14148:     if ($args->{'openall'}) {
                   14149:        my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
                   14150:        my %storecontent = ($storeunder         => time,
                   14151:                            $storeunder.'.type' => 'date_start');
                   14152:        
                   14153:        $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541     raeburn  14154:                  ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 14155:    }
                   14156: #
                   14157: # Set first page
                   14158: #
                   14159:     unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
                   14160: 	    || ($cloneid)) {
1.445     albertel 14161: 	use LONCAPA::map;
1.444     albertel 14162: 	$outcome .= &mt('Setting first resource').': ';
1.445     albertel 14163: 
                   14164: 	my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
                   14165:         my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
                   14166: 
1.444     albertel 14167:         $outcome .= ($fatal?$errtext:'read ok').' - ';
                   14168:         my $title; my $url;
                   14169:         if ($args->{'firstres'} eq 'syl') {
1.690     bisitz   14170: 	    $title=&mt('Syllabus');
1.444     albertel 14171:             $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
                   14172:         } else {
1.963     raeburn  14173:             $title=&mt('Table of Contents');
1.444     albertel 14174:             $url='/adm/navmaps';
                   14175:         }
1.445     albertel 14176: 
                   14177:         $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
                   14178: 	(my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
                   14179: 
                   14180: 	if ($errtext) { $fatal=2; }
1.541     raeburn  14181:         $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444     albertel 14182:     }
1.566     albertel 14183: 
                   14184:     return (1,$outcome);
1.444     albertel 14185: }
                   14186: 
                   14187: ############################################################
                   14188: ############################################################
                   14189: 
1.953     droeschl 14190: #SD
                   14191: # only Community and Course, or anything else?
1.378     raeburn  14192: sub course_type {
                   14193:     my ($cid) = @_;
                   14194:     if (!defined($cid)) {
                   14195:         $cid = $env{'request.course.id'};
                   14196:     }
1.404     albertel 14197:     if (defined($env{'course.'.$cid.'.type'})) {
                   14198:         return $env{'course.'.$cid.'.type'};
1.378     raeburn  14199:     } else {
                   14200:         return 'Course';
1.377     raeburn  14201:     }
                   14202: }
1.156     albertel 14203: 
1.406     raeburn  14204: sub group_term {
                   14205:     my $crstype = &course_type();
                   14206:     my %names = (
                   14207:                   'Course' => 'group',
1.865     raeburn  14208:                   'Community' => 'group',
1.406     raeburn  14209:                 );
                   14210:     return $names{$crstype};
                   14211: }
                   14212: 
1.902     raeburn  14213: sub course_types {
                   14214:     my @types = ('official','unofficial','community');
                   14215:     my %typename = (
                   14216:                          official   => 'Official course',
                   14217:                          unofficial => 'Unofficial course',
                   14218:                          community  => 'Community',
                   14219:                    );
                   14220:     return (\@types,\%typename);
                   14221: }
                   14222: 
1.156     albertel 14223: sub icon {
                   14224:     my ($file)=@_;
1.505     albertel 14225:     my $curfext = lc((split(/\./,$file))[-1]);
1.168     albertel 14226:     my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156     albertel 14227:     my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168     albertel 14228:     if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
                   14229: 	if (-e  $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
                   14230: 	          $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   14231: 	            $curfext.".gif") {
                   14232: 	    $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   14233: 		$curfext.".gif";
                   14234: 	}
                   14235:     }
1.249     albertel 14236:     return &lonhttpdurl($iconname);
1.154     albertel 14237: } 
1.84      albertel 14238: 
1.575     albertel 14239: sub lonhttpdurl {
1.692     www      14240: #
                   14241: # Had been used for "small fry" static images on separate port 8080.
                   14242: # Modify here if lightweight http functionality desired again.
                   14243: # Currently eliminated due to increasing firewall issues.
                   14244: #
1.575     albertel 14245:     my ($url)=@_;
1.692     www      14246:     return $url;
1.215     albertel 14247: }
                   14248: 
1.213     albertel 14249: sub connection_aborted {
                   14250:     my ($r)=@_;
                   14251:     $r->print(" ");$r->rflush();
                   14252:     my $c = $r->connection;
                   14253:     return $c->aborted();
                   14254: }
                   14255: 
1.221     foxr     14256: #    Escapes strings that may have embedded 's that will be put into
1.222     foxr     14257: #    strings as 'strings'.
                   14258: sub escape_single {
1.221     foxr     14259:     my ($input) = @_;
1.223     albertel 14260:     $input =~ s/\\/\\\\/g;	# Escape the \'s..(must be first)>
1.221     foxr     14261:     $input =~ s/\'/\\\'/g;	# Esacpe the 's....
                   14262:     return $input;
                   14263: }
1.223     albertel 14264: 
1.222     foxr     14265: #  Same as escape_single, but escape's "'s  This 
                   14266: #  can be used for  "strings"
                   14267: sub escape_double {
                   14268:     my ($input) = @_;
                   14269:     $input =~ s/\\/\\\\/g;	# Escape the /'s..(must be first)>
                   14270:     $input =~ s/\"/\\\"/g;	# Esacpe the "s....
                   14271:     return $input;
                   14272: }
1.223     albertel 14273:  
1.222     foxr     14274: #   Escapes the last element of a full URL.
                   14275: sub escape_url {
                   14276:     my ($url)   = @_;
1.238     raeburn  14277:     my @urlslices = split(/\//, $url,-1);
1.369     www      14278:     my $lastitem = &escape(pop(@urlslices));
1.223     albertel 14279:     return join('/',@urlslices).'/'.$lastitem;
1.222     foxr     14280: }
1.462     albertel 14281: 
1.820     raeburn  14282: sub compare_arrays {
                   14283:     my ($arrayref1,$arrayref2) = @_;
                   14284:     my (@difference,%count);
                   14285:     @difference = ();
                   14286:     %count = ();
                   14287:     if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
                   14288:         foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
                   14289:         foreach my $element (keys(%count)) {
                   14290:             if ($count{$element} == 1) {
                   14291:                 push(@difference,$element);
                   14292:             }
                   14293:         }
                   14294:     }
                   14295:     return @difference;
                   14296: }
                   14297: 
1.817     bisitz   14298: # -------------------------------------------------------- Initialize user login
1.462     albertel 14299: sub init_user_environment {
1.463     albertel 14300:     my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462     albertel 14301:     my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
                   14302: 
                   14303:     my $public=($username eq 'public' && $domain eq 'public');
                   14304: 
                   14305: # See if old ID present, if so, remove
                   14306: 
1.1062    raeburn  14307:     my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462     albertel 14308:     my $now=time;
                   14309: 
                   14310:     if ($public) {
                   14311: 	my $max_public=100;
                   14312: 	my $oldest;
                   14313: 	my $oldest_time=0;
                   14314: 	for(my $next=1;$next<=$max_public;$next++) {
                   14315: 	    if (-e $lonids."/publicuser_$next.id") {
                   14316: 		my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
                   14317: 		if ($mtime<$oldest_time || !$oldest_time) {
                   14318: 		    $oldest_time=$mtime;
                   14319: 		    $oldest=$next;
                   14320: 		}
                   14321: 	    } else {
                   14322: 		$cookie="publicuser_$next";
                   14323: 		last;
                   14324: 	    }
                   14325: 	}
                   14326: 	if (!$cookie) { $cookie="publicuser_$oldest"; }
                   14327:     } else {
1.463     albertel 14328: 	# if this isn't a robot, kill any existing non-robot sessions
                   14329: 	if (!$args->{'robot'}) {
                   14330: 	    opendir(DIR,$lonids);
                   14331: 	    while ($filename=readdir(DIR)) {
                   14332: 		if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
                   14333: 		    unlink($lonids.'/'.$filename);
                   14334: 		}
1.462     albertel 14335: 	    }
1.463     albertel 14336: 	    closedir(DIR);
1.462     albertel 14337: 	}
                   14338: # Give them a new cookie
1.463     albertel 14339: 	my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684     www      14340: 		                   : $now.$$.int(rand(10000)));
1.463     albertel 14341: 	$cookie="$username\_$id\_$domain\_$authhost";
1.462     albertel 14342:     
                   14343: # Initialize roles
                   14344: 
1.1062    raeburn  14345: 	($userroles,$firstaccenv,$timerintenv) = 
                   14346:             &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462     albertel 14347:     }
                   14348: # ------------------------------------ Check browser type and MathML capability
                   14349: 
                   14350:     my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1075.2.42  raeburn  14351:         $clientunicode,$clientos,$clientmobile,$clientinfo) = &decode_user_agent($r);
1.462     albertel 14352: 
                   14353: # ------------------------------------------------------------- Get environment
                   14354: 
                   14355:     my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
                   14356:     my ($tmp) = keys(%userenv);
                   14357:     if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   14358:     } else {
                   14359: 	undef(%userenv);
                   14360:     }
                   14361:     if (($userenv{'interface'}) && (!$form->{'interface'})) {
                   14362: 	$form->{'interface'}=$userenv{'interface'};
                   14363:     }
                   14364:     if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
                   14365: 
                   14366: # --------------- Do not trust query string to be put directly into environment
1.817     bisitz   14367:     foreach my $option ('interface','localpath','localres') {
                   14368:         $form->{$option}=~s/[\n\r\=]//gs;
1.462     albertel 14369:     }
                   14370: # --------------------------------------------------------- Write first profile
                   14371: 
                   14372:     {
                   14373: 	my %initial_env = 
                   14374: 	    ("user.name"          => $username,
                   14375: 	     "user.domain"        => $domain,
                   14376: 	     "user.home"          => $authhost,
                   14377: 	     "browser.type"       => $clientbrowser,
                   14378: 	     "browser.version"    => $clientversion,
                   14379: 	     "browser.mathml"     => $clientmathml,
                   14380: 	     "browser.unicode"    => $clientunicode,
                   14381: 	     "browser.os"         => $clientos,
1.1075.2.42  raeburn  14382:              "browser.mobile"     => $clientmobile,
                   14383:              "browser.info"       => $clientinfo,
1.462     albertel 14384: 	     "server.domain"      => $Apache::lonnet::perlvar{'lonDefDomain'},
                   14385: 	     "request.course.fn"  => '',
                   14386: 	     "request.course.uri" => '',
                   14387: 	     "request.course.sec" => '',
                   14388: 	     "request.role"       => 'cm',
                   14389: 	     "request.role.adv"   => $env{'user.adv'},
                   14390: 	     "request.host"       => $ENV{'REMOTE_ADDR'},);
                   14391: 
                   14392:         if ($form->{'localpath'}) {
                   14393: 	    $initial_env{"browser.localpath"}  = $form->{'localpath'};
                   14394: 	    $initial_env{"browser.localres"}   = $form->{'localres'};
                   14395:         }
                   14396: 	
                   14397: 	if ($form->{'interface'}) {
                   14398: 	    $form->{'interface'}=~s/\W//gs;
                   14399: 	    $initial_env{"browser.interface"} = $form->{'interface'};
                   14400: 	    $env{'browser.interface'}=$form->{'interface'};
                   14401: 	}
                   14402: 
1.981     raeburn  14403:         my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016    raeburn  14404:         my %domdef;
                   14405:         unless ($domain eq 'public') {
                   14406:             %domdef = &Apache::lonnet::get_domain_defaults($domain);
                   14407:         }
1.980     raeburn  14408: 
1.1075.2.7  raeburn  14409:         foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724     raeburn  14410:             $userenv{'availabletools.'.$tool} = 
1.980     raeburn  14411:                 &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
                   14412:                                                   undef,\%userenv,\%domdef,\%is_adv);
1.724     raeburn  14413:         }
                   14414: 
1.864     raeburn  14415:         foreach my $crstype ('official','unofficial','community') {
1.765     raeburn  14416:             $userenv{'canrequest.'.$crstype} =
                   14417:                 &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980     raeburn  14418:                                                   'reload','requestcourses',
                   14419:                                                   \%userenv,\%domdef,\%is_adv);
1.765     raeburn  14420:         }
                   14421: 
1.1075.2.14  raeburn  14422:         $userenv{'canrequest.author'} =
                   14423:             &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
                   14424:                                         'reload','requestauthor',
                   14425:                                         \%userenv,\%domdef,\%is_adv);
                   14426:         my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
                   14427:                                              $domain,$username);
                   14428:         my $reqstatus = $reqauthor{'author_status'};
                   14429:         if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
                   14430:             if (ref($reqauthor{'author'}) eq 'HASH') {
                   14431:                 $userenv{'requestauthorqueued'} = $reqstatus.':'.
                   14432:                                                   $reqauthor{'author'}{'timestamp'};
                   14433:             }
                   14434:         }
                   14435: 
1.462     albertel 14436: 	$env{'user.environment'} = "$lonids/$cookie.id";
1.1062    raeburn  14437: 
1.462     albertel 14438: 	if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
                   14439: 		 &GDBM_WRCREAT(),0640)) {
                   14440: 	    &_add_to_env(\%disk_env,\%initial_env);
                   14441: 	    &_add_to_env(\%disk_env,\%userenv,'environment.');
                   14442: 	    &_add_to_env(\%disk_env,$userroles);
1.1062    raeburn  14443:             if (ref($firstaccenv) eq 'HASH') {
                   14444:                 &_add_to_env(\%disk_env,$firstaccenv);
                   14445:             }
                   14446:             if (ref($timerintenv) eq 'HASH') {
                   14447:                 &_add_to_env(\%disk_env,$timerintenv);
                   14448:             }
1.463     albertel 14449: 	    if (ref($args->{'extra_env'})) {
                   14450: 		&_add_to_env(\%disk_env,$args->{'extra_env'});
                   14451: 	    }
1.462     albertel 14452: 	    untie(%disk_env);
                   14453: 	} else {
1.705     tempelho 14454: 	    &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
                   14455: 			   'Could not create environment storage in lonauth: '.$!.'</span>');
1.462     albertel 14456: 	    return 'error: '.$!;
                   14457: 	}
                   14458:     }
                   14459:     $env{'request.role'}='cm';
                   14460:     $env{'request.role.adv'}=$env{'user.adv'};
                   14461:     $env{'browser.type'}=$clientbrowser;
                   14462: 
                   14463:     return $cookie;
                   14464: 
                   14465: }
                   14466: 
                   14467: sub _add_to_env {
                   14468:     my ($idf,$env_data,$prefix) = @_;
1.676     raeburn  14469:     if (ref($env_data) eq 'HASH') {
                   14470:         while (my ($key,$value) = each(%$env_data)) {
                   14471: 	    $idf->{$prefix.$key} = $value;
                   14472: 	    $env{$prefix.$key}   = $value;
                   14473:         }
1.462     albertel 14474:     }
                   14475: }
                   14476: 
1.685     tempelho 14477: # --- Get the symbolic name of a problem and the url
                   14478: sub get_symb {
                   14479:     my ($request,$silent) = @_;
1.726     raeburn  14480:     (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685     tempelho 14481:     my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
                   14482:     if ($symb eq '') {
                   14483:         if (!$silent) {
1.1071    raeburn  14484:             if (ref($request)) { 
                   14485:                 $request->print("Unable to handle ambiguous references:$url:.");
                   14486:             }
1.685     tempelho 14487:             return ();
                   14488:         }
                   14489:     }
                   14490:     &Apache::lonenc::check_decrypt(\$symb);
                   14491:     return ($symb);
                   14492: }
                   14493: 
                   14494: # --------------------------------------------------------------Get annotation
                   14495: 
                   14496: sub get_annotation {
                   14497:     my ($symb,$enc) = @_;
                   14498: 
                   14499:     my $key = $symb;
                   14500:     if (!$enc) {
                   14501:         $key =
                   14502:             &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
                   14503:     }
                   14504:     my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
                   14505:     return $annotation{$key};
                   14506: }
                   14507: 
                   14508: sub clean_symb {
1.731     raeburn  14509:     my ($symb,$delete_enc) = @_;
1.685     tempelho 14510: 
                   14511:     &Apache::lonenc::check_decrypt(\$symb);
                   14512:     my $enc = $env{'request.enc'};
1.731     raeburn  14513:     if ($delete_enc) {
1.730     raeburn  14514:         delete($env{'request.enc'});
                   14515:     }
1.685     tempelho 14516: 
                   14517:     return ($symb,$enc);
                   14518: }
1.462     albertel 14519: 
1.990     raeburn  14520: sub build_release_hashes {
                   14521:     my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_;
                   14522:     return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') &&
                   14523:                   (ref($checkcrstypes) eq 'HASH') && (ref($anonsurvey) eq 'HASH') &&
                   14524:                   (ref($randomizetry) eq 'HASH'));
                   14525:     foreach my $key (keys(%Apache::lonnet::needsrelease)) {
                   14526:         my ($item,$name,$value) = split(/:/,$key);
                   14527:         if ($item eq 'parameter') {
                   14528:             if (ref($checkparms->{$name}) eq 'ARRAY') {
                   14529:                 unless(grep(/^\Q$name\E$/,@{$checkparms->{$name}})) {
                   14530:                     push(@{$checkparms->{$name}},$value);
                   14531:                 }
                   14532:             } else {
                   14533:                 push(@{$checkparms->{$name}},$value);
                   14534:             }
                   14535:         } elsif ($item eq 'resourcetag') {
                   14536:             if ($name eq 'responsetype') {
                   14537:                 $checkresponsetypes->{$value} = $Apache::lonnet::needsrelease{$key}
                   14538:             }
                   14539:         } elsif ($item eq 'course') {
                   14540:             if ($name eq 'crstype') {
                   14541:                 $checkcrstypes->{$value} = $Apache::lonnet::needsrelease{$key};
                   14542:             }
                   14543:         }
                   14544:     }
                   14545:     ($anonsurvey->{major},$anonsurvey->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
                   14546:     ($randomizetry->{major},$randomizetry->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
                   14547:     return;
                   14548: }
                   14549: 
1.1075.2.11  raeburn  14550: sub update_content_constraints {
                   14551:     my ($cdom,$cnum,$chome,$cid) = @_;
                   14552:     my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
                   14553:     my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
                   14554:     my %checkresponsetypes;
                   14555:     foreach my $key (keys(%Apache::lonnet::needsrelease)) {
                   14556:         my ($item,$name,$value) = split(/:/,$key);
                   14557:         if ($item eq 'resourcetag') {
                   14558:             if ($name eq 'responsetype') {
                   14559:                 $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
                   14560:             }
                   14561:         }
                   14562:     }
                   14563:     my $navmap = Apache::lonnavmaps::navmap->new();
                   14564:     if (defined($navmap)) {
                   14565:         my %allresponses;
                   14566:         foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
                   14567:             my %responses = $res->responseTypes();
                   14568:             foreach my $key (keys(%responses)) {
                   14569:                 next unless(exists($checkresponsetypes{$key}));
                   14570:                 $allresponses{$key} += $responses{$key};
                   14571:             }
                   14572:         }
                   14573:         foreach my $key (keys(%allresponses)) {
                   14574:             my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
                   14575:             if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
                   14576:                 ($reqdmajor,$reqdminor) = ($major,$minor);
                   14577:             }
                   14578:         }
                   14579:         undef($navmap);
                   14580:     }
                   14581:     unless (($reqdmajor eq '') && ($reqdminor eq '')) {
                   14582:         &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
                   14583:     }
                   14584:     return;
                   14585: }
                   14586: 
1.1075.2.27  raeburn  14587: sub allmaps_incourse {
                   14588:     my ($cdom,$cnum,$chome,$cid) = @_;
                   14589:     if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
                   14590:         $cid = $env{'request.course.id'};
                   14591:         $cdom = $env{'course.'.$cid.'.domain'};
                   14592:         $cnum = $env{'course.'.$cid.'.num'};
                   14593:         $chome = $env{'course.'.$cid.'.home'};
                   14594:     }
                   14595:     my %allmaps = ();
                   14596:     my $lastchange =
                   14597:         &Apache::lonnet::get_coursechange($cdom,$cnum);
                   14598:     if ($lastchange > $env{'request.course.tied'}) {
                   14599:         my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
                   14600:         unless ($ferr) {
                   14601:             &update_content_constraints($cdom,$cnum,$chome,$cid);
                   14602:         }
                   14603:     }
                   14604:     my $navmap = Apache::lonnavmaps::navmap->new();
                   14605:     if (defined($navmap)) {
                   14606:         foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
                   14607:             $allmaps{$res->src()} = 1;
                   14608:         }
                   14609:     }
                   14610:     return \%allmaps;
                   14611: }
                   14612: 
1.1075.2.11  raeburn  14613: sub parse_supplemental_title {
                   14614:     my ($title) = @_;
                   14615: 
                   14616:     my ($foldertitle,$renametitle);
                   14617:     if ($title =~ /&amp;&amp;&amp;/) {
                   14618:         $title = &HTML::Entites::decode($title);
                   14619:     }
                   14620:     if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
                   14621:         $renametitle=$4;
                   14622:         my ($time,$uname,$udom) = ($1,$2,$3);
                   14623:         $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
                   14624:         my $name =  &plainname($uname,$udom);
                   14625:         $name = &HTML::Entities::encode($name,'"<>&\'');
                   14626:         $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
                   14627:         $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
                   14628:             $name.': <br />'.$foldertitle;
                   14629:     }
                   14630:     if (wantarray) {
                   14631:         return ($title,$foldertitle,$renametitle);
                   14632:     }
                   14633:     return $title;
                   14634: }
                   14635: 
1.1075.2.43  raeburn  14636: sub recurse_supplemental {
                   14637:     my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
                   14638:     if ($suppmap) {
                   14639:         my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
                   14640:         if ($fatal) {
                   14641:             $errors ++;
                   14642:         } else {
                   14643:             if ($#LONCAPA::map::resources > 0) {
                   14644:                 foreach my $res (@LONCAPA::map::resources) {
                   14645:                     my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
                   14646:                     if (($src ne '') && ($status eq 'res')) {
1.1075.2.46  raeburn  14647:                         if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
                   14648:                             ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43  raeburn  14649:                         } else {
                   14650:                             $numfiles ++;
                   14651:                         }
                   14652:                     }
                   14653:                 }
                   14654:             }
                   14655:         }
                   14656:     }
                   14657:     return ($numfiles,$errors);
                   14658: }
                   14659: 
1.1075.2.18  raeburn  14660: sub symb_to_docspath {
                   14661:     my ($symb) = @_;
                   14662:     return unless ($symb);
                   14663:     my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
                   14664:     if ($resurl=~/\.(sequence|page)$/) {
                   14665:         $mapurl=$resurl;
                   14666:     } elsif ($resurl eq 'adm/navmaps') {
                   14667:         $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
                   14668:     }
                   14669:     my $mapresobj;
                   14670:     my $navmap = Apache::lonnavmaps::navmap->new();
                   14671:     if (ref($navmap)) {
                   14672:         $mapresobj = $navmap->getResourceByUrl($mapurl);
                   14673:     }
                   14674:     $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
                   14675:     my $type=$2;
                   14676:     my $path;
                   14677:     if (ref($mapresobj)) {
                   14678:         my $pcslist = $mapresobj->map_hierarchy();
                   14679:         if ($pcslist ne '') {
                   14680:             foreach my $pc (split(/,/,$pcslist)) {
                   14681:                 next if ($pc <= 1);
                   14682:                 my $res = $navmap->getByMapPc($pc);
                   14683:                 if (ref($res)) {
                   14684:                     my $thisurl = $res->src();
                   14685:                     $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
                   14686:                     my $thistitle = $res->title();
                   14687:                     $path .= '&'.
                   14688:                              &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46  raeburn  14689:                              &escape($thistitle).
1.1075.2.18  raeburn  14690:                              ':'.$res->randompick().
                   14691:                              ':'.$res->randomout().
                   14692:                              ':'.$res->encrypted().
                   14693:                              ':'.$res->randomorder().
                   14694:                              ':'.$res->is_page();
                   14695:                 }
                   14696:             }
                   14697:         }
                   14698:         $path =~ s/^\&//;
                   14699:         my $maptitle = $mapresobj->title();
                   14700:         if ($mapurl eq 'default') {
1.1075.2.38  raeburn  14701:             $maptitle = 'Main Content';
1.1075.2.18  raeburn  14702:         }
                   14703:         $path .= (($path ne '')? '&' : '').
                   14704:                  &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46  raeburn  14705:                  &escape($maptitle).
1.1075.2.18  raeburn  14706:                  ':'.$mapresobj->randompick().
                   14707:                  ':'.$mapresobj->randomout().
                   14708:                  ':'.$mapresobj->encrypted().
                   14709:                  ':'.$mapresobj->randomorder().
                   14710:                  ':'.$mapresobj->is_page();
                   14711:     } else {
                   14712:         my $maptitle = &Apache::lonnet::gettitle($mapurl);
                   14713:         my $ispage = (($type eq 'page')? 1 : '');
                   14714:         if ($mapurl eq 'default') {
1.1075.2.38  raeburn  14715:             $maptitle = 'Main Content';
1.1075.2.18  raeburn  14716:         }
                   14717:         $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46  raeburn  14718:                 &escape($maptitle).':::::'.$ispage;
1.1075.2.18  raeburn  14719:     }
                   14720:     unless ($mapurl eq 'default') {
                   14721:         $path = 'default&'.
1.1075.2.46  raeburn  14722:                 &escape('Main Content').
1.1075.2.18  raeburn  14723:                 ':::::&'.$path;
                   14724:     }
                   14725:     return $path;
                   14726: }
                   14727: 
1.1075.2.14  raeburn  14728: sub captcha_display {
                   14729:     my ($context,$lonhost) = @_;
                   14730:     my ($output,$error);
                   14731:     my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
                   14732:     if ($captcha eq 'original') {
                   14733:         $output = &create_captcha();
                   14734:         unless ($output) {
                   14735:             $error = 'captcha';
                   14736:         }
                   14737:     } elsif ($captcha eq 'recaptcha') {
                   14738:         $output = &create_recaptcha($pubkey);
                   14739:         unless ($output) {
                   14740:             $error = 'recaptcha';
                   14741:         }
                   14742:     }
                   14743:     return ($output,$error);
                   14744: }
                   14745: 
                   14746: sub captcha_response {
                   14747:     my ($context,$lonhost) = @_;
                   14748:     my ($captcha_chk,$captcha_error);
                   14749:     my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
                   14750:     if ($captcha eq 'original') {
                   14751:         ($captcha_chk,$captcha_error) = &check_captcha();
                   14752:     } elsif ($captcha eq 'recaptcha') {
                   14753:         $captcha_chk = &check_recaptcha($privkey);
                   14754:     } else {
                   14755:         $captcha_chk = 1;
                   14756:     }
                   14757:     return ($captcha_chk,$captcha_error);
                   14758: }
                   14759: 
                   14760: sub get_captcha_config {
                   14761:     my ($context,$lonhost) = @_;
                   14762:     my ($captcha,$pubkey,$privkey,$hashtocheck);
                   14763:     my $hostname = &Apache::lonnet::hostname($lonhost);
                   14764:     my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
                   14765:     my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
                   14766:     if ($context eq 'usercreation') {
                   14767:         my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
                   14768:         if (ref($domconfig{$context}) eq 'HASH') {
                   14769:             $hashtocheck = $domconfig{$context}{'cancreate'};
                   14770:             if (ref($hashtocheck) eq 'HASH') {
                   14771:                 if ($hashtocheck->{'captcha'} eq 'recaptcha') {
                   14772:                     if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
                   14773:                         $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
                   14774:                         $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
                   14775:                     }
                   14776:                     if ($privkey && $pubkey) {
                   14777:                         $captcha = 'recaptcha';
                   14778:                     } else {
                   14779:                         $captcha = 'original';
                   14780:                     }
                   14781:                 } elsif ($hashtocheck->{'captcha'} ne 'notused') {
                   14782:                     $captcha = 'original';
                   14783:                 }
                   14784:             }
                   14785:         } else {
                   14786:             $captcha = 'captcha';
                   14787:         }
                   14788:     } elsif ($context eq 'login') {
                   14789:         my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
                   14790:         if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
                   14791:             $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
                   14792:             $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
                   14793:             if ($privkey && $pubkey) {
                   14794:                 $captcha = 'recaptcha';
                   14795:             } else {
                   14796:                 $captcha = 'original';
                   14797:             }
                   14798:         } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
                   14799:             $captcha = 'original';
                   14800:         }
                   14801:     }
                   14802:     return ($captcha,$pubkey,$privkey);
                   14803: }
                   14804: 
                   14805: sub create_captcha {
                   14806:     my %captcha_params = &captcha_settings();
                   14807:     my ($output,$maxtries,$tries) = ('',10,0);
                   14808:     while ($tries < $maxtries) {
                   14809:         $tries ++;
                   14810:         my $captcha = Authen::Captcha->new (
                   14811:                                            output_folder => $captcha_params{'output_dir'},
                   14812:                                            data_folder   => $captcha_params{'db_dir'},
                   14813:                                           );
                   14814:         my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
                   14815: 
                   14816:         if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
                   14817:             $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
                   14818:                       &mt('Type in the letters/numbers shown below').'&nbsp;'.
                   14819:                      '<input type="text" size="5" name="code" value="" /><br />'.
                   14820:                      '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" />';
                   14821:             last;
                   14822:         }
                   14823:     }
                   14824:     return $output;
                   14825: }
                   14826: 
                   14827: sub captcha_settings {
                   14828:     my %captcha_params = (
                   14829:                            output_dir     => $Apache::lonnet::perlvar{'lonCaptchaDir'},
                   14830:                            www_output_dir => "/captchaspool",
                   14831:                            db_dir         => $Apache::lonnet::perlvar{'lonCaptchaDb'},
                   14832:                            numchars       => '5',
                   14833:                          );
                   14834:     return %captcha_params;
                   14835: }
                   14836: 
                   14837: sub check_captcha {
                   14838:     my ($captcha_chk,$captcha_error);
                   14839:     my $code = $env{'form.code'};
                   14840:     my $md5sum = $env{'form.crypt'};
                   14841:     my %captcha_params = &captcha_settings();
                   14842:     my $captcha = Authen::Captcha->new(
                   14843:                       output_folder => $captcha_params{'output_dir'},
                   14844:                       data_folder   => $captcha_params{'db_dir'},
                   14845:                   );
1.1075.2.26  raeburn  14846:     $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14  raeburn  14847:     my %captcha_hash = (
                   14848:                         0       => 'Code not checked (file error)',
                   14849:                        -1      => 'Failed: code expired',
                   14850:                        -2      => 'Failed: invalid code (not in database)',
                   14851:                        -3      => 'Failed: invalid code (code does not match crypt)',
                   14852:     );
                   14853:     if ($captcha_chk != 1) {
                   14854:         $captcha_error = $captcha_hash{$captcha_chk}
                   14855:     }
                   14856:     return ($captcha_chk,$captcha_error);
                   14857: }
                   14858: 
                   14859: sub create_recaptcha {
                   14860:     my ($pubkey) = @_;
1.1075.2.51  raeburn  14861:     my $use_ssl;
                   14862:     if ($ENV{'SERVER_PORT'} == 443) {
                   14863:         $use_ssl = 1;
                   14864:     }
1.1075.2.14  raeburn  14865:     my $captcha = Captcha::reCAPTCHA->new;
                   14866:     return $captcha->get_options_setter({theme => 'white'})."\n".
1.1075.2.51  raeburn  14867:            $captcha->get_html($pubkey,undef,$use_ssl).
1.1075.2.14  raeburn  14868:            &mt('If either word is hard to read, [_1] will replace them.',
1.1075.2.39  raeburn  14869:                '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
1.1075.2.14  raeburn  14870:            '<br /><br />';
                   14871: }
                   14872: 
                   14873: sub check_recaptcha {
                   14874:     my ($privkey) = @_;
                   14875:     my $captcha_chk;
                   14876:     my $captcha = Captcha::reCAPTCHA->new;
                   14877:     my $captcha_result =
                   14878:         $captcha->check_answer(
                   14879:                                 $privkey,
                   14880:                                 $ENV{'REMOTE_ADDR'},
                   14881:                                 $env{'form.recaptcha_challenge_field'},
                   14882:                                 $env{'form.recaptcha_response_field'},
                   14883:                               );
                   14884:     if ($captcha_result->{is_valid}) {
                   14885:         $captcha_chk = 1;
                   14886:     }
                   14887:     return $captcha_chk;
                   14888: }
                   14889: 
1.41      ng       14890: =pod
                   14891: 
                   14892: =back
                   14893: 
1.112     bowersj2 14894: =cut
1.41      ng       14895: 
1.112     bowersj2 14896: 1;
                   14897: __END__;
1.41      ng       14898: 

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