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

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.30! raeburn     4: # $Id: loncommon.pm,v 1.1075.2.29 2013/01/21 02:33:22 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.909     raeburn   531:     my ($domainfilter,$sec_element,$formname,$role_element,$crstype) = @_;
1.932     raeburn   532:     my $wintitle = 'Course_Browser';
1.931     raeburn   533:     if ($crstype eq 'Community') {
1.932     raeburn   534:         $wintitle = 'Community_Browser';
1.909     raeburn   535:     }
1.876     raeburn   536:     my $id_functions = &javascript_index_functions();
                    537:     my $output = '
1.776     bisitz    538: <script type="text/javascript" language="JavaScript">
1.824     bisitz    539: // <![CDATA[
1.468     raeburn   540:     var stdeditbrowser;'."\n";
1.876     raeburn   541: 
                    542:     $output .= <<"ENDSTDBRW";
1.909     raeburn   543:     function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91      www       544:         var url = '/adm/pickcourse?';
1.895     raeburn   545:         var formid = getFormIdByName(formname);
1.876     raeburn   546:         var domainfilter = getDomainFromSelectbox(formname,udom);
1.128     albertel  547:         if (domainfilter != null) {
                    548:            if (domainfilter != '') {
                    549:                url += 'domainfilter='+domainfilter+'&';
                    550: 	   }
                    551:         }
1.91      www       552:         url += 'form=' + formname + '&cnumelement='+uname+
1.187     albertel  553: 	                            '&cdomelement='+udom+
                    554:                                     '&cnameelement='+desc;
1.468     raeburn   555:         if (extra_element !=null && extra_element != '') {
1.594     raeburn   556:             if (formname == 'rolechoice' || formname == 'studentform') {
1.468     raeburn   557:                 url += '&roleelement='+extra_element;
                    558:                 if (domainfilter == null || domainfilter == '') {
                    559:                     url += '&domainfilter='+extra_element;
                    560:                 }
1.234     raeburn   561:             }
1.468     raeburn   562:             else {
                    563:                 if (formname == 'portform') {
                    564:                     url += '&setroles='+extra_element;
1.800     raeburn   565:                 } else {
                    566:                     if (formname == 'rules') {
                    567:                         url += '&fixeddom='+extra_element; 
                    568:                     }
1.468     raeburn   569:                 }
                    570:             }     
1.230     raeburn   571:         }
1.909     raeburn   572:         if (type != null && type != '') {
                    573:             url += '&type='+type;
                    574:         }
                    575:         if (type_elem != null && type_elem != '') {
                    576:             url += '&typeelement='+type_elem;
                    577:         }
1.872     raeburn   578:         if (formname == 'ccrs') {
                    579:             var ownername = document.forms[formid].ccuname.value;
                    580:             var ownerdom =  document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
                    581:             url += '&cloner='+ownername+':'+ownerdom;
                    582:         }
1.293     raeburn   583:         if (multflag !=null && multflag != '') {
                    584:             url += '&multiple='+multflag;
                    585:         }
1.909     raeburn   586:         var title = '$wintitle';
1.91      www       587:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    588:         options += ',width=700,height=600';
                    589:         stdeditbrowser = open(url,title,options,'1');
                    590:         stdeditbrowser.focus();
                    591:     }
1.876     raeburn   592: $id_functions
                    593: ENDSTDBRW
1.905     raeburn   594:     if (($sec_element ne '') || ($role_element ne '')) {
                    595:         $output .= &setsec_javascript($sec_element,$formname,$role_element);
1.876     raeburn   596:     }
                    597:     $output .= '
                    598: // ]]>
                    599: </script>';
                    600:     return $output;
                    601: }
                    602: 
                    603: sub javascript_index_functions {
                    604:     return <<"ENDJS";
                    605: 
                    606: function getFormIdByName(formname) {
                    607:     for (var i=0;i<document.forms.length;i++) {
                    608:         if (document.forms[i].name == formname) {
                    609:             return i;
                    610:         }
                    611:     }
                    612:     return -1;
                    613: }
                    614: 
                    615: function getIndexByName(formid,item) {
                    616:     for (var i=0;i<document.forms[formid].elements.length;i++) {
                    617:         if (document.forms[formid].elements[i].name == item) {
                    618:             return i;
                    619:         }
                    620:     }
                    621:     return -1;
                    622: }
1.468     raeburn   623: 
1.876     raeburn   624: function getDomainFromSelectbox(formname,udom) {
                    625:     var userdom;
                    626:     var formid = getFormIdByName(formname);
                    627:     if (formid > -1) {
                    628:         var domid = getIndexByName(formid,udom);
                    629:         if (domid > -1) {
                    630:             if (document.forms[formid].elements[domid].type == 'select-one') {
                    631:                 userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
                    632:             }
                    633:             if (document.forms[formid].elements[domid].type == 'hidden') {
                    634:                 userdom=document.forms[formid].elements[domid].value;
1.468     raeburn   635:             }
                    636:         }
                    637:     }
1.876     raeburn   638:     return userdom;
                    639: }
                    640: 
                    641: ENDJS
1.468     raeburn   642: 
1.876     raeburn   643: }
                    644: 
1.1017    raeburn   645: sub javascript_array_indexof {
1.1018    raeburn   646:     return <<ENDJS;
1.1017    raeburn   647: <script type="text/javascript" language="JavaScript">
                    648: // <![CDATA[
                    649: 
                    650: if (!Array.prototype.indexOf) {
                    651:     Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
                    652:         "use strict";
                    653:         if (this === void 0 || this === null) {
                    654:             throw new TypeError();
                    655:         }
                    656:         var t = Object(this);
                    657:         var len = t.length >>> 0;
                    658:         if (len === 0) {
                    659:             return -1;
                    660:         }
                    661:         var n = 0;
                    662:         if (arguments.length > 0) {
                    663:             n = Number(arguments[1]);
                    664:             if (n !== n) { // shortcut for verifying if it's NaN
                    665:                 n = 0;
                    666:             } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
                    667:                 n = (n > 0 || -1) * Math.floor(Math.abs(n));
                    668:             }
                    669:         }
                    670:         if (n >= len) {
                    671:             return -1;
                    672:         }
                    673:         var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
                    674:         for (; k < len; k++) {
                    675:             if (k in t && t[k] === searchElement) {
                    676:                 return k;
                    677:             }
                    678:         }
                    679:         return -1;
                    680:     }
                    681: }
                    682: 
                    683: // ]]>
                    684: </script>
                    685: 
                    686: ENDJS
                    687: 
                    688: }
                    689: 
1.876     raeburn   690: sub userbrowser_javascript {
                    691:     my $id_functions = &javascript_index_functions();
                    692:     return <<"ENDUSERBRW";
                    693: 
1.888     raeburn   694: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876     raeburn   695:     var url = '/adm/pickuser?';
                    696:     var userdom = getDomainFromSelectbox(formname,udom);
                    697:     if (userdom != null) {
                    698:        if (userdom != '') {
                    699:            url += 'srchdom='+userdom+'&';
                    700:        }
                    701:     }
                    702:     url += 'form=' + formname + '&unameelement='+uname+
                    703:                                 '&udomelement='+udom+
                    704:                                 '&ulastelement='+ulast+
                    705:                                 '&ufirstelement='+ufirst+
                    706:                                 '&uemailelement='+uemail+
1.881     raeburn   707:                                 '&hideudomelement='+hideudom+
                    708:                                 '&coursedom='+crsdom;
1.888     raeburn   709:     if ((caller != null) && (caller != undefined)) {
                    710:         url += '&caller='+caller;
                    711:     }
1.876     raeburn   712:     var title = 'User_Browser';
                    713:     var options = 'scrollbars=1,resizable=1,menubar=0';
                    714:     options += ',width=700,height=600';
                    715:     var stdeditbrowser = open(url,title,options,'1');
                    716:     stdeditbrowser.focus();
                    717: }
                    718: 
1.888     raeburn   719: function fix_domain (formname,udom,origdom,uname) {
1.876     raeburn   720:     var formid = getFormIdByName(formname);
                    721:     if (formid > -1) {
1.888     raeburn   722:         var unameid = getIndexByName(formid,uname);
1.876     raeburn   723:         var domid = getIndexByName(formid,udom);
                    724:         var hidedomid = getIndexByName(formid,origdom);
                    725:         if (hidedomid > -1) {
                    726:             var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888     raeburn   727:             var unameval = document.forms[formid].elements[unameid].value;
                    728:             if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
                    729:                 if (domid > -1) {
                    730:                     var slct = document.forms[formid].elements[domid];
                    731:                     if (slct.type == 'select-one') {
                    732:                         var i;
                    733:                         for (i=0;i<slct.length;i++) {
                    734:                             if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
                    735:                         }
                    736:                     }
                    737:                     if (slct.type == 'hidden') {
                    738:                         slct.value = fixeddom;
1.876     raeburn   739:                     }
                    740:                 }
1.468     raeburn   741:             }
                    742:         }
                    743:     }
1.876     raeburn   744:     return;
                    745: }
                    746: 
                    747: $id_functions
                    748: ENDUSERBRW
1.468     raeburn   749: }
                    750: 
                    751: sub setsec_javascript {
1.905     raeburn   752:     my ($sec_element,$formname,$role_element) = @_;
                    753:     my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
                    754:         $communityrolestr);
                    755:     if ($role_element ne '') {
                    756:         my @allroles = ('st','ta','ep','in','ad');
                    757:         foreach my $crstype ('Course','Community') {
                    758:             if ($crstype eq 'Community') {
                    759:                 foreach my $role (@allroles) {
                    760:                     push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
                    761:                 }
                    762:                 push(@communityrolenames,&Apache::lonnet::plaintext('co'));
                    763:             } else {
                    764:                 foreach my $role (@allroles) {
                    765:                     push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
                    766:                 }
                    767:                 push(@courserolenames,&Apache::lonnet::plaintext('cc'));
                    768:             }
                    769:         }
                    770:         $rolestr = '"'.join('","',@allroles).'"';
                    771:         $courserolestr = '"'.join('","',@courserolenames).'"';
                    772:         $communityrolestr = '"'.join('","',@communityrolenames).'"';
                    773:     }
1.468     raeburn   774:     my $setsections = qq|
                    775: function setSect(sectionlist) {
1.629     raeburn   776:     var sectionsArray = new Array();
                    777:     if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
                    778:         sectionsArray = sectionlist.split(",");
                    779:     }
1.468     raeburn   780:     var numSections = sectionsArray.length;
                    781:     document.$formname.$sec_element.length = 0;
                    782:     if (numSections == 0) {
                    783:         document.$formname.$sec_element.multiple=false;
                    784:         document.$formname.$sec_element.size=1;
                    785:         document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
                    786:     } else {
                    787:         if (numSections == 1) {
                    788:             document.$formname.$sec_element.multiple=false;
                    789:             document.$formname.$sec_element.size=1;
                    790:             document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
                    791:             document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
                    792:             document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
                    793:         } else {
                    794:             for (var i=0; i<numSections; i++) {
                    795:                 document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
                    796:             }
                    797:             document.$formname.$sec_element.multiple=true
                    798:             if (numSections < 3) {
                    799:                 document.$formname.$sec_element.size=numSections;
                    800:             } else {
                    801:                 document.$formname.$sec_element.size=3;
                    802:             }
                    803:             document.$formname.$sec_element.options[0].selected = false
                    804:         }
                    805:     }
1.91      www       806: }
1.905     raeburn   807: 
                    808: function setRole(crstype) {
1.468     raeburn   809: |;
1.905     raeburn   810:     if ($role_element eq '') {
                    811:         $setsections .= '    return;
                    812: }
                    813: ';
                    814:     } else {
                    815:         $setsections .= qq|
                    816:     var elementLength = document.$formname.$role_element.length;
                    817:     var allroles = Array($rolestr);
                    818:     var courserolenames = Array($courserolestr);
                    819:     var communityrolenames = Array($communityrolestr);
                    820:     if (elementLength != undefined) {
                    821:         if (document.$formname.$role_element.options[5].value == 'cc') {
                    822:             if (crstype == 'Course') {
                    823:                 return;
                    824:             } else {
                    825:                 allroles[5] = 'co';
                    826:                 for (var i=0; i<6; i++) {
                    827:                     document.$formname.$role_element.options[i].value = allroles[i];
                    828:                     document.$formname.$role_element.options[i].text = communityrolenames[i];
                    829:                 }
                    830:             }
                    831:         } else {
                    832:             if (crstype == 'Community') {
                    833:                 return;
                    834:             } else {
                    835:                 allroles[5] = 'cc';
                    836:                 for (var i=0; i<6; i++) {
                    837:                     document.$formname.$role_element.options[i].value = allroles[i];
                    838:                     document.$formname.$role_element.options[i].text = courserolenames[i];
                    839:                 }
                    840:             }
                    841:         }
                    842:     }
                    843:     return;
                    844: }
                    845: |;
                    846:     }
1.468     raeburn   847:     return $setsections;
                    848: }
                    849: 
1.91      www       850: sub selectcourse_link {
1.909     raeburn   851:    my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
                    852:        $typeelement) = @_;
                    853:    my $type = $selecttype;
1.871     raeburn   854:    my $linktext = &mt('Select Course');
                    855:    if ($selecttype eq 'Community') {
1.909     raeburn   856:        $linktext = &mt('Select Community');
1.906     raeburn   857:    } elsif ($selecttype eq 'Course/Community') {
                    858:        $linktext = &mt('Select Course/Community');
1.909     raeburn   859:        $type = '';
1.1019    raeburn   860:    } elsif ($selecttype eq 'Select') {
                    861:        $linktext = &mt('Select');
                    862:        $type = '';
1.871     raeburn   863:    }
1.787     bisitz    864:    return '<span class="LC_nobreak">'
                    865:          ."<a href='"
                    866:          .'javascript:opencrsbrowser("'.$form.'","'.$unameele
                    867:          .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909     raeburn   868:          .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871     raeburn   869:          ."'>".$linktext.'</a>'
1.787     bisitz    870:          .'</span>';
1.74      www       871: }
1.42      matthew   872: 
1.653     raeburn   873: sub selectauthor_link {
                    874:    my ($form,$udom)=@_;
                    875:    return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
                    876:           &mt('Select Author').'</a>';
                    877: }
                    878: 
1.876     raeburn   879: sub selectuser_link {
1.881     raeburn   880:     my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888     raeburn   881:         $coursedom,$linktext,$caller) = @_;
1.876     raeburn   882:     return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888     raeburn   883:            "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881     raeburn   884:            ');">'.$linktext.'</a>';
1.876     raeburn   885: }
                    886: 
1.273     raeburn   887: sub check_uncheck_jscript {
                    888:     my $jscript = <<"ENDSCRT";
                    889: function checkAll(field) {
                    890:     if (field.length > 0) {
                    891:         for (i = 0; i < field.length; i++) {
1.1075.2.14  raeburn   892:             if (!field[i].disabled) {
                    893:                 field[i].checked = true;
                    894:             }
1.273     raeburn   895:         }
                    896:     } else {
1.1075.2.14  raeburn   897:         if (!field.disabled) {
                    898:             field.checked = true;
                    899:         }
1.273     raeburn   900:     }
                    901: }
                    902:  
                    903: function uncheckAll(field) {
                    904:     if (field.length > 0) {
                    905:         for (i = 0; i < field.length; i++) {
                    906:             field[i].checked = false ;
1.543     albertel  907:         }
                    908:     } else {
1.273     raeburn   909:         field.checked = false ;
                    910:     }
                    911: }
                    912: ENDSCRT
                    913:     return $jscript;
                    914: }
                    915: 
1.656     www       916: sub select_timezone {
1.659     raeburn   917:    my ($name,$selected,$onchange,$includeempty)=@_;
                    918:    my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    919:    if ($includeempty) {
                    920:        $output .= '<option value=""';
                    921:        if (($selected eq '') || ($selected eq 'local')) {
                    922:            $output .= ' selected="selected" ';
                    923:        }
                    924:        $output .= '> </option>';
                    925:    }
1.657     raeburn   926:    my @timezones = DateTime::TimeZone->all_names;
                    927:    foreach my $tzone (@timezones) {
                    928:        $output.= '<option value="'.$tzone.'"';
                    929:        if ($tzone eq $selected) {
                    930:            $output.=' selected="selected"';
                    931:        }
                    932:        $output.=">$tzone</option>\n";
1.656     www       933:    }
                    934:    $output.="</select>";
                    935:    return $output;
                    936: }
1.273     raeburn   937: 
1.687     raeburn   938: sub select_datelocale {
                    939:     my ($name,$selected,$onchange,$includeempty)=@_;
                    940:     my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    941:     if ($includeempty) {
                    942:         $output .= '<option value=""';
                    943:         if ($selected eq '') {
                    944:             $output .= ' selected="selected" ';
                    945:         }
                    946:         $output .= '> </option>';
                    947:     }
                    948:     my (@possibles,%locale_names);
                    949:     my @locales = DateTime::Locale::Catalog::Locales;
                    950:     foreach my $locale (@locales) {
                    951:         if (ref($locale) eq 'HASH') {
                    952:             my $id = $locale->{'id'};
                    953:             if ($id ne '') {
                    954:                 my $en_terr = $locale->{'en_territory'};
                    955:                 my $native_terr = $locale->{'native_territory'};
1.695     raeburn   956:                 my @languages = &Apache::lonlocal::preferred_languages();
1.687     raeburn   957:                 if (grep(/^en$/,@languages) || !@languages) {
                    958:                     if ($en_terr ne '') {
                    959:                         $locale_names{$id} = '('.$en_terr.')';
                    960:                     } elsif ($native_terr ne '') {
                    961:                         $locale_names{$id} = $native_terr;
                    962:                     }
                    963:                 } else {
                    964:                     if ($native_terr ne '') {
                    965:                         $locale_names{$id} = $native_terr.' ';
                    966:                     } elsif ($en_terr ne '') {
                    967:                         $locale_names{$id} = '('.$en_terr.')';
                    968:                     }
                    969:                 }
                    970:                 push (@possibles,$id);
                    971:             }
                    972:         }
                    973:     }
                    974:     foreach my $item (sort(@possibles)) {
                    975:         $output.= '<option value="'.$item.'"';
                    976:         if ($item eq $selected) {
                    977:             $output.=' selected="selected"';
                    978:         }
                    979:         $output.=">$item";
                    980:         if ($locale_names{$item} ne '') {
                    981:             $output.="  $locale_names{$item}</option>\n";
                    982:         }
                    983:         $output.="</option>\n";
                    984:     }
                    985:     $output.="</select>";
                    986:     return $output;
                    987: }
                    988: 
1.792     raeburn   989: sub select_language {
                    990:     my ($name,$selected,$includeempty) = @_;
                    991:     my %langchoices;
                    992:     if ($includeempty) {
1.1075.2.29  raeburn   993:         %langchoices = ('' => &mt('No language preference'));
1.792     raeburn   994:     }
                    995:     foreach my $id (&languageids()) {
                    996:         my $code = &supportedlanguagecode($id);
                    997:         if ($code) {
                    998:             $langchoices{$code} = &plainlanguagedescription($id);
                    999:         }
                   1000:     }
1.970     raeburn  1001:     return &select_form($selected,$name,\%langchoices);
1.792     raeburn  1002: }
                   1003: 
1.42      matthew  1004: =pod
1.36      matthew  1005: 
1.648     raeburn  1006: =item * &linked_select_forms(...)
1.36      matthew  1007: 
                   1008: linked_select_forms returns a string containing a <script></script> block
                   1009: and html for two <select> menus.  The select menus will be linked in that
                   1010: changing the value of the first menu will result in new values being placed
                   1011: in the second menu.  The values in the select menu will appear in alphabetical
1.609     raeburn  1012: order unless a defined order is provided.
1.36      matthew  1013: 
                   1014: linked_select_forms takes the following ordered inputs:
                   1015: 
                   1016: =over 4
                   1017: 
1.112     bowersj2 1018: =item * $formname, the name of the <form> tag
1.36      matthew  1019: 
1.112     bowersj2 1020: =item * $middletext, the text which appears between the <select> tags
1.36      matthew  1021: 
1.112     bowersj2 1022: =item * $firstdefault, the default value for the first menu
1.36      matthew  1023: 
1.112     bowersj2 1024: =item * $firstselectname, the name of the first <select> tag
1.36      matthew  1025: 
1.112     bowersj2 1026: =item * $secondselectname, the name of the second <select> tag
1.36      matthew  1027: 
1.112     bowersj2 1028: =item * $hashref, a reference to a hash containing the data for the menus.
1.36      matthew  1029: 
1.609     raeburn  1030: =item * $menuorder, the order of values in the first menu
                   1031: 
1.41      ng       1032: =back 
                   1033: 
1.36      matthew  1034: Below is an example of such a hash.  Only the 'text', 'default', and 
                   1035: 'select2' keys must appear as stated.  keys(%menu) are the possible 
                   1036: values for the first select menu.  The text that coincides with the 
1.41      ng       1037: first menu value is given in $menu{$choice1}->{'text'}.  The values 
1.36      matthew  1038: and text for the second menu are given in the hash pointed to by 
                   1039: $menu{$choice1}->{'select2'}.  
                   1040: 
1.112     bowersj2 1041:  my %menu = ( A1 => { text =>"Choice A1" ,
                   1042:                        default => "B3",
                   1043:                        select2 => { 
                   1044:                            B1 => "Choice B1",
                   1045:                            B2 => "Choice B2",
                   1046:                            B3 => "Choice B3",
                   1047:                            B4 => "Choice B4"
1.609     raeburn  1048:                            },
                   1049:                        order => ['B4','B3','B1','B2'],
1.112     bowersj2 1050:                    },
                   1051:                A2 => { text =>"Choice A2" ,
                   1052:                        default => "C2",
                   1053:                        select2 => { 
                   1054:                            C1 => "Choice C1",
                   1055:                            C2 => "Choice C2",
                   1056:                            C3 => "Choice C3"
1.609     raeburn  1057:                            },
                   1058:                        order => ['C2','C1','C3'],
1.112     bowersj2 1059:                    },
                   1060:                A3 => { text =>"Choice A3" ,
                   1061:                        default => "D6",
                   1062:                        select2 => { 
                   1063:                            D1 => "Choice D1",
                   1064:                            D2 => "Choice D2",
                   1065:                            D3 => "Choice D3",
                   1066:                            D4 => "Choice D4",
                   1067:                            D5 => "Choice D5",
                   1068:                            D6 => "Choice D6",
                   1069:                            D7 => "Choice D7"
1.609     raeburn  1070:                            },
                   1071:                        order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112     bowersj2 1072:                    }
                   1073:                );
1.36      matthew  1074: 
                   1075: =cut
                   1076: 
                   1077: sub linked_select_forms {
                   1078:     my ($formname,
                   1079:         $middletext,
                   1080:         $firstdefault,
                   1081:         $firstselectname,
                   1082:         $secondselectname, 
1.609     raeburn  1083:         $hashref,
                   1084:         $menuorder,
1.36      matthew  1085:         ) = @_;
                   1086:     my $second = "document.$formname.$secondselectname";
                   1087:     my $first = "document.$formname.$firstselectname";
                   1088:     # output the javascript to do the changing
                   1089:     my $result = '';
1.776     bisitz   1090:     $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824     bisitz   1091:     $result.="// <![CDATA[\n";
1.36      matthew  1092:     $result.="var select2data = new Object();\n";
                   1093:     $" = '","';
                   1094:     my $debug = '';
                   1095:     foreach my $s1 (sort(keys(%$hashref))) {
                   1096:         $result.="select2data.d_$s1 = new Object();\n";        
                   1097:         $result.="select2data.d_$s1.def = new String('".
                   1098:             $hashref->{$s1}->{'default'}."');\n";
1.609     raeburn  1099:         $result.="select2data.d_$s1.values = new Array(";
1.36      matthew  1100:         my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609     raeburn  1101:         if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
                   1102:             @s2values = @{$hashref->{$s1}->{'order'}};
                   1103:         }
1.36      matthew  1104:         $result.="\"@s2values\");\n";
                   1105:         $result.="select2data.d_$s1.texts = new Array(";        
                   1106:         my @s2texts;
                   1107:         foreach my $value (@s2values) {
                   1108:             push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
                   1109:         }
                   1110:         $result.="\"@s2texts\");\n";
                   1111:     }
                   1112:     $"=' ';
                   1113:     $result.= <<"END";
                   1114: 
                   1115: function select1_changed() {
                   1116:     // Determine new choice
                   1117:     var newvalue = "d_" + $first.value;
                   1118:     // update select2
                   1119:     var values     = select2data[newvalue].values;
                   1120:     var texts      = select2data[newvalue].texts;
                   1121:     var select2def = select2data[newvalue].def;
                   1122:     var i;
                   1123:     // out with the old
                   1124:     for (i = 0; i < $second.options.length; i++) {
                   1125:         $second.options[i] = null;
                   1126:     }
                   1127:     // in with the nuclear
                   1128:     for (i=0;i<values.length; i++) {
                   1129:         $second.options[i] = new Option(values[i]);
1.143     matthew  1130:         $second.options[i].value = values[i];
1.36      matthew  1131:         $second.options[i].text = texts[i];
                   1132:         if (values[i] == select2def) {
                   1133:             $second.options[i].selected = true;
                   1134:         }
                   1135:     }
                   1136: }
1.824     bisitz   1137: // ]]>
1.36      matthew  1138: </script>
                   1139: END
                   1140:     # output the initial values for the selection lists
                   1141:     $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609     raeburn  1142:     my @order = sort(keys(%{$hashref}));
                   1143:     if (ref($menuorder) eq 'ARRAY') {
                   1144:         @order = @{$menuorder};
                   1145:     }
                   1146:     foreach my $value (@order) {
1.36      matthew  1147:         $result.="    <option value=\"$value\" ";
1.253     albertel 1148:         $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119     www      1149:         $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36      matthew  1150:     }
                   1151:     $result .= "</select>\n";
                   1152:     my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
                   1153:     $result .= $middletext;
                   1154:     $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
                   1155:     my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609     raeburn  1156:     
                   1157:     my @secondorder = sort(keys(%select2));
                   1158:     if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
                   1159:         @secondorder = @{$hashref->{$firstdefault}->{'order'}};
                   1160:     }
                   1161:     foreach my $value (@secondorder) {
1.36      matthew  1162:         $result.="    <option value=\"$value\" ";        
1.253     albertel 1163:         $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119     www      1164:         $result.=">".&mt($select2{$value})."</option>\n";
1.36      matthew  1165:     }
                   1166:     $result .= "</select>\n";
                   1167:     #    return $debug;
                   1168:     return $result;
                   1169: }   #  end of sub linked_select_forms {
                   1170: 
1.45      matthew  1171: =pod
1.44      bowersj2 1172: 
1.973     raeburn  1173: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44      bowersj2 1174: 
1.112     bowersj2 1175: Returns a string corresponding to an HTML link to the given help
                   1176: $topic, where $topic corresponds to the name of a .tex file in
                   1177: /home/httpd/html/adm/help/tex, with underscores replaced by
                   1178: spaces. 
                   1179: 
                   1180: $text will optionally be linked to the same topic, allowing you to
                   1181: link text in addition to the graphic. If you do not want to link
                   1182: text, but wish to specify one of the later parameters, pass an
                   1183: empty string. 
                   1184: 
                   1185: $stayOnPage is a value that will be interpreted as a boolean. If true,
                   1186: the link will not open a new window. If false, the link will open
                   1187: a new window using Javascript. (Default is false.) 
                   1188: 
                   1189: $width and $height are optional numerical parameters that will
                   1190: override the width and height of the popped up window, which may
1.973     raeburn  1191: be useful for certain help topics with big pictures included.
                   1192: 
                   1193: $imgid is the id of the img tag used for the help icon. This may be
                   1194: used in a javascript call to switch the image src.  See 
                   1195: lonhtmlcommon::htmlareaselectactive() for an example.
1.44      bowersj2 1196: 
                   1197: =cut
                   1198: 
                   1199: sub help_open_topic {
1.973     raeburn  1200:     my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48      bowersj2 1201:     $text = "" if (not defined $text);
1.44      bowersj2 1202:     $stayOnPage = 0 if (not defined $stayOnPage);
1.1033    www      1203:     $width = 500 if (not defined $width);
1.44      bowersj2 1204:     $height = 400 if (not defined $height);
                   1205:     my $filename = $topic;
                   1206:     $filename =~ s/ /_/g;
                   1207: 
1.48      bowersj2 1208:     my $template = "";
                   1209:     my $link;
1.572     banghart 1210:     
1.159     www      1211:     $topic=~s/\W/\_/g;
1.44      bowersj2 1212: 
1.572     banghart 1213:     if (!$stayOnPage) {
1.1033    www      1214: 	$link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037    www      1215:     } elsif ($stayOnPage eq 'popup') {
                   1216:         $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 1217:     } else {
1.48      bowersj2 1218: 	$link = "/adm/help/${filename}.hlp";
                   1219:     }
                   1220: 
                   1221:     # Add the text
1.755     neumanie 1222:     if ($text ne "") {	
1.763     bisitz   1223: 	$template.='<span class="LC_help_open_topic">'
                   1224:                   .'<a target="_top" href="'.$link.'">'
                   1225:                   .$text.'</a>';
1.48      bowersj2 1226:     }
                   1227: 
1.763     bisitz   1228:     # (Always) Add the graphic
1.179     matthew  1229:     my $title = &mt('Online Help');
1.667     raeburn  1230:     my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973     raeburn  1231:     if ($imgid ne '') {
                   1232:         $imgid = ' id="'.$imgid.'"';
                   1233:     }
1.763     bisitz   1234:     $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
                   1235:               .'<img src="'.$helpicon.'" border="0"'
                   1236:               .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973     raeburn  1237:               .' title="'.$title.'" style="vertical-align:middle;"'.$imgid 
1.763     bisitz   1238:               .' /></a>';
                   1239:     if ($text ne "") {	
                   1240:         $template.='</span>';
                   1241:     }
1.44      bowersj2 1242:     return $template;
                   1243: 
1.106     bowersj2 1244: }
                   1245: 
                   1246: # This is a quicky function for Latex cheatsheet editing, since it 
                   1247: # appears in at least four places
                   1248: sub helpLatexCheatsheet {
1.1037    www      1249:     my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732     raeburn  1250:     my $out;
1.106     bowersj2 1251:     my $addOther = '';
1.732     raeburn  1252:     if ($topic) {
1.1037    www      1253: 	$addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763     bisitz   1254:     }
                   1255:     $out = '<span>' # Start cheatsheet
                   1256: 	  .$addOther
                   1257:           .'<span>'
1.1037    www      1258: 	  .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763     bisitz   1259: 	  .'</span> <span>'
1.1037    www      1260: 	  .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763     bisitz   1261: 	  .'</span>';
1.732     raeburn  1262:     unless ($not_author) {
1.763     bisitz   1263:         $out .= ' <span>'
1.1037    www      1264: 	       .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1.763     bisitz   1265: 	       .'</span>';
1.732     raeburn  1266:     }
1.763     bisitz   1267:     $out .= '</span>'; # End cheatsheet
1.732     raeburn  1268:     return $out;
1.172     www      1269: }
                   1270: 
1.430     albertel 1271: sub general_help {
                   1272:     my $helptopic='Student_Intro';
                   1273:     if ($env{'request.role'}=~/^(ca|au)/) {
                   1274: 	$helptopic='Authoring_Intro';
1.907     raeburn  1275:     } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430     albertel 1276: 	$helptopic='Course_Coordination_Intro';
1.672     raeburn  1277:     } elsif ($env{'request.role'}=~/^dc/) {
                   1278:         $helptopic='Domain_Coordination_Intro';
1.430     albertel 1279:     }
                   1280:     return $helptopic;
                   1281: }
                   1282: 
                   1283: sub update_help_link {
                   1284:     my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
                   1285:     my $origurl = $ENV{'REQUEST_URI'};
                   1286:     $origurl=~s|^/~|/priv/|;
                   1287:     my $timestamp = time;
                   1288:     foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
                   1289:         $$datum = &escape($$datum);
                   1290:     }
                   1291: 
                   1292:     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";
                   1293:     my $output .= <<"ENDOUTPUT";
                   1294: <script type="text/javascript">
1.824     bisitz   1295: // <![CDATA[
1.430     albertel 1296: banner_link = '$banner_link';
1.824     bisitz   1297: // ]]>
1.430     albertel 1298: </script>
                   1299: ENDOUTPUT
                   1300:     return $output;
                   1301: }
                   1302: 
                   1303: # now just updates the help link and generates a blue icon
1.193     raeburn  1304: sub help_open_menu {
1.430     albertel 1305:     my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text) 
1.552     banghart 1306: 	= @_;    
1.949     droeschl 1307:     $stayOnPage = 1;
1.430     albertel 1308:     my $output;
                   1309:     if ($component_help) {
                   1310: 	if (!$text) {
                   1311: 	    $output=&help_open_topic($component_help,undef,$stayOnPage,
                   1312: 				       $width,$height);
                   1313: 	} else {
                   1314: 	    my $help_text;
                   1315: 	    $help_text=&unescape($topic);
                   1316: 	    $output='<table><tr><td>'.
                   1317: 		&help_open_topic($component_help,$help_text,$stayOnPage,
                   1318: 				 $width,$height).'</td></tr></table>';
                   1319: 	}
                   1320:     }
                   1321:     my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
                   1322:     return $output.$banner_link;
                   1323: }
                   1324: 
                   1325: sub top_nav_help {
                   1326:     my ($text) = @_;
1.436     albertel 1327:     $text = &mt($text);
1.949     droeschl 1328:     my $stay_on_page = 1;
                   1329: 
1.572     banghart 1330:     my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436     albertel 1331: 	                     : "javascript:helpMenu('open')";
1.572     banghart 1332:     my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436     albertel 1333: 
1.201     raeburn  1334:     my $title = &mt('Get help');
1.436     albertel 1335: 
                   1336:     return <<"END";
                   1337: $banner_link
                   1338:  <a href="$link" title="$title">$text</a>
                   1339: END
                   1340: }
                   1341: 
                   1342: sub help_menu_js {
                   1343:     my ($text) = @_;
1.949     droeschl 1344:     my $stayOnPage = 1;
1.436     albertel 1345:     my $width = 620;
                   1346:     my $height = 600;
1.430     albertel 1347:     my $helptopic=&general_help();
                   1348:     my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261     albertel 1349:     my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331     albertel 1350:     my $start_page =
                   1351:         &Apache::loncommon::start_page('Help Menu', undef,
                   1352: 				       {'frameset'    => 1,
                   1353: 					'js_ready'    => 1,
                   1354: 					'add_entries' => {
                   1355: 					    'border' => '0',
1.579     raeburn  1356: 					    'rows'   => "110,*",},});
1.331     albertel 1357:     my $end_page =
                   1358:         &Apache::loncommon::end_page({'frameset' => 1,
                   1359: 				      'js_ready' => 1,});
                   1360: 
1.436     albertel 1361:     my $template .= <<"ENDTEMPLATE";
                   1362: <script type="text/javascript">
1.877     bisitz   1363: // <![CDATA[
1.253     albertel 1364: // <!-- BEGIN LON-CAPA Internal
1.430     albertel 1365: var banner_link = '';
1.243     raeburn  1366: function helpMenu(target) {
                   1367:     var caller = this;
                   1368:     if (target == 'open') {
                   1369:         var newWindow = null;
                   1370:         try {
1.262     albertel 1371:             newWindow =  window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243     raeburn  1372:         }
                   1373:         catch(error) {
                   1374:             writeHelp(caller);
                   1375:             return;
                   1376:         }
                   1377:         if (newWindow) {
                   1378:             caller = newWindow;
                   1379:         }
1.193     raeburn  1380:     }
1.243     raeburn  1381:     writeHelp(caller);
                   1382:     return;
                   1383: }
                   1384: function writeHelp(caller) {
1.1072    raeburn  1385:     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  1386:     caller.document.close()
                   1387:     caller.focus()
1.193     raeburn  1388: }
1.877     bisitz   1389: // END LON-CAPA Internal -->
1.253     albertel 1390: // ]]>
1.436     albertel 1391: </script>
1.193     raeburn  1392: ENDTEMPLATE
                   1393:     return $template;
                   1394: }
                   1395: 
1.172     www      1396: sub help_open_bug {
                   1397:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1398:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1399:     unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
                   1400:     $text = "" if (not defined $text);
                   1401: 	$stayOnPage=1;
1.184     albertel 1402:     $width = 600 if (not defined $width);
                   1403:     $height = 600 if (not defined $height);
1.172     www      1404: 
                   1405:     $topic=~s/\W+/\+/g;
                   1406:     my $link='';
                   1407:     my $template='';
1.379     albertel 1408:     my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&amp;bug_file_loc='.
                   1409: 	&escape($ENV{'REQUEST_URI'}).'&amp;component='.$topic;
1.172     www      1410:     if (!$stayOnPage)
                   1411:     {
                   1412: 	$link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1413:     }
                   1414:     else
                   1415:     {
                   1416: 	$link = $url;
                   1417:     }
                   1418:     # Add the text
                   1419:     if ($text ne "")
                   1420:     {
                   1421: 	$template .= 
                   1422:   "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1423:   "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172     www      1424:     }
                   1425: 
                   1426:     # Add the graphic
1.179     matthew  1427:     my $title = &mt('Report a Bug');
1.215     albertel 1428:     my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172     www      1429:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1430:  <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172     www      1431: ENDTEMPLATE
                   1432:     if ($text ne '') { $template.='</td></tr></table>' };
                   1433:     return $template;
                   1434: 
                   1435: }
                   1436: 
                   1437: sub help_open_faq {
                   1438:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1439:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1440:     unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
                   1441:     $text = "" if (not defined $text);
                   1442: 	$stayOnPage=1;
                   1443:     $width = 350 if (not defined $width);
                   1444:     $height = 400 if (not defined $height);
                   1445: 
                   1446:     $topic=~s/\W+/\+/g;
                   1447:     my $link='';
                   1448:     my $template='';
                   1449:     my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
                   1450:     if (!$stayOnPage)
                   1451:     {
                   1452: 	$link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1453:     }
                   1454:     else
                   1455:     {
                   1456: 	$link = $url;
                   1457:     }
                   1458: 
                   1459:     # Add the text
                   1460:     if ($text ne "")
                   1461:     {
                   1462: 	$template .= 
1.173     www      1463:   "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1464:   "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172     www      1465:     }
                   1466: 
                   1467:     # Add the graphic
1.179     matthew  1468:     my $title = &mt('View the FAQ');
1.215     albertel 1469:     my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172     www      1470:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1471:  <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172     www      1472: ENDTEMPLATE
                   1473:     if ($text ne '') { $template.='</td></tr></table>' };
                   1474:     return $template;
                   1475: 
1.44      bowersj2 1476: }
1.37      matthew  1477: 
1.180     matthew  1478: ###############################################################
                   1479: ###############################################################
                   1480: 
1.45      matthew  1481: =pod
                   1482: 
1.648     raeburn  1483: =item * &change_content_javascript():
1.256     matthew  1484: 
                   1485: This and the next function allow you to create small sections of an
                   1486: otherwise static HTML page that you can update on the fly with
                   1487: Javascript, even in Netscape 4.
                   1488: 
                   1489: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
                   1490: must be written to the HTML page once. It will prove the Javascript
                   1491: function "change(name, content)". Calling the change function with the
                   1492: name of the section 
                   1493: you want to update, matching the name passed to C<changable_area>, and
                   1494: the new content you want to put in there, will put the content into
                   1495: that area.
                   1496: 
                   1497: B<Note>: Netscape 4 only reserves enough space for the changable area
                   1498: to contain room for the original contents. You need to "make space"
                   1499: for whatever changes you wish to make, and be B<sure> to check your
                   1500: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
                   1501: it's adequate for updating a one-line status display, but little more.
                   1502: This script will set the space to 100% width, so you only need to
                   1503: worry about height in Netscape 4.
                   1504: 
                   1505: Modern browsers are much less limiting, and if you can commit to the
                   1506: user not using Netscape 4, this feature may be used freely with
                   1507: pretty much any HTML.
                   1508: 
                   1509: =cut
                   1510: 
                   1511: sub change_content_javascript {
                   1512:     # If we're on Netscape 4, we need to use Layer-based code
1.258     albertel 1513:     if ($env{'browser.type'} eq 'netscape' &&
                   1514: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1515: 	return (<<NETSCAPE4);
                   1516: 	function change(name, content) {
                   1517: 	    doc = document.layers[name+"___escape"].layers[0].document;
                   1518: 	    doc.open();
                   1519: 	    doc.write(content);
                   1520: 	    doc.close();
                   1521: 	}
                   1522: NETSCAPE4
                   1523:     } else {
                   1524: 	# Otherwise, we need to use semi-standards-compliant code
                   1525: 	# (technically, "innerHTML" isn't standard but the equivalent
                   1526: 	# is really scary, and every useful browser supports it
                   1527: 	return (<<DOMBASED);
                   1528: 	function change(name, content) {
                   1529: 	    element = document.getElementById(name);
                   1530: 	    element.innerHTML = content;
                   1531: 	}
                   1532: DOMBASED
                   1533:     }
                   1534: }
                   1535: 
                   1536: =pod
                   1537: 
1.648     raeburn  1538: =item * &changable_area($name,$origContent):
1.256     matthew  1539: 
                   1540: This provides a "changable area" that can be modified on the fly via
                   1541: the Javascript code provided in C<change_content_javascript>. $name is
                   1542: the name you will use to reference the area later; do not repeat the
                   1543: same name on a given HTML page more then once. $origContent is what
                   1544: the area will originally contain, which can be left blank.
                   1545: 
                   1546: =cut
                   1547: 
                   1548: sub changable_area {
                   1549:     my ($name, $origContent) = @_;
                   1550: 
1.258     albertel 1551:     if ($env{'browser.type'} eq 'netscape' &&
                   1552: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1553: 	# If this is netscape 4, we need to use the Layer tag
                   1554: 	return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
                   1555:     } else {
                   1556: 	return "<span id='$name'>$origContent</span>";
                   1557:     }
                   1558: }
                   1559: 
                   1560: =pod
                   1561: 
1.648     raeburn  1562: =item * &viewport_geometry_js 
1.590     raeburn  1563: 
                   1564: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
                   1565: 
                   1566: =cut
                   1567: 
                   1568: 
                   1569: sub viewport_geometry_js { 
                   1570:     return <<"GEOMETRY";
                   1571: var Geometry = {};
                   1572: function init_geometry() {
                   1573:     if (Geometry.init) { return };
                   1574:     Geometry.init=1;
                   1575:     if (window.innerHeight) {
                   1576:         Geometry.getViewportHeight   = function() { return window.innerHeight; };
                   1577:         Geometry.getViewportWidth   = function() { return window.innerWidth; };
                   1578:         Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
                   1579:         Geometry.getVerticalScroll   = function() { return window.pageYOffset; };
                   1580:     }
                   1581:     else if (document.documentElement && document.documentElement.clientHeight) {
                   1582:         Geometry.getViewportHeight =
                   1583:             function() { return document.documentElement.clientHeight; };
                   1584:         Geometry.getViewportWidth =
                   1585:             function() { return document.documentElement.clientWidth; };
                   1586: 
                   1587:         Geometry.getHorizontalScroll =
                   1588:             function() { return document.documentElement.scrollLeft; };
                   1589:         Geometry.getVerticalScroll =
                   1590:             function() { return document.documentElement.scrollTop; };
                   1591:     }
                   1592:     else if (document.body.clientHeight) {
                   1593:         Geometry.getViewportHeight =
                   1594:             function() { return document.body.clientHeight; };
                   1595:         Geometry.getViewportWidth =
                   1596:             function() { return document.body.clientWidth; };
                   1597:         Geometry.getHorizontalScroll =
                   1598:             function() { return document.body.scrollLeft; };
                   1599:         Geometry.getVerticalScroll =
                   1600:             function() { return document.body.scrollTop; };
                   1601:     }
                   1602: }
                   1603: 
                   1604: GEOMETRY
                   1605: }
                   1606: 
                   1607: =pod
                   1608: 
1.648     raeburn  1609: =item * &viewport_size_js()
1.590     raeburn  1610: 
                   1611: 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. 
                   1612: 
                   1613: =cut
                   1614: 
                   1615: sub viewport_size_js {
                   1616:     my $geometry = &viewport_geometry_js();
                   1617:     return <<"DIMS";
                   1618: 
                   1619: $geometry
                   1620: 
                   1621: function getViewportDims(width,height) {
                   1622:     init_geometry();
                   1623:     width.value = Geometry.getViewportWidth();
                   1624:     height.value = Geometry.getViewportHeight();
                   1625:     return;
                   1626: }
                   1627: 
                   1628: DIMS
                   1629: }
                   1630: 
                   1631: =pod
                   1632: 
1.648     raeburn  1633: =item * &resize_textarea_js()
1.565     albertel 1634: 
                   1635: emits the needed javascript to resize a textarea to be as big as possible
                   1636: 
                   1637: creates a function resize_textrea that takes two IDs first should be
                   1638: the id of the element to resize, second should be the id of a div that
                   1639: surrounds everything that comes after the textarea, this routine needs
                   1640: to be attached to the <body> for the onload and onresize events.
                   1641: 
1.648     raeburn  1642: =back
1.565     albertel 1643: 
                   1644: =cut
                   1645: 
                   1646: sub resize_textarea_js {
1.590     raeburn  1647:     my $geometry = &viewport_geometry_js();
1.565     albertel 1648:     return <<"RESIZE";
                   1649:     <script type="text/javascript">
1.824     bisitz   1650: // <![CDATA[
1.590     raeburn  1651: $geometry
1.565     albertel 1652: 
1.588     albertel 1653: function getX(element) {
                   1654:     var x = 0;
                   1655:     while (element) {
                   1656: 	x += element.offsetLeft;
                   1657: 	element = element.offsetParent;
                   1658:     }
                   1659:     return x;
                   1660: }
                   1661: function getY(element) {
                   1662:     var y = 0;
                   1663:     while (element) {
                   1664: 	y += element.offsetTop;
                   1665: 	element = element.offsetParent;
                   1666:     }
                   1667:     return y;
                   1668: }
                   1669: 
                   1670: 
1.565     albertel 1671: function resize_textarea(textarea_id,bottom_id) {
                   1672:     init_geometry();
                   1673:     var textarea        = document.getElementById(textarea_id);
                   1674:     //alert(textarea);
                   1675: 
1.588     albertel 1676:     var textarea_top    = getY(textarea);
1.565     albertel 1677:     var textarea_height = textarea.offsetHeight;
                   1678:     var bottom          = document.getElementById(bottom_id);
1.588     albertel 1679:     var bottom_top      = getY(bottom);
1.565     albertel 1680:     var bottom_height   = bottom.offsetHeight;
                   1681:     var window_height   = Geometry.getViewportHeight();
1.588     albertel 1682:     var fudge           = 23;
1.565     albertel 1683:     var new_height      = window_height-fudge-textarea_top-bottom_height;
                   1684:     if (new_height < 300) {
                   1685: 	new_height = 300;
                   1686:     }
                   1687:     textarea.style.height=new_height+'px';
                   1688: }
1.824     bisitz   1689: // ]]>
1.565     albertel 1690: </script>
                   1691: RESIZE
                   1692: 
                   1693: }
                   1694: 
                   1695: =pod
                   1696: 
1.256     matthew  1697: =head1 Excel and CSV file utility routines
                   1698: 
                   1699: =over 4
                   1700: 
                   1701: =cut
                   1702: 
                   1703: ###############################################################
                   1704: ###############################################################
                   1705: 
                   1706: =pod
                   1707: 
1.648     raeburn  1708: =item * &csv_translate($text) 
1.37      matthew  1709: 
1.185     www      1710: Translate $text to allow it to be output as a 'comma separated values' 
1.37      matthew  1711: format.
                   1712: 
                   1713: =cut
                   1714: 
1.180     matthew  1715: ###############################################################
                   1716: ###############################################################
1.37      matthew  1717: sub csv_translate {
                   1718:     my $text = shift;
                   1719:     $text =~ s/\"/\"\"/g;
1.209     albertel 1720:     $text =~ s/\n/ /g;
1.37      matthew  1721:     return $text;
                   1722: }
1.180     matthew  1723: 
                   1724: ###############################################################
                   1725: ###############################################################
                   1726: 
                   1727: =pod
                   1728: 
1.648     raeburn  1729: =item * &define_excel_formats()
1.180     matthew  1730: 
                   1731: Define some commonly used Excel cell formats.
                   1732: 
                   1733: Currently supported formats:
                   1734: 
                   1735: =over 4
                   1736: 
                   1737: =item header
                   1738: 
                   1739: =item bold
                   1740: 
                   1741: =item h1
                   1742: 
                   1743: =item h2
                   1744: 
                   1745: =item h3
                   1746: 
1.256     matthew  1747: =item h4
                   1748: 
                   1749: =item i
                   1750: 
1.180     matthew  1751: =item date
                   1752: 
                   1753: =back
                   1754: 
                   1755: Inputs: $workbook
                   1756: 
                   1757: Returns: $format, a hash reference.
                   1758: 
1.1057    foxr     1759: 
1.180     matthew  1760: =cut
                   1761: 
                   1762: ###############################################################
                   1763: ###############################################################
                   1764: sub define_excel_formats {
                   1765:     my ($workbook) = @_;
                   1766:     my $format;
                   1767:     $format->{'header'} = $workbook->add_format(bold      => 1, 
                   1768:                                                 bottom    => 1,
                   1769:                                                 align     => 'center');
                   1770:     $format->{'bold'} = $workbook->add_format(bold=>1);
                   1771:     $format->{'h1'}   = $workbook->add_format(bold=>1, size=>18);
                   1772:     $format->{'h2'}   = $workbook->add_format(bold=>1, size=>16);
                   1773:     $format->{'h3'}   = $workbook->add_format(bold=>1, size=>14);
1.255     matthew  1774:     $format->{'h4'}   = $workbook->add_format(bold=>1, size=>12);
1.246     matthew  1775:     $format->{'i'}    = $workbook->add_format(italic=>1);
1.180     matthew  1776:     $format->{'date'} = $workbook->add_format(num_format=>
1.207     matthew  1777:                                             'mm/dd/yyyy hh:mm:ss');
1.180     matthew  1778:     return $format;
                   1779: }
                   1780: 
                   1781: ###############################################################
                   1782: ###############################################################
1.113     bowersj2 1783: 
                   1784: =pod
                   1785: 
1.648     raeburn  1786: =item * &create_workbook()
1.255     matthew  1787: 
                   1788: Create an Excel worksheet.  If it fails, output message on the
                   1789: request object and return undefs.
                   1790: 
                   1791: Inputs: Apache request object
                   1792: 
                   1793: Returns (undef) on failure, 
                   1794:     Excel worksheet object, scalar with filename, and formats 
                   1795:     from &Apache::loncommon::define_excel_formats on success
                   1796: 
                   1797: =cut
                   1798: 
                   1799: ###############################################################
                   1800: ###############################################################
                   1801: sub create_workbook {
                   1802:     my ($r) = @_;
                   1803:         #
                   1804:     # Create the excel spreadsheet
                   1805:     my $filename = '/prtspool/'.
1.258     albertel 1806:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255     matthew  1807:         time.'_'.rand(1000000000).'.xls';
                   1808:     my $workbook  = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
                   1809:     if (! defined($workbook)) {
                   1810:         $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928     bisitz   1811:         $r->print(
                   1812:             '<p class="LC_error">'
                   1813:            .&mt('Problems occurred in creating the new Excel file.')
                   1814:            .' '.&mt('This error has been logged.')
                   1815:            .' '.&mt('Please alert your LON-CAPA administrator.')
                   1816:            .'</p>'
                   1817:         );
1.255     matthew  1818:         return (undef);
                   1819:     }
                   1820:     #
1.1014    foxr     1821:     $workbook->set_tempdir(LONCAPA::tempdir());
1.255     matthew  1822:     #
                   1823:     my $format = &Apache::loncommon::define_excel_formats($workbook);
                   1824:     return ($workbook,$filename,$format);
                   1825: }
                   1826: 
                   1827: ###############################################################
                   1828: ###############################################################
                   1829: 
                   1830: =pod
                   1831: 
1.648     raeburn  1832: =item * &create_text_file()
1.113     bowersj2 1833: 
1.542     raeburn  1834: Create a file to write to and eventually make available to the user.
1.256     matthew  1835: If file creation fails, outputs an error message on the request object and 
                   1836: return undefs.
1.113     bowersj2 1837: 
1.256     matthew  1838: Inputs: Apache request object, and file suffix
1.113     bowersj2 1839: 
1.256     matthew  1840: Returns (undef) on failure, 
                   1841:     Filehandle and filename on success.
1.113     bowersj2 1842: 
                   1843: =cut
                   1844: 
1.256     matthew  1845: ###############################################################
                   1846: ###############################################################
                   1847: sub create_text_file {
                   1848:     my ($r,$suffix) = @_;
                   1849:     if (! defined($suffix)) { $suffix = 'txt'; };
                   1850:     my $fh;
                   1851:     my $filename = '/prtspool/'.
1.258     albertel 1852:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256     matthew  1853:         time.'_'.rand(1000000000).'.'.$suffix;
                   1854:     $fh = Apache::File->new('>/home/httpd'.$filename);
                   1855:     if (! defined($fh)) {
                   1856:         $r->log_error("Couldn't open $filename for output $!");
1.928     bisitz   1857:         $r->print(
                   1858:             '<p class="LC_error">'
                   1859:            .&mt('Problems occurred in creating the output file.')
                   1860:            .' '.&mt('This error has been logged.')
                   1861:            .' '.&mt('Please alert your LON-CAPA administrator.')
                   1862:            .'</p>'
                   1863:         );
1.113     bowersj2 1864:     }
1.256     matthew  1865:     return ($fh,$filename)
1.113     bowersj2 1866: }
                   1867: 
                   1868: 
1.256     matthew  1869: =pod 
1.113     bowersj2 1870: 
                   1871: =back
                   1872: 
                   1873: =cut
1.37      matthew  1874: 
                   1875: ###############################################################
1.33      matthew  1876: ##        Home server <option> list generating code          ##
                   1877: ###############################################################
1.35      matthew  1878: 
1.169     www      1879: # ------------------------------------------
                   1880: 
                   1881: sub domain_select {
                   1882:     my ($name,$value,$multiple)=@_;
                   1883:     my %domains=map { 
1.514     albertel 1884: 	$_ => $_.' '. &Apache::lonnet::domain($_,'description') 
1.512     albertel 1885:     } &Apache::lonnet::all_domains();
1.169     www      1886:     if ($multiple) {
                   1887: 	$domains{''}=&mt('Any domain');
1.550     albertel 1888: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287     albertel 1889: 	return &multiple_select_form($name,$value,4,\%domains);
1.169     www      1890:     } else {
1.550     albertel 1891: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970     raeburn  1892: 	return &select_form($name,$value,\%domains);
1.169     www      1893:     }
                   1894: }
                   1895: 
1.282     albertel 1896: #-------------------------------------------
                   1897: 
                   1898: =pod
                   1899: 
1.519     raeburn  1900: =head1 Routines for form select boxes
                   1901: 
                   1902: =over 4
                   1903: 
1.648     raeburn  1904: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282     albertel 1905: 
                   1906: Returns a string containing a <select> element int multiple mode
                   1907: 
                   1908: 
                   1909: Args:
                   1910:   $name - name of the <select> element
1.506     raeburn  1911:   $value - scalar or array ref of values that should already be selected
1.282     albertel 1912:   $size - number of rows long the select element is
1.283     albertel 1913:   $hash - the elements should be 'option' => 'shown text'
1.282     albertel 1914:           (shown text should already have been &mt())
1.506     raeburn  1915:   $order - (optional) array ref of the order to show the elements in
1.283     albertel 1916: 
1.282     albertel 1917: =cut
                   1918: 
                   1919: #-------------------------------------------
1.169     www      1920: sub multiple_select_form {
1.284     albertel 1921:     my ($name,$value,$size,$hash,$order)=@_;
1.169     www      1922:     my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
                   1923:     my $output='';
1.191     matthew  1924:     if (! defined($size)) {
                   1925:         $size = 4;
1.283     albertel 1926:         if (scalar(keys(%$hash))<4) {
                   1927:             $size = scalar(keys(%$hash));
1.191     matthew  1928:         }
                   1929:     }
1.734     bisitz   1930:     $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501     banghart 1931:     my @order;
1.506     raeburn  1932:     if (ref($order) eq 'ARRAY')  {
                   1933:         @order = @{$order};
                   1934:     } else {
                   1935:         @order = sort(keys(%$hash));
1.501     banghart 1936:     }
                   1937:     if (exists($$hash{'select_form_order'})) {
                   1938:         @order = @{$$hash{'select_form_order'}};
                   1939:     }
                   1940:         
1.284     albertel 1941:     foreach my $key (@order) {
1.356     albertel 1942:         $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284     albertel 1943:         $output.='selected="selected" ' if ($selected{$key});
                   1944:         $output.='>'.$hash->{$key}."</option>\n";
1.169     www      1945:     }
                   1946:     $output.="</select>\n";
                   1947:     return $output;
                   1948: }
                   1949: 
1.88      www      1950: #-------------------------------------------
                   1951: 
                   1952: =pod
                   1953: 
1.970     raeburn  1954: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88      www      1955: 
                   1956: Returns a string containing a <select name='$name' size='1'> form to 
1.970     raeburn  1957: allow a user to select options from a ref to a hash containing:
                   1958: option_name => displayed text. An optional $onchange can include
                   1959: a javascript onchange item, e.g., onchange="this.form.submit();"  
                   1960: 
1.88      www      1961: See lonrights.pm for an example invocation and use.
                   1962: 
                   1963: =cut
                   1964: 
                   1965: #-------------------------------------------
                   1966: sub select_form {
1.970     raeburn  1967:     my ($def,$name,$hashref,$onchange) = @_;
                   1968:     return unless (ref($hashref) eq 'HASH');
                   1969:     if ($onchange) {
                   1970:         $onchange = ' onchange="'.$onchange.'"';
                   1971:     }
                   1972:     my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128     albertel 1973:     my @keys;
1.970     raeburn  1974:     if (exists($hashref->{'select_form_order'})) {
                   1975: 	@keys=@{$hashref->{'select_form_order'}};
1.128     albertel 1976:     } else {
1.970     raeburn  1977: 	@keys=sort(keys(%{$hashref}));
1.128     albertel 1978:     }
1.356     albertel 1979:     foreach my $key (@keys) {
                   1980:         $selectform.=
                   1981: 	    '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
                   1982:             ($key eq $def ? 'selected="selected" ' : '').
1.970     raeburn  1983:                 ">".$hashref->{$key}."</option>\n";
1.88      www      1984:     }
                   1985:     $selectform.="</select>";
                   1986:     return $selectform;
                   1987: }
                   1988: 
1.475     www      1989: # For display filters
                   1990: 
                   1991: sub display_filter {
1.1074    raeburn  1992:     my ($context) = @_;
1.475     www      1993:     if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477     www      1994:     if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074    raeburn  1995:     my $phraseinput = 'hidden';
                   1996:     my $includeinput = 'hidden';
                   1997:     my ($checked,$includetypestext);
                   1998:     if ($env{'form.displayfilter'} eq 'containing') {
                   1999:         $phraseinput = 'text'; 
                   2000:         if ($context eq 'parmslog') {
                   2001:             $includeinput = 'checkbox';
                   2002:             if ($env{'form.includetypes'}) {
                   2003:                 $checked = ' checked="checked"';
                   2004:             }
                   2005:             $includetypestext = &mt('Include parameter types');
                   2006:         }
                   2007:     } else {
                   2008:         $includetypestext = '&nbsp;';
                   2009:     }
                   2010:     my ($additional,$secondid,$thirdid);
                   2011:     if ($context eq 'parmslog') {
                   2012:         $additional = 
                   2013:             '<label><input type="'.$includeinput.'" name="includetypes"'. 
                   2014:             $checked.' name="includetypes" value="1" id="includetypes" />'.
                   2015:             '&nbsp;<span id="includetypestext">'.$includetypestext.'</span>'.
                   2016:             '</label>';
                   2017:         $secondid = 'includetypes';
                   2018:         $thirdid = 'includetypestext';
                   2019:     }
                   2020:     my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
                   2021:                                                     '$secondid','$thirdid')";
                   2022:     return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475     www      2023: 			       &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
                   2024: 							   (&mt('all'),10,20,50,100,1000,10000))).
1.714     bisitz   2025: 	   '</label></span> <span class="LC_nobreak">'.
1.1074    raeburn  2026:            &mt('Filter: [_1]',
1.477     www      2027: 	   &select_form($env{'form.displayfilter'},
                   2028: 			'displayfilter',
1.970     raeburn  2029: 			{'currentfolder' => 'Current folder/page',
1.477     www      2030: 			 'containing' => 'Containing phrase',
1.1074    raeburn  2031: 			 'none' => 'None'},$onchange)).'&nbsp;'.
                   2032: 			 '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
                   2033:                          &HTML::Entities::encode($env{'form.containingphrase'}).
                   2034:                          '" />'.$additional;
                   2035: }
                   2036: 
                   2037: sub display_filter_js {
                   2038:     my $includetext = &mt('Include parameter types');
                   2039:     return <<"ENDJS";
                   2040:   
                   2041: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
                   2042:     var firstType = 'hidden';
                   2043:     if (setter.options[setter.selectedIndex].value == 'containing') {
                   2044:         firstType = 'text';
                   2045:     }
                   2046:     firstObject = document.getElementById(firstid);
                   2047:     if (typeof(firstObject) == 'object') {
                   2048:         if (firstObject.type != firstType) {
                   2049:             changeInputType(firstObject,firstType);
                   2050:         }
                   2051:     }
                   2052:     if (context == 'parmslog') {
                   2053:         var secondType = 'hidden';
                   2054:         if (firstType == 'text') {
                   2055:             secondType = 'checkbox';
                   2056:         }
                   2057:         secondObject = document.getElementById(secondid);  
                   2058:         if (typeof(secondObject) == 'object') {
                   2059:             if (secondObject.type != secondType) {
                   2060:                 changeInputType(secondObject,secondType);
                   2061:             }
                   2062:         }
                   2063:         var textItem = document.getElementById(thirdid);
                   2064:         var currtext = textItem.innerHTML;
                   2065:         var newtext;
                   2066:         if (firstType == 'text') {
                   2067:             newtext = '$includetext';
                   2068:         } else {
                   2069:             newtext = '&nbsp;';
                   2070:         }
                   2071:         if (currtext != newtext) {
                   2072:             textItem.innerHTML = newtext;
                   2073:         }
                   2074:     }
                   2075:     return;
                   2076: }
                   2077: 
                   2078: function changeInputType(oldObject,newType) {
                   2079:     var newObject = document.createElement('input');
                   2080:     newObject.type = newType;
                   2081:     if (oldObject.size) {
                   2082:         newObject.size = oldObject.size;
                   2083:     }
                   2084:     if (oldObject.value) {
                   2085:         newObject.value = oldObject.value;
                   2086:     }
                   2087:     if (oldObject.name) {
                   2088:         newObject.name = oldObject.name;
                   2089:     }
                   2090:     if (oldObject.id) {
                   2091:         newObject.id = oldObject.id;
                   2092:     }
                   2093:     oldObject.parentNode.replaceChild(newObject,oldObject);
                   2094:     return;
                   2095: }
                   2096: 
                   2097: ENDJS
1.475     www      2098: }
                   2099: 
1.167     www      2100: sub gradeleveldescription {
                   2101:     my $gradelevel=shift;
                   2102:     my %gradelevels=(0 => 'Not specified',
                   2103: 		     1 => 'Grade 1',
                   2104: 		     2 => 'Grade 2',
                   2105: 		     3 => 'Grade 3',
                   2106: 		     4 => 'Grade 4',
                   2107: 		     5 => 'Grade 5',
                   2108: 		     6 => 'Grade 6',
                   2109: 		     7 => 'Grade 7',
                   2110: 		     8 => 'Grade 8',
                   2111: 		     9 => 'Grade 9',
                   2112: 		     10 => 'Grade 10',
                   2113: 		     11 => 'Grade 11',
                   2114: 		     12 => 'Grade 12',
                   2115: 		     13 => 'Grade 13',
                   2116: 		     14 => '100 Level',
                   2117: 		     15 => '200 Level',
                   2118: 		     16 => '300 Level',
                   2119: 		     17 => '400 Level',
                   2120: 		     18 => 'Graduate Level');
                   2121:     return &mt($gradelevels{$gradelevel});
                   2122: }
                   2123: 
1.163     www      2124: sub select_level_form {
                   2125:     my ($deflevel,$name)=@_;
                   2126:     unless ($deflevel) { $deflevel=0; }
1.167     www      2127:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
                   2128:     for (my $i=0; $i<=18; $i++) {
                   2129:         $selectform.="<option value=\"$i\" ".
1.253     albertel 2130:             ($i==$deflevel ? 'selected="selected" ' : '').
1.167     www      2131:                 ">".&gradeleveldescription($i)."</option>\n";
                   2132:     }
                   2133:     $selectform.="</select>";
                   2134:     return $selectform;
1.163     www      2135: }
1.167     www      2136: 
1.35      matthew  2137: #-------------------------------------------
                   2138: 
1.45      matthew  2139: =pod
                   2140: 
1.910     raeburn  2141: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms)
1.35      matthew  2142: 
                   2143: Returns a string containing a <select name='$name' size='1'> form to 
                   2144: allow a user to select the domain to preform an operation in.  
                   2145: See loncreateuser.pm for an example invocation and use.
                   2146: 
1.90      www      2147: If the $includeempty flag is set, it also includes an empty choice ("no domain
                   2148: selected");
                   2149: 
1.743     raeburn  2150: If the $showdomdesc flag is set, the domain name is followed by the domain description.
                   2151: 
1.910     raeburn  2152: 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.
                   2153: 
                   2154: The optional $incdoms is a reference to an array of domains which will be the only available options. 
1.563     raeburn  2155: 
1.35      matthew  2156: =cut
                   2157: 
                   2158: #-------------------------------------------
1.34      matthew  2159: sub select_dom_form {
1.910     raeburn  2160:     my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms) = @_;
1.872     raeburn  2161:     if ($onchange) {
1.874     raeburn  2162:         $onchange = ' onchange="'.$onchange.'"';
1.743     raeburn  2163:     }
1.910     raeburn  2164:     my @domains;
                   2165:     if (ref($incdoms) eq 'ARRAY') {
                   2166:         @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
                   2167:     } else {
                   2168:         @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
                   2169:     }
1.90      www      2170:     if ($includeempty) { @domains=('',@domains); }
1.743     raeburn  2171:     my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356     albertel 2172:     foreach my $dom (@domains) {
                   2173:         $selectdomain.="<option value=\"$dom\" ".
1.563     raeburn  2174:             ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
                   2175:         if ($showdomdesc) {
                   2176:             if ($dom ne '') {
                   2177:                 my $domdesc = &Apache::lonnet::domain($dom,'description');
                   2178:                 if ($domdesc ne '') {
                   2179:                     $selectdomain .= ' ('.$domdesc.')';
                   2180:                 }
                   2181:             } 
                   2182:         }
                   2183:         $selectdomain .= "</option>\n";
1.34      matthew  2184:     }
                   2185:     $selectdomain.="</select>";
                   2186:     return $selectdomain;
                   2187: }
                   2188: 
1.35      matthew  2189: #-------------------------------------------
                   2190: 
1.45      matthew  2191: =pod
                   2192: 
1.648     raeburn  2193: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35      matthew  2194: 
1.586     raeburn  2195: input: 4 arguments (two required, two optional) - 
                   2196:     $domain - domain of new user
                   2197:     $name - name of form element
                   2198:     $default - Value of 'default' causes a default item to be first 
                   2199:                             option, and selected by default. 
                   2200:     $hide - Value of 'hide' causes hiding of the name of the server, 
                   2201:                             if 1 server found, or default, if 0 found.
1.594     raeburn  2202: output: returns 2 items: 
1.586     raeburn  2203: (a) form element which contains either:
                   2204:    (i) <select name="$name">
                   2205:         <option value="$hostid1">$hostid $servers{$hostid}</option>
                   2206:         <option value="$hostid2">$hostid $servers{$hostid}</option>       
                   2207:        </select>
                   2208:        form item if there are multiple library servers in $domain, or
                   2209:    (ii) an <input type="hidden" name="$name" value="$hostid" /> form item 
                   2210:        if there is only one library server in $domain.
                   2211: 
                   2212: (b) number of library servers found.
                   2213: 
                   2214: See loncreateuser.pm for example of use.
1.35      matthew  2215: 
                   2216: =cut
                   2217: 
                   2218: #-------------------------------------------
1.586     raeburn  2219: sub home_server_form_item {
                   2220:     my ($domain,$name,$default,$hide) = @_;
1.513     albertel 2221:     my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586     raeburn  2222:     my $result;
                   2223:     my $numlib = keys(%servers);
                   2224:     if ($numlib > 1) {
                   2225:         $result .= '<select name="'.$name.'" />'."\n";
                   2226:         if ($default) {
1.804     bisitz   2227:             $result .= '<option value="default" selected="selected">'.&mt('default').
1.586     raeburn  2228:                        '</option>'."\n";
                   2229:         }
                   2230:         foreach my $hostid (sort(keys(%servers))) {
                   2231:             $result.= '<option value="'.$hostid.'">'.
                   2232: 	              $hostid.' '.$servers{$hostid}."</option>\n";
                   2233:         }
                   2234:         $result .= '</select>'."\n";
                   2235:     } elsif ($numlib == 1) {
                   2236:         my $hostid;
                   2237:         foreach my $item (keys(%servers)) {
                   2238:             $hostid = $item;
                   2239:         }
                   2240:         $result .= '<input type="hidden" name="'.$name.'" value="'.
                   2241:                    $hostid.'" />';
                   2242:                    if (!$hide) {
                   2243:                        $result .= $hostid.' '.$servers{$hostid};
                   2244:                    }
                   2245:                    $result .= "\n";
                   2246:     } elsif ($default) {
                   2247:         $result .= '<input type="hidden" name="'.$name.
                   2248:                    '" value="default" />';
                   2249:                    if (!$hide) {
                   2250:                        $result .= &mt('default');
                   2251:                    }
                   2252:                    $result .= "\n";
1.33      matthew  2253:     }
1.586     raeburn  2254:     return ($result,$numlib);
1.33      matthew  2255: }
1.112     bowersj2 2256: 
                   2257: =pod
                   2258: 
1.534     albertel 2259: =back 
                   2260: 
1.112     bowersj2 2261: =cut
1.87      matthew  2262: 
                   2263: ###############################################################
1.112     bowersj2 2264: ##                  Decoding User Agent                      ##
1.87      matthew  2265: ###############################################################
                   2266: 
                   2267: =pod
                   2268: 
1.112     bowersj2 2269: =head1 Decoding the User Agent
                   2270: 
                   2271: =over 4
                   2272: 
                   2273: =item * &decode_user_agent()
1.87      matthew  2274: 
                   2275: Inputs: $r
                   2276: 
                   2277: Outputs:
                   2278: 
                   2279: =over 4
                   2280: 
1.112     bowersj2 2281: =item * $httpbrowser
1.87      matthew  2282: 
1.112     bowersj2 2283: =item * $clientbrowser
1.87      matthew  2284: 
1.112     bowersj2 2285: =item * $clientversion
1.87      matthew  2286: 
1.112     bowersj2 2287: =item * $clientmathml
1.87      matthew  2288: 
1.112     bowersj2 2289: =item * $clientunicode
1.87      matthew  2290: 
1.112     bowersj2 2291: =item * $clientos
1.87      matthew  2292: 
                   2293: =back
                   2294: 
1.157     matthew  2295: =back 
                   2296: 
1.87      matthew  2297: =cut
                   2298: 
                   2299: ###############################################################
                   2300: ###############################################################
                   2301: sub decode_user_agent {
1.247     albertel 2302:     my ($r)=@_;
1.87      matthew  2303:     my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
                   2304:     my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
                   2305:     my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247     albertel 2306:     if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87      matthew  2307:     my $clientbrowser='unknown';
                   2308:     my $clientversion='0';
                   2309:     my $clientmathml='';
                   2310:     my $clientunicode='0';
                   2311:     for (my $i=0;$i<=$#browsertype;$i++) {
                   2312:         my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
                   2313: 	if (($httpbrowser=~/$match/i)  && ($httpbrowser!~/$notmatch/i)) {
                   2314: 	    $clientbrowser=$bname;
                   2315:             $httpbrowser=~/$vreg/i;
                   2316: 	    $clientversion=$1;
                   2317:             $clientmathml=($clientversion>=$minv);
                   2318:             $clientunicode=($clientversion>=$univ);
                   2319: 	}
                   2320:     }
                   2321:     my $clientos='unknown';
                   2322:     if (($httpbrowser=~/linux/i) ||
                   2323:         ($httpbrowser=~/unix/i) ||
                   2324:         ($httpbrowser=~/ux/i) ||
                   2325:         ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
                   2326:     if (($httpbrowser=~/vax/i) ||
                   2327:         ($httpbrowser=~/vms/i)) { $clientos='vms'; }
                   2328:     if ($httpbrowser=~/next/i) { $clientos='next'; }
                   2329:     if (($httpbrowser=~/mac/i) ||
                   2330:         ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
                   2331:     if ($httpbrowser=~/win/i) { $clientos='win'; }
                   2332:     if ($httpbrowser=~/embed/i) { $clientos='pda'; }
                   2333:     return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   2334:             $clientunicode,$clientos,);
                   2335: }
                   2336: 
1.32      matthew  2337: ###############################################################
                   2338: ##    Authentication changing form generation subroutines    ##
                   2339: ###############################################################
                   2340: ##
                   2341: ## All of the authform_xxxxxxx subroutines take their inputs in a
                   2342: ## hash, and have reasonable default values.
                   2343: ##
                   2344: ##    formname = the name given in the <form> tag.
1.35      matthew  2345: #-------------------------------------------
                   2346: 
1.45      matthew  2347: =pod
                   2348: 
1.112     bowersj2 2349: =head1 Authentication Routines
                   2350: 
                   2351: =over 4
                   2352: 
1.648     raeburn  2353: =item * &authform_xxxxxx()
1.35      matthew  2354: 
                   2355: The authform_xxxxxx subroutines provide javascript and html forms which 
                   2356: handle some of the conveniences required for authentication forms.  
                   2357: This is not an optimal method, but it works.  
                   2358: 
                   2359: =over 4
                   2360: 
1.112     bowersj2 2361: =item * authform_header
1.35      matthew  2362: 
1.112     bowersj2 2363: =item * authform_authorwarning
1.35      matthew  2364: 
1.112     bowersj2 2365: =item * authform_nochange
1.35      matthew  2366: 
1.112     bowersj2 2367: =item * authform_kerberos
1.35      matthew  2368: 
1.112     bowersj2 2369: =item * authform_internal
1.35      matthew  2370: 
1.112     bowersj2 2371: =item * authform_filesystem
1.35      matthew  2372: 
                   2373: =back
                   2374: 
1.648     raeburn  2375: See loncreateuser.pm for invocation and use examples.
1.157     matthew  2376: 
1.35      matthew  2377: =cut
                   2378: 
                   2379: #-------------------------------------------
1.32      matthew  2380: sub authform_header{  
                   2381:     my %in = (
                   2382:         formname => 'cu',
1.80      albertel 2383:         kerb_def_dom => '',
1.32      matthew  2384:         @_,
                   2385:     );
                   2386:     $in{'formname'} = 'document.' . $in{'formname'};
                   2387:     my $result='';
1.80      albertel 2388: 
                   2389: #---------------------------------------------- Code for upper case translation
                   2390:     my $Javascript_toUpperCase;
                   2391:     unless ($in{kerb_def_dom}) {
                   2392:         $Javascript_toUpperCase =<<"END";
                   2393:         switch (choice) {
                   2394:            case 'krb': currentform.elements[choicearg].value =
                   2395:                currentform.elements[choicearg].value.toUpperCase();
                   2396:                break;
                   2397:            default:
                   2398:         }
                   2399: END
                   2400:     } else {
                   2401:         $Javascript_toUpperCase = "";
                   2402:     }
                   2403: 
1.165     raeburn  2404:     my $radioval = "'nochange'";
1.591     raeburn  2405:     if (defined($in{'curr_authtype'})) {
                   2406:         if ($in{'curr_authtype'} ne '') {
                   2407:             $radioval = "'".$in{'curr_authtype'}."arg'";
                   2408:         }
1.174     matthew  2409:     }
1.165     raeburn  2410:     my $argfield = 'null';
1.591     raeburn  2411:     if (defined($in{'mode'})) {
1.165     raeburn  2412:         if ($in{'mode'} eq 'modifycourse')  {
1.591     raeburn  2413:             if (defined($in{'curr_autharg'})) {
                   2414:                 if ($in{'curr_autharg'} ne '') {
1.165     raeburn  2415:                     $argfield = "'$in{'curr_autharg'}'";
                   2416:                 }
                   2417:             }
                   2418:         }
                   2419:     }
                   2420: 
1.32      matthew  2421:     $result.=<<"END";
                   2422: var current = new Object();
1.165     raeburn  2423: current.radiovalue = $radioval;
                   2424: current.argfield = $argfield;
1.32      matthew  2425: 
                   2426: function changed_radio(choice,currentform) {
                   2427:     var choicearg = choice + 'arg';
                   2428:     // If a radio button in changed, we need to change the argfield
                   2429:     if (current.radiovalue != choice) {
                   2430:         current.radiovalue = choice;
                   2431:         if (current.argfield != null) {
                   2432:             currentform.elements[current.argfield].value = '';
                   2433:         }
                   2434:         if (choice == 'nochange') {
                   2435:             current.argfield = null;
                   2436:         } else {
                   2437:             current.argfield = choicearg;
                   2438:             switch(choice) {
                   2439:                 case 'krb': 
                   2440:                     currentform.elements[current.argfield].value = 
                   2441:                         "$in{'kerb_def_dom'}";
                   2442:                 break;
                   2443:               default:
                   2444:                 break;
                   2445:             }
                   2446:         }
                   2447:     }
                   2448:     return;
                   2449: }
1.22      www      2450: 
1.32      matthew  2451: function changed_text(choice,currentform) {
                   2452:     var choicearg = choice + 'arg';
                   2453:     if (currentform.elements[choicearg].value !='') {
1.80      albertel 2454:         $Javascript_toUpperCase
1.32      matthew  2455:         // clear old field
                   2456:         if ((current.argfield != choicearg) && (current.argfield != null)) {
                   2457:             currentform.elements[current.argfield].value = '';
                   2458:         }
                   2459:         current.argfield = choicearg;
                   2460:     }
                   2461:     set_auth_radio_buttons(choice,currentform);
                   2462:     return;
1.20      www      2463: }
1.32      matthew  2464: 
                   2465: function set_auth_radio_buttons(newvalue,currentform) {
1.986     raeburn  2466:     var numauthchoices = currentform.login.length;
                   2467:     if (typeof numauthchoices  == "undefined") {
                   2468:         return;
                   2469:     } 
1.32      matthew  2470:     var i=0;
1.986     raeburn  2471:     while (i < numauthchoices) {
1.32      matthew  2472:         if (currentform.login[i].value == newvalue) { break; }
                   2473:         i++;
                   2474:     }
1.986     raeburn  2475:     if (i == numauthchoices) {
1.32      matthew  2476:         return;
                   2477:     }
                   2478:     current.radiovalue = newvalue;
                   2479:     currentform.login[i].checked = true;
                   2480:     return;
                   2481: }
                   2482: END
                   2483:     return $result;
                   2484: }
                   2485: 
1.1075.2.20  raeburn  2486: sub authform_authorwarning {
1.32      matthew  2487:     my $result='';
1.144     matthew  2488:     $result='<i>'.
                   2489:         &mt('As a general rule, only authors or co-authors should be '.
                   2490:             'filesystem authenticated '.
                   2491:             '(which allows access to the server filesystem).')."</i>\n";
1.32      matthew  2492:     return $result;
                   2493: }
                   2494: 
1.1075.2.20  raeburn  2495: sub authform_nochange {
1.32      matthew  2496:     my %in = (
                   2497:               formname => 'document.cu',
                   2498:               kerb_def_dom => 'MSU.EDU',
                   2499:               @_,
                   2500:           );
1.1075.2.20  raeburn  2501:     my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'}); 
1.586     raeburn  2502:     my $result;
1.1075.2.20  raeburn  2503:     if (!$authnum) {
                   2504:         $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586     raeburn  2505:     } else {
                   2506:         $result = '<label>'.&mt('[_1] Do not change login data',
                   2507:                   '<input type="radio" name="login" value="nochange" '.
                   2508:                   'checked="checked" onclick="'.
1.281     albertel 2509:             "javascript:changed_radio('nochange',$in{'formname'});".'" />').
                   2510: 	    '</label>';
1.586     raeburn  2511:     }
1.32      matthew  2512:     return $result;
                   2513: }
                   2514: 
1.591     raeburn  2515: sub authform_kerberos {
1.32      matthew  2516:     my %in = (
                   2517:               formname => 'document.cu',
                   2518:               kerb_def_dom => 'MSU.EDU',
1.80      albertel 2519:               kerb_def_auth => 'krb4',
1.32      matthew  2520:               @_,
                   2521:               );
1.586     raeburn  2522:     my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
                   2523:         $autharg,$jscall);
1.1075.2.20  raeburn  2524:     my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80      albertel 2525:     if ($in{'kerb_def_auth'} eq 'krb5') {
1.772     bisitz   2526:        $check5 = ' checked="checked"';
1.80      albertel 2527:     } else {
1.772     bisitz   2528:        $check4 = ' checked="checked"';
1.80      albertel 2529:     }
1.165     raeburn  2530:     $krbarg = $in{'kerb_def_dom'};
1.591     raeburn  2531:     if (defined($in{'curr_authtype'})) {
                   2532:         if ($in{'curr_authtype'} eq 'krb') {
1.772     bisitz   2533:             $krbcheck = ' checked="checked"';
1.623     raeburn  2534:             if (defined($in{'mode'})) {
                   2535:                 if ($in{'mode'} eq 'modifyuser') {
                   2536:                     $krbcheck = '';
                   2537:                 }
                   2538:             }
1.591     raeburn  2539:             if (defined($in{'curr_kerb_ver'})) {
                   2540:                 if ($in{'curr_krb_ver'} eq '5') {
1.772     bisitz   2541:                     $check5 = ' checked="checked"';
1.591     raeburn  2542:                     $check4 = '';
                   2543:                 } else {
1.772     bisitz   2544:                     $check4 = ' checked="checked"';
1.591     raeburn  2545:                     $check5 = '';
                   2546:                 }
1.586     raeburn  2547:             }
1.591     raeburn  2548:             if (defined($in{'curr_autharg'})) {
1.165     raeburn  2549:                 $krbarg = $in{'curr_autharg'};
                   2550:             }
1.586     raeburn  2551:             if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591     raeburn  2552:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2553:                     $result = 
                   2554:     &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
                   2555:         $in{'curr_autharg'},$krbver);
                   2556:                 } else {
                   2557:                     $result =
                   2558:     &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
                   2559:                 }
                   2560:                 return $result; 
                   2561:             }
                   2562:         }
                   2563:     } else {
                   2564:         if ($authnum == 1) {
1.784     bisitz   2565:             $authtype = '<input type="hidden" name="login" value="krb" />';
1.165     raeburn  2566:         }
                   2567:     }
1.586     raeburn  2568:     if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
                   2569:         return;
1.587     raeburn  2570:     } elsif ($authtype eq '') {
1.591     raeburn  2571:         if (defined($in{'mode'})) {
1.587     raeburn  2572:             if ($in{'mode'} eq 'modifycourse') {
                   2573:                 if ($authnum == 1) {
1.1075.2.20  raeburn  2574:                     $authtype = '<input type="radio" name="login" value="krb" />';
1.587     raeburn  2575:                 }
                   2576:             }
                   2577:         }
1.586     raeburn  2578:     }
                   2579:     $jscall = "javascript:changed_radio('krb',$in{'formname'});";
                   2580:     if ($authtype eq '') {
                   2581:         $authtype = '<input type="radio" name="login" value="krb" '.
                   2582:                     'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
                   2583:                     $krbcheck.' />';
                   2584:     }
                   2585:     if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1075.2.20  raeburn  2586:         ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586     raeburn  2587:          $in{'curr_authtype'} eq 'krb5') ||
1.1075.2.20  raeburn  2588:         (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586     raeburn  2589:          $in{'curr_authtype'} eq 'krb4')) {
                   2590:         $result .= &mt
1.144     matthew  2591:         ('[_1] Kerberos authenticated with domain [_2] '.
1.281     albertel 2592:          '[_3] Version 4 [_4] Version 5 [_5]',
1.586     raeburn  2593:          '<label>'.$authtype,
1.281     albertel 2594:          '</label><input type="text" size="10" name="krbarg" '.
1.165     raeburn  2595:              'value="'.$krbarg.'" '.
1.144     matthew  2596:              'onchange="'.$jscall.'" />',
1.281     albertel 2597:          '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
                   2598:          '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
                   2599: 	 '</label>');
1.586     raeburn  2600:     } elsif ($can_assign{'krb4'}) {
                   2601:         $result .= &mt
                   2602:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2603:          '[_3] Version 4 [_4]',
                   2604:          '<label>'.$authtype,
                   2605:          '</label><input type="text" size="10" name="krbarg" '.
                   2606:              'value="'.$krbarg.'" '.
                   2607:              'onchange="'.$jscall.'" />',
                   2608:          '<label><input type="hidden" name="krbver" value="4" />',
                   2609:          '</label>');
                   2610:     } elsif ($can_assign{'krb5'}) {
                   2611:         $result .= &mt
                   2612:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2613:          '[_3] Version 5 [_4]',
                   2614:          '<label>'.$authtype,
                   2615:          '</label><input type="text" size="10" name="krbarg" '.
                   2616:              'value="'.$krbarg.'" '.
                   2617:              'onchange="'.$jscall.'" />',
                   2618:          '<label><input type="hidden" name="krbver" value="5" />',
                   2619:          '</label>');
                   2620:     }
1.32      matthew  2621:     return $result;
                   2622: }
                   2623: 
1.1075.2.20  raeburn  2624: sub authform_internal {
1.586     raeburn  2625:     my %in = (
1.32      matthew  2626:                 formname => 'document.cu',
                   2627:                 kerb_def_dom => 'MSU.EDU',
                   2628:                 @_,
                   2629:                 );
1.586     raeburn  2630:     my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
1.1075.2.20  raeburn  2631:     my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591     raeburn  2632:     if (defined($in{'curr_authtype'})) {
                   2633:         if ($in{'curr_authtype'} eq 'int') {
1.586     raeburn  2634:             if ($can_assign{'int'}) {
1.772     bisitz   2635:                 $intcheck = 'checked="checked" ';
1.623     raeburn  2636:                 if (defined($in{'mode'})) {
                   2637:                     if ($in{'mode'} eq 'modifyuser') {
                   2638:                         $intcheck = '';
                   2639:                     }
                   2640:                 }
1.591     raeburn  2641:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2642:                     $intarg = $in{'curr_autharg'};
                   2643:                 }
                   2644:             } else {
                   2645:                 $result = &mt('Currently internally authenticated.');
                   2646:                 return $result;
1.165     raeburn  2647:             }
                   2648:         }
1.586     raeburn  2649:     } else {
                   2650:         if ($authnum == 1) {
1.784     bisitz   2651:             $authtype = '<input type="hidden" name="login" value="int" />';
1.586     raeburn  2652:         }
                   2653:     }
                   2654:     if (!$can_assign{'int'}) {
                   2655:         return;
1.587     raeburn  2656:     } elsif ($authtype eq '') {
1.591     raeburn  2657:         if (defined($in{'mode'})) {
1.587     raeburn  2658:             if ($in{'mode'} eq 'modifycourse') {
                   2659:                 if ($authnum == 1) {
1.1075.2.20  raeburn  2660:                     $authtype = '<input type="radio" name="login" value="int" />';
1.587     raeburn  2661:                 }
                   2662:             }
                   2663:         }
1.165     raeburn  2664:     }
1.586     raeburn  2665:     $jscall = "javascript:changed_radio('int',$in{'formname'});";
                   2666:     if ($authtype eq '') {
                   2667:         $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
                   2668:                     ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
                   2669:     }
1.605     bisitz   2670:     $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586     raeburn  2671:                $intarg.'" onchange="'.$jscall.'" />';
                   2672:     $result = &mt
1.144     matthew  2673:         ('[_1] Internally authenticated (with initial password [_2])',
1.586     raeburn  2674:          '<label>'.$authtype,'</label>'.$autharg);
1.824     bisitz   2675:     $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  2676:     return $result;
                   2677: }
                   2678: 
1.1075.2.20  raeburn  2679: sub authform_local {
1.32      matthew  2680:     my %in = (
                   2681:               formname => 'document.cu',
                   2682:               kerb_def_dom => 'MSU.EDU',
                   2683:               @_,
                   2684:               );
1.586     raeburn  2685:     my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
1.1075.2.20  raeburn  2686:     my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591     raeburn  2687:     if (defined($in{'curr_authtype'})) {
                   2688:         if ($in{'curr_authtype'} eq 'loc') {
1.586     raeburn  2689:             if ($can_assign{'loc'}) {
1.772     bisitz   2690:                 $loccheck = 'checked="checked" ';
1.623     raeburn  2691:                 if (defined($in{'mode'})) {
                   2692:                     if ($in{'mode'} eq 'modifyuser') {
                   2693:                         $loccheck = '';
                   2694:                     }
                   2695:                 }
1.591     raeburn  2696:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2697:                     $locarg = $in{'curr_autharg'};
                   2698:                 }
                   2699:             } else {
                   2700:                 $result = &mt('Currently using local (institutional) authentication.');
                   2701:                 return $result;
1.165     raeburn  2702:             }
                   2703:         }
1.586     raeburn  2704:     } else {
                   2705:         if ($authnum == 1) {
1.784     bisitz   2706:             $authtype = '<input type="hidden" name="login" value="loc" />';
1.586     raeburn  2707:         }
                   2708:     }
                   2709:     if (!$can_assign{'loc'}) {
                   2710:         return;
1.587     raeburn  2711:     } elsif ($authtype eq '') {
1.591     raeburn  2712:         if (defined($in{'mode'})) {
1.587     raeburn  2713:             if ($in{'mode'} eq 'modifycourse') {
                   2714:                 if ($authnum == 1) {
1.1075.2.20  raeburn  2715:                     $authtype = '<input type="radio" name="login" value="loc" />';
1.587     raeburn  2716:                 }
                   2717:             }
                   2718:         }
1.165     raeburn  2719:     }
1.586     raeburn  2720:     $jscall = "javascript:changed_radio('loc',$in{'formname'});";
                   2721:     if ($authtype eq '') {
                   2722:         $authtype = '<input type="radio" name="login" value="loc" '.
                   2723:                     $loccheck.' onchange="'.$jscall.'" onclick="'.
                   2724:                     $jscall.'" />';
                   2725:     }
                   2726:     $autharg = '<input type="text" size="10" name="locarg" value="'.
                   2727:                $locarg.'" onchange="'.$jscall.'" />';
                   2728:     $result = &mt('[_1] Local Authentication with argument [_2]',
                   2729:                   '<label>'.$authtype,'</label>'.$autharg);
1.32      matthew  2730:     return $result;
                   2731: }
                   2732: 
1.1075.2.20  raeburn  2733: sub authform_filesystem {
1.32      matthew  2734:     my %in = (
                   2735:               formname => 'document.cu',
                   2736:               kerb_def_dom => 'MSU.EDU',
                   2737:               @_,
                   2738:               );
1.586     raeburn  2739:     my ($fsyscheck,$result,$authtype,$autharg,$jscall);
1.1075.2.20  raeburn  2740:     my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591     raeburn  2741:     if (defined($in{'curr_authtype'})) {
                   2742:         if ($in{'curr_authtype'} eq 'fsys') {
1.586     raeburn  2743:             if ($can_assign{'fsys'}) {
1.772     bisitz   2744:                 $fsyscheck = 'checked="checked" ';
1.623     raeburn  2745:                 if (defined($in{'mode'})) {
                   2746:                     if ($in{'mode'} eq 'modifyuser') {
                   2747:                         $fsyscheck = '';
                   2748:                     }
                   2749:                 }
1.586     raeburn  2750:             } else {
                   2751:                 $result = &mt('Currently Filesystem Authenticated.');
                   2752:                 return $result;
                   2753:             }           
                   2754:         }
                   2755:     } else {
                   2756:         if ($authnum == 1) {
1.784     bisitz   2757:             $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586     raeburn  2758:         }
                   2759:     }
                   2760:     if (!$can_assign{'fsys'}) {
                   2761:         return;
1.587     raeburn  2762:     } elsif ($authtype eq '') {
1.591     raeburn  2763:         if (defined($in{'mode'})) {
1.587     raeburn  2764:             if ($in{'mode'} eq 'modifycourse') {
                   2765:                 if ($authnum == 1) {
1.1075.2.20  raeburn  2766:                     $authtype = '<input type="radio" name="login" value="fsys" />';
1.587     raeburn  2767:                 }
                   2768:             }
                   2769:         }
1.586     raeburn  2770:     }
                   2771:     $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
                   2772:     if ($authtype eq '') {
                   2773:         $authtype = '<input type="radio" name="login" value="fsys" '.
                   2774:                     $fsyscheck.' onchange="'.$jscall.'" onclick="'.
                   2775:                     $jscall.'" />';
                   2776:     }
                   2777:     $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
                   2778:                ' onchange="'.$jscall.'" />';
                   2779:     $result = &mt
1.144     matthew  2780:         ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281     albertel 2781:          '<label><input type="radio" name="login" value="fsys" '.
1.586     raeburn  2782:          $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605     bisitz   2783:          '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144     matthew  2784:                   'onchange="'.$jscall.'" />');
1.32      matthew  2785:     return $result;
                   2786: }
                   2787: 
1.586     raeburn  2788: sub get_assignable_auth {
                   2789:     my ($dom) = @_;
                   2790:     if ($dom eq '') {
                   2791:         $dom = $env{'request.role.domain'};
                   2792:     }
                   2793:     my %can_assign = (
                   2794:                           krb4 => 1,
                   2795:                           krb5 => 1,
                   2796:                           int  => 1,
                   2797:                           loc  => 1,
                   2798:                      );
                   2799:     my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
                   2800:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   2801:         if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
                   2802:             my $authhash = $domconfig{'usercreation'}{'authtypes'};
                   2803:             my $context;
                   2804:             if ($env{'request.role'} =~ /^au/) {
                   2805:                 $context = 'author';
                   2806:             } elsif ($env{'request.role'} =~ /^dc/) {
                   2807:                 $context = 'domain';
                   2808:             } elsif ($env{'request.course.id'}) {
                   2809:                 $context = 'course';
                   2810:             }
                   2811:             if ($context) {
                   2812:                 if (ref($authhash->{$context}) eq 'HASH') {
                   2813:                    %can_assign = %{$authhash->{$context}}; 
                   2814:                 }
                   2815:             }
                   2816:         }
                   2817:     }
                   2818:     my $authnum = 0;
                   2819:     foreach my $key (keys(%can_assign)) {
                   2820:         if ($can_assign{$key}) {
                   2821:             $authnum ++;
                   2822:         }
                   2823:     }
                   2824:     if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
                   2825:         $authnum --;
                   2826:     }
                   2827:     return ($authnum,%can_assign);
                   2828: }
                   2829: 
1.80      albertel 2830: ###############################################################
                   2831: ##    Get Kerberos Defaults for Domain                 ##
                   2832: ###############################################################
                   2833: ##
                   2834: ## Returns default kerberos version and an associated argument
                   2835: ## as listed in file domain.tab. If not listed, provides
                   2836: ## appropriate default domain and kerberos version.
                   2837: ##
                   2838: #-------------------------------------------
                   2839: 
                   2840: =pod
                   2841: 
1.648     raeburn  2842: =item * &get_kerberos_defaults()
1.80      albertel 2843: 
                   2844: get_kerberos_defaults($target_domain) returns the default kerberos
1.641     raeburn  2845: version and domain. If not found, it defaults to version 4 and the 
                   2846: domain of the server.
1.80      albertel 2847: 
1.648     raeburn  2848: =over 4
                   2849: 
1.80      albertel 2850: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
                   2851: 
1.648     raeburn  2852: =back
                   2853: 
                   2854: =back
                   2855: 
1.80      albertel 2856: =cut
                   2857: 
                   2858: #-------------------------------------------
                   2859: sub get_kerberos_defaults {
                   2860:     my $domain=shift;
1.641     raeburn  2861:     my ($krbdef,$krbdefdom);
                   2862:     my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
                   2863:     if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
                   2864:         $krbdef = $domdefaults{'auth_def'};
                   2865:         $krbdefdom = $domdefaults{'auth_arg_def'};
                   2866:     } else {
1.80      albertel 2867:         $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
                   2868:         my $krbdefdom=$1;
                   2869:         $krbdefdom=~tr/a-z/A-Z/;
                   2870:         $krbdef = "krb4";
                   2871:     }
                   2872:     return ($krbdef,$krbdefdom);
                   2873: }
1.112     bowersj2 2874: 
1.32      matthew  2875: 
1.46      matthew  2876: ###############################################################
                   2877: ##                Thesaurus Functions                        ##
                   2878: ###############################################################
1.20      www      2879: 
1.46      matthew  2880: =pod
1.20      www      2881: 
1.112     bowersj2 2882: =head1 Thesaurus Functions
                   2883: 
                   2884: =over 4
                   2885: 
1.648     raeburn  2886: =item * &initialize_keywords()
1.46      matthew  2887: 
                   2888: Initializes the package variable %Keywords if it is empty.  Uses the
                   2889: package variable $thesaurus_db_file.
                   2890: 
                   2891: =cut
                   2892: 
                   2893: ###################################################
                   2894: 
                   2895: sub initialize_keywords {
                   2896:     return 1 if (scalar keys(%Keywords));
                   2897:     # If we are here, %Keywords is empty, so fill it up
                   2898:     #   Make sure the file we need exists...
                   2899:     if (! -e $thesaurus_db_file) {
                   2900:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
                   2901:                                  " failed because it does not exist");
                   2902:         return 0;
                   2903:     }
                   2904:     #   Set up the hash as a database
                   2905:     my %thesaurus_db;
                   2906:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2907:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2908:         &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
                   2909:                                  $thesaurus_db_file);
                   2910:         return 0;
                   2911:     } 
                   2912:     #  Get the average number of appearances of a word.
                   2913:     my $avecount = $thesaurus_db{'average.count'};
                   2914:     #  Put keywords (those that appear > average) into %Keywords
                   2915:     while (my ($word,$data)=each (%thesaurus_db)) {
                   2916:         my ($count,undef) = split /:/,$data;
                   2917:         $Keywords{$word}++ if ($count > $avecount);
                   2918:     }
                   2919:     untie %thesaurus_db;
                   2920:     # Remove special values from %Keywords.
1.356     albertel 2921:     foreach my $value ('total.count','average.count') {
                   2922:         delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586     raeburn  2923:   }
1.46      matthew  2924:     return 1;
                   2925: }
                   2926: 
                   2927: ###################################################
                   2928: 
                   2929: =pod
                   2930: 
1.648     raeburn  2931: =item * &keyword($word)
1.46      matthew  2932: 
                   2933: Returns true if $word is a keyword.  A keyword is a word that appears more 
                   2934: than the average number of times in the thesaurus database.  Calls 
                   2935: &initialize_keywords
                   2936: 
                   2937: =cut
                   2938: 
                   2939: ###################################################
1.20      www      2940: 
                   2941: sub keyword {
1.46      matthew  2942:     return if (!&initialize_keywords());
                   2943:     my $word=lc(shift());
                   2944:     $word=~s/\W//g;
                   2945:     return exists($Keywords{$word});
1.20      www      2946: }
1.46      matthew  2947: 
                   2948: ###############################################################
                   2949: 
                   2950: =pod 
1.20      www      2951: 
1.648     raeburn  2952: =item * &get_related_words()
1.46      matthew  2953: 
1.160     matthew  2954: Look up a word in the thesaurus.  Takes a scalar argument and returns
1.46      matthew  2955: an array of words.  If the keyword is not in the thesaurus, an empty array
                   2956: will be returned.  The order of the words returned is determined by the
                   2957: database which holds them.
                   2958: 
                   2959: Uses global $thesaurus_db_file.
                   2960: 
1.1057    foxr     2961: 
1.46      matthew  2962: =cut
                   2963: 
                   2964: ###############################################################
                   2965: sub get_related_words {
                   2966:     my $keyword = shift;
                   2967:     my %thesaurus_db;
                   2968:     if (! -e $thesaurus_db_file) {
                   2969:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
                   2970:                                  "failed because the file does not exist");
                   2971:         return ();
                   2972:     }
                   2973:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2974:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2975:         return ();
                   2976:     } 
                   2977:     my @Words=();
1.429     www      2978:     my $count=0;
1.46      matthew  2979:     if (exists($thesaurus_db{$keyword})) {
1.356     albertel 2980: 	# The first element is the number of times
                   2981: 	# the word appears.  We do not need it now.
1.429     www      2982: 	my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
                   2983: 	my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
                   2984: 	my $threshold=$mostfrequentcount/10;
                   2985:         foreach my $possibleword (@RelatedWords) {
                   2986:             my ($word,$wordcount)=split(/\,/,$possibleword);
                   2987:             if ($wordcount>$threshold) {
                   2988: 		push(@Words,$word);
                   2989:                 $count++;
                   2990:                 if ($count>10) { last; }
                   2991: 	    }
1.20      www      2992:         }
                   2993:     }
1.46      matthew  2994:     untie %thesaurus_db;
                   2995:     return @Words;
1.14      harris41 2996: }
1.46      matthew  2997: 
1.112     bowersj2 2998: =pod
                   2999: 
                   3000: =back
                   3001: 
                   3002: =cut
1.61      www      3003: 
                   3004: # -------------------------------------------------------------- Plaintext name
1.81      albertel 3005: =pod
                   3006: 
1.112     bowersj2 3007: =head1 User Name Functions
                   3008: 
                   3009: =over 4
                   3010: 
1.648     raeburn  3011: =item * &plainname($uname,$udom,$first)
1.81      albertel 3012: 
1.112     bowersj2 3013: Takes a users logon name and returns it as a string in
1.226     albertel 3014: "first middle last generation" form 
                   3015: if $first is set to 'lastname' then it returns it as
                   3016: 'lastname generation, firstname middlename' if their is a lastname
1.81      albertel 3017: 
                   3018: =cut
1.61      www      3019: 
1.295     www      3020: 
1.81      albertel 3021: ###############################################################
1.61      www      3022: sub plainname {
1.226     albertel 3023:     my ($uname,$udom,$first)=@_;
1.537     albertel 3024:     return if (!defined($uname) || !defined($udom));
1.295     www      3025:     my %names=&getnames($uname,$udom);
1.226     albertel 3026:     my $name=&Apache::lonnet::format_name($names{'firstname'},
                   3027: 					  $names{'middlename'},
                   3028: 					  $names{'lastname'},
                   3029: 					  $names{'generation'},$first);
                   3030:     $name=~s/^\s+//;
1.62      www      3031:     $name=~s/\s+$//;
                   3032:     $name=~s/\s+/ /g;
1.353     albertel 3033:     if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62      www      3034:     return $name;
1.61      www      3035: }
1.66      www      3036: 
                   3037: # -------------------------------------------------------------------- Nickname
1.81      albertel 3038: =pod
                   3039: 
1.648     raeburn  3040: =item * &nickname($uname,$udom)
1.81      albertel 3041: 
                   3042: Gets a users name and returns it as a string as
                   3043: 
                   3044: "&quot;nickname&quot;"
1.66      www      3045: 
1.81      albertel 3046: if the user has a nickname or
                   3047: 
                   3048: "first middle last generation"
                   3049: 
                   3050: if the user does not
                   3051: 
                   3052: =cut
1.66      www      3053: 
                   3054: sub nickname {
                   3055:     my ($uname,$udom)=@_;
1.537     albertel 3056:     return if (!defined($uname) || !defined($udom));
1.295     www      3057:     my %names=&getnames($uname,$udom);
1.68      albertel 3058:     my $name=$names{'nickname'};
1.66      www      3059:     if ($name) {
                   3060:        $name='&quot;'.$name.'&quot;'; 
                   3061:     } else {
                   3062:        $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
                   3063: 	     $names{'lastname'}.' '.$names{'generation'};
                   3064:        $name=~s/\s+$//;
                   3065:        $name=~s/\s+/ /g;
                   3066:     }
                   3067:     return $name;
                   3068: }
                   3069: 
1.295     www      3070: sub getnames {
                   3071:     my ($uname,$udom)=@_;
1.537     albertel 3072:     return if (!defined($uname) || !defined($udom));
1.433     albertel 3073:     if ($udom eq 'public' && $uname eq 'public') {
                   3074: 	return ('lastname' => &mt('Public'));
                   3075:     }
1.295     www      3076:     my $id=$uname.':'.$udom;
                   3077:     my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
                   3078:     if ($cached) {
                   3079: 	return %{$names};
                   3080:     } else {
                   3081: 	my %loadnames=&Apache::lonnet::get('environment',
                   3082:                     ['firstname','middlename','lastname','generation','nickname'],
                   3083: 					 $udom,$uname);
                   3084: 	&Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
                   3085: 	return %loadnames;
                   3086:     }
                   3087: }
1.61      www      3088: 
1.542     raeburn  3089: # -------------------------------------------------------------------- getemails
1.648     raeburn  3090: 
1.542     raeburn  3091: =pod
                   3092: 
1.648     raeburn  3093: =item * &getemails($uname,$udom)
1.542     raeburn  3094: 
                   3095: Gets a user's email information and returns it as a hash with keys:
                   3096: notification, critnotification, permanentemail
                   3097: 
                   3098: For notification and critnotification, values are comma-separated lists 
1.648     raeburn  3099: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542     raeburn  3100:  
1.648     raeburn  3101: 
1.542     raeburn  3102: =cut
                   3103: 
1.648     raeburn  3104: 
1.466     albertel 3105: sub getemails {
                   3106:     my ($uname,$udom)=@_;
                   3107:     if ($udom eq 'public' && $uname eq 'public') {
                   3108: 	return;
                   3109:     }
1.467     www      3110:     if (!$udom) { $udom=$env{'user.domain'}; }
                   3111:     if (!$uname) { $uname=$env{'user.name'}; }
1.466     albertel 3112:     my $id=$uname.':'.$udom;
                   3113:     my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
                   3114:     if ($cached) {
                   3115: 	return %{$names};
                   3116:     } else {
                   3117: 	my %loadnames=&Apache::lonnet::get('environment',
                   3118:                     			   ['notification','critnotification',
                   3119: 					    'permanentemail'],
                   3120: 					   $udom,$uname);
                   3121: 	&Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
                   3122: 	return %loadnames;
                   3123:     }
                   3124: }
                   3125: 
1.551     albertel 3126: sub flush_email_cache {
                   3127:     my ($uname,$udom)=@_;
                   3128:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   3129:     if (!$uname) { $uname=$env{'user.name'};   }
                   3130:     return if ($udom eq 'public' && $uname eq 'public');
                   3131:     my $id=$uname.':'.$udom;
                   3132:     &Apache::lonnet::devalidate_cache_new('emailscache',$id);
                   3133: }
                   3134: 
1.728     raeburn  3135: # -------------------------------------------------------------------- getlangs
                   3136: 
                   3137: =pod
                   3138: 
                   3139: =item * &getlangs($uname,$udom)
                   3140: 
                   3141: Gets a user's language preference and returns it as a hash with key:
                   3142: language.
                   3143: 
                   3144: =cut
                   3145: 
                   3146: 
                   3147: sub getlangs {
                   3148:     my ($uname,$udom) = @_;
                   3149:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   3150:     if (!$uname) { $uname=$env{'user.name'};   }
                   3151:     my $id=$uname.':'.$udom;
                   3152:     my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
                   3153:     if ($cached) {
                   3154:         return %{$langs};
                   3155:     } else {
                   3156:         my %loadlangs=&Apache::lonnet::get('environment',['languages'],
                   3157:                                            $udom,$uname);
                   3158:         &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
                   3159:         return %loadlangs;
                   3160:     }
                   3161: }
                   3162: 
                   3163: sub flush_langs_cache {
                   3164:     my ($uname,$udom)=@_;
                   3165:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   3166:     if (!$uname) { $uname=$env{'user.name'};   }
                   3167:     return if ($udom eq 'public' && $uname eq 'public');
                   3168:     my $id=$uname.':'.$udom;
                   3169:     &Apache::lonnet::devalidate_cache_new('userlangs',$id);
                   3170: }
                   3171: 
1.61      www      3172: # ------------------------------------------------------------------ Screenname
1.81      albertel 3173: 
                   3174: =pod
                   3175: 
1.648     raeburn  3176: =item * &screenname($uname,$udom)
1.81      albertel 3177: 
                   3178: Gets a users screenname and returns it as a string
                   3179: 
                   3180: =cut
1.61      www      3181: 
                   3182: sub screenname {
                   3183:     my ($uname,$udom)=@_;
1.258     albertel 3184:     if ($uname eq $env{'user.name'} &&
                   3185: 	$udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212     albertel 3186:     my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68      albertel 3187:     return $names{'screenname'};
1.62      www      3188: }
                   3189: 
1.212     albertel 3190: 
1.802     bisitz   3191: # ------------------------------------------------------------- Confirm Wrapper
                   3192: =pod
                   3193: 
                   3194: =item confirmwrapper
                   3195: 
                   3196: Wrap messages about completion of operation in box
                   3197: 
                   3198: =cut
                   3199: 
                   3200: sub confirmwrapper {
                   3201:     my ($message)=@_;
                   3202:     if ($message) {
                   3203:         return "\n".'<div class="LC_confirm_box">'."\n"
                   3204:                .$message."\n"
                   3205:                .'</div>'."\n";
                   3206:     } else {
                   3207:         return $message;
                   3208:     }
                   3209: }
                   3210: 
1.62      www      3211: # ------------------------------------------------------------- Message Wrapper
                   3212: 
                   3213: sub messagewrapper {
1.369     www      3214:     my ($link,$username,$domain,$subject,$text)=@_;
1.62      www      3215:     return 
1.441     albertel 3216:         '<a href="/adm/email?compose=individual&amp;'.
                   3217:         'recname='.$username.'&amp;recdom='.$domain.
                   3218: 	'&amp;subject='.&escape($subject).'&amp;text='.&escape($text).'" '.
1.200     matthew  3219:         'title="'.&mt('Send message').'">'.$link.'</a>';
1.74      www      3220: }
1.802     bisitz   3221: 
1.74      www      3222: # --------------------------------------------------------------- Notes Wrapper
                   3223: 
                   3224: sub noteswrapper {
                   3225:     my ($link,$un,$do)=@_;
                   3226:     return 
1.896     amueller 3227: "<a href='/adm/email?recordftf=retrieve&amp;recname=$un&amp;recdom=$do'>$link</a>";
1.62      www      3228: }
1.802     bisitz   3229: 
1.62      www      3230: # ------------------------------------------------------------- Aboutme Wrapper
                   3231: 
                   3232: sub aboutmewrapper {
1.1070    raeburn  3233:     my ($link,$username,$domain,$target,$class)=@_;
1.447     raeburn  3234:     if (!defined($username)  && !defined($domain)) {
                   3235:         return;
                   3236:     }
1.1075.2.15  raeburn  3237:     return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070    raeburn  3238: 	($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62      www      3239: }
                   3240: 
                   3241: # ------------------------------------------------------------ Syllabus Wrapper
                   3242: 
                   3243: sub syllabuswrapper {
1.707     bisitz   3244:     my ($linktext,$coursedir,$domain)=@_;
1.208     matthew  3245:     return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61      www      3246: }
1.14      harris41 3247: 
1.802     bisitz   3248: # -----------------------------------------------------------------------------
                   3249: 
1.208     matthew  3250: sub track_student_link {
1.887     raeburn  3251:     my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268     albertel 3252:     my $link ="/adm/trackstudent?";
1.208     matthew  3253:     my $title = 'View recent activity';
                   3254:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   3255:         defined($sdom)  && $sdom  !~ /^\s*$/) {
1.268     albertel 3256:         $link .= "selected_student=$sname:$sdom";
1.208     matthew  3257:         $title .= ' of this student';
1.268     albertel 3258:     } 
1.208     matthew  3259:     if (defined($target) && $target !~ /^\s*$/) {
                   3260:         $target = qq{target="$target"};
                   3261:     } else {
                   3262:         $target = '';
                   3263:     }
1.268     albertel 3264:     if ($start) { $link.='&amp;start='.$start; }
1.887     raeburn  3265:     if ($only_body) { $link .= '&amp;only_body=1'; }
1.554     albertel 3266:     $title = &mt($title);
                   3267:     $linktext = &mt($linktext);
1.448     albertel 3268:     return qq{<a href="$link" title="$title" $target>$linktext</a>}.
                   3269: 	&help_open_topic('View_recent_activity');
1.208     matthew  3270: }
                   3271: 
1.781     raeburn  3272: sub slot_reservations_link {
                   3273:     my ($linktext,$sname,$sdom,$target) = @_;
                   3274:     my $link ="/adm/slotrequest?command=showresv&amp;origin=aboutme";
                   3275:     my $title = 'View slot reservation history';
                   3276:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   3277:         defined($sdom)  && $sdom  !~ /^\s*$/) {
                   3278:         $link .= "&amp;uname=$sname&amp;udom=$sdom";
                   3279:         $title .= ' of this student';
                   3280:     }
                   3281:     if (defined($target) && $target !~ /^\s*$/) {
                   3282:         $target = qq{target="$target"};
                   3283:     } else {
                   3284:         $target = '';
                   3285:     }
                   3286:     $title = &mt($title);
                   3287:     $linktext = &mt($linktext);
                   3288:     return qq{<a href="$link" title="$title" $target>$linktext</a>};
                   3289: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
                   3290: 
                   3291: }
                   3292: 
1.508     www      3293: # ===================================================== Display a student photo
                   3294: 
                   3295: 
1.509     albertel 3296: sub student_image_tag {
1.508     www      3297:     my ($domain,$user)=@_;
                   3298:     my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
                   3299:     if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
                   3300: 	return '<img src="'.$imgsrc.'" align="right" />';
                   3301:     } else {
                   3302: 	return '';
                   3303:     }
                   3304: }
                   3305: 
1.112     bowersj2 3306: =pod
                   3307: 
                   3308: =back
                   3309: 
                   3310: =head1 Access .tab File Data
                   3311: 
                   3312: =over 4
                   3313: 
1.648     raeburn  3314: =item * &languageids() 
1.112     bowersj2 3315: 
                   3316: returns list of all language ids
                   3317: 
                   3318: =cut
                   3319: 
1.14      harris41 3320: sub languageids {
1.16      harris41 3321:     return sort(keys(%language));
1.14      harris41 3322: }
                   3323: 
1.112     bowersj2 3324: =pod
                   3325: 
1.648     raeburn  3326: =item * &languagedescription() 
1.112     bowersj2 3327: 
                   3328: returns description of a specified language id
                   3329: 
                   3330: =cut
                   3331: 
1.14      harris41 3332: sub languagedescription {
1.125     www      3333:     my $code=shift;
                   3334:     return  ($supported_language{$code}?'* ':'').
                   3335:             $language{$code}.
1.126     www      3336: 	    ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145     www      3337: }
                   3338: 
1.1048    foxr     3339: =pod
                   3340: 
                   3341: =item * &plainlanguagedescription
                   3342: 
                   3343: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
                   3344: and the language character encoding (e.g. ISO) separated by a ' - ' string.
                   3345: 
                   3346: =cut
                   3347: 
1.145     www      3348: sub plainlanguagedescription {
                   3349:     my $code=shift;
                   3350:     return $language{$code};
                   3351: }
                   3352: 
1.1048    foxr     3353: =pod
                   3354: 
                   3355: =item * &supportedlanguagecode
                   3356: 
                   3357: Returns the supported language code (e.g. sptutf maps to pt) given a language
                   3358: code.
                   3359: 
                   3360: =cut
                   3361: 
1.145     www      3362: sub supportedlanguagecode {
                   3363:     my $code=shift;
                   3364:     return $supported_language{$code};
1.97      www      3365: }
                   3366: 
1.112     bowersj2 3367: =pod
                   3368: 
1.1048    foxr     3369: =item * &latexlanguage()
                   3370: 
                   3371: Given a language key code returns the correspondnig language to use
                   3372: to select the correct hyphenation on LaTeX printouts.  This is undef if there
                   3373: is no supported hyphenation for the language code.
                   3374: 
                   3375: =cut
                   3376: 
                   3377: sub latexlanguage {
                   3378:     my $code = shift;
                   3379:     return $latex_language{$code};
                   3380: }
                   3381: 
                   3382: =pod
                   3383: 
                   3384: =item * &latexhyphenation()
                   3385: 
                   3386: Same as above but what's supplied is the language as it might be stored
                   3387: in the metadata.
                   3388: 
                   3389: =cut
                   3390: 
                   3391: sub latexhyphenation {
                   3392:     my $key = shift;
                   3393:     return $latex_language_bykey{$key};
                   3394: }
                   3395: 
                   3396: =pod
                   3397: 
1.648     raeburn  3398: =item * &copyrightids() 
1.112     bowersj2 3399: 
                   3400: returns list of all copyrights
                   3401: 
                   3402: =cut
                   3403: 
                   3404: sub copyrightids {
                   3405:     return sort(keys(%cprtag));
                   3406: }
                   3407: 
                   3408: =pod
                   3409: 
1.648     raeburn  3410: =item * &copyrightdescription() 
1.112     bowersj2 3411: 
                   3412: returns description of a specified copyright id
                   3413: 
                   3414: =cut
                   3415: 
                   3416: sub copyrightdescription {
1.166     www      3417:     return &mt($cprtag{shift(@_)});
1.112     bowersj2 3418: }
1.197     matthew  3419: 
                   3420: =pod
                   3421: 
1.648     raeburn  3422: =item * &source_copyrightids() 
1.192     taceyjo1 3423: 
                   3424: returns list of all source copyrights
                   3425: 
                   3426: =cut
                   3427: 
                   3428: sub source_copyrightids {
                   3429:     return sort(keys(%scprtag));
                   3430: }
                   3431: 
                   3432: =pod
                   3433: 
1.648     raeburn  3434: =item * &source_copyrightdescription() 
1.192     taceyjo1 3435: 
                   3436: returns description of a specified source copyright id
                   3437: 
                   3438: =cut
                   3439: 
                   3440: sub source_copyrightdescription {
                   3441:     return &mt($scprtag{shift(@_)});
                   3442: }
1.112     bowersj2 3443: 
                   3444: =pod
                   3445: 
1.648     raeburn  3446: =item * &filecategories() 
1.112     bowersj2 3447: 
                   3448: returns list of all file categories
                   3449: 
                   3450: =cut
                   3451: 
                   3452: sub filecategories {
                   3453:     return sort(keys(%category_extensions));
                   3454: }
                   3455: 
                   3456: =pod
                   3457: 
1.648     raeburn  3458: =item * &filecategorytypes() 
1.112     bowersj2 3459: 
                   3460: returns list of file types belonging to a given file
                   3461: category
                   3462: 
                   3463: =cut
                   3464: 
                   3465: sub filecategorytypes {
1.356     albertel 3466:     my ($cat) = @_;
                   3467:     return @{$category_extensions{lc($cat)}};
1.112     bowersj2 3468: }
                   3469: 
                   3470: =pod
                   3471: 
1.648     raeburn  3472: =item * &fileembstyle() 
1.112     bowersj2 3473: 
                   3474: returns embedding style for a specified file type
                   3475: 
                   3476: =cut
                   3477: 
                   3478: sub fileembstyle {
                   3479:     return $fe{lc(shift(@_))};
1.169     www      3480: }
                   3481: 
1.351     www      3482: sub filemimetype {
                   3483:     return $fm{lc(shift(@_))};
                   3484: }
                   3485: 
1.169     www      3486: 
                   3487: sub filecategoryselect {
                   3488:     my ($name,$value)=@_;
1.189     matthew  3489:     return &select_form($value,$name,
1.970     raeburn  3490:                         {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112     bowersj2 3491: }
                   3492: 
                   3493: =pod
                   3494: 
1.648     raeburn  3495: =item * &filedescription() 
1.112     bowersj2 3496: 
                   3497: returns description for a specified file type
                   3498: 
                   3499: =cut
                   3500: 
                   3501: sub filedescription {
1.188     matthew  3502:     my $file_description = $fd{lc(shift())};
                   3503:     $file_description =~ s:([\[\]]):~$1:g;
                   3504:     return &mt($file_description);
1.112     bowersj2 3505: }
                   3506: 
                   3507: =pod
                   3508: 
1.648     raeburn  3509: =item * &filedescriptionex() 
1.112     bowersj2 3510: 
                   3511: returns description for a specified file type with
                   3512: extra formatting
                   3513: 
                   3514: =cut
                   3515: 
                   3516: sub filedescriptionex {
                   3517:     my $ex=shift;
1.188     matthew  3518:     my $file_description = $fd{lc($ex)};
                   3519:     $file_description =~ s:([\[\]]):~$1:g;
                   3520:     return '.'.$ex.' '.&mt($file_description);
1.112     bowersj2 3521: }
                   3522: 
                   3523: # End of .tab access
                   3524: =pod
                   3525: 
                   3526: =back
                   3527: 
                   3528: =cut
                   3529: 
                   3530: # ------------------------------------------------------------------ File Types
                   3531: sub fileextensions {
                   3532:     return sort(keys(%fe));
                   3533: }
                   3534: 
1.97      www      3535: # ----------------------------------------------------------- Display Languages
                   3536: # returns a hash with all desired display languages
                   3537: #
                   3538: 
                   3539: sub display_languages {
                   3540:     my %languages=();
1.695     raeburn  3541:     foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356     albertel 3542: 	$languages{$lang}=1;
1.97      www      3543:     }
                   3544:     &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258     albertel 3545:     if ($env{'form.displaylanguage'}) {
1.356     albertel 3546: 	foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
                   3547: 	    $languages{$lang}=1;
1.97      www      3548:         }
                   3549:     }
                   3550:     return %languages;
1.14      harris41 3551: }
                   3552: 
1.582     albertel 3553: sub languages {
                   3554:     my ($possible_langs) = @_;
1.695     raeburn  3555:     my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582     albertel 3556:     if (!ref($possible_langs)) {
                   3557: 	if( wantarray ) {
                   3558: 	    return @preferred_langs;
                   3559: 	} else {
                   3560: 	    return $preferred_langs[0];
                   3561: 	}
                   3562:     }
                   3563:     my %possibilities = map { $_ => 1 } (@$possible_langs);
                   3564:     my @preferred_possibilities;
                   3565:     foreach my $preferred_lang (@preferred_langs) {
                   3566: 	if (exists($possibilities{$preferred_lang})) {
                   3567: 	    push(@preferred_possibilities, $preferred_lang);
                   3568: 	}
                   3569:     }
                   3570:     if( wantarray ) {
                   3571: 	return @preferred_possibilities;
                   3572:     }
                   3573:     return $preferred_possibilities[0];
                   3574: }
                   3575: 
1.742     raeburn  3576: sub user_lang {
                   3577:     my ($touname,$toudom,$fromcid) = @_;
                   3578:     my @userlangs;
                   3579:     if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
                   3580:         @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
                   3581:                     $env{'course.'.$fromcid.'.languages'}));
                   3582:     } else {
                   3583:         my %langhash = &getlangs($touname,$toudom);
                   3584:         if ($langhash{'languages'} ne '') {
                   3585:             @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
                   3586:         } else {
                   3587:             my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
                   3588:             if ($domdefs{'lang_def'} ne '') {
                   3589:                 @userlangs = ($domdefs{'lang_def'});
                   3590:             }
                   3591:         }
                   3592:     }
                   3593:     my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
                   3594:     my $user_lh = Apache::localize->get_handle(@languages);
                   3595:     return $user_lh;
                   3596: }
                   3597: 
                   3598: 
1.112     bowersj2 3599: ###############################################################
                   3600: ##               Student Answer Attempts                     ##
                   3601: ###############################################################
                   3602: 
                   3603: =pod
                   3604: 
                   3605: =head1 Alternate Problem Views
                   3606: 
                   3607: =over 4
                   3608: 
1.648     raeburn  3609: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112     bowersj2 3610:     $getattempt, $regexp, $gradesub)
                   3611: 
                   3612: Return string with previous attempt on problem. Arguments:
                   3613: 
                   3614: =over 4
                   3615: 
                   3616: =item * $symb: Problem, including path
                   3617: 
                   3618: =item * $username: username of the desired student
                   3619: 
                   3620: =item * $domain: domain of the desired student
1.14      harris41 3621: 
1.112     bowersj2 3622: =item * $course: Course ID
1.14      harris41 3623: 
1.112     bowersj2 3624: =item * $getattempt: Leave blank for all attempts, otherwise put
                   3625:     something
1.14      harris41 3626: 
1.112     bowersj2 3627: =item * $regexp: if string matches this regexp, the string will be
                   3628:     sent to $gradesub
1.14      harris41 3629: 
1.112     bowersj2 3630: =item * $gradesub: routine that processes the string if it matches $regexp
1.14      harris41 3631: 
1.112     bowersj2 3632: =back
1.14      harris41 3633: 
1.112     bowersj2 3634: The output string is a table containing all desired attempts, if any.
1.16      harris41 3635: 
1.112     bowersj2 3636: =cut
1.1       albertel 3637: 
                   3638: sub get_previous_attempt {
1.43      ng       3639:   my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1       albertel 3640:   my $prevattempts='';
1.43      ng       3641:   no strict 'refs';
1.1       albertel 3642:   if ($symb) {
1.3       albertel 3643:     my (%returnhash)=
                   3644:       &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1       albertel 3645:     if ($returnhash{'version'}) {
                   3646:       my %lasthash=();
                   3647:       my $version;
                   3648:       for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356     albertel 3649:         foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
                   3650: 	  $lasthash{$key}=$returnhash{$version.':'.$key};
1.19      harris41 3651:         }
1.1       albertel 3652:       }
1.596     albertel 3653:       $prevattempts=&start_data_table().&start_data_table_header_row();
                   3654:       $prevattempts.='<th>'.&mt('History').'</th>';
1.978     raeburn  3655:       my (%typeparts,%lasthidden);
1.945     raeburn  3656:       my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356     albertel 3657:       foreach my $key (sort(keys(%lasthash))) {
                   3658: 	my ($ign,@parts) = split(/\./,$key);
1.41      ng       3659: 	if ($#parts > 0) {
1.31      albertel 3660: 	  my $data=$parts[-1];
1.989     raeburn  3661:           next if ($data eq 'foilorder');
1.31      albertel 3662: 	  pop(@parts);
1.1010    www      3663:           $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.'&nbsp;</th>';
1.945     raeburn  3664:           if ($data eq 'type') {
                   3665:               unless ($showsurv) {
                   3666:                   my $id = join(',',@parts);
                   3667:                   $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978     raeburn  3668:                   if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
                   3669:                       $lasthidden{$ign.'.'.$id} = 1;
                   3670:                   }
1.945     raeburn  3671:               }
1.1010    www      3672:           } 
1.31      albertel 3673: 	} else {
1.41      ng       3674: 	  if ($#parts == 0) {
                   3675: 	    $prevattempts.='<th>'.$parts[0].'</th>';
                   3676: 	  } else {
                   3677: 	    $prevattempts.='<th>'.$ign.'</th>';
                   3678: 	  }
1.31      albertel 3679: 	}
1.16      harris41 3680:       }
1.596     albertel 3681:       $prevattempts.=&end_data_table_header_row();
1.40      ng       3682:       if ($getattempt eq '') {
                   3683: 	for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945     raeburn  3684:             my @hidden;
                   3685:             if (%typeparts) {
                   3686:                 foreach my $id (keys(%typeparts)) {
                   3687:                     if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
                   3688:                         push(@hidden,$id);
                   3689:                     }
                   3690:                 }
                   3691:             }
                   3692:             $prevattempts.=&start_data_table_row().
                   3693:                            '<td>'.&mt('Transaction [_1]',$version).'</td>';
                   3694:             if (@hidden) {
                   3695:                 foreach my $key (sort(keys(%lasthash))) {
1.989     raeburn  3696:                     next if ($key =~ /\.foilorder$/);
1.945     raeburn  3697:                     my $hide;
                   3698:                     foreach my $id (@hidden) {
                   3699:                         if ($key =~ /^\Q$id\E/) {
                   3700:                             $hide = 1;
                   3701:                             last;
                   3702:                         }
                   3703:                     }
                   3704:                     if ($hide) {
                   3705:                         my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
                   3706:                         if (($data eq 'award') || ($data eq 'awarddetail')) {
                   3707:                             my $value = &format_previous_attempt_value($key,
                   3708:                                              $returnhash{$version.':'.$key});
                   3709:                             $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3710:                         } else {
                   3711:                             $prevattempts.='<td>&nbsp;</td>';
                   3712:                         }
                   3713:                     } else {
                   3714:                         if ($key =~ /\./) {
                   3715:                             my $value = &format_previous_attempt_value($key,
                   3716:                                               $returnhash{$version.':'.$key});
                   3717:                             $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3718:                         } else {
                   3719:                             $prevattempts.='<td>&nbsp;</td>';
                   3720:                         }
                   3721:                     }
                   3722:                 }
                   3723:             } else {
                   3724: 	        foreach my $key (sort(keys(%lasthash))) {
1.989     raeburn  3725:                     next if ($key =~ /\.foilorder$/);
1.945     raeburn  3726: 		    my $value = &format_previous_attempt_value($key,
                   3727: 			            $returnhash{$version.':'.$key});
                   3728: 		    $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3729: 	        }
                   3730:             }
                   3731: 	    $prevattempts.=&end_data_table_row();
1.40      ng       3732: 	 }
1.1       albertel 3733:       }
1.945     raeburn  3734:       my @currhidden = keys(%lasthidden);
1.596     albertel 3735:       $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356     albertel 3736:       foreach my $key (sort(keys(%lasthash))) {
1.989     raeburn  3737:           next if ($key =~ /\.foilorder$/);
1.945     raeburn  3738:           if (%typeparts) {
                   3739:               my $hidden;
                   3740:               foreach my $id (@currhidden) {
                   3741:                   if ($key =~ /^\Q$id\E/) {
                   3742:                       $hidden = 1;
                   3743:                       last;
                   3744:                   }
                   3745:               }
                   3746:               if ($hidden) {
                   3747:                   my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
                   3748:                   if (($data eq 'award') || ($data eq 'awarddetail')) {
                   3749:                       my $value = &format_previous_attempt_value($key,$lasthash{$key});
                   3750:                       if ($key =~/$regexp$/ && (defined &$gradesub)) {
                   3751:                           $value = &$gradesub($value);
                   3752:                       }
                   3753:                       $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3754:                   } else {
                   3755:                       $prevattempts.='<td>&nbsp;</td>';
                   3756:                   }
                   3757:               } else {
                   3758:                   my $value = &format_previous_attempt_value($key,$lasthash{$key});
                   3759:                   if ($key =~/$regexp$/ && (defined &$gradesub)) {
                   3760:                       $value = &$gradesub($value);
                   3761:                   }
                   3762:                   $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3763:               }
                   3764:           } else {
                   3765: 	      my $value = &format_previous_attempt_value($key,$lasthash{$key});
                   3766: 	      if ($key =~/$regexp$/ && (defined &$gradesub)) {
                   3767:                   $value = &$gradesub($value);
                   3768:               }
                   3769: 	      $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3770:           }
1.16      harris41 3771:       }
1.596     albertel 3772:       $prevattempts.= &end_data_table_row().&end_data_table();
1.1       albertel 3773:     } else {
1.596     albertel 3774:       $prevattempts=
                   3775: 	  &start_data_table().&start_data_table_row().
                   3776: 	  '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
                   3777: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3778:     }
                   3779:   } else {
1.596     albertel 3780:     $prevattempts=
                   3781: 	  &start_data_table().&start_data_table_row().
                   3782: 	  '<td>'.&mt('No data.').'</td>'.
                   3783: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3784:   }
1.10      albertel 3785: }
                   3786: 
1.581     albertel 3787: sub format_previous_attempt_value {
                   3788:     my ($key,$value) = @_;
1.1011    www      3789:     if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581     albertel 3790: 	$value = &Apache::lonlocal::locallocaltime($value);
                   3791:     } elsif (ref($value) eq 'ARRAY') {
                   3792: 	$value = '('.join(', ', @{ $value }).')';
1.988     raeburn  3793:     } elsif ($key =~ /answerstring$/) {
                   3794:         my %answers = &Apache::lonnet::str2hash($value);
                   3795:         my @anskeys = sort(keys(%answers));
                   3796:         if (@anskeys == 1) {
                   3797:             my $answer = $answers{$anskeys[0]};
1.1001    raeburn  3798:             if ($answer =~ m{\0}) {
                   3799:                 $answer =~ s{\0}{,}g;
1.988     raeburn  3800:             }
                   3801:             my $tag_internal_answer_name = 'INTERNAL';
                   3802:             if ($anskeys[0] eq $tag_internal_answer_name) {
                   3803:                 $value = $answer; 
                   3804:             } else {
                   3805:                 $value = $anskeys[0].'='.$answer;
                   3806:             }
                   3807:         } else {
                   3808:             foreach my $ans (@anskeys) {
                   3809:                 my $answer = $answers{$ans};
1.1001    raeburn  3810:                 if ($answer =~ m{\0}) {
                   3811:                     $answer =~ s{\0}{,}g;
1.988     raeburn  3812:                 }
                   3813:                 $value .=  $ans.'='.$answer.'<br />';;
                   3814:             } 
                   3815:         }
1.581     albertel 3816:     } else {
                   3817: 	$value = &unescape($value);
                   3818:     }
                   3819:     return $value;
                   3820: }
                   3821: 
                   3822: 
1.107     albertel 3823: sub relative_to_absolute {
                   3824:     my ($url,$output)=@_;
                   3825:     my $parser=HTML::TokeParser->new(\$output);
                   3826:     my $token;
                   3827:     my $thisdir=$url;
                   3828:     my @rlinks=();
                   3829:     while ($token=$parser->get_token) {
                   3830: 	if ($token->[0] eq 'S') {
                   3831: 	    if ($token->[1] eq 'a') {
                   3832: 		if ($token->[2]->{'href'}) {
                   3833: 		    $rlinks[$#rlinks+1]=$token->[2]->{'href'};
                   3834: 		}
                   3835: 	    } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
                   3836: 		$rlinks[$#rlinks+1]=$token->[2]->{'src'};
                   3837: 	    } elsif ($token->[1] eq 'base') {
                   3838: 		$thisdir=$token->[2]->{'href'};
                   3839: 	    }
                   3840: 	}
                   3841:     }
                   3842:     $thisdir=~s-/[^/]*$--;
1.356     albertel 3843:     foreach my $link (@rlinks) {
1.726     raeburn  3844: 	unless (($link=~/^https?\:\/\//i) ||
1.356     albertel 3845: 		($link=~/^\//) ||
                   3846: 		($link=~/^javascript:/i) ||
                   3847: 		($link=~/^mailto:/i) ||
                   3848: 		($link=~/^\#/)) {
                   3849: 	    my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
                   3850: 	    $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107     albertel 3851: 	}
                   3852:     }
                   3853: # -------------------------------------------------- Deal with Applet codebases
                   3854:     $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
                   3855:     return $output;
                   3856: }
                   3857: 
1.112     bowersj2 3858: =pod
                   3859: 
1.648     raeburn  3860: =item * &get_student_view()
1.112     bowersj2 3861: 
                   3862: show a snapshot of what student was looking at
                   3863: 
                   3864: =cut
                   3865: 
1.10      albertel 3866: sub get_student_view {
1.186     albertel 3867:   my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114     www      3868:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3869:   my (%form);
1.10      albertel 3870:   my @elements=('symb','courseid','domain','username');
                   3871:   foreach my $element (@elements) {
1.186     albertel 3872:       $form{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3873:   }
1.186     albertel 3874:   if (defined($moreenv)) {
                   3875:       %form=(%form,%{$moreenv});
                   3876:   }
1.236     albertel 3877:   if (defined($target)) { $form{'grade_target'} = $target; }
1.107     albertel 3878:   $feedurl=&Apache::lonnet::clutter($feedurl);
1.650     www      3879:   my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11      albertel 3880:   $userview=~s/\<body[^\>]*\>//gi;
                   3881:   $userview=~s/\<\/body\>//gi;
                   3882:   $userview=~s/\<html\>//gi;
                   3883:   $userview=~s/\<\/html\>//gi;
                   3884:   $userview=~s/\<head\>//gi;
                   3885:   $userview=~s/\<\/head\>//gi;
                   3886:   $userview=~s/action\s*\=/would_be_action\=/gi;
1.107     albertel 3887:   $userview=&relative_to_absolute($feedurl,$userview);
1.650     www      3888:   if (wantarray) {
                   3889:      return ($userview,$response);
                   3890:   } else {
                   3891:      return $userview;
                   3892:   }
                   3893: }
                   3894: 
                   3895: sub get_student_view_with_retries {
                   3896:   my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
                   3897: 
                   3898:     my $ok = 0;                 # True if we got a good response.
                   3899:     my $content;
                   3900:     my $response;
                   3901: 
                   3902:     # Try to get the student_view done. within the retries count:
                   3903:     
                   3904:     do {
                   3905:          ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
                   3906:          $ok      = $response->is_success;
                   3907:          if (!$ok) {
                   3908:             &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
                   3909:          }
                   3910:          $retries--;
                   3911:     } while (!$ok && ($retries > 0));
                   3912:     
                   3913:     if (!$ok) {
                   3914:        $content = '';          # On error return an empty content.
                   3915:     }
1.651     www      3916:     if (wantarray) {
                   3917:        return ($content, $response);
                   3918:     } else {
                   3919:        return $content;
                   3920:     }
1.11      albertel 3921: }
                   3922: 
1.112     bowersj2 3923: =pod
                   3924: 
1.648     raeburn  3925: =item * &get_student_answers() 
1.112     bowersj2 3926: 
                   3927: show a snapshot of how student was answering problem
                   3928: 
                   3929: =cut
                   3930: 
1.11      albertel 3931: sub get_student_answers {
1.100     sakharuk 3932:   my ($symb,$username,$domain,$courseid,%form) = @_;
1.114     www      3933:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3934:   my (%moreenv);
1.11      albertel 3935:   my @elements=('symb','courseid','domain','username');
                   3936:   foreach my $element (@elements) {
1.186     albertel 3937:     $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3938:   }
1.186     albertel 3939:   $moreenv{'grade_target'}='answer';
                   3940:   %moreenv=(%form,%moreenv);
1.497     raeburn  3941:   $feedurl = &Apache::lonnet::clutter($feedurl);
                   3942:   my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10      albertel 3943:   return $userview;
1.1       albertel 3944: }
1.116     albertel 3945: 
                   3946: =pod
                   3947: 
                   3948: =item * &submlink()
                   3949: 
1.242     albertel 3950: Inputs: $text $uname $udom $symb $target
1.116     albertel 3951: 
                   3952: Returns: A link to grades.pm such as to see the SUBM view of a student
                   3953: 
                   3954: =cut
                   3955: 
                   3956: ###############################################
                   3957: sub submlink {
1.242     albertel 3958:     my ($text,$uname,$udom,$symb,$target)=@_;
1.116     albertel 3959:     if (!($uname && $udom)) {
                   3960: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3961: 	    &Apache::lonnet::whichuser($symb);
1.116     albertel 3962: 	if (!$symb) { $symb=$cursymb; }
                   3963:     }
1.254     matthew  3964:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3965:     $symb=&escape($symb);
1.960     bisitz   3966:     if ($target) { $target=" target=\"$target\""; }
                   3967:     return
                   3968:         '<a href="/adm/grades?command=submission'.
                   3969:         '&amp;symb='.$symb.
                   3970:         '&amp;student='.$uname.
                   3971:         '&amp;userdom='.$udom.'"'.
                   3972:         $target.'>'.$text.'</a>';
1.242     albertel 3973: }
                   3974: ##############################################
                   3975: 
                   3976: =pod
                   3977: 
                   3978: =item * &pgrdlink()
                   3979: 
                   3980: Inputs: $text $uname $udom $symb $target
                   3981: 
                   3982: Returns: A link to grades.pm such as to see the PGRD view of a student
                   3983: 
                   3984: =cut
                   3985: 
                   3986: ###############################################
                   3987: sub pgrdlink {
                   3988:     my $link=&submlink(@_);
                   3989:     $link=~s/(&command=submission)/$1&showgrading=yes/;
                   3990:     return $link;
                   3991: }
                   3992: ##############################################
                   3993: 
                   3994: =pod
                   3995: 
                   3996: =item * &pprmlink()
                   3997: 
                   3998: Inputs: $text $uname $udom $symb $target
                   3999: 
                   4000: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283     albertel 4001: student and a specific resource
1.242     albertel 4002: 
                   4003: =cut
                   4004: 
                   4005: ###############################################
                   4006: sub pprmlink {
                   4007:     my ($text,$uname,$udom,$symb,$target)=@_;
                   4008:     if (!($uname && $udom)) {
                   4009: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 4010: 	    &Apache::lonnet::whichuser($symb);
1.242     albertel 4011: 	if (!$symb) { $symb=$cursymb; }
                   4012:     }
1.254     matthew  4013:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      4014:     $symb=&escape($symb);
1.242     albertel 4015:     if ($target) { $target="target=\"$target\""; }
1.595     albertel 4016:     return '<a href="/adm/parmset?command=set&amp;'.
                   4017: 	'symb='.$symb.'&amp;uname='.$uname.
                   4018: 	'&amp;udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116     albertel 4019: }
                   4020: ##############################################
1.37      matthew  4021: 
1.112     bowersj2 4022: =pod
                   4023: 
                   4024: =back
                   4025: 
                   4026: =cut
                   4027: 
1.37      matthew  4028: ###############################################
1.51      www      4029: 
                   4030: 
                   4031: sub timehash {
1.687     raeburn  4032:     my ($thistime) = @_;
                   4033:     my $timezone = &Apache::lonlocal::gettimezone();
                   4034:     my $dt = DateTime->from_epoch(epoch => $thistime)
                   4035:                      ->set_time_zone($timezone);
                   4036:     my $wday = $dt->day_of_week();
                   4037:     if ($wday == 7) { $wday = 0; }
                   4038:     return ( 'second' => $dt->second(),
                   4039:              'minute' => $dt->minute(),
                   4040:              'hour'   => $dt->hour(),
                   4041:              'day'     => $dt->day_of_month(),
                   4042:              'month'   => $dt->month(),
                   4043:              'year'    => $dt->year(),
                   4044:              'weekday' => $wday,
                   4045:              'dayyear' => $dt->day_of_year(),
                   4046:              'dlsav'   => $dt->is_dst() );
1.51      www      4047: }
                   4048: 
1.370     www      4049: sub utc_string {
                   4050:     my ($date)=@_;
1.371     www      4051:     return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370     www      4052: }
                   4053: 
1.51      www      4054: sub maketime {
                   4055:     my %th=@_;
1.687     raeburn  4056:     my ($epoch_time,$timezone,$dt);
                   4057:     $timezone = &Apache::lonlocal::gettimezone();
                   4058:     eval {
                   4059:         $dt = DateTime->new( year   => $th{'year'},
                   4060:                              month  => $th{'month'},
                   4061:                              day    => $th{'day'},
                   4062:                              hour   => $th{'hour'},
                   4063:                              minute => $th{'minute'},
                   4064:                              second => $th{'second'},
                   4065:                              time_zone => $timezone,
                   4066:                          );
                   4067:     };
                   4068:     if (!$@) {
                   4069:         $epoch_time = $dt->epoch;
                   4070:         if ($epoch_time) {
                   4071:             return $epoch_time;
                   4072:         }
                   4073:     }
1.51      www      4074:     return POSIX::mktime(
                   4075:         ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210     www      4076:          $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70      www      4077: }
                   4078: 
                   4079: #########################################
1.51      www      4080: 
                   4081: sub findallcourses {
1.482     raeburn  4082:     my ($roles,$uname,$udom) = @_;
1.355     albertel 4083:     my %roles;
                   4084:     if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348     albertel 4085:     my %courses;
1.51      www      4086:     my $now=time;
1.482     raeburn  4087:     if (!defined($uname)) {
                   4088:         $uname = $env{'user.name'};
                   4089:     }
                   4090:     if (!defined($udom)) {
                   4091:         $udom = $env{'user.domain'};
                   4092:     }
                   4093:     if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073    raeburn  4094:         my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482     raeburn  4095:         if (!%roles) {
                   4096:             %roles = (
                   4097:                        cc => 1,
1.907     raeburn  4098:                        co => 1,
1.482     raeburn  4099:                        in => 1,
                   4100:                        ep => 1,
                   4101:                        ta => 1,
                   4102:                        cr => 1,
                   4103:                        st => 1,
                   4104:              );
                   4105:         }
                   4106:         foreach my $entry (keys(%roleshash)) {
                   4107:             my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
                   4108:             if ($trole =~ /^cr/) { 
                   4109:                 next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
                   4110:             } else {
                   4111:                 next if (!exists($roles{$trole}));
                   4112:             }
                   4113:             if ($tend) {
                   4114:                 next if ($tend < $now);
                   4115:             }
                   4116:             if ($tstart) {
                   4117:                 next if ($tstart > $now);
                   4118:             }
1.1058    raeburn  4119:             my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482     raeburn  4120:             (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058    raeburn  4121:             my $value = $trole.'/'.$cdom.'/';
1.482     raeburn  4122:             if ($secpart eq '') {
                   4123:                 ($cnum,$role) = split(/_/,$cnumpart); 
                   4124:                 $sec = 'none';
1.1058    raeburn  4125:                 $value .= $cnum.'/';
1.482     raeburn  4126:             } else {
                   4127:                 $cnum = $cnumpart;
                   4128:                 ($sec,$role) = split(/_/,$secpart);
1.1058    raeburn  4129:                 $value .= $cnum.'/'.$sec;
                   4130:             }
                   4131:             if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
                   4132:                 unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
                   4133:                     push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
                   4134:                 }
                   4135:             } else {
                   4136:                 @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490     raeburn  4137:             }
1.482     raeburn  4138:         }
                   4139:     } else {
                   4140:         foreach my $key (keys(%env)) {
1.483     albertel 4141: 	    if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
                   4142:                  $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482     raeburn  4143: 	        my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
                   4144: 	        next if ($role eq 'ca' || $role eq 'aa');
                   4145: 	        next if (%roles && !exists($roles{$role}));
                   4146: 	        my ($starttime,$endtime)=split(/\./,$env{$key});
                   4147:                 my $active=1;
                   4148:                 if ($starttime) {
                   4149: 		    if ($now<$starttime) { $active=0; }
                   4150:                 }
                   4151:                 if ($endtime) {
                   4152:                     if ($now>$endtime) { $active=0; }
                   4153:                 }
                   4154:                 if ($active) {
1.1058    raeburn  4155:                     my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482     raeburn  4156:                     if ($sec eq '') {
                   4157:                         $sec = 'none';
1.1058    raeburn  4158:                     } else {
                   4159:                         $value .= $sec;
                   4160:                     }
                   4161:                     if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
                   4162:                         unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
                   4163:                             push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
                   4164:                         }
                   4165:                     } else {
                   4166:                         @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482     raeburn  4167:                     }
1.474     raeburn  4168:                 }
                   4169:             }
1.51      www      4170:         }
                   4171:     }
1.474     raeburn  4172:     return %courses;
1.51      www      4173: }
1.37      matthew  4174: 
1.54      www      4175: ###############################################
1.474     raeburn  4176: 
                   4177: sub blockcheck {
1.1062    raeburn  4178:     my ($setters,$activity,$uname,$udom,$url) = @_;
1.490     raeburn  4179: 
                   4180:     if (!defined($udom)) {
                   4181:         $udom = $env{'user.domain'};
                   4182:     }
                   4183:     if (!defined($uname)) {
                   4184:         $uname = $env{'user.name'};
                   4185:     }
                   4186: 
                   4187:     # If uname and udom are for a course, check for blocks in the course.
                   4188: 
                   4189:     if (&Apache::lonnet::is_course($udom,$uname)) {
1.1062    raeburn  4190:         my ($startblock,$endblock,$triggerblock) = 
                   4191:             &get_blocks($setters,$activity,$udom,$uname,$url);
                   4192:         return ($startblock,$endblock,$triggerblock);
1.490     raeburn  4193:     }
1.474     raeburn  4194: 
1.502     raeburn  4195:     my $startblock = 0;
                   4196:     my $endblock = 0;
1.1062    raeburn  4197:     my $triggerblock = '';
1.482     raeburn  4198:     my %live_courses = &findallcourses(undef,$uname,$udom);
1.474     raeburn  4199: 
1.490     raeburn  4200:     # If uname is for a user, and activity is course-specific, i.e.,
                   4201:     # boards, chat or groups, check for blocking in current course only.
1.474     raeburn  4202: 
1.490     raeburn  4203:     if (($activity eq 'boards' || $activity eq 'chat' ||
                   4204:          $activity eq 'groups') && ($env{'request.course.id'})) {
                   4205:         foreach my $key (keys(%live_courses)) {
                   4206:             if ($key ne $env{'request.course.id'}) {
                   4207:                 delete($live_courses{$key});
                   4208:             }
                   4209:         }
                   4210:     }
                   4211: 
                   4212:     my $otheruser = 0;
                   4213:     my %own_courses;
                   4214:     if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
                   4215:         # Resource belongs to user other than current user.
                   4216:         $otheruser = 1;
                   4217:         # Gather courses for current user
                   4218:         %own_courses = 
                   4219:             &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
                   4220:     }
                   4221: 
                   4222:     # Gather active course roles - course coordinator, instructor, 
                   4223:     # exam proctor, ta, student, or custom role.
1.474     raeburn  4224: 
                   4225:     foreach my $course (keys(%live_courses)) {
1.482     raeburn  4226:         my ($cdom,$cnum);
                   4227:         if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
                   4228:             $cdom = $env{'course.'.$course.'.domain'};
                   4229:             $cnum = $env{'course.'.$course.'.num'};
                   4230:         } else {
1.490     raeburn  4231:             ($cdom,$cnum) = split(/_/,$course); 
1.482     raeburn  4232:         }
                   4233:         my $no_ownblock = 0;
                   4234:         my $no_userblock = 0;
1.533     raeburn  4235:         if ($otheruser && $activity ne 'com') {
1.490     raeburn  4236:             # Check if current user has 'evb' priv for this
                   4237:             if (defined($own_courses{$course})) {
                   4238:                 foreach my $sec (keys(%{$own_courses{$course}})) {
                   4239:                     my $checkrole = 'cm./'.$cdom.'/'.$cnum;
                   4240:                     if ($sec ne 'none') {
                   4241:                         $checkrole .= '/'.$sec;
                   4242:                     }
                   4243:                     if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   4244:                         $no_ownblock = 1;
                   4245:                         last;
                   4246:                     }
                   4247:                 }
                   4248:             }
                   4249:             # if they have 'evb' priv and are currently not playing student
                   4250:             next if (($no_ownblock) &&
                   4251:                  ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
                   4252:         }
1.474     raeburn  4253:         foreach my $sec (keys(%{$live_courses{$course}})) {
1.482     raeburn  4254:             my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474     raeburn  4255:             if ($sec ne 'none') {
1.482     raeburn  4256:                 $checkrole .= '/'.$sec;
1.474     raeburn  4257:             }
1.490     raeburn  4258:             if ($otheruser) {
                   4259:                 # Resource belongs to user other than current user.
                   4260:                 # Assemble privs for that user, and check for 'evb' priv.
1.1058    raeburn  4261:                 my (%allroles,%userroles);
                   4262:                 if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
                   4263:                     foreach my $entry (@{$live_courses{$course}{$sec}}) { 
                   4264:                         my ($trole,$tdom,$tnum,$tsec);
                   4265:                         if ($entry =~ /^cr/) {
                   4266:                             ($trole,$tdom,$tnum,$tsec) = 
                   4267:                                 ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
                   4268:                         } else {
                   4269:                            ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
                   4270:                         }
                   4271:                         my ($spec,$area,$trest);
                   4272:                         $area = '/'.$tdom.'/'.$tnum;
                   4273:                         $trest = $tnum;
                   4274:                         if ($tsec ne '') {
                   4275:                             $area .= '/'.$tsec;
                   4276:                             $trest .= '/'.$tsec;
                   4277:                         }
                   4278:                         $spec = $trole.'.'.$area;
                   4279:                         if ($trole =~ /^cr/) {
                   4280:                             &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
                   4281:                                                               $tdom,$spec,$trest,$area);
                   4282:                         } else {
                   4283:                             &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
                   4284:                                                                 $tdom,$spec,$trest,$area);
                   4285:                         }
                   4286:                     }
                   4287:                     my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
                   4288:                     if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
                   4289:                         if ($1) {
                   4290:                             $no_userblock = 1;
                   4291:                             last;
                   4292:                         }
1.486     raeburn  4293:                     }
                   4294:                 }
1.490     raeburn  4295:             } else {
                   4296:                 # Resource belongs to current user
                   4297:                 # Check for 'evb' priv via lonnet::allowed().
1.482     raeburn  4298:                 if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   4299:                     $no_ownblock = 1;
                   4300:                     last;
                   4301:                 }
1.474     raeburn  4302:             }
                   4303:         }
                   4304:         # if they have the evb priv and are currently not playing student
1.482     raeburn  4305:         next if (($no_ownblock) &&
1.491     albertel 4306:                  ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482     raeburn  4307:         next if ($no_userblock);
1.474     raeburn  4308: 
1.866     kalberla 4309:         # Retrieve blocking times and identity of locker for course
1.490     raeburn  4310:         # of specified user, unless user has 'evb' privilege.
1.502     raeburn  4311:         
1.1062    raeburn  4312:         my ($start,$end,$trigger) = 
                   4313:             &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502     raeburn  4314:         if (($start != 0) && 
                   4315:             (($startblock == 0) || ($startblock > $start))) {
                   4316:             $startblock = $start;
1.1062    raeburn  4317:             if ($trigger ne '') {
                   4318:                 $triggerblock = $trigger;
                   4319:             }
1.502     raeburn  4320:         }
                   4321:         if (($end != 0)  &&
                   4322:             (($endblock == 0) || ($endblock < $end))) {
                   4323:             $endblock = $end;
1.1062    raeburn  4324:             if ($trigger ne '') {
                   4325:                 $triggerblock = $trigger;
                   4326:             }
1.502     raeburn  4327:         }
1.490     raeburn  4328:     }
1.1062    raeburn  4329:     return ($startblock,$endblock,$triggerblock);
1.490     raeburn  4330: }
                   4331: 
                   4332: sub get_blocks {
1.1062    raeburn  4333:     my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490     raeburn  4334:     my $startblock = 0;
                   4335:     my $endblock = 0;
1.1062    raeburn  4336:     my $triggerblock = '';
1.490     raeburn  4337:     my $course = $cdom.'_'.$cnum;
                   4338:     $setters->{$course} = {};
                   4339:     $setters->{$course}{'staff'} = [];
                   4340:     $setters->{$course}{'times'} = [];
1.1062    raeburn  4341:     $setters->{$course}{'triggers'} = [];
                   4342:     my (@blockers,%triggered);
                   4343:     my $now = time;
                   4344:     my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
                   4345:     if ($activity eq 'docs') {
                   4346:         @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
                   4347:         foreach my $block (@blockers) {
                   4348:             if ($block =~ /^firstaccess____(.+)$/) {
                   4349:                 my $item = $1;
                   4350:                 my $type = 'map';
                   4351:                 my $timersymb = $item;
                   4352:                 if ($item eq 'course') {
                   4353:                     $type = 'course';
                   4354:                 } elsif ($item =~ /___\d+___/) {
                   4355:                     $type = 'resource';
                   4356:                 } else {
                   4357:                     $timersymb = &Apache::lonnet::symbread($item);
                   4358:                 }
                   4359:                 my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
                   4360:                 my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
                   4361:                 $triggered{$block} = {
                   4362:                                        start => $start,
                   4363:                                        end   => $end,
                   4364:                                        type  => $type,
                   4365:                                      };
                   4366:             }
                   4367:         }
                   4368:     } else {
                   4369:         foreach my $block (keys(%commblocks)) {
                   4370:             if ($block =~ m/^(\d+)____(\d+)$/) { 
                   4371:                 my ($start,$end) = ($1,$2);
                   4372:                 if ($start <= time && $end >= time) {
                   4373:                     if (ref($commblocks{$block}) eq 'HASH') {
                   4374:                         if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
                   4375:                             if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
                   4376:                                 unless(grep(/^\Q$block\E$/,@blockers)) {
                   4377:                                     push(@blockers,$block);
                   4378:                                 }
                   4379:                             }
                   4380:                         }
                   4381:                     }
                   4382:                 }
                   4383:             } elsif ($block =~ /^firstaccess____(.+)$/) {
                   4384:                 my $item = $1;
                   4385:                 my $timersymb = $item; 
                   4386:                 my $type = 'map';
                   4387:                 if ($item eq 'course') {
                   4388:                     $type = 'course';
                   4389:                 } elsif ($item =~ /___\d+___/) {
                   4390:                     $type = 'resource';
                   4391:                 } else {
                   4392:                     $timersymb = &Apache::lonnet::symbread($item);
                   4393:                 }
                   4394:                 my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
                   4395:                 my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb}; 
                   4396:                 if ($start && $end) {
                   4397:                     if (($start <= time) && ($end >= time)) {
                   4398:                         unless (grep(/^\Q$block\E$/,@blockers)) {
                   4399:                             push(@blockers,$block);
                   4400:                             $triggered{$block} = {
                   4401:                                                    start => $start,
                   4402:                                                    end   => $end,
                   4403:                                                    type  => $type,
                   4404:                                                  };
                   4405:                         }
                   4406:                     }
1.490     raeburn  4407:                 }
1.1062    raeburn  4408:             }
                   4409:         }
                   4410:     }
                   4411:     foreach my $blocker (@blockers) {
                   4412:         my ($staff_name,$staff_dom,$title,$blocks) =
                   4413:             &parse_block_record($commblocks{$blocker});
                   4414:         push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
                   4415:         my ($start,$end,$triggertype);
                   4416:         if ($blocker =~ m/^(\d+)____(\d+)$/) {
                   4417:             ($start,$end) = ($1,$2);
                   4418:         } elsif (ref($triggered{$blocker}) eq 'HASH') {
                   4419:             $start = $triggered{$blocker}{'start'};
                   4420:             $end = $triggered{$blocker}{'end'};
                   4421:             $triggertype = $triggered{$blocker}{'type'};
                   4422:         }
                   4423:         if ($start) {
                   4424:             push(@{$$setters{$course}{'times'}}, [$start,$end]);
                   4425:             if ($triggertype) {
                   4426:                 push(@{$$setters{$course}{'triggers'}},$triggertype);
                   4427:             } else {
                   4428:                 push(@{$$setters{$course}{'triggers'}},0);
                   4429:             }
                   4430:             if ( ($startblock == 0) || ($startblock > $start) ) {
                   4431:                 $startblock = $start;
                   4432:                 if ($triggertype) {
                   4433:                     $triggerblock = $blocker;
1.474     raeburn  4434:                 }
                   4435:             }
1.1062    raeburn  4436:             if ( ($endblock == 0) || ($endblock < $end) ) {
                   4437:                $endblock = $end;
                   4438:                if ($triggertype) {
                   4439:                    $triggerblock = $blocker;
                   4440:                }
                   4441:             }
1.474     raeburn  4442:         }
                   4443:     }
1.1062    raeburn  4444:     return ($startblock,$endblock,$triggerblock);
1.474     raeburn  4445: }
                   4446: 
                   4447: sub parse_block_record {
                   4448:     my ($record) = @_;
                   4449:     my ($setuname,$setudom,$title,$blocks);
                   4450:     if (ref($record) eq 'HASH') {
                   4451:         ($setuname,$setudom) = split(/:/,$record->{'setter'});
                   4452:         $title = &unescape($record->{'event'});
                   4453:         $blocks = $record->{'blocks'};
                   4454:     } else {
                   4455:         my @data = split(/:/,$record,3);
                   4456:         if (scalar(@data) eq 2) {
                   4457:             $title = $data[1];
                   4458:             ($setuname,$setudom) = split(/@/,$data[0]);
                   4459:         } else {
                   4460:             ($setuname,$setudom,$title) = @data;
                   4461:         }
                   4462:         $blocks = { 'com' => 'on' };
                   4463:     }
                   4464:     return ($setuname,$setudom,$title,$blocks);
                   4465: }
                   4466: 
1.854     kalberla 4467: sub blocking_status {
1.1062    raeburn  4468:     my ($activity,$uname,$udom,$url) = @_;
1.1061    raeburn  4469:     my %setters;
1.890     droeschl 4470: 
1.1061    raeburn  4471: # check for active blocking
1.1062    raeburn  4472:     my ($startblock,$endblock,$triggerblock) = 
                   4473:         &blockcheck(\%setters,$activity,$uname,$udom,$url);
                   4474:     my $blocked = 0;
                   4475:     if ($startblock && $endblock) {
                   4476:         $blocked = 1;
                   4477:     }
1.890     droeschl 4478: 
1.1061    raeburn  4479: # caller just wants to know whether a block is active
                   4480:     if (!wantarray) { return $blocked; }
                   4481: 
                   4482: # build a link to a popup window containing the details
                   4483:     my $querystring  = "?activity=$activity";
                   4484: # $uname and $udom decide whose portfolio the user is trying to look at
1.1062    raeburn  4485:     if ($activity eq 'port') {
                   4486:         $querystring .= "&amp;udom=$udom"      if $udom;
                   4487:         $querystring .= "&amp;uname=$uname"    if $uname;
                   4488:     } elsif ($activity eq 'docs') {
                   4489:         $querystring .= '&amp;url='.&HTML::Entities::encode($url,'&"');
                   4490:     }
1.1061    raeburn  4491: 
                   4492:     my $output .= <<'END_MYBLOCK';
                   4493: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
                   4494:     var options = "width=" + w + ",height=" + h + ",";
                   4495:     options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
                   4496:     options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
                   4497:     var newWin = window.open(url, wdwName, options);
                   4498:     newWin.focus();
                   4499: }
1.890     droeschl 4500: END_MYBLOCK
1.854     kalberla 4501: 
1.1061    raeburn  4502:     $output = Apache::lonhtmlcommon::scripttag($output);
1.890     droeschl 4503:   
1.1061    raeburn  4504:     my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062    raeburn  4505:     my $text = &mt('Communication Blocked');
                   4506:     if ($activity eq 'docs') {
                   4507:         $text = &mt('Content Access Blocked');
1.1063    raeburn  4508:     } elsif ($activity eq 'printout') {
                   4509:         $text = &mt('Printing Blocked');
1.1062    raeburn  4510:     }
1.1061    raeburn  4511:     $output .= <<"END_BLOCK";
1.867     kalberla 4512: <div class='LC_comblock'>
1.869     kalberla 4513:   <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890     droeschl 4514:   title='$text'>
                   4515:   <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869     kalberla 4516:   <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring' 
1.890     droeschl 4517:   title='$text'>$text</a>
1.867     kalberla 4518: </div>
                   4519: 
                   4520: END_BLOCK
1.474     raeburn  4521: 
1.1061    raeburn  4522:     return ($blocked, $output);
1.854     kalberla 4523: }
1.490     raeburn  4524: 
1.60      matthew  4525: ###############################################
                   4526: 
1.682     raeburn  4527: sub check_ip_acc {
                   4528:     my ($acc)=@_;
                   4529:     &Apache::lonxml::debug("acc is $acc");
                   4530:     if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
                   4531:         return 1;
                   4532:     }
                   4533:     my $allowed=0;
                   4534:     my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
                   4535: 
                   4536:     my $name;
                   4537:     foreach my $pattern (split(',',$acc)) {
                   4538:         $pattern =~ s/^\s*//;
                   4539:         $pattern =~ s/\s*$//;
                   4540:         if ($pattern =~ /\*$/) {
                   4541:             #35.8.*
                   4542:             $pattern=~s/\*//;
                   4543:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   4544:         } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
                   4545:             #35.8.3.[34-56]
                   4546:             my $low=$2;
                   4547:             my $high=$3;
                   4548:             $pattern=$1;
                   4549:             if ($ip =~ /^\Q$pattern\E/) {
                   4550:                 my $last=(split(/\./,$ip))[3];
                   4551:                 if ($last <=$high && $last >=$low) { $allowed=1; }
                   4552:             }
                   4553:         } elsif ($pattern =~ /^\*/) {
                   4554:             #*.msu.edu
                   4555:             $pattern=~s/\*//;
                   4556:             if (!defined($name)) {
                   4557:                 use Socket;
                   4558:                 my $netaddr=inet_aton($ip);
                   4559:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   4560:             }
                   4561:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   4562:         } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
                   4563:             #127.0.0.1
                   4564:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   4565:         } else {
                   4566:             #some.name.com
                   4567:             if (!defined($name)) {
                   4568:                 use Socket;
                   4569:                 my $netaddr=inet_aton($ip);
                   4570:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   4571:             }
                   4572:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   4573:         }
                   4574:         if ($allowed) { last; }
                   4575:     }
                   4576:     return $allowed;
                   4577: }
                   4578: 
                   4579: ###############################################
                   4580: 
1.60      matthew  4581: =pod
                   4582: 
1.112     bowersj2 4583: =head1 Domain Template Functions
                   4584: 
                   4585: =over 4
                   4586: 
                   4587: =item * &determinedomain()
1.60      matthew  4588: 
                   4589: Inputs: $domain (usually will be undef)
                   4590: 
1.63      www      4591: Returns: Determines which domain should be used for designs
1.60      matthew  4592: 
                   4593: =cut
1.54      www      4594: 
1.60      matthew  4595: ###############################################
1.63      www      4596: sub determinedomain {
                   4597:     my $domain=shift;
1.531     albertel 4598:     if (! $domain) {
1.60      matthew  4599:         # Determine domain if we have not been given one
1.893     raeburn  4600:         $domain = &Apache::lonnet::default_login_domain();
1.258     albertel 4601:         if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
                   4602:         if ($env{'request.role.domain'}) { 
                   4603:             $domain=$env{'request.role.domain'}; 
1.60      matthew  4604:         }
                   4605:     }
1.63      www      4606:     return $domain;
                   4607: }
                   4608: ###############################################
1.517     raeburn  4609: 
1.518     albertel 4610: sub devalidate_domconfig_cache {
                   4611:     my ($udom)=@_;
                   4612:     &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
                   4613: }
                   4614: 
                   4615: # ---------------------- Get domain configuration for a domain
                   4616: sub get_domainconf {
                   4617:     my ($udom) = @_;
                   4618:     my $cachetime=1800;
                   4619:     my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
                   4620:     if (defined($cached)) { return %{$result}; }
                   4621: 
                   4622:     my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948     raeburn  4623: 					     ['login','rolecolors','autoenroll'],$udom);
1.632     raeburn  4624:     my (%designhash,%legacy);
1.518     albertel 4625:     if (keys(%domconfig) > 0) {
                   4626:         if (ref($domconfig{'login'}) eq 'HASH') {
1.632     raeburn  4627:             if (keys(%{$domconfig{'login'}})) {
                   4628:                 foreach my $key (keys(%{$domconfig{'login'}})) {
1.699     raeburn  4629:                     if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946     raeburn  4630:                         if ($key eq 'loginvia') {
                   4631:                             if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
1.1013    raeburn  4632:                                 foreach my $hostname (keys(%{$domconfig{'login'}{'loginvia'}})) {
1.948     raeburn  4633:                                     if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
                   4634:                                         if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
                   4635:                                             my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
                   4636:                                             $designhash{$udom.'.login.loginvia'} = $server;
                   4637:                                             if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
                   4638: 
                   4639:                                                 $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
                   4640:                                             } else {
1.1013    raeburn  4641:                                                 $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
1.948     raeburn  4642:                                             }
                   4643:                                             if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
                   4644:                                                 $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
                   4645:                                             }
1.946     raeburn  4646:                                         }
                   4647:                                     }
                   4648:                                 }
                   4649:                             }
                   4650:                         } else {
                   4651:                             foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
                   4652:                                 $designhash{$udom.'.login.'.$key.'_'.$img} = 
                   4653:                                     $domconfig{'login'}{$key}{$img};
                   4654:                             }
1.699     raeburn  4655:                         }
                   4656:                     } else {
                   4657:                         $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
                   4658:                     }
1.632     raeburn  4659:                 }
                   4660:             } else {
                   4661:                 $legacy{'login'} = 1;
1.518     albertel 4662:             }
1.632     raeburn  4663:         } else {
                   4664:             $legacy{'login'} = 1;
1.518     albertel 4665:         }
                   4666:         if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632     raeburn  4667:             if (keys(%{$domconfig{'rolecolors'}})) {
                   4668:                 foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
                   4669:                     if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
                   4670:                         foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
                   4671:                             $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
                   4672:                         }
1.518     albertel 4673:                     }
                   4674:                 }
1.632     raeburn  4675:             } else {
                   4676:                 $legacy{'rolecolors'} = 1;
1.518     albertel 4677:             }
1.632     raeburn  4678:         } else {
                   4679:             $legacy{'rolecolors'} = 1;
1.518     albertel 4680:         }
1.948     raeburn  4681:         if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   4682:             if ($domconfig{'autoenroll'}{'co-owners'}) {
                   4683:                 $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
                   4684:             }
                   4685:         }
1.632     raeburn  4686:         if (keys(%legacy) > 0) {
                   4687:             my %legacyhash = &get_legacy_domconf($udom);
                   4688:             foreach my $item (keys(%legacyhash)) {
                   4689:                 if ($item =~ /^\Q$udom\E\.login/) {
                   4690:                     if ($legacy{'login'}) { 
                   4691:                         $designhash{$item} = $legacyhash{$item};
                   4692:                     }
                   4693:                 } else {
                   4694:                     if ($legacy{'rolecolors'}) {
                   4695:                         $designhash{$item} = $legacyhash{$item};
                   4696:                     }
1.518     albertel 4697:                 }
                   4698:             }
                   4699:         }
1.632     raeburn  4700:     } else {
                   4701:         %designhash = &get_legacy_domconf($udom); 
1.518     albertel 4702:     }
                   4703:     &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
                   4704: 				  $cachetime);
                   4705:     return %designhash;
                   4706: }
                   4707: 
1.632     raeburn  4708: sub get_legacy_domconf {
                   4709:     my ($udom) = @_;
                   4710:     my %legacyhash;
                   4711:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
                   4712:     my $designfile =  $designdir.'/'.$udom.'.tab';
                   4713:     if (-e $designfile) {
                   4714:         if ( open (my $fh,"<$designfile") ) {
                   4715:             while (my $line = <$fh>) {
                   4716:                 next if ($line =~ /^\#/);
                   4717:                 chomp($line);
                   4718:                 my ($key,$val)=(split(/\=/,$line));
                   4719:                 if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
                   4720:             }
                   4721:             close($fh);
                   4722:         }
                   4723:     }
1.1026    raeburn  4724:     if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632     raeburn  4725:         $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
                   4726:     }
                   4727:     return %legacyhash;
                   4728: }
                   4729: 
1.63      www      4730: =pod
                   4731: 
1.112     bowersj2 4732: =item * &domainlogo()
1.63      www      4733: 
                   4734: Inputs: $domain (usually will be undef)
                   4735: 
                   4736: Returns: A link to a domain logo, if the domain logo exists.
                   4737: If the domain logo does not exist, a description of the domain.
                   4738: 
                   4739: =cut
1.112     bowersj2 4740: 
1.63      www      4741: ###############################################
                   4742: sub domainlogo {
1.517     raeburn  4743:     my $domain = &determinedomain(shift);
1.518     albertel 4744:     my %designhash = &get_domainconf($domain);    
1.517     raeburn  4745:     # See if there is a logo
                   4746:     if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519     raeburn  4747:         my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538     albertel 4748:         if ($imgsrc =~ m{^/(adm|res)/}) {
                   4749: 	    if ($imgsrc =~ m{^/res/}) {
                   4750: 		my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
                   4751: 		&Apache::lonnet::repcopy($local_name);
                   4752: 	    }
                   4753: 	   $imgsrc = &lonhttpdurl($imgsrc);
1.519     raeburn  4754:         } 
                   4755:         return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514     albertel 4756:     } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
                   4757:         return &Apache::lonnet::domain($domain,'description');
1.59      www      4758:     } else {
1.60      matthew  4759:         return '';
1.59      www      4760:     }
                   4761: }
1.63      www      4762: ##############################################
                   4763: 
                   4764: =pod
                   4765: 
1.112     bowersj2 4766: =item * &designparm()
1.63      www      4767: 
                   4768: Inputs: $which parameter; $domain (usually will be undef)
                   4769: 
                   4770: Returns: value of designparamter $which
                   4771: 
                   4772: =cut
1.112     bowersj2 4773: 
1.397     albertel 4774: 
1.400     albertel 4775: ##############################################
1.397     albertel 4776: sub designparm {
                   4777:     my ($which,$domain)=@_;
                   4778:     if (exists($env{'environment.color.'.$which})) {
1.817     bisitz   4779:         return $env{'environment.color.'.$which};
1.96      www      4780:     }
1.63      www      4781:     $domain=&determinedomain($domain);
1.1016    raeburn  4782:     my %domdesign;
                   4783:     unless ($domain eq 'public') {
                   4784:         %domdesign = &get_domainconf($domain);
                   4785:     }
1.520     raeburn  4786:     my $output;
1.517     raeburn  4787:     if ($domdesign{$domain.'.'.$which} ne '') {
1.817     bisitz   4788:         $output = $domdesign{$domain.'.'.$which};
1.63      www      4789:     } else {
1.520     raeburn  4790:         $output = $defaultdesign{$which};
                   4791:     }
                   4792:     if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635     raeburn  4793:         ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538     albertel 4794:         if ($output =~ m{^/(adm|res)/}) {
1.817     bisitz   4795:             if ($output =~ m{^/res/}) {
                   4796:                 my $local_name = &Apache::lonnet::filelocation('',$output);
                   4797:                 &Apache::lonnet::repcopy($local_name);
                   4798:             }
1.520     raeburn  4799:             $output = &lonhttpdurl($output);
                   4800:         }
1.63      www      4801:     }
1.520     raeburn  4802:     return $output;
1.63      www      4803: }
1.59      www      4804: 
1.822     bisitz   4805: ##############################################
                   4806: =pod
                   4807: 
1.832     bisitz   4808: =item * &authorspace()
                   4809: 
1.1028    raeburn  4810: Inputs: $url (usually will be undef).
1.832     bisitz   4811: 
1.1028    raeburn  4812: Returns: Path to Construction Space containing the resource or 
                   4813:          directory being viewed (or for which action is being taken). 
                   4814:          If $url is provided, and begins /priv/<domain>/<uname>
                   4815:          the path will be that portion of the $context argument.
                   4816:          Otherwise the path will be for the author space of the current
                   4817:          user when the current role is author, or for that of the 
                   4818:          co-author/assistant co-author space when the current role 
                   4819:          is co-author or assistant co-author.
1.832     bisitz   4820: 
                   4821: =cut
                   4822: 
                   4823: sub authorspace {
1.1028    raeburn  4824:     my ($url) = @_;
                   4825:     if ($url ne '') {
                   4826:         if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
                   4827:            return $1;
                   4828:         }
                   4829:     }
1.832     bisitz   4830:     my $caname = '';
1.1024    www      4831:     my $cadom = '';
1.1028    raeburn  4832:     if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024    www      4833:         ($cadom,$caname) =
1.832     bisitz   4834:             ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028    raeburn  4835:     } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832     bisitz   4836:         $caname = $env{'user.name'};
1.1024    www      4837:         $cadom = $env{'user.domain'};
1.832     bisitz   4838:     }
1.1028    raeburn  4839:     if (($caname ne '') && ($cadom ne '')) {
                   4840:         return "/priv/$cadom/$caname/";
                   4841:     }
                   4842:     return;
1.832     bisitz   4843: }
                   4844: 
                   4845: ##############################################
                   4846: =pod
                   4847: 
1.822     bisitz   4848: =item * &head_subbox()
                   4849: 
                   4850: Inputs: $content (contains HTML code with page functions, etc.)
                   4851: 
                   4852: Returns: HTML div with $content
                   4853:          To be included in page header
                   4854: 
                   4855: =cut
                   4856: 
                   4857: sub head_subbox {
                   4858:     my ($content)=@_;
                   4859:     my $output =
1.993     raeburn  4860:         '<div class="LC_head_subbox">'
1.822     bisitz   4861:        .$content
                   4862:        .'</div>'
                   4863: }
                   4864: 
                   4865: ##############################################
                   4866: =pod
                   4867: 
                   4868: =item * &CSTR_pageheader()
                   4869: 
1.1026    raeburn  4870: Input: (optional) filename from which breadcrumb trail is built.
                   4871:        In most cases no input as needed, as $env{'request.filename'}
                   4872:        is appropriate for use in building the breadcrumb trail.
1.822     bisitz   4873: 
                   4874: Returns: HTML div with CSTR path and recent box
                   4875:          To be included on Construction Space pages
                   4876: 
                   4877: =cut
                   4878: 
                   4879: sub CSTR_pageheader {
1.1026    raeburn  4880:     my ($trailfile) = @_;
                   4881:     if ($trailfile eq '') {
                   4882:         $trailfile = $env{'request.filename'};
                   4883:     }
                   4884: 
                   4885: # this is for resources; directories have customtitle, and crumbs
                   4886: # and select recent are created in lonpubdir.pm
                   4887: 
                   4888:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022    www      4889:     my ($udom,$uname,$thisdisfn)=
1.1075.2.29  raeburn  4890:         ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026    raeburn  4891:     my $formaction = "/priv/$udom/$uname/$thisdisfn";
                   4892:     $formaction =~ s{/+}{/}g;
1.822     bisitz   4893: 
                   4894:     my $parentpath = '';
                   4895:     my $lastitem = '';
                   4896:     if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
                   4897:         $parentpath = $1;
                   4898:         $lastitem = $2;
                   4899:     } else {
                   4900:         $lastitem = $thisdisfn;
                   4901:     }
1.921     bisitz   4902: 
                   4903:     my $output =
1.822     bisitz   4904:          '<div>'
                   4905:         .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
                   4906:         .'<b>'.&mt('Construction Space:').'</b> '
                   4907:         .'<form name="dirs" method="post" action="'.$formaction
1.921     bisitz   4908:         .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024    www      4909:         .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921     bisitz   4910: 
                   4911:     if ($lastitem) {
                   4912:         $output .=
                   4913:              '<span class="LC_filename">'
                   4914:             .$lastitem
                   4915:             .'</span>';
                   4916:     }
                   4917:     $output .=
                   4918:          '<br />'
1.822     bisitz   4919:         #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
                   4920:         .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
                   4921:         .'</form>'
                   4922:         .&Apache::lonmenu::constspaceform()
                   4923:         .'</div>';
1.921     bisitz   4924: 
                   4925:     return $output;
1.822     bisitz   4926: }
                   4927: 
1.60      matthew  4928: ###############################################
                   4929: ###############################################
                   4930: 
                   4931: =pod
                   4932: 
1.112     bowersj2 4933: =back
                   4934: 
1.549     albertel 4935: =head1 HTML Helpers
1.112     bowersj2 4936: 
                   4937: =over 4
                   4938: 
                   4939: =item * &bodytag()
1.60      matthew  4940: 
                   4941: Returns a uniform header for LON-CAPA web pages.
                   4942: 
                   4943: Inputs: 
                   4944: 
1.112     bowersj2 4945: =over 4
                   4946: 
                   4947: =item * $title, A title to be displayed on the page.
                   4948: 
                   4949: =item * $function, the current role (can be undef).
                   4950: 
                   4951: =item * $addentries, extra parameters for the <body> tag.
                   4952: 
                   4953: =item * $bodyonly, if defined, only return the <body> tag.
                   4954: 
                   4955: =item * $domain, if defined, force a given domain.
                   4956: 
                   4957: =item * $forcereg, if page should register as content page (relevant for 
1.86      www      4958:             text interface only)
1.60      matthew  4959: 
1.814     bisitz   4960: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
                   4961:                      navigational links
1.317     albertel 4962: 
1.338     albertel 4963: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
                   4964: 
1.1075.2.12  raeburn  4965: =item * $no_inline_link, if true and in remote mode, don't show the
                   4966:          'Switch To Inline Menu' link
                   4967: 
1.460     albertel 4968: =item * $args, optional argument valid values are
                   4969:             no_auto_mt_title -> prevents &mt()ing the title arg
1.562     albertel 4970:             inherit_jsmath -> when creating popup window in a page,
                   4971:                               should it have jsmath forced on by the
                   4972:                               current page
1.460     albertel 4973: 
1.1075.2.15  raeburn  4974: =item * $advtoolsref, optional argument, ref to an array containing
                   4975:             inlineremote items to be added in "Functions" menu below
                   4976:             breadcrumbs.
                   4977: 
1.112     bowersj2 4978: =back
                   4979: 
1.60      matthew  4980: Returns: A uniform header for LON-CAPA web pages.  
                   4981: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
                   4982: If $bodyonly is undef or zero, an html string containing a <body> tag and 
                   4983: other decorations will be returned.
                   4984: 
                   4985: =cut
                   4986: 
1.54      www      4987: sub bodytag {
1.831     bisitz   4988:     my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.15  raeburn  4989:         $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref)=@_;
1.339     albertel 4990: 
1.954     raeburn  4991:     my $public;
                   4992:     if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
                   4993:         || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
                   4994:         $public = 1;
                   4995:     }
1.460     albertel 4996:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339     albertel 4997: 
1.183     matthew  4998:     $function = &get_users_function() if (!$function);
1.339     albertel 4999:     my $img =    &designparm($function.'.img',$domain);
                   5000:     my $font =   &designparm($function.'.font',$domain);
                   5001:     my $pgbg   = $bgcolor || &designparm($function.'.pgbg',$domain);
                   5002: 
1.803     bisitz   5003:     my %design = ( 'style'   => 'margin-top: 0',
1.535     albertel 5004: 		   'bgcolor' => $pgbg,
1.339     albertel 5005: 		   'text'    => $font,
                   5006:                    'alink'   => &designparm($function.'.alink',$domain),
                   5007: 		   'vlink'   => &designparm($function.'.vlink',$domain),
                   5008: 		   'link'    => &designparm($function.'.link',$domain),);
1.438     albertel 5009:     @design{keys(%$addentries)} = @$addentries{keys(%$addentries)}; 
1.339     albertel 5010: 
1.63      www      5011:  # role and realm
1.378     raeburn  5012:     my ($role,$realm) = split(/\./,$env{'request.role'},2);
                   5013:     if ($role  eq 'ca') {
1.479     albertel 5014:         my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500     albertel 5015:         $realm = &plainname($rname,$rdom);
1.378     raeburn  5016:     } 
1.55      www      5017: # realm
1.258     albertel 5018:     if ($env{'request.course.id'}) {
1.378     raeburn  5019:         if ($env{'request.role'} !~ /^cr/) {
                   5020:             $role = &Apache::lonnet::plaintext($role,&course_type());
                   5021:         }
1.898     raeburn  5022:         if ($env{'request.course.sec'}) {
                   5023:             $role .= ('&nbsp;'x2).'-&nbsp;'.&mt('section:').'&nbsp;'.$env{'request.course.sec'};
                   5024:         }   
1.359     albertel 5025: 	$realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378     raeburn  5026:     } else {
                   5027:         $role = &Apache::lonnet::plaintext($role);
1.54      www      5028:     }
1.433     albertel 5029: 
1.359     albertel 5030:     if (!$realm) { $realm='&nbsp;'; }
1.330     albertel 5031: 
1.438     albertel 5032:     my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329     albertel 5033: 
1.101     www      5034: # construct main body tag
1.359     albertel 5035:     my $bodytag = "<body $extra_body_attr>".
1.562     albertel 5036: 	&Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252     albertel 5037: 
1.530     albertel 5038:     if ($bodyonly) {
1.60      matthew  5039:         return $bodytag;
1.798     tempelho 5040:     } 
1.359     albertel 5041: 
1.410     albertel 5042:     my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.954     raeburn  5043:     if ($public) {
1.433     albertel 5044: 	undef($role);
1.434     albertel 5045:     } else {
1.1070    raeburn  5046: 	$name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
                   5047:                                 undef,'LC_menubuttons_link');
1.433     albertel 5048:     }
1.359     albertel 5049:     
1.762     bisitz   5050:     my $titleinfo = '<h1>'.$title.'</h1>';
1.359     albertel 5051:     #
                   5052:     # Extra info if you are the DC
                   5053:     my $dc_info = '';
                   5054:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
                   5055:                         $env{'course.'.$env{'request.course.id'}.
                   5056:                                  '.domain'}.'/'})) {
                   5057:         my $cid = $env{'request.course.id'};
1.917     raeburn  5058:         $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380     www      5059:         $dc_info =~ s/\s+$//;
1.359     albertel 5060:     }
                   5061: 
1.898     raeburn  5062:     $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853     droeschl 5063:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   5064: 
1.1075.2.13  raeburn  5065:     if ($no_nav_bar || $env{'form.inhibitmenu'} eq 'yes') { 
                   5066:         return $bodytag; 
                   5067:     }
1.903     droeschl 5068: 
1.1075.2.13  raeburn  5069:     if ($env{'request.state'} eq 'construct') { $forcereg=1; }
                   5070: 
1.1075.2.21  raeburn  5071:     my $funclist;
                   5072:     if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
                   5073:         $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions(), 'start')."\n".
                   5074:                     Apache::lonmenu::serverform();
                   5075:         my $forbodytag;
                   5076:         &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
                   5077:                                             $forcereg,$args->{'group'},
                   5078:                                             $args->{'bread_crumbs'},
                   5079:                                             $advtoolsref,'',\$forbodytag);
                   5080:         unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
                   5081:             $funclist = $forbodytag;
                   5082:         }
                   5083:     } else {
1.903     droeschl 5084: 
                   5085:         #    if ($env{'request.state'} eq 'construct') {
                   5086:         #        $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
                   5087:         #    }
                   5088: 
1.359     albertel 5089: 
1.1075.2.2  raeburn  5090: 
1.916     droeschl 5091:         if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.1075.2.22  raeburn  5092:             if ($dc_info) {
                   5093:                  $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
1.1075.2.1  raeburn  5094:             }
1.1075.2.22  raeburn  5095:             $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
                   5096:                            <em>$realm</em> $dc_info</div>|;
1.903     droeschl 5097:             return $bodytag;
                   5098:         }
1.894     droeschl 5099: 
1.927     raeburn  5100:         unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
                   5101:             $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>|;
                   5102:         }
1.916     droeschl 5103: 
1.903     droeschl 5104:         $bodytag .= Apache::lonhtmlcommon::scripttag(
                   5105:             Apache::lonmenu::utilityfunctions(), 'start');
1.816     bisitz   5106: 
1.903     droeschl 5107:         $bodytag .= Apache::lonmenu::primary_menu();
1.852     droeschl 5108: 
1.917     raeburn  5109:         if ($dc_info) {
                   5110:             $dc_info = &dc_courseid_toggle($dc_info);
                   5111:         }
                   5112:         $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916     droeschl 5113: 
1.903     droeschl 5114:         #don't show menus for public users
1.954     raeburn  5115:         if (!$public){
1.903     droeschl 5116:             $bodytag .= Apache::lonmenu::secondary_menu();
                   5117:             $bodytag .= Apache::lonmenu::serverform();
1.920     raeburn  5118:             $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
                   5119:             if ($env{'request.state'} eq 'construct') {
1.962     droeschl 5120:                 $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920     raeburn  5121:                                 $args->{'bread_crumbs'});
                   5122:             } elsif ($forcereg) { 
1.1075.2.22  raeburn  5123:                 $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
                   5124:                                                             $args->{'group'});
1.1075.2.15  raeburn  5125:             } else {
1.1075.2.21  raeburn  5126:                 my $forbodytag;
                   5127:                 &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
                   5128:                                                     $forcereg,$args->{'group'},
                   5129:                                                     $args->{'bread_crumbs'},
                   5130:                                                     $advtoolsref,'',\$forbodytag);
                   5131:                 unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
                   5132:                     $bodytag .= $forbodytag;
                   5133:                 }
1.920     raeburn  5134:             }
1.903     droeschl 5135:         }else{
                   5136:             # this is to seperate menu from content when there's no secondary
                   5137:             # menu. Especially needed for public accessible ressources.
                   5138:             $bodytag .= '<hr style="clear:both" />';
                   5139:             $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end'); 
1.235     raeburn  5140:         }
1.903     droeschl 5141: 
1.235     raeburn  5142:         return $bodytag;
1.1075.2.12  raeburn  5143:     }
                   5144: 
                   5145: #
                   5146: # Top frame rendering, Remote is up
                   5147: #
                   5148: 
                   5149:     my $imgsrc = $img;
                   5150:     if ($img =~ /^\/adm/) {
                   5151:         $imgsrc = &lonhttpdurl($img);
                   5152:     }
                   5153:     my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
                   5154: 
                   5155:     # Explicit link to get inline menu
                   5156:     my $menu= ($no_inline_link?''
                   5157:                :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
                   5158: 
                   5159:     if ($dc_info) {
                   5160:         $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
                   5161:     }
                   5162: 
                   5163:     unless ($env{'form.inhibitmenu'}) {
                   5164:         $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
                   5165:                        <ol class="LC_primary_menu LC_right">
                   5166:                        <li>$menu</li>
                   5167:                        </ol><div id="LC_realm"> $realm $dc_info</div>|;
                   5168:     }
1.1075.2.13  raeburn  5169:     if ($env{'request.state'} eq 'construct') {
                   5170:         if (!$public){
                   5171:             if ($env{'request.state'} eq 'construct') {
                   5172:                 $funclist = &Apache::lonhtmlcommon::scripttag(
                   5173:                                 &Apache::lonmenu::utilityfunctions(), 'start').
                   5174:                             &Apache::lonhtmlcommon::scripttag('','end').
                   5175:                             &Apache::lonmenu::innerregister($forcereg,
                   5176:                                                             $args->{'bread_crumbs'});
                   5177:             }
                   5178:         }
                   5179:     }
1.1075.2.21  raeburn  5180:     return $bodytag."\n".$funclist;
1.182     matthew  5181: }
                   5182: 
1.917     raeburn  5183: sub dc_courseid_toggle {
                   5184:     my ($dc_info) = @_;
1.980     raeburn  5185:     return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069    raeburn  5186:            '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917     raeburn  5187:            &mt('(More ...)').'</a></span>'.
                   5188:            '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
                   5189: }
                   5190: 
1.330     albertel 5191: sub make_attr_string {
                   5192:     my ($register,$attr_ref) = @_;
                   5193: 
                   5194:     if ($attr_ref && !ref($attr_ref)) {
                   5195: 	die("addentries Must be a hash ref ".
                   5196: 	    join(':',caller(1))." ".
                   5197: 	    join(':',caller(0))." ");
                   5198:     }
                   5199: 
                   5200:     if ($register) {
1.339     albertel 5201: 	my ($on_load,$on_unload);
                   5202: 	foreach my $key (keys(%{$attr_ref})) {
                   5203: 	    if      (lc($key) eq 'onload') {
                   5204: 		$on_load.=$attr_ref->{$key}.';';
                   5205: 		delete($attr_ref->{$key});
                   5206: 
                   5207: 	    } elsif (lc($key) eq 'onunload') {
                   5208: 		$on_unload.=$attr_ref->{$key}.';';
                   5209: 		delete($attr_ref->{$key});
                   5210: 	    }
                   5211: 	}
1.1075.2.12  raeburn  5212:         if ($env{'environment.remote'} eq 'on') {
                   5213:             $attr_ref->{'onload'}  =
                   5214:                 &Apache::lonmenu::loadevents().  $on_load;
                   5215:             $attr_ref->{'onunload'}=
                   5216:                 &Apache::lonmenu::unloadevents().$on_unload;
                   5217:         } else {  
                   5218: 	    $attr_ref->{'onload'}  = $on_load;
                   5219: 	    $attr_ref->{'onunload'}= $on_unload;
                   5220:         }
1.330     albertel 5221:     }
1.339     albertel 5222: 
1.330     albertel 5223:     my $attr_string;
                   5224:     foreach my $attr (keys(%$attr_ref)) {
                   5225: 	$attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
                   5226:     }
                   5227:     return $attr_string;
                   5228: }
                   5229: 
                   5230: 
1.182     matthew  5231: ###############################################
1.251     albertel 5232: ###############################################
                   5233: 
                   5234: =pod
                   5235: 
                   5236: =item * &endbodytag()
                   5237: 
                   5238: Returns a uniform footer for LON-CAPA web pages.
                   5239: 
1.635     raeburn  5240: Inputs: 1 - optional reference to an args hash
                   5241: If in the hash, key for noredirectlink has a value which evaluates to true,
                   5242: a 'Continue' link is not displayed if the page contains an
                   5243: internal redirect in the <head></head> section,
                   5244: i.e., $env{'internal.head.redirect'} exists   
1.251     albertel 5245: 
                   5246: =cut
                   5247: 
                   5248: sub endbodytag {
1.635     raeburn  5249:     my ($args) = @_;
1.1075.2.6  raeburn  5250:     my $endbodytag;
                   5251:     unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
                   5252:         $endbodytag='</body>';
                   5253:     }
1.269     albertel 5254:     $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315     albertel 5255:     if ( exists( $env{'internal.head.redirect'} ) ) {
1.635     raeburn  5256:         if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
                   5257: 	    $endbodytag=
                   5258: 	        "<br /><a href=\"$env{'internal.head.redirect'}\">".
                   5259: 	        &mt('Continue').'</a>'.
                   5260: 	        $endbodytag;
                   5261:         }
1.315     albertel 5262:     }
1.251     albertel 5263:     return $endbodytag;
                   5264: }
                   5265: 
1.352     albertel 5266: =pod
                   5267: 
                   5268: =item * &standard_css()
                   5269: 
                   5270: Returns a style sheet
                   5271: 
                   5272: Inputs: (all optional)
                   5273:             domain         -> force to color decorate a page for a specific
                   5274:                                domain
                   5275:             function       -> force usage of a specific rolish color scheme
                   5276:             bgcolor        -> override the default page bgcolor
                   5277: 
                   5278: =cut
                   5279: 
1.343     albertel 5280: sub standard_css {
1.345     albertel 5281:     my ($function,$domain,$bgcolor) = @_;
1.352     albertel 5282:     $function  = &get_users_function() if (!$function);
                   5283:     my $img    = &designparm($function.'.img',   $domain);
                   5284:     my $tabbg  = &designparm($function.'.tabbg', $domain);
                   5285:     my $font   = &designparm($function.'.font',  $domain);
1.801     tempelho 5286:     my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791     tempelho 5287: #second colour for later usage
1.345     albertel 5288:     my $sidebg = &designparm($function.'.sidebg',$domain);
1.382     albertel 5289:     my $pgbg_or_bgcolor =
                   5290: 	         $bgcolor ||
1.352     albertel 5291: 	         &designparm($function.'.pgbg',  $domain);
1.382     albertel 5292:     my $pgbg   = &designparm($function.'.pgbg',  $domain);
1.352     albertel 5293:     my $alink  = &designparm($function.'.alink', $domain);
                   5294:     my $vlink  = &designparm($function.'.vlink', $domain);
                   5295:     my $link   = &designparm($function.'.link',  $domain);
                   5296: 
1.602     albertel 5297:     my $sans                 = 'Verdana,Arial,Helvetica,sans-serif';
1.395     albertel 5298:     my $mono                 = 'monospace';
1.850     bisitz   5299:     my $data_table_head      = $sidebg;
                   5300:     my $data_table_light     = '#FAFAFA';
1.1060    bisitz   5301:     my $data_table_dark      = '#E0E0E0';
1.470     banghart 5302:     my $data_table_darker    = '#CCCCCC';
1.349     albertel 5303:     my $data_table_highlight = '#FFFF00';
1.352     albertel 5304:     my $mail_new             = '#FFBB77';
                   5305:     my $mail_new_hover       = '#DD9955';
                   5306:     my $mail_read            = '#BBBB77';
                   5307:     my $mail_read_hover      = '#999944';
                   5308:     my $mail_replied         = '#AAAA88';
                   5309:     my $mail_replied_hover   = '#888855';
                   5310:     my $mail_other           = '#99BBBB';
                   5311:     my $mail_other_hover     = '#669999';
1.391     albertel 5312:     my $table_header         = '#DDDDDD';
1.489     raeburn  5313:     my $feedback_link_bg     = '#BBBBBB';
1.911     bisitz   5314:     my $lg_border_color      = '#C8C8C8';
1.952     onken    5315:     my $button_hover         = '#BF2317';
1.392     albertel 5316: 
1.608     albertel 5317:     my $border = ($env{'browser.type'} eq 'explorer' ||
1.911     bisitz   5318:       $env{'browser.type'} eq 'safari'     ) ? '0 2px 0 2px'
                   5319:                                              : '0 3px 0 4px';
1.448     albertel 5320: 
1.523     albertel 5321: 
1.343     albertel 5322:     return <<END;
1.947     droeschl 5323: 
                   5324: /* needed for iframe to allow 100% height in FF */
                   5325: body, html { 
                   5326:     margin: 0;
                   5327:     padding: 0 0.5%;
                   5328:     height: 99%; /* to avoid scrollbars */
                   5329: }
                   5330: 
1.795     www      5331: body {
1.911     bisitz   5332:   font-family: $sans;
                   5333:   line-height:130%;
                   5334:   font-size:0.83em;
                   5335:   color:$font;
1.795     www      5336: }
                   5337: 
1.959     onken    5338: a:focus,
                   5339: a:focus img {
1.795     www      5340:   color: red;
                   5341: }
1.698     harmsja  5342: 
1.911     bisitz   5343: form, .inline {
                   5344:   display: inline;
1.795     www      5345: }
1.721     harmsja  5346: 
1.795     www      5347: .LC_right {
1.911     bisitz   5348:   text-align:right;
1.795     www      5349: }
                   5350: 
                   5351: .LC_middle {
1.911     bisitz   5352:   vertical-align:middle;
1.795     www      5353: }
1.721     harmsja  5354: 
1.911     bisitz   5355: .LC_400Box {
                   5356:   width:400px;
                   5357: }
1.721     harmsja  5358: 
1.947     droeschl 5359: .LC_iframecontainer {
                   5360:     width: 98%;
                   5361:     margin: 0;
                   5362:     position: fixed;
                   5363:     top: 8.5em;
                   5364:     bottom: 0;
                   5365: }
                   5366: 
                   5367: .LC_iframecontainer iframe{
                   5368:     border: none;
                   5369:     width: 100%;
                   5370:     height: 100%;
                   5371: }
                   5372: 
1.778     bisitz   5373: .LC_filename {
                   5374:   font-family: $mono;
                   5375:   white-space:pre;
1.921     bisitz   5376:   font-size: 120%;
1.778     bisitz   5377: }
                   5378: 
                   5379: .LC_fileicon {
                   5380:   border: none;
                   5381:   height: 1.3em;
                   5382:   vertical-align: text-bottom;
                   5383:   margin-right: 0.3em;
                   5384:   text-decoration:none;
                   5385: }
                   5386: 
1.1008    www      5387: .LC_setting {
                   5388:   text-decoration:underline;
                   5389: }
                   5390: 
1.350     albertel 5391: .LC_error {
                   5392:   color: red;
                   5393: }
1.795     www      5394: 
1.1075.2.15  raeburn  5395: .LC_warning {
                   5396:   color: darkorange;
                   5397: }
                   5398: 
1.457     albertel 5399: .LC_diff_removed {
1.733     bisitz   5400:   color: red;
1.394     albertel 5401: }
1.532     albertel 5402: 
                   5403: .LC_info,
1.457     albertel 5404: .LC_success,
                   5405: .LC_diff_added {
1.350     albertel 5406:   color: green;
                   5407: }
1.795     www      5408: 
1.802     bisitz   5409: div.LC_confirm_box {
                   5410:   background-color: #FAFAFA;
                   5411:   border: 1px solid $lg_border_color;
                   5412:   margin-right: 0;
                   5413:   padding: 5px;
                   5414: }
                   5415: 
                   5416: div.LC_confirm_box .LC_error img,
                   5417: div.LC_confirm_box .LC_success img {
                   5418:   vertical-align: middle;
                   5419: }
                   5420: 
1.440     albertel 5421: .LC_icon {
1.771     droeschl 5422:   border: none;
1.790     droeschl 5423:   vertical-align: middle;
1.771     droeschl 5424: }
                   5425: 
1.543     albertel 5426: .LC_docs_spacer {
                   5427:   width: 25px;
                   5428:   height: 1px;
1.771     droeschl 5429:   border: none;
1.543     albertel 5430: }
1.346     albertel 5431: 
1.532     albertel 5432: .LC_internal_info {
1.735     bisitz   5433:   color: #999999;
1.532     albertel 5434: }
                   5435: 
1.794     www      5436: .LC_discussion {
1.1050    www      5437:   background: $data_table_dark;
1.911     bisitz   5438:   border: 1px solid black;
                   5439:   margin: 2px;
1.794     www      5440: }
                   5441: 
                   5442: .LC_disc_action_left {
1.1050    www      5443:   background: $sidebg;
1.911     bisitz   5444:   text-align: left;
1.1050    www      5445:   padding: 4px;
                   5446:   margin: 2px;
1.794     www      5447: }
                   5448: 
                   5449: .LC_disc_action_right {
1.1050    www      5450:   background: $sidebg;
1.911     bisitz   5451:   text-align: right;
1.1050    www      5452:   padding: 4px;
                   5453:   margin: 2px;
1.794     www      5454: }
                   5455: 
                   5456: .LC_disc_new_item {
1.911     bisitz   5457:   background: white;
                   5458:   border: 2px solid red;
1.1050    www      5459:   margin: 4px;
                   5460:   padding: 4px;
1.794     www      5461: }
                   5462: 
                   5463: .LC_disc_old_item {
1.911     bisitz   5464:   background: white;
1.1050    www      5465:   margin: 4px;
                   5466:   padding: 4px;
1.794     www      5467: }
                   5468: 
1.458     albertel 5469: table.LC_pastsubmission {
                   5470:   border: 1px solid black;
                   5471:   margin: 2px;
                   5472: }
                   5473: 
1.924     bisitz   5474: table#LC_menubuttons {
1.345     albertel 5475:   width: 100%;
                   5476:   background: $pgbg;
1.392     albertel 5477:   border: 2px;
1.402     albertel 5478:   border-collapse: separate;
1.803     bisitz   5479:   padding: 0;
1.345     albertel 5480: }
1.392     albertel 5481: 
1.801     tempelho 5482: table#LC_title_bar a {
                   5483:   color: $fontmenu;
                   5484: }
1.836     bisitz   5485: 
1.807     droeschl 5486: table#LC_title_bar {
1.819     tempelho 5487:   clear: both;
1.836     bisitz   5488:   display: none;
1.807     droeschl 5489: }
                   5490: 
1.795     www      5491: table#LC_title_bar,
1.933     droeschl 5492: table.LC_breadcrumbs, /* obsolete? */
1.393     albertel 5493: table#LC_title_bar.LC_with_remote {
1.359     albertel 5494:   width: 100%;
1.392     albertel 5495:   border-color: $pgbg;
                   5496:   border-style: solid;
                   5497:   border-width: $border;
1.379     albertel 5498:   background: $pgbg;
1.801     tempelho 5499:   color: $fontmenu;
1.392     albertel 5500:   border-collapse: collapse;
1.803     bisitz   5501:   padding: 0;
1.819     tempelho 5502:   margin: 0;
1.359     albertel 5503: }
1.795     www      5504: 
1.933     droeschl 5505: ul.LC_breadcrumb_tools_outerlist {
1.913     droeschl 5506:     margin: 0;
                   5507:     padding: 0;
1.933     droeschl 5508:     position: relative;
                   5509:     list-style: none;
1.913     droeschl 5510: }
1.933     droeschl 5511: ul.LC_breadcrumb_tools_outerlist li {
1.913     droeschl 5512:     display: inline;
                   5513: }
1.933     droeschl 5514: 
                   5515: .LC_breadcrumb_tools_navigation {
1.913     droeschl 5516:     padding: 0;
1.933     droeschl 5517:     margin: 0;
                   5518:     float: left;
1.913     droeschl 5519: }
1.933     droeschl 5520: .LC_breadcrumb_tools_tools {
                   5521:     padding: 0;
                   5522:     margin: 0;
1.913     droeschl 5523:     float: right;
                   5524: }
                   5525: 
1.359     albertel 5526: table#LC_title_bar td {
                   5527:   background: $tabbg;
                   5528: }
1.795     www      5529: 
1.911     bisitz   5530: table#LC_menubuttons img {
1.803     bisitz   5531:   border: none;
1.346     albertel 5532: }
1.795     www      5533: 
1.842     droeschl 5534: .LC_breadcrumbs_component {
1.911     bisitz   5535:   float: right;
                   5536:   margin: 0 1em;
1.357     albertel 5537: }
1.842     droeschl 5538: .LC_breadcrumbs_component img {
1.911     bisitz   5539:   vertical-align: middle;
1.777     tempelho 5540: }
1.795     www      5541: 
1.383     albertel 5542: td.LC_table_cell_checkbox {
                   5543:   text-align: center;
                   5544: }
1.795     www      5545: 
                   5546: .LC_fontsize_small {
1.911     bisitz   5547:   font-size: 70%;
1.705     tempelho 5548: }
                   5549: 
1.844     bisitz   5550: #LC_breadcrumbs {
1.911     bisitz   5551:   clear:both;
                   5552:   background: $sidebg;
                   5553:   border-bottom: 1px solid $lg_border_color;
                   5554:   line-height: 2.5em;
1.933     droeschl 5555:   overflow: hidden;
1.911     bisitz   5556:   margin: 0;
                   5557:   padding: 0;
1.995     raeburn  5558:   text-align: left;
1.819     tempelho 5559: }
1.862     bisitz   5560: 
1.1075.2.16  raeburn  5561: .LC_head_subbox, .LC_actionbox {
1.911     bisitz   5562:   clear:both;
                   5563:   background: #F8F8F8; /* $sidebg; */
1.915     droeschl 5564:   border: 1px solid $sidebg;
1.1075.2.16  raeburn  5565:   margin: 0 0 10px 0;
1.966     bisitz   5566:   padding: 3px;
1.995     raeburn  5567:   text-align: left;
1.822     bisitz   5568: }
                   5569: 
1.795     www      5570: .LC_fontsize_medium {
1.911     bisitz   5571:   font-size: 85%;
1.705     tempelho 5572: }
                   5573: 
1.795     www      5574: .LC_fontsize_large {
1.911     bisitz   5575:   font-size: 120%;
1.705     tempelho 5576: }
                   5577: 
1.346     albertel 5578: .LC_menubuttons_inline_text {
                   5579:   color: $font;
1.698     harmsja  5580:   font-size: 90%;
1.701     harmsja  5581:   padding-left:3px;
1.346     albertel 5582: }
                   5583: 
1.934     droeschl 5584: .LC_menubuttons_inline_text img{
                   5585:   vertical-align: middle;
                   5586: }
                   5587: 
1.1051    www      5588: li.LC_menubuttons_inline_text img {
1.951     onken    5589:   cursor:pointer;
1.1002    droeschl 5590:   text-decoration: none;
1.951     onken    5591: }
                   5592: 
1.526     www      5593: .LC_menubuttons_link {
                   5594:   text-decoration: none;
                   5595: }
1.795     www      5596: 
1.522     albertel 5597: .LC_menubuttons_category {
1.521     www      5598:   color: $font;
1.526     www      5599:   background: $pgbg;
1.521     www      5600:   font-size: larger;
                   5601:   font-weight: bold;
                   5602: }
                   5603: 
1.346     albertel 5604: td.LC_menubuttons_text {
1.911     bisitz   5605:   color: $font;
1.346     albertel 5606: }
1.706     harmsja  5607: 
1.346     albertel 5608: .LC_current_location {
                   5609:   background: $tabbg;
                   5610: }
1.795     www      5611: 
1.938     bisitz   5612: table.LC_data_table {
1.347     albertel 5613:   border: 1px solid #000000;
1.402     albertel 5614:   border-collapse: separate;
1.426     albertel 5615:   border-spacing: 1px;
1.610     albertel 5616:   background: $pgbg;
1.347     albertel 5617: }
1.795     www      5618: 
1.422     albertel 5619: .LC_data_table_dense {
                   5620:   font-size: small;
                   5621: }
1.795     www      5622: 
1.507     raeburn  5623: table.LC_nested_outer {
                   5624:   border: 1px solid #000000;
1.589     raeburn  5625:   border-collapse: collapse;
1.803     bisitz   5626:   border-spacing: 0;
1.507     raeburn  5627:   width: 100%;
                   5628: }
1.795     www      5629: 
1.879     raeburn  5630: table.LC_innerpickbox,
1.507     raeburn  5631: table.LC_nested {
1.803     bisitz   5632:   border: none;
1.589     raeburn  5633:   border-collapse: collapse;
1.803     bisitz   5634:   border-spacing: 0;
1.507     raeburn  5635:   width: 100%;
                   5636: }
1.795     www      5637: 
1.911     bisitz   5638: table.LC_data_table tr th,
                   5639: table.LC_calendar tr th,
1.879     raeburn  5640: table.LC_prior_tries tr th,
                   5641: table.LC_innerpickbox tr th {
1.349     albertel 5642:   font-weight: bold;
                   5643:   background-color: $data_table_head;
1.801     tempelho 5644:   color:$fontmenu;
1.701     harmsja  5645:   font-size:90%;
1.347     albertel 5646: }
1.795     www      5647: 
1.879     raeburn  5648: table.LC_innerpickbox tr th,
                   5649: table.LC_innerpickbox tr td {
                   5650:   vertical-align: top;
                   5651: }
                   5652: 
1.711     raeburn  5653: table.LC_data_table tr.LC_info_row > td {
1.735     bisitz   5654:   background-color: #CCCCCC;
1.711     raeburn  5655:   font-weight: bold;
                   5656:   text-align: left;
                   5657: }
1.795     www      5658: 
1.912     bisitz   5659: table.LC_data_table tr.LC_odd_row > td {
                   5660:   background-color: $data_table_light;
                   5661:   padding: 2px;
                   5662:   vertical-align: top;
                   5663: }
                   5664: 
1.809     bisitz   5665: table.LC_pick_box tr > td.LC_odd_row {
1.349     albertel 5666:   background-color: $data_table_light;
1.912     bisitz   5667:   vertical-align: top;
                   5668: }
                   5669: 
                   5670: table.LC_data_table tr.LC_even_row > td {
                   5671:   background-color: $data_table_dark;
1.425     albertel 5672:   padding: 2px;
1.900     bisitz   5673:   vertical-align: top;
1.347     albertel 5674: }
1.795     www      5675: 
1.809     bisitz   5676: table.LC_pick_box tr > td.LC_even_row {
1.349     albertel 5677:   background-color: $data_table_dark;
1.900     bisitz   5678:   vertical-align: top;
1.347     albertel 5679: }
1.795     www      5680: 
1.425     albertel 5681: table.LC_data_table tr.LC_data_table_highlight td {
                   5682:   background-color: $data_table_darker;
                   5683: }
1.795     www      5684: 
1.639     raeburn  5685: table.LC_data_table tr td.LC_leftcol_header {
                   5686:   background-color: $data_table_head;
                   5687:   font-weight: bold;
                   5688: }
1.795     www      5689: 
1.451     albertel 5690: table.LC_data_table tr.LC_empty_row td,
1.507     raeburn  5691: table.LC_nested tr.LC_empty_row td {
1.421     albertel 5692:   font-weight: bold;
                   5693:   font-style: italic;
                   5694:   text-align: center;
                   5695:   padding: 8px;
1.347     albertel 5696: }
1.795     www      5697: 
1.1075.2.30! raeburn  5698: table.LC_data_table tr.LC_empty_row td,
        !          5699: table.LC_data_table tr.LC_footer_row td {
1.940     bisitz   5700:   background-color: $sidebg;
                   5701: }
                   5702: 
                   5703: table.LC_nested tr.LC_empty_row td {
                   5704:   background-color: #FFFFFF;
                   5705: }
                   5706: 
1.890     droeschl 5707: table.LC_caption {
                   5708: }
                   5709: 
1.507     raeburn  5710: table.LC_nested tr.LC_empty_row td {
1.465     albertel 5711:   padding: 4ex
                   5712: }
1.795     www      5713: 
1.507     raeburn  5714: table.LC_nested_outer tr th {
                   5715:   font-weight: bold;
1.801     tempelho 5716:   color:$fontmenu;
1.507     raeburn  5717:   background-color: $data_table_head;
1.701     harmsja  5718:   font-size: small;
1.507     raeburn  5719:   border-bottom: 1px solid #000000;
                   5720: }
1.795     www      5721: 
1.507     raeburn  5722: table.LC_nested_outer tr td.LC_subheader {
                   5723:   background-color: $data_table_head;
                   5724:   font-weight: bold;
                   5725:   font-size: small;
                   5726:   border-bottom: 1px solid #000000;
                   5727:   text-align: right;
1.451     albertel 5728: }
1.795     www      5729: 
1.507     raeburn  5730: table.LC_nested tr.LC_info_row td {
1.735     bisitz   5731:   background-color: #CCCCCC;
1.451     albertel 5732:   font-weight: bold;
                   5733:   font-size: small;
1.507     raeburn  5734:   text-align: center;
                   5735: }
1.795     www      5736: 
1.589     raeburn  5737: table.LC_nested tr.LC_info_row td.LC_left_item,
                   5738: table.LC_nested_outer tr th.LC_left_item {
1.507     raeburn  5739:   text-align: left;
1.451     albertel 5740: }
1.795     www      5741: 
1.507     raeburn  5742: table.LC_nested td {
1.735     bisitz   5743:   background-color: #FFFFFF;
1.451     albertel 5744:   font-size: small;
1.507     raeburn  5745: }
1.795     www      5746: 
1.507     raeburn  5747: table.LC_nested_outer tr th.LC_right_item,
                   5748: table.LC_nested tr.LC_info_row td.LC_right_item,
                   5749: table.LC_nested tr.LC_odd_row td.LC_right_item,
                   5750: table.LC_nested tr td.LC_right_item {
1.451     albertel 5751:   text-align: right;
                   5752: }
                   5753: 
1.507     raeburn  5754: table.LC_nested tr.LC_odd_row td {
1.735     bisitz   5755:   background-color: #EEEEEE;
1.451     albertel 5756: }
                   5757: 
1.473     raeburn  5758: table.LC_createuser {
                   5759: }
                   5760: 
                   5761: table.LC_createuser tr.LC_section_row td {
1.701     harmsja  5762:   font-size: small;
1.473     raeburn  5763: }
                   5764: 
                   5765: table.LC_createuser tr.LC_info_row td  {
1.735     bisitz   5766:   background-color: #CCCCCC;
1.473     raeburn  5767:   font-weight: bold;
                   5768:   text-align: center;
                   5769: }
                   5770: 
1.349     albertel 5771: table.LC_calendar {
                   5772:   border: 1px solid #000000;
                   5773:   border-collapse: collapse;
1.917     raeburn  5774:   width: 98%;
1.349     albertel 5775: }
1.795     www      5776: 
1.349     albertel 5777: table.LC_calendar_pickdate {
                   5778:   font-size: xx-small;
                   5779: }
1.795     www      5780: 
1.349     albertel 5781: table.LC_calendar tr td {
                   5782:   border: 1px solid #000000;
                   5783:   vertical-align: top;
1.917     raeburn  5784:   width: 14%;
1.349     albertel 5785: }
1.795     www      5786: 
1.349     albertel 5787: table.LC_calendar tr td.LC_calendar_day_empty {
                   5788:   background-color: $data_table_dark;
                   5789: }
1.795     www      5790: 
1.779     bisitz   5791: table.LC_calendar tr td.LC_calendar_day_current {
                   5792:   background-color: $data_table_highlight;
1.777     tempelho 5793: }
1.795     www      5794: 
1.938     bisitz   5795: table.LC_data_table tr td.LC_mail_new {
1.349     albertel 5796:   background-color: $mail_new;
                   5797: }
1.795     www      5798: 
1.938     bisitz   5799: table.LC_data_table tr.LC_mail_new:hover {
1.349     albertel 5800:   background-color: $mail_new_hover;
                   5801: }
1.795     www      5802: 
1.938     bisitz   5803: table.LC_data_table tr td.LC_mail_read {
1.349     albertel 5804:   background-color: $mail_read;
                   5805: }
1.795     www      5806: 
1.938     bisitz   5807: /*
                   5808: table.LC_data_table tr.LC_mail_read:hover {
1.349     albertel 5809:   background-color: $mail_read_hover;
                   5810: }
1.938     bisitz   5811: */
1.795     www      5812: 
1.938     bisitz   5813: table.LC_data_table tr td.LC_mail_replied {
1.349     albertel 5814:   background-color: $mail_replied;
                   5815: }
1.795     www      5816: 
1.938     bisitz   5817: /*
                   5818: table.LC_data_table tr.LC_mail_replied:hover {
1.349     albertel 5819:   background-color: $mail_replied_hover;
                   5820: }
1.938     bisitz   5821: */
1.795     www      5822: 
1.938     bisitz   5823: table.LC_data_table tr td.LC_mail_other {
1.349     albertel 5824:   background-color: $mail_other;
                   5825: }
1.795     www      5826: 
1.938     bisitz   5827: /*
                   5828: table.LC_data_table tr.LC_mail_other:hover {
1.349     albertel 5829:   background-color: $mail_other_hover;
                   5830: }
1.938     bisitz   5831: */
1.494     raeburn  5832: 
1.777     tempelho 5833: table.LC_data_table tr > td.LC_browser_file,
                   5834: table.LC_data_table tr > td.LC_browser_file_published {
1.899     bisitz   5835:   background: #AAEE77;
1.389     albertel 5836: }
1.795     www      5837: 
1.777     tempelho 5838: table.LC_data_table tr > td.LC_browser_file_locked,
                   5839: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389     albertel 5840:   background: #FFAA99;
1.387     albertel 5841: }
1.795     www      5842: 
1.777     tempelho 5843: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899     bisitz   5844:   background: #888888;
1.779     bisitz   5845: }
1.795     www      5846: 
1.777     tempelho 5847: table.LC_data_table tr > td.LC_browser_file_modified,
1.779     bisitz   5848: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899     bisitz   5849:   background: #F8F866;
1.777     tempelho 5850: }
1.795     www      5851: 
1.696     bisitz   5852: table.LC_data_table tr.LC_browser_folder > td {
1.899     bisitz   5853:   background: #E0E8FF;
1.387     albertel 5854: }
1.696     bisitz   5855: 
1.707     bisitz   5856: table.LC_data_table tr > td.LC_roles_is {
1.911     bisitz   5857:   /* background: #77FF77; */
1.707     bisitz   5858: }
1.795     www      5859: 
1.707     bisitz   5860: table.LC_data_table tr > td.LC_roles_future {
1.939     bisitz   5861:   border-right: 8px solid #FFFF77;
1.707     bisitz   5862: }
1.795     www      5863: 
1.707     bisitz   5864: table.LC_data_table tr > td.LC_roles_will {
1.939     bisitz   5865:   border-right: 8px solid #FFAA77;
1.707     bisitz   5866: }
1.795     www      5867: 
1.707     bisitz   5868: table.LC_data_table tr > td.LC_roles_expired {
1.939     bisitz   5869:   border-right: 8px solid #FF7777;
1.707     bisitz   5870: }
1.795     www      5871: 
1.707     bisitz   5872: table.LC_data_table tr > td.LC_roles_will_not {
1.939     bisitz   5873:   border-right: 8px solid #AAFF77;
1.707     bisitz   5874: }
1.795     www      5875: 
1.707     bisitz   5876: table.LC_data_table tr > td.LC_roles_selected {
1.939     bisitz   5877:   border-right: 8px solid #11CC55;
1.707     bisitz   5878: }
                   5879: 
1.388     albertel 5880: span.LC_current_location {
1.701     harmsja  5881:   font-size:larger;
1.388     albertel 5882:   background: $pgbg;
                   5883: }
1.387     albertel 5884: 
1.1029    www      5885: span.LC_current_nav_location {
                   5886:   font-weight:bold;
                   5887:   background: $sidebg;
                   5888: }
                   5889: 
1.395     albertel 5890: span.LC_parm_menu_item {
                   5891:   font-size: larger;
                   5892: }
1.795     www      5893: 
1.395     albertel 5894: span.LC_parm_scope_all {
                   5895:   color: red;
                   5896: }
1.795     www      5897: 
1.395     albertel 5898: span.LC_parm_scope_folder {
                   5899:   color: green;
                   5900: }
1.795     www      5901: 
1.395     albertel 5902: span.LC_parm_scope_resource {
                   5903:   color: orange;
                   5904: }
1.795     www      5905: 
1.395     albertel 5906: span.LC_parm_part {
                   5907:   color: blue;
                   5908: }
1.795     www      5909: 
1.911     bisitz   5910: span.LC_parm_folder,
                   5911: span.LC_parm_symb {
1.395     albertel 5912:   font-size: x-small;
                   5913:   font-family: $mono;
                   5914:   color: #AAAAAA;
                   5915: }
                   5916: 
1.977     bisitz   5917: ul.LC_parm_parmlist li {
                   5918:   display: inline-block;
                   5919:   padding: 0.3em 0.8em;
                   5920:   vertical-align: top;
                   5921:   width: 150px;
                   5922:   border-top:1px solid $lg_border_color;
                   5923: }
                   5924: 
1.795     www      5925: td.LC_parm_overview_level_menu,
                   5926: td.LC_parm_overview_map_menu,
                   5927: td.LC_parm_overview_parm_selectors,
                   5928: td.LC_parm_overview_restrictions  {
1.396     albertel 5929:   border: 1px solid black;
                   5930:   border-collapse: collapse;
                   5931: }
1.795     www      5932: 
1.396     albertel 5933: table.LC_parm_overview_restrictions td {
                   5934:   border-width: 1px 4px 1px 4px;
                   5935:   border-style: solid;
                   5936:   border-color: $pgbg;
                   5937:   text-align: center;
                   5938: }
1.795     www      5939: 
1.396     albertel 5940: table.LC_parm_overview_restrictions th {
                   5941:   background: $tabbg;
                   5942:   border-width: 1px 4px 1px 4px;
                   5943:   border-style: solid;
                   5944:   border-color: $pgbg;
                   5945: }
1.795     www      5946: 
1.398     albertel 5947: table#LC_helpmenu {
1.803     bisitz   5948:   border: none;
1.398     albertel 5949:   height: 55px;
1.803     bisitz   5950:   border-spacing: 0;
1.398     albertel 5951: }
                   5952: 
                   5953: table#LC_helpmenu fieldset legend {
                   5954:   font-size: larger;
                   5955: }
1.795     www      5956: 
1.397     albertel 5957: table#LC_helpmenu_links {
                   5958:   width: 100%;
                   5959:   border: 1px solid black;
                   5960:   background: $pgbg;
1.803     bisitz   5961:   padding: 0;
1.397     albertel 5962:   border-spacing: 1px;
                   5963: }
1.795     www      5964: 
1.397     albertel 5965: table#LC_helpmenu_links tr td {
                   5966:   padding: 1px;
                   5967:   background: $tabbg;
1.399     albertel 5968:   text-align: center;
                   5969:   font-weight: bold;
1.397     albertel 5970: }
1.396     albertel 5971: 
1.795     www      5972: table#LC_helpmenu_links a:link,
                   5973: table#LC_helpmenu_links a:visited,
1.397     albertel 5974: table#LC_helpmenu_links a:active {
                   5975:   text-decoration: none;
                   5976:   color: $font;
                   5977: }
1.795     www      5978: 
1.397     albertel 5979: table#LC_helpmenu_links a:hover {
                   5980:   text-decoration: underline;
                   5981:   color: $vlink;
                   5982: }
1.396     albertel 5983: 
1.417     albertel 5984: .LC_chrt_popup_exists {
                   5985:   border: 1px solid #339933;
                   5986:   margin: -1px;
                   5987: }
1.795     www      5988: 
1.417     albertel 5989: .LC_chrt_popup_up {
                   5990:   border: 1px solid yellow;
                   5991:   margin: -1px;
                   5992: }
1.795     www      5993: 
1.417     albertel 5994: .LC_chrt_popup {
                   5995:   border: 1px solid #8888FF;
                   5996:   background: #CCCCFF;
                   5997: }
1.795     www      5998: 
1.421     albertel 5999: table.LC_pick_box {
                   6000:   border-collapse: separate;
                   6001:   background: white;
                   6002:   border: 1px solid black;
                   6003:   border-spacing: 1px;
                   6004: }
1.795     www      6005: 
1.421     albertel 6006: table.LC_pick_box td.LC_pick_box_title {
1.850     bisitz   6007:   background: $sidebg;
1.421     albertel 6008:   font-weight: bold;
1.900     bisitz   6009:   text-align: left;
1.740     bisitz   6010:   vertical-align: top;
1.421     albertel 6011:   width: 184px;
                   6012:   padding: 8px;
                   6013: }
1.795     www      6014: 
1.579     raeburn  6015: table.LC_pick_box td.LC_pick_box_value {
                   6016:   text-align: left;
                   6017:   padding: 8px;
                   6018: }
1.795     www      6019: 
1.579     raeburn  6020: table.LC_pick_box td.LC_pick_box_select {
                   6021:   text-align: left;
                   6022:   padding: 8px;
                   6023: }
1.795     www      6024: 
1.424     albertel 6025: table.LC_pick_box td.LC_pick_box_separator {
1.803     bisitz   6026:   padding: 0;
1.421     albertel 6027:   height: 1px;
                   6028:   background: black;
                   6029: }
1.795     www      6030: 
1.421     albertel 6031: table.LC_pick_box td.LC_pick_box_submit {
                   6032:   text-align: right;
                   6033: }
1.795     www      6034: 
1.579     raeburn  6035: table.LC_pick_box td.LC_evenrow_value {
                   6036:   text-align: left;
                   6037:   padding: 8px;
                   6038:   background-color: $data_table_light;
                   6039: }
1.795     www      6040: 
1.579     raeburn  6041: table.LC_pick_box td.LC_oddrow_value {
                   6042:   text-align: left;
                   6043:   padding: 8px;
                   6044:   background-color: $data_table_light;
                   6045: }
1.795     www      6046: 
1.579     raeburn  6047: span.LC_helpform_receipt_cat {
                   6048:   font-weight: bold;
                   6049: }
1.795     www      6050: 
1.424     albertel 6051: table.LC_group_priv_box {
                   6052:   background: white;
                   6053:   border: 1px solid black;
                   6054:   border-spacing: 1px;
                   6055: }
1.795     www      6056: 
1.424     albertel 6057: table.LC_group_priv_box td.LC_pick_box_title {
                   6058:   background: $tabbg;
                   6059:   font-weight: bold;
                   6060:   text-align: right;
                   6061:   width: 184px;
                   6062: }
1.795     www      6063: 
1.424     albertel 6064: table.LC_group_priv_box td.LC_groups_fixed {
                   6065:   background: $data_table_light;
                   6066:   text-align: center;
                   6067: }
1.795     www      6068: 
1.424     albertel 6069: table.LC_group_priv_box td.LC_groups_optional {
                   6070:   background: $data_table_dark;
                   6071:   text-align: center;
                   6072: }
1.795     www      6073: 
1.424     albertel 6074: table.LC_group_priv_box td.LC_groups_functionality {
                   6075:   background: $data_table_darker;
                   6076:   text-align: center;
                   6077:   font-weight: bold;
                   6078: }
1.795     www      6079: 
1.424     albertel 6080: table.LC_group_priv td {
                   6081:   text-align: left;
1.803     bisitz   6082:   padding: 0;
1.424     albertel 6083: }
                   6084: 
                   6085: .LC_navbuttons {
                   6086:   margin: 2ex 0ex 2ex 0ex;
                   6087: }
1.795     www      6088: 
1.423     albertel 6089: .LC_topic_bar {
                   6090:   font-weight: bold;
                   6091:   background: $tabbg;
1.918     wenzelju 6092:   margin: 1em 0em 1em 2em;
1.805     bisitz   6093:   padding: 3px;
1.918     wenzelju 6094:   font-size: 1.2em;
1.423     albertel 6095: }
1.795     www      6096: 
1.423     albertel 6097: .LC_topic_bar span {
1.918     wenzelju 6098:   left: 0.5em;
                   6099:   position: absolute;
1.423     albertel 6100:   vertical-align: middle;
1.918     wenzelju 6101:   font-size: 1.2em;
1.423     albertel 6102: }
1.795     www      6103: 
1.423     albertel 6104: table.LC_course_group_status {
                   6105:   margin: 20px;
                   6106: }
1.795     www      6107: 
1.423     albertel 6108: table.LC_status_selector td {
                   6109:   vertical-align: top;
                   6110:   text-align: center;
1.424     albertel 6111:   padding: 4px;
                   6112: }
1.795     www      6113: 
1.599     albertel 6114: div.LC_feedback_link {
1.616     albertel 6115:   clear: both;
1.829     kalberla 6116:   background: $sidebg;
1.779     bisitz   6117:   width: 100%;
1.829     kalberla 6118:   padding-bottom: 10px;
                   6119:   border: 1px $tabbg solid;
1.833     kalberla 6120:   height: 22px;
                   6121:   line-height: 22px;
                   6122:   padding-top: 5px;
                   6123: }
                   6124: 
                   6125: div.LC_feedback_link img {
                   6126:   height: 22px;
1.867     kalberla 6127:   vertical-align:middle;
1.829     kalberla 6128: }
                   6129: 
1.911     bisitz   6130: div.LC_feedback_link a {
1.829     kalberla 6131:   text-decoration: none;
1.489     raeburn  6132: }
1.795     www      6133: 
1.867     kalberla 6134: div.LC_comblock {
1.911     bisitz   6135:   display:inline;
1.867     kalberla 6136:   color:$font;
                   6137:   font-size:90%;
                   6138: }
                   6139: 
                   6140: div.LC_feedback_link div.LC_comblock {
                   6141:   padding-left:5px;
                   6142: }
                   6143: 
                   6144: div.LC_feedback_link div.LC_comblock a {
                   6145:   color:$font;
                   6146: }
                   6147: 
1.489     raeburn  6148: span.LC_feedback_link {
1.858     bisitz   6149:   /* background: $feedback_link_bg; */
1.599     albertel 6150:   font-size: larger;
                   6151: }
1.795     www      6152: 
1.599     albertel 6153: span.LC_message_link {
1.858     bisitz   6154:   /* background: $feedback_link_bg; */
1.599     albertel 6155:   font-size: larger;
                   6156:   position: absolute;
                   6157:   right: 1em;
1.489     raeburn  6158: }
1.421     albertel 6159: 
1.515     albertel 6160: table.LC_prior_tries {
1.524     albertel 6161:   border: 1px solid #000000;
                   6162:   border-collapse: separate;
                   6163:   border-spacing: 1px;
1.515     albertel 6164: }
1.523     albertel 6165: 
1.515     albertel 6166: table.LC_prior_tries td {
1.524     albertel 6167:   padding: 2px;
1.515     albertel 6168: }
1.523     albertel 6169: 
                   6170: .LC_answer_correct {
1.795     www      6171:   background: lightgreen;
                   6172:   color: darkgreen;
                   6173:   padding: 6px;
1.523     albertel 6174: }
1.795     www      6175: 
1.523     albertel 6176: .LC_answer_charged_try {
1.797     www      6177:   background: #FFAAAA;
1.795     www      6178:   color: darkred;
                   6179:   padding: 6px;
1.523     albertel 6180: }
1.795     www      6181: 
1.779     bisitz   6182: .LC_answer_not_charged_try,
1.523     albertel 6183: .LC_answer_no_grade,
                   6184: .LC_answer_late {
1.795     www      6185:   background: lightyellow;
1.523     albertel 6186:   color: black;
1.795     www      6187:   padding: 6px;
1.523     albertel 6188: }
1.795     www      6189: 
1.523     albertel 6190: .LC_answer_previous {
1.795     www      6191:   background: lightblue;
                   6192:   color: darkblue;
                   6193:   padding: 6px;
1.523     albertel 6194: }
1.795     www      6195: 
1.779     bisitz   6196: .LC_answer_no_message {
1.777     tempelho 6197:   background: #FFFFFF;
                   6198:   color: black;
1.795     www      6199:   padding: 6px;
1.779     bisitz   6200: }
1.795     www      6201: 
1.779     bisitz   6202: .LC_answer_unknown {
                   6203:   background: orange;
                   6204:   color: black;
1.795     www      6205:   padding: 6px;
1.777     tempelho 6206: }
1.795     www      6207: 
1.529     albertel 6208: span.LC_prior_numerical,
                   6209: span.LC_prior_string,
                   6210: span.LC_prior_custom,
                   6211: span.LC_prior_reaction,
                   6212: span.LC_prior_math {
1.925     bisitz   6213:   font-family: $mono;
1.523     albertel 6214:   white-space: pre;
                   6215: }
                   6216: 
1.525     albertel 6217: span.LC_prior_string {
1.925     bisitz   6218:   font-family: $mono;
1.525     albertel 6219:   white-space: pre;
                   6220: }
                   6221: 
1.523     albertel 6222: table.LC_prior_option {
                   6223:   width: 100%;
                   6224:   border-collapse: collapse;
                   6225: }
1.795     www      6226: 
1.911     bisitz   6227: table.LC_prior_rank,
1.795     www      6228: table.LC_prior_match {
1.528     albertel 6229:   border-collapse: collapse;
                   6230: }
1.795     www      6231: 
1.528     albertel 6232: table.LC_prior_option tr td,
                   6233: table.LC_prior_rank tr td,
                   6234: table.LC_prior_match tr td {
1.524     albertel 6235:   border: 1px solid #000000;
1.515     albertel 6236: }
                   6237: 
1.855     bisitz   6238: .LC_nobreak {
1.544     albertel 6239:   white-space: nowrap;
1.519     raeburn  6240: }
                   6241: 
1.576     raeburn  6242: span.LC_cusr_emph {
                   6243:   font-style: italic;
                   6244: }
                   6245: 
1.633     raeburn  6246: span.LC_cusr_subheading {
                   6247:   font-weight: normal;
                   6248:   font-size: 85%;
                   6249: }
                   6250: 
1.861     bisitz   6251: div.LC_docs_entry_move {
1.859     bisitz   6252:   border: 1px solid #BBBBBB;
1.545     albertel 6253:   background: #DDDDDD;
1.861     bisitz   6254:   width: 22px;
1.859     bisitz   6255:   padding: 1px;
                   6256:   margin: 0;
1.545     albertel 6257: }
                   6258: 
1.861     bisitz   6259: table.LC_data_table tr > td.LC_docs_entry_commands,
                   6260: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545     albertel 6261:   font-size: x-small;
                   6262: }
1.795     www      6263: 
1.861     bisitz   6264: .LC_docs_entry_parameter {
                   6265:   white-space: nowrap;
                   6266: }
                   6267: 
1.544     albertel 6268: .LC_docs_copy {
1.545     albertel 6269:   color: #000099;
1.544     albertel 6270: }
1.795     www      6271: 
1.544     albertel 6272: .LC_docs_cut {
1.545     albertel 6273:   color: #550044;
1.544     albertel 6274: }
1.795     www      6275: 
1.544     albertel 6276: .LC_docs_rename {
1.545     albertel 6277:   color: #009900;
1.544     albertel 6278: }
1.795     www      6279: 
1.544     albertel 6280: .LC_docs_remove {
1.545     albertel 6281:   color: #990000;
                   6282: }
                   6283: 
1.547     albertel 6284: .LC_docs_reinit_warn,
                   6285: .LC_docs_ext_edit {
                   6286:   font-size: x-small;
                   6287: }
                   6288: 
1.545     albertel 6289: table.LC_docs_adddocs td,
                   6290: table.LC_docs_adddocs th {
                   6291:   border: 1px solid #BBBBBB;
                   6292:   padding: 4px;
                   6293:   background: #DDDDDD;
1.543     albertel 6294: }
                   6295: 
1.584     albertel 6296: table.LC_sty_begin {
                   6297:   background: #BBFFBB;
                   6298: }
1.795     www      6299: 
1.584     albertel 6300: table.LC_sty_end {
                   6301:   background: #FFBBBB;
                   6302: }
                   6303: 
1.589     raeburn  6304: table.LC_double_column {
1.803     bisitz   6305:   border-width: 0;
1.589     raeburn  6306:   border-collapse: collapse;
                   6307:   width: 100%;
                   6308:   padding: 2px;
                   6309: }
                   6310: 
                   6311: table.LC_double_column tr td.LC_left_col {
1.590     raeburn  6312:   top: 2px;
1.589     raeburn  6313:   left: 2px;
                   6314:   width: 47%;
                   6315:   vertical-align: top;
                   6316: }
                   6317: 
                   6318: table.LC_double_column tr td.LC_right_col {
                   6319:   top: 2px;
1.779     bisitz   6320:   right: 2px;
1.589     raeburn  6321:   width: 47%;
                   6322:   vertical-align: top;
                   6323: }
                   6324: 
1.591     raeburn  6325: div.LC_left_float {
                   6326:   float: left;
                   6327:   padding-right: 5%;
1.597     albertel 6328:   padding-bottom: 4px;
1.591     raeburn  6329: }
                   6330: 
                   6331: div.LC_clear_float_header {
1.597     albertel 6332:   padding-bottom: 2px;
1.591     raeburn  6333: }
                   6334: 
                   6335: div.LC_clear_float_footer {
1.597     albertel 6336:   padding-top: 10px;
1.591     raeburn  6337:   clear: both;
                   6338: }
                   6339: 
1.597     albertel 6340: div.LC_grade_show_user {
1.941     bisitz   6341: /*  border-left: 5px solid $sidebg; */
                   6342:   border-top: 5px solid #000000;
                   6343:   margin: 50px 0 0 0;
1.936     bisitz   6344:   padding: 15px 0 5px 10px;
1.597     albertel 6345: }
1.795     www      6346: 
1.936     bisitz   6347: div.LC_grade_show_user_odd_row {
1.941     bisitz   6348: /*  border-left: 5px solid #000000; */
                   6349: }
                   6350: 
                   6351: div.LC_grade_show_user div.LC_Box {
                   6352:   margin-right: 50px;
1.597     albertel 6353: }
                   6354: 
                   6355: div.LC_grade_submissions,
                   6356: div.LC_grade_message_center,
1.936     bisitz   6357: div.LC_grade_info_links {
1.597     albertel 6358:   margin: 5px;
                   6359:   width: 99%;
                   6360:   background: #FFFFFF;
                   6361: }
1.795     www      6362: 
1.597     albertel 6363: div.LC_grade_submissions_header,
1.936     bisitz   6364: div.LC_grade_message_center_header {
1.705     tempelho 6365:   font-weight: bold;
                   6366:   font-size: large;
1.597     albertel 6367: }
1.795     www      6368: 
1.597     albertel 6369: div.LC_grade_submissions_body,
1.936     bisitz   6370: div.LC_grade_message_center_body {
1.597     albertel 6371:   border: 1px solid black;
                   6372:   width: 99%;
                   6373:   background: #FFFFFF;
                   6374: }
1.795     www      6375: 
1.613     albertel 6376: table.LC_scantron_action {
                   6377:   width: 100%;
                   6378: }
1.795     www      6379: 
1.613     albertel 6380: table.LC_scantron_action tr th {
1.698     harmsja  6381:   font-weight:bold;
                   6382:   font-style:normal;
1.613     albertel 6383: }
1.795     www      6384: 
1.779     bisitz   6385: .LC_edit_problem_header,
1.614     albertel 6386: div.LC_edit_problem_footer {
1.705     tempelho 6387:   font-weight: normal;
                   6388:   font-size:  medium;
1.602     albertel 6389:   margin: 2px;
1.1060    bisitz   6390:   background-color: $sidebg;
1.600     albertel 6391: }
1.795     www      6392: 
1.600     albertel 6393: div.LC_edit_problem_header,
1.602     albertel 6394: div.LC_edit_problem_header div,
1.614     albertel 6395: div.LC_edit_problem_footer,
                   6396: div.LC_edit_problem_footer div,
1.602     albertel 6397: div.LC_edit_problem_editxml_header,
                   6398: div.LC_edit_problem_editxml_header div {
1.600     albertel 6399:   margin-top: 5px;
                   6400: }
1.795     www      6401: 
1.600     albertel 6402: div.LC_edit_problem_header_title {
1.705     tempelho 6403:   font-weight: bold;
                   6404:   font-size: larger;
1.602     albertel 6405:   background: $tabbg;
                   6406:   padding: 3px;
1.1060    bisitz   6407:   margin: 0 0 5px 0;
1.602     albertel 6408: }
1.795     www      6409: 
1.602     albertel 6410: table.LC_edit_problem_header_title {
                   6411:   width: 100%;
1.600     albertel 6412:   background: $tabbg;
1.602     albertel 6413: }
                   6414: 
                   6415: div.LC_edit_problem_discards {
                   6416:   float: left;
                   6417:   padding-bottom: 5px;
                   6418: }
1.795     www      6419: 
1.602     albertel 6420: div.LC_edit_problem_saves {
                   6421:   float: right;
                   6422:   padding-bottom: 5px;
1.600     albertel 6423: }
1.795     www      6424: 
1.911     bisitz   6425: img.stift {
1.803     bisitz   6426:   border-width: 0;
                   6427:   vertical-align: middle;
1.677     riegler  6428: }
1.680     riegler  6429: 
1.923     bisitz   6430: table td.LC_mainmenu_col_fieldset {
1.680     riegler  6431:   vertical-align: top;
1.777     tempelho 6432: }
1.795     www      6433: 
1.716     raeburn  6434: div.LC_createcourse {
1.911     bisitz   6435:   margin: 10px 10px 10px 10px;
1.716     raeburn  6436: }
                   6437: 
1.917     raeburn  6438: .LC_dccid {
                   6439:   margin: 0.2em 0 0 0;
                   6440:   padding: 0;
                   6441:   font-size: 90%;
                   6442:   display:none;
                   6443: }
                   6444: 
1.897     wenzelju 6445: ol.LC_primary_menu a:hover,
1.721     harmsja  6446: ol#LC_MenuBreadcrumbs a:hover,
                   6447: ol#LC_PathBreadcrumbs a:hover,
1.897     wenzelju 6448: ul#LC_secondary_menu a:hover,
1.721     harmsja  6449: .LC_FormSectionClearButton input:hover
1.795     www      6450: ul.LC_TabContent   li:hover a {
1.952     onken    6451:   color:$button_hover;
1.911     bisitz   6452:   text-decoration:none;
1.693     droeschl 6453: }
                   6454: 
1.779     bisitz   6455: h1 {
1.911     bisitz   6456:   padding: 0;
                   6457:   line-height:130%;
1.693     droeschl 6458: }
1.698     harmsja  6459: 
1.911     bisitz   6460: h2,
                   6461: h3,
                   6462: h4,
                   6463: h5,
                   6464: h6 {
                   6465:   margin: 5px 0 5px 0;
                   6466:   padding: 0;
                   6467:   line-height:130%;
1.693     droeschl 6468: }
1.795     www      6469: 
                   6470: .LC_hcell {
1.911     bisitz   6471:   padding:3px 15px 3px 15px;
                   6472:   margin: 0;
                   6473:   background-color:$tabbg;
                   6474:   color:$fontmenu;
                   6475:   border-bottom:solid 1px $lg_border_color;
1.693     droeschl 6476: }
1.795     www      6477: 
1.840     bisitz   6478: .LC_Box > .LC_hcell {
1.911     bisitz   6479:   margin: 0 -10px 10px -10px;
1.835     bisitz   6480: }
                   6481: 
1.721     harmsja  6482: .LC_noBorder {
1.911     bisitz   6483:   border: 0;
1.698     harmsja  6484: }
1.693     droeschl 6485: 
1.721     harmsja  6486: .LC_FormSectionClearButton input {
1.911     bisitz   6487:   background-color:transparent;
                   6488:   border: none;
                   6489:   cursor:pointer;
                   6490:   text-decoration:underline;
1.693     droeschl 6491: }
1.763     bisitz   6492: 
                   6493: .LC_help_open_topic {
1.911     bisitz   6494:   color: #FFFFFF;
                   6495:   background-color: #EEEEFF;
                   6496:   margin: 1px;
                   6497:   padding: 4px;
                   6498:   border: 1px solid #000033;
                   6499:   white-space: nowrap;
                   6500:   /* vertical-align: middle; */
1.759     neumanie 6501: }
1.693     droeschl 6502: 
1.911     bisitz   6503: dl,
                   6504: ul,
                   6505: div,
                   6506: fieldset {
                   6507:   margin: 10px 10px 10px 0;
                   6508:   /* overflow: hidden; */
1.693     droeschl 6509: }
1.795     www      6510: 
1.838     bisitz   6511: fieldset > legend {
1.911     bisitz   6512:   font-weight: bold;
                   6513:   padding: 0 5px 0 5px;
1.838     bisitz   6514: }
                   6515: 
1.813     bisitz   6516: #LC_nav_bar {
1.911     bisitz   6517:   float: left;
1.995     raeburn  6518:   background-color: $pgbg_or_bgcolor;
1.966     bisitz   6519:   margin: 0 0 2px 0;
1.807     droeschl 6520: }
                   6521: 
1.916     droeschl 6522: #LC_realm {
                   6523:   margin: 0.2em 0 0 0;
                   6524:   padding: 0;
                   6525:   font-weight: bold;
                   6526:   text-align: center;
1.995     raeburn  6527:   background-color: $pgbg_or_bgcolor;
1.916     droeschl 6528: }
                   6529: 
1.911     bisitz   6530: #LC_nav_bar em {
                   6531:   font-weight: bold;
                   6532:   font-style: normal;
1.807     droeschl 6533: }
                   6534: 
1.897     wenzelju 6535: ol.LC_primary_menu {
1.911     bisitz   6536:   float: right;
1.934     droeschl 6537:   margin: 0;
1.1075.2.2  raeburn  6538:   padding: 0;
1.995     raeburn  6539:   background-color: $pgbg_or_bgcolor;
1.807     droeschl 6540: }
                   6541: 
1.852     droeschl 6542: ol#LC_PathBreadcrumbs {
1.911     bisitz   6543:   margin: 0;
1.693     droeschl 6544: }
                   6545: 
1.897     wenzelju 6546: ol.LC_primary_menu li {
1.1075.2.2  raeburn  6547:   color: RGB(80, 80, 80);
                   6548:   vertical-align: middle;
                   6549:   text-align: left;
                   6550:   list-style: none;
                   6551:   float: left;
                   6552: }
                   6553: 
                   6554: ol.LC_primary_menu li a {
                   6555:   display: block;
                   6556:   margin: 0;
                   6557:   padding: 0 5px 0 10px;
                   6558:   text-decoration: none;
                   6559: }
                   6560: 
                   6561: ol.LC_primary_menu li ul {
                   6562:   display: none;
                   6563:   width: 10em;
                   6564:   background-color: $data_table_light;
                   6565: }
                   6566: 
                   6567: ol.LC_primary_menu li:hover ul, ol.LC_primary_menu li.hover ul {
                   6568:   display: block;
                   6569:   position: absolute;
                   6570:   margin: 0;
                   6571:   padding: 0;
1.1075.2.5  raeburn  6572:   z-index: 2;
1.1075.2.2  raeburn  6573: }
                   6574: 
                   6575: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
                   6576:   font-size: 90%;
1.911     bisitz   6577:   vertical-align: top;
1.1075.2.2  raeburn  6578:   float: none;
1.1075.2.5  raeburn  6579:   border-left: 1px solid black;
                   6580:   border-right: 1px solid black;
1.1075.2.2  raeburn  6581: }
                   6582: 
                   6583: ol.LC_primary_menu li:hover li a, ol.LC_primary_menu li.hover li a {
1.1075.2.5  raeburn  6584:   background-color:$data_table_light;
1.1075.2.2  raeburn  6585: }
                   6586: 
                   6587: ol.LC_primary_menu li li a:hover {
                   6588:    color:$button_hover;
                   6589:    background-color:$data_table_dark;
1.693     droeschl 6590: }
                   6591: 
1.897     wenzelju 6592: ol.LC_primary_menu li img {
1.911     bisitz   6593:   vertical-align: bottom;
1.934     droeschl 6594:   height: 1.1em;
1.1075.2.3  raeburn  6595:   margin: 0.2em 0 0 0;
1.693     droeschl 6596: }
                   6597: 
1.897     wenzelju 6598: ol.LC_primary_menu a {
1.911     bisitz   6599:   color: RGB(80, 80, 80);
                   6600:   text-decoration: none;
1.693     droeschl 6601: }
1.795     www      6602: 
1.949     droeschl 6603: ol.LC_primary_menu a.LC_new_message {
                   6604:   font-weight:bold;
                   6605:   color: darkred;
                   6606: }
                   6607: 
1.975     raeburn  6608: ol.LC_docs_parameters {
                   6609:   margin-left: 0;
                   6610:   padding: 0;
                   6611:   list-style: none;
                   6612: }
                   6613: 
                   6614: ol.LC_docs_parameters li {
                   6615:   margin: 0;
                   6616:   padding-right: 20px;
                   6617:   display: inline;
                   6618: }
                   6619: 
1.976     raeburn  6620: ol.LC_docs_parameters li:before {
                   6621:   content: "\\002022 \\0020";
                   6622: }
                   6623: 
                   6624: li.LC_docs_parameters_title {
                   6625:   font-weight: bold;
                   6626: }
                   6627: 
                   6628: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
                   6629:   content: "";
                   6630: }
                   6631: 
1.897     wenzelju 6632: ul#LC_secondary_menu {
1.1075.2.23  raeburn  6633:   clear: right;
1.911     bisitz   6634:   color: $fontmenu;
                   6635:   background: $tabbg;
                   6636:   list-style: none;
                   6637:   padding: 0;
                   6638:   margin: 0;
                   6639:   width: 100%;
1.995     raeburn  6640:   text-align: left;
1.1075.2.4  raeburn  6641:   float: left;
1.808     droeschl 6642: }
                   6643: 
1.897     wenzelju 6644: ul#LC_secondary_menu li {
1.911     bisitz   6645:   font-weight: bold;
                   6646:   line-height: 1.8em;
                   6647:   border-right: 1px solid black;
                   6648:   vertical-align: middle;
1.1075.2.4  raeburn  6649:   float: left;
                   6650: }
                   6651: 
                   6652: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
                   6653:   background-color: $data_table_light;
                   6654: }
                   6655: 
                   6656: ul#LC_secondary_menu li a {
                   6657:   padding: 0 0.8em;
                   6658: }
                   6659: 
                   6660: ul#LC_secondary_menu li ul {
                   6661:   display: none;
                   6662: }
                   6663: 
                   6664: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
                   6665:   display: block;
                   6666:   position: absolute;
                   6667:   margin: 0;
                   6668:   padding: 0;
                   6669:   list-style:none;
                   6670:   float: none;
                   6671:   background-color: $data_table_light;
1.1075.2.5  raeburn  6672:   z-index: 2;
1.1075.2.10  raeburn  6673:   margin-left: -1px;
1.1075.2.4  raeburn  6674: }
                   6675: 
                   6676: ul#LC_secondary_menu li ul li {
                   6677:   font-size: 90%;
                   6678:   vertical-align: top;
                   6679:   border-left: 1px solid black;
                   6680:   border-right: 1px solid black;
                   6681:   background-color: $data_table_light
                   6682:   list-style:none;
                   6683:   float: none;
                   6684: }
                   6685: 
                   6686: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
                   6687:   background-color: $data_table_dark;
1.807     droeschl 6688: }
                   6689: 
1.847     tempelho 6690: ul.LC_TabContent {
1.911     bisitz   6691:   display:block;
                   6692:   background: $sidebg;
                   6693:   border-bottom: solid 1px $lg_border_color;
                   6694:   list-style:none;
1.1020    raeburn  6695:   margin: -1px -10px 0 -10px;
1.911     bisitz   6696:   padding: 0;
1.693     droeschl 6697: }
                   6698: 
1.795     www      6699: ul.LC_TabContent li,
                   6700: ul.LC_TabContentBigger li {
1.911     bisitz   6701:   float:left;
1.741     harmsja  6702: }
1.795     www      6703: 
1.897     wenzelju 6704: ul#LC_secondary_menu li a {
1.911     bisitz   6705:   color: $fontmenu;
                   6706:   text-decoration: none;
1.693     droeschl 6707: }
1.795     www      6708: 
1.721     harmsja  6709: ul.LC_TabContent {
1.952     onken    6710:   min-height:20px;
1.721     harmsja  6711: }
1.795     www      6712: 
                   6713: ul.LC_TabContent li {
1.911     bisitz   6714:   vertical-align:middle;
1.959     onken    6715:   padding: 0 16px 0 10px;
1.911     bisitz   6716:   background-color:$tabbg;
                   6717:   border-bottom:solid 1px $lg_border_color;
1.1020    raeburn  6718:   border-left: solid 1px $font;
1.721     harmsja  6719: }
1.795     www      6720: 
1.847     tempelho 6721: ul.LC_TabContent .right {
1.911     bisitz   6722:   float:right;
1.847     tempelho 6723: }
                   6724: 
1.911     bisitz   6725: ul.LC_TabContent li a,
                   6726: ul.LC_TabContent li {
                   6727:   color:rgb(47,47,47);
                   6728:   text-decoration:none;
                   6729:   font-size:95%;
                   6730:   font-weight:bold;
1.952     onken    6731:   min-height:20px;
                   6732: }
                   6733: 
1.959     onken    6734: ul.LC_TabContent li a:hover,
                   6735: ul.LC_TabContent li a:focus {
1.952     onken    6736:   color: $button_hover;
1.959     onken    6737:   background:none;
                   6738:   outline:none;
1.952     onken    6739: }
                   6740: 
                   6741: ul.LC_TabContent li:hover {
                   6742:   color: $button_hover;
                   6743:   cursor:pointer;
1.721     harmsja  6744: }
1.795     www      6745: 
1.911     bisitz   6746: ul.LC_TabContent li.active {
1.952     onken    6747:   color: $font;
1.911     bisitz   6748:   background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952     onken    6749:   border-bottom:solid 1px #FFFFFF;
                   6750:   cursor: default;
1.744     ehlerst  6751: }
1.795     www      6752: 
1.959     onken    6753: ul.LC_TabContent li.active a {
                   6754:   color:$font;
                   6755:   background:#FFFFFF;
                   6756:   outline: none;
                   6757: }
1.1047    raeburn  6758: 
                   6759: ul.LC_TabContent li.goback {
                   6760:   float: left;
                   6761:   border-left: none;
                   6762: }
                   6763: 
1.870     tempelho 6764: #maincoursedoc {
1.911     bisitz   6765:   clear:both;
1.870     tempelho 6766: }
                   6767: 
                   6768: ul.LC_TabContentBigger {
1.911     bisitz   6769:   display:block;
                   6770:   list-style:none;
                   6771:   padding: 0;
1.870     tempelho 6772: }
                   6773: 
1.795     www      6774: ul.LC_TabContentBigger li {
1.911     bisitz   6775:   vertical-align:bottom;
                   6776:   height: 30px;
                   6777:   font-size:110%;
                   6778:   font-weight:bold;
                   6779:   color: #737373;
1.841     tempelho 6780: }
                   6781: 
1.957     onken    6782: ul.LC_TabContentBigger li.active {
                   6783:   position: relative;
                   6784:   top: 1px;
                   6785: }
                   6786: 
1.870     tempelho 6787: ul.LC_TabContentBigger li a {
1.911     bisitz   6788:   background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
                   6789:   height: 30px;
                   6790:   line-height: 30px;
                   6791:   text-align: center;
                   6792:   display: block;
                   6793:   text-decoration: none;
1.958     onken    6794:   outline: none;  
1.741     harmsja  6795: }
1.795     www      6796: 
1.870     tempelho 6797: ul.LC_TabContentBigger li.active a {
1.911     bisitz   6798:   background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
                   6799:   color:$font;
1.744     ehlerst  6800: }
1.795     www      6801: 
1.870     tempelho 6802: ul.LC_TabContentBigger li b {
1.911     bisitz   6803:   background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
                   6804:   display: block;
                   6805:   float: left;
                   6806:   padding: 0 30px;
1.957     onken    6807:   border-bottom: 1px solid $lg_border_color;
1.870     tempelho 6808: }
                   6809: 
1.956     onken    6810: ul.LC_TabContentBigger li:hover b {
                   6811:   color:$button_hover;
                   6812: }
                   6813: 
1.870     tempelho 6814: ul.LC_TabContentBigger li.active b {
1.911     bisitz   6815:   background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
                   6816:   color:$font;
1.957     onken    6817:   border: 0;
1.741     harmsja  6818: }
1.693     droeschl 6819: 
1.870     tempelho 6820: 
1.862     bisitz   6821: ul.LC_CourseBreadcrumbs {
                   6822:   background: $sidebg;
1.1020    raeburn  6823:   height: 2em;
1.862     bisitz   6824:   padding-left: 10px;
1.1020    raeburn  6825:   margin: 0;
1.862     bisitz   6826:   list-style-position: inside;
                   6827: }
                   6828: 
1.911     bisitz   6829: ol#LC_MenuBreadcrumbs,
1.862     bisitz   6830: ol#LC_PathBreadcrumbs {
1.911     bisitz   6831:   padding-left: 10px;
                   6832:   margin: 0;
1.933     droeschl 6833:   height: 2.5em;  /* equal to #LC_breadcrumbs line-height */
1.693     droeschl 6834: }
                   6835: 
1.911     bisitz   6836: ol#LC_MenuBreadcrumbs li,
                   6837: ol#LC_PathBreadcrumbs li,
1.862     bisitz   6838: ul.LC_CourseBreadcrumbs li {
1.911     bisitz   6839:   display: inline;
1.933     droeschl 6840:   white-space: normal;  
1.693     droeschl 6841: }
                   6842: 
1.823     bisitz   6843: ol#LC_MenuBreadcrumbs li a,
1.862     bisitz   6844: ul.LC_CourseBreadcrumbs li a {
1.911     bisitz   6845:   text-decoration: none;
                   6846:   font-size:90%;
1.693     droeschl 6847: }
1.795     www      6848: 
1.969     droeschl 6849: ol#LC_MenuBreadcrumbs h1 {
                   6850:   display: inline;
                   6851:   font-size: 90%;
                   6852:   line-height: 2.5em;
                   6853:   margin: 0;
                   6854:   padding: 0;
                   6855: }
                   6856: 
1.795     www      6857: ol#LC_PathBreadcrumbs li a {
1.911     bisitz   6858:   text-decoration:none;
                   6859:   font-size:100%;
                   6860:   font-weight:bold;
1.693     droeschl 6861: }
1.795     www      6862: 
1.840     bisitz   6863: .LC_Box {
1.911     bisitz   6864:   border: solid 1px $lg_border_color;
                   6865:   padding: 0 10px 10px 10px;
1.746     neumanie 6866: }
1.795     www      6867: 
1.1020    raeburn  6868: .LC_DocsBox {
                   6869:   border: solid 1px $lg_border_color;
                   6870:   padding: 0 0 10px 10px;
                   6871: }
                   6872: 
1.795     www      6873: .LC_AboutMe_Image {
1.911     bisitz   6874:   float:left;
                   6875:   margin-right:10px;
1.747     neumanie 6876: }
1.795     www      6877: 
                   6878: .LC_Clear_AboutMe_Image {
1.911     bisitz   6879:   clear:left;
1.747     neumanie 6880: }
1.795     www      6881: 
1.721     harmsja  6882: dl.LC_ListStyleClean dt {
1.911     bisitz   6883:   padding-right: 5px;
                   6884:   display: table-header-group;
1.693     droeschl 6885: }
                   6886: 
1.721     harmsja  6887: dl.LC_ListStyleClean dd {
1.911     bisitz   6888:   display: table-row;
1.693     droeschl 6889: }
                   6890: 
1.721     harmsja  6891: .LC_ListStyleClean,
                   6892: .LC_ListStyleSimple,
                   6893: .LC_ListStyleNormal,
1.795     www      6894: .LC_ListStyleSpecial {
1.911     bisitz   6895:   /* display:block; */
                   6896:   list-style-position: inside;
                   6897:   list-style-type: none;
                   6898:   overflow: hidden;
                   6899:   padding: 0;
1.693     droeschl 6900: }
                   6901: 
1.721     harmsja  6902: .LC_ListStyleSimple li,
                   6903: .LC_ListStyleSimple dd,
                   6904: .LC_ListStyleNormal li,
                   6905: .LC_ListStyleNormal dd,
                   6906: .LC_ListStyleSpecial li,
1.795     www      6907: .LC_ListStyleSpecial dd {
1.911     bisitz   6908:   margin: 0;
                   6909:   padding: 5px 5px 5px 10px;
                   6910:   clear: both;
1.693     droeschl 6911: }
                   6912: 
1.721     harmsja  6913: .LC_ListStyleClean li,
                   6914: .LC_ListStyleClean dd {
1.911     bisitz   6915:   padding-top: 0;
                   6916:   padding-bottom: 0;
1.693     droeschl 6917: }
                   6918: 
1.721     harmsja  6919: .LC_ListStyleSimple dd,
1.795     www      6920: .LC_ListStyleSimple li {
1.911     bisitz   6921:   border-bottom: solid 1px $lg_border_color;
1.693     droeschl 6922: }
                   6923: 
1.721     harmsja  6924: .LC_ListStyleSpecial li,
                   6925: .LC_ListStyleSpecial dd {
1.911     bisitz   6926:   list-style-type: none;
                   6927:   background-color: RGB(220, 220, 220);
                   6928:   margin-bottom: 4px;
1.693     droeschl 6929: }
                   6930: 
1.721     harmsja  6931: table.LC_SimpleTable {
1.911     bisitz   6932:   margin:5px;
                   6933:   border:solid 1px $lg_border_color;
1.795     www      6934: }
1.693     droeschl 6935: 
1.721     harmsja  6936: table.LC_SimpleTable tr {
1.911     bisitz   6937:   padding: 0;
                   6938:   border:solid 1px $lg_border_color;
1.693     droeschl 6939: }
1.795     www      6940: 
                   6941: table.LC_SimpleTable thead {
1.911     bisitz   6942:   background:rgb(220,220,220);
1.693     droeschl 6943: }
                   6944: 
1.721     harmsja  6945: div.LC_columnSection {
1.911     bisitz   6946:   display: block;
                   6947:   clear: both;
                   6948:   overflow: hidden;
                   6949:   margin: 0;
1.693     droeschl 6950: }
                   6951: 
1.721     harmsja  6952: div.LC_columnSection>* {
1.911     bisitz   6953:   float: left;
                   6954:   margin: 10px 20px 10px 0;
                   6955:   overflow:hidden;
1.693     droeschl 6956: }
1.721     harmsja  6957: 
1.795     www      6958: table em {
1.911     bisitz   6959:   font-weight: bold;
                   6960:   font-style: normal;
1.748     schulted 6961: }
1.795     www      6962: 
1.779     bisitz   6963: table.LC_tableBrowseRes,
1.795     www      6964: table.LC_tableOfContent {
1.911     bisitz   6965:   border:none;
                   6966:   border-spacing: 1px;
                   6967:   padding: 3px;
                   6968:   background-color: #FFFFFF;
                   6969:   font-size: 90%;
1.753     droeschl 6970: }
1.789     droeschl 6971: 
1.911     bisitz   6972: table.LC_tableOfContent {
                   6973:   border-collapse: collapse;
1.789     droeschl 6974: }
                   6975: 
1.771     droeschl 6976: table.LC_tableBrowseRes a,
1.768     schulted 6977: table.LC_tableOfContent a {
1.911     bisitz   6978:   background-color: transparent;
                   6979:   text-decoration: none;
1.753     droeschl 6980: }
                   6981: 
1.795     www      6982: table.LC_tableOfContent img {
1.911     bisitz   6983:   border: none;
                   6984:   height: 1.3em;
                   6985:   vertical-align: text-bottom;
                   6986:   margin-right: 0.3em;
1.753     droeschl 6987: }
1.757     schulted 6988: 
1.795     www      6989: a#LC_content_toolbar_firsthomework {
1.911     bisitz   6990:   background-image:url(/res/adm/pages/open-first-problem.gif);
1.774     ehlerst  6991: }
                   6992: 
1.795     www      6993: a#LC_content_toolbar_everything {
1.911     bisitz   6994:   background-image:url(/res/adm/pages/show-all.gif);
1.774     ehlerst  6995: }
                   6996: 
1.795     www      6997: a#LC_content_toolbar_uncompleted {
1.911     bisitz   6998:   background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774     ehlerst  6999: }
                   7000: 
1.795     www      7001: #LC_content_toolbar_clearbubbles {
1.911     bisitz   7002:   background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774     ehlerst  7003: }
                   7004: 
1.795     www      7005: a#LC_content_toolbar_changefolder {
1.911     bisitz   7006:   background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757     schulted 7007: }
                   7008: 
1.795     www      7009: a#LC_content_toolbar_changefolder_toggled {
1.911     bisitz   7010:   background-image:url(/res/adm/pages/open-all-folders.gif);
1.757     schulted 7011: }
                   7012: 
1.1043    raeburn  7013: a#LC_content_toolbar_edittoplevel {
                   7014:   background-image:url(/res/adm/pages/edittoplevel.gif);
                   7015: }
                   7016: 
1.795     www      7017: ul#LC_toolbar li a:hover {
1.911     bisitz   7018:   background-position: bottom center;
1.757     schulted 7019: }
                   7020: 
1.795     www      7021: ul#LC_toolbar {
1.911     bisitz   7022:   padding: 0;
                   7023:   margin: 2px;
                   7024:   list-style:none;
                   7025:   position:relative;
                   7026:   background-color:white;
1.1075.2.9  raeburn  7027:   overflow: auto;
1.757     schulted 7028: }
                   7029: 
1.795     www      7030: ul#LC_toolbar li {
1.911     bisitz   7031:   border:1px solid white;
                   7032:   padding: 0;
                   7033:   margin: 0;
                   7034:   float: left;
                   7035:   display:inline;
                   7036:   vertical-align:middle;
1.1075.2.9  raeburn  7037:   white-space: nowrap;
1.911     bisitz   7038: }
1.757     schulted 7039: 
1.783     amueller 7040: 
1.795     www      7041: a.LC_toolbarItem {
1.911     bisitz   7042:   display:block;
                   7043:   padding: 0;
                   7044:   margin: 0;
                   7045:   height: 32px;
                   7046:   width: 32px;
                   7047:   color:white;
                   7048:   border: none;
                   7049:   background-repeat:no-repeat;
                   7050:   background-color:transparent;
1.757     schulted 7051: }
                   7052: 
1.915     droeschl 7053: ul.LC_funclist {
                   7054:     margin: 0;
                   7055:     padding: 0.5em 1em 0.5em 0;
                   7056: }
                   7057: 
1.933     droeschl 7058: ul.LC_funclist > li:first-child {
                   7059:     font-weight:bold; 
                   7060:     margin-left:0.8em;
                   7061: }
                   7062: 
1.915     droeschl 7063: ul.LC_funclist + ul.LC_funclist {
                   7064:     /* 
                   7065:        left border as a seperator if we have more than
                   7066:        one list 
                   7067:     */
                   7068:     border-left: 1px solid $sidebg;
                   7069:     /* 
                   7070:        this hides the left border behind the border of the 
                   7071:        outer box if element is wrapped to the next 'line' 
                   7072:     */
                   7073:     margin-left: -1px;
                   7074: }
                   7075: 
1.843     bisitz   7076: ul.LC_funclist li {
1.915     droeschl 7077:   display: inline;
1.782     bisitz   7078:   white-space: nowrap;
1.915     droeschl 7079:   margin: 0 0 0 25px;
                   7080:   line-height: 150%;
1.782     bisitz   7081: }
                   7082: 
1.974     wenzelju 7083: .LC_hidden {
                   7084:   display: none;
                   7085: }
                   7086: 
1.1030    www      7087: .LCmodal-overlay {
                   7088: 		position:fixed;
                   7089: 		top:0;
                   7090: 		right:0;
                   7091: 		bottom:0;
                   7092: 		left:0;
                   7093: 		height:100%;
                   7094: 		width:100%;
                   7095: 		margin:0;
                   7096: 		padding:0;
                   7097: 		background:#999;
                   7098: 		opacity:.75;
                   7099: 		filter: alpha(opacity=75);
                   7100: 		-moz-opacity: 0.75;
                   7101: 		z-index:101;
                   7102: }
                   7103: 
                   7104: * html .LCmodal-overlay {   
                   7105: 		position: absolute;
                   7106: 		height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
                   7107: }
                   7108: 
                   7109: .LCmodal-window {
                   7110: 		position:fixed;
                   7111: 		top:50%;
                   7112: 		left:50%;
                   7113: 		margin:0;
                   7114: 		padding:0;
                   7115: 		z-index:102;
                   7116: 	}
                   7117: 
                   7118: * html .LCmodal-window {
                   7119: 		position:absolute;
                   7120: }
                   7121: 
                   7122: .LCclose-window {
                   7123: 		position:absolute;
                   7124: 		width:32px;
                   7125: 		height:32px;
                   7126: 		right:8px;
                   7127: 		top:8px;
                   7128: 		background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
                   7129: 		text-indent:-99999px;
                   7130: 		overflow:hidden;
                   7131: 		cursor:pointer;
                   7132: }
                   7133: 
1.1075.2.17  raeburn  7134: /*
                   7135:   styles used by TTH when "Default set of options to pass to tth/m
                   7136:   when converting TeX" in course settings has been set
                   7137: 
                   7138:   option passed: -t
                   7139: 
                   7140: */
                   7141: 
                   7142: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
                   7143: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
                   7144: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
                   7145: td div.norm {line-height:normal;}
                   7146: 
                   7147: /*
                   7148:   option passed -y3
                   7149: */
                   7150: 
                   7151: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
                   7152: span.overacc2 {position: relative;  left: .8em; top: -1.2ex;}
                   7153: span.overacc1 {position: relative;  left: .6em; top: -1.2ex;}
                   7154: 
1.343     albertel 7155: END
                   7156: }
                   7157: 
1.306     albertel 7158: =pod
                   7159: 
                   7160: =item * &headtag()
                   7161: 
                   7162: Returns a uniform footer for LON-CAPA web pages.
                   7163: 
1.307     albertel 7164: Inputs: $title - optional title for the head
                   7165:         $head_extra - optional extra HTML to put inside the <head>
1.315     albertel 7166:         $args - optional arguments
1.319     albertel 7167:             force_register - if is true call registerurl so the remote is 
                   7168:                              informed
1.415     albertel 7169:             redirect       -> array ref of
                   7170:                                    1- seconds before redirect occurs
                   7171:                                    2- url to redirect to
                   7172:                                    3- whether the side effect should occur
1.315     albertel 7173:                            (side effect of setting 
                   7174:                                $env{'internal.head.redirect'} to the url 
                   7175:                                redirected too)
1.352     albertel 7176:             domain         -> force to color decorate a page for a specific
                   7177:                                domain
                   7178:             function       -> force usage of a specific rolish color scheme
                   7179:             bgcolor        -> override the default page bgcolor
1.460     albertel 7180:             no_auto_mt_title
                   7181:                            -> prevent &mt()ing the title arg
1.464     albertel 7182: 
1.306     albertel 7183: =cut
                   7184: 
                   7185: sub headtag {
1.313     albertel 7186:     my ($title,$head_extra,$args) = @_;
1.306     albertel 7187:     
1.363     albertel 7188:     my $function = $args->{'function'} || &get_users_function();
                   7189:     my $domain   = $args->{'domain'}   || &determinedomain();
                   7190:     my $bgcolor  = $args->{'bgcolor'}  || &designparm($function.'.pgbg',$domain);
1.418     albertel 7191:     my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458     albertel 7192: 		   $Apache::lonnet::perlvar{'lonVersion'},
1.531     albertel 7193: 		   #time(),
1.418     albertel 7194: 		   $env{'environment.color.timestamp'},
1.363     albertel 7195: 		   $function,$domain,$bgcolor);
                   7196: 
1.369     www      7197:     $url = '/adm/css/'.&escape($url).'.css';
1.363     albertel 7198: 
1.308     albertel 7199:     my $result =
                   7200: 	'<head>'.
1.461     albertel 7201: 	&font_settings();
1.319     albertel 7202: 
1.1064    raeburn  7203:     my $inhibitprint = &print_suppression();
                   7204: 
1.461     albertel 7205:     if (!$args->{'frameset'}) {
                   7206: 	$result .= &Apache::lonhtmlcommon::htmlareaheaders();
                   7207:     }
1.1075.2.12  raeburn  7208:     if ($args->{'force_register'}) {
                   7209:         $result .= &Apache::lonmenu::registerurl(1);
1.319     albertel 7210:     }
1.436     albertel 7211:     if (!$args->{'no_nav_bar'} 
                   7212: 	&& !$args->{'only_body'}
                   7213: 	&& !$args->{'frameset'}) {
                   7214: 	$result .= &help_menu_js();
1.1032    www      7215:         $result.=&modal_window();
1.1038    www      7216:         $result.=&togglebox_script();
1.1034    www      7217:         $result.=&wishlist_window();
1.1041    www      7218:         $result.=&LCprogressbarUpdate_script();
1.1034    www      7219:     } else {
                   7220:         if ($args->{'add_modal'}) {
                   7221:            $result.=&modal_window();
                   7222:         }
                   7223:         if ($args->{'add_wishlist'}) {
                   7224:            $result.=&wishlist_window();
                   7225:         }
1.1038    www      7226:         if ($args->{'add_togglebox'}) {
                   7227:            $result.=&togglebox_script();
                   7228:         }
1.1041    www      7229:         if ($args->{'add_progressbar'}) {
                   7230:            $result.=&LCprogressbarUpdate_script();
                   7231:         }
1.436     albertel 7232:     }
1.314     albertel 7233:     if (ref($args->{'redirect'})) {
1.414     albertel 7234: 	my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315     albertel 7235: 	$url = &Apache::lonenc::check_encrypt($url);
1.414     albertel 7236: 	if (!$inhibit_continue) {
                   7237: 	    $env{'internal.head.redirect'} = $url;
                   7238: 	}
1.313     albertel 7239: 	$result.=<<ADDMETA
                   7240: <meta http-equiv="pragma" content="no-cache" />
1.344     albertel 7241: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313     albertel 7242: ADDMETA
                   7243:     }
1.306     albertel 7244:     if (!defined($title)) {
                   7245: 	$title = 'The LearningOnline Network with CAPA';
                   7246:     }
1.460     albertel 7247:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
                   7248:     $result .= '<title> LON-CAPA '.$title.'</title>'
1.414     albertel 7249: 	.'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
1.1064    raeburn  7250:         .$inhibitprint
1.414     albertel 7251: 	.$head_extra;
1.962     droeschl 7252:     return $result.'</head>';
1.306     albertel 7253: }
                   7254: 
                   7255: =pod
                   7256: 
1.340     albertel 7257: =item * &font_settings()
                   7258: 
                   7259: Returns neccessary <meta> to set the proper encoding
                   7260: 
                   7261: Inputs: none
                   7262: 
                   7263: =cut
                   7264: 
                   7265: sub font_settings {
                   7266:     my $headerstring='';
1.647     www      7267:     if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340     albertel 7268: 	$headerstring.=
                   7269: 	    '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
                   7270:     }
                   7271:     return $headerstring;
                   7272: }
                   7273: 
1.341     albertel 7274: =pod
                   7275: 
1.1064    raeburn  7276: =item * &print_suppression()
                   7277: 
                   7278: In course context returns css which causes the body to be blank when media="print",
                   7279: if printout generation is unavailable for the current resource.
                   7280: 
                   7281: This could be because:
                   7282: 
                   7283: (a) printstartdate is in the future
                   7284: 
                   7285: (b) printenddate is in the past
                   7286: 
                   7287: (c) there is an active exam block with "printout"
                   7288: functionality blocked
                   7289: 
                   7290: Users with pav, pfo or evb privileges are exempt.
                   7291: 
                   7292: Inputs: none
                   7293: 
                   7294: =cut
                   7295: 
                   7296: 
                   7297: sub print_suppression {
                   7298:     my $noprint;
                   7299:     if ($env{'request.course.id'}) {
                   7300:         my $scope = $env{'request.course.id'};
                   7301:         if ((&Apache::lonnet::allowed('pav',$scope)) ||
                   7302:             (&Apache::lonnet::allowed('pfo',$scope))) {
                   7303:             return;
                   7304:         }
                   7305:         if ($env{'request.course.sec'} ne '') {
                   7306:             $scope .= "/$env{'request.course.sec'}";
                   7307:             if ((&Apache::lonnet::allowed('pav',$scope)) ||
                   7308:                 (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065    raeburn  7309:                 return;
1.1064    raeburn  7310:             }
                   7311:         }
                   7312:         my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   7313:         my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1065    raeburn  7314:         my $blocked = &blocking_status('printout',$cnum,$cdom);
1.1064    raeburn  7315:         if ($blocked) {
                   7316:             my $checkrole = "cm./$cdom/$cnum";
                   7317:             if ($env{'request.course.sec'} ne '') {
                   7318:                 $checkrole .= "/$env{'request.course.sec'}";
                   7319:             }
                   7320:             unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
                   7321:                     ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
                   7322:                 $noprint = 1;
                   7323:             }
                   7324:         }
                   7325:         unless ($noprint) {
                   7326:             my $symb = &Apache::lonnet::symbread();
                   7327:             if ($symb ne '') {
                   7328:                 my $navmap = Apache::lonnavmaps::navmap->new();
                   7329:                 if (ref($navmap)) {
                   7330:                     my $res = $navmap->getBySymb($symb);
                   7331:                     if (ref($res)) {
                   7332:                         if (!$res->resprintable()) {
                   7333:                             $noprint = 1;
                   7334:                         }
                   7335:                     }
                   7336:                 }
                   7337:             }
                   7338:         }
                   7339:         if ($noprint) {
                   7340:             return <<"ENDSTYLE";
                   7341: <style type="text/css" media="print">
                   7342:     body { display:none }
                   7343: </style>
                   7344: ENDSTYLE
                   7345:         }
                   7346:     }
                   7347:     return;
                   7348: }
                   7349: 
                   7350: =pod
                   7351: 
1.341     albertel 7352: =item * &xml_begin()
                   7353: 
                   7354: Returns the needed doctype and <html>
                   7355: 
                   7356: Inputs: none
                   7357: 
                   7358: =cut
                   7359: 
                   7360: sub xml_begin {
                   7361:     my $output='';
                   7362: 
                   7363:     if ($env{'browser.mathml'}) {
                   7364: 	$output='<?xml version="1.0"?>'
                   7365:             #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
                   7366: #            .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
                   7367:             
                   7368: #	    .'<!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">] >'
                   7369: 	    .'<!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">'
                   7370:             .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" ' 
                   7371: 	    .'xmlns="http://www.w3.org/1999/xhtml">';
                   7372:     } else {
1.849     bisitz   7373: 	$output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
                   7374:            .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341     albertel 7375:     }
                   7376:     return $output;
                   7377: }
1.340     albertel 7378: 
                   7379: =pod
                   7380: 
1.306     albertel 7381: =item * &start_page()
                   7382: 
                   7383: Returns a complete <html> .. <body> section for LON-CAPA web pages.
                   7384: 
1.648     raeburn  7385: Inputs:
                   7386: 
                   7387: =over 4
                   7388: 
                   7389: $title - optional title for the page
                   7390: 
                   7391: $head_extra - optional extra HTML to incude inside the <head>
                   7392: 
                   7393: $args - additional optional args supported are:
                   7394: 
                   7395: =over 8
                   7396: 
                   7397:              only_body      -> is true will set &bodytag() onlybodytag
1.317     albertel 7398:                                     arg on
1.814     bisitz   7399:              no_nav_bar     -> is true will set &bodytag() no_nav_bar arg on
1.648     raeburn  7400:              add_entries    -> additional attributes to add to the  <body>
                   7401:              domain         -> force to color decorate a page for a 
1.317     albertel 7402:                                     specific domain
1.648     raeburn  7403:              function       -> force usage of a specific rolish color
1.317     albertel 7404:                                     scheme
1.648     raeburn  7405:              redirect       -> see &headtag()
                   7406:              bgcolor        -> override the default page bg color
                   7407:              js_ready       -> return a string ready for being used in 
1.317     albertel 7408:                                     a javascript writeln
1.648     raeburn  7409:              html_encode    -> return a string ready for being used in 
1.320     albertel 7410:                                     a html attribute
1.648     raeburn  7411:              force_register -> if is true will turn on the &bodytag()
1.317     albertel 7412:                                     $forcereg arg
1.648     raeburn  7413:              frameset       -> if true will start with a <frameset>
1.330     albertel 7414:                                     rather than <body>
1.648     raeburn  7415:              skip_phases    -> hash ref of 
1.338     albertel 7416:                                     head -> skip the <html><head> generation
                   7417:                                     body -> skip all <body> generation
1.1075.2.12  raeburn  7418:              no_inline_link -> if true and in remote mode, don't show the
                   7419:                                     'Switch To Inline Menu' link
1.648     raeburn  7420:              no_auto_mt_title -> prevent &mt()ing the title arg
                   7421:              inherit_jsmath -> when creating popup window in a page,
                   7422:                                     should it have jsmath forced on by the
                   7423:                                     current page
1.867     kalberla 7424:              bread_crumbs ->             Array containing breadcrumbs
1.983     raeburn  7425:              bread_crumbs_component ->  if exists show it as headline else show only the breadcrumbs
1.1075.2.15  raeburn  7426:              group          -> includes the current group, if page is for a
                   7427:                                specific group
1.361     albertel 7428: 
1.648     raeburn  7429: =back
1.460     albertel 7430: 
1.648     raeburn  7431: =back
1.562     albertel 7432: 
1.306     albertel 7433: =cut
                   7434: 
                   7435: sub start_page {
1.309     albertel 7436:     my ($title,$head_extra,$args) = @_;
1.318     albertel 7437:     #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319     albertel 7438: 
1.315     albertel 7439:     $env{'internal.start_page'}++;
1.1075.2.15  raeburn  7440:     my ($result,@advtools);
1.964     droeschl 7441: 
1.338     albertel 7442:     if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1030    www      7443:         $result .= &xml_begin() . &headtag($title, $head_extra, $args);
1.338     albertel 7444:     }
                   7445:     
                   7446:     if (! exists($args->{'skip_phases'}{'body'}) ) {
                   7447: 	if ($args->{'frameset'}) {
                   7448: 	    my $attr_string = &make_attr_string($args->{'force_register'},
                   7449: 						$args->{'add_entries'});
                   7450: 	    $result .= "\n<frameset $attr_string>\n";
1.831     bisitz   7451:         } else {
                   7452:             $result .=
                   7453:                 &bodytag($title, 
                   7454:                          $args->{'function'},       $args->{'add_entries'},
                   7455:                          $args->{'only_body'},      $args->{'domain'},
                   7456:                          $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12  raeburn  7457:                          $args->{'bgcolor'},        $args->{'no_inline_link'},
1.1075.2.15  raeburn  7458:                          $args,                     \@advtools);
1.831     bisitz   7459:         }
1.330     albertel 7460:     }
1.338     albertel 7461: 
1.315     albertel 7462:     if ($args->{'js_ready'}) {
1.713     kaisler  7463: 		$result = &js_ready($result);
1.315     albertel 7464:     }
1.320     albertel 7465:     if ($args->{'html_encode'}) {
1.713     kaisler  7466: 		$result = &html_encode($result);
                   7467:     }
                   7468: 
1.813     bisitz   7469:     # Preparation for new and consistent functionlist at top of screen
                   7470:     # if ($args->{'functionlist'}) {
                   7471:     #            $result .= &build_functionlist();
                   7472:     #}
                   7473: 
1.964     droeschl 7474:     # Don't add anything more if only_body wanted or in const space
                   7475:     return $result if    $args->{'only_body'} 
                   7476:                       || $env{'request.state'} eq 'construct';
1.813     bisitz   7477: 
                   7478:     #Breadcrumbs
1.758     kaisler  7479:     if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
                   7480: 		&Apache::lonhtmlcommon::clear_breadcrumbs();
                   7481: 		#if any br links exists, add them to the breadcrumbs
                   7482: 		if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {         
                   7483: 			foreach my $crumb (@{$args->{'bread_crumbs'}}){
                   7484: 				&Apache::lonhtmlcommon::add_breadcrumb($crumb);
                   7485: 			}
                   7486: 		}
1.1075.2.19  raeburn  7487:                 # if @advtools array contains items add then to the breadcrumbs
                   7488:                 if (@advtools > 0) {
                   7489:                     &Apache::lonmenu::advtools_crumbs(@advtools);
                   7490:                 }
1.758     kaisler  7491: 
                   7492: 		#if bread_crumbs_component exists show it as headline else show only the breadcrumbs
                   7493: 		if(exists($args->{'bread_crumbs_component'})){
                   7494: 			$result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
                   7495: 		}else{
                   7496: 			$result .= &Apache::lonhtmlcommon::breadcrumbs();
                   7497: 		}
1.1075.2.24  raeburn  7498:     } elsif (($env{'environment.remote'} eq 'on') &&
                   7499:              ($env{'form.inhibitmenu'} ne 'yes') &&
                   7500:              ($env{'request.noversionuri'} =~ m{^/res/}) &&
                   7501:              ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21  raeburn  7502:         $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320     albertel 7503:     }
1.315     albertel 7504:     return $result;
1.306     albertel 7505: }
                   7506: 
                   7507: sub end_page {
1.315     albertel 7508:     my ($args) = @_;
                   7509:     $env{'internal.end_page'}++;
1.330     albertel 7510:     my $result;
1.335     albertel 7511:     if ($args->{'discussion'}) {
                   7512: 	my ($target,$parser);
                   7513: 	if (ref($args->{'discussion'})) {
                   7514: 	    ($target,$parser) =($args->{'discussion'}{'target'},
                   7515: 				$args->{'discussion'}{'parser'});
                   7516: 	}
                   7517: 	$result .= &Apache::lonxml::xmlend($target,$parser);
                   7518:     }
1.330     albertel 7519:     if ($args->{'frameset'}) {
                   7520: 	$result .= '</frameset>';
                   7521:     } else {
1.635     raeburn  7522: 	$result .= &endbodytag($args);
1.330     albertel 7523:     }
1.1075.2.6  raeburn  7524:     unless ($args->{'notbody'}) {
                   7525:         $result .= "\n</html>";
                   7526:     }
1.330     albertel 7527: 
1.315     albertel 7528:     if ($args->{'js_ready'}) {
1.317     albertel 7529: 	$result = &js_ready($result);
1.315     albertel 7530:     }
1.335     albertel 7531: 
1.320     albertel 7532:     if ($args->{'html_encode'}) {
                   7533: 	$result = &html_encode($result);
                   7534:     }
1.335     albertel 7535: 
1.315     albertel 7536:     return $result;
                   7537: }
                   7538: 
1.1034    www      7539: sub wishlist_window {
                   7540:     return(<<'ENDWISHLIST');
1.1046    raeburn  7541: <script type="text/javascript">
1.1034    www      7542: // <![CDATA[
                   7543: // <!-- BEGIN LON-CAPA Internal
                   7544: function set_wishlistlink(title, path) {
                   7545:     if (!title) {
                   7546:         title = document.title;
                   7547:         title = title.replace(/^LON-CAPA /,'');
                   7548:     }
                   7549:     if (!path) {
                   7550:         path = location.pathname;
                   7551:     }
                   7552:     Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
                   7553:                       'wishlistNewLink','width=560,height=350,scrollbars=0');
                   7554: }
                   7555: // END LON-CAPA Internal -->
                   7556: // ]]>
                   7557: </script>
                   7558: ENDWISHLIST
                   7559: }
                   7560: 
1.1030    www      7561: sub modal_window {
                   7562:     return(<<'ENDMODAL');
1.1046    raeburn  7563: <script type="text/javascript">
1.1030    www      7564: // <![CDATA[
                   7565: // <!-- BEGIN LON-CAPA Internal
                   7566: var modalWindow = {
                   7567: 	parent:"body",
                   7568: 	windowId:null,
                   7569: 	content:null,
                   7570: 	width:null,
                   7571: 	height:null,
                   7572: 	close:function()
                   7573: 	{
                   7574: 	        $(".LCmodal-window").remove();
                   7575: 	        $(".LCmodal-overlay").remove();
                   7576: 	},
                   7577: 	open:function()
                   7578: 	{
                   7579: 		var modal = "";
                   7580: 		modal += "<div class=\"LCmodal-overlay\"></div>";
                   7581: 		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;\">";
                   7582: 		modal += this.content;
                   7583: 		modal += "</div>";	
                   7584: 
                   7585: 		$(this.parent).append(modal);
                   7586: 
                   7587: 		$(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
                   7588: 		$(".LCclose-window").click(function(){modalWindow.close();});
                   7589: 		$(".LCmodal-overlay").click(function(){modalWindow.close();});
                   7590: 	}
                   7591: };
1.1031    www      7592: 	var openMyModal = function(source,width,height,scrolling)
1.1030    www      7593: 	{
                   7594: 		modalWindow.windowId = "myModal";
                   7595: 		modalWindow.width = width;
                   7596: 		modalWindow.height = height;
1.1031    www      7597: 		modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='true' src='" + source + "'>&lt/iframe>";
1.1030    www      7598: 		modalWindow.open();
                   7599: 	};	
                   7600: // END LON-CAPA Internal -->
                   7601: // ]]>
                   7602: </script>
                   7603: ENDMODAL
                   7604: }
                   7605: 
                   7606: sub modal_link {
1.1052    www      7607:     my ($link,$linktext,$width,$height,$target,$scrolling,$title)=@_;
1.1030    www      7608:     unless ($width) { $width=480; }
                   7609:     unless ($height) { $height=400; }
1.1031    www      7610:     unless ($scrolling) { $scrolling='yes'; }
1.1074    raeburn  7611:     my $target_attr;
                   7612:     if (defined($target)) {
                   7613:         $target_attr = 'target="'.$target.'"';
                   7614:     }
                   7615:     return <<"ENDLINK";
                   7616: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling'); return false;">
                   7617:            $linktext</a>
                   7618: ENDLINK
1.1030    www      7619: }
                   7620: 
1.1032    www      7621: sub modal_adhoc_script {
                   7622:     my ($funcname,$width,$height,$content)=@_;
                   7623:     return (<<ENDADHOC);
1.1046    raeburn  7624: <script type="text/javascript">
1.1032    www      7625: // <![CDATA[
                   7626:         var $funcname = function()
                   7627:         {
                   7628:                 modalWindow.windowId = "myModal";
                   7629:                 modalWindow.width = $width;
                   7630:                 modalWindow.height = $height;
                   7631:                 modalWindow.content = '$content';
                   7632:                 modalWindow.open();
                   7633:         };  
                   7634: // ]]>
                   7635: </script>
                   7636: ENDADHOC
                   7637: }
                   7638: 
1.1041    www      7639: sub modal_adhoc_inner {
                   7640:     my ($funcname,$width,$height,$content)=@_;
                   7641:     my $innerwidth=$width-20;
                   7642:     $content=&js_ready(
1.1042    www      7643:                &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1041    www      7644:                  &start_scrollbox($width.'px',$innerwidth.'px',$height.'px').
                   7645:                     $content.
                   7646:                  &end_scrollbox().
                   7647:                &end_page()
                   7648:              );
                   7649:     return &modal_adhoc_script($funcname,$width,$height,$content);
                   7650: }
                   7651: 
                   7652: sub modal_adhoc_window {
                   7653:     my ($funcname,$width,$height,$content,$linktext)=@_;
                   7654:     return &modal_adhoc_inner($funcname,$width,$height,$content).
                   7655:            "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
                   7656: }
                   7657: 
                   7658: sub modal_adhoc_launch {
                   7659:     my ($funcname,$width,$height,$content)=@_;
                   7660:     return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
                   7661: <script type="text/javascript">
                   7662: // <![CDATA[
                   7663: $funcname();
                   7664: // ]]>
                   7665: </script>
                   7666: ENDLAUNCH
                   7667: }
                   7668: 
                   7669: sub modal_adhoc_close {
                   7670:     return (<<ENDCLOSE);
                   7671: <script type="text/javascript">
                   7672: // <![CDATA[
                   7673: modalWindow.close();
                   7674: // ]]>
                   7675: </script>
                   7676: ENDCLOSE
                   7677: }
                   7678: 
1.1038    www      7679: sub togglebox_script {
                   7680:    return(<<ENDTOGGLE);
                   7681: <script type="text/javascript"> 
                   7682: // <![CDATA[
                   7683: function LCtoggleDisplay(id,hidetext,showtext) {
                   7684:    link = document.getElementById(id + "link").childNodes[0];
                   7685:    with (document.getElementById(id).style) {
                   7686:       if (display == "none" ) {
                   7687:           display = "inline";
                   7688:           link.nodeValue = hidetext;
                   7689:         } else {
                   7690:           display = "none";
                   7691:           link.nodeValue = showtext;
                   7692:        }
                   7693:    }
                   7694: }
                   7695: // ]]>
                   7696: </script>
                   7697: ENDTOGGLE
                   7698: }
                   7699: 
1.1039    www      7700: sub start_togglebox {
                   7701:     my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
                   7702:     unless ($heading) { $heading=''; } else { $heading.=' '; }
                   7703:     unless ($showtext) { $showtext=&mt('show'); }
                   7704:     unless ($hidetext) { $hidetext=&mt('hide'); }
                   7705:     unless ($headerbg) { $headerbg='#FFFFFF'; }
                   7706:     return &start_data_table().
                   7707:            &start_data_table_header_row().
                   7708:            '<td bgcolor="'.$headerbg.'">'.$heading.
                   7709:            '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
                   7710:            $showtext.'\')">'.$showtext.'</a>]</td>'.
                   7711:            &end_data_table_header_row().
                   7712:            '<tr id="'.$id.'" style="display:none""><td>';
                   7713: }
                   7714: 
                   7715: sub end_togglebox {
                   7716:     return '</td></tr>'.&end_data_table();
                   7717: }
                   7718: 
1.1041    www      7719: sub LCprogressbar_script {
1.1045    www      7720:    my ($id)=@_;
1.1041    www      7721:    return(<<ENDPROGRESS);
                   7722: <script type="text/javascript">
                   7723: // <![CDATA[
1.1045    www      7724: \$('#progressbar$id').progressbar({
1.1041    www      7725:   value: 0,
                   7726:   change: function(event, ui) {
                   7727:     var newVal = \$(this).progressbar('option', 'value');
                   7728:     \$('.pblabel', this).text(LCprogressTxt);
                   7729:   }
                   7730: });
                   7731: // ]]>
                   7732: </script>
                   7733: ENDPROGRESS
                   7734: }
                   7735: 
                   7736: sub LCprogressbarUpdate_script {
                   7737:    return(<<ENDPROGRESSUPDATE);
                   7738: <style type="text/css">
                   7739: .ui-progressbar { position:relative; }
                   7740: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
                   7741: </style>
                   7742: <script type="text/javascript">
                   7743: // <![CDATA[
1.1045    www      7744: var LCprogressTxt='---';
                   7745: 
                   7746: function LCupdateProgress(percent,progresstext,id) {
1.1041    www      7747:    LCprogressTxt=progresstext;
1.1045    www      7748:    \$('#progressbar'+id).progressbar('value',percent);
1.1041    www      7749: }
                   7750: // ]]>
                   7751: </script>
                   7752: ENDPROGRESSUPDATE
                   7753: }
                   7754: 
1.1042    www      7755: my $LClastpercent;
1.1045    www      7756: my $LCidcnt;
                   7757: my $LCcurrentid;
1.1042    www      7758: 
1.1041    www      7759: sub LCprogressbar {
1.1042    www      7760:     my ($r)=(@_);
                   7761:     $LClastpercent=0;
1.1045    www      7762:     $LCidcnt++;
                   7763:     $LCcurrentid=$$.'_'.$LCidcnt;
1.1041    www      7764:     my $starting=&mt('Starting');
                   7765:     my $content=(<<ENDPROGBAR);
                   7766: <p>
1.1045    www      7767:   <div id="progressbar$LCcurrentid">
1.1041    www      7768:     <span class="pblabel">$starting</span>
                   7769:   </div>
                   7770: </p>
                   7771: ENDPROGBAR
1.1045    www      7772:     &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041    www      7773: }
                   7774: 
                   7775: sub LCprogressbarUpdate {
1.1042    www      7776:     my ($r,$val,$text)=@_;
                   7777:     unless ($val) { 
                   7778:        if ($LClastpercent) {
                   7779:            $val=$LClastpercent;
                   7780:        } else {
                   7781:            $val=0;
                   7782:        }
                   7783:     }
1.1041    www      7784:     if ($val<0) { $val=0; }
                   7785:     if ($val>100) { $val=0; }
1.1042    www      7786:     $LClastpercent=$val;
1.1041    www      7787:     unless ($text) { $text=$val.'%'; }
                   7788:     $text=&js_ready($text);
1.1044    www      7789:     &r_print($r,<<ENDUPDATE);
1.1041    www      7790: <script type="text/javascript">
                   7791: // <![CDATA[
1.1045    www      7792: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041    www      7793: // ]]>
                   7794: </script>
                   7795: ENDUPDATE
1.1035    www      7796: }
                   7797: 
1.1042    www      7798: sub LCprogressbarClose {
                   7799:     my ($r)=@_;
                   7800:     $LClastpercent=0;
1.1044    www      7801:     &r_print($r,<<ENDCLOSE);
1.1042    www      7802: <script type="text/javascript">
                   7803: // <![CDATA[
1.1045    www      7804: \$("#progressbar$LCcurrentid").hide('slow'); 
1.1042    www      7805: // ]]>
                   7806: </script>
                   7807: ENDCLOSE
1.1044    www      7808: }
                   7809: 
                   7810: sub r_print {
                   7811:     my ($r,$to_print)=@_;
                   7812:     if ($r) {
                   7813:       $r->print($to_print);
                   7814:       $r->rflush();
                   7815:     } else {
                   7816:       print($to_print);
                   7817:     }
1.1042    www      7818: }
                   7819: 
1.320     albertel 7820: sub html_encode {
                   7821:     my ($result) = @_;
                   7822: 
1.322     albertel 7823:     $result = &HTML::Entities::encode($result,'<>&"');
1.320     albertel 7824:     
                   7825:     return $result;
                   7826: }
1.1044    www      7827: 
1.317     albertel 7828: sub js_ready {
                   7829:     my ($result) = @_;
                   7830: 
1.323     albertel 7831:     $result =~ s/[\n\r]/ /xmsg;
                   7832:     $result =~ s/\\/\\\\/xmsg;
                   7833:     $result =~ s/'/\\'/xmsg;
1.372     albertel 7834:     $result =~ s{</}{<\\/}xmsg;
1.317     albertel 7835:     
                   7836:     return $result;
                   7837: }
                   7838: 
1.315     albertel 7839: sub validate_page {
                   7840:     if (  exists($env{'internal.start_page'})
1.316     albertel 7841: 	  &&     $env{'internal.start_page'} > 1) {
                   7842: 	&Apache::lonnet::logthis('start_page called multiple times '.
1.318     albertel 7843: 				 $env{'internal.start_page'}.' '.
1.316     albertel 7844: 				 $ENV{'request.filename'});
1.315     albertel 7845:     }
                   7846:     if (  exists($env{'internal.end_page'})
1.316     albertel 7847: 	  &&     $env{'internal.end_page'} > 1) {
                   7848: 	&Apache::lonnet::logthis('end_page called multiple times '.
1.318     albertel 7849: 				 $env{'internal.end_page'}.' '.
1.316     albertel 7850: 				 $env{'request.filename'});
1.315     albertel 7851:     }
                   7852:     if (     exists($env{'internal.start_page'})
                   7853: 	&& ! exists($env{'internal.end_page'})) {
1.316     albertel 7854: 	&Apache::lonnet::logthis('start_page called without end_page '.
                   7855: 				 $env{'request.filename'});
1.315     albertel 7856:     }
                   7857:     if (   ! exists($env{'internal.start_page'})
                   7858: 	&&   exists($env{'internal.end_page'})) {
1.316     albertel 7859: 	&Apache::lonnet::logthis('end_page called without start_page'.
                   7860: 				 $env{'request.filename'});
1.315     albertel 7861:     }
1.306     albertel 7862: }
1.315     albertel 7863: 
1.996     www      7864: 
                   7865: sub start_scrollbox {
1.1075    raeburn  7866:     my ($outerwidth,$width,$height,$id,$bgcolor)=@_;
1.998     raeburn  7867:     unless ($outerwidth) { $outerwidth='520px'; }
                   7868:     unless ($width) { $width='500px'; }
                   7869:     unless ($height) { $height='200px'; }
1.1075    raeburn  7870:     my ($table_id,$div_id,$tdcol);
1.1018    raeburn  7871:     if ($id ne '') {
1.1020    raeburn  7872:         $table_id = " id='table_$id'";
                   7873:         $div_id = " id='div_$id'";
1.1018    raeburn  7874:     }
1.1075    raeburn  7875:     if ($bgcolor ne '') {
                   7876:         $tdcol = "background-color: $bgcolor;";
                   7877:     }
                   7878:     return <<"END";
                   7879: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol"><div style="overflow:auto; width:$width; height: $height;"$div_id>
                   7880: END
1.996     www      7881: }
                   7882: 
                   7883: sub end_scrollbox {
1.1036    www      7884:     return '</div></td></tr></table>';
1.996     www      7885: }
                   7886: 
1.318     albertel 7887: sub simple_error_page {
                   7888:     my ($r,$title,$msg) = @_;
                   7889:     my $page =
                   7890: 	&Apache::loncommon::start_page($title).
1.1075.2.15  raeburn  7891: 	'<p class="LC_error">'.&mt($msg).'</p>'.
1.318     albertel 7892: 	&Apache::loncommon::end_page();
                   7893:     if (ref($r)) {
                   7894: 	$r->print($page);
1.327     albertel 7895: 	return;
1.318     albertel 7896:     }
                   7897:     return $page;
                   7898: }
1.347     albertel 7899: 
                   7900: {
1.610     albertel 7901:     my @row_count;
1.961     onken    7902: 
                   7903:     sub start_data_table_count {
                   7904:         unshift(@row_count, 0);
                   7905:         return;
                   7906:     }
                   7907: 
                   7908:     sub end_data_table_count {
                   7909:         shift(@row_count);
                   7910:         return;
                   7911:     }
                   7912: 
1.347     albertel 7913:     sub start_data_table {
1.1018    raeburn  7914: 	my ($add_class,$id) = @_;
1.422     albertel 7915: 	my $css_class = (join(' ','LC_data_table',$add_class));
1.1018    raeburn  7916:         my $table_id;
                   7917:         if (defined($id)) {
                   7918:             $table_id = ' id="'.$id.'"';
                   7919:         }
1.961     onken    7920: 	&start_data_table_count();
1.1018    raeburn  7921: 	return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347     albertel 7922:     }
                   7923: 
                   7924:     sub end_data_table {
1.961     onken    7925: 	&end_data_table_count();
1.389     albertel 7926: 	return '</table>'."\n";;
1.347     albertel 7927:     }
                   7928: 
                   7929:     sub start_data_table_row {
1.974     wenzelju 7930: 	my ($add_class, $id) = @_;
1.610     albertel 7931: 	$row_count[0]++;
                   7932: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900     bisitz   7933: 	$css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974     wenzelju 7934:         $id = (' id="'.$id.'"') unless ($id eq '');
                   7935:         return  '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347     albertel 7936:     }
1.471     banghart 7937:     
                   7938:     sub continue_data_table_row {
1.974     wenzelju 7939: 	my ($add_class, $id) = @_;
1.610     albertel 7940: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974     wenzelju 7941: 	$css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
                   7942:         $id = (' id="'.$id.'"') unless ($id eq '');
                   7943:         return  '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471     banghart 7944:     }
1.347     albertel 7945: 
                   7946:     sub end_data_table_row {
1.389     albertel 7947: 	return '</tr>'."\n";;
1.347     albertel 7948:     }
1.367     www      7949: 
1.421     albertel 7950:     sub start_data_table_empty_row {
1.707     bisitz   7951: #	$row_count[0]++;
1.421     albertel 7952: 	return  '<tr class="LC_empty_row" >'."\n";;
                   7953:     }
                   7954: 
                   7955:     sub end_data_table_empty_row {
                   7956: 	return '</tr>'."\n";;
                   7957:     }
                   7958: 
1.367     www      7959:     sub start_data_table_header_row {
1.389     albertel 7960: 	return  '<tr class="LC_header_row">'."\n";;
1.367     www      7961:     }
                   7962: 
                   7963:     sub end_data_table_header_row {
1.389     albertel 7964: 	return '</tr>'."\n";;
1.367     www      7965:     }
1.890     droeschl 7966: 
                   7967:     sub data_table_caption {
                   7968:         my $caption = shift;
                   7969:         return "<caption class=\"LC_caption\">$caption</caption>";
                   7970:     }
1.347     albertel 7971: }
                   7972: 
1.548     albertel 7973: =pod
                   7974: 
                   7975: =item * &inhibit_menu_check($arg)
                   7976: 
                   7977: Checks for a inhibitmenu state and generates output to preserve it
                   7978: 
                   7979: Inputs:         $arg - can be any of
                   7980:                      - undef - in which case the return value is a string 
                   7981:                                to add  into arguments list of a uri
                   7982:                      - 'input' - in which case the return value is a HTML
                   7983:                                  <form> <input> field of type hidden to
                   7984:                                  preserve the value
                   7985:                      - a url - in which case the return value is the url with
                   7986:                                the neccesary cgi args added to preserve the
                   7987:                                inhibitmenu state
                   7988:                      - a ref to a url - no return value, but the string is
                   7989:                                         updated to include the neccessary cgi
                   7990:                                         args to preserve the inhibitmenu state
                   7991: 
                   7992: =cut
                   7993: 
                   7994: sub inhibit_menu_check {
                   7995:     my ($arg) = @_;
                   7996:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   7997:     if ($arg eq 'input') {
                   7998: 	if ($env{'form.inhibitmenu'}) {
                   7999: 	    return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
                   8000: 	} else {
                   8001: 	    return
                   8002: 	}
                   8003:     }
                   8004:     if ($env{'form.inhibitmenu'}) {
                   8005: 	if (ref($arg)) {
                   8006: 	    $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   8007: 	} elsif ($arg eq '') {
                   8008: 	    $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
                   8009: 	} else {
                   8010: 	    $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   8011: 	}
                   8012:     }
                   8013:     if (!ref($arg)) {
                   8014: 	return $arg;
                   8015:     }
                   8016: }
                   8017: 
1.251     albertel 8018: ###############################################
1.182     matthew  8019: 
                   8020: =pod
                   8021: 
1.549     albertel 8022: =back
                   8023: 
                   8024: =head1 User Information Routines
                   8025: 
                   8026: =over 4
                   8027: 
1.405     albertel 8028: =item * &get_users_function()
1.182     matthew  8029: 
                   8030: Used by &bodytag to determine the current users primary role.
                   8031: Returns either 'student','coordinator','admin', or 'author'.
                   8032: 
                   8033: =cut
                   8034: 
                   8035: ###############################################
                   8036: sub get_users_function {
1.815     tempelho 8037:     my $function = 'norole';
1.818     tempelho 8038:     if ($env{'request.role'}=~/^(st)/) {
                   8039:         $function='student';
                   8040:     }
1.907     raeburn  8041:     if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182     matthew  8042:         $function='coordinator';
                   8043:     }
1.258     albertel 8044:     if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182     matthew  8045:         $function='admin';
                   8046:     }
1.826     bisitz   8047:     if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025    raeburn  8048:         ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182     matthew  8049:         $function='author';
                   8050:     }
                   8051:     return $function;
1.54      www      8052: }
1.99      www      8053: 
                   8054: ###############################################
                   8055: 
1.233     raeburn  8056: =pod
                   8057: 
1.821     raeburn  8058: =item * &show_course()
                   8059: 
                   8060: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
                   8061: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
                   8062: 
                   8063: Inputs:
                   8064: None
                   8065: 
                   8066: Outputs:
                   8067: Scalar: 1 if 'Course' to be used, 0 otherwise.
                   8068: 
                   8069: =cut
                   8070: 
                   8071: ###############################################
                   8072: sub show_course {
                   8073:     my $course = !$env{'user.adv'};
                   8074:     if (!$env{'user.adv'}) {
                   8075:         foreach my $env (keys(%env)) {
                   8076:             next if ($env !~ m/^user\.priv\./);
                   8077:             if ($env !~ m/^user\.priv\.(?:st|cm)/) {
                   8078:                 $course = 0;
                   8079:                 last;
                   8080:             }
                   8081:         }
                   8082:     }
                   8083:     return $course;
                   8084: }
                   8085: 
                   8086: ###############################################
                   8087: 
                   8088: =pod
                   8089: 
1.542     raeburn  8090: =item * &check_user_status()
1.274     raeburn  8091: 
                   8092: Determines current status of supplied role for a
                   8093: specific user. Roles can be active, previous or future.
                   8094: 
                   8095: Inputs: 
                   8096: user's domain, user's username, course's domain,
1.375     raeburn  8097: course's number, optional section ID.
1.274     raeburn  8098: 
                   8099: Outputs:
                   8100: role status: active, previous or future. 
                   8101: 
                   8102: =cut
                   8103: 
                   8104: sub check_user_status {
1.412     raeburn  8105:     my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073    raeburn  8106:     my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.274     raeburn  8107:     my @uroles = keys %userinfo;
                   8108:     my $srchstr;
                   8109:     my $active_chk = 'none';
1.412     raeburn  8110:     my $now = time;
1.274     raeburn  8111:     if (@uroles > 0) {
1.908     raeburn  8112:         if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274     raeburn  8113:             $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
                   8114:         } else {
1.412     raeburn  8115:             $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
                   8116:         }
                   8117:         if (grep/^\Q$srchstr\E$/,@uroles) {
1.274     raeburn  8118:             my $role_end = 0;
                   8119:             my $role_start = 0;
                   8120:             $active_chk = 'active';
1.412     raeburn  8121:             if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
                   8122:                 $role_end = $1;
                   8123:                 if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
                   8124:                     $role_start = $1;
1.274     raeburn  8125:                 }
                   8126:             }
                   8127:             if ($role_start > 0) {
1.412     raeburn  8128:                 if ($now < $role_start) {
1.274     raeburn  8129:                     $active_chk = 'future';
                   8130:                 }
                   8131:             }
                   8132:             if ($role_end > 0) {
1.412     raeburn  8133:                 if ($now > $role_end) {
1.274     raeburn  8134:                     $active_chk = 'previous';
                   8135:                 }
                   8136:             }
                   8137:         }
                   8138:     }
                   8139:     return $active_chk;
                   8140: }
                   8141: 
                   8142: ###############################################
                   8143: 
                   8144: =pod
                   8145: 
1.405     albertel 8146: =item * &get_sections()
1.233     raeburn  8147: 
                   8148: Determines all the sections for a course including
                   8149: sections with students and sections containing other roles.
1.419     raeburn  8150: Incoming parameters: 
                   8151: 
                   8152: 1. domain
                   8153: 2. course number 
                   8154: 3. reference to array containing roles for which sections should 
                   8155: be gathered (optional).
                   8156: 4. reference to array containing status types for which sections 
                   8157: should be gathered (optional).
                   8158: 
                   8159: If the third argument is undefined, sections are gathered for any role. 
                   8160: If the fourth argument is undefined, sections are gathered for any status.
                   8161: Permissible values are 'active' or 'future' or 'previous'.
1.233     raeburn  8162:  
1.374     raeburn  8163: Returns section hash (keys are section IDs, values are
                   8164: number of users in each section), subject to the
1.419     raeburn  8165: optional roles filter, optional status filter 
1.233     raeburn  8166: 
                   8167: =cut
                   8168: 
                   8169: ###############################################
                   8170: sub get_sections {
1.419     raeburn  8171:     my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366     albertel 8172:     if (!defined($cdom) || !defined($cnum)) {
                   8173:         my $cid =  $env{'request.course.id'};
                   8174: 
                   8175: 	return if (!defined($cid));
                   8176: 
                   8177:         $cdom = $env{'course.'.$cid.'.domain'};
                   8178:         $cnum = $env{'course.'.$cid.'.num'};
                   8179:     }
                   8180: 
                   8181:     my %sectioncount;
1.419     raeburn  8182:     my $now = time;
1.240     albertel 8183: 
1.366     albertel 8184:     if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276     albertel 8185: 	my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240     albertel 8186: 	my $sec_index = &Apache::loncoursedata::CL_SECTION();
                   8187: 	my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419     raeburn  8188:         my $start_index = &Apache::loncoursedata::CL_START();
                   8189:         my $end_index = &Apache::loncoursedata::CL_END();
                   8190:         my $status;
1.366     albertel 8191: 	while (my ($student,$data) = each(%$classlist)) {
1.419     raeburn  8192: 	    my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
                   8193: 				                     $data->[$status_index],
                   8194:                                                      $data->[$start_index],
                   8195:                                                      $data->[$end_index]);
                   8196:             if ($stu_status eq 'Active') {
                   8197:                 $status = 'active';
                   8198:             } elsif ($end < $now) {
                   8199:                 $status = 'previous';
                   8200:             } elsif ($start > $now) {
                   8201:                 $status = 'future';
                   8202:             } 
                   8203: 	    if ($section ne '-1' && $section !~ /^\s*$/) {
                   8204:                 if ((!defined($possible_status)) || (($status ne '') && 
                   8205:                     (grep/^\Q$status\E$/,@{$possible_status}))) { 
                   8206: 		    $sectioncount{$section}++;
                   8207:                 }
1.240     albertel 8208: 	    }
                   8209: 	}
                   8210:     }
                   8211:     my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   8212:     foreach my $user (sort(keys(%courseroles))) {
                   8213: 	if ($user !~ /^(\w{2})/) { next; }
                   8214: 	my ($role) = ($user =~ /^(\w{2})/);
                   8215: 	if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419     raeburn  8216: 	my ($section,$status);
1.240     albertel 8217: 	if ($role eq 'cr' &&
                   8218: 	    $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
                   8219: 	    $section=$1;
                   8220: 	}
                   8221: 	if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
                   8222: 	if (!defined($section) || $section eq '-1') { next; }
1.419     raeburn  8223:         my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
                   8224:         if ($end == -1 && $start == -1) {
                   8225:             next; #deleted role
                   8226:         }
                   8227:         if (!defined($possible_status)) { 
                   8228:             $sectioncount{$section}++;
                   8229:         } else {
                   8230:             if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
                   8231:                 $status = 'active';
                   8232:             } elsif ($end < $now) {
                   8233:                 $status = 'future';
                   8234:             } elsif ($start > $now) {
                   8235:                 $status = 'previous';
                   8236:             }
                   8237:             if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
                   8238:                 $sectioncount{$section}++;
                   8239:             }
                   8240:         }
1.233     raeburn  8241:     }
1.366     albertel 8242:     return %sectioncount;
1.233     raeburn  8243: }
                   8244: 
1.274     raeburn  8245: ###############################################
1.294     raeburn  8246: 
                   8247: =pod
1.405     albertel 8248: 
                   8249: =item * &get_course_users()
                   8250: 
1.275     raeburn  8251: Retrieves usernames:domains for users in the specified course
                   8252: with specific role(s), and access status. 
                   8253: 
                   8254: Incoming parameters:
1.277     albertel 8255: 1. course domain
                   8256: 2. course number
                   8257: 3. access status: users must have - either active, 
1.275     raeburn  8258: previous, future, or all.
1.277     albertel 8259: 4. reference to array of permissible roles
1.288     raeburn  8260: 5. reference to array of section restrictions (optional)
                   8261: 6. reference to results object (hash of hashes).
                   8262: 7. reference to optional userdata hash
1.609     raeburn  8263: 8. reference to optional statushash
1.630     raeburn  8264: 9. flag if privileged users (except those set to unhide in
                   8265:    course settings) should be excluded    
1.609     raeburn  8266: Keys of top level results hash are roles.
1.275     raeburn  8267: Keys of inner hashes are username:domain, with 
                   8268: values set to access type.
1.288     raeburn  8269: Optional userdata hash returns an array with arguments in the 
                   8270: same order as loncoursedata::get_classlist() for student data.
                   8271: 
1.609     raeburn  8272: Optional statushash returns
                   8273: 
1.288     raeburn  8274: Entries for end, start, section and status are blank because
                   8275: of the possibility of multiple values for non-student roles.
                   8276: 
1.275     raeburn  8277: =cut
1.405     albertel 8278: 
1.275     raeburn  8279: ###############################################
1.405     albertel 8280: 
1.275     raeburn  8281: sub get_course_users {
1.630     raeburn  8282:     my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288     raeburn  8283:     my %idx = ();
1.419     raeburn  8284:     my %seclists;
1.288     raeburn  8285: 
                   8286:     $idx{udom} = &Apache::loncoursedata::CL_SDOM();
                   8287:     $idx{uname} =  &Apache::loncoursedata::CL_SNAME();
                   8288:     $idx{end} = &Apache::loncoursedata::CL_END();
                   8289:     $idx{start} = &Apache::loncoursedata::CL_START();
                   8290:     $idx{id} = &Apache::loncoursedata::CL_ID();
                   8291:     $idx{section} = &Apache::loncoursedata::CL_SECTION();
                   8292:     $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
                   8293:     $idx{status} = &Apache::loncoursedata::CL_STATUS();
                   8294: 
1.290     albertel 8295:     if (grep(/^st$/,@{$roles})) {
1.276     albertel 8296:         my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278     raeburn  8297:         my $now = time;
1.277     albertel 8298:         foreach my $student (keys(%{$classlist})) {
1.288     raeburn  8299:             my $match = 0;
1.412     raeburn  8300:             my $secmatch = 0;
1.419     raeburn  8301:             my $section = $$classlist{$student}[$idx{section}];
1.609     raeburn  8302:             my $status = $$classlist{$student}[$idx{status}];
1.419     raeburn  8303:             if ($section eq '') {
                   8304:                 $section = 'none';
                   8305:             }
1.291     albertel 8306:             if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 8307:                 if (grep(/^all$/,@{$sections})) {
1.412     raeburn  8308:                     $secmatch = 1;
                   8309:                 } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420     albertel 8310:                     if (grep(/^none$/,@{$sections})) {
1.412     raeburn  8311:                         $secmatch = 1;
                   8312:                     }
                   8313:                 } else {  
1.419     raeburn  8314: 		    if (grep(/^\Q$section\E$/,@{$sections})) {
1.412     raeburn  8315: 		        $secmatch = 1;
                   8316:                     }
1.290     albertel 8317: 		}
1.412     raeburn  8318:                 if (!$secmatch) {
                   8319:                     next;
                   8320:                 }
1.419     raeburn  8321:             }
1.275     raeburn  8322:             if (defined($$types{'active'})) {
1.288     raeburn  8323:                 if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275     raeburn  8324:                     push(@{$$users{st}{$student}},'active');
1.288     raeburn  8325:                     $match = 1;
1.275     raeburn  8326:                 }
                   8327:             }
                   8328:             if (defined($$types{'previous'})) {
1.609     raeburn  8329:                 if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275     raeburn  8330:                     push(@{$$users{st}{$student}},'previous');
1.288     raeburn  8331:                     $match = 1;
1.275     raeburn  8332:                 }
                   8333:             }
                   8334:             if (defined($$types{'future'})) {
1.609     raeburn  8335:                 if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275     raeburn  8336:                     push(@{$$users{st}{$student}},'future');
1.288     raeburn  8337:                     $match = 1;
1.275     raeburn  8338:                 }
                   8339:             }
1.609     raeburn  8340:             if ($match) {
                   8341:                 push(@{$seclists{$student}},$section);
                   8342:                 if (ref($userdata) eq 'HASH') {
                   8343:                     $$userdata{$student} = $$classlist{$student};
                   8344:                 }
                   8345:                 if (ref($statushash) eq 'HASH') {
                   8346:                     $statushash->{$student}{'st'}{$section} = $status;
                   8347:                 }
1.288     raeburn  8348:             }
1.275     raeburn  8349:         }
                   8350:     }
1.412     raeburn  8351:     if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439     raeburn  8352:         my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   8353:         my $now = time;
1.609     raeburn  8354:         my %displaystatus = ( previous => 'Expired',
                   8355:                               active   => 'Active',
                   8356:                               future   => 'Future',
                   8357:                             );
1.630     raeburn  8358:         my %nothide;
                   8359:         if ($hidepriv) {
                   8360:             my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
                   8361:             foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
                   8362:                 if ($user !~ /:/) {
                   8363:                     $nothide{join(':',split(/[\@]/,$user))}=1;
                   8364:                 } else {
                   8365:                     $nothide{$user} = 1;
                   8366:                 }
                   8367:             }
                   8368:         }
1.439     raeburn  8369:         foreach my $person (sort(keys(%coursepersonnel))) {
1.288     raeburn  8370:             my $match = 0;
1.412     raeburn  8371:             my $secmatch = 0;
1.439     raeburn  8372:             my $status;
1.412     raeburn  8373:             my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275     raeburn  8374:             $user =~ s/:$//;
1.439     raeburn  8375:             my ($end,$start) = split(/:/,$coursepersonnel{$person});
                   8376:             if ($end == -1 || $start == -1) {
                   8377:                 next;
                   8378:             }
                   8379:             if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
                   8380:                 (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412     raeburn  8381:                 my ($uname,$udom) = split(/:/,$user);
                   8382:                 if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 8383:                     if (grep(/^all$/,@{$sections})) {
1.412     raeburn  8384:                         $secmatch = 1;
                   8385:                     } elsif ($usec eq '') {
1.420     albertel 8386:                         if (grep(/^none$/,@{$sections})) {
1.412     raeburn  8387:                             $secmatch = 1;
                   8388:                         }
                   8389:                     } else {
                   8390:                         if (grep(/^\Q$usec\E$/,@{$sections})) {
                   8391:                             $secmatch = 1;
                   8392:                         }
                   8393:                     }
                   8394:                     if (!$secmatch) {
                   8395:                         next;
                   8396:                     }
1.288     raeburn  8397:                 }
1.419     raeburn  8398:                 if ($usec eq '') {
                   8399:                     $usec = 'none';
                   8400:                 }
1.275     raeburn  8401:                 if ($uname ne '' && $udom ne '') {
1.630     raeburn  8402:                     if ($hidepriv) {
                   8403:                         if ((&Apache::lonnet::privileged($uname,$udom)) &&
                   8404:                             (!$nothide{$uname.':'.$udom})) {
                   8405:                             next;
                   8406:                         }
                   8407:                     }
1.503     raeburn  8408:                     if ($end > 0 && $end < $now) {
1.439     raeburn  8409:                         $status = 'previous';
                   8410:                     } elsif ($start > $now) {
                   8411:                         $status = 'future';
                   8412:                     } else {
                   8413:                         $status = 'active';
                   8414:                     }
1.277     albertel 8415:                     foreach my $type (keys(%{$types})) { 
1.275     raeburn  8416:                         if ($status eq $type) {
1.420     albertel 8417:                             if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419     raeburn  8418:                                 push(@{$$users{$role}{$user}},$type);
                   8419:                             }
1.288     raeburn  8420:                             $match = 1;
                   8421:                         }
                   8422:                     }
1.419     raeburn  8423:                     if (($match) && (ref($userdata) eq 'HASH')) {
                   8424:                         if (!exists($$userdata{$uname.':'.$udom})) {
                   8425: 			    &get_user_info($udom,$uname,\%idx,$userdata);
                   8426:                         }
1.420     albertel 8427:                         if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419     raeburn  8428:                             push(@{$seclists{$uname.':'.$udom}},$usec);
                   8429:                         }
1.609     raeburn  8430:                         if (ref($statushash) eq 'HASH') {
                   8431:                             $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
                   8432:                         }
1.275     raeburn  8433:                     }
                   8434:                 }
                   8435:             }
                   8436:         }
1.290     albertel 8437:         if (grep(/^ow$/,@{$roles})) {
1.279     raeburn  8438:             if ((defined($cdom)) && (defined($cnum))) {
                   8439:                 my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
                   8440:                 if ( defined($csettings{'internal.courseowner'}) ) {
                   8441:                     my $owner = $csettings{'internal.courseowner'};
1.609     raeburn  8442:                     next if ($owner eq '');
                   8443:                     my ($ownername,$ownerdom);
                   8444:                     if ($owner =~ /^([^:]+):([^:]+)$/) {
                   8445:                         $ownername = $1;
                   8446:                         $ownerdom = $2;
                   8447:                     } else {
                   8448:                         $ownername = $owner;
                   8449:                         $ownerdom = $cdom;
                   8450:                         $owner = $ownername.':'.$ownerdom;
1.439     raeburn  8451:                     }
                   8452:                     @{$$users{'ow'}{$owner}} = 'any';
1.290     albertel 8453:                     if (defined($userdata) && 
1.609     raeburn  8454: 			!exists($$userdata{$owner})) {
                   8455: 			&get_user_info($ownerdom,$ownername,\%idx,$userdata);
                   8456:                         if (!grep(/^none$/,@{$seclists{$owner}})) {
                   8457:                             push(@{$seclists{$owner}},'none');
                   8458:                         }
                   8459:                         if (ref($statushash) eq 'HASH') {
                   8460:                             $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419     raeburn  8461:                         }
1.290     albertel 8462: 		    }
1.279     raeburn  8463:                 }
                   8464:             }
                   8465:         }
1.419     raeburn  8466:         foreach my $user (keys(%seclists)) {
                   8467:             @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
                   8468:             $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
                   8469:         }
1.275     raeburn  8470:     }
                   8471:     return;
                   8472: }
                   8473: 
1.288     raeburn  8474: sub get_user_info {
                   8475:     my ($udom,$uname,$idx,$userdata) = @_;
1.289     albertel 8476:     $$userdata{$uname.':'.$udom}[$$idx{fullname}] = 
                   8477: 	&plainname($uname,$udom,'lastname');
1.291     albertel 8478:     $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297     raeburn  8479:     $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609     raeburn  8480:     my %idhash =  &Apache::lonnet::idrget($udom,($uname));
                   8481:     $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname}; 
1.288     raeburn  8482:     return;
                   8483: }
1.275     raeburn  8484: 
1.472     raeburn  8485: ###############################################
                   8486: 
                   8487: =pod
                   8488: 
                   8489: =item * &get_user_quota()
                   8490: 
                   8491: Retrieves quota assigned for storage of portfolio files for a user  
                   8492: 
                   8493: Incoming parameters:
                   8494: 1. user's username
                   8495: 2. user's domain
                   8496: 
                   8497: Returns:
1.536     raeburn  8498: 1. Disk quota (in Mb) assigned to student.
                   8499: 2. (Optional) Type of setting: custom or default
                   8500:    (individually assigned or default for user's 
                   8501:    institutional status).
                   8502: 3. (Optional) - User's institutional status (e.g., faculty, staff
                   8503:    or student - types as defined in localenroll::inst_usertypes 
                   8504:    for user's domain, which determines default quota for user.
                   8505: 4. (Optional) - Default quota which would apply to the user.
1.472     raeburn  8506: 
                   8507: If a value has been stored in the user's environment, 
1.536     raeburn  8508: it will return that, otherwise it returns the maximal default
                   8509: defined for the user's instituional status(es) in the domain.
1.472     raeburn  8510: 
                   8511: =cut
                   8512: 
                   8513: ###############################################
                   8514: 
                   8515: 
                   8516: sub get_user_quota {
                   8517:     my ($uname,$udom) = @_;
1.536     raeburn  8518:     my ($quota,$quotatype,$settingstatus,$defquota);
1.472     raeburn  8519:     if (!defined($udom)) {
                   8520:         $udom = $env{'user.domain'};
                   8521:     }
                   8522:     if (!defined($uname)) {
                   8523:         $uname = $env{'user.name'};
                   8524:     }
                   8525:     if (($udom eq '' || $uname eq '') ||
                   8526:         ($udom eq 'public') && ($uname eq 'public')) {
                   8527:         $quota = 0;
1.536     raeburn  8528:         $quotatype = 'default';
                   8529:         $defquota = 0; 
1.472     raeburn  8530:     } else {
1.536     raeburn  8531:         my $inststatus;
1.472     raeburn  8532:         if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
                   8533:             $quota = $env{'environment.portfolioquota'};
1.536     raeburn  8534:             $inststatus = $env{'environment.inststatus'};
1.472     raeburn  8535:         } else {
1.536     raeburn  8536:             my %userenv = 
                   8537:                 &Apache::lonnet::get('environment',['portfolioquota',
                   8538:                                      'inststatus'],$udom,$uname);
1.472     raeburn  8539:             my ($tmp) = keys(%userenv);
                   8540:             if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   8541:                 $quota = $userenv{'portfolioquota'};
1.536     raeburn  8542:                 $inststatus = $userenv{'inststatus'};
1.472     raeburn  8543:             } else {
                   8544:                 undef(%userenv);
                   8545:             }
                   8546:         }
1.536     raeburn  8547:         ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472     raeburn  8548:         if ($quota eq '') {
1.536     raeburn  8549:             $quota = $defquota;
                   8550:             $quotatype = 'default';
                   8551:         } else {
                   8552:             $quotatype = 'custom';
1.472     raeburn  8553:         }
                   8554:     }
1.536     raeburn  8555:     if (wantarray) {
                   8556:         return ($quota,$quotatype,$settingstatus,$defquota);
                   8557:     } else {
                   8558:         return $quota;
                   8559:     }
1.472     raeburn  8560: }
                   8561: 
                   8562: ###############################################
                   8563: 
                   8564: =pod
                   8565: 
                   8566: =item * &default_quota()
                   8567: 
1.536     raeburn  8568: Retrieves default quota assigned for storage of user portfolio files,
                   8569: given an (optional) user's institutional status.
1.472     raeburn  8570: 
                   8571: Incoming parameters:
                   8572: 1. domain
1.536     raeburn  8573: 2. (Optional) institutional status(es).  This is a : separated list of 
                   8574:    status types (e.g., faculty, staff, student etc.)
                   8575:    which apply to the user for whom the default is being retrieved.
                   8576:    If the institutional status string in undefined, the domain
                   8577:    default quota will be returned. 
1.472     raeburn  8578: 
                   8579: Returns:
                   8580: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536     raeburn  8581: 2. (Optional) institutional type which determined the value of the
                   8582:    default quota.
1.472     raeburn  8583: 
                   8584: If a value has been stored in the domain's configuration db,
                   8585: it will return that, otherwise it returns 20 (for backwards 
                   8586: compatibility with domains which have not set up a configuration
                   8587: db file; the original statically defined portfolio quota was 20 Mb). 
                   8588: 
1.536     raeburn  8589: If the user's status includes multiple types (e.g., staff and student),
                   8590: the largest default quota which applies to the user determines the
                   8591: default quota returned.
                   8592: 
1.780     raeburn  8593: =back
                   8594: 
1.472     raeburn  8595: =cut
                   8596: 
                   8597: ###############################################
                   8598: 
                   8599: 
                   8600: sub default_quota {
1.536     raeburn  8601:     my ($udom,$inststatus) = @_;
                   8602:     my ($defquota,$settingstatus);
                   8603:     my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622     raeburn  8604:                                             ['quotas'],$udom);
                   8605:     if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536     raeburn  8606:         if ($inststatus ne '') {
1.765     raeburn  8607:             my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536     raeburn  8608:             foreach my $item (@statuses) {
1.711     raeburn  8609:                 if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   8610:                     if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
                   8611:                         if ($defquota eq '') {
                   8612:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   8613:                             $settingstatus = $item;
                   8614:                         } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
                   8615:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   8616:                             $settingstatus = $item;
                   8617:                         }
                   8618:                     }
                   8619:                 } else {
                   8620:                     if ($quotahash{'quotas'}{$item} ne '') {
                   8621:                         if ($defquota eq '') {
                   8622:                             $defquota = $quotahash{'quotas'}{$item};
                   8623:                             $settingstatus = $item;
                   8624:                         } elsif ($quotahash{'quotas'}{$item} > $defquota) {
                   8625:                             $defquota = $quotahash{'quotas'}{$item};
                   8626:                             $settingstatus = $item;
                   8627:                         }
1.536     raeburn  8628:                     }
                   8629:                 }
                   8630:             }
                   8631:         }
                   8632:         if ($defquota eq '') {
1.711     raeburn  8633:             if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   8634:                 $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
                   8635:             } else {
                   8636:                 $defquota = $quotahash{'quotas'}{'default'};
                   8637:             }
1.536     raeburn  8638:             $settingstatus = 'default';
                   8639:         }
                   8640:     } else {
                   8641:         $settingstatus = 'default';
                   8642:         $defquota = 20;
                   8643:     }
                   8644:     if (wantarray) {
                   8645:         return ($defquota,$settingstatus);
1.472     raeburn  8646:     } else {
1.536     raeburn  8647:         return $defquota;
1.472     raeburn  8648:     }
                   8649: }
                   8650: 
1.384     raeburn  8651: sub get_secgrprole_info {
                   8652:     my ($cdom,$cnum,$needroles,$type)  = @_;
                   8653:     my %sections_count = &get_sections($cdom,$cnum);
                   8654:     my @sections =  (sort {$a <=> $b} keys(%sections_count));
                   8655:     my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
                   8656:     my @groups = sort(keys(%curr_groups));
                   8657:     my $allroles = [];
                   8658:     my $rolehash;
                   8659:     my $accesshash = {
                   8660:                      active => 'Currently has access',
                   8661:                      future => 'Will have future access',
                   8662:                      previous => 'Previously had access',
                   8663:                   };
                   8664:     if ($needroles) {
                   8665:         $rolehash = {'all' => 'all'};
1.385     albertel 8666:         my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   8667: 	if (&Apache::lonnet::error(%user_roles)) {
                   8668: 	    undef(%user_roles);
                   8669: 	}
                   8670:         foreach my $item (keys(%user_roles)) {
1.384     raeburn  8671:             my ($role)=split(/\:/,$item,2);
                   8672:             if ($role eq 'cr') { next; }
                   8673:             if ($role =~ /^cr/) {
                   8674:                 $$rolehash{$role} = (split('/',$role))[3];
                   8675:             } else {
                   8676:                 $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
                   8677:             }
                   8678:         }
                   8679:         foreach my $key (sort(keys(%{$rolehash}))) {
                   8680:             push(@{$allroles},$key);
                   8681:         }
                   8682:         push (@{$allroles},'st');
                   8683:         $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
                   8684:     }
                   8685:     return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
                   8686: }
                   8687: 
1.555     raeburn  8688: sub user_picker {
1.994     raeburn  8689:     my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555     raeburn  8690:     my $currdom = $dom;
                   8691:     my %curr_selected = (
                   8692:                         srchin => 'dom',
1.580     raeburn  8693:                         srchby => 'lastname',
1.555     raeburn  8694:                       );
                   8695:     my $srchterm;
1.625     raeburn  8696:     if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555     raeburn  8697:         if ($srch->{'srchby'} ne '') {
                   8698:             $curr_selected{'srchby'} = $srch->{'srchby'};
                   8699:         }
                   8700:         if ($srch->{'srchin'} ne '') {
                   8701:             $curr_selected{'srchin'} = $srch->{'srchin'};
                   8702:         }
                   8703:         if ($srch->{'srchtype'} ne '') {
                   8704:             $curr_selected{'srchtype'} = $srch->{'srchtype'};
                   8705:         }
                   8706:         if ($srch->{'srchdomain'} ne '') {
                   8707:             $currdom = $srch->{'srchdomain'};
                   8708:         }
                   8709:         $srchterm = $srch->{'srchterm'};
                   8710:     }
                   8711:     my %lt=&Apache::lonlocal::texthash(
1.573     raeburn  8712:                     'usr'       => 'Search criteria',
1.563     raeburn  8713:                     'doma'      => 'Domain/institution to search',
1.558     albertel 8714:                     'uname'     => 'username',
                   8715:                     'lastname'  => 'last name',
1.555     raeburn  8716:                     'lastfirst' => 'last name, first name',
1.558     albertel 8717:                     'crs'       => 'in this course',
1.576     raeburn  8718:                     'dom'       => 'in selected LON-CAPA domain', 
1.558     albertel 8719:                     'alc'       => 'all LON-CAPA',
1.573     raeburn  8720:                     'instd'     => 'in institutional directory for selected domain',
1.558     albertel 8721:                     'exact'     => 'is',
                   8722:                     'contains'  => 'contains',
1.569     raeburn  8723:                     'begins'    => 'begins with',
1.571     raeburn  8724:                     'youm'      => "You must include some text to search for.",
                   8725:                     'thte'      => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
                   8726:                     'thet'      => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
                   8727:                     'yomc'      => "You must choose a domain when using an institutional directory search.",
                   8728:                     'ymcd'      => "You must choose a domain when using a domain search.",
                   8729:                     'whus'      => "When using searching by last,first you must include a comma as separator between last name and first name.",
                   8730:                     'whse'      => "When searching by last,first you must include at least one character in the first name.",
                   8731:                      'thfo'     => "The following need to be corrected before the search can be run:",
1.555     raeburn  8732:                                        );
1.563     raeburn  8733:     my $domform = &select_dom_form($currdom,'srchdomain',1,1);
                   8734:     my $srchinsel = ' <select name="srchin">';
1.555     raeburn  8735: 
                   8736:     my @srchins = ('crs','dom','alc','instd');
                   8737: 
                   8738:     foreach my $option (@srchins) {
                   8739:         # FIXME 'alc' option unavailable until 
                   8740:         #       loncreateuser::print_user_query_page()
                   8741:         #       has been completed.
                   8742:         next if ($option eq 'alc');
1.880     raeburn  8743:         next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));  
1.555     raeburn  8744:         next if ($option eq 'crs' && !$env{'request.course.id'});
1.563     raeburn  8745:         if ($curr_selected{'srchin'} eq $option) {
                   8746:             $srchinsel .= ' 
                   8747:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   8748:         } else {
                   8749:             $srchinsel .= '
                   8750:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   8751:         }
1.555     raeburn  8752:     }
1.563     raeburn  8753:     $srchinsel .= "\n  </select>\n";
1.555     raeburn  8754: 
                   8755:     my $srchbysel =  ' <select name="srchby">';
1.580     raeburn  8756:     foreach my $option ('lastname','lastfirst','uname') {
1.555     raeburn  8757:         if ($curr_selected{'srchby'} eq $option) {
                   8758:             $srchbysel .= '
                   8759:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   8760:         } else {
                   8761:             $srchbysel .= '
                   8762:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   8763:          }
                   8764:     }
                   8765:     $srchbysel .= "\n  </select>\n";
                   8766: 
                   8767:     my $srchtypesel = ' <select name="srchtype">';
1.580     raeburn  8768:     foreach my $option ('begins','contains','exact') {
1.555     raeburn  8769:         if ($curr_selected{'srchtype'} eq $option) {
                   8770:             $srchtypesel .= '
                   8771:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   8772:         } else {
                   8773:             $srchtypesel .= '
                   8774:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   8775:         }
                   8776:     }
                   8777:     $srchtypesel .= "\n  </select>\n";
                   8778: 
1.558     albertel 8779:     my ($newuserscript,$new_user_create);
1.994     raeburn  8780:     my $context_dom = $env{'request.role.domain'};
                   8781:     if ($context eq 'requestcrs') {
                   8782:         if ($env{'form.coursedom'} ne '') { 
                   8783:             $context_dom = $env{'form.coursedom'};
                   8784:         }
                   8785:     }
1.556     raeburn  8786:     if ($forcenewuser) {
1.576     raeburn  8787:         if (ref($srch) eq 'HASH') {
1.994     raeburn  8788:             if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627     raeburn  8789:                 if ($cancreate) {
                   8790:                     $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>';
                   8791:                 } else {
1.799     bisitz   8792:                     my $helplink = 'javascript:helpMenu('."'display'".')';
1.627     raeburn  8793:                     my %usertypetext = (
                   8794:                         official   => 'institutional',
                   8795:                         unofficial => 'non-institutional',
                   8796:                     );
1.799     bisitz   8797:                     $new_user_create = '<p class="LC_warning">'
                   8798:                                       .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
                   8799:                                       .' '
                   8800:                                       .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
                   8801:                                           ,'<a href="'.$helplink.'">','</a>')
                   8802:                                       .'</p><br />';
1.627     raeburn  8803:                 }
1.576     raeburn  8804:             }
                   8805:         }
                   8806: 
1.556     raeburn  8807:         $newuserscript = <<"ENDSCRIPT";
                   8808: 
1.570     raeburn  8809: function setSearch(createnew,callingForm) {
1.556     raeburn  8810:     if (createnew == 1) {
1.570     raeburn  8811:         for (var i=0; i<callingForm.srchby.length; i++) {
                   8812:             if (callingForm.srchby.options[i].value == 'uname') {
                   8813:                 callingForm.srchby.selectedIndex = i;
1.556     raeburn  8814:             }
                   8815:         }
1.570     raeburn  8816:         for (var i=0; i<callingForm.srchin.length; i++) {
                   8817:             if ( callingForm.srchin.options[i].value == 'dom') {
                   8818: 		callingForm.srchin.selectedIndex = i;
1.556     raeburn  8819:             }
                   8820:         }
1.570     raeburn  8821:         for (var i=0; i<callingForm.srchtype.length; i++) {
                   8822:             if (callingForm.srchtype.options[i].value == 'exact') {
                   8823:                 callingForm.srchtype.selectedIndex = i;
1.556     raeburn  8824:             }
                   8825:         }
1.570     raeburn  8826:         for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994     raeburn  8827:             if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570     raeburn  8828:                 callingForm.srchdomain.selectedIndex = i;
1.556     raeburn  8829:             }
                   8830:         }
                   8831:     }
                   8832: }
                   8833: ENDSCRIPT
1.558     albertel 8834: 
1.556     raeburn  8835:     }
                   8836: 
1.555     raeburn  8837:     my $output = <<"END_BLOCK";
1.556     raeburn  8838: <script type="text/javascript">
1.824     bisitz   8839: // <![CDATA[
1.570     raeburn  8840: function validateEntry(callingForm) {
1.558     albertel 8841: 
1.556     raeburn  8842:     var checkok = 1;
1.558     albertel 8843:     var srchin;
1.570     raeburn  8844:     for (var i=0; i<callingForm.srchin.length; i++) {
                   8845: 	if ( callingForm.srchin[i].checked ) {
                   8846: 	    srchin = callingForm.srchin[i].value;
1.558     albertel 8847: 	}
                   8848:     }
                   8849: 
1.570     raeburn  8850:     var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
                   8851:     var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
                   8852:     var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
                   8853:     var srchterm =  callingForm.srchterm.value;
                   8854:     var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556     raeburn  8855:     var msg = "";
                   8856: 
                   8857:     if (srchterm == "") {
                   8858:         checkok = 0;
1.571     raeburn  8859:         msg += "$lt{'youm'}\\n";
1.556     raeburn  8860:     }
                   8861: 
1.569     raeburn  8862:     if (srchtype== 'begins') {
                   8863:         if (srchterm.length < 2) {
                   8864:             checkok = 0;
1.571     raeburn  8865:             msg += "$lt{'thte'}\\n";
1.569     raeburn  8866:         }
                   8867:     }
                   8868: 
1.556     raeburn  8869:     if (srchtype== 'contains') {
                   8870:         if (srchterm.length < 3) {
                   8871:             checkok = 0;
1.571     raeburn  8872:             msg += "$lt{'thet'}\\n";
1.556     raeburn  8873:         }
                   8874:     }
                   8875:     if (srchin == 'instd') {
                   8876:         if (srchdomain == '') {
                   8877:             checkok = 0;
1.571     raeburn  8878:             msg += "$lt{'yomc'}\\n";
1.556     raeburn  8879:         }
                   8880:     }
                   8881:     if (srchin == 'dom') {
                   8882:         if (srchdomain == '') {
                   8883:             checkok = 0;
1.571     raeburn  8884:             msg += "$lt{'ymcd'}\\n";
1.556     raeburn  8885:         }
                   8886:     }
                   8887:     if (srchby == 'lastfirst') {
                   8888:         if (srchterm.indexOf(",") == -1) {
                   8889:             checkok = 0;
1.571     raeburn  8890:             msg += "$lt{'whus'}\\n";
1.556     raeburn  8891:         }
                   8892:         if (srchterm.indexOf(",") == srchterm.length -1) {
                   8893:             checkok = 0;
1.571     raeburn  8894:             msg += "$lt{'whse'}\\n";
1.556     raeburn  8895:         }
                   8896:     }
                   8897:     if (checkok == 0) {
1.571     raeburn  8898:         alert("$lt{'thfo'}\\n"+msg);
1.556     raeburn  8899:         return;
                   8900:     }
                   8901:     if (checkok == 1) {
1.570     raeburn  8902:         callingForm.submit();
1.556     raeburn  8903:     }
                   8904: }
                   8905: 
                   8906: $newuserscript
                   8907: 
1.824     bisitz   8908: // ]]>
1.556     raeburn  8909: </script>
1.558     albertel 8910: 
                   8911: $new_user_create
                   8912: 
1.555     raeburn  8913: END_BLOCK
1.558     albertel 8914: 
1.876     raeburn  8915:     $output .= &Apache::lonhtmlcommon::start_pick_box().
                   8916:                &Apache::lonhtmlcommon::row_title($lt{'doma'}).
                   8917:                $domform.
                   8918:                &Apache::lonhtmlcommon::row_closure().
                   8919:                &Apache::lonhtmlcommon::row_title($lt{'usr'}).
                   8920:                $srchbysel.
                   8921:                $srchtypesel. 
                   8922:                '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
                   8923:                $srchinsel.
                   8924:                &Apache::lonhtmlcommon::row_closure(1). 
                   8925:                &Apache::lonhtmlcommon::end_pick_box().
                   8926:                '<br />';
1.555     raeburn  8927:     return $output;
                   8928: }
                   8929: 
1.612     raeburn  8930: sub user_rule_check {
1.615     raeburn  8931:     my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612     raeburn  8932:     my $response;
                   8933:     if (ref($usershash) eq 'HASH') {
                   8934:         foreach my $user (keys(%{$usershash})) {
                   8935:             my ($uname,$udom) = split(/:/,$user);
                   8936:             next if ($udom eq '' || $uname eq '');
1.615     raeburn  8937:             my ($id,$newuser);
1.612     raeburn  8938:             if (ref($usershash->{$user}) eq 'HASH') {
1.615     raeburn  8939:                 $newuser = $usershash->{$user}->{'newuser'};
1.612     raeburn  8940:                 $id = $usershash->{$user}->{'id'};
                   8941:             }
                   8942:             my $inst_response;
                   8943:             if (ref($checks) eq 'HASH') {
                   8944:                 if (defined($checks->{'username'})) {
1.615     raeburn  8945:                     ($inst_response,%{$inst_results->{$user}}) = 
1.612     raeburn  8946:                         &Apache::lonnet::get_instuser($udom,$uname);
                   8947:                 } elsif (defined($checks->{'id'})) {
1.615     raeburn  8948:                     ($inst_response,%{$inst_results->{$user}}) =
1.612     raeburn  8949:                         &Apache::lonnet::get_instuser($udom,undef,$id);
                   8950:                 }
1.615     raeburn  8951:             } else {
                   8952:                 ($inst_response,%{$inst_results->{$user}}) =
                   8953:                     &Apache::lonnet::get_instuser($udom,$uname);
                   8954:                 return;
1.612     raeburn  8955:             }
1.615     raeburn  8956:             if (!$got_rules->{$udom}) {
1.612     raeburn  8957:                 my %domconfig = &Apache::lonnet::get_dom('configuration',
                   8958:                                                   ['usercreation'],$udom);
                   8959:                 if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615     raeburn  8960:                     foreach my $item ('username','id') {
1.612     raeburn  8961:                         if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
                   8962:                             $$curr_rules{$udom}{$item} = 
                   8963:                                 $domconfig{'usercreation'}{$item.'_rule'};
1.585     raeburn  8964:                         }
                   8965:                     }
                   8966:                 }
1.615     raeburn  8967:                 $got_rules->{$udom} = 1;  
1.585     raeburn  8968:             }
1.612     raeburn  8969:             foreach my $item (keys(%{$checks})) {
                   8970:                 if (ref($$curr_rules{$udom}) eq 'HASH') {
                   8971:                     if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
                   8972:                         if (@{$$curr_rules{$udom}{$item}} > 0) {
                   8973:                             my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
                   8974:                             foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
                   8975:                                 if ($rule_check{$rule}) {
                   8976:                                     $$rulematch{$user}{$item} = $rule;
                   8977:                                     if ($inst_response eq 'ok') {
1.615     raeburn  8978:                                         if (ref($inst_results) eq 'HASH') {
                   8979:                                             if (ref($inst_results->{$user}) eq 'HASH') {
                   8980:                                                 if (keys(%{$inst_results->{$user}}) == 0) {
                   8981:                                                     $$alerts{$item}{$udom}{$uname} = 1;
                   8982:                                                 }
1.612     raeburn  8983:                                             }
                   8984:                                         }
1.615     raeburn  8985:                                     }
                   8986:                                     last;
1.585     raeburn  8987:                                 }
                   8988:                             }
                   8989:                         }
                   8990:                     }
                   8991:                 }
                   8992:             }
                   8993:         }
                   8994:     }
1.612     raeburn  8995:     return;
                   8996: }
                   8997: 
                   8998: sub user_rule_formats {
                   8999:     my ($domain,$domdesc,$curr_rules,$check) = @_;
                   9000:     my %text = ( 
                   9001:                  'username' => 'Usernames',
                   9002:                  'id'       => 'IDs',
                   9003:                );
                   9004:     my $output;
                   9005:     my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
                   9006:     if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
                   9007:         if (@{$ruleorder} > 0) {
1.1075.2.20  raeburn  9008:             $output = '<br />'.
                   9009:                       &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
                   9010:                           '<span class="LC_cusr_emph">','</span>',$domdesc).
                   9011:                       ' <ul>';
1.612     raeburn  9012:             foreach my $rule (@{$ruleorder}) {
                   9013:                 if (ref($curr_rules) eq 'ARRAY') {
                   9014:                     if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
                   9015:                         if (ref($rules->{$rule}) eq 'HASH') {
                   9016:                             $output .= '<li>'.$rules->{$rule}{'name'}.': '.
                   9017:                                         $rules->{$rule}{'desc'}.'</li>';
                   9018:                         }
                   9019:                     }
                   9020:                 }
                   9021:             }
                   9022:             $output .= '</ul>';
                   9023:         }
                   9024:     }
                   9025:     return $output;
                   9026: }
                   9027: 
                   9028: sub instrule_disallow_msg {
1.615     raeburn  9029:     my ($checkitem,$domdesc,$count,$mode) = @_;
1.612     raeburn  9030:     my $response;
                   9031:     my %text = (
                   9032:                   item   => 'username',
                   9033:                   items  => 'usernames',
                   9034:                   match  => 'matches',
                   9035:                   do     => 'does',
                   9036:                   action => 'a username',
                   9037:                   one    => 'one',
                   9038:                );
                   9039:     if ($count > 1) {
                   9040:         $text{'item'} = 'usernames';
                   9041:         $text{'match'} ='match';
                   9042:         $text{'do'} = 'do';
                   9043:         $text{'action'} = 'usernames',
                   9044:         $text{'one'} = 'ones';
                   9045:     }
                   9046:     if ($checkitem eq 'id') {
                   9047:         $text{'items'} = 'IDs';
                   9048:         $text{'item'} = 'ID';
                   9049:         $text{'action'} = 'an ID';
1.615     raeburn  9050:         if ($count > 1) {
                   9051:             $text{'item'} = 'IDs';
                   9052:             $text{'action'} = 'IDs';
                   9053:         }
1.612     raeburn  9054:     }
1.674     bisitz   9055:     $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  9056:     if ($mode eq 'upload') {
                   9057:         if ($checkitem eq 'username') {
                   9058:             $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'}.");
                   9059:         } elsif ($checkitem eq 'id') {
1.674     bisitz   9060:             $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  9061:         }
1.669     raeburn  9062:     } elsif ($mode eq 'selfcreate') {
                   9063:         if ($checkitem eq 'id') {
                   9064:             $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.");
                   9065:         }
1.615     raeburn  9066:     } else {
                   9067:         if ($checkitem eq 'username') {
                   9068:             $response .= &mt("You must choose $text{'action'} with a different format --  $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
                   9069:         } elsif ($checkitem eq 'id') {
                   9070:             $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.");
                   9071:         }
1.612     raeburn  9072:     }
                   9073:     return $response;
1.585     raeburn  9074: }
                   9075: 
1.624     raeburn  9076: sub personal_data_fieldtitles {
                   9077:     my %fieldtitles = &Apache::lonlocal::texthash (
                   9078:                         id => 'Student/Employee ID',
                   9079:                         permanentemail => 'E-mail address',
                   9080:                         lastname => 'Last Name',
                   9081:                         firstname => 'First Name',
                   9082:                         middlename => 'Middle Name',
                   9083:                         generation => 'Generation',
                   9084:                         gen => 'Generation',
1.765     raeburn  9085:                         inststatus => 'Affiliation',
1.624     raeburn  9086:                    );
                   9087:     return %fieldtitles;
                   9088: }
                   9089: 
1.642     raeburn  9090: sub sorted_inst_types {
                   9091:     my ($dom) = @_;
                   9092:     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
                   9093:     my $othertitle = &mt('All users');
                   9094:     if ($env{'request.course.id'}) {
1.668     raeburn  9095:         $othertitle  = &mt('Any users');
1.642     raeburn  9096:     }
                   9097:     my @types;
                   9098:     if (ref($order) eq 'ARRAY') {
                   9099:         @types = @{$order};
                   9100:     }
                   9101:     if (@types == 0) {
                   9102:         if (ref($usertypes) eq 'HASH') {
                   9103:             @types = sort(keys(%{$usertypes}));
                   9104:         }
                   9105:     }
                   9106:     if (keys(%{$usertypes}) > 0) {
                   9107:         $othertitle = &mt('Other users');
                   9108:     }
                   9109:     return ($othertitle,$usertypes,\@types);
                   9110: }
                   9111: 
1.645     raeburn  9112: sub get_institutional_codes {
                   9113:     my ($settings,$allcourses,$LC_code) = @_;
                   9114: # Get complete list of course sections to update
                   9115:     my @currsections = ();
                   9116:     my @currxlists = ();
                   9117:     my $coursecode = $$settings{'internal.coursecode'};
                   9118: 
                   9119:     if ($$settings{'internal.sectionnums'} ne '') {
                   9120:         @currsections = split(/,/,$$settings{'internal.sectionnums'});
                   9121:     }
                   9122: 
                   9123:     if ($$settings{'internal.crosslistings'} ne '') {
                   9124:         @currxlists = split(/,/,$$settings{'internal.crosslistings'});
                   9125:     }
                   9126: 
                   9127:     if (@currxlists > 0) {
                   9128:         foreach (@currxlists) {
                   9129:             if (m/^([^:]+):(\w*)$/) {
                   9130:                 unless (grep/^$1$/,@{$allcourses}) {
                   9131:                     push @{$allcourses},$1;
                   9132:                     $$LC_code{$1} = $2;
                   9133:                 }
                   9134:             }
                   9135:         }
                   9136:     }
                   9137:  
                   9138:     if (@currsections > 0) {
                   9139:         foreach (@currsections) {
                   9140:             if (m/^(\w+):(\w*)$/) {
                   9141:                 my $sec = $coursecode.$1;
                   9142:                 my $lc_sec = $2;
                   9143:                 unless (grep/^$sec$/,@{$allcourses}) {
                   9144:                     push @{$allcourses},$sec;
                   9145:                     $$LC_code{$sec} = $lc_sec;
                   9146:                 }
                   9147:             }
                   9148:         }
                   9149:     }
                   9150:     return;
                   9151: }
                   9152: 
1.971     raeburn  9153: sub get_standard_codeitems {
                   9154:     return ('Year','Semester','Department','Number','Section');
                   9155: }
                   9156: 
1.112     bowersj2 9157: =pod
                   9158: 
1.780     raeburn  9159: =head1 Slot Helpers
                   9160: 
                   9161: =over 4
                   9162: 
                   9163: =item * sorted_slots()
                   9164: 
1.1040    raeburn  9165: Sorts an array of slot names in order of an optional sort key,
                   9166: default sort is by slot start time (earliest first). 
1.780     raeburn  9167: 
                   9168: Inputs:
                   9169: 
                   9170: =over 4
                   9171: 
                   9172: slotsarr  - Reference to array of unsorted slot names.
                   9173: 
                   9174: slots     - Reference to hash of hash, where outer hash keys are slot names.
                   9175: 
1.1040    raeburn  9176: sortkey   - Name of key in inner hash to be sorted on (e.g., starttime).
                   9177: 
1.549     albertel 9178: =back
                   9179: 
1.780     raeburn  9180: Returns:
                   9181: 
                   9182: =over 4
                   9183: 
1.1040    raeburn  9184: sorted   - An array of slot names sorted by a specified sort key 
                   9185:            (default sort key is start time of the slot).
1.780     raeburn  9186: 
                   9187: =back
                   9188: 
                   9189: =cut
                   9190: 
                   9191: 
                   9192: sub sorted_slots {
1.1040    raeburn  9193:     my ($slotsarr,$slots,$sortkey) = @_;
                   9194:     if ($sortkey eq '') {
                   9195:         $sortkey = 'starttime';
                   9196:     }
1.780     raeburn  9197:     my @sorted;
                   9198:     if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
                   9199:         @sorted =
                   9200:             sort {
                   9201:                      if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040    raeburn  9202:                          return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780     raeburn  9203:                      }
                   9204:                      if (ref($slots->{$a})) { return -1;}
                   9205:                      if (ref($slots->{$b})) { return 1;}
                   9206:                      return 0;
                   9207:                  } @{$slotsarr};
                   9208:     }
                   9209:     return @sorted;
                   9210: }
                   9211: 
1.1040    raeburn  9212: =pod
                   9213: 
                   9214: =item * get_future_slots()
                   9215: 
                   9216: Inputs:
                   9217: 
                   9218: =over 4
                   9219: 
                   9220: cnum - course number
                   9221: 
                   9222: cdom - course domain
                   9223: 
                   9224: now - current UNIX time
                   9225: 
                   9226: symb - optional symb
                   9227: 
                   9228: =back
                   9229: 
                   9230: Returns:
                   9231: 
                   9232: =over 4
                   9233: 
                   9234: sorted_reservable - ref to array of student_schedulable slots currently 
                   9235:                     reservable, ordered by end date of reservation period.
                   9236: 
                   9237: reservable_now - ref to hash of student_schedulable slots currently
                   9238:                  reservable.
                   9239: 
                   9240:     Keys in inner hash are:
                   9241:     (a) symb: either blank or symb to which slot use is restricted.
                   9242:     (b) endreserve: end date of reservation period. 
                   9243: 
                   9244: sorted_future - ref to array of student_schedulable slots reservable in
                   9245:                 the future, ordered by start date of reservation period.
                   9246: 
                   9247: future_reservable - ref to hash of student_schedulable slots reservable
                   9248:                     in the future.
                   9249: 
                   9250:     Keys in inner hash are:
                   9251:     (a) symb: either blank or symb to which slot use is restricted.
                   9252:     (b) startreserve:  start date of reservation period.
                   9253: 
                   9254: =back
                   9255: 
                   9256: =cut
                   9257: 
                   9258: sub get_future_slots {
                   9259:     my ($cnum,$cdom,$now,$symb) = @_;
                   9260:     my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
                   9261:     my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
                   9262:     foreach my $slot (keys(%slots)) {
                   9263:         next unless($slots{$slot}->{'type'} eq 'schedulable_student');
                   9264:         if ($symb) {
                   9265:             next if (($slots{$slot}->{'symb'} ne '') && 
                   9266:                      ($slots{$slot}->{'symb'} ne $symb));
                   9267:         }
                   9268:         if (($slots{$slot}->{'starttime'} > $now) &&
                   9269:             ($slots{$slot}->{'endtime'} > $now)) {
                   9270:             if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
                   9271:                 my $userallowed = 0;
                   9272:                 if ($slots{$slot}->{'allowedsections'}) {
                   9273:                     my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
                   9274:                     if (!defined($env{'request.role.sec'})
                   9275:                         && grep(/^No section assigned$/,@allowed_sec)) {
                   9276:                         $userallowed=1;
                   9277:                     } else {
                   9278:                         if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
                   9279:                             $userallowed=1;
                   9280:                         }
                   9281:                     }
                   9282:                     unless ($userallowed) {
                   9283:                         if (defined($env{'request.course.groups'})) {
                   9284:                             my @groups = split(/:/,$env{'request.course.groups'});
                   9285:                             foreach my $group (@groups) {
                   9286:                                 if (grep(/^\Q$group\E$/,@allowed_sec)) {
                   9287:                                     $userallowed=1;
                   9288:                                     last;
                   9289:                                 }
                   9290:                             }
                   9291:                         }
                   9292:                     }
                   9293:                 }
                   9294:                 if ($slots{$slot}->{'allowedusers'}) {
                   9295:                     my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
                   9296:                     my $user = $env{'user.name'}.':'.$env{'user.domain'};
                   9297:                     if (grep(/^\Q$user\E$/,@allowed_users)) {
                   9298:                         $userallowed = 1;
                   9299:                     }
                   9300:                 }
                   9301:                 next unless($userallowed);
                   9302:             }
                   9303:             my $startreserve = $slots{$slot}->{'startreserve'};
                   9304:             my $endreserve = $slots{$slot}->{'endreserve'};
                   9305:             my $symb = $slots{$slot}->{'symb'};
                   9306:             if (($startreserve < $now) &&
                   9307:                 (!$endreserve || $endreserve > $now)) {
                   9308:                 my $lastres = $endreserve;
                   9309:                 if (!$lastres) {
                   9310:                     $lastres = $slots{$slot}->{'starttime'};
                   9311:                 }
                   9312:                 $reservable_now{$slot} = {
                   9313:                                            symb       => $symb,
                   9314:                                            endreserve => $lastres
                   9315:                                          };
                   9316:             } elsif (($startreserve > $now) &&
                   9317:                      (!$endreserve || $endreserve > $startreserve)) {
                   9318:                 $future_reservable{$slot} = {
                   9319:                                               symb         => $symb,
                   9320:                                               startreserve => $startreserve
                   9321:                                             };
                   9322:             }
                   9323:         }
                   9324:     }
                   9325:     my @unsorted_reservable = keys(%reservable_now);
                   9326:     if (@unsorted_reservable > 0) {
                   9327:         @sorted_reservable = 
                   9328:             &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
                   9329:     }
                   9330:     my @unsorted_future = keys(%future_reservable);
                   9331:     if (@unsorted_future > 0) {
                   9332:         @sorted_future =
                   9333:             &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
                   9334:     }
                   9335:     return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
                   9336: }
1.780     raeburn  9337: 
                   9338: =pod
                   9339: 
1.1057    foxr     9340: =back
                   9341: 
1.549     albertel 9342: =head1 HTTP Helpers
                   9343: 
                   9344: =over 4
                   9345: 
1.648     raeburn  9346: =item * &get_unprocessed_cgi($query,$possible_names)
1.112     bowersj2 9347: 
1.258     albertel 9348: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112     bowersj2 9349: $query.  The parameters listed in $possible_names (an array reference),
1.258     albertel 9350: will be set in $env{'form.name'} if they do not already exist.
1.112     bowersj2 9351: 
                   9352: Typically called with $ENV{'QUERY_STRING'} as the first parameter.  
                   9353: $possible_names is an ref to an array of form element names.  As an example:
                   9354: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258     albertel 9355: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112     bowersj2 9356: 
                   9357: =cut
1.1       albertel 9358: 
1.6       albertel 9359: sub get_unprocessed_cgi {
1.25      albertel 9360:   my ($query,$possible_names)= @_;
1.26      matthew  9361:   # $Apache::lonxml::debug=1;
1.356     albertel 9362:   foreach my $pair (split(/&/,$query)) {
                   9363:     my ($name, $value) = split(/=/,$pair);
1.369     www      9364:     $name = &unescape($name);
1.25      albertel 9365:     if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
                   9366:       $value =~ tr/+/ /;
                   9367:       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258     albertel 9368:       unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25      albertel 9369:     }
1.16      harris41 9370:   }
1.6       albertel 9371: }
                   9372: 
1.112     bowersj2 9373: =pod
                   9374: 
1.648     raeburn  9375: =item * &cacheheader() 
1.112     bowersj2 9376: 
                   9377: returns cache-controlling header code
                   9378: 
                   9379: =cut
                   9380: 
1.7       albertel 9381: sub cacheheader {
1.258     albertel 9382:     unless ($env{'request.method'} eq 'GET') { return ''; }
1.216     albertel 9383:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
                   9384:     my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7       albertel 9385:                 <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
                   9386:                 <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216     albertel 9387:     return $output;
1.7       albertel 9388: }
                   9389: 
1.112     bowersj2 9390: =pod
                   9391: 
1.648     raeburn  9392: =item * &no_cache($r) 
1.112     bowersj2 9393: 
                   9394: specifies header code to not have cache
                   9395: 
                   9396: =cut
                   9397: 
1.9       albertel 9398: sub no_cache {
1.216     albertel 9399:     my ($r) = @_;
                   9400:     if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258     albertel 9401: 	$env{'request.method'} ne 'GET') { return ''; }
1.216     albertel 9402:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
                   9403:     $r->no_cache(1);
                   9404:     $r->header_out("Expires" => $date);
                   9405:     $r->header_out("Pragma" => "no-cache");
1.123     www      9406: }
                   9407: 
                   9408: sub content_type {
1.181     albertel 9409:     my ($r,$type,$charset) = @_;
1.299     foxr     9410:     if ($r) {
                   9411: 	#  Note that printout.pl calls this with undef for $r.
                   9412: 	&no_cache($r);
                   9413:     }
1.258     albertel 9414:     if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181     albertel 9415:     unless ($charset) {
                   9416: 	$charset=&Apache::lonlocal::current_encoding;
                   9417:     }
                   9418:     if ($charset) { $type.='; charset='.$charset; }
                   9419:     if ($r) {
                   9420: 	$r->content_type($type);
                   9421:     } else {
                   9422: 	print("Content-type: $type\n\n");
                   9423:     }
1.9       albertel 9424: }
1.25      albertel 9425: 
1.112     bowersj2 9426: =pod
                   9427: 
1.648     raeburn  9428: =item * &add_to_env($name,$value) 
1.112     bowersj2 9429: 
1.258     albertel 9430: adds $name to the %env hash with value
1.112     bowersj2 9431: $value, if $name already exists, the entry is converted to an array
                   9432: reference and $value is added to the array.
                   9433: 
                   9434: =cut
                   9435: 
1.25      albertel 9436: sub add_to_env {
                   9437:   my ($name,$value)=@_;
1.258     albertel 9438:   if (defined($env{$name})) {
                   9439:     if (ref($env{$name})) {
1.25      albertel 9440:       #already have multiple values
1.258     albertel 9441:       push(@{ $env{$name} },$value);
1.25      albertel 9442:     } else {
                   9443:       #first time seeing multiple values, convert hash entry to an arrayref
1.258     albertel 9444:       my $first=$env{$name};
                   9445:       undef($env{$name});
                   9446:       push(@{ $env{$name} },$first,$value);
1.25      albertel 9447:     }
                   9448:   } else {
1.258     albertel 9449:     $env{$name}=$value;
1.25      albertel 9450:   }
1.31      albertel 9451: }
1.149     albertel 9452: 
                   9453: =pod
                   9454: 
1.648     raeburn  9455: =item * &get_env_multiple($name) 
1.149     albertel 9456: 
1.258     albertel 9457: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149     albertel 9458: values may be defined and end up as an array ref.
                   9459: 
                   9460: returns an array of values
                   9461: 
                   9462: =cut
                   9463: 
                   9464: sub get_env_multiple {
                   9465:     my ($name) = @_;
                   9466:     my @values;
1.258     albertel 9467:     if (defined($env{$name})) {
1.149     albertel 9468:         # exists is it an array
1.258     albertel 9469:         if (ref($env{$name})) {
                   9470:             @values=@{ $env{$name} };
1.149     albertel 9471:         } else {
1.258     albertel 9472:             $values[0]=$env{$name};
1.149     albertel 9473:         }
                   9474:     }
                   9475:     return(@values);
                   9476: }
                   9477: 
1.660     raeburn  9478: sub ask_for_embedded_content {
                   9479:     my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071    raeburn  9480:     my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11  raeburn  9481:         %currsubfile,%unused,$rem);
1.1071    raeburn  9482:     my $counter = 0;
                   9483:     my $numnew = 0;
1.987     raeburn  9484:     my $numremref = 0;
                   9485:     my $numinvalid = 0;
                   9486:     my $numpathchg = 0;
                   9487:     my $numexisting = 0;
1.1071    raeburn  9488:     my $numunused = 0;
                   9489:     my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
                   9490:         $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path);
                   9491:     my $heading = &mt('Upload embedded files');
                   9492:     my $buttontext = &mt('Upload');
                   9493: 
1.1075.2.11  raeburn  9494:     my $navmap;
                   9495:     if ($env{'request.course.id'}) {
                   9496:         $navmap = Apache::lonnavmaps::navmap->new();
                   9497:     }
1.984     raeburn  9498:     if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
                   9499:         my $current_path='/';
                   9500:         if ($env{'form.currentpath'}) {
                   9501:             $current_path = $env{'form.currentpath'};
                   9502:         }
                   9503:         if ($actionurl eq '/adm/coursegrp_portfolio') {
                   9504:             $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   9505:             $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
                   9506:             $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
                   9507:         } else {
                   9508:             $udom = $env{'user.domain'};
                   9509:             $uname = $env{'user.name'};
                   9510:             $url = '/userfiles/portfolio';
                   9511:         }
1.987     raeburn  9512:         $toplevel = $url.'/';
1.984     raeburn  9513:         $url .= $current_path;
                   9514:         $getpropath = 1;
1.987     raeburn  9515:     } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
                   9516:              ($actionurl eq '/adm/imsimport')) { 
1.1022    www      9517:         my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026    raeburn  9518:         $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987     raeburn  9519:         $toplevel = $url;
1.984     raeburn  9520:         if ($rest ne '') {
1.987     raeburn  9521:             $url .= $rest;
                   9522:         }
                   9523:     } elsif ($actionurl eq '/adm/coursedocs') {
                   9524:         if (ref($args) eq 'HASH') {
1.1071    raeburn  9525:             $url = $args->{'docs_url'};
                   9526:             $toplevel = $url;
1.1075.2.11  raeburn  9527:             if ($args->{'context'} eq 'paste') {
                   9528:                 ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
                   9529:                 ($path) =
                   9530:                     ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
                   9531:                 $fileloc = &Apache::lonnet::filelocation('',$toplevel);
                   9532:                 $fileloc =~ s{^/}{};
                   9533:             }
1.1071    raeburn  9534:         }
                   9535:     } elsif ($actionurl eq '/adm/dependencies') {
                   9536:         if ($env{'request.course.id'} ne '') {
                   9537:             $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   9538:             $cnum =  $env{'course.'.$env{'request.course.id'}.'.num'};
                   9539:             if (ref($args) eq 'HASH') {
                   9540:                 $url = $args->{'docs_url'};
                   9541:                 $title = $args->{'docs_title'};
                   9542:                 $toplevel = "/$url";
1.1075.2.11  raeburn  9543:                 ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1071    raeburn  9544:                 ($path) =  
                   9545:                     ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
                   9546:                 $fileloc = &Apache::lonnet::filelocation('',$toplevel);
                   9547:                 $fileloc =~ s{^/}{};
                   9548:                 ($filename) = ($fileloc =~ m{.+/([^/]+)$});
                   9549:                 $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
                   9550:             }
1.987     raeburn  9551:         }
                   9552:     }
                   9553:     my $now = time();
                   9554:     foreach my $embed_file (keys(%{$allfiles})) {
                   9555:         my $absolutepath;
                   9556:         if ($embed_file =~ m{^\w+://}) {
                   9557:             $newfiles{$embed_file} = 1;
                   9558:             $mapping{$embed_file} = $embed_file;
                   9559:         } else {
                   9560:             if ($embed_file =~ m{^/}) {
                   9561:                 $absolutepath = $embed_file;
                   9562:                 $embed_file =~ s{^(/+)}{};
                   9563:             }
                   9564:             if ($embed_file =~ m{/}) {
                   9565:                 my ($path,$fname) = ($embed_file =~ m{^(.+)/([^/]*)$});
                   9566:                 $path = &check_for_traversal($path,$url,$toplevel);
                   9567:                 my $item = $fname;
                   9568:                 if ($path ne '') {
                   9569:                     $item = $path.'/'.$fname;
                   9570:                     $subdependencies{$path}{$fname} = 1;
                   9571:                 } else {
                   9572:                     $dependencies{$item} = 1;
                   9573:                 }
                   9574:                 if ($absolutepath) {
                   9575:                     $mapping{$item} = $absolutepath;
                   9576:                 } else {
                   9577:                     $mapping{$item} = $embed_file;
                   9578:                 }
                   9579:             } else {
                   9580:                 $dependencies{$embed_file} = 1;
                   9581:                 if ($absolutepath) {
                   9582:                     $mapping{$embed_file} = $absolutepath;
                   9583:                 } else {
                   9584:                     $mapping{$embed_file} = $embed_file;
                   9585:                 }
                   9586:             }
1.984     raeburn  9587:         }
                   9588:     }
1.1071    raeburn  9589:     my $dirptr = 16384;
1.984     raeburn  9590:     foreach my $path (keys(%subdependencies)) {
1.1071    raeburn  9591:         $currsubfile{$path} = {};
1.984     raeburn  9592:         if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) { 
1.1021    raeburn  9593:             my ($sublistref,$listerror) =
                   9594:                 &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
                   9595:             if (ref($sublistref) eq 'ARRAY') {
                   9596:                 foreach my $line (@{$sublistref}) {
                   9597:                     my ($file_name,$rest) = split(/\&/,$line,2);
1.1071    raeburn  9598:                     $currsubfile{$path}{$file_name} = 1;
1.1021    raeburn  9599:                 }
1.984     raeburn  9600:             }
1.987     raeburn  9601:         } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984     raeburn  9602:             if (opendir(my $dir,$url.'/'.$path)) {
                   9603:                 my @subdir_list = grep(!/^\./,readdir($dir));
1.1071    raeburn  9604:                 map {$currsubfile{$path}{$_} = 1;} @subdir_list;
                   9605:             }
1.1075.2.11  raeburn  9606:         } elsif (($actionurl eq '/adm/dependencies') ||
                   9607:                  (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
                   9608:                   ($args->{'context'} eq 'paste'))) {
1.1071    raeburn  9609:             if ($env{'request.course.id'} ne '') {
                   9610:                 my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
                   9611:                 if ($dir ne '') {
                   9612:                     my ($sublistref,$listerror) =
                   9613:                         &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
                   9614:                     if (ref($sublistref) eq 'ARRAY') {
                   9615:                         foreach my $line (@{$sublistref}) {
                   9616:                             my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
                   9617:                                 undef,$mtime)=split(/\&/,$line,12);
                   9618:                             unless (($testdir&$dirptr) ||
                   9619:                                     ($file_name =~ /^\.\.?$/)) {
                   9620:                                 $currsubfile{$path}{$file_name} = [$size,$mtime];
                   9621:                             }
                   9622:                         }
                   9623:                     }
                   9624:                 }
1.984     raeburn  9625:             }
                   9626:         }
                   9627:         foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071    raeburn  9628:             if (exists($currsubfile{$path}{$file})) {
1.987     raeburn  9629:                 my $item = $path.'/'.$file;
                   9630:                 unless ($mapping{$item} eq $item) {
                   9631:                     $pathchanges{$item} = 1;
                   9632:                 }
                   9633:                 $existing{$item} = 1;
                   9634:                 $numexisting ++;
                   9635:             } else {
                   9636:                 $newfiles{$path.'/'.$file} = 1;
1.984     raeburn  9637:             }
                   9638:         }
1.1071    raeburn  9639:         if ($actionurl eq '/adm/dependencies') {
                   9640:             foreach my $path (keys(%currsubfile)) {
                   9641:                 if (ref($currsubfile{$path}) eq 'HASH') {
                   9642:                     foreach my $file (keys(%{$currsubfile{$path}})) {
                   9643:                          unless ($subdependencies{$path}{$file}) {
1.1075.2.11  raeburn  9644:                              next if (($rem ne '') &&
                   9645:                                       (($env{"httpref.$rem"."$path/$file"} ne '') ||
                   9646:                                        (ref($navmap) &&
                   9647:                                        (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
                   9648:                                         (($file =~ /^(.*\.s?html?)\.bak$/i) &&
                   9649:                                          ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071    raeburn  9650:                              $unused{$path.'/'.$file} = 1; 
                   9651:                          }
                   9652:                     }
                   9653:                 }
                   9654:             }
                   9655:         }
1.984     raeburn  9656:     }
1.987     raeburn  9657:     my %currfile;
1.984     raeburn  9658:     if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021    raeburn  9659:         my ($dirlistref,$listerror) =
                   9660:             &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
                   9661:         if (ref($dirlistref) eq 'ARRAY') {
                   9662:             foreach my $line (@{$dirlistref}) {
                   9663:                 my ($file_name,$rest) = split(/\&/,$line,2);
                   9664:                 $currfile{$file_name} = 1;
                   9665:             }
1.984     raeburn  9666:         }
1.987     raeburn  9667:     } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984     raeburn  9668:         if (opendir(my $dir,$url)) {
1.987     raeburn  9669:             my @dir_list = grep(!/^\./,readdir($dir));
1.984     raeburn  9670:             map {$currfile{$_} = 1;} @dir_list;
                   9671:         }
1.1075.2.11  raeburn  9672:     } elsif (($actionurl eq '/adm/dependencies') ||
                   9673:              (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
                   9674:               ($args->{'context'} eq 'paste'))) {
1.1071    raeburn  9675:         if ($env{'request.course.id'} ne '') {
                   9676:             my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
                   9677:             if ($dir ne '') {
                   9678:                 my ($dirlistref,$listerror) =
                   9679:                     &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
                   9680:                 if (ref($dirlistref) eq 'ARRAY') {
                   9681:                     foreach my $line (@{$dirlistref}) {
                   9682:                         my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
                   9683:                             $size,undef,$mtime)=split(/\&/,$line,12);
                   9684:                         unless (($testdir&$dirptr) ||
                   9685:                                 ($file_name =~ /^\.\.?$/)) {
                   9686:                             $currfile{$file_name} = [$size,$mtime];
                   9687:                         }
                   9688:                     }
                   9689:                 }
                   9690:             }
                   9691:         }
1.984     raeburn  9692:     }
                   9693:     foreach my $file (keys(%dependencies)) {
1.1071    raeburn  9694:         if (exists($currfile{$file})) {
1.987     raeburn  9695:             unless ($mapping{$file} eq $file) {
                   9696:                 $pathchanges{$file} = 1;
                   9697:             }
                   9698:             $existing{$file} = 1;
                   9699:             $numexisting ++;
                   9700:         } else {
1.984     raeburn  9701:             $newfiles{$file} = 1;
                   9702:         }
                   9703:     }
1.1071    raeburn  9704:     foreach my $file (keys(%currfile)) {
                   9705:         unless (($file eq $filename) ||
                   9706:                 ($file eq $filename.'.bak') ||
                   9707:                 ($dependencies{$file})) {
1.1075.2.11  raeburn  9708:             if ($actionurl eq '/adm/dependencies') {
                   9709:                 next if (($rem ne '') &&
                   9710:                          (($env{"httpref.$rem".$file} ne '') ||
                   9711:                           (ref($navmap) &&
                   9712:                           (($navmap->getResourceByUrl($rem.$file) ne '') ||
                   9713:                            (($file =~ /^(.*\.s?html?)\.bak$/i) &&
                   9714:                             ($navmap->getResourceByUrl($rem.$1)))))));
                   9715:             }
1.1071    raeburn  9716:             $unused{$file} = 1;
                   9717:         }
                   9718:     }
1.1075.2.11  raeburn  9719:     if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
                   9720:         ($args->{'context'} eq 'paste')) {
                   9721:         $counter = scalar(keys(%existing));
                   9722:         $numpathchg = scalar(keys(%pathchanges));
                   9723:         return ($output,$counter,$numpathchg,\%existing);
                   9724:     }
1.984     raeburn  9725:     foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071    raeburn  9726:         if ($actionurl eq '/adm/dependencies') {
                   9727:             next if ($embed_file =~ m{^\w+://});
                   9728:         }
1.660     raeburn  9729:         $upload_output .= &start_data_table_row().
1.1071    raeburn  9730:                           '<td><img src="'.&icon($embed_file).'" />&nbsp;'.
                   9731:                           '<span class="LC_filename">'.$embed_file.'</span>';
1.987     raeburn  9732:         unless ($mapping{$embed_file} eq $embed_file) {
                   9733:             $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.&mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
                   9734:         }
                   9735:         $upload_output .= '</td><td>';
1.1071    raeburn  9736:         if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) { 
1.660     raeburn  9737:             $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
1.987     raeburn  9738:             $numremref++;
1.660     raeburn  9739:         } elsif ($args->{'error_on_invalid_names'}
                   9740:             && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.987     raeburn  9741:             $upload_output.='<span class="LC_warning">'.&mt('Invalid characters').'</span>';
                   9742:             $numinvalid++;
1.660     raeburn  9743:         } else {
1.1071    raeburn  9744:             $upload_output .= &embedded_file_element('upload_embedded',$counter,
1.987     raeburn  9745:                                                      $embed_file,\%mapping,
1.1071    raeburn  9746:                                                      $allfiles,$codebase,'upload');
                   9747:             $counter ++;
                   9748:             $numnew ++;
1.987     raeburn  9749:         }
                   9750:         $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
                   9751:     }
                   9752:     foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071    raeburn  9753:         if ($actionurl eq '/adm/dependencies') {
                   9754:             my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
                   9755:             $modify_output .= &start_data_table_row().
                   9756:                               '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
                   9757:                               '<img src="'.&icon($embed_file).'" border="0" />'.
                   9758:                               '&nbsp;<span class="LC_filename">'.$embed_file.'</span></a></td>'.
                   9759:                               '<td>'.$size.'</td>'.
                   9760:                               '<td>'.$mtime.'</td>'.
                   9761:                               '<td><label><input type="checkbox" name="mod_upload_dep" '.
                   9762:                               'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
                   9763:                               $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
                   9764:                               '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
                   9765:                               &embedded_file_element('upload_embedded',$counter,
                   9766:                                                      $embed_file,\%mapping,
                   9767:                                                      $allfiles,$codebase,'modify').
                   9768:                               '</div></td>'.
                   9769:                               &end_data_table_row()."\n";
                   9770:             $counter ++;
                   9771:         } else {
                   9772:             $upload_output .= &start_data_table_row().
                   9773:                               '<td><span class="LC_filename">'.$embed_file.'</span></td>';
                   9774:                               '<td><span class="LC_warning">'.&mt('Already exists').'</span></td>'.
                   9775:                               &Apache::loncommon::end_data_table_row()."\n";
                   9776:         }
                   9777:     }
                   9778:     my $delidx = $counter;
                   9779:     foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
                   9780:         my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
                   9781:         $delete_output .= &start_data_table_row().
                   9782:                           '<td><img src="'.&icon($oldfile).'" />'.
                   9783:                           '&nbsp;<span class="LC_filename">'.$oldfile.'</span></td>'.
                   9784:                           '<td>'.$size.'</td>'.
                   9785:                           '<td>'.$mtime.'</td>'.
                   9786:                           '<td><label><input type="checkbox" name="del_upload_dep" '.
                   9787:                           ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
                   9788:                           &embedded_file_element('upload_embedded',$delidx,
                   9789:                                                  $oldfile,\%mapping,$allfiles,
                   9790:                                                  $codebase,'delete').'</td>'.
                   9791:                           &end_data_table_row()."\n"; 
                   9792:         $numunused ++;
                   9793:         $delidx ++;
1.987     raeburn  9794:     }
                   9795:     if ($upload_output) {
                   9796:         $upload_output = &start_data_table().
                   9797:                          $upload_output.
                   9798:                          &end_data_table()."\n";
                   9799:     }
1.1071    raeburn  9800:     if ($modify_output) {
                   9801:         $modify_output = &start_data_table().
                   9802:                          &start_data_table_header_row().
                   9803:                          '<th>'.&mt('File').'</th>'.
                   9804:                          '<th>'.&mt('Size (KB)').'</th>'.
                   9805:                          '<th>'.&mt('Modified').'</th>'.
                   9806:                          '<th>'.&mt('Upload replacement?').'</th>'.
                   9807:                          &end_data_table_header_row().
                   9808:                          $modify_output.
                   9809:                          &end_data_table()."\n";
                   9810:     }
                   9811:     if ($delete_output) {
                   9812:         $delete_output = &start_data_table().
                   9813:                          &start_data_table_header_row().
                   9814:                          '<th>'.&mt('File').'</th>'.
                   9815:                          '<th>'.&mt('Size (KB)').'</th>'.
                   9816:                          '<th>'.&mt('Modified').'</th>'.
                   9817:                          '<th>'.&mt('Delete?').'</th>'.
                   9818:                          &end_data_table_header_row().
                   9819:                          $delete_output.
                   9820:                          &end_data_table()."\n";
                   9821:     }
1.987     raeburn  9822:     my $applies = 0;
                   9823:     if ($numremref) {
                   9824:         $applies ++;
                   9825:     }
                   9826:     if ($numinvalid) {
                   9827:         $applies ++;
                   9828:     }
                   9829:     if ($numexisting) {
                   9830:         $applies ++;
                   9831:     }
1.1071    raeburn  9832:     if ($counter || $numunused) {
1.987     raeburn  9833:         $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
                   9834:                   ' method="post" enctype="multipart/form-data">'."\n".
1.1071    raeburn  9835:                   $state.'<h3>'.$heading.'</h3>'; 
                   9836:         if ($actionurl eq '/adm/dependencies') {
                   9837:             if ($numnew) {
                   9838:                 $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
                   9839:                            '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
                   9840:                            $upload_output.'<br />'."\n";
                   9841:             }
                   9842:             if ($numexisting) {
                   9843:                 $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
                   9844:                            '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
                   9845:                            $modify_output.'<br />'."\n";
                   9846:                            $buttontext = &mt('Save changes');
                   9847:             }
                   9848:             if ($numunused) {
                   9849:                 $output .= '<h4>'.&mt('Unused files').'</h4>'.
                   9850:                            '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
                   9851:                            $delete_output.'<br />'."\n";
                   9852:                            $buttontext = &mt('Save changes');
                   9853:             }
                   9854:         } else {
                   9855:             $output .= $upload_output.'<br />'."\n";
                   9856:         }
                   9857:         $output .= '<input type ="hidden" name="number_embedded_items" value="'.
                   9858:                    $counter.'" />'."\n";
                   9859:         if ($actionurl eq '/adm/dependencies') { 
                   9860:             $output .= '<input type ="hidden" name="number_newemb_items" value="'.
                   9861:                        $numnew.'" />'."\n";
                   9862:         } elsif ($actionurl eq '') {
1.987     raeburn  9863:             $output .=  '<input type="hidden" name="phase" value="three" />';
                   9864:         }
                   9865:     } elsif ($applies) {
                   9866:         $output = '<b>'.&mt('Referenced files').'</b>:<br />';
                   9867:         if ($applies > 1) {
                   9868:             $output .=  
                   9869:                 &mt('No files need to be uploaded, as one of the following applies to each reference:').'<ul>';
                   9870:             if ($numremref) {
                   9871:                 $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
                   9872:             }
                   9873:             if ($numinvalid) {
                   9874:                 $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
                   9875:             }
                   9876:             if ($numexisting) {
                   9877:                 $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
                   9878:             }
                   9879:             $output .= '</ul><br />';
                   9880:         } elsif ($numremref) {
                   9881:             $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
                   9882:         } elsif ($numinvalid) {
                   9883:             $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
                   9884:         } elsif ($numexisting) {
                   9885:             $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
                   9886:         }
                   9887:         $output .= $upload_output.'<br />';
                   9888:     }
                   9889:     my ($pathchange_output,$chgcount);
1.1071    raeburn  9890:     $chgcount = $counter;
1.987     raeburn  9891:     if (keys(%pathchanges) > 0) {
                   9892:         foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071    raeburn  9893:             if ($counter) {
1.987     raeburn  9894:                 $output .= &embedded_file_element('pathchange',$chgcount,
                   9895:                                                   $embed_file,\%mapping,
1.1071    raeburn  9896:                                                   $allfiles,$codebase,'change');
1.987     raeburn  9897:             } else {
                   9898:                 $pathchange_output .= 
                   9899:                     &start_data_table_row().
                   9900:                     '<td><input type ="checkbox" name="namechange" value="'.
                   9901:                     $chgcount.'" checked="checked" /></td>'.
                   9902:                     '<td>'.$mapping{$embed_file}.'</td>'.
                   9903:                     '<td>'.$embed_file.
                   9904:                     &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071    raeburn  9905:                                            \%mapping,$allfiles,$codebase,'change').
1.987     raeburn  9906:                     '</td>'.&end_data_table_row();
1.660     raeburn  9907:             }
1.987     raeburn  9908:             $numpathchg ++;
                   9909:             $chgcount ++;
1.660     raeburn  9910:         }
                   9911:     }
1.1071    raeburn  9912:     if ($counter) {
1.987     raeburn  9913:         if ($numpathchg) {
                   9914:             $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
                   9915:                        $numpathchg.'" />'."\n";
                   9916:         }
                   9917:         if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') || 
                   9918:             ($actionurl eq '/adm/imsimport')) {
                   9919:             $output .= '<input type="hidden" name="phase" value="three" />'."\n";
                   9920:         } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
                   9921:             $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071    raeburn  9922:         } elsif ($actionurl eq '/adm/dependencies') {
                   9923:             $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987     raeburn  9924:         }
1.1071    raeburn  9925:         $output .=  '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987     raeburn  9926:     } elsif ($numpathchg) {
                   9927:         my %pathchange = ();
                   9928:         $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
                   9929:         if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
                   9930:             $output .= '<p>'.&mt('or').'</p>'; 
                   9931:         } 
                   9932:     }
1.1071    raeburn  9933:     return ($output,$counter,$numpathchg);
1.987     raeburn  9934: }
                   9935: 
                   9936: sub embedded_file_element {
1.1071    raeburn  9937:     my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987     raeburn  9938:     return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
                   9939:                    (ref($codebase) eq 'HASH'));
                   9940:     my $output;
1.1071    raeburn  9941:     if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987     raeburn  9942:        $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
                   9943:     }
                   9944:     $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
                   9945:                &escape($embed_file).'" />';
                   9946:     unless (($context eq 'upload_embedded') && 
                   9947:             ($mapping->{$embed_file} eq $embed_file)) {
                   9948:         $output .='
                   9949:         <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
                   9950:     }
                   9951:     my $attrib;
                   9952:     if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
                   9953:         $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
                   9954:     }
                   9955:     $output .=
                   9956:         "\n\t\t".
                   9957:         '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
                   9958:         $attrib.'" />';
                   9959:     if (exists($codebase->{$mapping->{$embed_file}})) {
                   9960:         $output .=
                   9961:             "\n\t\t".
                   9962:             '<input name="codebase_'.$num.'" type="hidden" value="'.
                   9963:             &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984     raeburn  9964:     }
1.987     raeburn  9965:     return $output;
1.660     raeburn  9966: }
                   9967: 
1.1071    raeburn  9968: sub get_dependency_details {
                   9969:     my ($currfile,$currsubfile,$embed_file) = @_;
                   9970:     my ($size,$mtime,$showsize,$showmtime);
                   9971:     if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
                   9972:         if ($embed_file =~ m{/}) {
                   9973:             my ($path,$fname) = split(/\//,$embed_file);
                   9974:             if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
                   9975:                 ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
                   9976:             }
                   9977:         } else {
                   9978:             if (ref($currfile->{$embed_file}) eq 'ARRAY') {
                   9979:                 ($size,$mtime) = @{$currfile->{$embed_file}};
                   9980:             }
                   9981:         }
                   9982:         $showsize = $size/1024.0;
                   9983:         $showsize = sprintf("%.1f",$showsize);
                   9984:         if ($mtime > 0) {
                   9985:             $showmtime = &Apache::lonlocal::locallocaltime($mtime);
                   9986:         }
                   9987:     }
                   9988:     return ($showsize,$showmtime);
                   9989: }
                   9990: 
                   9991: sub ask_embedded_js {
                   9992:     return <<"END";
                   9993: <script type="text/javascript"">
                   9994: // <![CDATA[
                   9995: function toggleBrowse(counter) {
                   9996:     var chkboxid = document.getElementById('mod_upload_dep_'+counter);
                   9997:     var fileid = document.getElementById('embedded_item_'+counter);
                   9998:     var uploaddivid = document.getElementById('moduploaddep_'+counter);
                   9999:     if (chkboxid.checked == true) {
                   10000:         uploaddivid.style.display='block';
                   10001:     } else {
                   10002:         uploaddivid.style.display='none';
                   10003:         fileid.value = '';
                   10004:     }
                   10005: }
                   10006: // ]]>
                   10007: </script>
                   10008: 
                   10009: END
                   10010: }
                   10011: 
1.661     raeburn  10012: sub upload_embedded {
                   10013:     my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987     raeburn  10014:         $current_disk_usage,$hiddenstate,$actionurl) = @_;
                   10015:     my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661     raeburn  10016:     for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
                   10017:         next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
                   10018:         my $orig_uploaded_filename =
                   10019:             $env{'form.embedded_item_'.$i.'.filename'};
1.987     raeburn  10020:         foreach my $type ('orig','ref','attrib','codebase') {
                   10021:             if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
                   10022:                 $env{'form.embedded_'.$type.'_'.$i} =
                   10023:                     &unescape($env{'form.embedded_'.$type.'_'.$i});
                   10024:             }
                   10025:         }
1.661     raeburn  10026:         my ($path,$fname) =
                   10027:             ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
                   10028:         # no path, whole string is fname
                   10029:         if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
                   10030:         $fname = &Apache::lonnet::clean_filename($fname);
                   10031:         # See if there is anything left
                   10032:         next if ($fname eq '');
                   10033: 
                   10034:         # Check if file already exists as a file or directory.
                   10035:         my ($state,$msg);
                   10036:         if ($context eq 'portfolio') {
                   10037:             my $port_path = $dirpath;
                   10038:             if ($group ne '') {
                   10039:                 $port_path = "groups/$group/$port_path";
                   10040:             }
1.987     raeburn  10041:             ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
                   10042:                                               $fname,$group,'embedded_item_'.$i,
1.661     raeburn  10043:                                               $dir_root,$port_path,$disk_quota,
                   10044:                                               $current_disk_usage,$uname,$udom);
                   10045:             if ($state eq 'will_exceed_quota'
1.984     raeburn  10046:                 || $state eq 'file_locked') {
1.661     raeburn  10047:                 $output .= $msg;
                   10048:                 next;
                   10049:             }
                   10050:         } elsif (($context eq 'author') || ($context eq 'testbank')) {
                   10051:             ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
                   10052:             if ($state eq 'exists') {
                   10053:                 $output .= $msg;
                   10054:                 next;
                   10055:             }
                   10056:         }
                   10057:         # Check if extension is valid
                   10058:         if (($fname =~ /\.(\w+)$/) &&
                   10059:             (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.987     raeburn  10060:             $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  10061:             next;
                   10062:         } elsif (($fname =~ /\.(\w+)$/) &&
                   10063:                  (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987     raeburn  10064:             $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661     raeburn  10065:             next;
                   10066:         } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.987     raeburn  10067:             $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2).'<br />';
1.661     raeburn  10068:             next;
                   10069:         }
                   10070:         $env{'form.embedded_item_'.$i.'.filename'}=$fname;
                   10071:         if ($context eq 'portfolio') {
1.984     raeburn  10072:             my $result;
                   10073:             if ($state eq 'existingfile') {
                   10074:                 $result=
                   10075:                     &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.987     raeburn  10076:                                                     $dirpath.$env{'form.currentpath'}.$path);
1.661     raeburn  10077:             } else {
1.984     raeburn  10078:                 $result=
                   10079:                     &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987     raeburn  10080:                                                     $dirpath.
                   10081:                                                     $env{'form.currentpath'}.$path);
1.984     raeburn  10082:                 if ($result !~ m|^/uploaded/|) {
                   10083:                     $output .= '<span class="LC_error">'
                   10084:                                .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
                   10085:                                ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
                   10086:                                .'</span><br />';
                   10087:                     next;
                   10088:                 } else {
1.987     raeburn  10089:                     $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
                   10090:                                $path.$fname.'</span>').'<br />';     
1.984     raeburn  10091:                 }
1.661     raeburn  10092:             }
1.987     raeburn  10093:         } elsif ($context eq 'coursedoc') {
                   10094:             my $result =
                   10095:                 &Apache::lonnet::userfileupload('embedded_item_'.$i,'coursedoc',
                   10096:                                                 $dirpath.'/'.$path);
                   10097:             if ($result !~ m|^/uploaded/|) {
                   10098:                 $output .= '<span class="LC_error">'
                   10099:                            .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
                   10100:                            ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
                   10101:                            .'</span><br />';
                   10102:                     next;
                   10103:             } else {
                   10104:                 $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
                   10105:                            $path.$fname.'</span>').'<br />';
                   10106:             }
1.661     raeburn  10107:         } else {
                   10108: # Save the file
                   10109:             my $target = $env{'form.embedded_item_'.$i};
                   10110:             my $fullpath = $dir_root.$dirpath.'/'.$path;
                   10111:             my $dest = $fullpath.$fname;
                   10112:             my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027    raeburn  10113:             my @parts=split(/\//,"$dirpath/$path");
1.661     raeburn  10114:             my $count;
                   10115:             my $filepath = $dir_root;
1.1027    raeburn  10116:             foreach my $subdir (@parts) {
                   10117:                 $filepath .= "/$subdir";
                   10118:                 if (!-e $filepath) {
1.661     raeburn  10119:                     mkdir($filepath,0770);
                   10120:                 }
                   10121:             }
                   10122:             my $fh;
                   10123:             if (!open($fh,'>'.$dest)) {
                   10124:                 &Apache::lonnet::logthis('Failed to create '.$dest);
                   10125:                 $output .= '<span class="LC_error">'.
1.1071    raeburn  10126:                            &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
                   10127:                                $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661     raeburn  10128:                            '</span><br />';
                   10129:             } else {
                   10130:                 if (!print $fh $env{'form.embedded_item_'.$i}) {
                   10131:                     &Apache::lonnet::logthis('Failed to write to '.$dest);
                   10132:                     $output .= '<span class="LC_error">'.
1.1071    raeburn  10133:                               &mt('An error occurred while writing the file [_1] for embedded element [_2].',
                   10134:                                   $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661     raeburn  10135:                               '</span><br />';
                   10136:                 } else {
1.987     raeburn  10137:                     $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
                   10138:                                $url.'</span>').'<br />';
                   10139:                     unless ($context eq 'testbank') {
                   10140:                         $footer .= &mt('View embedded file: [_1]',
                   10141:                                        '<a href="'.$url.'">'.$fname.'</a>').'<br />';
                   10142:                     }
                   10143:                 }
                   10144:                 close($fh);
                   10145:             }
                   10146:         }
                   10147:         if ($env{'form.embedded_ref_'.$i}) {
                   10148:             $pathchange{$i} = 1;
                   10149:         }
                   10150:     }
                   10151:     if ($output) {
                   10152:         $output = '<p>'.$output.'</p>';
                   10153:     }
                   10154:     $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
                   10155:     $returnflag = 'ok';
1.1071    raeburn  10156:     my $numpathchgs = scalar(keys(%pathchange));
                   10157:     if ($numpathchgs > 0) {
1.987     raeburn  10158:         if ($context eq 'portfolio') {
                   10159:             $output .= '<p>'.&mt('or').'</p>';
                   10160:         } elsif ($context eq 'testbank') {
1.1071    raeburn  10161:             $output .=  '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
                   10162:                                   '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987     raeburn  10163:             $returnflag = 'modify_orightml';
                   10164:         }
                   10165:     }
1.1071    raeburn  10166:     return ($output.$footer,$returnflag,$numpathchgs);
1.987     raeburn  10167: }
                   10168: 
                   10169: sub modify_html_form {
                   10170:     my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
                   10171:     my $end = 0;
                   10172:     my $modifyform;
                   10173:     if ($context eq 'upload_embedded') {
                   10174:         return unless (ref($pathchange) eq 'HASH');
                   10175:         if ($env{'form.number_embedded_items'}) {
                   10176:             $end += $env{'form.number_embedded_items'};
                   10177:         }
                   10178:         if ($env{'form.number_pathchange_items'}) {
                   10179:             $end += $env{'form.number_pathchange_items'};
                   10180:         }
                   10181:         if ($end) {
                   10182:             for (my $i=0; $i<$end; $i++) {
                   10183:                 if ($i < $env{'form.number_embedded_items'}) {
                   10184:                     next unless($pathchange->{$i});
                   10185:                 }
                   10186:                 $modifyform .=
                   10187:                     &start_data_table_row().
                   10188:                     '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
                   10189:                     'checked="checked" /></td>'.
                   10190:                     '<td>'.$env{'form.embedded_ref_'.$i}.
                   10191:                     '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
                   10192:                     &escape($env{'form.embedded_ref_'.$i}).'" />'.
                   10193:                     '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
                   10194:                     &escape($env{'form.embedded_codebase_'.$i}).'" />'.
                   10195:                     '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
                   10196:                     &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
                   10197:                     '<td>'.$env{'form.embedded_orig_'.$i}.
                   10198:                     '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
                   10199:                     &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
                   10200:                     &end_data_table_row();
1.1071    raeburn  10201:             }
1.987     raeburn  10202:         }
                   10203:     } else {
                   10204:         $modifyform = $pathchgtable;
                   10205:         if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
                   10206:             $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
                   10207:         } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
                   10208:             $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
                   10209:         }
                   10210:     }
                   10211:     if ($modifyform) {
1.1071    raeburn  10212:         if ($actionurl eq '/adm/dependencies') {
                   10213:             $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
                   10214:         }
1.987     raeburn  10215:         return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
                   10216:                '<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".
                   10217:                '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
                   10218:                '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
                   10219:                '</ol></p>'."\n".'<p>'.
                   10220:                &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
                   10221:                '<form method="post" name="refchanger" action="'.$actionurl.'">'.
                   10222:                &start_data_table()."\n".
                   10223:                &start_data_table_header_row().
                   10224:                '<th>'.&mt('Change?').'</th>'.
                   10225:                '<th>'.&mt('Current reference').'</th>'.
                   10226:                '<th>'.&mt('Required reference').'</th>'.
                   10227:                &end_data_table_header_row()."\n".
                   10228:                $modifyform.
                   10229:                &end_data_table().'<br />'."\n".$hiddenstate.
                   10230:                '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
                   10231:                '</form>'."\n";
                   10232:     }
                   10233:     return;
                   10234: }
                   10235: 
                   10236: sub modify_html_refs {
                   10237:     my ($context,$dirpath,$uname,$udom,$dir_root) = @_;
                   10238:     my $container;
                   10239:     if ($context eq 'portfolio') {
                   10240:         $container = $env{'form.container'};
                   10241:     } elsif ($context eq 'coursedoc') {
                   10242:         $container = $env{'form.primaryurl'};
1.1071    raeburn  10243:     } elsif ($context eq 'manage_dependencies') {
                   10244:         (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
                   10245:         $container = "/$container";
1.987     raeburn  10246:     } else {
1.1027    raeburn  10247:         $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987     raeburn  10248:     }
                   10249:     my (%allfiles,%codebase,$output,$content);
                   10250:     my @changes = &get_env_multiple('form.namechange');
1.1071    raeburn  10251:     unless (@changes > 0) {
                   10252:         if (wantarray) {
                   10253:             return ('',0,0); 
                   10254:         } else {
                   10255:             return;
                   10256:         }
                   10257:     }
                   10258:     if (($context eq 'portfolio') || ($context eq 'coursedoc') || 
                   10259:         ($context eq 'manage_dependencies')) {
                   10260:         unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
                   10261:             if (wantarray) {
                   10262:                 return ('',0,0);
                   10263:             } else {
                   10264:                 return;
                   10265:             }
                   10266:         } 
1.987     raeburn  10267:         $content = &Apache::lonnet::getfile($container);
1.1071    raeburn  10268:         if ($content eq '-1') {
                   10269:             if (wantarray) {
                   10270:                 return ('',0,0);
                   10271:             } else {
                   10272:                 return;
                   10273:             }
                   10274:         }
1.987     raeburn  10275:     } else {
1.1071    raeburn  10276:         unless ($container =~ /^\Q$dir_root\E/) {
                   10277:             if (wantarray) {
                   10278:                 return ('',0,0);
                   10279:             } else {
                   10280:                 return;
                   10281:             }
                   10282:         } 
1.987     raeburn  10283:         if (open(my $fh,"<$container")) {
                   10284:             $content = join('', <$fh>);
                   10285:             close($fh);
                   10286:         } else {
1.1071    raeburn  10287:             if (wantarray) {
                   10288:                 return ('',0,0);
                   10289:             } else {
                   10290:                 return;
                   10291:             }
1.987     raeburn  10292:         }
                   10293:     }
                   10294:     my ($count,$codebasecount) = (0,0);
                   10295:     my $mm = new File::MMagic;
                   10296:     my $mime_type = $mm->checktype_contents($content);
                   10297:     if ($mime_type eq 'text/html') {
                   10298:         my $parse_result = 
                   10299:             &Apache::lonnet::extract_embedded_items($container,\%allfiles,
                   10300:                                                     \%codebase,\$content);
                   10301:         if ($parse_result eq 'ok') {
                   10302:             foreach my $i (@changes) {
                   10303:                 my $orig = &unescape($env{'form.embedded_orig_'.$i});
                   10304:                 my $ref = &unescape($env{'form.embedded_ref_'.$i});
                   10305:                 if ($allfiles{$ref}) {
                   10306:                     my $newname =  $orig;
                   10307:                     my ($attrib_regexp,$codebase);
1.1006    raeburn  10308:                     $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987     raeburn  10309:                     if ($attrib_regexp =~ /:/) {
                   10310:                         $attrib_regexp =~ s/\:/|/g;
                   10311:                     }
                   10312:                     if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
                   10313:                         my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
                   10314:                         $count += $numchg;
                   10315:                     }
                   10316:                     if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006    raeburn  10317:                         $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987     raeburn  10318:                         my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
                   10319:                         $codebasecount ++;
                   10320:                     }
                   10321:                 }
                   10322:             }
                   10323:             if ($count || $codebasecount) {
                   10324:                 my $saveresult;
1.1071    raeburn  10325:                 if (($context eq 'portfolio') || ($context eq 'coursedoc') || 
                   10326:                     ($context eq 'manage_dependencies')) {
1.987     raeburn  10327:                     my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
                   10328:                     if ($url eq $container) {
                   10329:                         my ($fname) = ($container =~ m{/([^/]+)$});
                   10330:                         $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
                   10331:                                             $count,'<span class="LC_filename">'.
1.1071    raeburn  10332:                                             $fname.'</span>').'</p>';
1.987     raeburn  10333:                     } else {
                   10334:                          $output = '<p class="LC_error">'.
                   10335:                                    &mt('Error: update failed for: [_1].',
                   10336:                                    '<span class="LC_filename">'.
                   10337:                                    $container.'</span>').'</p>';
                   10338:                     }
                   10339:                 } else {
                   10340:                     if (open(my $fh,">$container")) {
                   10341:                         print $fh $content;
                   10342:                         close($fh);
                   10343:                         $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
                   10344:                                   $count,'<span class="LC_filename">'.
                   10345:                                   $container.'</span>').'</p>';
1.661     raeburn  10346:                     } else {
1.987     raeburn  10347:                          $output = '<p class="LC_error">'.
                   10348:                                    &mt('Error: could not update [_1].',
                   10349:                                    '<span class="LC_filename">'.
                   10350:                                    $container.'</span>').'</p>';
1.661     raeburn  10351:                     }
                   10352:                 }
                   10353:             }
1.987     raeburn  10354:         } else {
                   10355:             &logthis('Failed to parse '.$container.
                   10356:                      ' to modify references: '.$parse_result);
1.661     raeburn  10357:         }
                   10358:     }
1.1071    raeburn  10359:     if (wantarray) {
                   10360:         return ($output,$count,$codebasecount);
                   10361:     } else {
                   10362:         return $output;
                   10363:     }
1.661     raeburn  10364: }
                   10365: 
                   10366: sub check_for_existing {
                   10367:     my ($path,$fname,$element) = @_;
                   10368:     my ($state,$msg);
                   10369:     if (-d $path.'/'.$fname) {
                   10370:         $state = 'exists';
                   10371:         $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   10372:     } elsif (-e $path.'/'.$fname) {
                   10373:         $state = 'exists';
                   10374:         $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   10375:     }
                   10376:     if ($state eq 'exists') {
                   10377:         $msg = '<span class="LC_error">'.$msg.'</span><br />';
                   10378:     }
                   10379:     return ($state,$msg);
                   10380: }
                   10381: 
                   10382: sub check_for_upload {
                   10383:     my ($path,$fname,$group,$element,$portfolio_root,$port_path,
                   10384:         $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985     raeburn  10385:     my $filesize = length($env{'form.'.$element});
                   10386:     if (!$filesize) {
                   10387:         my $msg = '<span class="LC_error">'.
                   10388:                   &mt('Unable to upload [_1]. (size = [_2] bytes)', 
                   10389:                       '<span class="LC_filename">'.$fname.'</span>',
                   10390:                       $filesize).'<br />'.
1.1007    raeburn  10391:                   &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985     raeburn  10392:                   '</span>';
                   10393:         return ('zero_bytes',$msg);
                   10394:     }
                   10395:     $filesize =  $filesize/1000; #express in k (1024?)
1.661     raeburn  10396:     my $getpropath = 1;
1.1021    raeburn  10397:     my ($dirlistref,$listerror) =
                   10398:          &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661     raeburn  10399:     my $found_file = 0;
                   10400:     my $locked_file = 0;
1.991     raeburn  10401:     my @lockers;
                   10402:     my $navmap;
                   10403:     if ($env{'request.course.id'}) {
                   10404:         $navmap = Apache::lonnavmaps::navmap->new();
                   10405:     }
1.1021    raeburn  10406:     if (ref($dirlistref) eq 'ARRAY') {
                   10407:         foreach my $line (@{$dirlistref}) {
                   10408:             my ($file_name,$rest)=split(/\&/,$line,2);
                   10409:             if ($file_name eq $fname){
                   10410:                 $file_name = $path.$file_name;
                   10411:                 if ($group ne '') {
                   10412:                     $file_name = $group.$file_name;
                   10413:                 }
                   10414:                 $found_file = 1;
                   10415:                 if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
                   10416:                     foreach my $lock (@lockers) {
                   10417:                         if (ref($lock) eq 'ARRAY') {
                   10418:                             my ($symb,$crsid) = @{$lock};
                   10419:                             if ($crsid eq $env{'request.course.id'}) {
                   10420:                                 if (ref($navmap)) {
                   10421:                                     my $res = $navmap->getBySymb($symb);
                   10422:                                     foreach my $part (@{$res->parts()}) { 
                   10423:                                         my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
                   10424:                                         unless (($slot_status == $res->RESERVED) ||
                   10425:                                                 ($slot_status == $res->RESERVED_LOCATION)) {
                   10426:                                             $locked_file = 1;
                   10427:                                         }
1.991     raeburn  10428:                                     }
1.1021    raeburn  10429:                                 } else {
                   10430:                                     $locked_file = 1;
1.991     raeburn  10431:                                 }
                   10432:                             } else {
                   10433:                                 $locked_file = 1;
                   10434:                             }
                   10435:                         }
1.1021    raeburn  10436:                    }
                   10437:                 } else {
                   10438:                     my @info = split(/\&/,$rest);
                   10439:                     my $currsize = $info[6]/1000;
                   10440:                     if ($currsize < $filesize) {
                   10441:                         my $extra = $filesize - $currsize;
                   10442:                         if (($current_disk_usage + $extra) > $disk_quota) {
                   10443:                             my $msg = '<span class="LC_error">'.
                   10444:                                       &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.',
                   10445:                                           '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</span>'.
                   10446:                                       '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
                   10447:                                                    $disk_quota,$current_disk_usage);
                   10448:                             return ('will_exceed_quota',$msg);
                   10449:                         }
1.984     raeburn  10450:                     }
                   10451:                 }
1.661     raeburn  10452:             }
                   10453:         }
                   10454:     }
                   10455:     if (($current_disk_usage + $filesize) > $disk_quota){
                   10456:         my $msg = '<span class="LC_error">'.
                   10457:                 &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
                   10458:                   '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
                   10459:         return ('will_exceed_quota',$msg);
                   10460:     } elsif ($found_file) {
                   10461:         if ($locked_file) {
                   10462:             my $msg = '<span class="LC_error">';
                   10463:             $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>');
                   10464:             $msg .= '</span><br />';
                   10465:             $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
                   10466:             return ('file_locked',$msg);
                   10467:         } else {
                   10468:             my $msg = '<span class="LC_error">';
1.984     raeburn  10469:             $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  10470:             $msg .= '</span>';
1.984     raeburn  10471:             return ('existingfile',$msg);
1.661     raeburn  10472:         }
                   10473:     }
                   10474: }
                   10475: 
1.987     raeburn  10476: sub check_for_traversal {
                   10477:     my ($path,$url,$toplevel) = @_;
                   10478:     my @parts=split(/\//,$path);
                   10479:     my $cleanpath;
                   10480:     my $fullpath = $url;
                   10481:     for (my $i=0;$i<@parts;$i++) {
                   10482:         next if ($parts[$i] eq '.');
                   10483:         if ($parts[$i] eq '..') {
                   10484:             $fullpath =~ s{([^/]+/)$}{};
                   10485:         } else {
                   10486:             $fullpath .= $parts[$i].'/';
                   10487:         }
                   10488:     }
                   10489:     if ($fullpath =~ /^\Q$url\E(.*)$/) {
                   10490:         $cleanpath = $1;
                   10491:     } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
                   10492:         my $curr_toprel = $1;
                   10493:         my @parts = split(/\//,$curr_toprel);
                   10494:         my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
                   10495:         my @urlparts = split(/\//,$url_toprel);
                   10496:         my $doubledots;
                   10497:         my $startdiff = -1;
                   10498:         for (my $i=0; $i<@urlparts; $i++) {
                   10499:             if ($startdiff == -1) {
                   10500:                 unless ($urlparts[$i] eq $parts[$i]) {
                   10501:                     $startdiff = $i;
                   10502:                     $doubledots .= '../';
                   10503:                 }
                   10504:             } else {
                   10505:                 $doubledots .= '../';
                   10506:             }
                   10507:         }
                   10508:         if ($startdiff > -1) {
                   10509:             $cleanpath = $doubledots;
                   10510:             for (my $i=$startdiff; $i<@parts; $i++) {
                   10511:                 $cleanpath .= $parts[$i].'/';
                   10512:             }
                   10513:         }
                   10514:     }
                   10515:     $cleanpath =~ s{(/)$}{};
                   10516:     return $cleanpath;
                   10517: }
1.31      albertel 10518: 
1.1053    raeburn  10519: sub is_archive_file {
                   10520:     my ($mimetype) = @_;
                   10521:     if (($mimetype eq 'application/octet-stream') ||
                   10522:         ($mimetype eq 'application/x-stuffit') ||
                   10523:         ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
                   10524:         return 1;
                   10525:     }
                   10526:     return;
                   10527: }
                   10528: 
                   10529: sub decompress_form {
1.1065    raeburn  10530:     my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053    raeburn  10531:     my %lt = &Apache::lonlocal::texthash (
                   10532:         this => 'This file is an archive file.',
1.1067    raeburn  10533:         camt => 'This file is a Camtasia archive file.',
1.1065    raeburn  10534:         itsc => 'Its contents are as follows:',
1.1053    raeburn  10535:         youm => 'You may wish to extract its contents.',
                   10536:         extr => 'Extract contents',
1.1067    raeburn  10537:         auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
                   10538:         proa => 'Process automatically?',
1.1053    raeburn  10539:         yes  => 'Yes',
                   10540:         no   => 'No',
1.1067    raeburn  10541:         fold => 'Title for folder containing movie',
                   10542:         movi => 'Title for page containing embedded movie', 
1.1053    raeburn  10543:     );
1.1065    raeburn  10544:     my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067    raeburn  10545:     my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065    raeburn  10546:     my $info = &list_archive_contents($fileloc,\@paths);
                   10547:     if (@paths) {
                   10548:         foreach my $path (@paths) {
                   10549:             $path =~ s{^/}{};
1.1067    raeburn  10550:             if ($path =~ m{^([^/]+)/$}) {
                   10551:                 $topdir = $1;
                   10552:             }
1.1065    raeburn  10553:             if ($path =~ m{^([^/]+)/}) {
                   10554:                 $toplevel{$1} = $path;
                   10555:             } else {
                   10556:                 $toplevel{$path} = $path;
                   10557:             }
                   10558:         }
                   10559:     }
1.1067    raeburn  10560:     if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
                   10561:         my @camtasia = ("$topdir/","$topdir/index.html",
                   10562:                         "$topdir/media/",
                   10563:                         "$topdir/media/$topdir.mp4",
                   10564:                         "$topdir/media/FirstFrame.png",
                   10565:                         "$topdir/media/player.swf",
                   10566:                         "$topdir/media/swfobject.js",
                   10567:                         "$topdir/media/expressInstall.swf");
                   10568:         my @diffs = &compare_arrays(\@paths,\@camtasia);
                   10569:         if (@diffs == 0) {
                   10570:             $is_camtasia = 1;
                   10571:         }
                   10572:     }
                   10573:     my $output;
                   10574:     if ($is_camtasia) {
                   10575:         $output = <<"ENDCAM";
                   10576: <script type="text/javascript" language="Javascript">
                   10577: // <![CDATA[
                   10578: 
                   10579: function camtasiaToggle() {
                   10580:     for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
                   10581:         if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
                   10582:             if (document.uploaded_decompress.autoextract_camtasia[i].value == 1) {
                   10583: 
                   10584:                 document.getElementById('camtasia_titles').style.display='block';
                   10585:             } else {
                   10586:                 document.getElementById('camtasia_titles').style.display='none';
                   10587:             }
                   10588:         }
                   10589:     }
                   10590:     return;
                   10591: }
                   10592: 
                   10593: // ]]>
                   10594: </script>
                   10595: <p>$lt{'camt'}</p>
                   10596: ENDCAM
1.1065    raeburn  10597:     } else {
1.1067    raeburn  10598:         $output = '<p>'.$lt{'this'};
                   10599:         if ($info eq '') {
                   10600:             $output .= ' '.$lt{'youm'}.'</p>'."\n";
                   10601:         } else {
                   10602:             $output .= ' '.$lt{'itsc'}.'</p>'."\n".
                   10603:                        '<div><pre>'.$info.'</pre></div>';
                   10604:         }
1.1065    raeburn  10605:     }
1.1067    raeburn  10606:     $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065    raeburn  10607:     my $duplicates;
                   10608:     my $num = 0;
                   10609:     if (ref($dirlist) eq 'ARRAY') {
                   10610:         foreach my $item (@{$dirlist}) {
                   10611:             if (ref($item) eq 'ARRAY') {
                   10612:                 if (exists($toplevel{$item->[0]})) {
                   10613:                     $duplicates .= 
                   10614:                         &start_data_table_row().
                   10615:                         '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
                   10616:                         'value="0" checked="checked" />'.&mt('No').'</label>'.
                   10617:                         '&nbsp;<label><input type="radio" name="archive_overwrite_'.$num.'" '.
                   10618:                         'value="1" />'.&mt('Yes').'</label>'.
                   10619:                         '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
                   10620:                         '<td>'.$item->[0].'</td>';
                   10621:                     if ($item->[2]) {
                   10622:                         $duplicates .= '<td>'.&mt('Directory').'</td>';
                   10623:                     } else {
                   10624:                         $duplicates .= '<td>'.&mt('File').'</td>';
                   10625:                     }
                   10626:                     $duplicates .= '<td>'.$item->[3].'</td>'.
                   10627:                                    '<td>'.
                   10628:                                    &Apache::lonlocal::locallocaltime($item->[4]).
                   10629:                                    '</td>'.
                   10630:                                    &end_data_table_row();
                   10631:                     $num ++;
                   10632:                 }
                   10633:             }
                   10634:         }
                   10635:     }
                   10636:     my $itemcount;
                   10637:     if (@paths > 0) {
                   10638:         $itemcount = scalar(@paths);
                   10639:     } else {
                   10640:         $itemcount = 1;
                   10641:     }
1.1067    raeburn  10642:     if ($is_camtasia) {
                   10643:         $output .= $lt{'auto'}.'<br />'.
                   10644:                    '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
                   10645:                    '<input type="radio" name="autoextract_camtasia" value="1" onclick="javascript:camtasiaToggle();" checked="checked" />'.
                   10646:                    $lt{'yes'}.'</label>&nbsp;<label>'.
                   10647:                    '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
                   10648:                    $lt{'no'}.'</label></span><br />'.
                   10649:                    '<div id="camtasia_titles" style="display:block">'.
                   10650:                    &Apache::lonhtmlcommon::start_pick_box().
                   10651:                    &Apache::lonhtmlcommon::row_title($lt{'fold'}).
                   10652:                    '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
                   10653:                    &Apache::lonhtmlcommon::row_closure().
                   10654:                    &Apache::lonhtmlcommon::row_title($lt{'movi'}).
                   10655:                    '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
                   10656:                    &Apache::lonhtmlcommon::row_closure(1).
                   10657:                    &Apache::lonhtmlcommon::end_pick_box().
                   10658:                    '</div>';
                   10659:     }
1.1065    raeburn  10660:     $output .= 
                   10661:         '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067    raeburn  10662:         '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
                   10663:         "\n";
1.1065    raeburn  10664:     if ($duplicates ne '') {
                   10665:         $output .= '<p><span class="LC_warning">'.
                   10666:                    &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.  
                   10667:                    &start_data_table().
                   10668:                    &start_data_table_header_row().
                   10669:                    '<th>'.&mt('Overwrite?').'</th>'.
                   10670:                    '<th>'.&mt('Name').'</th>'.
                   10671:                    '<th>'.&mt('Type').'</th>'.
                   10672:                    '<th>'.&mt('Size').'</th>'.
                   10673:                    '<th>'.&mt('Last modified').'</th>'.
                   10674:                    &end_data_table_header_row().
                   10675:                    $duplicates.
                   10676:                    &end_data_table().
                   10677:                    '</p>';
                   10678:     }
1.1067    raeburn  10679:     $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053    raeburn  10680:     if (ref($hiddenelements) eq 'HASH') {
                   10681:         foreach my $hidden (sort(keys(%{$hiddenelements}))) {
                   10682:             $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
                   10683:         }
                   10684:     }
                   10685:     $output .= <<"END";
1.1067    raeburn  10686: <br />
1.1053    raeburn  10687: <input type="submit" name="decompress" value="$lt{'extr'}" />
                   10688: </form>
                   10689: $noextract
                   10690: END
                   10691:     return $output;
                   10692: }
                   10693: 
1.1065    raeburn  10694: sub decompression_utility {
                   10695:     my ($program) = @_;
                   10696:     my @utilities = ('tar','gunzip','bunzip2','unzip'); 
                   10697:     my $location;
                   10698:     if (grep(/^\Q$program\E$/,@utilities)) { 
                   10699:         foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
                   10700:                          '/usr/sbin/') {
                   10701:             if (-x $dir.$program) {
                   10702:                 $location = $dir.$program;
                   10703:                 last;
                   10704:             }
                   10705:         }
                   10706:     }
                   10707:     return $location;
                   10708: }
                   10709: 
                   10710: sub list_archive_contents {
                   10711:     my ($file,$pathsref) = @_;
                   10712:     my (@cmd,$output);
                   10713:     my $needsregexp;
                   10714:     if ($file =~ /\.zip$/) {
                   10715:         @cmd = (&decompression_utility('unzip'),"-l");
                   10716:         $needsregexp = 1;
                   10717:     } elsif (($file =~ m/\.tar\.gz$/) ||
                   10718:              ($file =~ /\.tgz$/)) {
                   10719:         @cmd = (&decompression_utility('tar'),"-ztf");
                   10720:     } elsif ($file =~ /\.tar\.bz2$/) {
                   10721:         @cmd = (&decompression_utility('tar'),"-jtf");
                   10722:     } elsif ($file =~ m|\.tar$|) {
                   10723:         @cmd = (&decompression_utility('tar'),"-tf");
                   10724:     }
                   10725:     if (@cmd) {
                   10726:         undef($!);
                   10727:         undef($@);
                   10728:         if (open(my $fh,"-|", @cmd, $file)) {
                   10729:             while (my $line = <$fh>) {
                   10730:                 $output .= $line;
                   10731:                 chomp($line);
                   10732:                 my $item;
                   10733:                 if ($needsregexp) {
                   10734:                     ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/); 
                   10735:                 } else {
                   10736:                     $item = $line;
                   10737:                 }
                   10738:                 if ($item ne '') {
                   10739:                     unless (grep(/^\Q$item\E$/,@{$pathsref})) {
                   10740:                         push(@{$pathsref},$item);
                   10741:                     } 
                   10742:                 }
                   10743:             }
                   10744:             close($fh);
                   10745:         }
                   10746:     }
                   10747:     return $output;
                   10748: }
                   10749: 
1.1053    raeburn  10750: sub decompress_uploaded_file {
                   10751:     my ($file,$dir) = @_;
                   10752:     &Apache::lonnet::appenv({'cgi.file' => $file});
                   10753:     &Apache::lonnet::appenv({'cgi.dir' => $dir});
                   10754:     my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
                   10755:     my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
                   10756:     my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
                   10757:     &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
                   10758:     my $decompressed = $env{'cgi.decompressed'};
                   10759:     &Apache::lonnet::delenv('cgi.file');
                   10760:     &Apache::lonnet::delenv('cgi.dir');
                   10761:     &Apache::lonnet::delenv('cgi.decompressed');
                   10762:     return ($decompressed,$result);
                   10763: }
                   10764: 
1.1055    raeburn  10765: sub process_decompression {
                   10766:     my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
                   10767:     my ($dir,$error,$warning,$output);
                   10768:     if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
                   10769:         $error = &mt('File name not a supported archive file type.').
                   10770:                  '<br />'.&mt('File name should end with one of: [_1].',
                   10771:                               '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
                   10772:     } else {
                   10773:         my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
                   10774:         if ($docuhome eq 'no_host') {
                   10775:             $error = &mt('Could not determine home server for course.');
                   10776:         } else {
                   10777:             my @ids=&Apache::lonnet::current_machine_ids();
                   10778:             my $currdir = "$dir_root/$destination";
                   10779:             if (grep(/^\Q$docuhome\E$/,@ids)) {
                   10780:                 $dir = &LONCAPA::propath($docudom,$docuname).
                   10781:                        "$dir_root/$destination";
                   10782:             } else {
                   10783:                 $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
                   10784:                        "$dir_root/$docudom/$docuname/$destination";
                   10785:                 unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
                   10786:                     $error = &mt('Archive file not found.');
                   10787:                 }
                   10788:             }
1.1065    raeburn  10789:             my (@to_overwrite,@to_skip);
                   10790:             if ($env{'form.archive_overwrite_total'} > 0) {
                   10791:                 my $total = $env{'form.archive_overwrite_total'};
                   10792:                 for (my $i=0; $i<$total; $i++) {
                   10793:                     if ($env{'form.archive_overwrite_'.$i} == 1) {
                   10794:                         push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
                   10795:                     } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
                   10796:                         push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
                   10797:                     }
                   10798:                 }
                   10799:             }
                   10800:             my $numskip = scalar(@to_skip);
                   10801:             if (($numskip > 0) && 
                   10802:                 ($numskip == $env{'form.archive_itemcount'})) {
                   10803:                 $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');         
                   10804:             } elsif ($dir eq '') {
1.1055    raeburn  10805:                 $error = &mt('Directory containing archive file unavailable.');
                   10806:             } elsif (!$error) {
1.1065    raeburn  10807:                 my ($decompressed,$display);
                   10808:                 if ($numskip > 0) {
                   10809:                     my $tempdir = time.'_'.$$.int(rand(10000));
                   10810:                     mkdir("$dir/$tempdir",0755);
                   10811:                     system("mv $dir/$file $dir/$tempdir/$file");
                   10812:                     ($decompressed,$display) = 
                   10813:                         &decompress_uploaded_file($file,"$dir/$tempdir");
                   10814:                     foreach my $item (@to_skip) {
                   10815:                         if (($item ne '') && ($item !~ /\.\./)) {
                   10816:                             if (-f "$dir/$tempdir/$item") { 
                   10817:                                 unlink("$dir/$tempdir/$item");
                   10818:                             } elsif (-d "$dir/$tempdir/$item") {
                   10819:                                 system("rm -rf $dir/$tempdir/$item");
                   10820:                             }
                   10821:                         }
                   10822:                     }
                   10823:                     system("mv $dir/$tempdir/* $dir");
                   10824:                     rmdir("$dir/$tempdir");   
                   10825:                 } else {
                   10826:                     ($decompressed,$display) = 
                   10827:                         &decompress_uploaded_file($file,$dir);
                   10828:                 }
1.1055    raeburn  10829:                 if ($decompressed eq 'ok') {
1.1065    raeburn  10830:                     $output = '<p class="LC_info">'.
                   10831:                               &mt('Files extracted successfully from archive.').
                   10832:                               '</p>'."\n";
1.1055    raeburn  10833:                     my ($warning,$result,@contents);
                   10834:                     my ($newdirlistref,$newlisterror) =
                   10835:                         &Apache::lonnet::dirlist($currdir,$docudom,
                   10836:                                                  $docuname,1);
                   10837:                     my (%is_dir,%changes,@newitems);
                   10838:                     my $dirptr = 16384;
1.1065    raeburn  10839:                     if (ref($newdirlistref) eq 'ARRAY') {
1.1055    raeburn  10840:                         foreach my $dir_line (@{$newdirlistref}) {
                   10841:                             my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065    raeburn  10842:                             unless (($item =~ /^\.+$/) || ($item eq $file) || 
                   10843:                                     ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055    raeburn  10844:                                 push(@newitems,$item);
                   10845:                                 if ($dirptr&$testdir) {
                   10846:                                     $is_dir{$item} = 1;
                   10847:                                 }
                   10848:                                 $changes{$item} = 1;
                   10849:                             }
                   10850:                         }
                   10851:                     }
                   10852:                     if (keys(%changes) > 0) {
                   10853:                         foreach my $item (sort(@newitems)) {
                   10854:                             if ($changes{$item}) {
                   10855:                                 push(@contents,$item);
                   10856:                             }
                   10857:                         }
                   10858:                     }
                   10859:                     if (@contents > 0) {
1.1067    raeburn  10860:                         my $wantform;
                   10861:                         unless ($env{'form.autoextract_camtasia'}) {
                   10862:                             $wantform = 1;
                   10863:                         }
1.1056    raeburn  10864:                         my (%children,%parent,%dirorder,%titles);
1.1055    raeburn  10865:                         my ($count,$datatable) = &get_extracted($docudom,$docuname,
                   10866:                                                                 $currdir,\%is_dir,
                   10867:                                                                 \%children,\%parent,
1.1056    raeburn  10868:                                                                 \@contents,\%dirorder,
                   10869:                                                                 \%titles,$wantform);
1.1055    raeburn  10870:                         if ($datatable ne '') {
                   10871:                             $output .= &archive_options_form('decompressed',$datatable,
                   10872:                                                              $count,$hiddenelem);
1.1065    raeburn  10873:                             my $startcount = 6;
1.1055    raeburn  10874:                             $output .= &archive_javascript($startcount,$count,
1.1056    raeburn  10875:                                                            \%titles,\%children);
1.1055    raeburn  10876:                         }
1.1067    raeburn  10877:                         if ($env{'form.autoextract_camtasia'}) {
                   10878:                             my %displayed;
                   10879:                             my $total = 1;
                   10880:                             $env{'form.archive_directory'} = [];
                   10881:                             foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
                   10882:                                 my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
                   10883:                                 $path =~ s{/$}{};
                   10884:                                 my $item;
                   10885:                                 if ($path ne '') {
                   10886:                                     $item = "$path/$titles{$i}";
                   10887:                                 } else {
                   10888:                                     $item = $titles{$i};
                   10889:                                 }
                   10890:                                 $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
                   10891:                                 if ($item eq $contents[0]) {
                   10892:                                     push(@{$env{'form.archive_directory'}},$i);
                   10893:                                     $env{'form.archive_'.$i} = 'display';
                   10894:                                     $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
                   10895:                                     $displayed{'folder'} = $i;
                   10896:                                 } elsif ($item eq "$contents[0]/index.html") {
                   10897:                                     $env{'form.archive_'.$i} = 'display';
                   10898:                                     $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
                   10899:                                     $displayed{'web'} = $i;
                   10900:                                 } else {
                   10901:                                     if ($item eq "$contents[0]/media") {
                   10902:                                         push(@{$env{'form.archive_directory'}},$i);
                   10903:                                     }
                   10904:                                     $env{'form.archive_'.$i} = 'dependency';
                   10905:                                 }
                   10906:                                 $total ++;
                   10907:                             }
                   10908:                             for (my $i=1; $i<$total; $i++) {
                   10909:                                 next if ($i == $displayed{'web'});
                   10910:                                 next if ($i == $displayed{'folder'});
                   10911:                                 $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
                   10912:                             }
                   10913:                             $env{'form.phase'} = 'decompress_cleanup';
                   10914:                             $env{'form.archivedelete'} = 1;
                   10915:                             $env{'form.archive_count'} = $total-1;
                   10916:                             $output .=
                   10917:                                 &process_extracted_files('coursedocs',$docudom,
                   10918:                                                          $docuname,$destination,
                   10919:                                                          $dir_root,$hiddenelem);
                   10920:                         }
1.1055    raeburn  10921:                     } else {
                   10922:                         $warning = &mt('No new items extracted from archive file.');
                   10923:                     }
                   10924:                 } else {
                   10925:                     $output = $display;
                   10926:                     $error = &mt('An error occurred during extraction from the archive file.');
                   10927:                 }
                   10928:             }
                   10929:         }
                   10930:     }
                   10931:     if ($error) {
                   10932:         $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
                   10933:                    $error.'</p>'."\n";
                   10934:     }
                   10935:     if ($warning) {
                   10936:         $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
                   10937:     }
                   10938:     return $output;
                   10939: }
                   10940: 
                   10941: sub get_extracted {
1.1056    raeburn  10942:     my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
                   10943:         $titles,$wantform) = @_;
1.1055    raeburn  10944:     my $count = 0;
                   10945:     my $depth = 0;
                   10946:     my $datatable;
1.1056    raeburn  10947:     my @hierarchy;
1.1055    raeburn  10948:     return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056    raeburn  10949:                    (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
                   10950:                    (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055    raeburn  10951:     foreach my $item (@{$contents}) {
                   10952:         $count ++;
1.1056    raeburn  10953:         @{$dirorder->{$count}} = @hierarchy;
                   10954:         $titles->{$count} = $item;
1.1055    raeburn  10955:         &archive_hierarchy($depth,$count,$parent,$children);
                   10956:         if ($wantform) {
                   10957:             $datatable .= &archive_row($is_dir->{$item},$item,
                   10958:                                        $currdir,$depth,$count);
                   10959:         }
                   10960:         if ($is_dir->{$item}) {
                   10961:             $depth ++;
1.1056    raeburn  10962:             push(@hierarchy,$count);
                   10963:             $parent->{$depth} = $count;
1.1055    raeburn  10964:             $datatable .=
                   10965:                 &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056    raeburn  10966:                                            \$depth,\$count,\@hierarchy,$dirorder,
                   10967:                                            $children,$parent,$titles,$wantform);
1.1055    raeburn  10968:             $depth --;
1.1056    raeburn  10969:             pop(@hierarchy);
1.1055    raeburn  10970:         }
                   10971:     }
                   10972:     return ($count,$datatable);
                   10973: }
                   10974: 
                   10975: sub recurse_extracted_archive {
1.1056    raeburn  10976:     my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
                   10977:         $children,$parent,$titles,$wantform) = @_;
1.1055    raeburn  10978:     my $result='';
1.1056    raeburn  10979:     unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
                   10980:             (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
                   10981:             (ref($dirorder) eq 'HASH')) {
1.1055    raeburn  10982:         return $result;
                   10983:     }
                   10984:     my $dirptr = 16384;
                   10985:     my ($newdirlistref,$newlisterror) =
                   10986:         &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
                   10987:     if (ref($newdirlistref) eq 'ARRAY') {
                   10988:         foreach my $dir_line (@{$newdirlistref}) {
                   10989:             my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
                   10990:             unless ($item =~ /^\.+$/) {
                   10991:                 $$count ++;
1.1056    raeburn  10992:                 @{$dirorder->{$$count}} = @{$hierarchy};
                   10993:                 $titles->{$$count} = $item;
1.1055    raeburn  10994:                 &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056    raeburn  10995: 
1.1055    raeburn  10996:                 my $is_dir;
                   10997:                 if ($dirptr&$testdir) {
                   10998:                     $is_dir = 1;
                   10999:                 }
                   11000:                 if ($wantform) {
                   11001:                     $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
                   11002:                 }
                   11003:                 if ($is_dir) {
                   11004:                     $$depth ++;
1.1056    raeburn  11005:                     push(@{$hierarchy},$$count);
                   11006:                     $parent->{$$depth} = $$count;
1.1055    raeburn  11007:                     $result .=
                   11008:                         &recurse_extracted_archive("$currdir/$item",$docudom,
                   11009:                                                    $docuname,$depth,$count,
1.1056    raeburn  11010:                                                    $hierarchy,$dirorder,$children,
                   11011:                                                    $parent,$titles,$wantform);
1.1055    raeburn  11012:                     $$depth --;
1.1056    raeburn  11013:                     pop(@{$hierarchy});
1.1055    raeburn  11014:                 }
                   11015:             }
                   11016:         }
                   11017:     }
                   11018:     return $result;
                   11019: }
                   11020: 
                   11021: sub archive_hierarchy {
                   11022:     my ($depth,$count,$parent,$children) =@_;
                   11023:     if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
                   11024:         if (exists($parent->{$depth})) {
                   11025:              $children->{$parent->{$depth}} .= $count.':';
                   11026:         }
                   11027:     }
                   11028:     return;
                   11029: }
                   11030: 
                   11031: sub archive_row {
                   11032:     my ($is_dir,$item,$currdir,$depth,$count) = @_;
                   11033:     my ($name) = ($item =~ m{([^/]+)$});
                   11034:     my %choices = &Apache::lonlocal::texthash (
1.1059    raeburn  11035:                                        'display'    => 'Add as file',
1.1055    raeburn  11036:                                        'dependency' => 'Include as dependency',
                   11037:                                        'discard'    => 'Discard',
                   11038:                                       );
                   11039:     if ($is_dir) {
1.1059    raeburn  11040:         $choices{'display'} = &mt('Add as folder'); 
1.1055    raeburn  11041:     }
1.1056    raeburn  11042:     my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
                   11043:     my $offset = 0;
1.1055    raeburn  11044:     foreach my $action ('display','dependency','discard') {
1.1056    raeburn  11045:         $offset ++;
1.1065    raeburn  11046:         if ($action ne 'display') {
                   11047:             $offset ++;
                   11048:         }  
1.1055    raeburn  11049:         $output .= '<td><span class="LC_nobreak">'.
                   11050:                    '<label><input type="radio" name="archive_'.$count.
                   11051:                    '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
                   11052:         my $text = $choices{$action};
                   11053:         if ($is_dir) {
                   11054:             $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
                   11055:             if ($action eq 'display') {
1.1059    raeburn  11056:                 $text = &mt('Add as folder');
1.1055    raeburn  11057:             }
1.1056    raeburn  11058:         } else {
                   11059:             $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
                   11060: 
                   11061:         }
                   11062:         $output .= ' />&nbsp;'.$choices{$action}.'</label></span>';
                   11063:         if ($action eq 'dependency') {
                   11064:             $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
                   11065:                        &mt('Used by:').'&nbsp;<select name="archive_dependent_on_'.$count.'" '.
                   11066:                        'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
                   11067:                        '<option value=""></option>'."\n".
                   11068:                        '</select>'."\n".
                   11069:                        '</div>';
1.1059    raeburn  11070:         } elsif ($action eq 'display') {
                   11071:             $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
                   11072:                        &mt('Title:').'&nbsp;<input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
                   11073:                        '</div>';
1.1055    raeburn  11074:         }
1.1056    raeburn  11075:         $output .= '</td>';
1.1055    raeburn  11076:     }
                   11077:     $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
                   11078:                &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.('&nbsp;' x 2);
                   11079:     for (my $i=0; $i<$depth; $i++) {
                   11080:         $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
                   11081:     }
                   11082:     if ($is_dir) {
                   11083:         $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" />&nbsp;'."\n".
                   11084:                    '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
                   11085:     } else {
                   11086:         $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
                   11087:     }
                   11088:     $output .= '&nbsp;'.$name.'</td>'."\n".
                   11089:                &end_data_table_row();
                   11090:     return $output;
                   11091: }
                   11092: 
                   11093: sub archive_options_form {
1.1065    raeburn  11094:     my ($form,$display,$count,$hiddenelem) = @_;
                   11095:     my %lt = &Apache::lonlocal::texthash(
                   11096:                perm => 'Permanently remove archive file?',
                   11097:                hows => 'How should each extracted item be incorporated in the course?',
                   11098:                cont => 'Content actions for all',
                   11099:                addf => 'Add as folder/file',
                   11100:                incd => 'Include as dependency for a displayed file',
                   11101:                disc => 'Discard',
                   11102:                no   => 'No',
                   11103:                yes  => 'Yes',
                   11104:                save => 'Save',
                   11105:     );
                   11106:     my $output = <<"END";
                   11107: <form name="$form" method="post" action="">
                   11108: <p><span class="LC_nobreak">$lt{'perm'}&nbsp;
                   11109: <label>
                   11110:   <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
                   11111: </label>
                   11112: &nbsp;
                   11113: <label>
                   11114:   <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
                   11115: </span>
                   11116: </p>
                   11117: <input type="hidden" name="phase" value="decompress_cleanup" />
                   11118: <br />$lt{'hows'}
                   11119: <div class="LC_columnSection">
                   11120:   <fieldset>
                   11121:     <legend>$lt{'cont'}</legend>
                   11122:     <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" /> 
                   11123:     &nbsp;&nbsp;<input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
                   11124:     &nbsp;&nbsp;<input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
                   11125:   </fieldset>
                   11126: </div>
                   11127: END
                   11128:     return $output.
1.1055    raeburn  11129:            &start_data_table()."\n".
1.1065    raeburn  11130:            $display."\n".
1.1055    raeburn  11131:            &end_data_table()."\n".
                   11132:            '<input type="hidden" name="archive_count" value="'.$count.'" />'.
                   11133:            $hiddenelem.
1.1065    raeburn  11134:            '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055    raeburn  11135:            '</form>';
                   11136: }
                   11137: 
                   11138: sub archive_javascript {
1.1056    raeburn  11139:     my ($startcount,$numitems,$titles,$children) = @_;
                   11140:     return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059    raeburn  11141:     my $maintitle = $env{'form.comment'};
1.1055    raeburn  11142:     my $scripttag = <<START;
                   11143: <script type="text/javascript">
                   11144: // <![CDATA[
                   11145: 
                   11146: function checkAll(form,prefix) {
                   11147:     var idstr =  new RegExp("^archive_"+prefix+"_\\\\d+\$");
                   11148:     for (var i=0; i < form.elements.length; i++) {
                   11149:         var id = form.elements[i].id;
                   11150:         if ((id != '') && (id != undefined)) {
                   11151:             if (idstr.test(id)) {
                   11152:                 if (form.elements[i].type == 'radio') {
                   11153:                     form.elements[i].checked = true;
1.1056    raeburn  11154:                     var nostart = i-$startcount;
1.1059    raeburn  11155:                     var offset = nostart%7;
                   11156:                     var count = (nostart-offset)/7;    
1.1056    raeburn  11157:                     dependencyCheck(form,count,offset);
1.1055    raeburn  11158:                 }
                   11159:             }
                   11160:         }
                   11161:     }
                   11162: }
                   11163: 
                   11164: function propagateCheck(form,count) {
                   11165:     if (count > 0) {
1.1059    raeburn  11166:         var startelement = $startcount + ((count-1) * 7);
                   11167:         for (var j=1; j<6; j++) {
                   11168:             if ((j != 2) && (j != 4)) {
1.1056    raeburn  11169:                 var item = startelement + j; 
                   11170:                 if (form.elements[item].type == 'radio') {
                   11171:                     if (form.elements[item].checked) {
                   11172:                         containerCheck(form,count,j);
                   11173:                         break;
                   11174:                     }
1.1055    raeburn  11175:                 }
                   11176:             }
                   11177:         }
                   11178:     }
                   11179: }
                   11180: 
                   11181: numitems = $numitems
1.1056    raeburn  11182: var titles = new Array(numitems);
                   11183: var parents = new Array(numitems);
1.1055    raeburn  11184: for (var i=0; i<numitems; i++) {
1.1056    raeburn  11185:     parents[i] = new Array;
1.1055    raeburn  11186: }
1.1059    raeburn  11187: var maintitle = '$maintitle';
1.1055    raeburn  11188: 
                   11189: START
                   11190: 
1.1056    raeburn  11191:     foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
                   11192:         my @contents = split(/:/,$children->{$container});
1.1055    raeburn  11193:         for (my $i=0; $i<@contents; $i ++) {
                   11194:             $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
                   11195:         }
                   11196:     }
                   11197: 
1.1056    raeburn  11198:     foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
                   11199:         $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
                   11200:     }
                   11201: 
1.1055    raeburn  11202:     $scripttag .= <<END;
                   11203: 
                   11204: function containerCheck(form,count,offset) {
                   11205:     if (count > 0) {
1.1056    raeburn  11206:         dependencyCheck(form,count,offset);
1.1059    raeburn  11207:         var item = (offset+$startcount)+7*(count-1);
1.1055    raeburn  11208:         form.elements[item].checked = true;
                   11209:         if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
                   11210:             if (parents[count].length > 0) {
                   11211:                 for (var j=0; j<parents[count].length; j++) {
1.1056    raeburn  11212:                     containerCheck(form,parents[count][j],offset);
                   11213:                 }
                   11214:             }
                   11215:         }
                   11216:     }
                   11217: }
                   11218: 
                   11219: function dependencyCheck(form,count,offset) {
                   11220:     if (count > 0) {
1.1059    raeburn  11221:         var chosen = (offset+$startcount)+7*(count-1);
                   11222:         var depitem = $startcount + ((count-1) * 7) + 4;
1.1056    raeburn  11223:         var currtype = form.elements[depitem].type;
                   11224:         if (form.elements[chosen].value == 'dependency') {
                   11225:             document.getElementById('arc_depon_'+count).style.display='block'; 
                   11226:             form.elements[depitem].options.length = 0;
                   11227:             form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11  raeburn  11228:             for (var i=1; i<=numitems; i++) {
                   11229:                 if (i == count) {
                   11230:                     continue;
                   11231:                 }
1.1059    raeburn  11232:                 var startelement = $startcount + (i-1) * 7;
                   11233:                 for (var j=1; j<6; j++) {
                   11234:                     if ((j != 2) && (j!= 4)) {
1.1056    raeburn  11235:                         var item = startelement + j;
                   11236:                         if (form.elements[item].type == 'radio') {
                   11237:                             if (form.elements[item].checked) {
                   11238:                                 if (form.elements[item].value == 'display') {
                   11239:                                     var n = form.elements[depitem].options.length;
                   11240:                                     form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
                   11241:                                 }
                   11242:                             }
                   11243:                         }
                   11244:                     }
                   11245:                 }
                   11246:             }
                   11247:         } else {
                   11248:             document.getElementById('arc_depon_'+count).style.display='none';
                   11249:             form.elements[depitem].options.length = 0;
                   11250:             form.elements[depitem].options[0] = new Option('Select','',true,true);
                   11251:         }
1.1059    raeburn  11252:         titleCheck(form,count,offset);
1.1056    raeburn  11253:     }
                   11254: }
                   11255: 
                   11256: function propagateSelect(form,count,offset) {
                   11257:     if (count > 0) {
1.1065    raeburn  11258:         var item = (1+offset+$startcount)+7*(count-1);
1.1056    raeburn  11259:         var picked = form.elements[item].options[form.elements[item].selectedIndex].value; 
                   11260:         if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
                   11261:             if (parents[count].length > 0) {
                   11262:                 for (var j=0; j<parents[count].length; j++) {
                   11263:                     containerSelect(form,parents[count][j],offset,picked);
1.1055    raeburn  11264:                 }
                   11265:             }
                   11266:         }
                   11267:     }
                   11268: }
1.1056    raeburn  11269: 
                   11270: function containerSelect(form,count,offset,picked) {
                   11271:     if (count > 0) {
1.1065    raeburn  11272:         var item = (offset+$startcount)+7*(count-1);
1.1056    raeburn  11273:         if (form.elements[item].type == 'radio') {
                   11274:             if (form.elements[item].value == 'dependency') {
                   11275:                 if (form.elements[item+1].type == 'select-one') {
                   11276:                     for (var i=0; i<form.elements[item+1].options.length; i++) {
                   11277:                         if (form.elements[item+1].options[i].value == picked) {
                   11278:                             form.elements[item+1].selectedIndex = i;
                   11279:                             break;
                   11280:                         }
                   11281:                     }
                   11282:                 }
                   11283:                 if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
                   11284:                     if (parents[count].length > 0) {
                   11285:                         for (var j=0; j<parents[count].length; j++) {
                   11286:                             containerSelect(form,parents[count][j],offset,picked);
                   11287:                         }
                   11288:                     }
                   11289:                 }
                   11290:             }
                   11291:         }
                   11292:     }
                   11293: }
                   11294: 
1.1059    raeburn  11295: function titleCheck(form,count,offset) {
                   11296:     if (count > 0) {
                   11297:         var chosen = (offset+$startcount)+7*(count-1);
                   11298:         var depitem = $startcount + ((count-1) * 7) + 2;
                   11299:         var currtype = form.elements[depitem].type;
                   11300:         if (form.elements[chosen].value == 'display') {
                   11301:             document.getElementById('arc_title_'+count).style.display='block';
                   11302:             if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
                   11303:                 document.getElementById('archive_title_'+count).value=maintitle;
                   11304:             }
                   11305:         } else {
                   11306:             document.getElementById('arc_title_'+count).style.display='none';
                   11307:             if (currtype == 'text') { 
                   11308:                 document.getElementById('archive_title_'+count).value='';
                   11309:             }
                   11310:         }
                   11311:     }
                   11312:     return;
                   11313: }
                   11314: 
1.1055    raeburn  11315: // ]]>
                   11316: </script>
                   11317: END
                   11318:     return $scripttag;
                   11319: }
                   11320: 
                   11321: sub process_extracted_files {
1.1067    raeburn  11322:     my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055    raeburn  11323:     my $numitems = $env{'form.archive_count'};
                   11324:     return unless ($numitems);
                   11325:     my @ids=&Apache::lonnet::current_machine_ids();
                   11326:     my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067    raeburn  11327:         %folders,%containers,%mapinner,%prompttofetch);
1.1055    raeburn  11328:     my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
                   11329:     if (grep(/^\Q$docuhome\E$/,@ids)) {
                   11330:         $prefix = &LONCAPA::propath($docudom,$docuname);
                   11331:         $pathtocheck = "$dir_root/$destination";
                   11332:         $dir = $dir_root;
                   11333:         $ishome = 1;
                   11334:     } else {
                   11335:         $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
                   11336:         $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
                   11337:         $dir = "$dir_root/$docudom/$docuname";    
                   11338:     }
                   11339:     my $currdir = "$dir_root/$destination";
                   11340:     (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
                   11341:     if ($env{'form.folderpath'}) {
                   11342:         my @items = split('&',$env{'form.folderpath'});
                   11343:         $folders{'0'} = $items[-2];
1.1075.2.17  raeburn  11344:         if ($env{'form.folderpath'} =~ /\:1$/) {
                   11345:             $containers{'0'}='page';
                   11346:         } else {
                   11347:             $containers{'0'}='sequence';
                   11348:         }
1.1055    raeburn  11349:     }
                   11350:     my @archdirs = &get_env_multiple('form.archive_directory');
                   11351:     if ($numitems) {
                   11352:         for (my $i=1; $i<=$numitems; $i++) {
                   11353:             my $path = $env{'form.archive_content_'.$i};
                   11354:             if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
                   11355:                 my $item = $1;
                   11356:                 $toplevelitems{$item} = $i;
                   11357:                 if (grep(/^\Q$i\E$/,@archdirs)) {
                   11358:                     $is_dir{$item} = 1;
                   11359:                 }
                   11360:             }
                   11361:         }
                   11362:     }
1.1067    raeburn  11363:     my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055    raeburn  11364:     if (keys(%toplevelitems) > 0) {
                   11365:         my @contents = sort(keys(%toplevelitems));
1.1056    raeburn  11366:         (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
                   11367:                                            \%parent,\@contents,\%dirorder,\%titles);
1.1055    raeburn  11368:     }
1.1066    raeburn  11369:     my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055    raeburn  11370:     if ($numitems) {
                   11371:         for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11  raeburn  11372:             next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055    raeburn  11373:             my $path = $env{'form.archive_content_'.$i};
                   11374:             if ($path =~ /^\Q$pathtocheck\E/) {
                   11375:                 if ($env{'form.archive_'.$i} eq 'discard') {
                   11376:                     if ($prefix ne '' && $path ne '') {
                   11377:                         if (-e $prefix.$path) {
1.1066    raeburn  11378:                             if ((@archdirs > 0) && 
                   11379:                                 (grep(/^\Q$i\E$/,@archdirs))) {
                   11380:                                 $todeletedir{$prefix.$path} = 1;
                   11381:                             } else {
                   11382:                                 $todelete{$prefix.$path} = 1;
                   11383:                             }
1.1055    raeburn  11384:                         }
                   11385:                     }
                   11386:                 } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059    raeburn  11387:                     my ($docstitle,$title,$url,$outer);
1.1055    raeburn  11388:                     ($title) = ($path =~ m{/([^/]+)$});
1.1059    raeburn  11389:                     $docstitle = $env{'form.archive_title_'.$i};
                   11390:                     if ($docstitle eq '') {
                   11391:                         $docstitle = $title;
                   11392:                     }
1.1055    raeburn  11393:                     $outer = 0;
1.1056    raeburn  11394:                     if (ref($dirorder{$i}) eq 'ARRAY') {
                   11395:                         if (@{$dirorder{$i}} > 0) {
                   11396:                             foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055    raeburn  11397:                                 if ($env{'form.archive_'.$item} eq 'display') {
                   11398:                                     $outer = $item;
                   11399:                                     last;
                   11400:                                 }
                   11401:                             }
                   11402:                         }
                   11403:                     }
                   11404:                     my ($errtext,$fatal) = 
                   11405:                         &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
                   11406:                                                '/'.$folders{$outer}.'.'.
                   11407:                                                $containers{$outer});
                   11408:                     next if ($fatal);
                   11409:                     if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
                   11410:                         if ($context eq 'coursedocs') {
1.1056    raeburn  11411:                             $mapinner{$i} = time;
1.1055    raeburn  11412:                             $folders{$i} = 'default_'.$mapinner{$i};
                   11413:                             $containers{$i} = 'sequence';
                   11414:                             my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
                   11415:                                       $folders{$i}.'.'.$containers{$i};
                   11416:                             my $newidx = &LONCAPA::map::getresidx();
                   11417:                             $LONCAPA::map::resources[$newidx]=
1.1059    raeburn  11418:                                 $docstitle.':'.$url.':false:normal:res';
1.1055    raeburn  11419:                             push(@LONCAPA::map::order,$newidx);
                   11420:                             my ($outtext,$errtext) =
                   11421:                                 &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
                   11422:                                                         $docuname.'/'.$folders{$outer}.
1.1075.2.11  raeburn  11423:                                                         '.'.$containers{$outer},1,1);
1.1056    raeburn  11424:                             $newseqid{$i} = $newidx;
1.1067    raeburn  11425:                             unless ($errtext) {
                   11426:                                 $result .=  '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
                   11427:                             }
1.1055    raeburn  11428:                         }
                   11429:                     } else {
                   11430:                         if ($context eq 'coursedocs') {
                   11431:                             my $newidx=&LONCAPA::map::getresidx();
                   11432:                             my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
                   11433:                                       $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
                   11434:                                       $title;
                   11435:                             if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
                   11436:                                 mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
                   11437:                             }
                   11438:                             if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
                   11439:                                 mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
                   11440:                             }
                   11441:                             if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
                   11442:                                 system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056    raeburn  11443:                                 $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067    raeburn  11444:                                 unless ($ishome) {
                   11445:                                     my $fetch = "$newdest{$i}/$title";
                   11446:                                     $fetch =~ s/^\Q$prefix$dir\E//;
                   11447:                                     $prompttofetch{$fetch} = 1;
                   11448:                                 }
1.1055    raeburn  11449:                             }
                   11450:                             $LONCAPA::map::resources[$newidx]=
1.1059    raeburn  11451:                                 $docstitle.':'.$url.':false:normal:res';
1.1055    raeburn  11452:                             push(@LONCAPA::map::order, $newidx);
                   11453:                             my ($outtext,$errtext)=
                   11454:                                 &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
                   11455:                                                         $docuname.'/'.$folders{$outer}.
1.1075.2.11  raeburn  11456:                                                         '.'.$containers{$outer},1,1);
1.1067    raeburn  11457:                             unless ($errtext) {
                   11458:                                 if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
                   11459:                                     $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
                   11460:                                 }
                   11461:                             }
1.1055    raeburn  11462:                         }
                   11463:                     }
1.1075.2.11  raeburn  11464:                 }
                   11465:             } else {
                   11466:                 $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
                   11467:             }
                   11468:         }
                   11469:         for (my $i=1; $i<=$numitems; $i++) {
                   11470:             next unless ($env{'form.archive_'.$i} eq 'dependency');
                   11471:             my $path = $env{'form.archive_content_'.$i};
                   11472:             if ($path =~ /^\Q$pathtocheck\E/) {
                   11473:                 my ($title) = ($path =~ m{/([^/]+)$});
                   11474:                 $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
                   11475:                 if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
                   11476:                     if (ref($dirorder{$i}) eq 'ARRAY') {
                   11477:                         my ($itemidx,$fullpath,$relpath);
                   11478:                         if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
                   11479:                             my $container = $dirorder{$referrer{$i}}->[-1];
1.1056    raeburn  11480:                             for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11  raeburn  11481:                                 if ($dirorder{$i}->[$j] eq $container) {
                   11482:                                     $itemidx = $j;
1.1056    raeburn  11483:                                 }
                   11484:                             }
1.1075.2.11  raeburn  11485:                         }
                   11486:                         if ($itemidx eq '') {
                   11487:                             $itemidx =  0;
                   11488:                         }
                   11489:                         if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
                   11490:                             if ($mapinner{$referrer{$i}}) {
                   11491:                                 $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
                   11492:                                 for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
                   11493:                                     if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
                   11494:                                         unless (defined($newseqid{$dirorder{$i}->[$j]})) {
                   11495:                                             $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
                   11496:                                             $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
                   11497:                                             if (!-e $fullpath) {
                   11498:                                                 mkdir($fullpath,0755);
1.1056    raeburn  11499:                                             }
                   11500:                                         }
1.1075.2.11  raeburn  11501:                                     } else {
                   11502:                                         last;
1.1056    raeburn  11503:                                     }
1.1075.2.11  raeburn  11504:                                 }
                   11505:                             }
                   11506:                         } elsif ($newdest{$referrer{$i}}) {
                   11507:                             $fullpath = $newdest{$referrer{$i}};
                   11508:                             for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
                   11509:                                 if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
                   11510:                                     $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
                   11511:                                     last;
                   11512:                                 } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
                   11513:                                     unless (defined($newseqid{$dirorder{$i}->[$j]})) {
                   11514:                                         $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
                   11515:                                         $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
                   11516:                                         if (!-e $fullpath) {
                   11517:                                             mkdir($fullpath,0755);
1.1056    raeburn  11518:                                         }
                   11519:                                     }
1.1075.2.11  raeburn  11520:                                 } else {
                   11521:                                     last;
1.1056    raeburn  11522:                                 }
1.1075.2.11  raeburn  11523:                             }
                   11524:                         }
                   11525:                         if ($fullpath ne '') {
                   11526:                             if (-e "$prefix$path") {
                   11527:                                 system("mv $prefix$path $fullpath/$title");
                   11528:                             }
                   11529:                             if (-e "$fullpath/$title") {
                   11530:                                 my $showpath;
                   11531:                                 if ($relpath ne '') {
                   11532:                                     $showpath = "$relpath/$title";
                   11533:                                 } else {
                   11534:                                     $showpath = "/$title";
1.1056    raeburn  11535:                                 }
1.1075.2.11  raeburn  11536:                                 $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
                   11537:                             }
                   11538:                             unless ($ishome) {
                   11539:                                 my $fetch = "$fullpath/$title";
                   11540:                                 $fetch =~ s/^\Q$prefix$dir\E//;
                   11541:                                 $prompttofetch{$fetch} = 1;
1.1055    raeburn  11542:                             }
                   11543:                         }
                   11544:                     }
1.1075.2.11  raeburn  11545:                 } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
                   11546:                     $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
                   11547:                                     $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055    raeburn  11548:                 }
                   11549:             } else {
1.1075.2.11  raeburn  11550:                 $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
1.1055    raeburn  11551:             }
                   11552:         }
                   11553:         if (keys(%todelete)) {
                   11554:             foreach my $key (keys(%todelete)) {
                   11555:                 unlink($key);
1.1066    raeburn  11556:             }
                   11557:         }
                   11558:         if (keys(%todeletedir)) {
                   11559:             foreach my $key (keys(%todeletedir)) {
                   11560:                 rmdir($key);
                   11561:             }
                   11562:         }
                   11563:         foreach my $dir (sort(keys(%is_dir))) {
                   11564:             if (($pathtocheck ne '') && ($dir ne ''))  {
                   11565:                 &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055    raeburn  11566:             }
                   11567:         }
1.1067    raeburn  11568:         if ($result ne '') {
                   11569:             $output .= '<ul>'."\n".
                   11570:                        $result."\n".
                   11571:                        '</ul>';
                   11572:         }
                   11573:         unless ($ishome) {
                   11574:             my $replicationfail;
                   11575:             foreach my $item (keys(%prompttofetch)) {
                   11576:                 my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
                   11577:                 unless ($fetchresult eq 'ok') {
                   11578:                     $replicationfail .= '<li>'.$item.'</li>'."\n";
                   11579:                 }
                   11580:             }
                   11581:             if ($replicationfail) {
                   11582:                 $output .= '<p class="LC_error">'.
                   11583:                            &mt('Course home server failed to retrieve:').'<ul>'.
                   11584:                            $replicationfail.
                   11585:                            '</ul></p>';
                   11586:             }
                   11587:         }
1.1055    raeburn  11588:     } else {
                   11589:         $warning = &mt('No items found in archive.');
                   11590:     }
                   11591:     if ($error) {
                   11592:         $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
                   11593:                    $error.'</p>'."\n";
                   11594:     }
                   11595:     if ($warning) {
                   11596:         $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
                   11597:     }
                   11598:     return $output;
                   11599: }
                   11600: 
1.1066    raeburn  11601: sub cleanup_empty_dirs {
                   11602:     my ($path) = @_;
                   11603:     if (($path ne '') && (-d $path)) {
                   11604:         if (opendir(my $dirh,$path)) {
                   11605:             my @dircontents = grep(!/^\./,readdir($dirh));
                   11606:             my $numitems = 0;
                   11607:             foreach my $item (@dircontents) {
                   11608:                 if (-d "$path/$item") {
1.1075.2.28  raeburn  11609:                     &cleanup_empty_dirs("$path/$item");
1.1066    raeburn  11610:                     if (-e "$path/$item") {
                   11611:                         $numitems ++;
                   11612:                     }
                   11613:                 } else {
                   11614:                     $numitems ++;
                   11615:                 }
                   11616:             }
                   11617:             if ($numitems == 0) {
                   11618:                 rmdir($path);
                   11619:             }
                   11620:             closedir($dirh);
                   11621:         }
                   11622:     }
                   11623:     return;
                   11624: }
                   11625: 
1.41      ng       11626: =pod
1.45      matthew  11627: 
1.1068    raeburn  11628: =item &get_folder_hierarchy()
                   11629: 
                   11630: Provides hierarchy of names of folders/sub-folders containing the current
                   11631: item,
                   11632: 
                   11633: Inputs: 3
                   11634:      - $navmap - navmaps object
                   11635: 
                   11636:      - $map - url for map (either the trigger itself, or map containing
                   11637:                            the resource, which is the trigger).
                   11638: 
                   11639:      - $showitem - 1 => show title for map itself; 0 => do not show.
                   11640: 
                   11641: Outputs: 1 @pathitems - array of folder/subfolder names.
                   11642: 
                   11643: =cut
                   11644: 
                   11645: sub get_folder_hierarchy {
                   11646:     my ($navmap,$map,$showitem) = @_;
                   11647:     my @pathitems;
                   11648:     if (ref($navmap)) {
                   11649:         my $mapres = $navmap->getResourceByUrl($map);
                   11650:         if (ref($mapres)) {
                   11651:             my $pcslist = $mapres->map_hierarchy();
                   11652:             if ($pcslist ne '') {
                   11653:                 my @pcs = split(/,/,$pcslist);
                   11654:                 foreach my $pc (@pcs) {
                   11655:                     if ($pc == 1) {
                   11656:                         push(@pathitems,&mt('Main Course Documents'));
                   11657:                     } else {
                   11658:                         my $res = $navmap->getByMapPc($pc);
                   11659:                         if (ref($res)) {
                   11660:                             my $title = $res->compTitle();
                   11661:                             $title =~ s/\W+/_/g;
                   11662:                             if ($title ne '') {
                   11663:                                 push(@pathitems,$title);
                   11664:                             }
                   11665:                         }
                   11666:                     }
                   11667:                 }
                   11668:             }
1.1071    raeburn  11669:             if ($showitem) {
                   11670:                 if ($mapres->{ID} eq '0.0') {
                   11671:                     push(@pathitems,&mt('Main Course Documents'));
                   11672:                 } else {
                   11673:                     my $maptitle = $mapres->compTitle();
                   11674:                     $maptitle =~ s/\W+/_/g;
                   11675:                     if ($maptitle ne '') {
                   11676:                         push(@pathitems,$maptitle);
                   11677:                     }
1.1068    raeburn  11678:                 }
                   11679:             }
                   11680:         }
                   11681:     }
                   11682:     return @pathitems;
                   11683: }
                   11684: 
                   11685: =pod
                   11686: 
1.1015    raeburn  11687: =item * &get_turnedin_filepath()
                   11688: 
                   11689: Determines path in a user's portfolio file for storage of files uploaded
                   11690: to a specific essayresponse or dropbox item.
                   11691: 
                   11692: Inputs: 3 required + 1 optional.
                   11693: $symb is symb for resource, $uname and $udom are for current user (required).
                   11694: $caller is optional (can be "submission", if routine is called when storing
                   11695: an upoaded file when "Submit Answer" button was pressed).
                   11696: 
                   11697: Returns array containing $path and $multiresp. 
                   11698: $path is path in portfolio.  $multiresp is 1 if this resource contains more
                   11699: than one file upload item.  Callers of routine should append partid as a 
                   11700: subdirectory to $path in cases where $multiresp is 1.
                   11701: 
                   11702: Called by: homework/essayresponse.pm and homework/structuretags.pm
                   11703: 
                   11704: =cut
                   11705: 
                   11706: sub get_turnedin_filepath {
                   11707:     my ($symb,$uname,$udom,$caller) = @_;
                   11708:     my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
                   11709:     my $turnindir;
                   11710:     my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
                   11711:     $turnindir = $userhash{'turnindir'};
                   11712:     my ($path,$multiresp);
                   11713:     if ($turnindir eq '') {
                   11714:         if ($caller eq 'submission') {
                   11715:             $turnindir = &mt('turned in');
                   11716:             $turnindir =~ s/\W+/_/g;
                   11717:             my %newhash = (
                   11718:                             'turnindir' => $turnindir,
                   11719:                           );
                   11720:             &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
                   11721:         }
                   11722:     }
                   11723:     if ($turnindir ne '') {
                   11724:         $path = '/'.$turnindir.'/';
                   11725:         my ($multipart,$turnin,@pathitems);
                   11726:         my $navmap = Apache::lonnavmaps::navmap->new();
                   11727:         if (defined($navmap)) {
                   11728:             my $mapres = $navmap->getResourceByUrl($map);
                   11729:             if (ref($mapres)) {
                   11730:                 my $pcslist = $mapres->map_hierarchy();
                   11731:                 if ($pcslist ne '') {
                   11732:                     foreach my $pc (split(/,/,$pcslist)) {
                   11733:                         my $res = $navmap->getByMapPc($pc);
                   11734:                         if (ref($res)) {
                   11735:                             my $title = $res->compTitle();
                   11736:                             $title =~ s/\W+/_/g;
                   11737:                             if ($title ne '') {
                   11738:                                 push(@pathitems,$title);
                   11739:                             }
                   11740:                         }
                   11741:                     }
                   11742:                 }
                   11743:                 my $maptitle = $mapres->compTitle();
                   11744:                 $maptitle =~ s/\W+/_/g;
                   11745:                 if ($maptitle ne '') {
                   11746:                     push(@pathitems,$maptitle);
                   11747:                 }
                   11748:                 unless ($env{'request.state'} eq 'construct') {
                   11749:                     my $res = $navmap->getBySymb($symb);
                   11750:                     if (ref($res)) {
                   11751:                         my $partlist = $res->parts();
                   11752:                         my $totaluploads = 0;
                   11753:                         if (ref($partlist) eq 'ARRAY') {
                   11754:                             foreach my $part (@{$partlist}) {
                   11755:                                 my @types = $res->responseType($part);
                   11756:                                 my @ids = $res->responseIds($part);
                   11757:                                 for (my $i=0; $i < scalar(@ids); $i++) {
                   11758:                                     if ($types[$i] eq 'essay') {
                   11759:                                         my $partid = $part.'_'.$ids[$i];
                   11760:                                         if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
                   11761:                                             $totaluploads ++;
                   11762:                                         }
                   11763:                                     }
                   11764:                                 }
                   11765:                             }
                   11766:                             if ($totaluploads > 1) {
                   11767:                                 $multiresp = 1;
                   11768:                             }
                   11769:                         }
                   11770:                     }
                   11771:                 }
                   11772:             } else {
                   11773:                 return;
                   11774:             }
                   11775:         } else {
                   11776:             return;
                   11777:         }
                   11778:         my $restitle=&Apache::lonnet::gettitle($symb);
                   11779:         $restitle =~ s/\W+/_/g;
                   11780:         if ($restitle eq '') {
                   11781:             $restitle = ($resurl =~ m{/[^/]+$});
                   11782:             if ($restitle eq '') {
                   11783:                 $restitle = time;
                   11784:             }
                   11785:         }
                   11786:         push(@pathitems,$restitle);
                   11787:         $path .= join('/',@pathitems);
                   11788:     }
                   11789:     return ($path,$multiresp);
                   11790: }
                   11791: 
                   11792: =pod
                   11793: 
1.464     albertel 11794: =back
1.41      ng       11795: 
1.112     bowersj2 11796: =head1 CSV Upload/Handling functions
1.38      albertel 11797: 
1.41      ng       11798: =over 4
                   11799: 
1.648     raeburn  11800: =item * &upfile_store($r)
1.41      ng       11801: 
                   11802: Store uploaded file, $r should be the HTTP Request object,
1.258     albertel 11803: needs $env{'form.upfile'}
1.41      ng       11804: returns $datatoken to be put into hidden field
                   11805: 
                   11806: =cut
1.31      albertel 11807: 
                   11808: sub upfile_store {
                   11809:     my $r=shift;
1.258     albertel 11810:     $env{'form.upfile'}=~s/\r/\n/gs;
                   11811:     $env{'form.upfile'}=~s/\f/\n/gs;
                   11812:     $env{'form.upfile'}=~s/\n+/\n/gs;
                   11813:     $env{'form.upfile'}=~s/\n+$//gs;
1.31      albertel 11814: 
1.258     albertel 11815:     my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
                   11816: 	'_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31      albertel 11817:     {
1.158     raeburn  11818:         my $datafile = $r->dir_config('lonDaemons').
                   11819:                            '/tmp/'.$datatoken.'.tmp';
                   11820:         if ( open(my $fh,">$datafile") ) {
1.258     albertel 11821:             print $fh $env{'form.upfile'};
1.158     raeburn  11822:             close($fh);
                   11823:         }
1.31      albertel 11824:     }
                   11825:     return $datatoken;
                   11826: }
                   11827: 
1.56      matthew  11828: =pod
                   11829: 
1.648     raeburn  11830: =item * &load_tmp_file($r)
1.41      ng       11831: 
                   11832: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258     albertel 11833: needs $env{'form.datatoken'},
                   11834: sets $env{'form.upfile'} to the contents of the file
1.41      ng       11835: 
                   11836: =cut
1.31      albertel 11837: 
                   11838: sub load_tmp_file {
                   11839:     my $r=shift;
                   11840:     my @studentdata=();
                   11841:     {
1.158     raeburn  11842:         my $studentfile = $r->dir_config('lonDaemons').
1.258     albertel 11843:                               '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158     raeburn  11844:         if ( open(my $fh,"<$studentfile") ) {
                   11845:             @studentdata=<$fh>;
                   11846:             close($fh);
                   11847:         }
1.31      albertel 11848:     }
1.258     albertel 11849:     $env{'form.upfile'}=join('',@studentdata);
1.31      albertel 11850: }
                   11851: 
1.56      matthew  11852: =pod
                   11853: 
1.648     raeburn  11854: =item * &upfile_record_sep()
1.41      ng       11855: 
                   11856: Separate uploaded file into records
                   11857: returns array of records,
1.258     albertel 11858: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41      ng       11859: 
                   11860: =cut
1.31      albertel 11861: 
                   11862: sub upfile_record_sep {
1.258     albertel 11863:     if ($env{'form.upfiletype'} eq 'xml') {
1.31      albertel 11864:     } else {
1.248     albertel 11865: 	my @records;
1.258     albertel 11866: 	foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248     albertel 11867: 	    if ($line=~/^\s*$/) { next; }
                   11868: 	    push(@records,$line);
                   11869: 	}
                   11870: 	return @records;
1.31      albertel 11871:     }
                   11872: }
                   11873: 
1.56      matthew  11874: =pod
                   11875: 
1.648     raeburn  11876: =item * &record_sep($record)
1.41      ng       11877: 
1.258     albertel 11878: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41      ng       11879: 
                   11880: =cut
                   11881: 
1.263     www      11882: sub takeleft {
                   11883:     my $index=shift;
                   11884:     return substr('0000'.$index,-4,4);
                   11885: }
                   11886: 
1.31      albertel 11887: sub record_sep {
                   11888:     my $record=shift;
                   11889:     my %components=();
1.258     albertel 11890:     if ($env{'form.upfiletype'} eq 'xml') {
                   11891:     } elsif ($env{'form.upfiletype'} eq 'space') {
1.31      albertel 11892:         my $i=0;
1.356     albertel 11893:         foreach my $field (split(/\s+/,$record)) {
1.31      albertel 11894:             $field=~s/^(\"|\')//;
                   11895:             $field=~s/(\"|\')$//;
1.263     www      11896:             $components{&takeleft($i)}=$field;
1.31      albertel 11897:             $i++;
                   11898:         }
1.258     albertel 11899:     } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31      albertel 11900:         my $i=0;
1.356     albertel 11901:         foreach my $field (split(/\t/,$record)) {
1.31      albertel 11902:             $field=~s/^(\"|\')//;
                   11903:             $field=~s/(\"|\')$//;
1.263     www      11904:             $components{&takeleft($i)}=$field;
1.31      albertel 11905:             $i++;
                   11906:         }
                   11907:     } else {
1.561     www      11908:         my $separator=',';
1.480     banghart 11909:         if ($env{'form.upfiletype'} eq 'semisv') {
1.561     www      11910:             $separator=';';
1.480     banghart 11911:         }
1.31      albertel 11912:         my $i=0;
1.561     www      11913: # the character we are looking for to indicate the end of a quote or a record 
                   11914:         my $looking_for=$separator;
                   11915: # do not add the characters to the fields
                   11916:         my $ignore=0;
                   11917: # we just encountered a separator (or the beginning of the record)
                   11918:         my $just_found_separator=1;
                   11919: # store the field we are working on here
                   11920:         my $field='';
                   11921: # work our way through all characters in record
                   11922:         foreach my $character ($record=~/(.)/g) {
                   11923:             if ($character eq $looking_for) {
                   11924:                if ($character ne $separator) {
                   11925: # Found the end of a quote, again looking for separator
                   11926:                   $looking_for=$separator;
                   11927:                   $ignore=1;
                   11928:                } else {
                   11929: # Found a separator, store away what we got
                   11930:                   $components{&takeleft($i)}=$field;
                   11931: 	          $i++;
                   11932:                   $just_found_separator=1;
                   11933:                   $ignore=0;
                   11934:                   $field='';
                   11935:                }
                   11936:                next;
                   11937:             }
                   11938: # single or double quotation marks after a separator indicate beginning of a quote
                   11939: # we are now looking for the end of the quote and need to ignore separators
                   11940:             if ((($character eq '"') || ($character eq "'")) && ($just_found_separator))  {
                   11941:                $looking_for=$character;
                   11942:                next;
                   11943:             }
                   11944: # ignore would be true after we reached the end of a quote
                   11945:             if ($ignore) { next; }
                   11946:             if (($just_found_separator) && ($character=~/\s/)) { next; }
                   11947:             $field.=$character;
                   11948:             $just_found_separator=0; 
1.31      albertel 11949:         }
1.561     www      11950: # catch the very last entry, since we never encountered the separator
                   11951:         $components{&takeleft($i)}=$field;
1.31      albertel 11952:     }
                   11953:     return %components;
                   11954: }
                   11955: 
1.144     matthew  11956: ######################################################
                   11957: ######################################################
                   11958: 
1.56      matthew  11959: =pod
                   11960: 
1.648     raeburn  11961: =item * &upfile_select_html()
1.41      ng       11962: 
1.144     matthew  11963: Return HTML code to select a file from the users machine and specify 
                   11964: the file type.
1.41      ng       11965: 
                   11966: =cut
                   11967: 
1.144     matthew  11968: ######################################################
                   11969: ######################################################
1.31      albertel 11970: sub upfile_select_html {
1.144     matthew  11971:     my %Types = (
                   11972:                  csv   => &mt('CSV (comma separated values, spreadsheet)'),
1.480     banghart 11973:                  semisv => &mt('Semicolon separated values'),
1.144     matthew  11974:                  space => &mt('Space separated'),
                   11975:                  tab   => &mt('Tabulator separated'),
                   11976: #                 xml   => &mt('HTML/XML'),
                   11977:                  );
                   11978:     my $Str = '<input type="file" name="upfile" size="50" />'.
1.727     riegler  11979:         '<br />'.&mt('Type').': <select name="upfiletype">';
1.144     matthew  11980:     foreach my $type (sort(keys(%Types))) {
                   11981:         $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
                   11982:     }
                   11983:     $Str .= "</select>\n";
                   11984:     return $Str;
1.31      albertel 11985: }
                   11986: 
1.301     albertel 11987: sub get_samples {
                   11988:     my ($records,$toget) = @_;
                   11989:     my @samples=({});
                   11990:     my $got=0;
                   11991:     foreach my $rec (@$records) {
                   11992: 	my %temp = &record_sep($rec);
                   11993: 	if (! grep(/\S/, values(%temp))) { next; }
                   11994: 	if (%temp) {
                   11995: 	    $samples[$got]=\%temp;
                   11996: 	    $got++;
                   11997: 	    if ($got == $toget) { last; }
                   11998: 	}
                   11999:     }
                   12000:     return \@samples;
                   12001: }
                   12002: 
1.144     matthew  12003: ######################################################
                   12004: ######################################################
                   12005: 
1.56      matthew  12006: =pod
                   12007: 
1.648     raeburn  12008: =item * &csv_print_samples($r,$records)
1.41      ng       12009: 
                   12010: Prints a table of sample values from each column uploaded $r is an
                   12011: Apache Request ref, $records is an arrayref from
                   12012: &Apache::loncommon::upfile_record_sep
                   12013: 
                   12014: =cut
                   12015: 
1.144     matthew  12016: ######################################################
                   12017: ######################################################
1.31      albertel 12018: sub csv_print_samples {
                   12019:     my ($r,$records) = @_;
1.662     bisitz   12020:     my $samples = &get_samples($records,5);
1.301     albertel 12021: 
1.594     raeburn  12022:     $r->print(&mt('Samples').'<br />'.&start_data_table().
                   12023:               &start_data_table_header_row());
1.356     albertel 12024:     foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) { 
1.845     bisitz   12025:         $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594     raeburn  12026:     $r->print(&end_data_table_header_row());
1.301     albertel 12027:     foreach my $hash (@$samples) {
1.594     raeburn  12028: 	$r->print(&start_data_table_row());
1.356     albertel 12029: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31      albertel 12030: 	    $r->print('<td>');
1.356     albertel 12031: 	    if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31      albertel 12032: 	    $r->print('</td>');
                   12033: 	}
1.594     raeburn  12034: 	$r->print(&end_data_table_row());
1.31      albertel 12035:     }
1.594     raeburn  12036:     $r->print(&end_data_table().'<br />'."\n");
1.31      albertel 12037: }
                   12038: 
1.144     matthew  12039: ######################################################
                   12040: ######################################################
                   12041: 
1.56      matthew  12042: =pod
                   12043: 
1.648     raeburn  12044: =item * &csv_print_select_table($r,$records,$d)
1.41      ng       12045: 
                   12046: Prints a table to create associations between values and table columns.
1.144     matthew  12047: 
1.41      ng       12048: $r is an Apache Request ref,
                   12049: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174     matthew  12050: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41      ng       12051: 
                   12052: =cut
                   12053: 
1.144     matthew  12054: ######################################################
                   12055: ######################################################
1.31      albertel 12056: sub csv_print_select_table {
                   12057:     my ($r,$records,$d) = @_;
1.301     albertel 12058:     my $i=0;
                   12059:     my $samples = &get_samples($records,1);
1.144     matthew  12060:     $r->print(&mt('Associate columns with student attributes.')."\n".
1.594     raeburn  12061: 	      &start_data_table().&start_data_table_header_row().
1.144     matthew  12062:               '<th>'.&mt('Attribute').'</th>'.
1.594     raeburn  12063:               '<th>'.&mt('Column').'</th>'.
                   12064:               &end_data_table_header_row()."\n");
1.356     albertel 12065:     foreach my $array_ref (@$d) {
                   12066: 	my ($value,$display,$defaultcol)=@{ $array_ref };
1.729     raeburn  12067: 	$r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31      albertel 12068: 
1.875     bisitz   12069: 	$r->print('<td><select name="f'.$i.'"'.
1.32      matthew  12070: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.31      albertel 12071: 	$r->print('<option value="none"></option>');
1.356     albertel 12072: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
                   12073: 	    $r->print('<option value="'.$sample.'"'.
                   12074:                       ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662     bisitz   12075:                       '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31      albertel 12076: 	}
1.594     raeburn  12077: 	$r->print('</select></td>'.&end_data_table_row()."\n");
1.31      albertel 12078: 	$i++;
                   12079:     }
1.594     raeburn  12080:     $r->print(&end_data_table());
1.31      albertel 12081:     $i--;
                   12082:     return $i;
                   12083: }
1.56      matthew  12084: 
1.144     matthew  12085: ######################################################
                   12086: ######################################################
                   12087: 
1.56      matthew  12088: =pod
1.31      albertel 12089: 
1.648     raeburn  12090: =item * &csv_samples_select_table($r,$records,$d)
1.41      ng       12091: 
                   12092: Prints a table of sample values from the upload and can make associate samples to internal names.
                   12093: 
                   12094: $r is an Apache Request ref,
                   12095: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
                   12096: $d is an array of 2 element arrays (internal name, displayed name)
                   12097: 
                   12098: =cut
                   12099: 
1.144     matthew  12100: ######################################################
                   12101: ######################################################
1.31      albertel 12102: sub csv_samples_select_table {
                   12103:     my ($r,$records,$d) = @_;
                   12104:     my $i=0;
1.144     matthew  12105:     #
1.662     bisitz   12106:     my $max_samples = 5;
                   12107:     my $samples = &get_samples($records,$max_samples);
1.594     raeburn  12108:     $r->print(&start_data_table().
                   12109:               &start_data_table_header_row().'<th>'.
                   12110:               &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
                   12111:               &end_data_table_header_row());
1.301     albertel 12112: 
                   12113:     foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594     raeburn  12114: 	$r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32      matthew  12115: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.301     albertel 12116: 	foreach my $option (@$d) {
                   12117: 	    my ($value,$display,$defaultcol)=@{ $option };
1.174     matthew  12118: 	    $r->print('<option value="'.$value.'"'.
1.253     albertel 12119:                       ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174     matthew  12120:                       $display.'</option>');
1.31      albertel 12121: 	}
                   12122: 	$r->print('</select></td><td>');
1.662     bisitz   12123: 	foreach my $line (0..($max_samples-1)) {
1.301     albertel 12124: 	    if (defined($samples->[$line]{$key})) { 
                   12125: 		$r->print($samples->[$line]{$key}."<br />\n"); 
                   12126: 	    }
                   12127: 	}
1.594     raeburn  12128: 	$r->print('</td>'.&end_data_table_row());
1.31      albertel 12129: 	$i++;
                   12130:     }
1.594     raeburn  12131:     $r->print(&end_data_table());
1.31      albertel 12132:     $i--;
                   12133:     return($i);
1.115     matthew  12134: }
                   12135: 
1.144     matthew  12136: ######################################################
                   12137: ######################################################
                   12138: 
1.115     matthew  12139: =pod
                   12140: 
1.648     raeburn  12141: =item * &clean_excel_name($name)
1.115     matthew  12142: 
                   12143: Returns a replacement for $name which does not contain any illegal characters.
                   12144: 
                   12145: =cut
                   12146: 
1.144     matthew  12147: ######################################################
                   12148: ######################################################
1.115     matthew  12149: sub clean_excel_name {
                   12150:     my ($name) = @_;
                   12151:     $name =~ s/[:\*\?\/\\]//g;
                   12152:     if (length($name) > 31) {
                   12153:         $name = substr($name,0,31);
                   12154:     }
                   12155:     return $name;
1.25      albertel 12156: }
1.84      albertel 12157: 
1.85      albertel 12158: =pod
                   12159: 
1.648     raeburn  12160: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85      albertel 12161: 
                   12162: Returns either 1 or undef
                   12163: 
                   12164: 1 if the part is to be hidden, undef if it is to be shown
                   12165: 
                   12166: Arguments are:
                   12167: 
                   12168: $id the id of the part to be checked
                   12169: $symb, optional the symb of the resource to check
                   12170: $udom, optional the domain of the user to check for
                   12171: $uname, optional the username of the user to check for
                   12172: 
                   12173: =cut
1.84      albertel 12174: 
                   12175: sub check_if_partid_hidden {
                   12176:     my ($id,$symb,$udom,$uname) = @_;
1.133     albertel 12177:     my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84      albertel 12178: 					 $symb,$udom,$uname);
1.141     albertel 12179:     my $truth=1;
                   12180:     #if the string starts with !, then the list is the list to show not hide
                   12181:     if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84      albertel 12182:     my @hiddenlist=split(/,/,$hiddenparts);
                   12183:     foreach my $checkid (@hiddenlist) {
1.141     albertel 12184: 	if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84      albertel 12185:     }
1.141     albertel 12186:     return !$truth;
1.84      albertel 12187: }
1.127     matthew  12188: 
1.138     matthew  12189: 
                   12190: ############################################################
                   12191: ############################################################
                   12192: 
                   12193: =pod
                   12194: 
1.157     matthew  12195: =back 
                   12196: 
1.138     matthew  12197: =head1 cgi-bin script and graphing routines
                   12198: 
1.157     matthew  12199: =over 4
                   12200: 
1.648     raeburn  12201: =item * &get_cgi_id()
1.138     matthew  12202: 
                   12203: Inputs: none
                   12204: 
                   12205: Returns an id which can be used to pass environment variables
                   12206: to various cgi-bin scripts.  These environment variables will
                   12207: be removed from the users environment after a given time by
                   12208: the routine &Apache::lonnet::transfer_profile_to_env.
                   12209: 
                   12210: =cut
                   12211: 
                   12212: ############################################################
                   12213: ############################################################
1.152     albertel 12214: my $uniq=0;
1.136     matthew  12215: sub get_cgi_id {
1.154     albertel 12216:     $uniq=($uniq+1)%100000;
1.280     albertel 12217:     return (time.'_'.$$.'_'.$uniq);
1.136     matthew  12218: }
                   12219: 
1.127     matthew  12220: ############################################################
                   12221: ############################################################
                   12222: 
                   12223: =pod
                   12224: 
1.648     raeburn  12225: =item * &DrawBarGraph()
1.127     matthew  12226: 
1.138     matthew  12227: Facilitates the plotting of data in a (stacked) bar graph.
                   12228: Puts plot definition data into the users environment in order for 
                   12229: graph.png to plot it.  Returns an <img> tag for the plot.
                   12230: The bars on the plot are labeled '1','2',...,'n'.
                   12231: 
                   12232: Inputs:
                   12233: 
                   12234: =over 4
                   12235: 
                   12236: =item $Title: string, the title of the plot
                   12237: 
                   12238: =item $xlabel: string, text describing the X-axis of the plot
                   12239: 
                   12240: =item $ylabel: string, text describing the Y-axis of the plot
                   12241: 
                   12242: =item $Max: scalar, the maximum Y value to use in the plot
                   12243: If $Max is < any data point, the graph will not be rendered.
                   12244: 
1.140     matthew  12245: =item $colors: array ref holding the colors to be used for the data sets when
1.138     matthew  12246: they are plotted.  If undefined, default values will be used.
                   12247: 
1.178     matthew  12248: =item $labels: array ref holding the labels to use on the x-axis for the bars.
                   12249: 
1.138     matthew  12250: =item @Values: An array of array references.  Each array reference holds data
                   12251: to be plotted in a stacked bar chart.
                   12252: 
1.239     matthew  12253: =item If the final element of @Values is a hash reference the key/value
                   12254: pairs will be added to the graph definition.
                   12255: 
1.138     matthew  12256: =back
                   12257: 
                   12258: Returns:
                   12259: 
                   12260: An <img> tag which references graph.png and the appropriate identifying
                   12261: information for the plot.
                   12262: 
1.127     matthew  12263: =cut
                   12264: 
                   12265: ############################################################
                   12266: ############################################################
1.134     matthew  12267: sub DrawBarGraph {
1.178     matthew  12268:     my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134     matthew  12269:     #
                   12270:     if (! defined($colors)) {
                   12271:         $colors = ['#33ff00', 
                   12272:                   '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
                   12273:                   '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
                   12274:                   ]; 
                   12275:     }
1.228     matthew  12276:     my $extra_settings = {};
                   12277:     if (ref($Values[-1]) eq 'HASH') {
                   12278:         $extra_settings = pop(@Values);
                   12279:     }
1.127     matthew  12280:     #
1.136     matthew  12281:     my $identifier = &get_cgi_id();
                   12282:     my $id = 'cgi.'.$identifier;        
1.129     matthew  12283:     if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127     matthew  12284:         return '';
                   12285:     }
1.225     matthew  12286:     #
                   12287:     my @Labels;
                   12288:     if (defined($labels)) {
                   12289:         @Labels = @$labels;
                   12290:     } else {
                   12291:         for (my $i=0;$i<@{$Values[0]};$i++) {
                   12292:             push (@Labels,$i+1);
                   12293:         }
                   12294:     }
                   12295:     #
1.129     matthew  12296:     my $NumBars = scalar(@{$Values[0]});
1.225     matthew  12297:     if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129     matthew  12298:     my %ValuesHash;
                   12299:     my $NumSets=1;
                   12300:     foreach my $array (@Values) {
                   12301:         next if (! ref($array));
1.136     matthew  12302:         $ValuesHash{$id.'.data.'.$NumSets++} = 
1.132     matthew  12303:             join(',',@$array);
1.129     matthew  12304:     }
1.127     matthew  12305:     #
1.136     matthew  12306:     my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225     matthew  12307:     if ($NumBars < 3) {
                   12308:         $width = 120+$NumBars*32;
1.220     matthew  12309:         $xskip = 1;
1.225     matthew  12310:         $bar_width = 30;
                   12311:     } elsif ($NumBars < 5) {
                   12312:         $width = 120+$NumBars*20;
                   12313:         $xskip = 1;
                   12314:         $bar_width = 20;
1.220     matthew  12315:     } elsif ($NumBars < 10) {
1.136     matthew  12316:         $width = 120+$NumBars*15;
                   12317:         $xskip = 1;
                   12318:         $bar_width = 15;
                   12319:     } elsif ($NumBars <= 25) {
                   12320:         $width = 120+$NumBars*11;
                   12321:         $xskip = 5;
                   12322:         $bar_width = 8;
                   12323:     } elsif ($NumBars <= 50) {
                   12324:         $width = 120+$NumBars*8;
                   12325:         $xskip = 5;
                   12326:         $bar_width = 4;
                   12327:     } else {
                   12328:         $width = 120+$NumBars*8;
                   12329:         $xskip = 5;
                   12330:         $bar_width = 4;
                   12331:     }
                   12332:     #
1.137     matthew  12333:     $Max = 1 if ($Max < 1);
                   12334:     if ( int($Max) < $Max ) {
                   12335:         $Max++;
                   12336:         $Max = int($Max);
                   12337:     }
1.127     matthew  12338:     $Title  = '' if (! defined($Title));
                   12339:     $xlabel = '' if (! defined($xlabel));
                   12340:     $ylabel = '' if (! defined($ylabel));
1.369     www      12341:     $ValuesHash{$id.'.title'}    = &escape($Title);
                   12342:     $ValuesHash{$id.'.xlabel'}   = &escape($xlabel);
                   12343:     $ValuesHash{$id.'.ylabel'}   = &escape($ylabel);
1.137     matthew  12344:     $ValuesHash{$id.'.y_max_value'} = $Max;
1.136     matthew  12345:     $ValuesHash{$id.'.NumBars'}  = $NumBars;
                   12346:     $ValuesHash{$id.'.NumSets'}  = $NumSets;
                   12347:     $ValuesHash{$id.'.PlotType'} = 'bar';
                   12348:     $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   12349:     $ValuesHash{$id.'.height'}   = $height;
                   12350:     $ValuesHash{$id.'.width'}    = $width;
                   12351:     $ValuesHash{$id.'.xskip'}    = $xskip;
                   12352:     $ValuesHash{$id.'.bar_width'} = $bar_width;
                   12353:     $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127     matthew  12354:     #
1.228     matthew  12355:     # Deal with other parameters
                   12356:     while (my ($key,$value) = each(%$extra_settings)) {
                   12357:         $ValuesHash{$id.'.'.$key} = $value;
                   12358:     }
                   12359:     #
1.646     raeburn  12360:     &Apache::lonnet::appenv(\%ValuesHash);
1.137     matthew  12361:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   12362: }
                   12363: 
                   12364: ############################################################
                   12365: ############################################################
                   12366: 
                   12367: =pod
                   12368: 
1.648     raeburn  12369: =item * &DrawXYGraph()
1.137     matthew  12370: 
1.138     matthew  12371: Facilitates the plotting of data in an XY graph.
                   12372: Puts plot definition data into the users environment in order for 
                   12373: graph.png to plot it.  Returns an <img> tag for the plot.
                   12374: 
                   12375: Inputs:
                   12376: 
                   12377: =over 4
                   12378: 
                   12379: =item $Title: string, the title of the plot
                   12380: 
                   12381: =item $xlabel: string, text describing the X-axis of the plot
                   12382: 
                   12383: =item $ylabel: string, text describing the Y-axis of the plot
                   12384: 
                   12385: =item $Max: scalar, the maximum Y value to use in the plot
                   12386: If $Max is < any data point, the graph will not be rendered.
                   12387: 
                   12388: =item $colors: Array ref containing the hex color codes for the data to be 
                   12389: plotted in.  If undefined, default values will be used.
                   12390: 
                   12391: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   12392: 
                   12393: =item $Ydata: Array ref containing Array refs.  
1.185     www      12394: Each of the contained arrays will be plotted as a separate curve.
1.138     matthew  12395: 
                   12396: =item %Values: hash indicating or overriding any default values which are 
                   12397: passed to graph.png.  
                   12398: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   12399: 
                   12400: =back
                   12401: 
                   12402: Returns:
                   12403: 
                   12404: An <img> tag which references graph.png and the appropriate identifying
                   12405: information for the plot.
                   12406: 
1.137     matthew  12407: =cut
                   12408: 
                   12409: ############################################################
                   12410: ############################################################
                   12411: sub DrawXYGraph {
                   12412:     my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
                   12413:     #
                   12414:     # Create the identifier for the graph
                   12415:     my $identifier = &get_cgi_id();
                   12416:     my $id = 'cgi.'.$identifier;
                   12417:     #
                   12418:     $Title  = '' if (! defined($Title));
                   12419:     $xlabel = '' if (! defined($xlabel));
                   12420:     $ylabel = '' if (! defined($ylabel));
                   12421:     my %ValuesHash = 
                   12422:         (
1.369     www      12423:          $id.'.title'  => &escape($Title),
                   12424:          $id.'.xlabel' => &escape($xlabel),
                   12425:          $id.'.ylabel' => &escape($ylabel),
1.137     matthew  12426:          $id.'.y_max_value'=> $Max,
                   12427:          $id.'.labels'     => join(',',@$Xlabels),
                   12428:          $id.'.PlotType'   => 'XY',
                   12429:          );
                   12430:     #
                   12431:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   12432:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   12433:     }
                   12434:     #
                   12435:     if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
                   12436:         return '';
                   12437:     }
                   12438:     my $NumSets=1;
1.138     matthew  12439:     foreach my $array (@{$Ydata}){
1.137     matthew  12440:         next if (! ref($array));
                   12441:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
                   12442:     }
1.138     matthew  12443:     $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137     matthew  12444:     #
                   12445:     # Deal with other parameters
                   12446:     while (my ($key,$value) = each(%Values)) {
                   12447:         $ValuesHash{$id.'.'.$key} = $value;
1.127     matthew  12448:     }
                   12449:     #
1.646     raeburn  12450:     &Apache::lonnet::appenv(\%ValuesHash);
1.136     matthew  12451:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   12452: }
                   12453: 
                   12454: ############################################################
                   12455: ############################################################
                   12456: 
                   12457: =pod
                   12458: 
1.648     raeburn  12459: =item * &DrawXYYGraph()
1.138     matthew  12460: 
                   12461: Facilitates the plotting of data in an XY graph with two Y axes.
                   12462: Puts plot definition data into the users environment in order for 
                   12463: graph.png to plot it.  Returns an <img> tag for the plot.
                   12464: 
                   12465: Inputs:
                   12466: 
                   12467: =over 4
                   12468: 
                   12469: =item $Title: string, the title of the plot
                   12470: 
                   12471: =item $xlabel: string, text describing the X-axis of the plot
                   12472: 
                   12473: =item $ylabel: string, text describing the Y-axis of the plot
                   12474: 
                   12475: =item $colors: Array ref containing the hex color codes for the data to be 
                   12476: plotted in.  If undefined, default values will be used.
                   12477: 
                   12478: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   12479: 
                   12480: =item $Ydata1: The first data set
                   12481: 
                   12482: =item $Min1: The minimum value of the left Y-axis
                   12483: 
                   12484: =item $Max1: The maximum value of the left Y-axis
                   12485: 
                   12486: =item $Ydata2: The second data set
                   12487: 
                   12488: =item $Min2: The minimum value of the right Y-axis
                   12489: 
                   12490: =item $Max2: The maximum value of the left Y-axis
                   12491: 
                   12492: =item %Values: hash indicating or overriding any default values which are 
                   12493: passed to graph.png.  
                   12494: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   12495: 
                   12496: =back
                   12497: 
                   12498: Returns:
                   12499: 
                   12500: An <img> tag which references graph.png and the appropriate identifying
                   12501: information for the plot.
1.136     matthew  12502: 
                   12503: =cut
                   12504: 
                   12505: ############################################################
                   12506: ############################################################
1.137     matthew  12507: sub DrawXYYGraph {
                   12508:     my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
                   12509:                                         $Ydata2,$Min2,$Max2,%Values)=@_;
1.136     matthew  12510:     #
                   12511:     # Create the identifier for the graph
                   12512:     my $identifier = &get_cgi_id();
                   12513:     my $id = 'cgi.'.$identifier;
                   12514:     #
                   12515:     $Title  = '' if (! defined($Title));
                   12516:     $xlabel = '' if (! defined($xlabel));
                   12517:     $ylabel = '' if (! defined($ylabel));
                   12518:     my %ValuesHash = 
                   12519:         (
1.369     www      12520:          $id.'.title'  => &escape($Title),
                   12521:          $id.'.xlabel' => &escape($xlabel),
                   12522:          $id.'.ylabel' => &escape($ylabel),
1.136     matthew  12523:          $id.'.labels' => join(',',@$Xlabels),
                   12524:          $id.'.PlotType' => 'XY',
                   12525:          $id.'.NumSets' => 2,
1.137     matthew  12526:          $id.'.two_axes' => 1,
                   12527:          $id.'.y1_max_value' => $Max1,
                   12528:          $id.'.y1_min_value' => $Min1,
                   12529:          $id.'.y2_max_value' => $Max2,
                   12530:          $id.'.y2_min_value' => $Min2,
1.136     matthew  12531:          );
                   12532:     #
1.137     matthew  12533:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   12534:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   12535:     }
                   12536:     #
                   12537:     if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
                   12538:         ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136     matthew  12539:         return '';
                   12540:     }
                   12541:     my $NumSets=1;
1.137     matthew  12542:     foreach my $array ($Ydata1,$Ydata2){
1.136     matthew  12543:         next if (! ref($array));
                   12544:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137     matthew  12545:     }
                   12546:     #
                   12547:     # Deal with other parameters
                   12548:     while (my ($key,$value) = each(%Values)) {
                   12549:         $ValuesHash{$id.'.'.$key} = $value;
1.136     matthew  12550:     }
                   12551:     #
1.646     raeburn  12552:     &Apache::lonnet::appenv(\%ValuesHash);
1.130     albertel 12553:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139     matthew  12554: }
                   12555: 
                   12556: ############################################################
                   12557: ############################################################
                   12558: 
                   12559: =pod
                   12560: 
1.157     matthew  12561: =back 
                   12562: 
1.139     matthew  12563: =head1 Statistics helper routines?  
                   12564: 
                   12565: Bad place for them but what the hell.
                   12566: 
1.157     matthew  12567: =over 4
                   12568: 
1.648     raeburn  12569: =item * &chartlink()
1.139     matthew  12570: 
                   12571: Returns a link to the chart for a specific student.  
                   12572: 
                   12573: Inputs:
                   12574: 
                   12575: =over 4
                   12576: 
                   12577: =item $linktext: The text of the link
                   12578: 
                   12579: =item $sname: The students username
                   12580: 
                   12581: =item $sdomain: The students domain
                   12582: 
                   12583: =back
                   12584: 
1.157     matthew  12585: =back
                   12586: 
1.139     matthew  12587: =cut
                   12588: 
                   12589: ############################################################
                   12590: ############################################################
                   12591: sub chartlink {
                   12592:     my ($linktext, $sname, $sdomain) = @_;
                   12593:     my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369     www      12594:         '&amp;SelectedStudent='.&escape($sname.':'.$sdomain).
1.219     albertel 12595:         '&amp;chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139     matthew  12596:        '">'.$linktext.'</a>';
1.153     matthew  12597: }
                   12598: 
                   12599: #######################################################
                   12600: #######################################################
                   12601: 
                   12602: =pod
                   12603: 
                   12604: =head1 Course Environment Routines
1.157     matthew  12605: 
                   12606: =over 4
1.153     matthew  12607: 
1.648     raeburn  12608: =item * &restore_course_settings()
1.153     matthew  12609: 
1.648     raeburn  12610: =item * &store_course_settings()
1.153     matthew  12611: 
                   12612: Restores/Store indicated form parameters from the course environment.
                   12613: Will not overwrite existing values of the form parameters.
                   12614: 
                   12615: Inputs: 
                   12616: a scalar describing the data (e.g. 'chart', 'problem_analysis')
                   12617: 
                   12618: a hash ref describing the data to be stored.  For example:
                   12619:    
                   12620: %Save_Parameters = ('Status' => 'scalar',
                   12621:     'chartoutputmode' => 'scalar',
                   12622:     'chartoutputdata' => 'scalar',
                   12623:     'Section' => 'array',
1.373     raeburn  12624:     'Group' => 'array',
1.153     matthew  12625:     'StudentData' => 'array',
                   12626:     'Maps' => 'array');
                   12627: 
                   12628: Returns: both routines return nothing
                   12629: 
1.631     raeburn  12630: =back
                   12631: 
1.153     matthew  12632: =cut
                   12633: 
                   12634: #######################################################
                   12635: #######################################################
                   12636: sub store_course_settings {
1.496     albertel 12637:     return &store_settings($env{'request.course.id'},@_);
                   12638: }
                   12639: 
                   12640: sub store_settings {
1.153     matthew  12641:     # save to the environment
                   12642:     # appenv the same items, just to be safe
1.300     albertel 12643:     my $udom  = $env{'user.domain'};
                   12644:     my $uname = $env{'user.name'};
1.496     albertel 12645:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  12646:     my %SaveHash;
                   12647:     my %AppHash;
                   12648:     while (my ($setting,$type) = each(%$Settings)) {
1.496     albertel 12649:         my $basename = join('.','internal',$context,$prefix,$setting);
1.300     albertel 12650:         my $envname = 'environment.'.$basename;
1.258     albertel 12651:         if (exists($env{'form.'.$setting})) {
1.153     matthew  12652:             # Save this value away
                   12653:             if ($type eq 'scalar' &&
1.258     albertel 12654:                 (! exists($env{$envname}) || 
                   12655:                  $env{$envname} ne $env{'form.'.$setting})) {
                   12656:                 $SaveHash{$basename} = $env{'form.'.$setting};
                   12657:                 $AppHash{$envname}   = $env{'form.'.$setting};
1.153     matthew  12658:             } elsif ($type eq 'array') {
                   12659:                 my $stored_form;
1.258     albertel 12660:                 if (ref($env{'form.'.$setting})) {
1.153     matthew  12661:                     $stored_form = join(',',
                   12662:                                         map {
1.369     www      12663:                                             &escape($_);
1.258     albertel 12664:                                         } sort(@{$env{'form.'.$setting}}));
1.153     matthew  12665:                 } else {
                   12666:                     $stored_form = 
1.369     www      12667:                         &escape($env{'form.'.$setting});
1.153     matthew  12668:                 }
                   12669:                 # Determine if the array contents are the same.
1.258     albertel 12670:                 if ($stored_form ne $env{$envname}) {
1.153     matthew  12671:                     $SaveHash{$basename} = $stored_form;
                   12672:                     $AppHash{$envname}   = $stored_form;
                   12673:                 }
                   12674:             }
                   12675:         }
                   12676:     }
                   12677:     my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300     albertel 12678:                                           $udom,$uname);
1.153     matthew  12679:     if ($put_result !~ /^(ok|delayed)/) {
                   12680:         &Apache::lonnet::logthis('unable to save form parameters, '.
                   12681:                                  'got error:'.$put_result);
                   12682:     }
                   12683:     # Make sure these settings stick around in this session, too
1.646     raeburn  12684:     &Apache::lonnet::appenv(\%AppHash);
1.153     matthew  12685:     return;
                   12686: }
                   12687: 
                   12688: sub restore_course_settings {
1.499     albertel 12689:     return &restore_settings($env{'request.course.id'},@_);
1.496     albertel 12690: }
                   12691: 
                   12692: sub restore_settings {
                   12693:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  12694:     while (my ($setting,$type) = each(%$Settings)) {
1.258     albertel 12695:         next if (exists($env{'form.'.$setting}));
1.496     albertel 12696:         my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153     matthew  12697:             '.'.$setting;
1.258     albertel 12698:         if (exists($env{$envname})) {
1.153     matthew  12699:             if ($type eq 'scalar') {
1.258     albertel 12700:                 $env{'form.'.$setting} = $env{$envname};
1.153     matthew  12701:             } elsif ($type eq 'array') {
1.258     albertel 12702:                 $env{'form.'.$setting} = [ 
1.153     matthew  12703:                                            map { 
1.369     www      12704:                                                &unescape($_); 
1.258     albertel 12705:                                            } split(',',$env{$envname})
1.153     matthew  12706:                                            ];
                   12707:             }
                   12708:         }
                   12709:     }
1.127     matthew  12710: }
                   12711: 
1.618     raeburn  12712: #######################################################
                   12713: #######################################################
                   12714: 
                   12715: =pod
                   12716: 
                   12717: =head1 Domain E-mail Routines  
                   12718: 
                   12719: =over 4
                   12720: 
1.648     raeburn  12721: =item * &build_recipient_list()
1.618     raeburn  12722: 
1.884     raeburn  12723: Build recipient lists for five types of e-mail:
1.766     raeburn  12724: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.884     raeburn  12725: (d) Help requests, (e) Course requests needing approval,  generated by
                   12726: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
                   12727: loncoursequeueadmin.pm respectively.
1.618     raeburn  12728: 
                   12729: Inputs:
1.619     raeburn  12730: defmail (scalar - email address of default recipient), 
1.618     raeburn  12731: mailing type (scalar - errormail, packagesmail, or helpdeskmail), 
1.619     raeburn  12732: defdom (domain for which to retrieve configuration settings),
                   12733: origmail (scalar - email address of recipient from loncapa.conf, 
                   12734: i.e., predates configuration by DC via domainprefs.pm 
1.618     raeburn  12735: 
1.655     raeburn  12736: Returns: comma separated list of addresses to which to send e-mail.
                   12737: 
                   12738: =back
1.618     raeburn  12739: 
                   12740: =cut
                   12741: 
                   12742: ############################################################
                   12743: ############################################################
                   12744: sub build_recipient_list {
1.619     raeburn  12745:     my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618     raeburn  12746:     my @recipients;
                   12747:     my $otheremails;
                   12748:     my %domconfig =
                   12749:          &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
                   12750:     if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766     raeburn  12751:         if (exists($domconfig{'contacts'}{$mailing})) {
                   12752:             if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
                   12753:                 my @contacts = ('adminemail','supportemail');
                   12754:                 foreach my $item (@contacts) {
                   12755:                     if ($domconfig{'contacts'}{$mailing}{$item}) {
                   12756:                         my $addr = $domconfig{'contacts'}{$item}; 
                   12757:                         if (!grep(/^\Q$addr\E$/,@recipients)) {
                   12758:                             push(@recipients,$addr);
                   12759:                         }
1.619     raeburn  12760:                     }
1.766     raeburn  12761:                     $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618     raeburn  12762:                 }
                   12763:             }
1.766     raeburn  12764:         } elsif ($origmail ne '') {
                   12765:             push(@recipients,$origmail);
1.618     raeburn  12766:         }
1.619     raeburn  12767:     } elsif ($origmail ne '') {
                   12768:         push(@recipients,$origmail);
1.618     raeburn  12769:     }
1.688     raeburn  12770:     if (defined($defmail)) {
                   12771:         if ($defmail ne '') {
                   12772:             push(@recipients,$defmail);
                   12773:         }
1.618     raeburn  12774:     }
                   12775:     if ($otheremails) {
1.619     raeburn  12776:         my @others;
                   12777:         if ($otheremails =~ /,/) {
                   12778:             @others = split(/,/,$otheremails);
1.618     raeburn  12779:         } else {
1.619     raeburn  12780:             push(@others,$otheremails);
                   12781:         }
                   12782:         foreach my $addr (@others) {
                   12783:             if (!grep(/^\Q$addr\E$/,@recipients)) {
                   12784:                 push(@recipients,$addr);
                   12785:             }
1.618     raeburn  12786:         }
                   12787:     }
1.619     raeburn  12788:     my $recipientlist = join(',',@recipients); 
1.618     raeburn  12789:     return $recipientlist;
                   12790: }
                   12791: 
1.127     matthew  12792: ############################################################
                   12793: ############################################################
1.154     albertel 12794: 
1.655     raeburn  12795: =pod
                   12796: 
                   12797: =head1 Course Catalog Routines
                   12798: 
                   12799: =over 4
                   12800: 
                   12801: =item * &gather_categories()
                   12802: 
                   12803: Converts category definitions - keys of categories hash stored in  
                   12804: coursecategories in configuration.db on the primary library server in a 
                   12805: domain - to an array.  Also generates javascript and idx hash used to 
                   12806: generate Domain Coordinator interface for editing Course Categories.
                   12807: 
                   12808: Inputs:
1.663     raeburn  12809: 
1.655     raeburn  12810: categories (reference to hash of category definitions).
1.663     raeburn  12811: 
1.655     raeburn  12812: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   12813:       categories and subcategories).
1.663     raeburn  12814: 
1.655     raeburn  12815: idx (reference to hash of counters used in Domain Coordinator interface for 
                   12816:       editing Course Categories).
1.663     raeburn  12817: 
1.655     raeburn  12818: jsarray (reference to array of categories used to create Javascript arrays for
                   12819:          Domain Coordinator interface for editing Course Categories).
                   12820: 
                   12821: Returns: nothing
                   12822: 
                   12823: Side effects: populates cats, idx and jsarray. 
                   12824: 
                   12825: =cut
                   12826: 
                   12827: sub gather_categories {
                   12828:     my ($categories,$cats,$idx,$jsarray) = @_;
                   12829:     my %counters;
                   12830:     my $num = 0;
                   12831:     foreach my $item (keys(%{$categories})) {
                   12832:         my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   12833:         if ($container eq '' && $depth == 0) {
                   12834:             $cats->[$depth][$categories->{$item}] = $cat;
                   12835:         } else {
                   12836:             $cats->[$depth]{$container}[$categories->{$item}] = $cat;
                   12837:         }
                   12838:         my ($escitem,$tail) = split(/:/,$item,2);
                   12839:         if ($counters{$tail} eq '') {
                   12840:             $counters{$tail} = $num;
                   12841:             $num ++;
                   12842:         }
                   12843:         if (ref($idx) eq 'HASH') {
                   12844:             $idx->{$item} = $counters{$tail};
                   12845:         }
                   12846:         if (ref($jsarray) eq 'ARRAY') {
                   12847:             push(@{$jsarray->[$counters{$tail}]},$item);
                   12848:         }
                   12849:     }
                   12850:     return;
                   12851: }
                   12852: 
                   12853: =pod
                   12854: 
                   12855: =item * &extract_categories()
                   12856: 
                   12857: Used to generate breadcrumb trails for course categories.
                   12858: 
                   12859: Inputs:
1.663     raeburn  12860: 
1.655     raeburn  12861: categories (reference to hash of category definitions).
1.663     raeburn  12862: 
1.655     raeburn  12863: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   12864:       categories and subcategories).
1.663     raeburn  12865: 
1.655     raeburn  12866: trails (reference to array of breacrumb trails for each category).
1.663     raeburn  12867: 
1.655     raeburn  12868: allitems (reference to hash - key is category key 
                   12869:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  12870: 
1.655     raeburn  12871: idx (reference to hash of counters used in Domain Coordinator interface for
                   12872:       editing Course Categories).
1.663     raeburn  12873: 
1.655     raeburn  12874: jsarray (reference to array of categories used to create Javascript arrays for
                   12875:          Domain Coordinator interface for editing Course Categories).
                   12876: 
1.665     raeburn  12877: subcats (reference to hash of arrays containing all subcategories within each 
                   12878:          category, -recursive)
                   12879: 
1.655     raeburn  12880: Returns: nothing
                   12881: 
                   12882: Side effects: populates trails and allitems hash references.
                   12883: 
                   12884: =cut
                   12885: 
                   12886: sub extract_categories {
1.665     raeburn  12887:     my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655     raeburn  12888:     if (ref($categories) eq 'HASH') {
                   12889:         &gather_categories($categories,$cats,$idx,$jsarray);
                   12890:         if (ref($cats->[0]) eq 'ARRAY') {
                   12891:             for (my $i=0; $i<@{$cats->[0]}; $i++) {
                   12892:                 my $name = $cats->[0][$i];
                   12893:                 my $item = &escape($name).'::0';
                   12894:                 my $trailstr;
                   12895:                 if ($name eq 'instcode') {
                   12896:                     $trailstr = &mt('Official courses (with institutional codes)');
1.919     raeburn  12897:                 } elsif ($name eq 'communities') {
                   12898:                     $trailstr = &mt('Communities');
1.655     raeburn  12899:                 } else {
                   12900:                     $trailstr = $name;
                   12901:                 }
                   12902:                 if ($allitems->{$item} eq '') {
                   12903:                     push(@{$trails},$trailstr);
                   12904:                     $allitems->{$item} = scalar(@{$trails})-1;
                   12905:                 }
                   12906:                 my @parents = ($name);
                   12907:                 if (ref($cats->[1]{$name}) eq 'ARRAY') {
                   12908:                     for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
                   12909:                         my $category = $cats->[1]{$name}[$j];
1.665     raeburn  12910:                         if (ref($subcats) eq 'HASH') {
                   12911:                             push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
                   12912:                         }
                   12913:                         &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
                   12914:                     }
                   12915:                 } else {
                   12916:                     if (ref($subcats) eq 'HASH') {
                   12917:                         $subcats->{$item} = [];
1.655     raeburn  12918:                     }
                   12919:                 }
                   12920:             }
                   12921:         }
                   12922:     }
                   12923:     return;
                   12924: }
                   12925: 
                   12926: =pod
                   12927: 
                   12928: =item *&recurse_categories()
                   12929: 
                   12930: Recursively used to generate breadcrumb trails for course categories.
                   12931: 
                   12932: Inputs:
1.663     raeburn  12933: 
1.655     raeburn  12934: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   12935:       categories and subcategories).
1.663     raeburn  12936: 
1.655     raeburn  12937: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663     raeburn  12938: 
                   12939: category (current course category, for which breadcrumb trail is being generated).
                   12940: 
                   12941: trails (reference to array of breadcrumb trails for each category).
                   12942: 
1.655     raeburn  12943: allitems (reference to hash - key is category key
                   12944:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  12945: 
1.655     raeburn  12946: parents (array containing containers directories for current category, 
                   12947:          back to top level). 
                   12948: 
                   12949: Returns: nothing
                   12950: 
                   12951: Side effects: populates trails and allitems hash references
                   12952: 
                   12953: =cut
                   12954: 
                   12955: sub recurse_categories {
1.665     raeburn  12956:     my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655     raeburn  12957:     my $shallower = $depth - 1;
                   12958:     if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
                   12959:         for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
                   12960:             my $name = $cats->[$depth]{$category}[$k];
                   12961:             my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   12962:             my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   12963:             if ($allitems->{$item} eq '') {
                   12964:                 push(@{$trails},$trailstr);
                   12965:                 $allitems->{$item} = scalar(@{$trails})-1;
                   12966:             }
                   12967:             my $deeper = $depth+1;
                   12968:             push(@{$parents},$category);
1.665     raeburn  12969:             if (ref($subcats) eq 'HASH') {
                   12970:                 my $subcat = &escape($name).':'.$category.':'.$depth;
                   12971:                 for (my $j=@{$parents}; $j>=0; $j--) {
                   12972:                     my $higher;
                   12973:                     if ($j > 0) {
                   12974:                         $higher = &escape($parents->[$j]).':'.
                   12975:                                   &escape($parents->[$j-1]).':'.$j;
                   12976:                     } else {
                   12977:                         $higher = &escape($parents->[$j]).'::'.$j;
                   12978:                     }
                   12979:                     push(@{$subcats->{$higher}},$subcat);
                   12980:                 }
                   12981:             }
                   12982:             &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
                   12983:                                 $subcats);
1.655     raeburn  12984:             pop(@{$parents});
                   12985:         }
                   12986:     } else {
                   12987:         my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   12988:         my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   12989:         if ($allitems->{$item} eq '') {
                   12990:             push(@{$trails},$trailstr);
                   12991:             $allitems->{$item} = scalar(@{$trails})-1;
                   12992:         }
                   12993:     }
                   12994:     return;
                   12995: }
                   12996: 
1.663     raeburn  12997: =pod
                   12998: 
                   12999: =item *&assign_categories_table()
                   13000: 
                   13001: Create a datatable for display of hierarchical categories in a domain,
                   13002: with checkboxes to allow a course to be categorized. 
                   13003: 
                   13004: Inputs:
                   13005: 
                   13006: cathash - reference to hash of categories defined for the domain (from
                   13007:           configuration.db)
                   13008: 
                   13009: currcat - scalar with an & separated list of categories assigned to a course. 
                   13010: 
1.919     raeburn  13011: type    - scalar contains course type (Course or Community).
                   13012: 
1.663     raeburn  13013: Returns: $output (markup to be displayed) 
                   13014: 
                   13015: =cut
                   13016: 
                   13017: sub assign_categories_table {
1.919     raeburn  13018:     my ($cathash,$currcat,$type) = @_;
1.663     raeburn  13019:     my $output;
                   13020:     if (ref($cathash) eq 'HASH') {
                   13021:         my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
                   13022:         &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
                   13023:         $maxdepth = scalar(@cats);
                   13024:         if (@cats > 0) {
                   13025:             my $itemcount = 0;
                   13026:             if (ref($cats[0]) eq 'ARRAY') {
                   13027:                 my @currcategories;
                   13028:                 if ($currcat ne '') {
                   13029:                     @currcategories = split('&',$currcat);
                   13030:                 }
1.919     raeburn  13031:                 my $table;
1.663     raeburn  13032:                 for (my $i=0; $i<@{$cats[0]}; $i++) {
                   13033:                     my $parent = $cats[0][$i];
1.919     raeburn  13034:                     next if ($parent eq 'instcode');
                   13035:                     if ($type eq 'Community') {
                   13036:                         next unless ($parent eq 'communities');
                   13037:                     } else {
                   13038:                         next if ($parent eq 'communities');
                   13039:                     }
1.663     raeburn  13040:                     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   13041:                     my $item = &escape($parent).'::0';
                   13042:                     my $checked = '';
                   13043:                     if (@currcategories > 0) {
                   13044:                         if (grep(/^\Q$item\E$/,@currcategories)) {
1.772     bisitz   13045:                             $checked = ' checked="checked"';
1.663     raeburn  13046:                         }
                   13047:                     }
1.919     raeburn  13048:                     my $parent_title = $parent;
                   13049:                     if ($parent eq 'communities') {
                   13050:                         $parent_title = &mt('Communities');
                   13051:                     }
                   13052:                     $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
                   13053:                               '<input type="checkbox" name="usecategory" value="'.
                   13054:                               $item.'"'.$checked.' />'.$parent_title.'</span>'.
                   13055:                               '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663     raeburn  13056:                     my $depth = 1;
                   13057:                     push(@path,$parent);
1.919     raeburn  13058:                     $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663     raeburn  13059:                     pop(@path);
1.919     raeburn  13060:                     $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663     raeburn  13061:                     $itemcount ++;
                   13062:                 }
1.919     raeburn  13063:                 if ($itemcount) {
                   13064:                     $output = &Apache::loncommon::start_data_table().
                   13065:                               $table.
                   13066:                               &Apache::loncommon::end_data_table();
                   13067:                 }
1.663     raeburn  13068:             }
                   13069:         }
                   13070:     }
                   13071:     return $output;
                   13072: }
                   13073: 
                   13074: =pod
                   13075: 
                   13076: =item *&assign_category_rows()
                   13077: 
                   13078: Create a datatable row for display of nested categories in a domain,
                   13079: with checkboxes to allow a course to be categorized,called recursively.
                   13080: 
                   13081: Inputs:
                   13082: 
                   13083: itemcount - track row number for alternating colors
                   13084: 
                   13085: cats - reference to array of arrays/hashes which encapsulates hierarchy of
                   13086:       categories and subcategories.
                   13087: 
                   13088: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
                   13089: 
                   13090: parent - parent of current category item
                   13091: 
                   13092: path - Array containing all categories back up through the hierarchy from the
                   13093:        current category to the top level.
                   13094: 
                   13095: currcategories - reference to array of current categories assigned to the course
                   13096: 
                   13097: Returns: $output (markup to be displayed).
                   13098: 
                   13099: =cut
                   13100: 
                   13101: sub assign_category_rows {
                   13102:     my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
                   13103:     my ($text,$name,$item,$chgstr);
                   13104:     if (ref($cats) eq 'ARRAY') {
                   13105:         my $maxdepth = scalar(@{$cats});
                   13106:         if (ref($cats->[$depth]) eq 'HASH') {
                   13107:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   13108:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   13109:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   13110:                 $text .= '<td><table class="LC_datatable">';
                   13111:                 for (my $j=0; $j<$numchildren; $j++) {
                   13112:                     $name = $cats->[$depth]{$parent}[$j];
                   13113:                     $item = &escape($name).':'.&escape($parent).':'.$depth;
                   13114:                     my $deeper = $depth+1;
                   13115:                     my $checked = '';
                   13116:                     if (ref($currcategories) eq 'ARRAY') {
                   13117:                         if (@{$currcategories} > 0) {
                   13118:                             if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772     bisitz   13119:                                 $checked = ' checked="checked"';
1.663     raeburn  13120:                             }
                   13121:                         }
                   13122:                     }
1.664     raeburn  13123:                     $text .= '<tr><td><span class="LC_nobreak"><label>'.
                   13124:                              '<input type="checkbox" name="usecategory" value="'.
1.675     raeburn  13125:                              $item.'"'.$checked.' />'.$name.'</label></span>'.
                   13126:                              '<input type="hidden" name="catname" value="'.$name.'" />'.
                   13127:                              '</td><td>';
1.663     raeburn  13128:                     if (ref($path) eq 'ARRAY') {
                   13129:                         push(@{$path},$name);
                   13130:                         $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
                   13131:                         pop(@{$path});
                   13132:                     }
                   13133:                     $text .= '</td></tr>';
                   13134:                 }
                   13135:                 $text .= '</table></td>';
                   13136:             }
                   13137:         }
                   13138:     }
                   13139:     return $text;
                   13140: }
                   13141: 
1.655     raeburn  13142: ############################################################
                   13143: ############################################################
                   13144: 
                   13145: 
1.443     albertel 13146: sub commit_customrole {
1.664     raeburn  13147:     my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630     raeburn  13148:     my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443     albertel 13149:                          ($start?', '.&mt('starting').' '.localtime($start):'').
                   13150:                          ($end?', ending '.localtime($end):'').': <b>'.
                   13151:               &Apache::lonnet::assigncustomrole(
1.664     raeburn  13152:                  $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443     albertel 13153:                  '</b><br />';
                   13154:     return $output;
                   13155: }
                   13156: 
                   13157: sub commit_standardrole {
1.541     raeburn  13158:     my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
                   13159:     my ($output,$logmsg,$linefeed);
                   13160:     if ($context eq 'auto') {
                   13161:         $linefeed = "\n";
                   13162:     } else {
                   13163:         $linefeed = "<br />\n";
                   13164:     }  
1.443     albertel 13165:     if ($three eq 'st') {
1.541     raeburn  13166:         my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
                   13167:                                          $one,$two,$sec,$context);
                   13168:         if (($result =~ /^error/) || ($result eq 'not_in_class') || 
1.626     raeburn  13169:             ($result eq 'unknown_course') || ($result eq 'refused')) {
                   13170:             $output = $logmsg.' '.&mt('Error: ').$result."\n"; 
1.443     albertel 13171:         } else {
1.541     raeburn  13172:             $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443     albertel 13173:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  13174:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
                   13175:             if ($context eq 'auto') {
                   13176:                 $output .= $result.$linefeed.&mt('Add to classlist').': ok';
                   13177:             } else {
                   13178:                $output .= '<b>'.$result.'</b>'.$linefeed.
                   13179:                &mt('Add to classlist').': <b>ok</b>';
                   13180:             }
                   13181:             $output .= $linefeed;
1.443     albertel 13182:         }
                   13183:     } else {
                   13184:         $output = &mt('Assigning').' '.$three.' in '.$url.
                   13185:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  13186:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652     raeburn  13187:         my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541     raeburn  13188:         if ($context eq 'auto') {
                   13189:             $output .= $result.$linefeed;
                   13190:         } else {
                   13191:             $output .= '<b>'.$result.'</b>'.$linefeed;
                   13192:         }
1.443     albertel 13193:     }
                   13194:     return $output;
                   13195: }
                   13196: 
                   13197: sub commit_studentrole {
1.541     raeburn  13198:     my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626     raeburn  13199:     my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541     raeburn  13200:     if ($context eq 'auto') {
                   13201:         $linefeed = "\n";
                   13202:     } else {
                   13203:         $linefeed = '<br />'."\n";
                   13204:     }
1.443     albertel 13205:     if (defined($one) && defined($two)) {
                   13206:         my $cid=$one.'_'.$two;
                   13207:         my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
                   13208:         my $secchange = 0;
                   13209:         my $expire_role_result;
                   13210:         my $modify_section_result;
1.628     raeburn  13211:         if ($oldsec ne '-1') { 
                   13212:             if ($oldsec ne $sec) {
1.443     albertel 13213:                 $secchange = 1;
1.628     raeburn  13214:                 my $now = time;
1.443     albertel 13215:                 my $uurl='/'.$cid;
                   13216:                 $uurl=~s/\_/\//g;
                   13217:                 if ($oldsec) {
                   13218:                     $uurl.='/'.$oldsec;
                   13219:                 }
1.626     raeburn  13220:                 $oldsecurl = $uurl;
1.628     raeburn  13221:                 $expire_role_result = 
1.652     raeburn  13222:                     &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628     raeburn  13223:                 if ($env{'request.course.sec'} ne '') { 
                   13224:                     if ($expire_role_result eq 'refused') {
                   13225:                         my @roles = ('st');
                   13226:                         my @statuses = ('previous');
                   13227:                         my @roledoms = ($one);
                   13228:                         my $withsec = 1;
                   13229:                         my %roleshash = 
                   13230:                             &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
                   13231:                                               \@statuses,\@roles,\@roledoms,$withsec);
                   13232:                         if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
                   13233:                             my ($oldstart,$oldend) = 
                   13234:                                 split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
                   13235:                             if ($oldend > 0 && $oldend <= $now) {
                   13236:                                 $expire_role_result = 'ok';
                   13237:                             }
                   13238:                         }
                   13239:                     }
                   13240:                 }
1.443     albertel 13241:                 $result = $expire_role_result;
                   13242:             }
                   13243:         }
                   13244:         if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652     raeburn  13245:             $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443     albertel 13246:             if ($modify_section_result =~ /^ok/) {
                   13247:                 if ($secchange == 1) {
1.628     raeburn  13248:                     if ($sec eq '') {
                   13249:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
                   13250:                     } else {
                   13251:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
                   13252:                     }
1.443     albertel 13253:                 } elsif ($oldsec eq '-1') {
1.628     raeburn  13254:                     if ($sec eq '') {
                   13255:                         $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
                   13256:                     } else {
                   13257:                         $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   13258:                     }
1.443     albertel 13259:                 } else {
1.628     raeburn  13260:                     if ($sec eq '') {
                   13261:                         $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
                   13262:                     } else {
                   13263:                         $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   13264:                     }
1.443     albertel 13265:                 }
                   13266:             } else {
1.628     raeburn  13267:                 if ($secchange) {       
                   13268:                     $$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;
                   13269:                 } else {
                   13270:                     $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
                   13271:                 }
1.443     albertel 13272:             }
                   13273:             $result = $modify_section_result;
                   13274:         } elsif ($secchange == 1) {
1.628     raeburn  13275:             if ($oldsec eq '') {
1.1075.2.20  raeburn  13276:                 $$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  13277:             } else {
                   13278:                 $$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;
                   13279:             }
1.626     raeburn  13280:             if ($expire_role_result eq 'refused') {
                   13281:                 my $newsecurl = '/'.$cid;
                   13282:                 $newsecurl =~ s/\_/\//g;
                   13283:                 if ($sec ne '') {
                   13284:                     $newsecurl.='/'.$sec;
                   13285:                 }
                   13286:                 if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
                   13287:                     if ($sec eq '') {
                   13288:                         $$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;
                   13289:                     } else {
                   13290:                         $$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;
                   13291:                     }
                   13292:                 }
                   13293:             }
1.443     albertel 13294:         }
                   13295:     } else {
1.626     raeburn  13296:         $$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 13297:         $result = "error: incomplete course id\n";
                   13298:     }
                   13299:     return $result;
                   13300: }
                   13301: 
1.1075.2.25  raeburn  13302: sub show_role_extent {
                   13303:     my ($scope,$context,$role) = @_;
                   13304:     $scope =~ s{^/}{};
                   13305:     my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
                   13306:     push(@courseroles,'co');
                   13307:     my @authorroles = &Apache::lonuserutils::roles_by_context('author');
                   13308:     if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
                   13309:         $scope =~ s{/}{_};
                   13310:         return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
                   13311:     } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
                   13312:         my ($audom,$auname) = split(/\//,$scope);
                   13313:         return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
                   13314:                    &Apache::loncommon::plainname($auname,$audom).'</span>');
                   13315:     } else {
                   13316:         $scope =~ s{/$}{};
                   13317:         return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
                   13318:                    &Apache::lonnet::domain($scope,'description').'</span>');
                   13319:     }
                   13320: }
                   13321: 
1.443     albertel 13322: ############################################################
                   13323: ############################################################
                   13324: 
1.566     albertel 13325: sub check_clone {
1.578     raeburn  13326:     my ($args,$linefeed) = @_;
1.566     albertel 13327:     my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
                   13328:     my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
                   13329:     my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
                   13330:     my $clonemsg;
                   13331:     my $can_clone = 0;
1.944     raeburn  13332:     my $lctype = lc($args->{'crstype'});
1.908     raeburn  13333:     if ($lctype ne 'community') {
                   13334:         $lctype = 'course';
                   13335:     }
1.566     albertel 13336:     if ($clonehome eq 'no_host') {
1.944     raeburn  13337:         if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  13338:             $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'});
                   13339:         } else {
                   13340:             $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'});
                   13341:         }     
1.566     albertel 13342:     } else {
                   13343: 	my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944     raeburn  13344:         if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  13345:             if ($clonedesc{'type'} ne 'Community') {
                   13346:                  $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'});
                   13347:                 return ($can_clone, $clonemsg, $cloneid, $clonehome);
                   13348:             }
                   13349:         }
1.882     raeburn  13350: 	if (($env{'request.role.domain'} eq $args->{'clonedomain'}) && 
                   13351:             (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566     albertel 13352: 	    $can_clone = 1;
                   13353: 	} else {
                   13354: 	    my %clonehash = &Apache::lonnet::get('environment',['cloners'],
                   13355: 						 $args->{'clonedomain'},$args->{'clonecourse'});
                   13356: 	    my @cloners = split(/,/,$clonehash{'cloners'});
1.578     raeburn  13357:             if (grep(/^\*$/,@cloners)) {
                   13358:                 $can_clone = 1;
                   13359:             } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
                   13360:                 $can_clone = 1;
                   13361:             } else {
1.908     raeburn  13362:                 my $ccrole = 'cc';
1.944     raeburn  13363:                 if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  13364:                     $ccrole = 'co';
                   13365:                 }
1.578     raeburn  13366: 	        my %roleshash =
                   13367: 		    &Apache::lonnet::get_my_roles($args->{'ccuname'},
                   13368: 					 $args->{'ccdomain'},
1.908     raeburn  13369:                                          'userroles',['active'],[$ccrole],
1.578     raeburn  13370: 					 [$args->{'clonedomain'}]);
1.908     raeburn  13371: 	        if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942     raeburn  13372:                     $can_clone = 1;
                   13373:                 } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
                   13374:                     $can_clone = 1;
                   13375:                 } else {
1.944     raeburn  13376:                     if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  13377:                         $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'});
                   13378:                     } else {
                   13379:                         $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'});
                   13380:                     }
1.578     raeburn  13381: 	        }
1.566     albertel 13382: 	    }
1.578     raeburn  13383:         }
1.566     albertel 13384:     }
                   13385:     return ($can_clone, $clonemsg, $cloneid, $clonehome);
                   13386: }
                   13387: 
1.444     albertel 13388: sub construct_course {
1.885     raeburn  13389:     my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444     albertel 13390:     my $outcome;
1.541     raeburn  13391:     my $linefeed =  '<br />'."\n";
                   13392:     if ($context eq 'auto') {
                   13393:         $linefeed = "\n";
                   13394:     }
1.566     albertel 13395: 
                   13396: #
                   13397: # Are we cloning?
                   13398: #
                   13399:     my ($can_clone, $clonemsg, $cloneid, $clonehome);
                   13400:     if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578     raeburn  13401: 	($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566     albertel 13402: 	if ($context ne 'auto') {
1.578     raeburn  13403:             if ($clonemsg ne '') {
                   13404: 	        $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
                   13405:             }
1.566     albertel 13406: 	}
                   13407: 	$outcome .= $clonemsg.$linefeed;
                   13408: 
                   13409:         if (!$can_clone) {
                   13410: 	    return (0,$outcome);
                   13411: 	}
                   13412:     }
                   13413: 
1.444     albertel 13414: #
                   13415: # Open course
                   13416: #
                   13417:     my $crstype = lc($args->{'crstype'});
                   13418:     my %cenv=();
                   13419:     $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
                   13420:                                              $args->{'cdescr'},
                   13421:                                              $args->{'curl'},
                   13422:                                              $args->{'course_home'},
                   13423:                                              $args->{'nonstandard'},
                   13424:                                              $args->{'crscode'},
                   13425:                                              $args->{'ccuname'}.':'.
                   13426:                                              $args->{'ccdomain'},
1.882     raeburn  13427:                                              $args->{'crstype'},
1.885     raeburn  13428:                                              $cnum,$context,$category);
1.444     albertel 13429: 
                   13430:     # Note: The testing routines depend on this being output; see 
                   13431:     # Utils::Course. This needs to at least be output as a comment
                   13432:     # if anyone ever decides to not show this, and Utils::Course::new
                   13433:     # will need to be suitably modified.
1.541     raeburn  13434:     $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943     raeburn  13435:     if ($$courseid =~ /^error:/) {
                   13436:         return (0,$outcome);
                   13437:     }
                   13438: 
1.444     albertel 13439: #
                   13440: # Check if created correctly
                   13441: #
1.479     albertel 13442:     ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444     albertel 13443:     my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943     raeburn  13444:     if ($crsuhome eq 'no_host') {
                   13445:         $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
                   13446:         return (0,$outcome);
                   13447:     }
1.541     raeburn  13448:     $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566     albertel 13449: 
1.444     albertel 13450: #
1.566     albertel 13451: # Do the cloning
                   13452: #   
                   13453:     if ($can_clone && $cloneid) {
                   13454: 	$clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
                   13455: 	if ($context ne 'auto') {
                   13456: 	    $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
                   13457: 	}
                   13458: 	$outcome .= $clonemsg.$linefeed;
                   13459: 	my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444     albertel 13460: # Copy all files
1.637     www      13461: 	&Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444     albertel 13462: # Restore URL
1.566     albertel 13463: 	$cenv{'url'}=$oldcenv{'url'};
1.444     albertel 13464: # Restore title
1.566     albertel 13465: 	$cenv{'description'}=$oldcenv{'description'};
1.955     raeburn  13466: # Restore creation date, creator and creation context.
                   13467:         $cenv{'internal.created'}=$oldcenv{'internal.created'};
                   13468:         $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
                   13469:         $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444     albertel 13470: # Mark as cloned
1.566     albertel 13471: 	$cenv{'clonedfrom'}=$cloneid;
1.638     www      13472: # Need to clone grading mode
                   13473:         my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
                   13474:         $cenv{'grading'}=$newenv{'grading'};
                   13475: # Do not clone these environment entries
                   13476:         &Apache::lonnet::del('environment',
                   13477:                   ['default_enrollment_start_date',
                   13478:                    'default_enrollment_end_date',
                   13479:                    'question.email',
                   13480:                    'policy.email',
                   13481:                    'comment.email',
                   13482:                    'pch.users.denied',
1.725     raeburn  13483:                    'plc.users.denied',
                   13484:                    'hidefromcat',
                   13485:                    'categories'],
1.638     www      13486:                    $$crsudom,$$crsunum);
1.444     albertel 13487:     }
1.566     albertel 13488: 
1.444     albertel 13489: #
                   13490: # Set environment (will override cloned, if existing)
                   13491: #
                   13492:     my @sections = ();
                   13493:     my @xlists = ();
                   13494:     if ($args->{'crstype'}) {
                   13495:         $cenv{'type'}=$args->{'crstype'};
                   13496:     }
                   13497:     if ($args->{'crsid'}) {
                   13498:         $cenv{'courseid'}=$args->{'crsid'};
                   13499:     }
                   13500:     if ($args->{'crscode'}) {
                   13501:         $cenv{'internal.coursecode'}=$args->{'crscode'};
                   13502:     }
                   13503:     if ($args->{'crsquota'} ne '') {
                   13504:         $cenv{'internal.coursequota'}=$args->{'crsquota'};
                   13505:     } else {
                   13506:         $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
                   13507:     }
                   13508:     if ($args->{'ccuname'}) {
                   13509:         $cenv{'internal.courseowner'} = $args->{'ccuname'}.
                   13510:                                         ':'.$args->{'ccdomain'};
                   13511:     } else {
                   13512:         $cenv{'internal.courseowner'} = $args->{'curruser'};
                   13513:     }
                   13514:     my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
                   13515:     if ($args->{'crssections'}) {
                   13516:         $cenv{'internal.sectionnums'} = '';
                   13517:         if ($args->{'crssections'} =~ m/,/) {
                   13518:             @sections = split/,/,$args->{'crssections'};
                   13519:         } else {
                   13520:             $sections[0] = $args->{'crssections'};
                   13521:         }
                   13522:         if (@sections > 0) {
                   13523:             foreach my $item (@sections) {
                   13524:                 my ($sec,$gp) = split/:/,$item;
                   13525:                 my $class = $args->{'crscode'}.$sec;
                   13526:                 my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
                   13527:                 $cenv{'internal.sectionnums'} .= $item.',';
                   13528:                 unless ($addcheck eq 'ok') {
                   13529:                     push @badclasses, $class;
                   13530:                 }
                   13531:             }
                   13532:             $cenv{'internal.sectionnums'} =~ s/,$//;
                   13533:         }
                   13534:     }
                   13535: # do not hide course coordinator from staff listing, 
                   13536: # even if privileged
                   13537:     $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   13538: # add crosslistings
                   13539:     if ($args->{'crsxlist'}) {
                   13540:         $cenv{'internal.crosslistings'}='';
                   13541:         if ($args->{'crsxlist'} =~ m/,/) {
                   13542:             @xlists = split/,/,$args->{'crsxlist'};
                   13543:         } else {
                   13544:             $xlists[0] = $args->{'crsxlist'};
                   13545:         }
                   13546:         if (@xlists > 0) {
                   13547:             foreach my $item (@xlists) {
                   13548:                 my ($xl,$gp) = split/:/,$item;
                   13549:                 my $addcheck =  &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
                   13550:                 $cenv{'internal.crosslistings'} .= $item.',';
                   13551:                 unless ($addcheck eq 'ok') {
                   13552:                     push @badclasses, $xl;
                   13553:                 }
                   13554:             }
                   13555:             $cenv{'internal.crosslistings'} =~ s/,$//;
                   13556:         }
                   13557:     }
                   13558:     if ($args->{'autoadds'}) {
                   13559:         $cenv{'internal.autoadds'}=$args->{'autoadds'};
                   13560:     }
                   13561:     if ($args->{'autodrops'}) {
                   13562:         $cenv{'internal.autodrops'}=$args->{'autodrops'};
                   13563:     }
                   13564: # check for notification of enrollment changes
                   13565:     my @notified = ();
                   13566:     if ($args->{'notify_owner'}) {
                   13567:         if ($args->{'ccuname'} ne '') {
                   13568:             push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
                   13569:         }
                   13570:     }
                   13571:     if ($args->{'notify_dc'}) {
                   13572:         if ($uname ne '') { 
1.630     raeburn  13573:             push(@notified,$uname.':'.$udom);
1.444     albertel 13574:         }
                   13575:     }
                   13576:     if (@notified > 0) {
                   13577:         my $notifylist;
                   13578:         if (@notified > 1) {
                   13579:             $notifylist = join(',',@notified);
                   13580:         } else {
                   13581:             $notifylist = $notified[0];
                   13582:         }
                   13583:         $cenv{'internal.notifylist'} = $notifylist;
                   13584:     }
                   13585:     if (@badclasses > 0) {
                   13586:         my %lt=&Apache::lonlocal::texthash(
                   13587:                 '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',
                   13588:                 'dnhr' => 'does not have rights to access enrollment in these classes',
                   13589:                 'adby' => 'as determined by the policies of your institution on access to official classlists'
                   13590:         );
1.541     raeburn  13591:         my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
                   13592:                            ' ('.$lt{'adby'}.')';
                   13593:         if ($context eq 'auto') {
                   13594:             $outcome .= $badclass_msg.$linefeed;
1.566     albertel 13595:             $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541     raeburn  13596:             foreach my $item (@badclasses) {
                   13597:                 if ($context eq 'auto') {
                   13598:                     $outcome .= " - $item\n";
                   13599:                 } else {
                   13600:                     $outcome .= "<li>$item</li>\n";
                   13601:                 }
                   13602:             }
                   13603:             if ($context eq 'auto') {
                   13604:                 $outcome .= $linefeed;
                   13605:             } else {
1.566     albertel 13606:                 $outcome .= "</ul><br /><br /></div>\n";
1.541     raeburn  13607:             }
                   13608:         } 
1.444     albertel 13609:     }
                   13610:     if ($args->{'no_end_date'}) {
                   13611:         $args->{'endaccess'} = 0;
                   13612:     }
                   13613:     $cenv{'internal.autostart'}=$args->{'enrollstart'};
                   13614:     $cenv{'internal.autoend'}=$args->{'enrollend'};
                   13615:     $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
                   13616:     $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
                   13617:     if ($args->{'showphotos'}) {
                   13618:       $cenv{'internal.showphotos'}=$args->{'showphotos'};
                   13619:     }
                   13620:     $cenv{'internal.authtype'} = $args->{'authtype'};
                   13621:     $cenv{'internal.autharg'} = $args->{'autharg'}; 
                   13622:     if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
                   13623:         if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'}  eq '') {
1.541     raeburn  13624:             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'); 
                   13625:             if ($context eq 'auto') {
                   13626:                 $outcome .= $krb_msg;
                   13627:             } else {
1.566     albertel 13628:                 $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541     raeburn  13629:             }
                   13630:             $outcome .= $linefeed;
1.444     albertel 13631:         }
                   13632:     }
                   13633:     if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
                   13634:        if ($args->{'setpolicy'}) {
                   13635:            $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   13636:        }
                   13637:        if ($args->{'setcontent'}) {
                   13638:            $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   13639:        }
                   13640:     }
                   13641:     if ($args->{'reshome'}) {
                   13642: 	$cenv{'reshome'}=$args->{'reshome'}.'/';
                   13643: 	$cenv{'reshome'}=~s/\/+$/\//;
                   13644:     }
                   13645: #
                   13646: # course has keyed access
                   13647: #
                   13648:     if ($args->{'setkeys'}) {
                   13649:        $cenv{'keyaccess'}='yes';
                   13650:     }
                   13651: # if specified, key authority is not course, but user
                   13652: # only active if keyaccess is yes
                   13653:     if ($args->{'keyauth'}) {
1.487     albertel 13654: 	my ($user,$domain) = split(':',$args->{'keyauth'});
                   13655: 	$user = &LONCAPA::clean_username($user);
                   13656: 	$domain = &LONCAPA::clean_username($domain);
1.488     foxr     13657: 	if ($user ne '' && $domain ne '') {
1.487     albertel 13658: 	    $cenv{'keyauth'}=$user.':'.$domain;
1.444     albertel 13659: 	}
                   13660:     }
                   13661: 
                   13662:     if ($args->{'disresdis'}) {
                   13663:         $cenv{'pch.roles.denied'}='st';
                   13664:     }
                   13665:     if ($args->{'disablechat'}) {
                   13666:         $cenv{'plc.roles.denied'}='st';
                   13667:     }
                   13668: 
                   13669:     # Record we've not yet viewed the Course Initialization Helper for this 
                   13670:     # course
                   13671:     $cenv{'course.helper.not.run'} = 1;
                   13672:     #
                   13673:     # Use new Randomseed
                   13674:     #
                   13675:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
                   13676:     $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
                   13677:     #
                   13678:     # The encryption code and receipt prefix for this course
                   13679:     #
                   13680:     $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
                   13681:     $cenv{'internal.encpref'}=100+int(9*rand(99));
                   13682:     #
                   13683:     # By default, use standard grading
                   13684:     if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
                   13685: 
1.541     raeburn  13686:     $outcome .= $linefeed.&mt('Setting environment').': '.                 
                   13687:           &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 13688: #
                   13689: # Open all assignments
                   13690: #
                   13691:     if ($args->{'openall'}) {
                   13692:        my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
                   13693:        my %storecontent = ($storeunder         => time,
                   13694:                            $storeunder.'.type' => 'date_start');
                   13695:        
                   13696:        $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541     raeburn  13697:                  ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 13698:    }
                   13699: #
                   13700: # Set first page
                   13701: #
                   13702:     unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
                   13703: 	    || ($cloneid)) {
1.445     albertel 13704: 	use LONCAPA::map;
1.444     albertel 13705: 	$outcome .= &mt('Setting first resource').': ';
1.445     albertel 13706: 
                   13707: 	my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
                   13708:         my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
                   13709: 
1.444     albertel 13710:         $outcome .= ($fatal?$errtext:'read ok').' - ';
                   13711:         my $title; my $url;
                   13712:         if ($args->{'firstres'} eq 'syl') {
1.690     bisitz   13713: 	    $title=&mt('Syllabus');
1.444     albertel 13714:             $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
                   13715:         } else {
1.963     raeburn  13716:             $title=&mt('Table of Contents');
1.444     albertel 13717:             $url='/adm/navmaps';
                   13718:         }
1.445     albertel 13719: 
                   13720:         $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
                   13721: 	(my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
                   13722: 
                   13723: 	if ($errtext) { $fatal=2; }
1.541     raeburn  13724:         $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444     albertel 13725:     }
1.566     albertel 13726: 
                   13727:     return (1,$outcome);
1.444     albertel 13728: }
                   13729: 
                   13730: ############################################################
                   13731: ############################################################
                   13732: 
1.953     droeschl 13733: #SD
                   13734: # only Community and Course, or anything else?
1.378     raeburn  13735: sub course_type {
                   13736:     my ($cid) = @_;
                   13737:     if (!defined($cid)) {
                   13738:         $cid = $env{'request.course.id'};
                   13739:     }
1.404     albertel 13740:     if (defined($env{'course.'.$cid.'.type'})) {
                   13741:         return $env{'course.'.$cid.'.type'};
1.378     raeburn  13742:     } else {
                   13743:         return 'Course';
1.377     raeburn  13744:     }
                   13745: }
1.156     albertel 13746: 
1.406     raeburn  13747: sub group_term {
                   13748:     my $crstype = &course_type();
                   13749:     my %names = (
                   13750:                   'Course' => 'group',
1.865     raeburn  13751:                   'Community' => 'group',
1.406     raeburn  13752:                 );
                   13753:     return $names{$crstype};
                   13754: }
                   13755: 
1.902     raeburn  13756: sub course_types {
                   13757:     my @types = ('official','unofficial','community');
                   13758:     my %typename = (
                   13759:                          official   => 'Official course',
                   13760:                          unofficial => 'Unofficial course',
                   13761:                          community  => 'Community',
                   13762:                    );
                   13763:     return (\@types,\%typename);
                   13764: }
                   13765: 
1.156     albertel 13766: sub icon {
                   13767:     my ($file)=@_;
1.505     albertel 13768:     my $curfext = lc((split(/\./,$file))[-1]);
1.168     albertel 13769:     my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156     albertel 13770:     my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168     albertel 13771:     if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
                   13772: 	if (-e  $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
                   13773: 	          $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   13774: 	            $curfext.".gif") {
                   13775: 	    $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   13776: 		$curfext.".gif";
                   13777: 	}
                   13778:     }
1.249     albertel 13779:     return &lonhttpdurl($iconname);
1.154     albertel 13780: } 
1.84      albertel 13781: 
1.575     albertel 13782: sub lonhttpdurl {
1.692     www      13783: #
                   13784: # Had been used for "small fry" static images on separate port 8080.
                   13785: # Modify here if lightweight http functionality desired again.
                   13786: # Currently eliminated due to increasing firewall issues.
                   13787: #
1.575     albertel 13788:     my ($url)=@_;
1.692     www      13789:     return $url;
1.215     albertel 13790: }
                   13791: 
1.213     albertel 13792: sub connection_aborted {
                   13793:     my ($r)=@_;
                   13794:     $r->print(" ");$r->rflush();
                   13795:     my $c = $r->connection;
                   13796:     return $c->aborted();
                   13797: }
                   13798: 
1.221     foxr     13799: #    Escapes strings that may have embedded 's that will be put into
1.222     foxr     13800: #    strings as 'strings'.
                   13801: sub escape_single {
1.221     foxr     13802:     my ($input) = @_;
1.223     albertel 13803:     $input =~ s/\\/\\\\/g;	# Escape the \'s..(must be first)>
1.221     foxr     13804:     $input =~ s/\'/\\\'/g;	# Esacpe the 's....
                   13805:     return $input;
                   13806: }
1.223     albertel 13807: 
1.222     foxr     13808: #  Same as escape_single, but escape's "'s  This 
                   13809: #  can be used for  "strings"
                   13810: sub escape_double {
                   13811:     my ($input) = @_;
                   13812:     $input =~ s/\\/\\\\/g;	# Escape the /'s..(must be first)>
                   13813:     $input =~ s/\"/\\\"/g;	# Esacpe the "s....
                   13814:     return $input;
                   13815: }
1.223     albertel 13816:  
1.222     foxr     13817: #   Escapes the last element of a full URL.
                   13818: sub escape_url {
                   13819:     my ($url)   = @_;
1.238     raeburn  13820:     my @urlslices = split(/\//, $url,-1);
1.369     www      13821:     my $lastitem = &escape(pop(@urlslices));
1.223     albertel 13822:     return join('/',@urlslices).'/'.$lastitem;
1.222     foxr     13823: }
1.462     albertel 13824: 
1.820     raeburn  13825: sub compare_arrays {
                   13826:     my ($arrayref1,$arrayref2) = @_;
                   13827:     my (@difference,%count);
                   13828:     @difference = ();
                   13829:     %count = ();
                   13830:     if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
                   13831:         foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
                   13832:         foreach my $element (keys(%count)) {
                   13833:             if ($count{$element} == 1) {
                   13834:                 push(@difference,$element);
                   13835:             }
                   13836:         }
                   13837:     }
                   13838:     return @difference;
                   13839: }
                   13840: 
1.817     bisitz   13841: # -------------------------------------------------------- Initialize user login
1.462     albertel 13842: sub init_user_environment {
1.463     albertel 13843:     my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462     albertel 13844:     my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
                   13845: 
                   13846:     my $public=($username eq 'public' && $domain eq 'public');
                   13847: 
                   13848: # See if old ID present, if so, remove
                   13849: 
1.1062    raeburn  13850:     my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462     albertel 13851:     my $now=time;
                   13852: 
                   13853:     if ($public) {
                   13854: 	my $max_public=100;
                   13855: 	my $oldest;
                   13856: 	my $oldest_time=0;
                   13857: 	for(my $next=1;$next<=$max_public;$next++) {
                   13858: 	    if (-e $lonids."/publicuser_$next.id") {
                   13859: 		my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
                   13860: 		if ($mtime<$oldest_time || !$oldest_time) {
                   13861: 		    $oldest_time=$mtime;
                   13862: 		    $oldest=$next;
                   13863: 		}
                   13864: 	    } else {
                   13865: 		$cookie="publicuser_$next";
                   13866: 		last;
                   13867: 	    }
                   13868: 	}
                   13869: 	if (!$cookie) { $cookie="publicuser_$oldest"; }
                   13870:     } else {
1.463     albertel 13871: 	# if this isn't a robot, kill any existing non-robot sessions
                   13872: 	if (!$args->{'robot'}) {
                   13873: 	    opendir(DIR,$lonids);
                   13874: 	    while ($filename=readdir(DIR)) {
                   13875: 		if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
                   13876: 		    unlink($lonids.'/'.$filename);
                   13877: 		}
1.462     albertel 13878: 	    }
1.463     albertel 13879: 	    closedir(DIR);
1.462     albertel 13880: 	}
                   13881: # Give them a new cookie
1.463     albertel 13882: 	my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684     www      13883: 		                   : $now.$$.int(rand(10000)));
1.463     albertel 13884: 	$cookie="$username\_$id\_$domain\_$authhost";
1.462     albertel 13885:     
                   13886: # Initialize roles
                   13887: 
1.1062    raeburn  13888: 	($userroles,$firstaccenv,$timerintenv) = 
                   13889:             &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462     albertel 13890:     }
                   13891: # ------------------------------------ Check browser type and MathML capability
                   13892: 
                   13893:     my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   13894:         $clientunicode,$clientos) = &decode_user_agent($r);
                   13895: 
                   13896: # ------------------------------------------------------------- Get environment
                   13897: 
                   13898:     my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
                   13899:     my ($tmp) = keys(%userenv);
                   13900:     if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   13901:     } else {
                   13902: 	undef(%userenv);
                   13903:     }
                   13904:     if (($userenv{'interface'}) && (!$form->{'interface'})) {
                   13905: 	$form->{'interface'}=$userenv{'interface'};
                   13906:     }
                   13907:     if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
                   13908: 
                   13909: # --------------- Do not trust query string to be put directly into environment
1.817     bisitz   13910:     foreach my $option ('interface','localpath','localres') {
                   13911:         $form->{$option}=~s/[\n\r\=]//gs;
1.462     albertel 13912:     }
                   13913: # --------------------------------------------------------- Write first profile
                   13914: 
                   13915:     {
                   13916: 	my %initial_env = 
                   13917: 	    ("user.name"          => $username,
                   13918: 	     "user.domain"        => $domain,
                   13919: 	     "user.home"          => $authhost,
                   13920: 	     "browser.type"       => $clientbrowser,
                   13921: 	     "browser.version"    => $clientversion,
                   13922: 	     "browser.mathml"     => $clientmathml,
                   13923: 	     "browser.unicode"    => $clientunicode,
                   13924: 	     "browser.os"         => $clientos,
                   13925: 	     "server.domain"      => $Apache::lonnet::perlvar{'lonDefDomain'},
                   13926: 	     "request.course.fn"  => '',
                   13927: 	     "request.course.uri" => '',
                   13928: 	     "request.course.sec" => '',
                   13929: 	     "request.role"       => 'cm',
                   13930: 	     "request.role.adv"   => $env{'user.adv'},
                   13931: 	     "request.host"       => $ENV{'REMOTE_ADDR'},);
                   13932: 
                   13933:         if ($form->{'localpath'}) {
                   13934: 	    $initial_env{"browser.localpath"}  = $form->{'localpath'};
                   13935: 	    $initial_env{"browser.localres"}   = $form->{'localres'};
                   13936:         }
                   13937: 	
                   13938: 	if ($form->{'interface'}) {
                   13939: 	    $form->{'interface'}=~s/\W//gs;
                   13940: 	    $initial_env{"browser.interface"} = $form->{'interface'};
                   13941: 	    $env{'browser.interface'}=$form->{'interface'};
                   13942: 	}
                   13943: 
1.981     raeburn  13944:         my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016    raeburn  13945:         my %domdef;
                   13946:         unless ($domain eq 'public') {
                   13947:             %domdef = &Apache::lonnet::get_domain_defaults($domain);
                   13948:         }
1.980     raeburn  13949: 
1.1075.2.7  raeburn  13950:         foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724     raeburn  13951:             $userenv{'availabletools.'.$tool} = 
1.980     raeburn  13952:                 &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
                   13953:                                                   undef,\%userenv,\%domdef,\%is_adv);
1.724     raeburn  13954:         }
                   13955: 
1.864     raeburn  13956:         foreach my $crstype ('official','unofficial','community') {
1.765     raeburn  13957:             $userenv{'canrequest.'.$crstype} =
                   13958:                 &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980     raeburn  13959:                                                   'reload','requestcourses',
                   13960:                                                   \%userenv,\%domdef,\%is_adv);
1.765     raeburn  13961:         }
                   13962: 
1.1075.2.14  raeburn  13963:         $userenv{'canrequest.author'} =
                   13964:             &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
                   13965:                                         'reload','requestauthor',
                   13966:                                         \%userenv,\%domdef,\%is_adv);
                   13967:         my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
                   13968:                                              $domain,$username);
                   13969:         my $reqstatus = $reqauthor{'author_status'};
                   13970:         if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
                   13971:             if (ref($reqauthor{'author'}) eq 'HASH') {
                   13972:                 $userenv{'requestauthorqueued'} = $reqstatus.':'.
                   13973:                                                   $reqauthor{'author'}{'timestamp'};
                   13974:             }
                   13975:         }
                   13976: 
1.462     albertel 13977: 	$env{'user.environment'} = "$lonids/$cookie.id";
1.1062    raeburn  13978: 
1.462     albertel 13979: 	if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
                   13980: 		 &GDBM_WRCREAT(),0640)) {
                   13981: 	    &_add_to_env(\%disk_env,\%initial_env);
                   13982: 	    &_add_to_env(\%disk_env,\%userenv,'environment.');
                   13983: 	    &_add_to_env(\%disk_env,$userroles);
1.1062    raeburn  13984:             if (ref($firstaccenv) eq 'HASH') {
                   13985:                 &_add_to_env(\%disk_env,$firstaccenv);
                   13986:             }
                   13987:             if (ref($timerintenv) eq 'HASH') {
                   13988:                 &_add_to_env(\%disk_env,$timerintenv);
                   13989:             }
1.463     albertel 13990: 	    if (ref($args->{'extra_env'})) {
                   13991: 		&_add_to_env(\%disk_env,$args->{'extra_env'});
                   13992: 	    }
1.462     albertel 13993: 	    untie(%disk_env);
                   13994: 	} else {
1.705     tempelho 13995: 	    &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
                   13996: 			   'Could not create environment storage in lonauth: '.$!.'</span>');
1.462     albertel 13997: 	    return 'error: '.$!;
                   13998: 	}
                   13999:     }
                   14000:     $env{'request.role'}='cm';
                   14001:     $env{'request.role.adv'}=$env{'user.adv'};
                   14002:     $env{'browser.type'}=$clientbrowser;
                   14003: 
                   14004:     return $cookie;
                   14005: 
                   14006: }
                   14007: 
                   14008: sub _add_to_env {
                   14009:     my ($idf,$env_data,$prefix) = @_;
1.676     raeburn  14010:     if (ref($env_data) eq 'HASH') {
                   14011:         while (my ($key,$value) = each(%$env_data)) {
                   14012: 	    $idf->{$prefix.$key} = $value;
                   14013: 	    $env{$prefix.$key}   = $value;
                   14014:         }
1.462     albertel 14015:     }
                   14016: }
                   14017: 
1.685     tempelho 14018: # --- Get the symbolic name of a problem and the url
                   14019: sub get_symb {
                   14020:     my ($request,$silent) = @_;
1.726     raeburn  14021:     (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685     tempelho 14022:     my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
                   14023:     if ($symb eq '') {
                   14024:         if (!$silent) {
1.1071    raeburn  14025:             if (ref($request)) { 
                   14026:                 $request->print("Unable to handle ambiguous references:$url:.");
                   14027:             }
1.685     tempelho 14028:             return ();
                   14029:         }
                   14030:     }
                   14031:     &Apache::lonenc::check_decrypt(\$symb);
                   14032:     return ($symb);
                   14033: }
                   14034: 
                   14035: # --------------------------------------------------------------Get annotation
                   14036: 
                   14037: sub get_annotation {
                   14038:     my ($symb,$enc) = @_;
                   14039: 
                   14040:     my $key = $symb;
                   14041:     if (!$enc) {
                   14042:         $key =
                   14043:             &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
                   14044:     }
                   14045:     my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
                   14046:     return $annotation{$key};
                   14047: }
                   14048: 
                   14049: sub clean_symb {
1.731     raeburn  14050:     my ($symb,$delete_enc) = @_;
1.685     tempelho 14051: 
                   14052:     &Apache::lonenc::check_decrypt(\$symb);
                   14053:     my $enc = $env{'request.enc'};
1.731     raeburn  14054:     if ($delete_enc) {
1.730     raeburn  14055:         delete($env{'request.enc'});
                   14056:     }
1.685     tempelho 14057: 
                   14058:     return ($symb,$enc);
                   14059: }
1.462     albertel 14060: 
1.990     raeburn  14061: sub build_release_hashes {
                   14062:     my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_;
                   14063:     return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') &&
                   14064:                   (ref($checkcrstypes) eq 'HASH') && (ref($anonsurvey) eq 'HASH') &&
                   14065:                   (ref($randomizetry) eq 'HASH'));
                   14066:     foreach my $key (keys(%Apache::lonnet::needsrelease)) {
                   14067:         my ($item,$name,$value) = split(/:/,$key);
                   14068:         if ($item eq 'parameter') {
                   14069:             if (ref($checkparms->{$name}) eq 'ARRAY') {
                   14070:                 unless(grep(/^\Q$name\E$/,@{$checkparms->{$name}})) {
                   14071:                     push(@{$checkparms->{$name}},$value);
                   14072:                 }
                   14073:             } else {
                   14074:                 push(@{$checkparms->{$name}},$value);
                   14075:             }
                   14076:         } elsif ($item eq 'resourcetag') {
                   14077:             if ($name eq 'responsetype') {
                   14078:                 $checkresponsetypes->{$value} = $Apache::lonnet::needsrelease{$key}
                   14079:             }
                   14080:         } elsif ($item eq 'course') {
                   14081:             if ($name eq 'crstype') {
                   14082:                 $checkcrstypes->{$value} = $Apache::lonnet::needsrelease{$key};
                   14083:             }
                   14084:         }
                   14085:     }
                   14086:     ($anonsurvey->{major},$anonsurvey->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
                   14087:     ($randomizetry->{major},$randomizetry->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
                   14088:     return;
                   14089: }
                   14090: 
1.1075.2.11  raeburn  14091: sub update_content_constraints {
                   14092:     my ($cdom,$cnum,$chome,$cid) = @_;
                   14093:     my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
                   14094:     my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
                   14095:     my %checkresponsetypes;
                   14096:     foreach my $key (keys(%Apache::lonnet::needsrelease)) {
                   14097:         my ($item,$name,$value) = split(/:/,$key);
                   14098:         if ($item eq 'resourcetag') {
                   14099:             if ($name eq 'responsetype') {
                   14100:                 $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
                   14101:             }
                   14102:         }
                   14103:     }
                   14104:     my $navmap = Apache::lonnavmaps::navmap->new();
                   14105:     if (defined($navmap)) {
                   14106:         my %allresponses;
                   14107:         foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
                   14108:             my %responses = $res->responseTypes();
                   14109:             foreach my $key (keys(%responses)) {
                   14110:                 next unless(exists($checkresponsetypes{$key}));
                   14111:                 $allresponses{$key} += $responses{$key};
                   14112:             }
                   14113:         }
                   14114:         foreach my $key (keys(%allresponses)) {
                   14115:             my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
                   14116:             if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
                   14117:                 ($reqdmajor,$reqdminor) = ($major,$minor);
                   14118:             }
                   14119:         }
                   14120:         undef($navmap);
                   14121:     }
                   14122:     unless (($reqdmajor eq '') && ($reqdminor eq '')) {
                   14123:         &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
                   14124:     }
                   14125:     return;
                   14126: }
                   14127: 
1.1075.2.27  raeburn  14128: sub allmaps_incourse {
                   14129:     my ($cdom,$cnum,$chome,$cid) = @_;
                   14130:     if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
                   14131:         $cid = $env{'request.course.id'};
                   14132:         $cdom = $env{'course.'.$cid.'.domain'};
                   14133:         $cnum = $env{'course.'.$cid.'.num'};
                   14134:         $chome = $env{'course.'.$cid.'.home'};
                   14135:     }
                   14136:     my %allmaps = ();
                   14137:     my $lastchange =
                   14138:         &Apache::lonnet::get_coursechange($cdom,$cnum);
                   14139:     if ($lastchange > $env{'request.course.tied'}) {
                   14140:         my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
                   14141:         unless ($ferr) {
                   14142:             &update_content_constraints($cdom,$cnum,$chome,$cid);
                   14143:         }
                   14144:     }
                   14145:     my $navmap = Apache::lonnavmaps::navmap->new();
                   14146:     if (defined($navmap)) {
                   14147:         foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
                   14148:             $allmaps{$res->src()} = 1;
                   14149:         }
                   14150:     }
                   14151:     return \%allmaps;
                   14152: }
                   14153: 
1.1075.2.11  raeburn  14154: sub parse_supplemental_title {
                   14155:     my ($title) = @_;
                   14156: 
                   14157:     my ($foldertitle,$renametitle);
                   14158:     if ($title =~ /&amp;&amp;&amp;/) {
                   14159:         $title = &HTML::Entites::decode($title);
                   14160:     }
                   14161:     if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
                   14162:         $renametitle=$4;
                   14163:         my ($time,$uname,$udom) = ($1,$2,$3);
                   14164:         $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
                   14165:         my $name =  &plainname($uname,$udom);
                   14166:         $name = &HTML::Entities::encode($name,'"<>&\'');
                   14167:         $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
                   14168:         $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
                   14169:             $name.': <br />'.$foldertitle;
                   14170:     }
                   14171:     if (wantarray) {
                   14172:         return ($title,$foldertitle,$renametitle);
                   14173:     }
                   14174:     return $title;
                   14175: }
                   14176: 
1.1075.2.18  raeburn  14177: sub symb_to_docspath {
                   14178:     my ($symb) = @_;
                   14179:     return unless ($symb);
                   14180:     my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
                   14181:     if ($resurl=~/\.(sequence|page)$/) {
                   14182:         $mapurl=$resurl;
                   14183:     } elsif ($resurl eq 'adm/navmaps') {
                   14184:         $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
                   14185:     }
                   14186:     my $mapresobj;
                   14187:     my $navmap = Apache::lonnavmaps::navmap->new();
                   14188:     if (ref($navmap)) {
                   14189:         $mapresobj = $navmap->getResourceByUrl($mapurl);
                   14190:     }
                   14191:     $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
                   14192:     my $type=$2;
                   14193:     my $path;
                   14194:     if (ref($mapresobj)) {
                   14195:         my $pcslist = $mapresobj->map_hierarchy();
                   14196:         if ($pcslist ne '') {
                   14197:             foreach my $pc (split(/,/,$pcslist)) {
                   14198:                 next if ($pc <= 1);
                   14199:                 my $res = $navmap->getByMapPc($pc);
                   14200:                 if (ref($res)) {
                   14201:                     my $thisurl = $res->src();
                   14202:                     $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
                   14203:                     my $thistitle = $res->title();
                   14204:                     $path .= '&'.
                   14205:                              &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
                   14206:                              &Apache::lonhtmlcommon::entity_encode($thistitle).
                   14207:                              ':'.$res->randompick().
                   14208:                              ':'.$res->randomout().
                   14209:                              ':'.$res->encrypted().
                   14210:                              ':'.$res->randomorder().
                   14211:                              ':'.$res->is_page();
                   14212:                 }
                   14213:             }
                   14214:         }
                   14215:         $path =~ s/^\&//;
                   14216:         my $maptitle = $mapresobj->title();
                   14217:         if ($mapurl eq 'default') {
                   14218:             $maptitle = 'Main Course Documents';
                   14219:         }
                   14220:         $path .= (($path ne '')? '&' : '').
                   14221:                  &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
                   14222:                  &Apache::lonhtmlcommon::entity_encode($maptitle).
                   14223:                  ':'.$mapresobj->randompick().
                   14224:                  ':'.$mapresobj->randomout().
                   14225:                  ':'.$mapresobj->encrypted().
                   14226:                  ':'.$mapresobj->randomorder().
                   14227:                  ':'.$mapresobj->is_page();
                   14228:     } else {
                   14229:         my $maptitle = &Apache::lonnet::gettitle($mapurl);
                   14230:         my $ispage = (($type eq 'page')? 1 : '');
                   14231:         if ($mapurl eq 'default') {
                   14232:             $maptitle = 'Main Course Documents';
                   14233:         }
                   14234:         $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
                   14235:                 &Apache::lonhtmlcommon::entity_encode($maptitle).':::::'.$ispage;
                   14236:     }
                   14237:     unless ($mapurl eq 'default') {
                   14238:         $path = 'default&'.
                   14239:                 &Apache::lonhtmlcommon::entity_encode('Main Course Documents').
                   14240:                 ':::::&'.$path;
                   14241:     }
                   14242:     return $path;
                   14243: }
                   14244: 
1.1075.2.14  raeburn  14245: sub captcha_display {
                   14246:     my ($context,$lonhost) = @_;
                   14247:     my ($output,$error);
                   14248:     my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
                   14249:     if ($captcha eq 'original') {
                   14250:         $output = &create_captcha();
                   14251:         unless ($output) {
                   14252:             $error = 'captcha';
                   14253:         }
                   14254:     } elsif ($captcha eq 'recaptcha') {
                   14255:         $output = &create_recaptcha($pubkey);
                   14256:         unless ($output) {
                   14257:             $error = 'recaptcha';
                   14258:         }
                   14259:     }
                   14260:     return ($output,$error);
                   14261: }
                   14262: 
                   14263: sub captcha_response {
                   14264:     my ($context,$lonhost) = @_;
                   14265:     my ($captcha_chk,$captcha_error);
                   14266:     my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
                   14267:     if ($captcha eq 'original') {
                   14268:         ($captcha_chk,$captcha_error) = &check_captcha();
                   14269:     } elsif ($captcha eq 'recaptcha') {
                   14270:         $captcha_chk = &check_recaptcha($privkey);
                   14271:     } else {
                   14272:         $captcha_chk = 1;
                   14273:     }
                   14274:     return ($captcha_chk,$captcha_error);
                   14275: }
                   14276: 
                   14277: sub get_captcha_config {
                   14278:     my ($context,$lonhost) = @_;
                   14279:     my ($captcha,$pubkey,$privkey,$hashtocheck);
                   14280:     my $hostname = &Apache::lonnet::hostname($lonhost);
                   14281:     my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
                   14282:     my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
                   14283:     if ($context eq 'usercreation') {
                   14284:         my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
                   14285:         if (ref($domconfig{$context}) eq 'HASH') {
                   14286:             $hashtocheck = $domconfig{$context}{'cancreate'};
                   14287:             if (ref($hashtocheck) eq 'HASH') {
                   14288:                 if ($hashtocheck->{'captcha'} eq 'recaptcha') {
                   14289:                     if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
                   14290:                         $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
                   14291:                         $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
                   14292:                     }
                   14293:                     if ($privkey && $pubkey) {
                   14294:                         $captcha = 'recaptcha';
                   14295:                     } else {
                   14296:                         $captcha = 'original';
                   14297:                     }
                   14298:                 } elsif ($hashtocheck->{'captcha'} ne 'notused') {
                   14299:                     $captcha = 'original';
                   14300:                 }
                   14301:             }
                   14302:         } else {
                   14303:             $captcha = 'captcha';
                   14304:         }
                   14305:     } elsif ($context eq 'login') {
                   14306:         my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
                   14307:         if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
                   14308:             $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
                   14309:             $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
                   14310:             if ($privkey && $pubkey) {
                   14311:                 $captcha = 'recaptcha';
                   14312:             } else {
                   14313:                 $captcha = 'original';
                   14314:             }
                   14315:         } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
                   14316:             $captcha = 'original';
                   14317:         }
                   14318:     }
                   14319:     return ($captcha,$pubkey,$privkey);
                   14320: }
                   14321: 
                   14322: sub create_captcha {
                   14323:     my %captcha_params = &captcha_settings();
                   14324:     my ($output,$maxtries,$tries) = ('',10,0);
                   14325:     while ($tries < $maxtries) {
                   14326:         $tries ++;
                   14327:         my $captcha = Authen::Captcha->new (
                   14328:                                            output_folder => $captcha_params{'output_dir'},
                   14329:                                            data_folder   => $captcha_params{'db_dir'},
                   14330:                                           );
                   14331:         my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
                   14332: 
                   14333:         if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
                   14334:             $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
                   14335:                       &mt('Type in the letters/numbers shown below').'&nbsp;'.
                   14336:                      '<input type="text" size="5" name="code" value="" /><br />'.
                   14337:                      '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" />';
                   14338:             last;
                   14339:         }
                   14340:     }
                   14341:     return $output;
                   14342: }
                   14343: 
                   14344: sub captcha_settings {
                   14345:     my %captcha_params = (
                   14346:                            output_dir     => $Apache::lonnet::perlvar{'lonCaptchaDir'},
                   14347:                            www_output_dir => "/captchaspool",
                   14348:                            db_dir         => $Apache::lonnet::perlvar{'lonCaptchaDb'},
                   14349:                            numchars       => '5',
                   14350:                          );
                   14351:     return %captcha_params;
                   14352: }
                   14353: 
                   14354: sub check_captcha {
                   14355:     my ($captcha_chk,$captcha_error);
                   14356:     my $code = $env{'form.code'};
                   14357:     my $md5sum = $env{'form.crypt'};
                   14358:     my %captcha_params = &captcha_settings();
                   14359:     my $captcha = Authen::Captcha->new(
                   14360:                       output_folder => $captcha_params{'output_dir'},
                   14361:                       data_folder   => $captcha_params{'db_dir'},
                   14362:                   );
1.1075.2.26  raeburn  14363:     $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14  raeburn  14364:     my %captcha_hash = (
                   14365:                         0       => 'Code not checked (file error)',
                   14366:                        -1      => 'Failed: code expired',
                   14367:                        -2      => 'Failed: invalid code (not in database)',
                   14368:                        -3      => 'Failed: invalid code (code does not match crypt)',
                   14369:     );
                   14370:     if ($captcha_chk != 1) {
                   14371:         $captcha_error = $captcha_hash{$captcha_chk}
                   14372:     }
                   14373:     return ($captcha_chk,$captcha_error);
                   14374: }
                   14375: 
                   14376: sub create_recaptcha {
                   14377:     my ($pubkey) = @_;
                   14378:     my $captcha = Captcha::reCAPTCHA->new;
                   14379:     return $captcha->get_options_setter({theme => 'white'})."\n".
                   14380:            $captcha->get_html($pubkey).
                   14381:            &mt('If either word is hard to read, [_1] will replace them.',
                   14382:                '<image src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
                   14383:            '<br /><br />';
                   14384: }
                   14385: 
                   14386: sub check_recaptcha {
                   14387:     my ($privkey) = @_;
                   14388:     my $captcha_chk;
                   14389:     my $captcha = Captcha::reCAPTCHA->new;
                   14390:     my $captcha_result =
                   14391:         $captcha->check_answer(
                   14392:                                 $privkey,
                   14393:                                 $ENV{'REMOTE_ADDR'},
                   14394:                                 $env{'form.recaptcha_challenge_field'},
                   14395:                                 $env{'form.recaptcha_response_field'},
                   14396:                               );
                   14397:     if ($captcha_result->{is_valid}) {
                   14398:         $captcha_chk = 1;
                   14399:     }
                   14400:     return $captcha_chk;
                   14401: }
                   14402: 
1.41      ng       14403: =pod
                   14404: 
                   14405: =back
                   14406: 
1.112     bowersj2 14407: =cut
1.41      ng       14408: 
1.112     bowersj2 14409: 1;
                   14410: __END__;
1.41      ng       14411: 

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